InternPool: use separate key for slices

This change eliminates some problematic recursive logic in InternPool,
and provides a safer API.
This commit is contained in:
mlugg
2024-02-01 16:58:52 +00:00
committed by Matthew Lugg
parent 5a3ae38f3b
commit 9eda6ccefc
11 changed files with 540 additions and 553 deletions

View File

@@ -855,18 +855,12 @@ const DeclGen = struct {
const int_ty = ty.intTagType(mod);
return try self.constant(int_ty, int_val, repr);
},
.ptr => |ptr| {
const ptr_ty = switch (ptr.len) {
.none => ty,
else => ty.slicePtrFieldType(mod),
};
const ptr_id = try self.constantPtr(ptr_ty, val);
if (ptr.len == .none) {
return ptr_id;
}
const len_id = try self.constant(Type.usize, Value.fromInterned(ptr.len), .indirect);
return try self.constructStruct(
.ptr => return self.constantPtr(ty, val),
.slice => |slice| {
const ptr_ty = ty.slicePtrFieldType(mod);
const ptr_id = try self.constantPtr(ptr_ty, Value.fromInterned(slice.ptr));
const len_id = try self.constant(Type.usize, Value.fromInterned(slice.len), .indirect);
return self.constructStruct(
ty,
&.{ ptr_ty, Type.usize },
&.{ ptr_id, len_id },