4150 Commits

Author SHA1 Message Date
Jakub Konka
e6729036e4 x64: partially fix genImul, enable overflow tests 2022-03-28 17:45:50 +02:00
Andrew Kelley
c8f8440271 stage1: disable failing test
The new behavior test introduced in the previous commit is not passing
for stage1 on mips.
2022-03-27 14:40:24 -07:00
Andrew Kelley
6d2ec7a4e3 LLVM: handle aggregate_init for packed structs 2022-03-27 14:22:47 -07:00
Andrew Kelley
052079c994
Merge pull request #11302 from mitchellh/slice-null-cptr
stage2: runtime safety checks for slicing a null C pointer and @intCast truncating bits
2022-03-27 15:37:09 -04:00
Luuk de Gram
e1bb09648f
wasm: Enable overflow behavior tests 2022-03-27 19:02:45 +02:00
Mitchell Hashimoto
8fbac2e86d
stage2: runtime safety check integer cast truncating bits 2022-03-27 09:20:37 -07:00
Mitchell Hashimoto
01698528d1
stage2: safety checks for slicing a null C pointer 2022-03-27 09:20:35 -07:00
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
6ef761307c
Merge pull request #11284 from topolarity/compile-errors-indep-files
Add primitive file support for compile error tests
2022-03-26 00:45:38 -04: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
Cody Tapscott
0568b45779 Move existing compile errors to independent files
Some cases had to stay behind, either because they required complex case
configuration that we don't support in independent files yet, or because
they have associated comments which we don't want to lose track of.

To make sure I didn't drop any tests in the process, I logged all
obj/test/exe test cases from a run of "zig build test" and compared
before/after this change.

All of the test cases match, with two exceptions:
 - "use of comptime-known undefined function value" was deleted, since
   it was a duplicate
 - "slice sentinel mismatch" was renamed to "vector index out of
   bounds", since it was incorrectly named
2022-03-25 12:27:46 -07:00
Cody Tapscott
7f64f7c925 Add rudimentary compile error test file support
This brings two quality-of-life improvements for folks working on
compile error test cases:
 - test cases can be added/changed without re-building Zig
 - wrapping the source in a multi-line string literal is not necessary

I decided to keep things as simple as possible for this initial
implementation. The test "manifest" is a contiguous comment block at the
end of the test file:
1. The first line is the test case name
2. The second line is a blank comment
2. The following lines are expected errors

Here's an example:
```zig
const U = union(enum(u2)) {
    A: u8,
    B: u8,
    C: u8,
    D: u8,
    E: u8,
};
export fn entry() void {
    _ = U{ .E = 1 };
}

// union with too small explicit unsigned tag type
//
// tmp.zig:1:22: error: specified integer tag type cannot represent every field
// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
```

The mode of the test (obj/exe/test), as well as the target
(stage1/stage2) is determined based on the directory containing the
test.

We'll probably eventually want to support embedding this information
in the test files themselves, similar to the arocc test runner, but
that enhancement can be tackled later.
2022-03-25 12:25:43 -07: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
44f9061b71 fix merge conflicts and test cases 2022-03-22 15:58:19 -07: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
Andrew Kelley
593130ce0a stage2: lazy @alignOf
Add a `target` parameter to every function that deals with Type and
Value.
2022-03-22 15:45:58 -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