Commit Graph

1273 Commits

Author SHA1 Message Date
Andrew Kelley 9ff514b6a3 compiler: move error union types and error set types to InternPool
One change worth noting in this commit is that `module.global_error_set`
is no longer kept strictly up-to-date. The previous code reserved
integer error values when dealing with error set types, but this is no
longer needed because the integer values are not needed for semantic
analysis unless `@errorToInt` or `@intToError` are used and therefore
may be assigned lazily.
2023-06-10 20:47:53 -07:00
Andrew Kelley 7bf91fc79a compiler: eliminate legacy Type.Tag.pointer
Now pointer types are stored only in InternPool.
2023-06-10 20:47:53 -07:00
Andrew Kelley 17882162b3 stage2: move function types to InternPool 2023-06-10 20:47:53 -07:00
Andrew Kelley d18881de1b stage2: move anon tuples and anon structs to InternPool 2023-06-10 20:47:52 -07:00
Andrew Kelley 88dbd62bcb stage2: move enum tag values into the InternPool
I'm seeing a new assertion trip: the call to `enumTagFieldIndex` in the
implementation of `@Type` is attempting to query the field index of an
union's enum tag, but the type of the enum tag value provided is not the
same as the union's tag type. Most likely this is a problem with type
coercion, since values are now typed.

Another problem is that I added some hacks in std.builtin because I
didn't see any convenient way to access them from Sema. That should
definitely be cleaned up before merging this branch.
2023-06-10 20:46:17 -07:00
Andrew Kelley d89807efbb stage2: remove legacy Type array and array_sentinel
These are now handled by the InternPool.
2023-06-10 20:42:31 -07:00
mlugg 466328d1ca InternPool: transition float values 2023-06-10 20:42:30 -07:00
Andrew Kelley 5881a2d637 stage2: move enum types into the InternPool
Unlike unions and structs, enums are actually *encoded* into the
InternPool directly, rather than using the SegmentedList trick. This
results in them being quite compact, and greatly improved the ergonomics
of using enum types throughout the compiler.

It did however require introducing a new concept to the InternPool which
is an "incomplete" item - something that is added to gain a permanent
Index, but which is then mutated in place. This was necessary because
enum tag values and tag types may reference the namespaces created by
the enum itself, which required constructing the namespace, decl, and
calling analyzeDecl on the decl, which required the decl value, which
required the enum type, which required an InternPool index to be
assigned and for it to be meaningful.

The API for updating enums in place turned out to be quite slick and
efficient - the methods directly populate pre-allocated arrays and
return the information necessary to output the same compilation errors
as before.
2023-06-10 20:42:30 -07:00
Andrew Kelley 3ba099bfba stage2: move union types and values to InternPool 2023-06-10 20:42:30 -07:00
Andrew Kelley 8297f28546 stage2: move struct types and aggregate values to InternPool 2023-06-10 20:42:30 -07:00
Andrew Kelley 275652f620 stage2: move opaque types to InternPool 2023-06-10 20:42:30 -07:00
Andrew Kelley 3116477dcc stage2: move empty struct type and value to InternPool 2023-06-10 20:42:30 -07:00
Andrew Kelley 4d88f825bc stage2: implement intTagType logic
This commit changes a lot of `*const Module` to `*Module` to make it
work, since accessing the integer tag type of an enum might need to
mutate the InternPool by adding a new integer type into it.

An alternate strategy would be to pre-heat the InternPool with the
integer tag type when creating an enum type, which would make it so that
intTagType could accept a const Module instead of a mutable one,
asserting that the InternPool already had the integer tag type.
2023-06-10 20:42:29 -07:00
Andrew Kelley a5fb169594 stage2: bug fixes related to Type/Value/InternPool 2023-06-10 20:42:29 -07:00
mlugg 2ffef605c7 Replace uses of Value.zero, Value.one, Value.negative_one
This is a bit nasty, mainly because Type.onePossibleValue is now
errorable, which is a quite viral change.
2023-06-10 20:42:29 -07:00
mlugg c1ca16d779 wip: progress towards compiling tests 2023-06-10 20:42:29 -07:00
Andrew Kelley 75900ec1b5 stage2: move integer values to InternPool 2023-06-10 20:42:29 -07:00
Andrew Kelley f7bd42785b LLVM backend: update integer constant lowering for InternPool 2023-06-10 20:42:29 -07:00
Andrew Kelley 31aee50c1a InternPool: add a slice encoding
This uses the data field to reference its pointer field type, which
allows for efficient and infallible access of a slice type's pointer
type.
2023-06-10 20:42:29 -07:00
Andrew Kelley 9ec0017f46 stage2: migrate many pointer types to the 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 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 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 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 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
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
Robin Voetter 3c4cc1eedb spirv: eliminate remaining uses of emitConstant 2023-05-30 19:43:37 +02:00
Robin Voetter 0c41945a01 spirv: rename TypeConstantCache -> Cache 2023-05-30 19:43:37 +02:00
Robin Voetter 0552a8b11f spirv: translate remaining types 2023-05-30 19:43:37 +02:00
Robin Voetter fcb422585c spirv: translate remaining types 2023-05-30 19:43:37 +02:00
Robin Voetter 112acb1bda spirv: cache strings for debug names 2023-05-30 19:43:37 +02:00
Robin Voetter a72179fed0 spirv: translate structs to cache key 2023-05-30 19:43:37 +02:00
Robin Voetter 05f1392d8b spirv: translate vectors to cache key 2023-05-30 19:43:37 +02:00
Robin Voetter f13a6ee19e spirv: cache pointers 2023-05-30 19:43:36 +02:00
Robin Voetter e05ace7673 spirv: cache function prototypes 2023-05-30 19:43:36 +02:00
Robin Voetter 8c72ad5320 spirv: cache for ints 2023-05-30 19:43:36 +02:00
Robin Voetter aade6f1195 spirv: cache for floats 2023-05-30 19:43:36 +02:00
Robin Voetter b2a984cda6 spirv: basic setup for using new type constant cache 2023-05-30 19:43:36 +02:00
Robin Voetter 96a66d14a1 spirv: TypeConstantCache 2023-05-30 19:43:36 +02:00
Veikka Tuominen ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Veikka Tuominen 4a3539e449 llvm: fix vector type in vector_store_elem
Closes #15848
2023-05-25 15:57:30 +03:00
Ali Chraghi 3db3cf7790 std.sort: add pdqsort and heapsort 2023-05-23 17:55:59 -07:00
Veikka Tuominen 4ce1ae71a5 Merge pull request #15235 from Vexu/safety
add runtime safety for noreturn function returning
2023-05-23 13:34:52 +03:00
Tw a0652fb930 llvm: also generate metadata for extern global variables
Signed-off-by: Tw <tw19881113@gmail.com>
2023-05-22 23:04:19 +03:00