aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
AgeCommit message (Collapse)Author
2023-06-10behavior: additional llvm fixesJacob Young
2023-06-10Module: move memoized data to the intern poolJacob Young
This avoids memory management bugs with the previous implementation.
2023-06-10behavior: pass more tests on llvm againJacob Young
2023-06-10behavior: get more test cases passing with llvmJacob Young
2023-06-10InternPool: optimize zigTypeTag()Andrew Kelley
This is a particularly hot function, so we operate directly on encodings rather than the more straightforward implementation of calling `indexToKey`. I measured this as 1.05 ± 0.04 times faster than the previous commit with a ReleaseFast build against hello world (which includes std.debug and formatted printing). I also profiled the function and found that zigTypeTag() went from being a major caller of `indexToKey` to being completely insignificant due to being so fast.
2023-06-10InternPool: correct the logic for struct size dumpAndrew Kelley
2023-06-10InternPool: fix build-exe and compiler-rt crashesJacob Young
2023-06-10InternPool: fix more crashesJacob Young
2023-06-10InternPool: fix enough crashes to run `build-obj` on a simple programJacob Young
2023-06-10Sema: inferred allocations no longer abuse type/value systemAndrew Kelley
Previously, there were types and values for inferred allocations and a lot of special-case handling. Now, instead, the special casing is limited to AIR instructions for these use cases. Instead of storing data in Value payloads, the data is now stored in AIR instruction data as well as the previously `void` value type of the `unresolved_inferred_allocs` hash map.
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