stage2: remove error number from error set map

This saves memory since it is already stored in module
as well as allowing for better threading.
Part 2 of what is outlined in #8079.
This commit is contained in:
jacob gw 2021-03-01 09:21:51 -05:00 committed by Andrew Kelley
parent 904f774563
commit 2ebeb0dbf3
3 changed files with 8 additions and 8 deletions

View File

@ -4083,15 +4083,15 @@ pub fn namedFieldPtr(
const child_type = try val.toType(scope.arena()); const child_type = try val.toType(scope.arena());
switch (child_type.zigTypeTag()) { switch (child_type.zigTypeTag()) {
.ErrorSet => { .ErrorSet => {
var name: []const u8 = undefined;
// TODO resolve inferred error sets // TODO resolve inferred error sets
const entry = if (val.castTag(.error_set)) |payload| if (val.castTag(.error_set)) |payload|
(payload.data.fields.getEntry(field_name) orelse name = (payload.data.fields.getEntry(field_name) orelse return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).key
return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).*
else else
try mod.getErrorValue(field_name); name = (try mod.getErrorValue(field_name)).key;
const result_type = if (child_type.tag() == .anyerror) const result_type = if (child_type.tag() == .anyerror)
try Type.Tag.error_set_single.create(scope.arena(), entry.key) try Type.Tag.error_set_single.create(scope.arena(), name)
else else
child_type; child_type;
@ -4100,7 +4100,7 @@ pub fn namedFieldPtr(
.val = try Value.Tag.ref_val.create( .val = try Value.Tag.ref_val.create(
scope.arena(), scope.arena(),
try Value.Tag.@"error".create(scope.arena(), .{ try Value.Tag.@"error".create(scope.arena(), .{
.name = entry.key, .name = name,
}), }),
), ),
}); });

View File

@ -2144,7 +2144,7 @@ pub const Value = extern union {
base: Payload = .{ .tag = base_tag }, base: Payload = .{ .tag = base_tag },
data: struct { data: struct {
/// TODO revisit this when we have the concept of the error tag type /// TODO revisit this when we have the concept of the error tag type
fields: std.StringHashMapUnmanaged(u16), fields: std.StringHashMapUnmanaged(void),
decl: *Module.Decl, decl: *Module.Decl,
}, },
}; };

View File

@ -1165,7 +1165,7 @@ fn zirErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError
for (inst.positionals.fields) |field_name| { for (inst.positionals.fields) |field_name| {
const entry = try mod.getErrorValue(field_name); const entry = try mod.getErrorValue(field_name);
if (payload.data.fields.fetchPutAssumeCapacity(entry.key, entry.value)) |prev| { if (payload.data.fields.fetchPutAssumeCapacity(entry.key, {})) |_| {
return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name}); return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name});
} }
} }