673 Commits

Author SHA1 Message Date
leesongun
7ae22813ee
stage1: implement casting from u0 2022-03-27 11:49:54 +03:00
Luuk de Gram
16e88b75ba wasm: Enable passing tests 2022-03-26 21:20:29 +01:00
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
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
f6bd534fc9 Sema: ensure error_set_merged is sorted 2022-03-25 22:32:14 +02: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
12d5efcbe6 stage2: implement @select 2022-03-25 16:13:54 +01: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
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
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
Jakub Konka
4ef26fc355 pass more behaviour tests 2022-03-24 17:04:50 +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
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
41e300adf1 add behavior test to cover bug fix in previous commit 2022-03-23 13:46:06 -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
William Sengir
b872539a13 stage2: enable some passing array & vector tests 2022-03-23 16:39:29 -04:00
William Sengir
d7530c8f7b stage2: make zero-sized array not cause recursive type definition 2022-03-23 16:38:33 -04:00
Cody Tapscott
6fc07f49a9 stage2: concat/mult of slices yields ptr to array 2022-03-23 16:34:48 -04:00
Cody Tapscott
a9a91a5d49 stage2 CBE: Improve support for unions and error sets
This includes various fixes/improvements to the C backend to improve
error/union support. It also fixes up our handling of decls, where some
decls were not correctly marked alive.
2022-03-23 16:29:38 -04:00
Daniele Cocca
8f9c3fd3df
CBE: enable more passing tests (#11258) 2022-03-22 23:24:36 -04:00
joachimschmidt557
be1cca3416 stage2 ARM: implement comparison of optional pointers 2022-03-22 20:16:05 -07:00
Andrew Kelley
e8813b296b
Merge pull request #11260 from ziglang/lazy-alignof
stage2: lazy `@alignOf`
2022-03-22 22:30:38 -04:00
Mitchell Hashimoto
cb6364624f stage2: slice behavior test passes, just has diff behavior from stage1
This is from discussions from #11249. The stage2 behavior is correct and
is strictly more accurate, so we'd prefer to keep it. In that case, I
modified the behavior tests to have the conditional between
stage1/stage2 and get this test passing.
2022-03-22 19:56:10 -04:00
Andrew Kelley
60d8c4739d Sema: introduce a mechanism in Value to resolve types
This commit adds a new optional argument to several Value methods which
provides the ability to resolve types if it comes to it. This prevents
having duplicated logic inside both Sema and Value.

With this commit, the "struct contains slice of itself" test is passing
by exploiting the new lazy_align Value Tag.
2022-03-22 15:45:59 -07:00
Mitchell Hashimoto
91fd0f42c8 stage2: out of bounds error for slicing 2022-03-21 22:10:34 -04:00
Luuk de Gram
be579d4797 wasm: Implement @popCount 2022-03-21 22:01:34 -04:00
Andrew Kelley
7eddef423d behavior tests: alter test coverage for vectors
* Use `@Vector` syntax instead of `std.meta.Vector`.
 * Use `var` instead of `const` for tests so that we get runtime
   coverage instead of only comptime coverage. Comptime coverage is done
   with `comptime doTheTest()` calls.
2022-03-21 17:03:24 -07:00
William Sengir
c9598c4cd3 behavior tests: enable all vector tests for the stage2 LLVM backend 2022-03-21 16:54:19 -07:00
William Sengir
cda8f65489 behavior tests: use expect instead of expectEqual in vector.zig 2022-03-21 16:54:19 -07:00
Jakub Konka
d71bd0300b
Merge pull request #11195 from mparadinha/float-to-int
stage2: x86_64: implement `@floatToInt` for `f32` and `f64`
2022-03-21 23:54:36 +01:00
Jakub Konka
00e2113c8b x64: refactor fix reg aliasing in genSetReg 2022-03-21 23:38:01 +01:00
mparadinha
79e2d4b3f6 stage2: x86_64: update passing tests after implementing ptr_elem_val
the 3 tests that called `testArray2DConstDoublePtr` started passing
after implementing `ptr_elem_val`. the rest of these I think were
already passing before.
2022-03-21 20:13:27 +00:00
Andrew Kelley
18a43b61f9
Merge pull request #11253 from Vexu/pretty-print-values
stage2: print values with types
2022-03-21 15:15:38 -04:00
Veikka Tuominen
0577069af5 stage2 llvm: fix lowerDeclRefValue for function aliases 2022-03-21 15:12:32 -04:00
Veikka Tuominen
59668fbe80 stage2: add test for fixed issue
Closes #11157
2022-03-21 15:05:21 +02:00
Daniele Cocca
b6203b89d6 CBE: implement mod, divFloor, divTrunc 2022-03-19 21:01:36 -04:00
Andrew Kelley
1bd595ceea
Merge pull request #11233 from Luukdegram/wasm-tests
stage2: wasm - union_init and passing tests
2022-03-19 19:41:55 -04:00
Cody Tapscott
19331b323d stage2: Correctly align decls for comptime allocs
This updates WipAnonDecl to require an alignment provided by the caller,
which is needed for explicitly aligned comptime allocs.
2022-03-19 19:41:23 -04:00
Andrew Kelley
a318aeed9b
Merge pull request #11222 from Vexu/dbg_block
stage2: add debug info for payload captures + inline function parameters
2022-03-19 16:05:22 -04:00