12417 Commits

Author SHA1 Message Date
Andrew Kelley
ce3cffbd5a fill out more InternPool Type methods
particularly, printing types
2023-06-10 20:42:28 -07:00
Andrew Kelley
0471638734 InternPool: add a dump function
So we can see stats
2023-06-10 20:42:28 -07:00
Andrew Kelley
9ec0017f46 stage2: migrate many pointer types to the InternPool 2023-06-10 20:42:28 -07:00
Andrew Kelley
2f05b1482a Sema: update core comptime detection logic to be InternPool aware
* Add some assertions to make sure instructions are not none. I tested
   all these with master branch as well and made sure the behavior tests
   still passed with the assertions intact (along with a handful of
   callsite updates).
 * Fix Sema.resolveMaybeUndefValAllowVariablesMaybeRuntime not noticing
   that interned values are comptime-known. This was causing all kinds
   of chaos.
 * Fix print_air writeType calling tag() without checking for ip_index
2023-06-10 20:42:28 -07:00
Andrew Kelley
ac07ddadeb InternPool: enhance integer values
The Key struct now has a Storage tagged union which can store a u64,
i64, or big int.

This is needed so that indexToKey can be implemented for integers stored
compactly in the data structure.
2023-06-10 20:42:28 -07:00
Andrew Kelley
41cdcd5486 stage2: add a few more Value checks for InternPool 2023-06-10 20:42:28 -07:00
Andrew Kelley
6ab8b6f8b2 stage2: move undef, unreach, null values to InternPool 2023-06-10 20:42:28 -07:00
Andrew Kelley
773fabf361 InternPool: add the missing pointer data 2023-06-10 20:42:28 -07:00
Andrew Kelley
5e636643d2 stage2: move many Type encodings to InternPool
Notably, `vector`.

Additionally, all alternate encodings of `pointer`, `optional`, and
`array`.
2023-06-10 20:42:27 -07:00
Andrew Kelley
9d422bff18 stage2: move all integer types to InternPool 2023-06-10 20:40:04 -07:00
Andrew Kelley
85c69c5194 Type.isSlice: make it InternPool aware 2023-06-10 20:40:04 -07:00
Andrew Kelley
fb16ad3add Type: update to use InternPool for some methods 2023-06-10 20:40:04 -07:00
Andrew Kelley
ca3cf93b21 stage2: move most simple values to InternPool 2023-06-10 20:40:04 -07:00
Andrew Kelley
836d8a1f64 stage2: move most simple types to InternPool 2023-06-10 20:40:04 -07:00
Andrew Kelley
bcd4bb8afb stage2: move named int types to InternPool 2023-06-10 20:40:04 -07:00
Andrew Kelley
4cd8a40b3b stage2: move float types to InternPool 2023-06-10 20:40:03 -07:00
Andrew Kelley
aa1bb5517d InternPool: implement isSinglePointer 2023-06-10 20:40:03 -07:00
Andrew Kelley
e77dede87e InternPool: implement typePtrOrOptionalPtrTy 2023-06-10 20:40:03 -07:00
Andrew Kelley
264292f430 InternPool: implement resolveTypeFields 2023-06-10 20:40:03 -07:00
Andrew Kelley
cdf6acba96 InternPool: implement hasWellDefinedLayout for simple_type 2023-06-10 20:40:03 -07:00
Andrew Kelley
d1887ab1dd InternPool: implement hasRuntimeBitsAdvanced for simple_type 2023-06-10 20:40:03 -07:00
Andrew Kelley
b125063dcf InternPool: implement typeHasOnePossibleValue for simple_type 2023-06-10 20:40:03 -07:00
Andrew Kelley
50f33734c6 stage2: isGenericPoison InternPool awareness 2023-06-10 20:40:03 -07:00
Andrew Kelley
00f82f1c46 stage2: add interned AIR tag
This required additionally passing the `InternPool` into some AIR
methods.

Also, implement `Type.isNoReturn` for interned types.
2023-06-10 20:40:03 -07:00
Andrew Kelley
c7e84ddb72 InternPool: flesh out some of the implementations
* hashing
 * equality
 * encoding
2023-06-10 20:40:03 -07:00
Andrew Kelley
9aec2758cc stage2: start the InternPool transition
Instead of doing everything at once which is a hopelessly large task,
this introduces a piecemeal transition that can be done in small
increments at a time.

This is a minimal changeset that keeps the compiler compiling. It only
uses the InternPool for a small set of types.

Behavior tests are not passing.

Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but
compile-time verified to have the same fields in the same order.

The large set of changes is mainly to deal with the fact that most Type
and Value methods now require a Module to be passed in, so that the
InternPool object can be accessed.
2023-06-10 20:40:03 -07:00
mlugg
1e7dcaa3ae Sema: resolve peer vector types before comparison
Resolves: #15732
2023-06-10 21:41:49 +03:00
mlugg
34d44e0c1c Sema: emit error on @intToPtr with slice dest type
Resolves: #15967
2023-06-10 11:12:35 +03:00
mlugg
bf4b43a2f7 AstGen: handle ref_table for params
This is kind of similar to 1a4b0d9. In this case, we need to handle
ref_table when appending the body of param instructions.

Resolves: #15952
2023-06-10 07:18:05 +03:00
David Gonzalez Martin
c16d4ab9e4 llvm: stop generating FPU code if there is no FPU
Fixes https://github.com/ziglang/zig/issues/14465

For aarch64, LLVM was crashing because Zig commands it to generate FPU code
even when there is no FPU present. This commit implements the necessary checks
to avoid this undesired situation and aarch64 can be compiled again with
no FPU.
2023-06-06 18:30:56 +00:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
DraagrenKirneh
105078519a fix missing insertion of module to all_modules on first download 2023-06-03 13:40:28 -07:00
mlugg
1a4b0d9790 AstGen: handle ref_table for errdefer captures
Resolves: #15861
2023-06-03 13:36:44 -07:00
Andrew Kelley
9461ed5037
Merge pull request #15900 from Snektron/spirv-pool
SPIR-V Intern Pool
2023-06-02 12:17:02 -07:00
Luuk de Gram
3faf376b08
Merge pull request #15919 from Luukdegram/wasm-behavior-tests 2023-06-01 19:42:04 +02:00
Evin Yulo
6c2f374556 Use the word 'base' consistently instead of 'radix' 2023-06-01 00:02:16 +03:00
Evin Yulo
3085e2af41 add missing note "operation is runtime due to this operand" 2023-05-31 19:18:36 +03:00
Luuk de Gram
ebfd3450d9
codegen: Write padding bytes for unions
Previously we did not write any missing padding bytes after the smallest
field (either tag or payload, depending on alignment). This resulted in
writing too few bytes and not matching the full abisize of the union.
2023-05-31 18:04:33 +02:00
Luuk de Gram
7e10cf4fbe
wasm: shl_with_overflow ensure rhs is coerced
Both operands must have the same Wasm type before we are allowed
to perform any binary operation on the values.
2023-05-31 18:04:33 +02:00
Luuk de Gram
e36cc0ce8f
wasm: union_init support packed unions 2023-05-31 18:04:33 +02:00
Luuk de Gram
128814f9bf
wasm: aggregate_init store sentinel for arrays 2023-05-31 18:04:32 +02:00
Luuk de Gram
969f921162
wasm: ptr_elem_val use pointer type for local
When storing the address after calculating the element's address,
ensure it's stored in a local with the correct type. Previously it
would incorrectly use the element's type, which could be a float for
example and therefore generate invalid WebAssembly code.

This change also introduces a more robust `store` function.
2023-05-31 18:04:32 +02:00
Luuk de Gram
ffa89d3b83
wasm: UnwrapErrUnionPayloadPtr ensure ptr ret
When the paylaod is zero-sized we must ensure a valid pointer
is still returned for the ptr variation of the instruction. This,
because it's valid to have a pointer to a zero-sized value.
In such a case, we simply return the operand.
2023-05-31 18:04:32 +02:00
Luuk de Gram
3c72b4d25e
wasm: support and optimize for all packed unions
For packed unions where its abi size is less than or equal to 8 bytes
we store it directly and don't pass it by reference. This means that
when retrieving the field, we will perform shifts and bitcasts to ensure
the correct type is returned. For larger packed unions, we either allocate
a new stack value based on the field type when the field type is also passed
by reference, or load it directly into a local if it's not.
2023-05-31 18:04:32 +02:00
Luuk de Gram
7cfc44d86f
wasm: implement struct_field_val for packed unions
We currently have `isRef` return true for any type of union, including
packed unions. This means we can simply load it from the data section
to the exact type we want. In the future we can optimize it so it works
similarly to packed structs below 64 bits which do not get stored in
the data section and are not passed by ref.
2023-05-31 18:04:32 +02:00
Luuk de Gram
49fddbf4c1
wasm: union_init correctly store the tag
Previously we would only store the payload, but not the actual tag
that was set. This meant miscompilations where it would incorrectly
return the tag value.

This also adds a tiny optimization for payloads which are not `byRef`
by directly storing them based on offset, rather than first calculating
a pointer to an offset.
2023-05-31 18:04:32 +02:00
Luuk de Gram
00dedabc41
wasm: memcpy support elem abi-size > 1
Previously it was incorrectly assumed that all memcopy's generated by
the `memcpy` AIR instruction had an element size of 1 byte. However,
this would result in miscompilations for pointer's to arrays where
the element size of the array was larger than 1 byte. We now corectly
calculate this size.
2023-05-31 18:04:31 +02:00
yujiri8
cd1417dbdf
don't crash when can't evaluate comptime expression with inferred type
Closes #15911.
2023-05-31 11:15:52 +00:00
Bogdan Romanyuk
32e719e070
sema: add compile error for incorrect extern type 2023-05-31 04:38:32 +00:00
Robin Voetter
3c4cc1eedb
spirv: eliminate remaining uses of emitConstant 2023-05-30 19:43:37 +02:00