11295 Commits

Author SHA1 Message Date
Jacob Young
f316cb29cc x86_64: implement atomic and fence ops 2023-03-21 08:49:54 +01:00
Jacob Young
3f4569bf18 codegen: fix backend breakage due to optional layout change 2023-03-21 08:49:54 +01:00
Jacob Young
6c453dd806 x86_64: implement some slice ops 2023-03-21 08:49:54 +01:00
Jacob Young
958c8e1ce9 x86_64: implement @popCount for older processors
This fixes the behavior tests when compiled for baseline.
2023-03-21 08:49:54 +01:00
Jacob Young
f95faac5ae x86_64: (re)implement optional ops
Note that this commit also changes the layout of optional for all
other backends using `src/codegen.zig` without updating them!
2023-03-21 08:49:54 +01:00
Jacob Young
24f0900ecb x86_64: implement some error union ops 2023-03-21 08:49:54 +01:00
Jacob Young
bbd05e2d97 x86_64: improve codegen for neg and not 2023-03-21 08:49:54 +01:00
Jacob Young
80427796df x86_64: implement @returnAddress and @frameAddress 2023-03-21 08:49:54 +01:00
Jacob Young
53ec2a955e x86_64: implement clz, ctz, and popCount 2023-03-21 08:49:54 +01:00
Jacob Young
edd63f9aba x86_64: reimplement inline memcpy and memset 2023-03-21 08:49:54 +01:00
Jacob Young
c865c8fb2a x86_64: implement float division intrinsics 2023-03-21 08:49:54 +01:00
Jacob Young
b6eebb709f x86_64: fix OBO
These loops were skipping over the top stack entry, and there's already
a function that does this correctly.
2023-03-21 08:49:54 +01:00
Jacob Young
30e1daa746 x86_64: implement basic float ops 2023-03-21 08:49:54 +01:00
Jacob Young
29e6aedc95 x86_64: implement min and max as commutative binary ops 2023-03-21 08:49:54 +01:00
Jakub Konka
9a203fa789
Merge pull request #14986 from ziglang/macos-hcs
Upstream macOS hot-code swapping PoC
2023-03-19 21:22:40 +01:00
Ganesan Rajagopal
30aeb41a19 Fix linker segfault adding rpath to sharedlib
If the shared library is a relative path, dirname will return null causing a segfault. In the case I debugged, the current directory was already in RPATH so just ignoring this case seems a reasonable fix. After this fix "make" and "make test" pass for mimalloc.

Closes #13766
2023-03-19 17:42:27 +01:00
Jakub Konka
6874b29308 macho: fix 32bit build 2023-03-19 17:13:38 +01:00
Luuk de Gram
c26cbd561c
Merge pull request #14998 from Luukdegram/shared-mem
wasm-linker: Implement shared-memory
2023-03-19 15:43:06 +01:00
Luuk de Gram
322ace70f9
Merge pull request #14838 from Luukdegram/bss-fix
wasm-linker: fix storing atoms in the correct segment
2023-03-19 15:42:39 +01:00
Jakub Konka
f026939a40 macho: enable hot update state only when on compatible host 2023-03-19 09:45:05 +01:00
Jakub Konka
6f15eedff1 darwin: put posix spawn constants in POSIX_SPAWN struct 2023-03-18 21:54:05 +01:00
Jakub Konka
0aab3bda12 macho: add wrappers for attaching/detaching from HCS process 2023-03-18 21:53:46 +01:00
Jakub Konka
37192bcdcb macos: HCS PoC working 2023-03-18 21:53:36 +01:00
Jakub Konka
f1e25cf43e macho: add hot-code swapping poc 2023-03-18 21:53:26 +01:00
Jakub Konka
e35c8a2fd6 link: use std.os.ptrace wrapper on linux 2023-03-18 21:52:52 +01:00
Jakub Konka
2ac8d90df0
Merge pull request #14935 from ziglang/fix-macos-build2
link: move macOS kernel inode cache invalidation to MachO linker
2023-03-18 21:45:21 +01:00
Luuk de Gram
4e0d7154b1
wasm-linker: implement __wasm_init_memory & flag
Implements the __wasm_init_memory and __wasm_init_memory_flag synthetic
function and symbol.

The former will initialize all passive segments during runtime. For the
bss section we will fill it with zeroes, whereas the other segments
will simply be initialized only.

The latter stores the offset into the linear data section, after all
heap memory that is part of the Wasm module. Any memory initialized
at runtime starts from this offset.
2023-03-18 20:13:30 +01:00
Luuk de Gram
09d6938df9
wasm: add atomics opcodes and refactoring
This adds the atomic opcodes for the Threads proposal to the
WebAssembly specification: https://github.com/WebAssembly/threads

PrefixedOpcode has been renamed to MiscOpcode as there's multiple
types of prefixed opcodes. This naming is similar to other tools
such as LLVM. As we now use the 0xFE prefix, we moved the
function_index MIR instruction as it was occupying the same value.
This commit includes renaming all related opcodes.
2023-03-18 20:13:30 +01:00
Luuk de Gram
9fce1df4cd
wasm-linker: implement runtime TLS relocations 2023-03-18 20:13:30 +01:00
Luuk de Gram
9d13c2257d
wasm-linker: implement TLS initialization function
Implements the TLS initialization function. This is a synthetic function
created by the linker. This will only be created when shared-memory is
enabled. This function will be called during thread creation, if there's
any TLS symbols, which will initialize the TLS segment using the
bulk-memory feature.
2023-03-18 20:13:30 +01:00
Luuk de Gram
ff28c8b600
wasm-linker: create TLS symbols
Initialize TLS symbols when shared-memory is enabled. Those symbols
will be called by synthetic functions created by the linker. (TODO).
2023-03-18 20:13:30 +01:00
Luuk de Gram
00af3a79ae
wasm-linker: emit 'data count' & segment flags
When linking with shared-memory enabled, we must ensure to emit
the "data count" section as well as emit the correct segment flags
to tell the runtime/loader that each segment is passive. This is
required as we don't emit the offsets for such segments but instead
initialize each segment (for each thread) during runtime.
2023-03-18 20:13:29 +01:00
Luuk de Gram
fb9d3cd50e
wasm-linker: feature verifiction for shared-mem
When the user enables shared-memory, we must ensure the linked objects
have the 'atomics' and 'bulk-memory' features allowed.
2023-03-18 20:13:29 +01:00
Luuk de Gram
09abd53da7
wasm-linker: refactor Limits and add flags
Rather than adding the flags "on-demand" during limits writing,
we now properly parse them and store the flags within the limits
itself. This also allows us to store whether we're using shared-
memory or not. Only when the correct flag is set will we set the
max within `Limits` or else we will leave it `undefined`.
2023-03-18 20:13:29 +01:00
Luuk de Gram
b0024c4884
wasm-linker: basic TLS support
Linker now parses segments with regards to TLS segments. If the name
represents a TLS segment but does not contain the TLS flag, we set it
manually as the object file is created using an older compiler (LLVM).

For now we panic when we find a TLS relocation and implement those
later.
2023-03-18 20:13:25 +01:00
square
887abd0f33 delete --prominent-compile-errors from help 2023-03-18 20:13:52 +02:00
Jakub Konka
46171bf6c8 macho+zld: clean up how to interface with link.zig and openPath() 2023-03-18 19:05:06 +01:00
Luuk de Gram
bddf138e72
wasm-link: fix storing decls in the right segment
When a decl is `undefined` is must be stored in the data segment when
the build mode is safe. For unsafe optimize modes, it must be stored
in the bss segment instead.

For mutable decls where the atom contains all zeroes, it must always
be stored in the bss segment. All other values will result in the
atom being stored in the data segment.
2023-03-18 16:12:42 +01:00
Jakub Konka
ee705e3ac7 macho+zld: clean up opening and closing of file descriptors 2023-03-18 09:32:29 +01:00
mlugg
71e873703f Sema: make @returnAddress return 0 at comptime
See also #14938.

Resolves: #14931
2023-03-17 15:55:02 -04:00
Jacob Young
cfcd6698cd main: add debug option to dump unoptimized llvm ir 2023-03-17 01:57:14 -04:00
mlugg
4ec299007a Sema: allow dereferencing ill-defined pointers to zero-bit types at comptime
It doesn't matter if a pointer to a zero-bit (i.e. OPV) type is
undefined or runtime-known; we still know the result of the dereference
at comptime. Code may use this, for instance, when allocating zero-bit
types: `@as(*void, undefined)` is entirely reasonable to use at runtime,
since we know the pointer will never be accessed, thus it should be
valid at comptime too.
2023-03-17 01:56:36 -04:00
Jakub Konka
76afdd0586 link: move macOS kernel inode cache invalidation to MachO linker 2023-03-16 17:30:25 +01:00
InKryption
9964f1c160 Add error for bad cast from *T to *[n]T
Casting `*T` to `*[1]T` should still work, but every other length
will now be a compiler error instead of a potential OOB access.
2023-03-16 13:00:36 +02:00
Andrew Kelley
363d4a107d add compile log output to build runner 2023-03-15 10:48:15 -07:00
Andrew Kelley
bde1293093 CLI: remove the experimental --watch flag
The compiler REPL will move to an external process that communicates
with the compiler over the binary protocol.
2023-03-15 10:48:15 -07:00
Andrew Kelley
1dbb616e73 Module: handle incremental update from ZIR with AST errors 2023-03-15 10:48:15 -07:00
Andrew Kelley
ede5dcffea make the build runner and test runner talk to each other
std.Build.addTest creates a CompileStep as before, however, this kind of
step no longer actually runs the unit tests. Instead it only compiles
it, and one must additionally create a RunStep from the CompileStep in
order to actually run the tests.

RunStep gains integration with the default test runner, which now
supports the standard --listen=- argument in order to communicate over
stdin and stdout. It also reports test statistics; how many passed,
failed, and leaked, as well as directly associating the relevant stderr
with the particular test name that failed.

This separation of CompileStep and RunStep means that
`CompileStep.Kind.test_exe` is no longer needed, and therefore has been
removed in this commit.

 * build runner: show unit test statistics in build summary
 * added Step.writeManifest since many steps want to treat it as a
   warning and emit the same message if it fails.
 * RunStep: fixed error message that prints the failed command printing
   the original argv and not the adjusted argv in case an interpreter
   was used.
 * RunStep: fixed not passing the command line arguments to the
   interpreter.
 * move src/Server.zig to std.zig.Server so that the default test runner
   can use it.
 * the simpler test runner function which is used by work-in-progress
   backends now no longer prints to stderr, which is necessary in order
   for the build runner to not print the stderr as a warning message.
2023-03-15 10:48:14 -07:00
Andrew Kelley
a333bb91ff zig objcopy: support the compiler protocol
This commit extracts out server code into src/Server.zig and uses it
both in the main CLI as well as `zig objcopy`.

std.Build.ObjCopyStep now adds `--listen=-` to the CLI for `zig objcopy`
and observes the protocol for progress and other kinds of integrations.

This fixes the last two test failures of this branch when I run
`zig build test` locally.
2023-03-15 10:48:14 -07:00
Andrew Kelley
29cfd47d65 re-enable test-cases and get them all passing
Instead of using `zig test` to build a special version of the compiler
that runs all the test-cases, the zig build system is now used as much
as possible - all with the basic steps found in the standard library.

For incremental compilation tests (the ones that look like foo.0.zig,
foo.1.zig, foo.2.zig, etc.), a special version of the compiler is
compiled into a utility executable called "check-case" which checks
exactly one sequence of incremental updates in an independent
subprocess. Previously, all incremental and non-incremental test cases
were done in the same test runner process.

The compile error checking code is now simpler, but also a bit
rudimentary, and so it additionally makes sure that the actual compile
errors do not include *extra* messages, and it makes sure that the
actual compile errors output in the same order as expected. It is also
based on the "ends-with" property of each line rather than the previous
logic, which frankly I didn't want to touch with a ten-meter pole. The
compile error test cases have been updated to pass in light of these
differences.

Previously, 'error' mode with 0 compile errors was used to shoehorn in a
different kind of test-case - one that only checks if a piece of code
compiles without errors. Now there is a 'compile' mode of test-cases,
and 'error' must be only used when there are greater than 0 errors.

link test cases are updated to omit the target object format argument
when calling checkObject since that is no longer needed.

The test/stage2 directory is removed; the 2 files within are moved to be
directly in the test/ directory.
2023-03-15 10:48:14 -07:00