aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2023-01-24 13:35:10 +0200
committerAndrew Kelley <andrew@ziglang.org>2023-10-16 04:08:45 -0400
commit78855bd21866b515018259a2194e036e4b3120df (patch)
tree9d5df7cd0e5d909163475a5bdb30c94794460321 /src/type.zig
parentfbd90e487b4abe32422dc997467b1d81ad574d5d (diff)
downloadzig-78855bd21866b515018259a2194e036e4b3120df.tar.gz
zig-78855bd21866b515018259a2194e036e4b3120df.zip
make distinct error limit configurable
Closes #786
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/type.zig b/src/type.zig
index 5bdca27667..49582bd3c8 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -905,8 +905,11 @@ pub const Type = struct {
.opt_type => return abiAlignmentAdvancedOptional(ty, mod, strat),
.error_union_type => |info| return abiAlignmentAdvancedErrorUnion(ty, mod, strat, info.payload_type.toType()),
- // TODO revisit this when we have the concept of the error tag type
- .error_set_type, .inferred_error_set_type => return .{ .scalar = .@"2" },
+ .error_set_type, .inferred_error_set_type => {
+ const bits = mod.errorSetBits();
+ if (bits == 0) return AbiAlignmentAdvanced{ .scalar = .@"1" };
+ return .{ .scalar = intAbiAlignment(bits, target) };
+ },
// represents machine code; not a pointer
.func_type => |func_type| return .{
@@ -967,10 +970,11 @@ pub const Type = struct {
else => return .{ .scalar = .@"16" },
},
- // TODO revisit this when we have the concept of the error tag type
- .anyerror,
- .adhoc_inferred_error_set,
- => return .{ .scalar = .@"2" },
+ .anyerror, .adhoc_inferred_error_set => {
+ const bits = mod.errorSetBits();
+ if (bits == 0) return AbiAlignmentAdvanced{ .scalar = .@"1" };
+ return .{ .scalar = intAbiAlignment(bits, target) };
+ },
.void,
.type,
@@ -1284,8 +1288,11 @@ pub const Type = struct {
.opt_type => return ty.abiSizeAdvancedOptional(mod, strat),
- // TODO revisit this when we have the concept of the error tag type
- .error_set_type, .inferred_error_set_type => return AbiSizeAdvanced{ .scalar = 2 },
+ .error_set_type, .inferred_error_set_type => {
+ const bits = mod.errorSetBits();
+ if (bits == 0) return AbiSizeAdvanced{ .scalar = 0 };
+ return AbiSizeAdvanced{ .scalar = intAbiSize(bits, target) };
+ },
.error_union_type => |error_union_type| {
const payload_ty = error_union_type.payload_type.toType();
@@ -1379,10 +1386,11 @@ pub const Type = struct {
.enum_literal,
=> return AbiSizeAdvanced{ .scalar = 0 },
- // TODO revisit this when we have the concept of the error tag type
- .anyerror,
- .adhoc_inferred_error_set,
- => return AbiSizeAdvanced{ .scalar = 2 },
+ .anyerror, .adhoc_inferred_error_set => {
+ const bits = mod.errorSetBits();
+ if (bits == 0) return AbiSizeAdvanced{ .scalar = 0 };
+ return AbiSizeAdvanced{ .scalar = intAbiSize(bits, target) };
+ },
.prefetch_options => unreachable, // missing call to resolveTypeFields
.export_options => unreachable, // missing call to resolveTypeFields
@@ -1576,8 +1584,7 @@ pub const Type = struct {
return (try abiSizeAdvanced(ty, mod, strat)).scalar * 8;
},
- // TODO revisit this when we have the concept of the error tag type
- .error_set_type, .inferred_error_set_type => return 16,
+ .error_set_type, .inferred_error_set_type => return mod.errorSetBits(),
.error_union_type => {
// Optionals and error unions are not packed so their bitsize
@@ -1610,10 +1617,9 @@ pub const Type = struct {
.bool => return 1,
.void => return 0,
- // TODO revisit this when we have the concept of the error tag type
.anyerror,
.adhoc_inferred_error_set,
- => return 16,
+ => return mod.errorSetBits(),
.anyopaque => unreachable,
.type => unreachable,
@@ -2172,8 +2178,7 @@ pub const Type = struct {
while (true) switch (ty.toIntern()) {
.anyerror_type, .adhoc_inferred_error_set_type => {
- // TODO revisit this when error sets support custom int types
- return .{ .signedness = .unsigned, .bits = 16 };
+ return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
},
.usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
.isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
@@ -2192,8 +2197,9 @@ pub const Type = struct {
.enum_type => |enum_type| ty = enum_type.tag_ty.toType(),
.vector_type => |vector_type| ty = vector_type.child.toType(),
- // TODO revisit this when error sets support custom int types
- .error_set_type, .inferred_error_set_type => return .{ .signedness = .unsigned, .bits = 16 },
+ .error_set_type, .inferred_error_set_type => {
+ return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
+ },
.anon_struct_type => unreachable,