authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-03-01 09:21:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-03 11:49:54-08:00
log2ebeb0dbf30751cec6fd7cc8578a7aac4cb068ce
treeefe4ab8d109e68b8863b77119f31fbba260eea3a
parent904f774563c69feae9f73a8ee9637e3b760ecd3a

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.

3 files changed, 8 insertions(+), 8 deletions(-)

src/Module.zig+6-6
...@@ -4083,15 +4083,15 @@ pub fn namedFieldPtr(...@@ -4083,15 +4083,15 @@ pub fn namedFieldPtr(
4083 const child_type = try val.toType(scope.arena());4083 const child_type = try val.toType(scope.arena());
4084 switch (child_type.zigTypeTag()) {4084 switch (child_type.zigTypeTag()) {
4085 .ErrorSet => {4085 .ErrorSet => {
4086 var name: []const u8 = undefined;
4086 // TODO resolve inferred error sets4087 // TODO resolve inferred error sets
4087 const entry = if (val.castTag(.error_set)) |payload|4088 if (val.castTag(.error_set)) |payload|
4088 (payload.data.fields.getEntry(field_name) orelse4089 name = (payload.data.fields.getEntry(field_name) orelse return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).key
4089 return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).*
4090 else4090 else
4091 try mod.getErrorValue(field_name);4091 name = (try mod.getErrorValue(field_name)).key;
40924092
4093 const result_type = if (child_type.tag() == .anyerror)4093 const result_type = if (child_type.tag() == .anyerror)
4094 try Type.Tag.error_set_single.create(scope.arena(), entry.key)4094 try Type.Tag.error_set_single.create(scope.arena(), name)
4095 else4095 else
4096 child_type;4096 child_type;
40974097
...@@ -4100,7 +4100,7 @@ pub fn namedFieldPtr(...@@ -4100,7 +4100,7 @@ pub fn namedFieldPtr(
4100 .val = try Value.Tag.ref_val.create(4100 .val = try Value.Tag.ref_val.create(
4101 scope.arena(),4101 scope.arena(),
4102 try Value.Tag.@"error".create(scope.arena(), .{4102 try Value.Tag.@"error".create(scope.arena(), .{
4103 .name = entry.key,4103 .name = name,
4104 }),4104 }),
4105 ),4105 ),
4106 });4106 });
src/value.zig+1-1
...@@ -2144,7 +2144,7 @@ pub const Value = extern union {...@@ -2144,7 +2144,7 @@ pub const Value = extern union {
2144 base: Payload = .{ .tag = base_tag },2144 base: Payload = .{ .tag = base_tag },
2145 data: struct {2145 data: struct {
2146 /// TODO revisit this when we have the concept of the error tag type2146 /// TODO revisit this when we have the concept of the error tag type
2147 fields: std.StringHashMapUnmanaged(u16),2147 fields: std.StringHashMapUnmanaged(void),
2148 decl: *Module.Decl,2148 decl: *Module.Decl,
2149 },2149 },
2150 };2150 };
src/zir_sema.zig+1-1
...@@ -1165,7 +1165,7 @@ fn zirErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError...@@ -1165,7 +1165,7 @@ fn zirErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError
11651165
1166 for (inst.positionals.fields) |field_name| {1166 for (inst.positionals.fields) |field_name| {
1167 const entry = try mod.getErrorValue(field_name);1167 const entry = try mod.getErrorValue(field_name);
1168 if (payload.data.fields.fetchPutAssumeCapacity(entry.key, entry.value)) |prev| {1168 if (payload.data.fields.fetchPutAssumeCapacity(entry.key, {})) |_| {
1169 return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name});1169 return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name});
1170 }1170 }
1171 }1171 }