aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-05-07 22:12:04 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:42:29 -0700
commit2ffef605c75b62ba49e21bfb3256537a4a2c0a5e (patch)
treeba18403418bcd0c1e6f6f52f9effa51dfd91c878 /src/Module.zig
parent4c3c605e5f53c91430efac821ce1b863cbb5bf06 (diff)
downloadzig-2ffef605c75b62ba49e21bfb3256537a4a2c0a5e.tar.gz
zig-2ffef605c75b62ba49e21bfb3256537a4a2c0a5e.zip
Replace uses of Value.zero, Value.one, Value.negative_one
This is a bit nasty, mainly because Type.onePossibleValue is now errorable, which is a quite viral change.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig
index f56235c933..3f5dc8039e 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5750,7 +5750,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
const arg_val = if (!arg_tv.val.isGenericPoison())
arg_tv.val
- else if (arg_tv.ty.onePossibleValue(mod)) |opv|
+ else if (try arg_tv.ty.onePossibleValue(mod)) |opv|
opv
else
break :t arg_tv.ty;
@@ -6887,6 +6887,16 @@ pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
}
pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
+ if (std.debug.runtime_safety) {
+ // TODO: decide if this also works for ABI int types like enums
+ const tag = ty.zigTypeTag(mod);
+ assert(tag == .Int or tag == .ComptimeInt);
+ }
+ if (@TypeOf(x) == comptime_int) {
+ if (comptime std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted);
+ if (comptime std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted);
+ @compileError("Out-of-range comptime_int passed to Module.intValue");
+ }
if (std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted);
if (std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted);
var limbs_buffer: [4]usize = undefined;