17771 Commits

Author SHA1 Message Date
Andrew Kelley
88e98a0611
Merge pull request #11289 from schmee/stage2-select
stage2: implement `@select`
2022-03-26 00:33:22 -04:00
Andrew Kelley
bae35bdf2d stage2: result location types for function call arguments
* AstGen: restore the param_type ZIR instruction and pass it to the
   expression for function call arguments. This does not solve the
   problem for generic function parameters, but it catches stage2 up to
   stage1 which also does not solve the problem for generic function
   parameters.
   - Most of the enhancements in this commit will still be needed for a
     more sophisticated further improvement to handle generic function
     types.
   - In Sema, handling of `as` coercion recognizes the `var_args_param`
     Type Tag and passes the operand through doing no coercion.
   - That was the last ZIR tag and we are now using all 256 ZIR tags.
 * AstGen: array init and struct init expressions use the anon form even
   when the result location has a type. Prevents the type system
   incorrectly believing, for example, that a tuple is actually an array
   when the result location is a param_type of a function with `anytype`
   parameter.
 * Sema: add missing coercion in `unionInit` to coerce the init to the
   corresponding union field type.
 * `Value.fieldValue` now takes a type and does not take an allocator.

closes #11293

After this commit, stage2 passes all the parser tests.
2022-03-26 00:27:12 -04:00
Andrew Kelley
bcd7eb012a
Merge pull request #11304 from joachimschmidt557/stage2-aarch64
stage2 AArch64: remove MCValue.embedded_in_code
2022-03-25 22:22:47 -04:00
joachimschmidt557
c1098e9036 stage2 x86_64: remove MCValue.embedded_in_code 2022-03-25 22:22:16 -04:00
Andrew Kelley
600c7fe1da
Merge pull request #11299 from Vexu/stage2-build
stage2 fixes on the way to `zig2 build --help` working
2022-03-25 21:35:04 -04:00
Veikka Tuominen
2f326f24dd Sema: implement zirSwitchCapture multi for unions 2022-03-25 22:32:15 +02:00
Veikka Tuominen
17d214a249 Sema: implement zirStructInit for runtime-known union values 2022-03-25 22:32:15 +02:00
Veikka Tuominen
5ff518fbb9 Sema: implement zirSwitchCapture for error sets 2022-03-25 22:32:14 +02:00
Veikka Tuominen
26dfbf8122 type: fix onePossibleValue for auto numbered enums 2022-03-25 22:32:14 +02:00
Veikka Tuominen
f6bd534fc9 Sema: ensure error_set_merged is sorted 2022-03-25 22:32:14 +02:00
Veikka Tuominen
a4c5ec49f1 Sema: add error for empty switch 2022-03-25 22:30:35 +02:00
joachimschmidt557
f7da4b9bc8
stage2 AArch64: change semantics of MCValue.stack_offset
Mirrors the changes performed to stack_offset in the ARM backend
2022-03-25 19:21:34 +01:00
joachimschmidt557
16e4966332
stage2 AArch64: remove MCValue.embedded_in_code 2022-03-25 19:21:34 +01:00
joachimschmidt557
061d6699c0
stage2 AArch64: lower cmp to binOp 2022-03-25 19:21:34 +01:00
John Schmidt
cd46daf7d0 sema: coerce inputs to vectors in zirSelect 2022-03-25 19:14:11 +01:00
John Schmidt
f47db0a0db sema: use pl_op for @select 2022-03-25 16:13:54 +01:00
John Schmidt
12d5efcbe6 stage2: implement @select 2022-03-25 16:13:54 +01:00
Jakub Konka
1c33ea2c35 dwarf: add debug info for unions 2022-03-25 13:53:40 +01:00
Evan Haas
0d5d353197 translate-c: Use @Vector for vector expressions
Removes translate-c usage of std.meta.Vector, which was deprecated in d42d31f72f
2022-03-25 14:47:51 +02:00
dxps
9a127501f6 chore: doc fixes, closes 11091 2022-03-25 11:22:30 +02:00
Andrew Kelley
7f91be9c80 AstGen: emit break_inline from inline while loop 2022-03-24 22:45:10 -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
b802a67562 std.MultiArrayList: check size of element, not pointer
Ever since a semi-recent language specification update, pointers to
zero-sized types still have runtime bits.
2022-03-24 19:55:12 -07:00
Andrew Kelley
bb0e28a54f Sema: fix generic function with void parameters
This also fixes a bug that I didn't see causing any problems yet in
generic function instantiation where it would read from a GetOrPutResult
too late.

Also it delays full resolution of generic function type parameters until
after the function body is finished being analyzed.

closes #11291
2022-03-24 19:36:36 -07:00
Andrew Kelley
7cfa97aa4e std.meta.trait: remove assumption about vector ABI size
The unit test for hasUniqueRepresentation asserted that a vector of
length 3 would not have a unique representation. This would be true if
it were lowered to ABI size 8 instead of 6. However lowering it to ABI
size 6 is perfectly valid depending on the target.

This commit also simplifies the logic for hasUniqueRepresentation of
integers.
2022-03-24 18:09:45 -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
9a1d5001d4 Sema: fix false negative detecting comptime const
The code for detecting when a local const initialization expression
ended up being comptime-known gave up when it encountered dbg_stmt
instructions, but such instructions are not supposed to matter.
2022-03-24 17:47:39 -07:00
Andrew Kelley
f5f5b9373d std.meta: fix unit tests depending on unstable behavior
The unit tests of std.meta depended on `@typeInfo` for the same type
returning a slice of declarations and fields with the same pointer
address. This is not something guaranteed by the language specification.
2022-03-24 17:47:39 -07:00
Jakub Konka
20cc560c2d
Merge pull request #11286 from ziglang/stage2-aggregate-init
stage2: add debug info for tuples (and anon structs), and implement aggregate_init for structs and arrays
2022-03-24 22:29:20 +01:00
Andrew Kelley
b09280b484 move some files to the .github directory 2022-03-24 12:22:23 -07:00
Jakub Konka
04523db6ae x64: fix for 32bit builds 2022-03-24 18:54:17 +01:00
Jakub Konka
4ef26fc355 pass more behaviour tests 2022-03-24 17:04:50 +01:00
Jakub Konka
608025456b x64: account for signed ints in struct_field_val when struct fits in a register 2022-03-24 17:02:29 +01:00
Jakub Konka
9d2ff7ed16 x64: fix struct_field_val for structs fitting in register 2022-03-24 17:02:29 +01:00
Jakub Konka
77352c5bea x64: implement aggregate_init for arrays 2022-03-24 17:02:29 +01:00
Jakub Konka
4e801c2783 x64: implement aggregate_init for structs 2022-03-24 17:02:29 +01:00
Jakub Konka
2286f9bd1f dwarf: add debug info for tuples and anon structs 2022-03-24 17:02:29 +01:00
Andrew Kelley
2af69710a7 stage2: fix some generics issues
* std.meta: correct use of `default_value` in reification. stage1
   accepted a wrong type for `null`.
 * Sema: after instantiating a generic function, if the return type ends
   up being a comptime-known type, then we return an error, undoing the
   generic function instantiation, and making a comptime function call
   instead.
   - We also needed to clean up the dependency graph in this case.
 * Sema: reified enums set tag_ty_inferred to false since an integer tag
   type is provided. This is a limitation of the `@Type` builtin which
   will be addressed with #10710.
 * Sema: fix resolveInferredErrorSet incorrectly calling
   ensureFuncBodyAnalyzed on generic functions.
2022-03-23 23:28:05 -07:00
Andrew Kelley
aca42c6259 Sema: fix comptime elem_ptr compare fixed address 2022-03-23 19:58:13 -07:00
Andrew Kelley
74ccd0c40b Sema: Value.copy: we gotta copy the bytes
For Value.Tag.bytes, the value copy implementation did not copy the
bytes array. No good. This operation must do a deep copy. If we want
some other mechanism for not copying very large byte buffers then it has
to work differently than this one.
2022-03-23 19:20:38 -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
57539a26b4 std.os: disable failing fnctl file locking test
See #11074
2022-03-23 17:29:39 -07:00
Andrew Kelley
e02ec8f7f5
Merge pull request #11280 from Luukdegram/wasm-errors
stage2: wasm - `@errorName` and more
2022-03-23 20:18:50 -04:00
Mitchell Hashimoto
a36f4ee290 stage2: able to slice to sentinel index at comptime
The runtime behavior allowed this in both stage1 and stage2, but stage1
fails with index out of bounds during comptime. This behavior makes
sense to support, and comptime behavior should match runtime behavior. I
implement this fix only in stage2.
2022-03-23 17:08:08 -04: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
a2b0b0015d
Merge pull request #11273 from topolarity/bugfix-11272
stage2: Properly "flatten" elem_ptrs before deref
2022-03-23 16:46:50 -04:00
Andrew Kelley
41e300adf1 add behavior test to cover bug fix in previous commit 2022-03-23 13:46:06 -07:00
Cody Tapscott
5374e245c5 stage2: Remove premature elem_val index check
We were enforcing bounds on the index of an elem_ptr in pointerDeref,
but we want to support out-of-bounds accesses by reinterpreting memory.
This removes that check, so that the deref falls back to bitcasting, as
usual.

This was masked by another bug that was forcing bitcasts incorrectly,
which is why this wasn't noticed earlier.
2022-03-23 13:44:31 -07:00
Cody Tapscott
1c22381909 stage2: Properly "flatten" elem_ptrs before deref
Sema.pointerDeref() assumes that elem_ptrs have been "flattened" when
they were created, so that you an elem_ptr will never be the array_ptr
of another elem_ptr when they share the same type.

Value.elemPtr does this already, but a couple of places in Sema were
bypassing this logic.
2022-03-23 13:44:31 -07:00
Luuk de Gram
5cb16dfa59
wasm: Enable all passing tests
All tests have been manually verified which are now passing. This means that any remaining
TODO is an actual to-be-fixed or to-be-implemented test case.
2022-03-23 21:40:33 +01:00