882 Commits

Author SHA1 Message Date
Luuk de Gram
4957c7cbbd
wasm: enable passing behavior tests
This also splits the test cases for addition and subtraction as the wasm
backend does not yet provide support for 128bit saturating arithmetic.
2022-06-19 17:27:56 +02:00
Andrew Kelley
33cf6ef621
Merge pull request #11881 from Vexu/stage2
Stage2: fixes for bugs found while looking for miscompilations
2022-06-17 19:23:08 -04:00
Xavier Bouchoux
b66247c97a stage2: coerce tuple to vector 2022-06-17 19:06:17 +03:00
Omar Alhammadi
69e2cac0d3
stage2: comptime @bitCast packed struct bug fix 2022-06-17 19:04:51 +03:00
Veikka Tuominen
b9dcbe6b4c Sema: handle sentinels in tupleToArray 2022-06-17 18:57:02 +03:00
Andrew Kelley
13f02c30e6 stage2: fix some inline asm incompatibilities with stage1 2022-06-12 14:46:05 -07:00
Andrew Kelley
ffa700ee58
Merge pull request #11837 from Vexu/stage2
Fix (nearly) all stage2 crashes when testing stdlib
2022-06-12 17:45:57 -04:00
Veikka Tuominen
0a9d6956e7 Sema: add missing set_union_tag 2022-06-12 19:17:41 +03:00
Andrew Kelley
e64d5a0753 Sema: rework beginComptimePtrMutation
This comment is now deleted because the task is completed in this
commit:

```
// TODO: Update this to behave like `beginComptimePtrLoad` and properly check/use
// `container_ty` and `array_ty`, instead of trusting that the parent decl type
// matches the type used to derive the elem_ptr/field_ptr/etc.
//
// This is needed because the types will not match if the pointer we're mutating
// through is reinterpreting comptime memory.
```

The main strategy is to change the ComptimePtrMutationKit struct so that
instead of `val: *Value` it now returns a tagged union which can be one
of three possibilities:

 * The pointer type matches the actual comptime Value so a direct
   modification is possible. Before this commit, the implementation
   incorrectly assumed this was always the case.

 * In the case of needing to write through a reinterpreted pointer, a
   mutable base Value pointer is provided along with a byte offset
   pointing to the element value in virtual memory.

 * Otherwise, it means a compile error must be emitted because one or
   both of the types (the owner of the value, or the pointer type being
   used to write through) do not have a well-defined memory layout.

After calling beginComptimePtrMutation, the one callsite now switches on
this tagged union and does the appropriate thing. The main new logic is
for the second case, which involves pointer reinterpretation, which now
takes this strategy:

 1. write the base value to a memory buffer.
 2. perform the pointer store at the proper byte offset, thereby
    modifying a subset of the buffer.
 3. read the base value from the memory buffer, overwriting the old base
    value.
2022-06-12 01:33:56 -07:00
Veikka Tuominen
35c7e376b8 stage2: improve anon name strategy for local variables 2022-06-11 23:49:33 +03:00
Veikka Tuominen
0333ff4476 stage2: make error{} the same size as anyerror
Having `error{}` be a zero bit type causes issues when it interracts
with empty inferred error sets which are the same size as `anyerror`.
2022-06-11 23:49:33 +03:00
Veikka Tuominen
488e1e5f51 stage2: small fixes + adjustments to std tests 2022-06-11 23:49:33 +03:00
Veikka Tuominen
eaa6b04c3c Sema: skip decl causing namespace lookup when doing lookup 2022-06-11 11:02:56 +03:00
Andrew Kelley
c1eb6c30e8
Merge pull request #11835 from ziglang/stage2-behavior
stage2: fix handling of aggregates with mixed comptime-only fields
2022-06-11 00:27:41 -04:00
Andrew Kelley
3c3bc5af29 Sema: introduce bitSizeAdvanced to recursively resolve types
Same pattern as abiSizeAdvanced.

Fixes compiler crash for nested packed structs.
2022-06-10 15:04:39 -07:00
Andrew Kelley
58bc562cb4 update packed struct behavior tests to new language semantics 2022-06-09 20:37:24 -07:00
Andrew Kelley
32c90cb553 stage2: fix handling of aggregates with mixed comptime-only fields 2022-06-09 19:23:36 -07:00
Andrew Kelley
83f300218f upgrade behavior test to stage2 fn ptr semantics 2022-06-09 15:37:16 -07:00
Andrew Kelley
f4d5fcde72 AstGen: avoid redundant "ref" instructions
Whenever a `ref` instruction is needed, it is created and saved in
`AstGen.ref_table` instead of being immediately appended to the current
block body. Then, when the referenced instruction is being added to the
parent block (e.g. from setBlockBody), if it has a ref_table entry, then
the ref instruction is added directly after the instruction being referenced.
This makes sure two properties are upheld:
1. All pointers to the same locals return the same address. This is required
   to be compliant with the language specification.
2. `ref` instructions will dominate their uses. This is a required property
   of ZIR.

A complication arises when a ref instruction refs another ref
instruction. The logic in appendBodyWithFixups must take this into
account, recursively handling ref refs.
2022-06-08 20:40:16 -07:00
Andrew Kelley
7c0614ea65 Sema: implement zirRetErrValueCode 2022-06-08 15:51:48 -07:00
Andrew Kelley
d557dedf6c add a missing align() to a behavior test 2022-06-08 15:38:15 -07:00
Andrew Kelley
434226c89d stage2: fix type printing of sub-byte pointers 2022-06-08 15:18:43 -07:00
Andrew Kelley
53c86febcb stage2: packed struct fixes for big-endian targets 2022-06-07 22:47:08 -07:00
Andrew Kelley
3e30ba3f20 stage2: better codegen for byte-aligned packed struct fields
* Sema: handle overaligned packed struct field pointers
 * LLVM: handle byte-aligned packed struct field pointers
2022-06-07 21:05:40 -07:00
Andrew Kelley
6ff7b437ff
Merge pull request #11813 from Vexu/stage2
`zig2 build test-std` finale
2022-06-07 20:07:28 -04:00
Jakub Konka
3cb3873382
Merge pull request #11814 from ziglang/x64-stack-handling
x64: improves stack handling, fixes a heisenbug, adds micro-optimisations
2022-06-07 23:22:20 +02:00
Jakub Konka
6c59aa9e02
Merge pull request #11806 from koachan/sparc64-codegen
stage2: sparc64: Some more Air lowerings
2022-06-07 21:24:56 +02:00
Veikka Tuominen
e4c0b848a4 Sema: allow simple else body even when all errors handled 2022-06-07 21:27:06 +03:00
Veikka Tuominen
d5e3d5d74c Sema: make analyzeIsNonErr even lazier for inferred error sets 2022-06-07 21:27:06 +03:00
Jakub Konka
a8bce8f14b x64: pass behavior test bugs/1381 2022-06-07 19:33:43 +02:00
Andrew Kelley
e9fc58eab7 LLVM: handle extern function name collisions
Zig allows multiple extern functions with the same name, and the
backends have to handle this possibility.

For LLVM, we keep a sparse map of collisions, and then resolve them in
flushModule(). This introduces some technical debt that will have to be
resolved when adding incremental compilation support to the LLVM
backend.
2022-06-07 00:47:10 -04:00
Jakub Konka
d9b0c984aa
Merge pull request #11794 from ziglang/elf-macho-alignment
elf+macho: use explicit alignment on Decl if specified
2022-06-07 01:03:15 +02:00
Veikka Tuominen
84000aa820 Sema: fix inline call of func using ret_ptr with comptime only type 2022-06-06 13:11:50 -07:00
Veikka Tuominen
8fa88c88c2 AstGen: fix coercion scope type when stores are eliminated 2022-06-06 13:11:50 -07:00
Veikka Tuominen
cb5d2b691a Sema: validate equality on store to comptime field 2022-06-06 13:11:50 -07:00
Veikka Tuominen
a040ccb42f Sema: fix coerce result ptr outside of functions 2022-06-06 13:11:50 -07:00
Koakuma
97d35a5147 behaviortest: Skip 'align(N) on functions' on sparc64 for now 2022-06-06 21:17:09 +07:00
Jakub Konka
95966f6fd7 elf+macho: use explicit alignment on decl is specified 2022-06-05 16:46:50 +02:00
Jakub Konka
33826a6a2e x64: disable misbehaving behavior tests 2022-06-05 10:36:54 +02:00
Jakub Konka
1b5dd4e148
Merge pull request #11790 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic switch expressions
2022-06-05 09:10:12 +02:00
joachimschmidt557
d5ee451177
stage2 ARM: introduce support for basic switch expressions 2022-06-04 19:58:34 +02:00
Veikka Tuominen
2b93546b39 Sema: fix initialization of array with comptime only elem type 2022-06-03 20:21:20 +03:00
Andrew Kelley
288e89b606 Sema: fix compiler crash with comptime arithmetic involving @ptrToInt 2022-06-01 16:45:28 -07:00
Andrew Kelley
a4cdb49a58
Merge pull request #11763 from Vexu/stage2-alloc-const
Stage2: detect when initializer of const variable is comptime known
2022-06-01 18:59:13 -04:00
Andrew Kelley
b82cccc9e9 Sema: fix alignment of element ptr result type 2022-06-01 15:43:21 -07:00
Veikka Tuominen
94624893d8 disable failing test 2022-06-01 13:06:31 +03:00
Veikka Tuominen
9431100736 Sema: apply previous changes to validateUnionInit 2022-06-01 13:01:39 +03:00
Veikka Tuominen
36df79cd37 stage2: ignore generic return type when hashing function type
Generic parameter types are already ignored.
2022-05-31 16:43:58 +03:00
Veikka Tuominen
febc7d3cd6 Sema: take dbg_stmt into account in zirResolveInferredAlloc 2022-05-31 16:22:00 +03:00
Andrew Kelley
c3ef4ac15f
Merge pull request #11752 from ziglang/zir-fancy-fns
stage2: add missing data to ZIR encoding of functions
2022-05-30 21:18:10 -04:00