Commit graph

80 commits

Author SHA1 Message Date
Veikka Tuominen
a760ce598c Sema: ensure that !is_comptime and !is_typeof implies sema.func != null
Closes #13481
2022-11-12 15:41:29 +02:00
Veikka Tuominen
f96748ebc1 Sema: coerce elements of array cat
Closes #13347
2022-11-05 13:22:21 +02:00
Cody Tapscott
ca332f57f7 stage2: Make x and false/x or true comptime-known
Same as preceding change, but for stage2.
2022-10-30 12:38:08 -07:00
Jacob Young
ab468d57e3 cbe: implement packed structs
Sometimes you have to break a test to make progress :)
2022-10-25 05:11:29 -04:00
Jacob Young
912b84bbad cbe: fix atomics 2022-10-25 05:11:29 -04:00
Jacob Young
1dd4a6102f cbe: implement global assembly 2022-10-25 05:11:29 -04:00
Jacob Young
525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00
Cody Tapscott
74b9cbd895 stage2: Skip test exposing #13175
This PR (#12873) in combination with this particular test exposed
a pre-existing bug (#13175).

This means that the test for #13038 has regressed
2022-10-21 12:40:33 -07:00
Veikka Tuominen
34e4b07d0c Sema: allow runtime only instructions to be emitted in outside functions
It is possible to get comptime-known values from runtime-known values
for example the length of array. Allowing runtime only instructions to
be emitted outside function bodies allows these operations to happen.
In places where comptime-known values are required we have other methods
to ensure that and they usually result in more specific compile errors too.

Closes #12240
2022-10-20 20:11:00 +03:00
Cody Tapscott
83e2d3fb37 stage1: Skip new tests that never passed in stage1
This gets the behavior tests passing for stage1 again.
2022-10-13 12:53:20 -07:00
Andrew Kelley
7ce1ee1bce
Merge pull request #13081 from r00ster91/docs
fix(text): hyphenation and other fixes
2022-10-12 05:26:11 -04:00
Veikka Tuominen
b626977f45 Sema: create sub block for inline loops
Closes #13038
2022-10-06 15:39:06 +03:00
r00ster91
51d9db8569 fix(text): hyphenate "comptime" adjectives 2022-10-05 21:19:30 +02:00
Veikka Tuominen
5e37da6ade Sema: check_comptime_control_flow needs to check runtime_index 2022-09-15 00:50:18 +03:00
Veikka Tuominen
bf4a3df9a9 Sema: allow runtime break from inline loop
Closes #12787
2022-09-15 00:48:47 +03:00
joachimschmidt557
94499898e5
stage2 ARM: implement basic array_elem_val 2022-09-09 20:26:04 +02:00
joachimschmidt557
b976997e16
stage2 ARM: implement ptr_elem_val 2022-09-09 19:17:18 +02:00
joachimschmidt557
a0a7d15142
stage2 ARM: support larger function stacks
This is done by introducing a new Mir pseudo-instruction
2022-09-09 19:17:18 +02:00
joachimschmidt557
3794f2c493
stage2 ARM: implement struct_field_val for registers 2022-09-09 19:17:18 +02:00
joachimschmidt557
261fec8036
stage2 ARM: amend implementation of various AIR instructions
- unwrap_errunion_err for registers
- unwrap_errunion_payload for registers
- ptr_slice_len_ptr for all MCValues
- ptr_slice_ptr_ptr for all MCValues
2022-09-09 19:17:17 +02:00
Veikka Tuominen
c1afe57d70 Sema: resolve lazy values in resolveMaybeUndefValIntable
Closes #12512
Closes #12513
2022-08-22 11:16:36 +03:00
Veikka Tuominen
20d0018d79 Sema: ignore dbg_block instructions when checking for comptimeness
Closes #12514
2022-08-21 12:53:19 +03:00
Veikka Tuominen
40447b25e8 Sema: fix expansion of repeated value
Closes #12386
2022-08-10 15:18:09 -04:00
Veikka Tuominen
1f748fe426 Sema: fix mutation of optional ptr represented as regular ptr 2022-07-22 19:50:11 +03:00
Veikka Tuominen
c619371ec1 Sema: fix loading and storing of optional pointers represented as pointers 2022-07-22 17:03:42 +03:00
Andrew Kelley
1d5f865cfa Sema: fix runtime instructions omitted
in the presence of comptime control flow.

fixes #12171
2022-07-19 17:45:38 -07:00
joachimschmidt557
960c142060 stage2 ARM: implement basic intCast and error union wrapping 2022-06-25 21:16:51 +02:00
Andrew Kelley
e64d5a0753 Sema: rework beginComptimePtrMutation
This comment is now deleted because the task is completed in this
commit:

```
// TODO: Update this to behave like `beginComptimePtrLoad` and properly check/use
// `container_ty` and `array_ty`, instead of trusting that the parent decl type
// matches the type used to derive the elem_ptr/field_ptr/etc.
//
// This is needed because the types will not match if the pointer we're mutating
// through is reinterpreting comptime memory.
```

The main strategy is to change the ComptimePtrMutationKit struct so that
instead of `val: *Value` it now returns a tagged union which can be one
of three possibilities:

 * The pointer type matches the actual comptime Value so a direct
   modification is possible. Before this commit, the implementation
   incorrectly assumed this was always the case.

 * In the case of needing to write through a reinterpreted pointer, a
   mutable base Value pointer is provided along with a byte offset
   pointing to the element value in virtual memory.

 * Otherwise, it means a compile error must be emitted because one or
   both of the types (the owner of the value, or the pointer type being
   used to write through) do not have a well-defined memory layout.

After calling beginComptimePtrMutation, the one callsite now switches on
this tagged union and does the appropriate thing. The main new logic is
for the second case, which involves pointer reinterpretation, which now
takes this strategy:

 1. write the base value to a memory buffer.
 2. perform the pointer store at the proper byte offset, thereby
    modifying a subset of the buffer.
 3. read the base value from the memory buffer, overwriting the old base
    value.
2022-06-12 01:33:56 -07:00
Andrew Kelley
32c90cb553 stage2: fix handling of aggregates with mixed comptime-only fields 2022-06-09 19:23:36 -07:00
Andrew Kelley
f4d5fcde72 AstGen: avoid redundant "ref" instructions
Whenever a `ref` instruction is needed, it is created and saved in
`AstGen.ref_table` instead of being immediately appended to the current
block body. Then, when the referenced instruction is being added to the
parent block (e.g. from setBlockBody), if it has a ref_table entry, then
the ref instruction is added directly after the instruction being referenced.
This makes sure two properties are upheld:
1. All pointers to the same locals return the same address. This is required
   to be compliant with the language specification.
2. `ref` instructions will dominate their uses. This is a required property
   of ZIR.

A complication arises when a ref instruction refs another ref
instruction. The logic in appendBodyWithFixups must take this into
account, recursively handling ref refs.
2022-06-08 20:40:16 -07:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04:00
Andrew Kelley
4751356d7f clean up some behavior tests
* improve names
 * properly categorize a couple of bug cases
 * mark one as already passing
2022-05-26 21:58:19 -07:00
Andrew Kelley
83f69af971 stage2: implement runtime array multiplication
Additionally:

 * Sema: fix array cat/mul not setting the sentinel value
   - This required an LLVM backend enhancement to the handling of the
     AIR instruction aggregate_init that likely needs to be
     propagated to the other backends.
 * Sema: report integer overflow of array concatenation in a proper
   compile error instead of crashing.
 * Sema: fix not using proper pointer address space for array cat/mul
2022-05-25 22:33:48 -07:00
Andrew Kelley
b82081e709 Sema: implement array concatenation with runtime operands 2022-05-25 22:33:48 -07:00
Andrew Kelley
ab88165326 Sema: generic function instantiations inherit branch quota 2022-05-25 23:32:52 -04:00
Andrew Kelley
60af42705d mark two behavior tests as passing 2022-05-24 18:21:34 -07:00
Andrew Kelley
7db39384f7 move bound function behavior test to compile error test 2022-05-24 15:34:52 -07:00
Andrew Kelley
1bf7a6dff5 enable passing behavior test
This was disabled for macOS but I just tested it on my M1 and it works
fine.
2022-05-24 15:34:52 -07:00
Andrew Kelley
818fbd9c56 stage2: string literal interning
This is a temporary addition to stage2 in order to match stage1 behavior,
however the end-game once the lang spec is settled will be to use a global
InternPool for comptime memoized objects, making this behavior consistent
across all types, not only string literals. Or, we might decide to not
guarantee string literals to have equal comptime pointers, in which case
this commit can be reverted.
2022-05-24 01:01:24 -07:00
Andrew Kelley
95f5e17e49 behavior tests: correction of C pointer test
This test was also covering this behavior:

```zig
test "equality of pointers to comptime const" {
    const a: i32 = undefined;
    comptime assert(&a == &a);
}
```

This check belongs in its own behavior test which isolates this
behavior; not bundled along with a C pointer test.
2022-05-17 23:50:38 -07:00
Andrew Kelley
9afc4fe0e2 Sema: solve a false positive "depends on itself"
This improves the ABI alignment resolution code.

This commit fully enables the MachO linker code in stage3. Note,
however, that there are still miscompilations in stage3.
2022-05-06 22:40:57 -07:00
Andrew Kelley
3b32e0be31 behavior tests: disable failing stage1 test
I forgot to check that the new behavior tests also pass in stage1. One
of them does not.

Fixes regression from 4618c41fa6.
2022-04-02 19:02:29 -07:00
Andrew Kelley
4618c41fa6 Sema: mechanism for converting comptime breaks to runtime
closes #11369
2022-04-02 18:30:44 -07:00
Daniele Cocca
8238d4b335 CBE: fix C output after PR #11302, reenable tests
Commit 052079c994 surfaced two issues with
the generated C code:

  - renderInt128() contained a seemingly unnecessary assertion to verify
    that the high 64 bits of the number were nonzero, dating back to
    9bf1681990. I removed it.
  - renderValue() didn't have any special handling for undefined structs,
    falling back to printing "{}" which generated invalid expressions
    such as "return {}" for functions returning structs, whereas
    "return (S){}" is the correct form. I changed it accordingly.

At the same time I'm reenabling the relevant tests.
2022-03-29 02:28:20 -04:00
Mitchell Hashimoto
8fbac2e86d
stage2: runtime safety check integer cast truncating bits 2022-03-27 09:20:37 -07:00
Andrew Kelley
bcf2eb1a00 Sema: fix closure capture typeof runtime-known parameter
Closures are not necessarily constant values. For example, Zig
code might do something like this:

    fn foo(x: anytype) void {
        const S = struct {field: @TypeOf(x)};
    }

...in which case the closure_capture instruction has access to a
runtime value only. In such case we preserve the type and use a
dummy runtime value.

closes #11292
2022-03-24 21:47:18 -07:00
Andrew Kelley
5c68afef94 AstGen: fix const locals with comptime initializations
`const foo = comptime ...` generated invalid ZIR when the initialization
expression contained an array literal because the
validate_array_init_comptime instruction assumed that the corresponding
alloc instruction was comptime. The solution is to look slightly ahead
and notice that the initialization expression would be comptime-known
and affect the alloc instruction tag accordingly.
2022-03-24 17:47:39 -07:00
Andrew Kelley
7378ce67da Sema: introduce a type resolution queue
That happens after a function body is analyzed. This prevents circular
dependency compile errors and yet a way to mark types that need to be
fully resolved before a given function is sent to the codegen backend.
2022-03-23 18:45:51 -07:00
Andrew Kelley
f27d3409bd behavior tests: disable failing stage1 test
My previous commit added a new behavior test that passes for stage2 but
I forgot to check whether it passes for stage1. Since it does not, it
has to be disabled.

Additionally, this commit organizes behavior tests; there is no longer a
section of tests only passing for stage1. Instead, tests are disabled on
an individual basis. There is an except for the file which has global
assembly in it.
2022-03-23 14:06:07 -07:00
Andrew Kelley
41e300adf1 add behavior test to cover bug fix in previous commit 2022-03-23 13:46:06 -07:00