Commit Graph

14506 Commits

Author SHA1 Message Date
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
22b20f20b6 AstGen: fix missing compile error for unreachable @TypeOf argument 2021-07-02 13:26:50 -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
527c55aa56 stage1: get rid of the is_noreturn flag on IrInstSrc
One more step towards lowering the memory footprint of stage1. This flag
was hiding in padding but now that it is gone we can re-arrange the
memory layout more easily.
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
J.C. Moyer
d84b386f60 stage2: print valid filename in error messages 2021-07-02 14:08:52 -04:00
Veikka Tuominen
7140bb64e1 stage2: fix @asyncCall parameter count
Closes #9269
2021-07-01 22:39:26 +03:00
LemonBoy
1fc877fd94 std: Catch and handle overflow in json parser
When a floating-point value with no fractional part is shoved into an
integer type we must check whether it fits or not before calling
`@floatToInt` as the builtin panics in case of overflow.

Catch the error and bubble it up to the caller.
2021-07-01 22:35:19 +03:00
Christopher Smyth
628f490c59
Add context to fatal OpenErrors
Now it also outputs what directory it attempted to open.
2021-07-01 22:24:18 +03:00
Andrew Kelley
acf2e8fe64 fix start code for WebAssembly 2021-06-30 18:39:04 -07:00
Takeshi Yoneda
d606811f55 Fix test cases for stage2.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-30 20:35:17 -04:00
Takeshi Yoneda
bc7761d8e0
Add support for WASI reactor in pure Zig-exe. (#9178)
* Add command line help for "-mexec-model"
* Define WasmExecModel enum in std.builtin.
* Drop the support for the old crt1.o in favor of crt1-command.o

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-30 20:02:48 -04:00
Jakub Konka
a95ba0d10d
Merge pull request #9254 from moosichu/feature/macos-link-universal-static-libs
Add fat/universal archive support to zig ld
2021-06-30 10:22:49 +02:00
Nameless
908b431abe std/os/uefi: fix packed struct bitfields 2021-06-30 09:28:08 +03:00
Sreehari Sreedev
b8329351b1 boot_services: allow custom MemoryTypes 2021-06-30 09:26:09 +03:00
Jakub Konka
81bf05bf6c
Merge pull request #9266 from ziglang/zld-dylibs
zig ld can create dylibs now; remove system linker hack and any mention of ld64.lld from the codebase
2021-06-30 00:03:55 +02:00
Jakub Konka
0e15205521 Remove mention of lldMachO from the project
including:
* finding lldMachO in CMake config
* punting `ld64.lld` to LLD linker
* providing bindings to LLD linker
2021-06-29 23:38:19 +02:00
Andrew Kelley
37fbf5b0d3
Merge pull request #9258 from ziglang/shared-cache-locking
Shared Cache Locking
2021-06-29 17:29:59 -04:00
Andrew Kelley
e32530b6a3 std.fs.File: update doc comments regarding locking
Update to accomodate the differences in Windows, which is now advisory
file locking, and include details about which operating systems have
atomic locking flags.
2021-06-29 14:25:04 -07:00
Andrew Kelley
06129d7e3d std: implement a cross platform file locking abstraction
This modifies the lock semantics from using AccessMode to using
NtLockFile/NtUnlockFile.

This is a breaking change.
2021-06-29 14:25:04 -07:00
Andrew Kelley
488f68069b implement std.fs.File.setLock for Windows 2021-06-29 14:25:04 -07:00
Andrew Kelley
3d7ae63c6f stage2: remove c_object_cache_digest_set
This logic was a workaround to prevent cache deadlocks which happened
from always using exclusive file locks. Now that the Cache system
supports sharing cached artifacts, this workaround is no longer needed.

Closes #7596
2021-06-29 14:25:04 -07:00
Andrew Kelley
4e61af404e stage2: Cache system handles shared objects
Fixes #9139
Fixes #9187
2021-06-29 14:25:04 -07:00
Andrew Kelley
6ba6b98b72 std add fs.File.setLock
Windows implementation is still missing.
2021-06-29 14:25:04 -07:00
Tom Maenan Read Cutting
186577225f Add fat/universal archive support to zig ld
This is an extension of adding fat dylib support to zig ld, pulling out
the functionality needed to support fat headers & offsets and applying
it to zig archives.

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2021-06-29 18:42:57 +01:00
Jakub Konka
8211cef77c zld: we can now create basic dylibs targeting macOS! 2021-06-29 17:46:23 +02:00
Jakub Konka
069fcf1c95 zld: put all global symbols in the export trie
* sort the symbols by name to optimise the export trie first
* insert only symbols with global linkage (private exts or weak should
  not make the cut)
2021-06-29 11:21:44 +02:00
Jakub Konka
75a13a456b zld: remove system linker hack and lld hooks 2021-06-29 07:59:46 +02:00
Jakub Konka
2c385e58f9
Merge pull request #9242 from ziglang/zld-link-system-libsystem-when-native
zld: link against system libSystem when available
2021-06-28 21:06:12 +02:00
Jakub Konka
9b5a463111 zld: if libSystem.dylib found, then need to link libc.dylib too 2021-06-28 17:42:59 +02:00
Jakub Konka
eca12b74b8 zld: recurse dylibs reexports when defined and desired 2021-06-28 15:14:50 +02:00
Jakub Konka
5aff1d5d6f zld: frameworks do not need dylib ext on older macs 2021-06-28 12:17:26 +02:00
Andrew Kelley
6d47b4f39e Revert "Include package root dir in stage2 error messages"
This reverts commit 15a030ef3d.

ast-check started crashing after this commit. Needs more QA before
merging.
2021-06-27 17:30:29 -07:00
J.C. Moyer
15a030ef3d Include package root dir in stage2 error messages 2021-06-27 14:53:46 +03:00
Isaac Freund
f398ac3ee4 std/fmt: add fmtDurationSigned
When working with durations it often makes sense to use signed integers
and allow negative durations, and there is currently no nice way to
format these in std.fmt. This patch adds a simple wrapper for the
existing fmtDurtion to fit this need.
2021-06-27 12:54:31 +03:00
g-w1
ef56e42a2a
stage2: fix unreachable in union(enum) with anytype payload 2021-06-27 12:26:29 +03:00
Evan Haas
3be682bac9
translate-c: Add documentation for zig translate-c 2021-06-27 12:25:32 +03:00
Jakub Konka
b94787afd7 zld: link against system libSystem.tbd
when native OS _and_ `libSystem.tbd` can be found. Otherwise,
fallback to linking against Zig-provided `lib/libc/darwin/libSystem.B.tbd`.
2021-06-26 10:11:39 +02:00
Emil Lerch
2ac769eab9 allow json scientific notation to coerce to integers as long as they actually resolve to int type 2021-06-26 10:10:36 +03:00
Robin Voetter
dacc5e624e Export isValidId, remove pub on unexported functions 2021-06-26 09:59:40 +03:00
Andrew Kelley
1534cd2f88
Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-06-25 21:42:18 -04:00
Jakub Konka
7a85dc6935
Merge pull request #9202 from ifreund/sysroot
stage2: add --sysroot link option
2021-06-25 22:37:46 +02:00
Andrew Kelley
73f77f3080 AstGen: fix O(N^2) perf for many decls with same parent
AstGen was calling findLineColumn() for every sibling Decl, using the
parent Decl as the starting point for the search for newlines. This
resulted in poor performance for large numbers of Decls with the same
parent.

The solution is simple: since AstGen progresses monotonically through
the AST, keep a single cursor into the source file, and whenever
line/column information is needed, advance the cursor. This guarantees
O(N) on the number of bytes in the file.

Perf:
As an example I ran ast-check on zigwin32/win32/everything.zig
(a 17 MiB file) in master branch, and after this commit.
With master branch, I killed the process after 17 seconds out of
boredom. With this commit, it completed in 300 milliseconds.

Closes #9234
2021-06-25 12:58:21 -07:00
Jakub Konka
49b3986417 zld: fix section mapping for Go specific sections
which include:
* `__TEXT,__rodata` => `__DATA_CONST,__const`
* `__TEXT,__typelink` => `__DATA_CONST,__const`
* `__TEXT,__itablink` => `__DATA_CONST,__const`
* `__TEXT,__gosymtab` => `__DATA_CONST,__const`
* `__TEXT,__gopclntab` => `__DATA_CONST,__const`

Also, we treat section as containing machine code and mapping
it to `__TEXT,__text` if it is `S_REGULAR` and contains either
`S_ATTR_PURE_INSTRUCTIONS` or `S_ATTR_SOME_INSTRUCTIONS` or both.
2021-06-25 20:32:58 +02:00
Isaac Freund
f9171bf542
std/build: add --sysroot general option 2021-06-25 19:13:43 +02:00
Isaac Freund
260c5aed86
stage2: add --sysroot link option
This feature is necessary for cross-compiling code that dynamically
links system libraries, at least with the current feature set of lld.
2021-06-25 19:13:43 +02:00
xackus
411f9c60b1 mark tsan as linguist-vendored 2021-06-25 12:46:23 +03:00
Tom Maenan Read Cutting
177b1b6bf9 Add fat/universal dylib support to zig ld
With this change zig ld can link with dynamic libraries
contained within a fat/universal file that had multiple
seperate binaries embedded within it for multi-arch
support (in macOS).

Whilst zig can still only create single-architecture
executables - the ability to link with fat libraries is
useful for cases where they are the easiest (or only)
option to link against.
2021-06-25 08:38:47 +02:00
Jacob G-W
2d2a6ed1a4 stage2: implement @setRuntimeSafety 2021-06-25 08:57:03 +03:00