8856 Commits

Author SHA1 Message Date
Meghan
c08b190c69
lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
Jacob G-W
398c0b10e4 Plan9: fix amount to say included line count is
Not sure why this was working before...
2022-01-06 22:58:53 -05:00
Jimmi Holst Christensen
7f4fdcc4fc stage2: Implement validating switch on errors 2022-01-06 22:57:45 -05:00
Jacob G-W
ab400ad624 Plan9: implement getDeclVAddr 2022-01-06 22:47:27 -05:00
Jacob G-W
4d6849ceb8 plan9 debuginfo: fix case where pc change is > 64 * inst quanta 2022-01-06 22:46:55 -05:00
Luuk de Gram
6d951aff7e
wasm-linker: Only export symbols notated as such
This exposes a function from stage2 to stage1 to append symbols to automatically export them.

This happends under the following conditions:
- Target is wasm
- User has not provided --export/--rdynamic flags themselves.
2022-01-06 20:19:47 +01: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
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
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
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
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
Andrew Kelley
b6d6152e65 link: avoid creating stage2 llvm module when using stage1 2022-01-04 00:11:45 -07: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
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
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
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
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