From 2ffef605c75b62ba49e21bfb3256537a4a2c0a5e Mon Sep 17 00:00:00 2001 From: mlugg Date: Sun, 7 May 2023 22:12:04 +0100 Subject: 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. --- src/Module.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Module.zig') 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; -- cgit v1.2.3