Commit Graph

47 Commits

Author SHA1 Message Date
Jakub Konka
62625d9d95 test: migrate stage1 compile error tests to updated test manifest 2022-04-28 18:35:01 +02:00
Jakub Konka
5a5648c0f0 test: migrate llvm incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
495bb12e6a test: migrate plan9 and sparcv9 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
ed51a5d02a test: migrate arm incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
fc4fbfe8e1 test: migrate aarch64 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
7e17cbbda5 test: migrate riscv64 incremental tests 2022-04-28 18:35:01 +02:00
Jakub Konka
8e05e6a1ed test: migrate wasm incremental tests 2022-04-28 18:35:01 +02:00
Koakuma
e791f062ba stage2: sparcv9: Load tests to the list of testcases 2022-04-14 23:24:46 +07:00
Andrew Kelley
547e6f6ee1 disable failing nvptx test cases
See #10968
2022-03-14 00:11:46 -07:00
Guillaume Wenzek
f000f8a59a fix nvptx test failure #10968
allow test cases to chose wether to link libc or not.
default behavior is to not link libc, except for `exeUsingLLVMBackend`
2022-03-12 14:25:59 -05:00
Andrew Kelley
7f48bc3493 disable failing nvptx test case
workaround for #10968
2022-02-21 23:48:07 -07:00
gwenzek
628e9e6d04
enable Gpu address spaces (#10884) 2022-02-21 14:05:27 -05:00
Jakub Konka
4b5f8bca5e stage2: clean up tests
* move darwin tests into respective architecture test files: `x86_64`
and `aarch64`
* run majority of `x86_64` tests on macOS
2021-12-15 17:28:48 +01:00
Luuk de Gram
adf059f272
wasm: Update wasm stage2 test backend to use 'main' 2021-11-29 08:05:51 +01:00
Jakub Konka
696e51be49 stage2: re-enable all tests
I've committed what I didn't want to by mistake...
2021-11-19 22:41:10 +01:00
Jakub Konka
ad5533fdfb stage2,x86_64: revert fixing callee preserved regs
This will require further rework in the codegen so reverting for now.
2021-11-19 22:18:56 +01:00
Jacob G-W
149bc79486 add tests for previous commit 2021-11-19 09:38:36 +01:00
Martin Wickham
d86678778a Fix failing tests and windows link dependencies 2021-09-22 14:39:02 -05:00
Robin Voetter
68fcbb5c0d Address Spaces: fmt a bunch of stuff 2021-09-20 02:29:04 +02:00
Robin Voetter
2f43749c2b Address Spaces: Move stage 2 tests to stage2/llvm.zig 2021-09-20 02:29:04 +02:00
Robin Voetter
8f28c58759 Address Spaces: compiles() test cases 2021-09-20 02:29:04 +02:00
Robin Voetter
7686165c82 Address Spaces: Pointer coercion errors tests 2021-09-20 02:29:04 +02:00
Robin Voetter
6336f08c21 Address Spaces: Address space on local variable test 2021-09-20 02:29:04 +02:00
Andrew Kelley
dbe9a5114e stage2: implement @setAlignStack and 128-bit cmpxchg
* test runner is improved to respect `error.SkipZigTest`
 * start code is improved to `@setAlignStack(16)` before calling main()
 * the newly passing behavior test has a workaround for the fact that
   stage2 cannot yet call `std.Target.x86.featureSetHas()` at comptime.
   This is blocking on comptime closures. The workaround is that there
   is a new decl `@import("builtin").stage2_x86_cx16` which is a `bool`.
 * Implement `@setAlignStack`. This language feature should be re-evaluated
   at some point - I'll file an issue for it.
 * LLVM backend: apply/remove the cold attribute and noinline attribute
   where appropriate.
 * LLVM backend: loads and stores are properly annotated with alignment
   and volatile attributes.
 * LLVM backend: allocas are properly annotated with alignment.
 * Type: fix integers reporting wrong alignment for 256-bit integers and
   beyond. Once you get to 16 byte aligned, there is no further
   alignment for larger integers.
2021-09-16 21:03:55 -07:00
Andrew Kelley
cca57042df std: fix regressions from this branch
Also move some usingnamespace test cases from compare_output to
behavior.
2021-09-01 17:54:07 -07:00
Andrew Kelley
4bb5d17edc AstGen: pre-scan all decls in a namespace
Also:
 * improve the "ambiguous reference" error by swapping the order of
   "declared here" and "also declared here" notes.
 * improve the "not accessible from inner function" error:
   - point out that it has to do with the thing being mutable
   - eliminate the incorrect association with it being a function
   - note where it crosses a namespace boundary
 * struct field types are evaluated in a context that has the struct
   namespace visible. Likewise with align expressions, linksection
   expressions, enum tag values, and union/enum tag argument
   expressions.

Closes #9194
Closes #9622
2021-08-28 16:04:38 -07:00
Andrew Kelley
f1f28af188 fix stage2 test cases expecting wrong line numbers
Previous commit shifted everything down in the start.zig file, and
unfortunately our stage2 test harness depends on absolute line
numbers for a couple tests.
2021-08-24 13:42:31 -07:00
Jacob G-W
df10e998ee stage2 x86_64: enable bitwise and + or and add tests 2021-08-19 22:21:16 +03:00
Jacob G-W
d785dc49aa stage2: add error set type equality 2021-08-19 14:09:53 +03:00
Jakub Konka
1373df4c34
Merge pull request #9227 from mathetake/libc-wasi-test
WASI,libc: fix libstd with wasi-libc linkage, and enable tests.
2021-08-13 21:56:32 +02:00
Andrew Kelley
a0670e748e
Merge pull request #9166 from joachimschmidt557/stage2
stage2 Sema: Add error notes to unresolvable peer types
2021-08-12 13:22:27 -04:00
Takeshi Yoneda
97560cd915 Merge remote-tracking branch 'origin' into libc-wasi-test 2021-08-09 14:39:26 +09:00
Andrew Kelley
d4468affb7 stage2 generics improvements: anytype and param type exprs
AstGen result locations now have a `coerced_ty` tag which is the same as
`ty` except it assumes that Sema will do a coercion, so it does not
redundantly add an `as` instruction into the ZIR code. This results in
cleaner ZIR and about a 14% reduction of ZIR bytes.

param and param_comptime ZIR instructions now have a block body for
their type expressions. This allows Sema to skip evaluation of the
block in the case that the parameter is comptime-provided. It also
allows a new mechanism to function: when evaluating type expressions of
generic functions, if it would depend on another parameter, it returns
`error.GenericPoison` which bubbles up and then is caught by the
param/param_comptime instruction and then handled.

This allows parameters to be evaluated independently so that the type
info for functions which have comptime or anytype parameters will still
have types populated for parameters that do not depend on values of
previous parameters (because evaluation of their param blocks will return
successfully instead of `error.GenericPoison`).

It also makes iteration over the block that contains function parameters
slightly more efficient since it now only contains the param
instructions.

Finally, it fixes the case where a generic function type expression contains
a function prototype. Formerly, this situation would cause shared state
to clobber each other; now it is in a proper tree structure so that
can't happen. This fix also required adding a field to Sema
`comptime_args_fn_inst` to make sure that the `comptime_args` field
passed into Sema is applied to the correct `func` instruction.

Source location for `node_offset_asm_ret_ty` is fixed; it was pointing at
the asm output name rather than the return type as intended.

Generic function instantiation is fixed, notably with respect to
parameter type expressions that depend on previous parameters, and with
respect to types which must be always comptime-known. This involves
passing all the comptime arguments at a callsite of a generic function,
and allowing the generic function semantic analysis to coerce the values
to the proper types (since it has access to the evaluated parameter type
expressions) and then decide based on the type whether the parameter is
runtime known or not. In the case of explicitly marked `comptime`
parameters, there is a check at the semantic analysis of the `call`
instruction.

Semantic analysis of `call` instructions does type coercion on the
arguments, which is needed both for generic functions and to make up for
using `coerced_ty` result locations (mentioned above).

Tasks left in this branch:
 * Implement the memoization table.
 * Add test coverage.
 * Improve error reporting and source locations for compile errors.
2021-08-04 21:11:31 -07:00
joachimschmidt557
16c1198858
stage2 Sema: Resolve LazySrcLocs for bitwise and arithmetic exprs 2021-08-04 09:33:12 +02:00
joachimschmidt557
fcdc5c6b3c
stage2 Sema: Resolve source locations of @TypeOf parameters 2021-08-04 09:31:46 +02:00
Andrew Kelley
a5c6e51f03 stage2: more principled approach to comptime references
* AIR no longer has a `variables` array. Instead of the `varptr`
   instruction, Sema emits a constant with a `decl_ref`.
 * AIR no longer has a `ref` instruction. There is no longer any
   instruction that takes a value and returns a pointer to it. If this
   is desired, Sema must either create an anynomous Decl and return a
   constant `decl_ref`, or in the case of a runtime value, emit an
   `alloc` instruction, `store` the value to it, and then return the
   `alloc`.
 * The `ref_val` Value Tag is eliminated. `decl_ref` should be used
   instead. Also added is `eu_payload_ptr` which points to the payload
   of an error union, given an error union pointer.

In general, Sema should avoid calling `analyzeRef` if it can be helped.
For example in the case of field_val and elem_val, there should never be
a reason to create a temporary (alloc or decl). Recent previous commits
made progress along that front.

There is a new abstraction in Sema, which looks like this:

    var anon_decl = try block.startAnonDecl();
    defer anon_decl.deinit();
    // here 'anon_decl.arena()` may be used
    const decl = try anon_decl.finish(ty, val);
    // decl is typically now used with `decl_ref`.

This pattern is used to upgrade `ref_val` usages to `decl_ref` usages.

Additional improvements:

 * Sema: fix source location resolution for calling convention
   expression.
 * Sema: properly report "unable to resolve comptime value" for loads of
   global variables. There is now a set of functions which can be
   called if the callee wants to obtain the Value even if the tag is
   `variable` (indicating comptime-known address but runtime-known value).
 * Sema: `coerce` resolves builtin types before checking equality.
 * Sema: fix `u1_type` missing from `addType`, making this type have a
   slightly more efficient representation in AIR.
 * LLVM backend: fix `genTypedValue` for tags `decl_ref` and `variable`
   to properly do an LLVMConstBitCast.
 * Remove unused parameter from `Value.toEnum`.

After this commit, some test cases are no longer passing. This is due to
the more principled approach to comptime references causing more
anonymous decls to get sent to the linker for codegen. However, in all
these cases the decls are not actually referenced by the runtime machine
code. A future commit in this branch will implement garbage collection
of decls so that unused decls do not get sent to the linker for codegen.
This will make the tests go back to passing.
2021-07-29 15:59:51 -07:00
Takeshi Yoneda
1e20a62126 WASI,libc: enable tests.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-27 09:01:00 +09:00
Jacob G-W
1799455e05 astgen: errors for shadowing in if captures 2021-07-14 18:17:55 -04:00
Jacob G-W
759d1d9aef astgen: errors for shadowing in loop captures 2021-07-14 18:03:15 -04:00
Andrew Kelley
7ef8546826
Merge pull request #9352 from g-w1/fix-9346
stage2 astgen: error for return outside of function scope
2021-07-11 15:11:28 -04:00
Jacob G-W
b0b9c3c2dc stage2: remove redundancy from error message
invalid 'try' outside function scope ->
'try' outside function scope
2021-07-11 10:03:47 -04:00
Jacob G-W
7b5d139fd3 plan9 codegen, add tests
They generate an object file, but do not execute yet,
since we don't have something to execute them with.
2021-07-09 14:20:36 -04:00
Jacob G-W
ec36ac8b21 stage2 astgen: provide 3 more errors for invalid inline assembly 2021-07-08 14:33:01 -04:00
Jacob G-W
6c11e9bb07 stage2: add error note for comparing booleans with '||' 2021-07-06 07:51:30 +03:00
Andrew Kelley
c5c23db627 tokenizer: clean up invalid token error
It now displays the byte with proper printability handling. This makes
the relevant compile error test case no longer a regression in quality
from stage1 to stage2.
2021-07-02 13:28:31 -07:00
Andrew Kelley
7a2e0d9810 AstGen: cleanups to pass more compile error test cases 2021-07-02 13:28:29 -07:00
Andrew Kelley
8ce880ca75 avoid calling into stage1 backend when AstGen fails
The motivation for this commit is that there exists source files which
produce ast-check errors, but crash stage1 or otherwise trigger stage1
bugs. Previously to this commit, Zig would run AstGen, collect the
compile errors, run stage1, report stage1 compile errors and exit if
any, and then report AstGen compile errors.

The main change in this commit is to report AstGen errors prior to
invoking stage1, and in fact if any AstGen errors occur, do not invoke
stage1 at all.

This caused most of the compile error tests to fail due to things such
as unused local variables and mismatched stage1/stage2 error messages.
It was taking a long time to update the test cases one-by-one, so I
took this opportunity to unify the stage1 and stage2 testing harness,
specifically with regards to compile errors. In this way we can start
keeping track of which tests pass for 1, 2, or both.
`zig build test-compile-errors` no longer works; it is now integrated
into `zig build test-stage2`.

This is one step closer to executing compile error tests in parallel; in
fact the ThreadPool object is already in scope.

There are some cases where the stage1 compile errors were actually
better; those are left failing in this commit, to be addressed in a
follow-up commit.

Other changes in this commit:

 * build.zig: improve support for -Dstage1 used with the test step.
 * AstGen: minor cosmetic changes to error messages.
 * stage2: add -fstage1 and -fno-stage1 flags. This now allows one to
   download a binary of the zig compiler and use the llvm backend of
   self-hosted. This was also needed for hooking up the test harness.
   However, I realized that stage1 calls exit() and also has memory
   leaks, so had to complicate the test harness by not using this flag
   after all and instead invoking as a child process.
   - These CLI flags will disappear once we start shipping the
     self-hosted compiler as the main compiler. Until then, they can be
     used to try out the work-in-progress stage2.
 * stage2: select the LLVM backend by default for release modes, as long
   as the target architecture is supported by LLVM.
 * test harness: support setting the optimize mode
2021-07-02 13:27:28 -07:00