aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
AgeCommit message (Collapse)Author
2023-06-10Air: remove constant tagJacob Young
Some uses have been moved to their own tag, the rest use interned. Also, finish porting comptime mutation to be more InternPool aware.
2023-06-10InternPool: fix crashes up to in progress comptime mutationJacob Young
2023-06-10InternPool: remove more legacy valuesJacob Young
Reinstate some tags that will be needed for comptime init.
2023-06-10InternPool: port most of value tagsJacob Young
2023-06-10InternPool: support int->comptime_int in getCoercedAndrew Kelley
2023-06-10InternPool: add lldb pretty printing for indicesJacob Young
2023-06-10InternPool: add missing logicJacob Young
2023-06-10InternPool: fix logic bugsJacob Young
2023-06-10InternPool: add more pointer valuesJacob Young
2023-06-10InternPool: fix coersion issuesJacob Young
2023-06-10InternPool: add missing ensureCapacity call with enumsAndrew Kelley
2023-06-10Sema: move `inferred_alloc_const/mut_type` to InternPoolAndrew Kelley
Now, all types are migrated to use `InternPool`. The `Type.Tag` enum is deleted in this commit.
2023-06-10compiler: remove var_args_param_type from SimpleTypeAndrew Kelley
This is now represented instead by a special `InternPool.Index.Tag` that has no corresponding type/value.
2023-06-10Value: add `intern` and `unintern` to facilitate code conversionJacob Young
This allows some code (like struct initializers) to use interned types while other code (such as comptime mutation) continues to use legacy types. With these changes, an `zig build-obj empty.zig` gets to a crash on missing interned error union types.
2023-06-10Sema: port Value.decl_ptr to InternPoolJacob Young
2023-06-10InternPool: add repeated aggregate storageJacob Young
2023-06-10compiler: move error union types and error set types to InternPoolAndrew Kelley
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-10compiler: eliminate legacy Type.Tag.pointerAndrew Kelley
Now pointer types are stored only in InternPool.
2023-06-10compiler: move `anyframe->T` to InternPoolAndrew Kelley
Also I moved `anyframe` from being represented by `SimpleType` to being represented by the `none` tag of `anyframe_type` because most code wants to handle these two types together.
2023-06-10stage2: move function types to InternPoolAndrew Kelley
2023-06-10stage2: encode one-possible-value tuple speciallyAndrew Kelley
Anonymous structs and anonymous tuples can be stored via a only_possible_value tag because their type encodings, by definition, will have every value specified, which can be used to populate the fields slice in `Key.Aggregate`. Also fix `isTupleOrAnonStruct`.
2023-06-10stage2: move anon tuples and anon structs to InternPoolAndrew Kelley
2023-06-10stage2: move enum tag values into the InternPoolAndrew Kelley
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-10InternPool: transition float valuesmlugg
2023-06-10stage2: move enum types into the InternPoolAndrew Kelley
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-10InternPool: fix deinit leaking inner mapsAndrew Kelley
2023-06-10InternPool: ability to encode enumsAndrew Kelley
This introduces a string table into InternPool as well as a curious new field called `maps` which is an array list of array hash maps with void/void key/value. Some types such as enums, structs, and unions need to store mappings from field names to field index, or value to field index. In such cases, they will store the underlying field names and values directly, relying on one of these maps, stored separately, to provide lookup. This allows the InternPool to be serialized via simple array copies, omitting all the maps, which are only used for optimizing lookup based on field name or field value. When the InternPool is deserialized it can be loaded via simple array copies, and then as a post-processing step the field name maps can be generated as extra metadata that is tacked on. This commit provides two encodings for enums - one when the integer tag type is explicitly provided and one when it is not. This is simpler than the previous setup, which has three encodings. Previous sizes: * EnumSimple: 40 bytes + 16 bytes per field * EnumNumbered: 80 bytes + 24 bytes per field * EnumFull: 184 bytes + 24 bytes per field Sizes after this commit: * type_enum_explicit: 24 bytes + 8 bytes per field * type_enum_auto: 16 bytes + 4 bytes per field
2023-06-10stage2: move union types and values to InternPoolAndrew Kelley
2023-06-10stage2: move struct types and aggregate values to InternPoolAndrew Kelley
2023-06-10stage2: move opaque types to InternPoolAndrew Kelley
2023-06-10InternPool: add optional valuesAndrew Kelley
2023-06-10InternPool: add ptr-to-int valueAndrew Kelley
Also modify coercion in Sema to be InternPool-aware by calling getCoerced. The unnecessary comptime logic in mod.intValue is deleted too
2023-06-10InternPool: add indexToKey for empty struct typesAndrew Kelley
2023-06-10InternPool: add an int_u8 value encodingAndrew Kelley
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-10InternPool: fix UAF in getCoercedInt and add u16 int value encodingAndrew Kelley
2023-06-10InternPool: add getCoercedInt to avoid copy in SemaAndrew Kelley
2023-06-10InternPool: implement indexToKey and equality for int valuesAndrew Kelley
2023-06-10InternPool: add an encoding for arrays with sentinelsAndrew Kelley
2023-06-10stage2: move integer values to InternPoolAndrew Kelley
2023-06-10InternPool: fix bug in addLimbsExtraAssumeCapacityAndrew Kelley
2023-06-10InternPool: add a slice encodingAndrew Kelley
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-10stage2: add tmp_hack_arena for the InternPool transitionAndrew Kelley
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-10InternPool: add a dump functionAndrew Kelley
So we can see stats
2023-06-10stage2: migrate many pointer types to the InternPoolAndrew Kelley
2023-06-10InternPool: enhance integer valuesAndrew Kelley
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-10InternPool: add the missing pointer dataAndrew Kelley
2023-06-10stage2: move many Type encodings to InternPoolAndrew Kelley
Notably, `vector`. Additionally, all alternate encodings of `pointer`, `optional`, and `array`.
2023-06-10Type.isSlice: make it InternPool awareAndrew Kelley
2023-06-10stage2: move most simple values to InternPoolAndrew Kelley
2023-06-10InternPool: implement resolveTypeFieldsAndrew Kelley