aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2023-01-24 13:35:10 +0200
committerVeikka Tuominen <git@vexu.eu>2023-10-21 12:36:29 +0300
commitbf61c5c0656e3b2198fb009fe5cc59f55263ceae (patch)
treed72d4f475af2d6ba6cbc4080ecb6e8b0d7a24c3d /src/value.zig
parent3d6e63337164b42fec4df55687071be38d33dce9 (diff)
downloadzig-bf61c5c0656e3b2198fb009fe5cc59f55263ceae.tar.gz
zig-bf61c5c0656e3b2198fb009fe5cc59f55263ceae.zip
make distinct error limit configurable
Closes #786
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/value.zig b/src/value.zig
index 2c4a88da17..15289de6b2 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -701,15 +701,20 @@ pub const Value = struct {
}
},
.ErrorSet => {
- // TODO revisit this when we have the concept of the error tag type
- const Int = u16;
+ const bits = mod.errorSetBits();
+ const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
+
const name = switch (ip.indexToKey(val.toIntern())) {
.err => |err| err.name,
.error_union => |error_union| error_union.val.err_name,
else => unreachable,
};
- const int = @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(name).?));
- std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @as(Int, @intCast(int)), endian);
+ var bigint_buffer: BigIntSpace = undefined;
+ const bigint = BigIntMutable.init(
+ &bigint_buffer.limbs,
+ mod.global_error_set.getIndex(name).?,
+ ).toConst();
+ bigint.writeTwosComplement(buffer[0..byte_count], endian);
},
.Union => switch (ty.containerLayout(mod)) {
.Auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already
@@ -987,10 +992,12 @@ pub const Value = struct {
}
},
.ErrorSet => {
- // TODO revisit this when we have the concept of the error tag type
- const Int = u16;
- const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);
- const name = mod.global_error_set.keys()[@as(usize, @intCast(int))];
+ const bits = mod.errorSetBits();
+ const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
+ const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
+ const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
+ const name = mod.global_error_set.keys()[@intCast(index)];
+
return (try mod.intern(.{ .err = .{
.ty = ty.toIntern(),
.name = name,