authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-02-26 09:56:16-05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-28 22:01:13+02:00
log58b14d01aeb919989d1750a8894350a07fd4e844
tree574dbe169aa0fba72b8901333a82c9e3e5d11c51
parent1f17221bc4e17bcd7116fe12ab3f939346179799

stage2: remove value field from error

This saves memory and from what I have heard allows threading to be easier.

3 files changed, 2 insertions(+), 5 deletions(-)

src/Module.zig-1
...@@ -4101,7 +4101,6 @@ pub fn namedFieldPtr(...@@ -4101,7 +4101,6 @@ pub fn namedFieldPtr(
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 = entry.key,
4104 .value = entry.value,
4105 }),4104 }),
4106 ),4105 ),
4107 });4106 });
src/value.zig-2
...@@ -1561,7 +1561,6 @@ pub const Value = extern union {...@@ -1561,7 +1561,6 @@ pub const Value = extern union {
1561 .@"error" => {1561 .@"error" => {
1562 const payload = self.castTag(.@"error").?.data;1562 const payload = self.castTag(.@"error").?.data;
1563 hasher.update(payload.name);1563 hasher.update(payload.name);
1564 std.hash.autoHash(&hasher, payload.value);
1565 },1564 },
1566 .error_union => {1565 .error_union => {
1567 const payload = self.castTag(.error_union).?.data;1566 const payload = self.castTag(.error_union).?.data;
...@@ -2157,7 +2156,6 @@ pub const Value = extern union {...@@ -2157,7 +2156,6 @@ pub const Value = extern union {
2157 /// duration of the compilation.2156 /// duration of the compilation.
2158 /// TODO revisit this when we have the concept of the error tag type2157 /// TODO revisit this when we have the concept of the error tag type
2159 name: []const u8,2158 name: []const u8,
2160 value: u16,
2161 },2159 },
2162 };2160 };
21632161
src/zir_sema.zig+2-2
...@@ -1178,7 +1178,6 @@ fn zirErrorValue(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorValue) InnerE...@@ -1178,7 +1178,6 @@ fn zirErrorValue(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorValue) InnerE
1178 .ty = result_type,1178 .ty = result_type,
1179 .val = try Value.Tag.@"error".create(scope.arena(), .{1179 .val = try Value.Tag.@"error".create(scope.arena(), .{
1180 .name = entry.key,1180 .name = entry.key,
1181 .value = entry.value,
1182 }),1181 }),
1183 });1182 });
1184}1183}
...@@ -2215,7 +2214,8 @@ fn zirCmp(...@@ -2215,7 +2214,8 @@ fn zirCmp(
2215 }2214 }
2216 if (rhs.value()) |rval| {2215 if (rhs.value()) |rval| {
2217 if (lhs.value()) |lval| {2216 if (lhs.value()) |lval| {
2218 return mod.constBool(scope, inst.base.src, (lval.castTag(.@"error").?.data.value == rval.castTag(.@"error").?.data.value) == (op == .eq));2217 // TODO optimisation oppurtunity: evaluate if std.mem.eql is faster with the names, or calling to Module.getErrorValue to get the values and then compare them is faster
2218 return mod.constBool(scope, inst.base.src, std.mem.eql(u8, lval.castTag(.@"error").?.data.name, rval.castTag(.@"error").?.data.name) == (op == .eq));
2219 }2219 }
2220 }2220 }
2221 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between runtime errors", .{});2221 return mod.fail(scope, inst.base.src, "TODO implement equality comparison between runtime errors", .{});