aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-10 20:47:33 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:42:30 -0700
commit50bebb9e21c7e131522bec467b477ed7f55feb91 (patch)
tree91fc8d696f772b909218c6544bc03d9c9f41b448 /src/Sema.zig
parent1c7095cb7dfcba3537edf3624a61046c9b772b1f (diff)
downloadzig-50bebb9e21c7e131522bec467b477ed7f55feb91.tar.gz
zig-50bebb9e21c7e131522bec467b477ed7f55feb91.zip
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
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig4
1 files changed, 4 insertions, 0 deletions
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,