8067 Commits

Author SHA1 Message Date
Andrew Kelley
55ba335e0f Sema: fix resolution of inferred error sets
Introduce `Module.ensureFuncBodyAnalyzed` and corresponding `Sema`
function. This mirrors `ensureDeclAnalyzed` except also waits until the
function body has been semantically analyzed, meaning that inferred
error sets will have been populated.

Resolving error sets can now emit a "unable to resolve inferred error
set" error instead of producing an incorrect error set type. Resolving
error sets now calls `ensureFuncBodyAnalyzed`. Closes #11046.

`coerceInMemoryAllowedErrorSets` now does a lot more work to avoid
resolving an inferred error set if possible. Same with
`wrapErrorUnionSet`.

Inferred error set types no longer check the `func` field to determine if
they are equal. That was incorrect because an inline or comptime function
call produces a unique error set which has the same `*Module.Fn` value for
this field. Instead we use the `*Module.Fn.InferredErrorSet` pointers to
test equality of inferred error sets.
2022-03-11 19:38:07 -07:00
Andrew Kelley
2ee3cc453c stage2: remove SPDX license header comments
These were missed in d29871977f97b50fe5e3f16cd9c68ebeba02a562.
2022-03-11 19:38:07 -07:00
Andrew Kelley
6f986298c6
Merge pull request #11125 from jmc-88/cbe
CBE: promote an already passing test, and add implementation for clz, ctz for integers
2022-03-11 20:15:13 -05:00
Daniele Cocca
226fcd7c70 CBE: implement clz, ctz for ints <= 128 bits 2022-03-11 23:12:15 +00:00
Mitchell Hashimoto
fca51c81bc stage2: is_non_error always returns comptime true for empty error set 2022-03-11 17:16:34 -05:00
Mitchell Hashimoto
797f4db227 stage2: Array len field should be a usize not comptime_int 2022-03-11 17:15:36 -05:00
Andrew Kelley
a2517117e7 Sema: make @hasField support tuples too 2022-03-11 12:59:20 -07:00
Mitchell Hashimoto
6a9c9afbae stage2: @hasField for anon structs 2022-03-11 12:51:21 -07:00
Andrew Kelley
4c1cc4d8d9
Merge pull request #11120 from Vexu/stage2
Stage2: make std.rand tests pass
2022-03-11 13:48:28 -05:00
Veikka Tuominen
03b8206f27 Sema: make check for whether call should be memoized more thorough 2022-03-11 16:56:33 +02:00
joachimschmidt557
4590e980f7
stage2 ARM: implement caller-saved registers 2022-03-11 14:12:11 +01:00
joachimschmidt557
06058ed6f3
stage2 regalloc: replace Register.allocIndex with generic indexOfReg
* callee_preserved_regs and other ABI-specific information have been
moved to the respective abi.zig files
2022-03-11 13:29:16 +01:00
Veikka Tuominen
01cd4119b0 Sema: implement @shuffle at comptime and for differing lengths 2022-03-11 14:25:15 +02:00
Veikka Tuominen
cba68090a6 stage2: implement @shuffle at runtime 2022-03-11 13:12:32 +02:00
Veikka Tuominen
db42624170 Sema: enable shl and bitwise for vectors at runtime 2022-03-11 13:06:22 +02:00
Veikka Tuominen
98a5998d83 Sema: improve detection of generic parameters 2022-03-11 11:25:45 +02:00
Andrew Kelley
078037ab9b stage2: passing threadlocal tests for x86_64-linux
* use the real start code for LLVM backend with x86_64-linux
   - there is still a check for zig_backend after initializing the TLS
     area to skip some stuff.
 * introduce new AIR instructions and implement them for the LLVM
   backend. They are the same as `call` except with a modifier.
   - call_always_tail
   - call_never_tail
   - call_never_inline
 * LLVM backend calls hasRuntimeBitsIgnoringComptime in more places to
   avoid unnecessarily depending on comptimeOnly being resolved for some
   types.
 * LLVM backend: remove duplicate code for setting linkage and value
   name. The canonical place for this is in `updateDeclExports`.
 * LLVM backend: do some assembly template massaging to make `%%`
   rendered as `%`. More hacks will be needed to make inline assembly
   catch up with stage1.
2022-03-11 00:04:42 -07:00
Andrew Kelley
b28b3f6f7b stage2: fix comptime element load of undef array 2022-03-10 22:57:13 -07:00
Andrew Kelley
273da9efd9 AstGen: structInitExpr and arrayInitExpr avoid crash
when an inferred alloc is passed as the result pointer of a block.
2022-03-10 17:52:18 -07:00
Andrew Kelley
a30d283981 AstGen: lower anon struct inits differently
This is a companion commit to f2a5d0bf94897554e25e889dc1c6c4c7fc6c1217.
What that one did for tuples, this one does for anonymous structs.
2022-03-10 17:52:18 -07:00
Andrew Kelley
b642fa24a6 stage2: implement integer pointer constants 2022-03-10 17:52:18 -07:00
Andrew Kelley
9f163310f2 stage2: improve Type.eql and Type.hash for error sets
* Reduce branching in Type.eql and Type.hash for error sets.
 * `Type.eql` uses element-wise bytes comparison since it can rely on
   the error sets being pre-sorted.
 * Avoid unnecessarily skipping tests that are passing.
2022-03-10 14:21:37 -07:00
Mitchell Hashimoto
569870ca41 stage2: error_set_merged type equality
This implements type equality for error sets. This is done
through element-wise error set comparison.

Inferred error sets are always distinct types and other error sets are
always sorted. See #11022.
2022-03-10 14:20:16 -07:00
Veikka Tuominen
f9e4344bb5 Sema: implement zirStructInit is_ref=true union 2022-03-10 20:00:07 +02:00
Veikka Tuominen
673fafc231 stage2 llvm: implement lowerParentPtr for int_{u,i}64 2022-03-10 19:52:03 +02:00
Veikka Tuominen
e0fb0770d1 Sema: if generic function evaluates to another generic function call it inline
```zig
fn foo(a: anytype, b: @TypeOf(a)) void { _ = b; }
test {
    // foo evaluates to `fn (type) void` and must be called inline
    foo(u32, u32);
}
```
2022-03-10 13:04:55 +02:00
Veikka Tuominen
b9f521b402 Sema: add coercion from [:x]T to [*:x]T 2022-03-10 12:02:31 +02:00
Andrew Kelley
f736cde397 Sema: implement pointer to tuple to pointer to array coercion
This involved an LLVM backend fix for the aggregate_init instruction.
2022-03-09 18:49:37 -07:00
Andrew Kelley
f32a77b30d Sema: implement pointer-to-tuple coercion to slice and struct 2022-03-09 17:33:01 -07:00
Andrew Kelley
3b6e8fa59e Sema: fix crash with @sizeOf on unions 2022-03-09 16:02:42 -07:00
Andrew Kelley
83bb3d1ad6 Sema: fix generic fn instantiation with anytype
When the anytype parameter had only one-possible-value
(e.g. `void`), it would create a mismatch in the function type and the
function call. Now the function type and the callsite both omit the
one-possible-value anytype parameter in instantiated generic functions.
2022-03-09 15:35:13 -07:00
Luuk de Gram
90f08a69aa wasm: Enable passing behavior tests
This also adds some float-related instructions to MIR/Emit
2022-03-09 13:53:20 -07:00
Luuk de Gram
3ea113e008 wasm: Implement field_parent_ptr 2022-03-09 13:53:10 -07:00
Luuk de Gram
f931c0638d wasm: Implement errunion_payload_ptr_set
This also fixes `ret_ptr` where the pointee type is zero-sized.
2022-03-09 13:53:10 -07:00
Luuk de Gram
d01bfa032d wasm: Preliminary fptrunc support
This implements the initial fptrunc instruction. For all other floating-point truncating,
a call to compiler-rt is required. (This also updates fpext to emit the same error).
2022-03-09 13:53:10 -07:00
Luuk de Gram
684b81f366 wasm: Implement fpext
This implements initial support for floating-point promotion for bitsizes <= 64
2022-03-09 13:53:10 -07:00
Luuk de Gram
557f396f61 wasm: Improve switch implementation
- Implement switching over booleans and pointers.
- Fix sparse-detection where the lowest value was never truly set
as it started at a non-zero number and the case was > 50.
- Fix indexing the jump table by ensuring it starts indexing from 0.
2022-03-09 13:53:10 -07:00
Veikka Tuominen
01b454f851 AstGen: ensure lableld block implicitly ends in a break 2022-03-09 17:12:40 +02:00
Veikka Tuominen
bb1fa0bdbd Sema: handle noreturn result in condbr_inline 2022-03-09 17:07:25 +02:00
Andrew Kelley
0f0d27ce24 Sema: implement tuple fieldptr and fieldval 2022-03-09 01:19:29 -07:00
Andrew Kelley
bb73775d40 Sema: implement coercion of tuples to structs 2022-03-08 22:19:25 -07:00
Andrew Kelley
6f560c9909 Sema: implement comptime struct fields 2022-03-08 20:52:38 -07:00
Andrew Kelley
a91753219d
Merge pull request #11085 from ziglang/llvm-debug-info
stage2 LLVM debug info
2022-03-08 21:09:20 -05:00
Andrew Kelley
935d208ffb
Merge pull request #11090 from mitchellh/inferred-ty
stage2: correct comptime-known inferred alloc type, plus comptime array init sentinels
2022-03-08 20:56:00 -05:00
Andrew Kelley
fb4ad37e0b LLVM: fix memory leak of debug type names
This required adjusting `Type.nameAlloc` to be used with a
general-purpose allocator and added `Type.nameAllocArena` for the arena
use case (avoids allocation sometimes).
2022-03-08 15:03:03 -07:00
Andrew Kelley
874b51d8d4 LLVM: add debug info for opaque, vector, and tuples
Also fix UAF of Type memory in the di_type_map.
2022-03-08 14:58:54 -07:00
Andrew Kelley
fa57335ec6 stage2: implement Type.getOwnerDecl for opaque types 2022-03-08 14:58:54 -07:00
Andrew Kelley
1046ead0cc LLVM: no longer store args into alloca instructions
Previously, we did this so that we could insert a debug variable
declaration intrinsic on the alloca. But there is a dbg.value intrinsic
for declaring variables that are values.
2022-03-08 14:58:53 -07:00
Andrew Kelley
7cea8f063f LLVM: add debug info for parameters 2022-03-08 14:58:53 -07:00
Andrew Kelley
ba566eed76 LLVM: fix not handling dbg_stmt relative line
Also make `namespaceToDebugScope` behave correctly for file-level
structs. Instead of being inside their own scope, they use the file
scope.
2022-03-08 14:58:53 -07:00