16373 Commits

Author SHA1 Message Date
Jakub Konka
f4aa276a0c stage2: fix inline memcpy 2022-01-06 09:54:33 +01:00
Jakub Konka
f01e6eec56 stage2: implement slice_ptr 2022-01-06 09:54:33 +01:00
Jakub Konka
2b77775cbb stage2: fix loading pointer value from register
Fix accessing optional payload.
2022-01-06 09:54:33 +01:00
Jakub Konka
b3f70db438 stage2: implement CMP stack value with immediate 2022-01-06 09:54:33 +01:00
Andrew Kelley
1d55e4cae1 zig fmt 2022-01-06 01:18:54 -07:00
Andrew Kelley
8c6175c134 Sema: const inferred alloc infers comptime-ness
const locals now detect if the value ends up being comptime known. In
such case, it replaces the runtime AIR instructions with a decl_ref
const.

In the backends, some more sophisticated logic for marking decls as
alive was needed to prevent Decls incorrectly being garbage collected
that were indirectly referenced in such manner.
2022-01-06 00:52:10 -07:00
Andrew Kelley
713d2a9b38 Sema: better code generated for struct literals
Add a variant of the `validate_struct_init` ZIR instruction:
`validate_struct_init_comptime` which is the same thing except it
indicates a comptime scope.

Sema code for this instruction now handles default struct field
values and detects when the struct initialization resulted in a
comptime value, replacing the already-emitted AIR instructions
to store each individual field with a single `store` instruction
with a comptime struct value as the operand.

In the case of a comptime scope, there is a simpler path that only
evals the implicit store instructions for default field values, avoiding
the mechanism for detecting comptime values.

This regressed one test case for the wasm backend, but it's just hitting
a different prong of `emitConstant` which currently has "TODO" in there,
so I think it's fine.
2022-01-04 23:49:49 -07:00
Andrew Kelley
4bc6b4925c std.builtin: remove deprecated globals 2022-01-04 18:28:42 -07:00
Andrew Kelley
1c24ef0d0b stage2: introduce std.builtin.CompilerBackend
This allows Zig code to perform conditional compilation based on a tag
by which a Zig compiler implementation identifies itself.

See the doc comment in this commit for more details.
2022-01-04 18:12:45 -07:00
Andrew Kelley
5087ec6f41
Merge pull request #10508 from Luukdegram/wasm-behavior-tests
Stage2: wasm - Pass more behavior tests
2022-01-04 14:54:50 -05:00
Luuk de Gram
89b1fdc443
wasm: Implement memset, and sret arguments.
We now detect if the return type will be set by passing the first argument
as a pointer to stack memory from the callee's frame. This way, we do not have to
worry about stack memory being overwritten.

Besides this, we implement memset by either using wasm's memory.fill instruction when available,
or lower it manually. In the future we can lower this to a compiler_rt call.
2022-01-04 17:59:05 +01:00
Luuk de Gram
5c21a45cf0
wasm: Implement 'slice' instruction
Emitting undefined ptr's also has been implemented.
This means we now pass the void.zig behavior tests.
2022-01-04 17:51:49 +01:00
Luuk de Gram
c888485f85
wasm: Fix lowering constant struct values to the stack
We now get the null.zig, this.zig and member_func.zig behavior tests passing.
2022-01-04 17:51:24 +01:00
Luuk de Gram
c519d9c80e
wasm: Implement (and fix) most optional instructions
Previously we were performing the wrapping and unwrapping operations incorrectly.
We now correctly create the type and set its values.
Besides this, we also set the null-byte to the incorrect value, which meant we were
doing the opposite action of a is_null check. This is now fixed as well.

While implementing this, I found a small bug in the wrapErrUnionPayload where we
would load a pointer value and save that, rather than store the pointer with the error.
This is now fixed as well, by copying the entire operand into the payload of the error union.
2022-01-04 17:46:58 +01:00
Andrew Kelley
5c228765f1
Merge pull request #10504 from ziglang/linker-plumbing
linker: fix build-obj and -fno-emit-bin
2022-01-04 04:54:30 -05:00
Ryan Liptak
3c87d4e14e Add CANNOT_DELETE as a possible error in os.windows.DeleteFile
Can happen when e.g. trying to delete a file with the Read Only flag set
2022-01-04 02:15:29 -05:00
Andrew Kelley
5b0be0d436
Merge pull request #10499 from paulsnar/paulsnar/stage1-packed-structs-cabi
stage1: Fix LLVM C ABI type resolution for small packed structs
2022-01-04 02:14:29 -05:00
Vincent Rischmann
6630a5ede5 io_uring: improve IO_Uring.copy_cqe
copy_cqes() is not guaranteed to return as many CQEs as provided in the
`wait_nr` argument, meaning the assert in `copy_cqe` can trigger.

Instead, loop until we do get at least one CQE returned.

This mimics the behaviour of liburing's _io_uring_get_cqe.
2022-01-04 02:13:41 -05:00
Andrew Kelley
b6d6152e65 link: avoid creating stage2 llvm module when using stage1 2022-01-04 00:11:45 -07:00
Andrew Kelley
76fd6fc365
Merge pull request #10503 from ziglang/stage2-x86_64-zig-test
stage2: enable "zig test" on x86_64
2022-01-04 01:53:02 -05:00
Andrew Kelley
ff66a18555 linker: fix build-obj and -fno-emit-bin
This commit fixes two problems:

* `zig build-obj` regressed from the cache-mode branch. It would crash
  because it assumed that dirname on the emit bin path would not be
  null. This assumption was invalid when outputting to the current
  working directory - a pretty common use case for `zig build-obj`.

* When using the LLVM backend, `-fno-emit-bin` combined with any other
  kind of emitting, such as `-femit-asm`, emitted nothing.

Both issues are now fixed.
2022-01-03 20:03:22 -07:00
Jakub Konka
a8ff51b092 stage2: turn several panics into codegen errors
Add x86_64 backend to behavior.zig test suite.
2022-01-04 02:06:18 +01:00
Andrew Kelley
4e38b3ed9b readme: dynamic logo light/dark 2022-01-03 17:45:09 -07:00
Jakub Konka
aad20ce92c stage2: pass empty zig test 2022-01-04 01:21:24 +01:00
Jakub Konka
47ed87dab8 stage2: implement struct_field_val and struct_field_val_ptr
Handle function pointers in airCall
2022-01-04 01:21:24 +01:00
Jakub Konka
384b19716d stage2: implement inline memcpy 2022-01-04 01:21:24 +01:00
Jakub Konka
d288f202a4 stage2: implement slice_elem_val 2022-01-04 01:21:24 +01:00
Jakub Konka
e9f069f536 stage2: implement isErr/isNonErr and unwrap error 2022-01-04 01:21:24 +01:00
Jakub Konka
818672312f stage2: implement setting stack from memory value 2022-01-04 01:21:23 +01:00
Jakub Konka
5851e81284 stage2: clean up load function 2022-01-04 01:21:23 +01:00
Jakub Konka
3f7b09bd35 stage2: re-implement arithmetic ops with SIB 2022-01-04 01:21:23 +01:00
Jakub Konka
f37598c779 stage2: clean up encoding of memory operands 2022-01-04 01:21:23 +01:00
Jakub Konka
978de70381 stage2: add helper for encoding imm32 based on target size 2022-01-04 01:21:23 +01:00
Jakub Konka
7a8a630bb2 stage2: dedup DS/RIP encoding for memory operand in Isel 2022-01-04 01:21:23 +01:00
Jakub Konka
8628bb780f stage2: use Encoder.prefix16BitMode() helper to encode 0x66 prefix 2022-01-04 01:21:23 +01:00
Jakub Konka
09bfc122fa stage2: dedup encoding memory op with base register in Isel 2022-01-04 01:21:23 +01:00
Jakub Konka
4590820c4c stage2: implement slice_len for slices on the stack 2022-01-04 01:21:23 +01:00
Jakub Konka
aeff635863 stage2: fix loading ptr into register 2022-01-04 01:21:23 +01:00
Andrew Kelley
81fa31c054
Merge pull request #10451 from ziglang/cache-mode
stage2: introduce CacheMode
2022-01-03 16:50:29 -05:00
Andrew Kelley
d94303be2b stage2: introduce renameTmpIntoCache into the linker API
Doc comments reproduced here:

This function is called by the frontend before flush(). It communicates that
`options.bin_file.emit` directory needs to be renamed from
`[zig-cache]/tmp/[random]` to `[zig-cache]/o/[digest]`.
The frontend would like to simply perform a file system rename, however,
some linker backends care about the file paths of the objects they are linking.
So this function call tells linker backends to rename the paths of object files
to observe the new directory path.
Linker backends which do not have this requirement can fall back to the simple
implementation at the bottom of this function.
This function is only called when CacheMode is `whole`.

This solves stack trace regressions on Windows and macOS because the
linker backends do not observe object file paths until flush().
2022-01-03 14:49:35 -07:00
paulsnar
0736d30774
stage1: Add tests for packed structs in C ABI 2022-01-03 21:25:48 +02:00
paulsnar
822c3a4819
stage1: Resolve LLVM C ABI type for small packed structs
Small packed structs weren't included in this resolution so their
c_abi_type would be NULL when attempting usage later, leading to a
compiler crash.

Resolves #10431.
2022-01-03 21:23:50 +02:00
Andrew Kelley
850b053ea6
Merge pull request #10492 from Snektron/stage2-some-stuff
stage 2 stuff
2022-01-03 05:20:08 -05:00
Andrew Kelley
663ffa5a7a stage2: fix missing items from whole cache mode hash
Without this, Zig would re-use a compiler-rt built with stage2 when one
built by stage1 was needed.
2022-01-02 18:54:47 -07:00
Robin Voetter
67449b659d stage2: move some more tests 2022-01-03 02:09:54 +01:00
Andrew Kelley
5e086b2b4c compiler-rt: small refactor in atomics 2022-01-02 17:58:54 -07:00
Andrew Kelley
d3f87f8ac0 std.fs.rename: fix Windows implementation
The semantics of this function are that it moves both files and
directories. Previously we had this `is_dir` boolean field of
`std.os.windows.OpenFile` which required the API user to choose: are we
opening a file or directory? And the other kind would either cause
error.IsDir or error.NotDir. But that is not a limitation of the Windows
file system API; it was self-imposed.

On Windows, rename is implemented internally with `NtCreateFile` so we
need to allow it to open either files or directories. This is now done
by `std.os.windows.OpenFile` accepting enum{file_only,dir_only,any}
instead of a boolean.
2022-01-02 16:58:05 -08:00
Robin Voetter
7f77d3d671 stage2: pointer reify 2022-01-03 01:56:59 +01:00
Robin Voetter
41e52bd5cc stage2: don't call comptime functions with generic poison arguments
When calling a comptime or inline function, if the parameter is generic and
is resolved to generic_poison or generic_poison_type, the invocation was
part of another function's parameters or return type expression and is
dependent on an as-of-yet type of another parameter. In this case, processing
should stop, and we return error.GenericPoison to let the caller in funcCommon,
zirParam or zirParamAnytype know that the function is generic.
2022-01-03 00:19:59 +01:00
Andrew Kelley
b4d6e85a33 Sema: implement peer type resolution of signed and unsigned ints
This allows stage2 to build more of compiler-rt.

I also changed `-%` to `-` for comptime ints in the div and mul
implementations of compiler-rt. This is clearer code and also happens to
work around a bug in stage2.
2022-01-02 14:11:37 -07:00