| author | |
| committer | |
| log | 2ebeb0dbf30751cec6fd7cc8578a7aac4cb068ce |
| tree | efe4ab8d109e68b8863b77119f31fbba260eea3a |
| parent | 904f774563c69feae9f73a8ee9637e3b760ecd3a |
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 | 4083 | const child_type = try val.toType(scope.arena()); |
| 4084 | 4084 | switch (child_type.zigTypeTag()) { |
| 4085 | 4085 | .ErrorSet => { |
| 4086 | var name: []const u8 = undefined; | |
| 4086 | 4087 | // TODO resolve inferred error sets |
| 4087 | const entry = if (val.castTag(.error_set)) |payload| | |
| 4088 | (payload.data.fields.getEntry(field_name) orelse | |
| 4089 | return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).* | |
| 4088 | if (val.castTag(.error_set)) |payload| | |
| 4089 | name = (payload.data.fields.getEntry(field_name) orelse return mod.fail(scope, src, "no error named '{s}' in '{}'", .{ field_name, child_type })).key | |
| 4090 | 4090 | else |
| 4091 | try mod.getErrorValue(field_name); | |
| 4091 | name = (try mod.getErrorValue(field_name)).key; | |
| 4092 | 4092 | |
| 4093 | 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 | 4095 | else |
| 4096 | 4096 | child_type; |
| 4097 | 4097 | |
| ... | ... | @@ -4100,7 +4100,7 @@ pub fn namedFieldPtr( |
| 4100 | 4100 | .val = try Value.Tag.ref_val.create( |
| 4101 | 4101 | scope.arena(), |
| 4102 | 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 | 2144 | base: Payload = .{ .tag = base_tag }, |
| 2145 | 2145 | data: struct { |
| 2146 | 2146 | /// TODO revisit this when we have the concept of the error tag type |
| 2147 | fields: std.StringHashMapUnmanaged(u16), | |
| 2147 | fields: std.StringHashMapUnmanaged(void), | |
| 2148 | 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 | 1165 | |
| 1166 | 1166 | for (inst.positionals.fields) |field_name| { |
| 1167 | 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 | 1169 | return mod.fail(scope, inst.base.src, "duplicate error: '{s}'", .{field_name}); |
| 1170 | 1170 | } |
| 1171 | 1171 | } |