16385 Commits

Author SHA1 Message Date
Lee Cannon
1cdc51ec10 handle error.PathAlreadyExists in renameTmpIntoCache 2022-01-07 16:50:37 -05:00
r00ster
dd076d8cba Add missing package to the langref that's always available 2022-01-07 14:18:47 -05:00
Meghan
c08b190c69
lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
Jimmi Holst Christensen
7f4fdcc4fc stage2: Implement validating switch on errors 2022-01-06 22:57:45 -05:00
Andrew Kelley
59315463f2 ci: add test coverage for self-hosted arm and x86_64 backends 2022-01-06 22:57:29 -05:00
Andrew Kelley
77f230ebd8 C backend is passing test/behavior/undefined.zig
closes #10505
2022-01-06 13:07:38 -07:00
Jakub Konka
0772fb0518
Merge pull request #10518 from ziglang/stage2-x86_64-zig-test-fixes
stage2: fix x86_64 backend to actually correctly run Zig tests!
2022-01-06 15:31:39 +01:00
Jacob G-W
b47530b9fe plan9: fix .z symbol in debuginfo
This allows the `acid` debugger on
plan9 to be used to debug a zig source
file without patching `acid`!

The patch adds a second `z` symbol. This z
symbol has a value of 0, which means that it
pops the history stack. We put a very large
number for the value of the second symbol because
it has to be at least as large as the linecount of
the file. The debuginfo format is meant to be used
with c files, where the stack would look something
like this:
```
->  Line: 0x1 (1)  Name: 0x1/0x2/0x3/0xe/0x13/0x1b (/sys/src/libc/port/malloc.c)
->  Line: 0x2 (2)  Name: 0x1/0x6/0x7/0x8 (/amd64/include/u.h)
->  Line: 0x4f (79)  Name:  ()
->  Line: 0x50 (80)  Name: 0x1/0x2/0x7/0x9 (/sys/include/libc.h)
->  Line: 0x358 (856)  Name:  ()
->  Line: 0x359 (857)  Name: 0x1/0x2/0x7/0x1c (/sys/include/pool.h)
->  Line: 0x392 (914)  Name:  ()
->  Line: 0x393 (915)  Name: 0x1/0x2/0x7/0x1d (/sys/include/tos.h)
->  Line: 0x3ab (939)  Name:  ()
->  Line: 0x4eb (1259)  Name:  ()
```
however in zig, we do not use includes and .h files,
so we only need the first and last items in the stack:
the source file that the symbols belong to, and the pop
symbol with a null name and a value of the total linecount of the
preprocessed source. Since there is no preprocessing in zig, we
just make the linecount very large. There do not appear to be
any downsides to this approach. If this causes a bug in the future,
a simple fix would be to make the pop symbol just have the value
of how many newlines are in the source file.
2022-01-06 13:17:00 +01:00
Jakub Konka
97e76bf36c stage2: temporarily disable offending stage2 test on macOS
Another caveat, `zig test` doesn't currently work on stage2.
2022-01-06 12:57:34 +01:00
Jakub Konka
a124192fb0 stage2: implement basics of airWrapErrUnionErr
Enable more behavior tests for x86_64.
2022-01-06 10:12:01 +01:00
Jakub Konka
ee6e9b3c48 stage2: fix airStructFieldPtr and airStructFieldVal
This finally fixes `zig test`.
2022-01-06 09:54:33 +01:00
Jakub Konka
b215241ef2 stage2: fix airSliceElemVal
Refactor codegen and fix a bug in Isel.
2022-01-06 09:54:33 +01:00
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