Commit graph

627 commits

Author SHA1 Message Date
Andrew Kelley
d979dd9b58 stage2: improve AstGen FileNotFound error message
Partially addresses #9203. It fixes the first case, but not the second
one mentioned in the issue.
2021-07-02 15:27:00 -07:00
Andrew Kelley
5103053977 compile errors test harness: support unknown file/line/column
This gets us 2 more passing compile error test cases.
2021-07-02 13:28:31 -07: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
abfee12735 AstGen: pass more compile error tests
* Implement "initializing array with struct syntax"
 * Implement "'_' used as an identifier without @\"_\" syntax"
 * Fix source location of "missing parameter name"
 * Update test cases where appropriate
2021-07-02 13:27:35 -07:00
Andrew Kelley
24c432608f stage2: improve compile errors from tokenizer
In order to not regress the quality of compile errors, some improvements
had to be made.

 * std.zig.parseCharLiteral is improved to return more detailed parse
   failure information.
 * tokenizer is improved to handle null bytes in the middle of strings,
   character literals, and line comments.
 * validating how many unicode escape digits in string literals is moved
   to std.zig.parseStringLiteral rather than handled in the tokenizer.
 * when a tokenizer error occurs, if the reported token is the 'invalid'
   tag, an error note is added to point to the invalid byte location.
   Further improvements would be:
   - Mention the expected set of allowed bytes at this location.
   - Display the invalid byte (if printable, print it, otherwise
     escape-print it).
2021-07-02 13:27:35 -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
Andrew Kelley
7f5560689a AstGen: introduce 'reachableExpr' function
This function can be swapped out for calls to expr() to report a compile
error when the expression results in control flow that does not return.
2021-07-02 13:26:50 -07:00
Andrew Kelley
cffa22a658 AstGen: implement compile error for useless locals
When a local variable has an initialization expression of type
'noreturn', emit a compile error. This brings this branch closer
to parity with master branch.
2021-07-02 13:26:50 -07:00
Andrew Kelley
125b85d737 move "unreachable code" error from stage1 to stage2
* AstGen: implement "unreachable code" error for blocks. This works at
   the statement level.
 * stage1: remove the "unreachable code" error implementation, which
   means removing the `is_gen` field from IrInstSrc. This is one small
   step towards a smaller memory footprint for stage1. The benefits
   won't be realized until a future commit because this flag took
   advantage of padding.

There may be a regression here with "union has no associated enum"
error, and there is a regression with the following code:

```zig
const a = noreturn;
```

A future commit will address these regressions.
2021-07-02 13:26:50 -07:00
Jonathan Marler
0134cb0214 nice error for unsupported async sockets on Windows 2021-06-23 12:54:20 +03:00
Jarred Sumner
540b52931a Improve error message when std.fmt.format is missing arguments
Use fmt in fmt so the number in the error message is fmt'd
2021-06-13 10:33:49 +03:00
Exonorid
f63338195d Renamed @byteOffsetOf to @offsetOf 2021-06-12 19:16:01 +03:00
Matthew Borkowski
9ac6d28614 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 20:58:30 +03:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
8cfa231104 update langref, compile-error tests, safety tests
for the std.builtin re-arranging
2021-05-17 15:25:27 -07:00
Veikka Tuominen
0a38f61d58 update usage of std.testing in behavior and standalone tests 2021-05-08 15:15:30 +03:00
LemonBoy
82f1d592fa stage1: Use correct alignment for asyncCall frame 2021-04-25 20:41:49 +02:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Mathieu Guay-Paquet
93f8110e5d Allow async in nosuspend scope
Starting an async function call is actually a synchronous operation,
since the caller is not awaiting on the callee for a return value.

This commit removes the compiler code which generates the error and
updates the relevant test case.

In the presence of CallModifierAsync, the callee is expected to
suspend, so it should not be changed to CallModifierNoSuspend.
2021-02-16 23:43:36 -05:00
Mathieu Guay-Paquet
c0cfbe98f3 Allow resume in nosuspend scope
Resuming a suspended async function call is actually a synchronous
operation.

This commit removes the compiler code which generates the error and
updates the relevant test case.
2021-02-16 21:51:19 -05:00
Tadeo Kondrak
5dfe0e7e8f
Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
Tadeo Kondrak
0b5f3c2ef9
Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
Michael Dusan
f9b85c6e50 stage1: add error for slice.len incr beyond bounds
comptime direct slice.len increment dodges bounds checking but
we can emit an error for it, at least in the simple case.

- promote original assert to compile-error
- add test case

closes #7810
2021-01-30 11:19:25 +02:00
Andrew Kelley
025f1559a0
Merge pull request #7200 from Vexu/arr
Type coercion for pointers to anon literals
2021-01-11 16:09:28 -08:00
LemonBoy
fffb0904f8 stage1: Prevent crash with some lazy pointer types
Make sure the child element is not undefined, let's catch this problem
early on.

Closes #7568
2020-12-28 15:27:31 +02:00
Vexu
0bc82a9070
stage1: validate pointer attributes when coercing anon literals 2020-12-25 14:58:13 +02:00
Vexu
286077fec8 stage1: add missing error check on inferred struct field ptr 2020-12-21 12:40:51 +02:00
LemonBoy
8ac711596d stage1: Validate the specified cc for lazy fn types
Closes #7337
2020-12-08 19:09:25 -05:00
Andrew Kelley
afaef36194 stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:07:13 -07:00
Veikka Tuominen
cf819b95fe
Merge pull request #6829 from tadeokondrak/error-unsupported-callconv
stage1: Compile error instead of falling back to C for unsupported cc
2020-11-19 19:03:08 +02:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Vexu
3a28b659bd
add compile-error tests for unsupported calling convention 2020-11-19 14:25:46 +02:00
pfg
cf7de64f1a stage1: improve error for missing a number type on a runtime var 2020-11-18 21:45:51 +02:00
frmdstryr
a39d3155b4 Change error when runtime value passed to comptime arg 2020-11-18 13:33:45 +02:00
LemonBoy
129ccad434 stage1: Reject undefined values when taking union ptr
The code rightfully assumes the union_val object to be fully initialized.

Closes #7019
2020-11-18 13:21:36 +02:00
Vexu
08270d72b4 ensure TypeInfo payload is not undefined 2020-11-11 16:04:46 +02:00
LemonBoy
78840c4ab2 stage1: Make sure union(enum(T)) is valid
The T type should be wide enough to fit values in the  0...num field
range.

Closes #6988
2020-11-05 17:24:04 -05:00
Travis
bb6e39e274 remove extra space in .** error message 2020-10-30 21:26:05 +02:00
Veikka Tuominen
80dd432137
Merge pull request #6858 from travv0/no-star-after-dot-star
don't allow a token starting with an asterisk directly following .*
2020-10-30 16:08:04 +02:00
LemonBoy
490cafe2c5 stage1: Error out when trying to execute unreachable
Closes #6802
2020-10-29 20:06:52 -04:00
Travis
960b5b518f updated zig tokenizer to handle .*** and added tests 2020-10-29 12:03:45 -05:00
Andrew Kelley
e6ac082437
Merge pull request #6744 from LemonBoy/intcast-vec
stage1: Implement `@intCast` between vectors
2020-10-22 17:36:18 -04:00
LemonBoy
2f465761bb stage1: Implement @intCast between vectors
Explicit and implicit integer casts on vector types are now supported
and follow the same rules as their scalar counterparts.

Implicit float casts are accidentally supported, `@floatCast` is still
not vector-aware.
2020-10-19 20:05:09 +02:00
LemonBoy
2a256d5ea0 stage1: Fix type-checking of unary neg for vector types
Validate the vector element type as done for the scalar case.

Fixes #6708
2020-10-17 21:08:39 -04:00
LemonBoy
2a62d4b20b stage1: Expand undefined struct/arrays when indexed
Fixes #6693
2020-10-16 17:13:38 +03:00
Tadeo Kondrak
0e57f220fb stage1: Disallow arrays in function parameters or return types
Closes #6535.
2020-10-08 04:17:32 -04:00
Andrew Kelley
95a37373e9
Merge pull request #6421 from tadeokondrak/opaque-syntax
Add opaque syntax that allows declarations
2020-10-07 16:58:50 -04:00
pfg
ae161863db stage1: improve error messages for missing try statements 2020-10-07 03:50:11 -04:00
Tadeo Kondrak
bf4bfe54ac
Update compile error test for field access of opaque type 2020-10-06 22:08:30 -06:00