8537 Commits

Author SHA1 Message Date
Annika L
c992b25908 C backend: Fix array declarations 2022-04-22 07:42:47 -07:00
Jakub Konka
5c501e8dad
Merge pull request #11485 from ziglang/fix-4353 2022-04-22 06:34:06 +02:00
Andrew Kelley
9c5fe5b5a4 LLVM: C calling convention lowering fixes
For parameters and return types of functions with the C calling
convention, the LLVM backend now has a special lowering for the function
type that makes the function adhere to the C ABI. The AIR instruction
lowerings for call, ret, and ret_load are adjusted to bitcast the real
type to the ABI type if necessary.

More work on this will need to be done, however, this improvement is
enough that stage3 now passes all the same behavior tests that stage2
passes - notably, translate-c no longer has a segfault due to C ABI
issues with Zig's Clang C API wrapper.
2022-04-21 20:27:06 -07:00
Andrew Kelley
ffaa045429 stage2: add zig_backend to the cache hash
This makes stage2 and stage3 have different cache namespaces, so that
building something with stage3 does not try to reuse the same cached
artifacts as were produced by stage2. This makes sense since the code
of stage3 is produced by the self-hosted compiler, whereas the code of
stage2 is produced by the bootstrap compiler. Note also that stage4 and
stage3 will share the same zig_backend, end hence cache namespace.
Ideally stage4 and stage3 are identical binaries, so this checks out.
2022-04-21 13:29:46 -07:00
Jakub Konka
42ed34d1f6 macho: create LlvmObject in createEmpty only
Prior to this change we would also create it in `openPath`, but as
`openPath` internally calls `createEmpty` we would end up with a
memory leak.
2022-04-21 10:08:37 -04:00
Andrew Kelley
31758f79db link: Wasm: don't assume we have a zig module 2022-04-20 18:14:38 -07:00
Andrew Kelley
f7596ae942 stage2: use indexes for Decl objects
Rather than allocating Decl objects with an Allocator, we instead allocate
them with a SegmentedList. This provides four advantages:
 * Stable memory so that one thread can access a Decl object while another
   thread allocates additional Decl objects from this list.
 * It allows us to use u32 indexes to reference Decl objects rather than
   pointers, saving memory in Type, Value, and dependency sets.
 * Using integers to reference Decl objects rather than pointers makes
   serialization trivial.
 * It provides a unique integer to be used for anonymous symbol names,
   avoiding multi-threaded contention on an atomic counter.
2022-04-20 17:37:35 -07:00
Jakub Konka
26153ce73a dwarf: clean up allocations in std.dwarf module
While this code probably could do with some love and a redesign,
this commit fixes the allocations by making sure we explicitly
pass an allocator where required, and we use arenas for temporary
or narrowly-scoped objects such as a `Die` (for `Die` in particular,
not every `FormValue` will be allocated - we could duplicate, or
we can use an arena which is the proposal of this commit).
2022-04-21 00:06:52 +02:00
Joachim Schmidt
1a1b5ee264
Merge pull request #11462 from joachimschmidt557/stage2-aarch64
stage2 AArch64: truncation support
2022-04-20 09:44:43 +02:00
Andrew Kelley
0c5ad335d2 build system: add -fstage1/-fno-stage1 to zig build
So that people can start experimenting with compiling their projects
with the self-hosted compiler.

I expect this commit to be reverted after #89 is closed.
2022-04-19 14:40:27 -07:00
joachimschmidt557
fa85a739d9
stage2 AArch64: fix shl, shr, shl_exact, shr_exact
Introduces the necessary truncation after shift
2022-04-19 22:40:51 +02:00
joachimschmidt557
cbb13c023e
stage2 AArch64: change binOp lowering mechanism to use Mir tags
Mirrors e2e69803dc16efe11a6d42c6c49853e16a41fd0c for AArch64
2022-04-19 22:40:50 +02:00
joachimschmidt557
0a909a6712
stage2 AArch64: implement addwrap, subwrap, mulwrap 2022-04-19 22:40:50 +02:00
joachimschmidt557
d9d9fea6ae
stage2 AArch64: Add ldrsb, ldrsh instructions 2022-04-19 22:40:48 +02:00
joachimschmidt557
f95a8ddafa
stage2 AArch64: Implement basic truncate functionality 2022-04-19 22:39:14 +02:00
joachimschmidt557
c78daeb642
stage2 AArch64: add basic assertions to bits.zig for correct codegen
Includes many fixes of errors discovered by adding these assertions
2022-04-19 22:37:56 +02:00
Andrew Kelley
9c2cbe39c2
Merge pull request #11461 from Luukdegram/wasm-debug-info
Wasm: add support for debug information
2022-04-19 14:12:13 -04:00
Luuk de Gram
be08d2bdbd
wasm: Fix unreachable paths
When the last instruction is a debug instruction, the type of it is void.
Similarly for 'noreturn' emit an 'unreachable' instruction to tell the wasm-validator
the path cannot be reached.

Also respect the '--strip' flag in the self-hosted wasm linker and not emit a 'name' section
when the flag is set to `true`.
2022-04-19 19:58:49 +02:00
Andrew Kelley
78f26b970e
Merge pull request #11469 from topolarity/wasm-fixup
stage2: Move `selfExePathWasi` to `introspect.zig`
2022-04-19 13:30:15 -04:00
Andrew Kelley
535d5624e4 wasm: fix lowerDeclRefValue using wrong Decl 2022-04-19 13:04:59 -04:00
Cody Tapscott
f8dc6fc416 stage2: Only bypass flock on WASI 2022-04-18 23:08:00 -07:00
Cody Tapscott
bb9cd6db1c stage2: Move WASI/Zig-specific selfExePath to introspect.zig 2022-04-18 23:06:49 -07:00
Andrew Kelley
edb4a07d4d Sema: fix not reserving enough memory for comptime shl 2022-04-18 16:41:54 -07:00
Andrew Kelley
c9858f833c stage2: fix building stage3 in release mode
Previously, comptime function calls could cause a crash in the hash
function due to a lazy value depending on an unresolved type.
2022-04-18 16:41:54 -07:00
Andrew Kelley
b75d86027d stage2: avoid binary bloat from GeneralPurposeAllocator
In the case of not using it.
2022-04-18 16:41:54 -07:00
Jakub Konka
b03345f32a
Merge pull request #11024 from topolarity/wasi-stage2
stage2: Add limited WASI support for selfExePath and globalCacheDir
2022-04-18 23:53:41 +02:00
Jakub Konka
5195b87639
Merge pull request #11396 from wojtekmach/wm-zig-cc-subsystem
zig cc: support --subsystem linker flag
2022-04-18 19:20:23 +02:00
Cody Tapscott
692ccd01b4 stage2: Initialize WASI preopens on startup 2022-04-18 10:20:20 -07:00
Cody Tapscott
089651716c stage2: Bypass file locks in src/Cache.zig for WASI targets 2022-04-18 10:20:15 -07:00
Cody Tapscott
922d8378e7 stage2: Add limited WASI support for selfExePath and globalCacheDir
This change adds support for locating the Zig executable and the library
and global cache directories, based on looking in the fixed "/zig" and
"/cache" directories.

Since our argv[0] on WASI is just the basename (any absolute/relative
path information is deleted by the runtime), there's very limited
introspection we can do on WASI, so we rely on these fixed directories.
These can be provided on the command-line using `--mapdir`, as follows:

```
wasmtime --mapdir=/cwd::. --mapdir=/cache::"$HOME/.cache/zig" --mapdir=/zig::./zig-out/ ./zig-out/bin/zig.wasm
```
2022-04-18 10:19:34 -07:00
Luuk de Gram
2193f7c4a2
wasm: Add support for debug info
This implements basic DWARF output when building for the wasm target.
Stacktraces, however, are currently not supported.
2022-04-18 13:11:37 +02:00
Wojtek Mach
b2344cc18e Support --subsystem=x instead of --subsystem,x 2022-04-18 11:43:17 +02:00
Andrew Kelley
a7c05c06be stage2: expose progress bar API to linker backends
This gives us insight as to what is happening when we are waiting for
things such as LLVM emit object and LLD linking.
2022-04-17 04:09:35 -07:00
Jakub Konka
8f75823728
Merge pull request #11446 from ziglang/aarch64-macos-llvm
stage2: fix behavior test failures on aarch64-macos (LLVM+native), and other minor fixes
2022-04-16 18:07:02 +02:00
Jakub Konka
897df18573 stage2: fix @mulAdd on aarch64 Darwin
According to Apple docs, the long double type is a double precision
IEEE754 binary floating-point type, which makes it identical to the
double type. This behavior contrasts to the standard specification,
in which a long double is a quad-precision, IEEE754 binary,
floating-point type.

Thus, we need to take this into account when using the compiler
intrinsics so that we select the correct function version for
FloatMulAdd.
2022-04-16 12:23:47 +02:00
Jakub Konka
88d87d6506 stage2,macho: swap out inodes before checking for intermediary basename
This way we avoid the infamous SIGKILL on arm64 macos.
2022-04-16 12:06:58 +02:00
Andrew Kelley
578a792b33
Merge pull request #11442 from Vexu/stage3
Make self hosted compiler capable of building itself
2022-04-16 05:42:25 -04:00
joachimschmidt557
3bfb1616db stage2 ARM: move genArgDbgInfo back to CodeGen
This removes the questionable Air -> Mir dependency that existed
before. The x86_64 backend also performed this change.
2022-04-16 09:41:27 +02:00
Veikka Tuominen
101aac92c2 stage2: fix bugs preventing stage2 from building stage3 with LLVM 2022-04-15 23:32:26 +03:00
Veikka Tuominen
1c4c826a50 AstGen: fix defer generation in breakExpr 2022-04-15 22:33:07 +03:00
Veikka Tuominen
7be62f695f stage2 llvm: fix optional pointers to zero bit payloads 2022-04-15 19:17:50 +03:00
Andrew Kelley
4c83b11f71
Merge pull request #11438 from Vexu/stage2-fixes
Stage2 fixes
2022-04-15 12:02:55 -04:00
Jakub Konka
52c8ac1a84 stage2: lower u128, and refactor some bits in x64 2022-04-15 11:50:08 -04:00
Veikka Tuominen
dbe0d3d579 stage2 llvm: handle dollar signs in asm template 2022-04-15 16:16:22 +03:00
Veikka Tuominen
ef7282bab4 stage2 macho: workaround stage2 bugs 2022-04-15 16:05:27 +03:00
Veikka Tuominen
3723eb7f31
Merge pull request #11242 from schmee/sema-handle-more-union-errors
stage2: add more union compile errors / improve error messages
2022-04-15 11:34:04 +03:00
Veikka Tuominen
6ad510d832 update self hosted sources to language changes 2022-04-15 11:17:19 +03:00
Veikka Tuominen
4911d39769 AstGen: handle rl_ty_inst for mutable variables 2022-04-15 11:17:06 +03:00
Veikka Tuominen
4ef1c1c705 Sema: allow fieldType on optionals and error unions 2022-04-15 10:24:18 +03:00
Luuk de Gram
d66c61a2cf wasm-linker: Prevent overalignment for segments
Previously, the data segments were being aligned twice.
This caused us to overalign the segment and therefore allocate a much larger
size for each segment than was required. This fix ensures we align and set the size
just once, ensuring semantically correct binaries as well as smaller binaries.
2022-04-14 22:53:13 +02:00