13828 Commits

Author SHA1 Message Date
Andrew Kelley
07606d12da stage2: remove SPU Mark II backend
As it stands, the backend is incomplete, and there is no active contributor,
making it dead weight.

However, anyone is free to resurrect this backend at any time.
2021-05-15 21:25:42 -07:00
Andrew Kelley
7cd94d2123 stage2: omit Decl compile errors from failed AstGen files
Just like when new parse errors occur during an update, when new AstGen
errors occur during an update, we do not reveal compile errors for Decl
objects which are inside of a newly failed File. Once the File passes
AstGen successfully, it will be compared with the previously succeeded
ZIR and the saved Decl compile errors will be handled properly.
2021-05-15 21:20:06 -07:00
Andrew Kelley
dc036f5b6f codegen: implement const value rendering for ints <= 64 bits 2021-05-15 21:00:15 -07:00
Andrew Kelley
5769ed2d44 stage2: compile log stores node offset
Previously, compile log stored full SrcLoc info, which included absolute
AST node index. This becomes invalid after an incremental compilation.
To make it survive incremental compilation, store an offset from parent
Decl instead.
2021-05-14 23:10:38 -07:00
Andrew Kelley
b4692c9a78 stage2: improve Decl dependency management
* Do not report export collision errors until the very end, because it
   is possible, during an update, for a new export to be added before an
   old one is semantically analyzed to be deleted. In such a case there
   should be no compile error.
   - Likewise we defer emitting exports until the end when we know for
     sure what will happen.
 * Sema: Fix not adding a Decl dependency on imported files.
 * Sema: Properly add Decl dependencies for all identifier and namespace
   lookups.
 * After semantic analysis for a Decl, if it is still marked as
   `in_progress`, change it to `dependency_failure` because if the Decl
   itself failed, it would have already been changed during the call to
   add the compile error.
2021-05-14 17:41:22 -07:00
Andrew Kelley
9958652d92 stage2: update test cases to improved source locations 2021-05-14 00:08:29 -07:00
Andrew Kelley
8344a50e1c AstGen: add compile error for decl name conflicts
* Remove the ability for GenZir parent Scope to be null. Now there is a
   Top Scope at the top.
 * Introduce Scope.Namespace to contain a table of decl names in order
   to emit a compile error for name conflicts.
 * Fix use of invalid memory when reporting compile errors by
   duplicating decl names into a temporary heap allocated buffer.
 * Fix memory leak in while and for loops, not cleaning up their
   labeled_breaks and store_to_block_ptr_list arrays.
 * Fix stage2 test cases because now the source location of redundant
   comptime keyword compile errors is improved.
 * Implement compile error for local variable shadowing declaration.
2021-05-13 23:51:22 -07:00
Andrew Kelley
93896ef860 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-13 23:50:39 -07:00
Andrew Kelley
134853f106 stage2: fix tests expected values 2021-05-13 20:44:34 -07:00
Andrew Kelley
579694893e Sema: remove compile error for comptime function calls
Not sure why that was there - comptime function calls are already
implemented!
2021-05-13 20:09:25 -07:00
Andrew Kelley
2cee19ab21 CLI repl: "run" command handles cross compiled binaries
with an appropriate error message, and does not terminate the repl.
2021-05-13 20:08:35 -07:00
Andrew Kelley
a854795f52 link: fix memory leak of system_libs 2021-05-13 20:08:17 -07:00
Andrew Kelley
edab03bc22 link/MachO: fixes to debug symbols
commitDeclDebugInfo: stop trying to write length 0 debug info - avoids
hitting an error where zig tries to move the debug info section
unnecessarily, gets confused, and reports `error.InputOutput`.

The 2 pieces of code that looked at the source and tried to compute
source line offsets is now improved to match link/Elf - use the
line/column data stored in the Decl object to skip the costly scanning
of source bytes. No need to load Zig source code, AST, or tokens, when
we have the ZIR!
2021-05-13 20:05:41 -07:00
Andrew Kelley
78632894da AstGen: fix elision of store_to_block_ptr for condbr 2021-05-13 17:56:01 -07:00
Andrew Kelley
e83cf6a454 Sema: detect and skip over elided instructions
It would be better if AstGen would actually omit these instructions
rather than only marking them as elided, but that can be solved
separately.
2021-05-13 16:50:27 -07:00
Andrew Kelley
b109daacdd stage2: fix test cases to add pub on exported _start fn
This way the start code respects them.
2021-05-12 23:17:24 -07:00
Andrew Kelley
c102e13710 stage2: fix source location of Decl compile errors
In `Module.semaDecl`, the source location being used was double-relative
to the `Decl`, causing a crash when trying to compute byte offset for
the compile error.

Change the source location to node_offset = 0 since the scope being used
makes the source location relative to the Decl, which already has the
source node index populated.
2021-05-12 22:50:47 -07:00
Andrew Kelley
a7aa3ca66c stage2: build and provide libunwind when compiling for native libc
5ac91794cce8bd53916a378815be01e4365d53d9 made Zig link against the
system libc when targeting the native C ABI. However this made it stop
putting libunwind.a on the linker line when it needed to sometimes,
causing undefined symbols when linking against C++ code.
2021-05-12 22:25:20 -07:00
Andrew Kelley
344dc0cc0f stage2: fix handling of "prev successful ZIR"
Before this change, the attempt to save the most recent successful ZIR
code only worked in some cases; this reworks the code to be more robust,
thereby fixing a crash when running the stage2 "enums" CBE test cases.
2021-05-12 22:02:44 -07:00
Andrew Kelley
417b5b1daa std: fix redundant comptime keywords
caught by stage2 astgen
2021-05-12 20:44:05 -07:00
Andrew Kelley
1ab3dff846 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need the latest commit which fixes std and behavior tests for cross
compiled glibcs.
2021-05-12 20:37:40 -07:00
Andrew Kelley
799d1f0d36 build system: fix wrong glibc dir passed to qemu for i386
Without this, and with `-Denable-qemu -Denable-foreign-glibc`,
i386-linux-gnu tests failed because the `-L` path passed to qemu
was "i386-linux-gnu" (nonexistent) rather than "i686-linux-gnu".

Fixes std lib and behavior tests when using these options to enable
test coverage with cross compiled glibcs.
2021-05-12 20:34:54 -07:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Matthew Borkowski
40a47eae65 fix shrinkAndFree and remove shrinkRetainingCapacity in PriorityQueue and PriorityDequeue 2021-05-12 18:33:25 -04:00
Evan Haas
19aab5302c translate-c: Ensure extra_cflags are passed to clang
Additionally ensure that the Zig cache incorporates any extra cflags when
using translate-c.

Fixes the issue identified in #8662
2021-05-12 18:17:45 -04:00
Andrew Kelley
43da102920
Merge pull request #8698 from ifreund/scanZ
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
2021-05-12 18:15:36 -04:00
LemonBoy
893a428656 stage2: Drop LLVM's host CPU detection method as fallback
The CPU detection code is nearly at feature parity, we do support
detecting the native CPU on Sparc systems and macos, our ARM/AArch64
model list is quite comprehensive and so is our PPC one.

The only missing pieces are:
- ARM32 detection on Darwin hosts (I don't think anybody is planning on
  running the compiler on a old-ass iPhone)
- s390x detection on Linux hosts, this can be easily added at a later
  stage.
2021-05-12 14:03:59 -04:00
Jakub Konka
7b77246289 macho: allow overriding stack size in binary 2021-05-12 19:25:26 +02:00
Michael Dusan
fb8527b289 azure: bump timeout for macos-arm64 2021-05-12 06:38:01 -04:00
Isaac Freund
cd7b5a3718
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
The current spanZ() function will not scan for a 0 terminator if the
type is not 0 terminated. This encourages using 0 terminated array
types to bind C arrays which hold 0 terminated strings. However, this is
a big footgun as nothing in the C type system guarantees there to be a
0 terminator at the end of the array and if there is none this becomes
Illegal Behavior in Zig.

To solve this, deprecate spanZ() and lenZ(), adding a new sliceTo()
function that always scans for the given terminator even if the type is
not sentinel terminated.
2021-05-12 11:24:49 +02:00
Jakub Konka
53acb54fad
Bump zig-bootstrap and wasmtime versions in linux CI (#8738)
* Bump zig-bootstrap and wasmtime versions in linux CI

* Revert wasm stage2 test fixup; point to issue
2021-05-12 09:56:55 +02:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Andrew Kelley
71afc30880 stage2: more Decl lifetime fixes
* File stores `root_decl: Decl` instead of `namespace: *Namespace`.
   This maps more cleanly to the actual ownership, since the `File` does
   own the root decl, but it does not directly own the `Namespace`.
 * `semaFile` completes the creation of the `Decl` even when semantic
   analysis fails. The `analysis` field of the `Decl` will contain the
   results of semantic analysis. This prevents cleaning up of memory
   still referenced by other Decl objects.
 * `semaDecl` sets `Struct.zir_index` of the root struct decl, which
   fixes use of undefined value in case the first update contained a ZIR
   compile error.
2021-05-11 23:20:22 -07:00
Andrew Kelley
1ab1a96f87 stage2: improve Decl lifetime management
* Compilation: iteration over the deletion_set only tries to delete the
   first one, relying on Decl destroy to remove itself from the deletion
   set.
 * link: `freeDecl` now has to handle the possibility of freeing a Decl
   that was never called with `allocateDeclIndexes`.
 * `deleteDecl` recursively iterates over a Decl's Namespace sub-Decl
   objects and calls `deleteDecl` on them.
   - Prevents Decl objects from being destroyed when they are still in
     `deletion_set`.
 * Sema: fix cleanup of anonymous Decl objects when an error occurs
   during semantic analysis.
 * tests: update test cases for fully qualified names
2021-05-11 22:12:36 -07:00
Michael Dusan
30ace64fc4 bsd: detect os version
- netbsd, dragonly: use sysctlbyname
- openbsd: use sysctl
- updated default semver ranges
2021-05-11 22:05:08 -04:00
Andrew Kelley
d7567c06fd Sema: implement duplicate enum tag compile error 2021-05-11 18:56:56 -07:00
Andrew Kelley
7873e4f588 stage2: lookupIdentifier can return error.AnalysisFailed
This avoids causing false positive compile errors when, for example, a
file had ZIR errors, and then code tried to look up a public decl from
the failed file.
2021-05-11 17:44:19 -07:00
Andrew Kelley
cbbc7cc8b1 stage2: better handling of file-level compile errors across updates
* `Module.File` now retains the most recent successful ZIR in the event
   that an update causes a ZIR compile error. This way Zig does not
   throw out useful semantic analysis results when an update temporarily
   introduces a ZIR compile error.
 * Semantic analysis of a File now unconditionally creates a Decl object
   for the File. The Decl object is marked as `file_failed` in case of
   File-level compile errors. This allows detecting of the File being
   outdated, and dependency tracking just like any other Decl.
2021-05-11 17:34:13 -07:00
Andrew Kelley
e3dd4dc91d
Merge pull request #8737 from ifreund/link-system-libc
stage2: use system libc when targeting the native OS/ABI
2021-05-11 20:28:14 -04:00
Andrew Kelley
5d9fc11d18 stage2: update tests now that structs have fully qualified names 2021-05-11 14:51:54 -07:00
Andrew Kelley
a74632b50a C backend: fix emitting '$' in identifier names
This causes warnings from clang when compiled.
2021-05-11 14:51:21 -07:00
Andrew Kelley
fb39526159 AstGen: support emitting multiple compile errors 2021-05-11 14:51:08 -07:00
Andrew Kelley
bcf15e39e2 stage2: add owns_tv flag to Module.Decl
Decl objects need to know whether they are the owner of the Type/Value
associated with them, in order to decide whether to destroy the
associated Namespace, Fn, or Var when cleaning up.
2021-05-11 14:17:52 -07:00
Isaac Freund
e6881d4373
std/json: fix previous commit for std.testing changes 2021-05-11 23:09:25 +02:00
Matthew Borkowski
1b87d45494 fix a double free in parse when duplicate_field_behavior is UseLast and a leak in parse when allocating a single item 2021-05-11 22:54:02 +02:00
Isaac Freund
c036957521
std.meta.Elem: support all optional types 2021-05-11 22:22:21 +02:00
Isaac Freund
f8cf106fc9
ci: unset CC/CXX before make install on macos arm64
Having these set causes zig's native libc detection code to fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
3b2c9ef828
stage2: link all libc components if using system libc 2021-05-11 21:30:13 +02:00
Isaac Freund
01e30002c5
stage2: error if requested glibc version too high
Falling back to the max provided glibc version is insufficient as
linking to shared objects compiled against the requested version
will fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
5ac91794cc
stage2: use system libc when targeting the native OS/ABI
Currently zig will always try to build its own libc and compile against
that. This of course makes sense for cross-compilation, but can cause
problems when targeting the native OS/ABI.

For example, if the system uses a newer glibc version than zig ships
zig will fall back to using the newest version it does ship. However
this causes linking system libraries to fail as they are built against a
different glibc version than the zig code is built against.

To remedy this, simply default to linking the system libc when targeting
the native OS/ABI.
2021-05-11 21:30:07 +02:00