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
e94a81c951
InternPool: add optional values
2023-06-10 20:42:30 -07:00
Andrew Kelley
68b95a39b1
InternPool: add ptr-to-int value
...
Also modify coercion in Sema to be InternPool-aware by calling
getCoerced.
The unnecessary comptime logic in mod.intValue is deleted too
2023-06-10 20:42:30 -07:00
Andrew Kelley
fd674d95be
InternPool: add indexToKey for empty struct types
2023-06-10 20:42:30 -07:00
Andrew Kelley
ad06b249b6
Sema: introduce Value.enum_field_0
...
and use it to fix typeHasOnePossibleValue logic in two different places.
2023-06-10 20:42:30 -07:00
Andrew Kelley
8587e510e4
stage2: more InternPool related fixes
...
* make Sema.zirPtrType coerce the sentinel value against the element
type
* fix lazyAbiAlignment wrong result type
* typeHasOnePossibleValue no longer tries to create interned enum tag
value with integer zero, instead uses enum_field_index
* Type.ptr avoids trying to store typed null values into the intern
pool
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
2f9b7dc102
InternPool: add an int_u8 value encoding
...
On a simple input file, this had a total savings of 21% in the
InternPool:
Before:
int_positive: 427 occurrences, 8975 total bytes
After:
int_positive: 258 occurrences, 5426 total bytes
int_u8: 169 occurrences, 845 total bytes
2023-06-10 20:42:29 -07:00
Andrew Kelley
4fe0c583be
stage2: more InternPool-related fixes
2023-06-10 20:42:29 -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
Andrew Kelley
8699cdc3df
InternPool: fix UAF in getCoercedInt and add u16 int value encoding
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
Andrew Kelley
4c3c605e5f
InternPool: add getCoercedInt to avoid copy in Sema
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
9d9e1a2991
InternPool: implement indexToKey and equality for int values
2023-06-10 20:42:29 -07:00
Andrew Kelley
6c713b40f7
InternPool: add an encoding for arrays with sentinels
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
73720b6975
Sema: update onePossibleValue for 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
27d641eb35
stage2: fix interned integer value printing
2023-06-10 20:42:29 -07:00
Andrew Kelley
6350aabf9d
InternPool: fix bug in addLimbsExtraAssumeCapacity
2023-06-10 20:42:29 -07:00
Andrew Kelley
9626811725
Sema: add typeHasOnePossibleValue logic 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
08e9763951
stage2: add missing comptimeOnly logic for InternPool
2023-06-10 20:42:28 -07:00
Andrew Kelley
80bf5af345
fix AIR printing of interned constants
2023-06-10 20:42:28 -07:00
Andrew Kelley
3e6dd0da7a
stage2: add tmp_hack_arena for the InternPool transition
...
Temporarily used for some unfortunate allocations made by backends that
need to construct pointer types that can't be represented by the
InternPool. Once all types are migrated to be stored in the InternPool,
this can be removed.
2023-06-10 20:42:28 -07:00
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
70a4b76aca
std.builtin.AddressSpace: allocate one more bit to this enum
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
75cf06c187
std.mem.alignForwardGeneric: manually inline the assertions
...
This matches more directly the documentation comments, and makes it more
obvious what went wrong when an assertion fails.
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