From 50bebb9e21c7e131522bec467b477ed7f55feb91 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 10 May 2023 20:47:33 -0700 Subject: InternPool: ability to encode enums 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 --- src/Sema.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Sema.zig') diff --git a/src/Sema.zig b/src/Sema.zig index 76ac887c06..e9bf66565e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -31760,6 +31760,8 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { .opaque_type => false, + .enum_type => @panic("TODO"), + // values, not types .un => unreachable, .simple_value => unreachable, @@ -33293,6 +33295,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { return only.toValue(); }, .opaque_type => null, + .enum_type => @panic("TODO"), // values, not types .un => unreachable, @@ -33862,6 +33865,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { }, .opaque_type => false, + .enum_type => @panic("TODO"), // values, not types .un => unreachable, -- cgit v1.2.3