256 Commits

Author SHA1 Message Date
Luuk de Gram
09d6938df9
wasm: add atomics opcodes and refactoring
This adds the atomic opcodes for the Threads proposal to the
WebAssembly specification: https://github.com/WebAssembly/threads

PrefixedOpcode has been renamed to MiscOpcode as there's multiple
types of prefixed opcodes. This naming is similar to other tools
such as LLVM. As we now use the 0xFE prefix, we moved the
function_index MIR instruction as it was occupying the same value.
This commit includes renaming all related opcodes.
2023-03-18 20:13:30 +01:00
Andrew Kelley
e7f128c205
Merge pull request #14782 from r00ster91/trap
add `@trap` builtin
2023-03-04 16:20:31 -05:00
r00ster91
4eb3f50fcf Wasm @breakpoint: emit unreachable
This should improve the developer debugging experience.
2023-03-04 12:08:23 +01:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Jakub Konka
dc709fbf48 codegen: rename GenerateSymbolError to CodeGenError 2023-03-03 18:56:57 +01:00
Jakub Konka
c746cbc686 codegen: move gen logic for typed values, consts and decl ref to common codegen 2023-03-03 18:06:25 +01:00
Isaac Freund
05da5b32a8 Sema: implement @fieldParentPtr for unions 2023-02-21 15:57:13 +02:00
Veikka Tuominen
f10950526e implement writeToMemory/readFromMemory for pointers 2023-02-19 13:54:52 -05:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Luuk de Gram
c9b957c937 link: remove FnData and make it self-owned
This finishes the work started in #14502 where atoms are owned by the
linker themselves. This now makes debug atoms fully owned by dwarf,
and no information is left stored on the decl.
2023-02-03 22:55:46 +01:00
Jakub Konka
304420b99c
Merge pull request #14502 from ziglang/link-owned-atoms
link: move ownership of linker atom from frontend to the linkers
2023-02-02 01:39:01 +01:00
Jakub Konka
beb20d29db link: remove union types which are now internal to backends 2023-02-01 19:32:54 +01:00
Luuk de Gram
46f54b23ae
link: make Wasm atoms fully owned by the linker 2023-02-01 19:10:56 +01:00
Jakub Konka
5de2aae63c link: decouple DI atoms from linker atoms, and manage them in Dwarf linker 2023-02-01 15:03:55 +01:00
Techatrix
47ff57ed7d wasm: apply request change 2023-01-31 17:01:56 +01:00
Techatrix
1f64432196 wasm: correctly handle optional slices 2023-01-31 00:59:18 +01:00
Luuk de Gram
b25efb86e1
wasm: migrate to new non-allocateDeclIndexes API 2023-01-27 19:24:15 +01:00
Jakub Konka
a95d58caf2 self-hosted: rename codegen Result.appended to Result.ok 2023-01-25 10:28:18 +01:00
Jakub Konka
4983da40d0 self-hosted: remove unused externally_managed prong for Decls code 2023-01-25 10:10:50 +01:00
Veikka Tuominen
4e64373fc0 fix generic function arg debug info referencing wrong parameter
Closes #14123
2022-12-30 17:00:50 +02:00
Luuk de Gram
0d66112643 wasm: refactor extended instructions
The extended instructions starting with opcode `0xFC` are refactored
to make the work the same as the SIMD instructions. This means a
`Mir` instruction no longer contains a field 'secondary'. Instead,
we use the `payload` field to store the index into the extra list
which contains the extended opcode value. In case of instructions
such as 'memory.fill' which also have an immediate value, such
values will also be stored in the extra list right after the
instruction itself. This makes each `Mir` instruction smaller.
2022-12-21 17:02:53 +01:00
Andrew Kelley
aca9c74e80
Merge pull request #13914 from Vexu/variadic
implement defining C variadic functions
2022-12-18 16:24:13 -05:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Veikka Tuominen
9bb1104e37 implement defining C variadic functions 2022-12-17 13:22:09 +02:00
Veikka Tuominen
8a0a6b7387 port packed vector elem ptr logic from stage1
Closes #12812
Closes #13925
2022-12-15 21:06:35 -05:00
Andrew Kelley
6378644d4e
Merge pull request #13907 from Vexu/call-merge
Remove `stack` option from `@call`
2022-12-13 18:15:18 -05:00
Veikka Tuominen
7b2a936173 remove stack option from @call 2022-12-13 12:52:21 +02:00
Luuk de Gram
355b5929b2
wasm: splat for vector elements divisible by 8
This implements `@splat` for vectors where the element type is
divisible by 8 and a power of two. This is fairly simple as we can
store the values directly within the virtual stack. But for
all other sizes, we must first shift and bitwise-or the values
before we can store them to fit them like a packed-struct, rather
than an array.
2022-12-12 17:42:00 +01:00
Luuk de Gram
c6d654f73b
wasm: implement the 'splat' instruction part 1
This implements `airSplat` for the native WebAssembly backend when
the features 'simd128' or 'relaxed-simd' are enabled. The commit
supports splat where the value lives in the linear memory segment,
as well as on the stack. This saves a lot of instruction cost.
When it detects the element type is not 8, 16, 32 or 64 bits,
the backend will instead use the same strategy as if the features
where disabled.
2022-12-12 17:42:00 +01:00
Luuk de Gram
63b69e2c55
wasm: load+store simd immediate values
This implements loading and storing immediate values representing
a vector with exactly 128 bits. When the vector does not equal to
128 bits, or when the simd128 or relaxed-simd features are disabled
the value will be treated as an array instead.
2022-12-12 17:41:59 +01:00
Veikka Tuominen
9d93b2ccf1 Eliminate BoundFn type from the language
Closes #9484
2022-12-09 20:37:18 -07:00
Andrew Kelley
3a9375cae9 wasm codegen: fix some missing Liveness reaps
I did not do a full audit, but I did notice a few issues which are
resolved in this commit. Probably it would be worth adding debug
infrastructure to assert that the number of reaps equals the number of
calls to resolveInst() per air lowering function.
2022-12-04 15:57:40 -07:00
Andrew Kelley
fdbb0fb7b9
Merge pull request #13744 from Vexu/stage2-fixes
Improve error messages, fix dependency loops
2022-12-03 00:42:11 -05:00
Veikka Tuominen
0e38cc16d5 Sema: fix comparisons between lazy and runtime values
Closes #12498
2022-12-03 00:09:23 +02:00
Jakub Konka
bfd36cbf97 dwarf: pass linker Tag and owner Decl.Index instead of *Atom 2022-12-02 13:17:52 +01:00
Jakub Konka
3ec0520bac dwarf: use common DI union object for arg and var gen 2022-12-02 12:22:17 +01:00
Jakub Konka
8fea84f77e dwarf: move Wasm specific dwarf gen out of codegen 2022-12-01 20:55:55 +01:00
Luuk de Gram
3933a4bac5
codegen: support generating packed structs 2022-11-30 17:56:02 +01:00
Luuk de Gram
df7ddb475e
wasm: Fix pointer to field of packed struct
When requesting a pointer to a field of a packed struct (of which is
not byte-aligned), we simply provide the address of the packed struct
itself.
2022-11-30 17:56:02 +01:00
Luuk de Gram
6924f21bbd
wasm: support non-natural alignment in load/store
This implements support for loading and storing where the lhs is
of pointer type with host_size != 0. e.g. when loading a specific
field from a packed struct with a non-byte alignment such as (0:1:3).
2022-11-30 17:56:02 +01:00
Luuk de Gram
a7ad1212cb
wasm: airAggregateInit - Support packed structs
This allows the Wasm backend to construct an instance of a packed
struct during runtime. We first allocate a local, and then
shift+or each field's value into the result local. We then finally
return this result local as value.

The commit also fixes a type-issue in `airElemVal` where we used
the element type instead of a pointer type to store the value's
address into.
2022-11-30 17:56:02 +01:00
Luuk de Gram
a314e86772
wasm: support passing packed struct over C-ABI
This also adds support loading a runtime pointer from a packed struct.
Also, this commit improves many utility functions such as `trunc` and
`intcast` to also support non-integer types such as booleans.
2022-11-30 17:56:02 +01:00
Luuk de Gram
4af5bbde53
wasm: airStructFieldPtr - Support packed structs
Simplifies the airStructFieldPtr(index) functions to only obtain the
correct struct type and field index, which is then passed into the
structFieldPtr function. This function now calculates the byte-offset
of the field's address and returns a new `WValue` with this offset.
This means we only have to do this calculation in a single function,
and no longer have to duplicate any logic. This also handles both
regular (tagged) unions and packed unions.
2022-11-30 17:56:01 +01:00
Luuk de Gram
eb2caf9390
wasm: airStructFieldVal - Support packed structs
This implements loading a field from a packed struct, regardless of
its field's type. This means it supports pointers, floats and
integers. The commit also extracts the logic from airTrunc into its
own `trunc` function so it can be re-used.
2022-11-30 17:56:01 +01:00
Luuk de Gram
7cf442cabc
wasm: Support bitcasting between floats and ints 2022-11-30 17:56:01 +01:00
Luuk de Gram
2be0d5bbca
wasm: add support packed structs in lowerConstant
When lowering constants of packed structs, which are smaller than 65
bits, we lower the value to an integer rather than store it in the
constant data section. This allows us to use an immediate value,
for quick loads and stores.
2022-11-30 17:56:01 +01:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Veikka Tuominen
d03c47bf85 Sema: use runtime_value instead of creating allocs 2022-10-27 21:08:25 -04:00
Cody Tapscott
724d753638 stage2: Add .save_err_return_trace_index AIR op
This is encoded as a primitive AIR instruction to resolve one corner
case: A function may include a `catch { ... }` or `else |err| { ... }`
block but not call any errorable fn. In that case, there is no error
return trace to save the index of and codegen needs to avoid
interacting with the non-existing error trace.

By using a primitive AIR op, we can depend on Liveness to mark this
unused in this corner case.
2022-10-21 10:44:20 -07:00
Luuk de Gram
0aa23fe8b7
wasm: rename 'self' to more explanatory name
'Self' isn't a very good name to describe what it does.
This commit changes the type name into `CodeGen` and the parameter
to `func` as we're generating code for a function.
With this change, the backend's coding style is in line with the
self-hosted Wasm-linker.
2022-10-16 15:54:56 +02:00