compiler: namespace type equivalence based on AST node + captures

This implements the accepted proposal #18816. Namespace-owning types
(struct, enum, union, opaque) are no longer unique whenever analysed;
instead, their identity is determined based on their AST node and the
set of values they capture.

Reified types (`@Type`) are deduplicated based on the structure of the
type created. For instance, if two structs are created by the same
reification with identical fields, layout, etc, they will be the same
type.

This commit does not produce a working compiler; the next commit, adding
captures for decl references, is necessary. It felt appropriate to split
this up.

Resolves: #18816
This commit is contained in:
mlugg
2024-03-05 06:02:58 +00:00
parent 8ec6f730ef
commit d0c022f734
5 changed files with 1725 additions and 1278 deletions

View File

@@ -3548,12 +3548,11 @@ pub const Object = struct {
);
return ty;
},
.opaque_type => |opaque_type| {
.opaque_type => {
const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
if (!gop.found_existing) {
const name = try o.builder.string(ip.stringToSlice(
try mod.opaqueFullyQualifiedName(opaque_type),
));
const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);
const name = try o.builder.string(ip.stringToSlice(try decl.getFullyQualifiedName(mod)));
gop.value_ptr.* = try o.builder.opaqueType(name);
}
return gop.value_ptr.*;