authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-06 19:20:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:29-07:00
log75900ec1b5a250935a6abe050a006738fba99e66
tree9d3dd571b59648a585c3ce5bcdb2dbb50a574d58
parent73720b6975e2650ece48cc5f38495c091360c6c9

stage2: move integer values to InternPool


16 files changed, 1168 insertions(+), 1727 deletions(-)

src/Air.zig+1
......@@ -913,6 +913,7 @@ pub const Inst = struct {
913913 zero_u8 = @enumToInt(InternPool.Index.zero_u8),
914914 one = @enumToInt(InternPool.Index.one),
915915 one_usize = @enumToInt(InternPool.Index.one_usize),
916 negative_one = @enumToInt(InternPool.Index.negative_one),
916917 calling_convention_c = @enumToInt(InternPool.Index.calling_convention_c),
917918 calling_convention_inline = @enumToInt(InternPool.Index.calling_convention_inline),
918919 void_value = @enumToInt(InternPool.Index.void_value),
src/InternPool.zig+13-5
......@@ -390,6 +390,8 @@ pub const Index = enum(u32) {
390390 one,
391391 /// `1` (usize)
392392 one_usize,
393 /// `-1` (comptime_int)
394 negative_one,
393395 /// `std.builtin.CallingConvention.C`
394396 calling_convention_c,
395397 /// `std.builtin.CallingConvention.Inline`
......@@ -624,6 +626,11 @@ pub const static_keys = [_]Key{
624626 .storage = .{ .u64 = 1 },
625627 } },
626628
629 .{ .int = .{
630 .ty = .comptime_int_type,
631 .storage = .{ .i64 = -1 },
632 } },
633
627634 .{ .enum_tag = .{
628635 .ty = .calling_convention_type,
629636 .tag = .{
......@@ -999,23 +1006,23 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
9991006 .type_error_union => @panic("TODO"),
10001007 .type_enum_simple => @panic("TODO"),
10011008 .simple_internal => @panic("TODO"),
1002 .int_u32 => return .{ .int = .{
1009 .int_u32 => .{ .int = .{
10031010 .ty = .u32_type,
10041011 .storage = .{ .u64 = data },
10051012 } },
1006 .int_i32 => return .{ .int = .{
1013 .int_i32 => .{ .int = .{
10071014 .ty = .i32_type,
10081015 .storage = .{ .i64 = @bitCast(i32, data) },
10091016 } },
1010 .int_usize => return .{ .int = .{
1017 .int_usize => .{ .int = .{
10111018 .ty = .usize_type,
10121019 .storage = .{ .u64 = data },
10131020 } },
1014 .int_comptime_int_u32 => return .{ .int = .{
1021 .int_comptime_int_u32 => .{ .int = .{
10151022 .ty = .comptime_int_type,
10161023 .storage = .{ .u64 = data },
10171024 } },
1018 .int_comptime_int_i32 => return .{ .int = .{
1025 .int_comptime_int_i32 => .{ .int = .{
10191026 .ty = .comptime_int_type,
10201027 .storage = .{ .i64 = @bitCast(i32, data) },
10211028 } },
......@@ -1137,6 +1144,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
11371144
11381145 .int => |int| b: {
11391146 switch (int.ty) {
1147 .none => unreachable,
11401148 .u32_type => switch (int.storage) {
11411149 .big_int => |big_int| {
11421150 if (big_int.to(u32)) |casted| {
src/Module.zig+50-23
......@@ -6597,7 +6597,7 @@ pub fn populateTestFunctions(
65976597 field_vals.* = .{
65986598 try Value.Tag.slice.create(arena, .{
65996599 .ptr = try Value.Tag.decl_ref.create(arena, test_name_decl_index),
6600 .len = try Value.Tag.int_u64.create(arena, test_name_slice.len),
6600 .len = try mod.intValue(Type.usize, test_name_slice.len),
66016601 }), // name
66026602 try Value.Tag.decl_ref.create(arena, test_decl_index), // func
66036603 Value.null, // async_frame_size
......@@ -6628,7 +6628,7 @@ pub fn populateTestFunctions(
66286628 new_var.* = decl.val.castTag(.variable).?.data.*;
66296629 new_var.init = try Value.Tag.slice.create(arena, .{
66306630 .ptr = try Value.Tag.decl_ref.create(arena, array_decl_index),
6631 .len = try Value.Tag.int_u64.create(arena, mod.test_functions.count()),
6631 .len = try mod.intValue(Type.usize, mod.test_functions.count()),
66326632 });
66336633 const new_val = try Value.Tag.variable.create(arena, new_var);
66346634
......@@ -6875,6 +6875,38 @@ pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
68756875 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });
68766876}
68776877
6878pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
6879 if (std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted);
6880 if (std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted);
6881 var limbs_buffer: [4]usize = undefined;
6882 var big_int = BigIntMutable.init(&limbs_buffer, x);
6883 return intValue_big(mod, ty, big_int.toConst());
6884}
6885
6886pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Value {
6887 const i = try intern(mod, .{ .int = .{
6888 .ty = ty.ip_index,
6889 .storage = .{ .big_int = x },
6890 } });
6891 return i.toValue();
6892}
6893
6894pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6895 const i = try intern(mod, .{ .int = .{
6896 .ty = ty.ip_index,
6897 .storage = .{ .u64 = x },
6898 } });
6899 return i.toValue();
6900}
6901
6902pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
6903 const i = try intern(mod, .{ .int = .{
6904 .ty = ty.ip_index,
6905 .storage = .{ .i64 = x },
6906 } });
6907 return i.toValue();
6908}
6909
68786910pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
68796911 return intType(mod, .unsigned, Type.smallestUnsignedBits(max));
68806912}
......@@ -6907,32 +6939,27 @@ pub fn intFittingRange(mod: *Module, min: Value, max: Value) !Type {
69076939/// Asserts that `val` is not undef. If `val` is negative, asserts that `sign` is true.
69086940pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
69096941 assert(!val.isUndef());
6910 switch (val.tag()) {
6911 .int_big_positive => {
6912 const limbs = val.castTag(.int_big_positive).?.data;
6913 const big: std.math.big.int.Const = .{ .limbs = limbs, .positive = true };
6914 return @intCast(u16, big.bitCountAbs() + @boolToInt(sign));
6915 },
6916 .int_big_negative => {
6917 const limbs = val.castTag(.int_big_negative).?.data;
6918 // Zero is still a possibility, in which case unsigned is fine
6919 for (limbs) |limb| {
6920 if (limb != 0) break;
6921 } else return 0; // val == 0
6922 assert(sign);
6923 const big: std.math.big.int.Const = .{ .limbs = limbs, .positive = false };
6924 return @intCast(u16, big.bitCountTwosComp());
6925 },
6926 .int_i64 => {
6927 const x = val.castTag(.int_i64).?.data;
6928 if (x >= 0) return Type.smallestUnsignedBits(@intCast(u64, x));
6942
6943 const key = mod.intern_pool.indexToKey(val.ip_index);
6944 switch (key.int.storage) {
6945 .i64 => |x| {
6946 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted);
69296947 assert(sign);
6948 // Protect against overflow in the following negation.
6949 if (x == std.math.minInt(i64)) return 64;
69306950 return Type.smallestUnsignedBits(@intCast(u64, -x - 1)) + 1;
69316951 },
6932 else => {
6933 const x = val.toUnsignedInt(mod);
6952 .u64 => |x| {
69346953 return Type.smallestUnsignedBits(x) + @boolToInt(sign);
69356954 },
6955 .big_int => |big| {
6956 if (big.positive) return @intCast(u16, big.bitCountAbs() + @boolToInt(sign));
6957
6958 // Zero is still a possibility, in which case unsigned is fine
6959 if (big.eqZero()) return 0;
6960
6961 return @intCast(u16, big.bitCountTwosComp());
6962 },
69366963 }
69376964}
69386965
src/RangeSet.zig+3-3
......@@ -35,8 +35,8 @@ pub fn add(
3535 src: SwitchProngSrc,
3636) !?SwitchProngSrc {
3737 for (self.ranges.items) |range| {
38 if (last.compareAll(.gte, range.first, ty, self.module) and
39 first.compareAll(.lte, range.last, ty, self.module))
38 if (last.compareScalar(.gte, range.first, ty, self.module) and
39 first.compareScalar(.lte, range.last, ty, self.module))
4040 {
4141 return range.src; // They overlap.
4242 }
......@@ -53,7 +53,7 @@ const LessThanContext = struct { ty: Type, module: *Module };
5353
5454/// Assumes a and b do not overlap
5555fn lessThan(ctx: LessThanContext, a: Range, b: Range) bool {
56 return a.first.compareAll(.lt, b.first, ctx.ty, ctx.module);
56 return a.first.compareScalar(.lt, b.first, ctx.ty, ctx.module);
5757}
5858
5959pub fn spans(self: *RangeSet, first: Value, last: Value, ty: Type) !bool {
src/Sema.zig+298-440
......@@ -2995,7 +2995,6 @@ fn zirEnumDecl(
29952995 var cur_bit_bag: u32 = undefined;
29962996 var field_i: u32 = 0;
29972997 var last_tag_val: ?Value = null;
2998 var tag_val_buf: Value.Payload.U64 = undefined;
29992998 while (field_i < fields_len) : (field_i += 1) {
30002999 if (field_i % 32 == 0) {
30013000 cur_bit_bag = sema.code.extra[bit_bag_index];
......@@ -3084,11 +3083,7 @@ fn zirEnumDecl(
30843083 return sema.failWithOwnedErrorMsg(msg);
30853084 }
30863085 } else {
3087 tag_val_buf = .{
3088 .base = .{ .tag = .int_u64 },
3089 .data = field_i,
3090 };
3091 last_tag_val = Value.initPayload(&tag_val_buf.base);
3086 last_tag_val = try mod.intValue(enum_obj.tag_ty, field_i);
30923087 }
30933088
30943089 if (!(try sema.intFitsInType(last_tag_val.?, enum_obj.tag_ty, null))) {
......@@ -5180,16 +5175,23 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
51805175 const tracy = trace(@src());
51815176 defer tracy.end();
51825177
5183 const arena = sema.arena;
5178 const mod = sema.mod;
51845179 const int = sema.code.instructions.items(.data)[inst].str;
51855180 const byte_count = int.len * @sizeOf(std.math.big.Limb);
51865181 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
5187 const limbs = try arena.alloc(std.math.big.Limb, int.len);
5182
5183 // TODO: this allocation and copy is only needed because the limbs may be unaligned.
5184 // If ZIR is adjusted so that big int limbs are guaranteed to be aligned, these
5185 // two lines can be removed.
5186 const limbs = try sema.arena.alloc(std.math.big.Limb, int.len);
51885187 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
51895188
51905189 return sema.addConstant(
51915190 Type.comptime_int,
5192 try Value.Tag.int_big_positive.create(arena, limbs),
5191 try mod.intValue_big(Type.comptime_int, .{
5192 .limbs = limbs,
5193 .positive = true,
5194 }),
51935195 );
51945196}
51955197
......@@ -8095,6 +8097,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
80958097 const tracy = trace(@src());
80968098 defer tracy.end();
80978099
8100 const mod = sema.mod;
80988101 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
80998102 const src = LazySrcLoc.nodeOffset(extra.node);
81008103 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
......@@ -8107,12 +8110,13 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
81078110 }
81088111 switch (val.tag()) {
81098112 .@"error" => {
8110 const payload = try sema.arena.create(Value.Payload.U64);
8111 payload.* = .{
8112 .base = .{ .tag = .int_u64 },
8113 .data = (try sema.mod.getErrorValue(val.castTag(.@"error").?.data.name)).value,
8114 };
8115 return sema.addConstant(Type.err_int, Value.initPayload(&payload.base));
8113 return sema.addConstant(
8114 Type.err_int,
8115 try mod.intValue(
8116 Type.err_int,
8117 (try sema.mod.getErrorValue(val.castTag(.@"error").?.data.name)).value,
8118 ),
8119 );
81168120 },
81178121
81188122 // This is not a valid combination with the type `anyerror`.
......@@ -8280,8 +8284,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
82808284 }
82818285
82828286 if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| {
8283 var buffer: Value.Payload.U64 = undefined;
8284 const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer);
8287 const val = try enum_tag_val.enumToInt(enum_tag_ty, mod);
82858288 return sema.addConstant(int_tag_ty, try val.copy(sema.arena));
82868289 }
82878290
......@@ -9685,7 +9688,7 @@ fn intCast(
96859688 // range shrinkage
96869689 // requirement: int value fits into target type
96879690 if (wanted_value_bits < actual_value_bits) {
9688 const dest_max_val_scalar = try dest_scalar_ty.maxInt(sema.arena, mod);
9691 const dest_max_val_scalar = try dest_scalar_ty.maxIntScalar(mod);
96899692 const dest_max_val = if (is_vector)
96909693 try Value.Tag.repeated.create(sema.arena, dest_max_val_scalar)
96919694 else
......@@ -9946,7 +9949,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99469949 }
99479950
99489951 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
9949 return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target));
9952 return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, mod));
99509953 }
99519954 if (dest_is_comptime_float) {
99529955 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{});
......@@ -10470,7 +10473,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1047010473 // Duplicate checking variables later also used for `inline else`.
1047110474 var seen_enum_fields: []?Module.SwitchProngSrc = &.{};
1047210475 var seen_errors = SwitchErrorSet.init(gpa);
10473 var range_set = RangeSet.init(gpa, sema.mod);
10476 var range_set = RangeSet.init(gpa, mod);
1047410477 var true_count: u8 = 0;
1047510478 var false_count: u8 = 0;
1047610479
......@@ -10596,11 +10599,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1059610599 .{field_name},
1059710600 );
1059810601 }
10599 try sema.mod.errNoteNonLazy(
10600 operand_ty.declSrcLoc(sema.mod),
10602 try mod.errNoteNonLazy(
10603 operand_ty.declSrcLoc(mod),
1060110604 msg,
1060210605 "enum '{}' declared here",
10603 .{operand_ty.fmt(sema.mod)},
10606 .{operand_ty.fmt(mod)},
1060410607 );
1060510608 break :msg msg;
1060610609 };
......@@ -10827,7 +10830,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1082710830 defer arena.deinit();
1082810831
1082910832 const min_int = try operand_ty.minInt(arena.allocator(), mod);
10830 const max_int = try operand_ty.maxInt(arena.allocator(), mod);
10833 const max_int = try operand_ty.maxIntScalar(mod);
1083110834 if (try range_set.spans(min_int, max_int, operand_ty)) {
1083210835 if (special_prong == .@"else") {
1083310836 return sema.fail(
......@@ -10926,13 +10929,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1092610929 block,
1092710930 src,
1092810931 "else prong required when switching on type '{}'",
10929 .{operand_ty.fmt(sema.mod)},
10932 .{operand_ty.fmt(mod)},
1093010933 );
1093110934 }
1093210935
1093310936 var seen_values = ValueSrcMap.initContext(gpa, .{
1093410937 .ty = operand_ty,
10935 .mod = sema.mod,
10938 .mod = mod,
1093610939 });
1093710940 defer seen_values.deinit();
1093810941
......@@ -10996,7 +10999,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1099610999 .ComptimeFloat,
1099711000 .Float,
1099811001 => return sema.fail(block, operand_src, "invalid switch operand type '{}'", .{
10999 operand_ty.fmt(sema.mod),
11002 operand_ty.fmt(mod),
1100011003 }),
1100111004 }
1100211005
......@@ -11054,7 +11057,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1105411057 const item = try sema.resolveInst(item_ref);
1105511058 // Validation above ensured these will succeed.
1105611059 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11057 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
11060 if (operand_val.eql(item_val, operand_ty, mod)) {
1105811061 if (is_inline) child_block.inline_case_capture = operand;
1105911062
1106011063 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -11080,7 +11083,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1108011083 const item = try sema.resolveInst(item_ref);
1108111084 // Validation above ensured these will succeed.
1108211085 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11083 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
11086 if (operand_val.eql(item_val, operand_ty, mod)) {
1108411087 if (is_inline) child_block.inline_case_capture = operand;
1108511088
1108611089 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -11128,7 +11131,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1112811131 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand)) {
1112911132 return Air.Inst.Ref.unreachable_value;
1113011133 }
11131 if (sema.mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and
11134 if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and
1113211135 (!operand_ty.isNonexhaustiveEnum() or union_originally))
1113311136 {
1113411137 try sema.zirDbgStmt(block, cond_dbg_node_index);
......@@ -11182,7 +11185,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1118211185
1118311186 const analyze_body = if (union_originally) blk: {
1118411187 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
11185 const field_ty = maybe_union_ty.unionFieldType(item_val, sema.mod);
11188 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1118611189 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1118711190 } else true;
1118811191
......@@ -11245,9 +11248,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1124511248 const item_last_ref = try sema.resolveInst(last_ref);
1124611249 const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
1124711250
11248 while (item.compareAll(.lte, item_last, operand_ty, sema.mod)) : ({
11251 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
1124911252 // Previous validation has resolved any possible lazy values.
11250 item = try sema.intAddScalar(item, Value.one);
11253 item = try sema.intAddScalar(item, Value.one, operand_ty);
1125111254 }) {
1125211255 cases_len += 1;
1125311256
......@@ -11260,7 +11263,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1126011263 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
1126111264 error.NeededSourceLocation => {
1126211265 const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } };
11263 const decl = sema.mod.declPtr(case_block.src_decl);
11266 const decl = mod.declPtr(case_block.src_decl);
1126411267 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
1126511268 unreachable;
1126611269 },
......@@ -11289,14 +11292,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1128911292
1129011293 const analyze_body = if (union_originally) blk: {
1129111294 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
11292 const field_ty = maybe_union_ty.unionFieldType(item_val, sema.mod);
11295 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1129311296 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1129411297 } else true;
1129511298
1129611299 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
1129711300 error.NeededSourceLocation => {
1129811301 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } };
11299 const decl = sema.mod.declPtr(case_block.src_decl);
11302 const decl = mod.declPtr(case_block.src_decl);
1130011303 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
1130111304 unreachable;
1130211305 },
......@@ -11333,7 +11336,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1133311336 for (items) |item_ref| {
1133411337 const item = try sema.resolveInst(item_ref);
1133511338 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
11336 const field_ty = maybe_union_ty.unionFieldType(item_val, sema.mod);
11339 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1133711340 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1133811341 } else false
1133911342 else
......@@ -11461,7 +11464,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1146111464 .Enum => {
1146211465 if (operand_ty.isNonexhaustiveEnum() and !union_originally) {
1146311466 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
11464 operand_ty.fmt(sema.mod),
11467 operand_ty.fmt(mod),
1146511468 });
1146611469 }
1146711470 for (seen_enum_fields, 0..) |f, i| {
......@@ -11476,7 +11479,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1147611479 case_block.wip_capture_scope = child_block.wip_capture_scope;
1147711480
1147811481 const analyze_body = if (union_originally) blk: {
11479 const field_ty = maybe_union_ty.unionFieldType(item_val, sema.mod);
11482 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1148011483 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1148111484 } else true;
1148211485
......@@ -11499,7 +11502,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1149911502 .ErrorSet => {
1150011503 if (operand_ty.isAnyError()) {
1150111504 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
11502 operand_ty.fmt(sema.mod),
11505 operand_ty.fmt(mod),
1150311506 });
1150411507 }
1150511508 for (operand_ty.errorSetNames()) |error_name| {
......@@ -11587,7 +11590,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1158711590 }
1158811591 },
1158911592 else => return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
11590 operand_ty.fmt(sema.mod),
11593 operand_ty.fmt(mod),
1159111594 }),
1159211595 };
1159311596
......@@ -11598,7 +11601,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1159811601 case_block.wip_capture_scope = wip_captures.scope;
1159911602 case_block.inline_case_capture = .none;
1160011603
11601 if (sema.mod.backendSupportsFeature(.is_named_enum_value) and special.body.len != 0 and block.wantSafety() and
11604 if (mod.backendSupportsFeature(.is_named_enum_value) and special.body.len != 0 and block.wantSafety() and
1160211605 operand_ty.zigTypeTag(mod) == .Enum and (!operand_ty.isNonexhaustiveEnum() or union_originally))
1160311606 {
1160411607 try sema.zirDbgStmt(&case_block, cond_dbg_node_index);
......@@ -11679,7 +11682,7 @@ const RangeSetUnhandledIterator = struct {
1167911682 fn init(sema: *Sema, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator {
1168011683 const mod = sema.mod;
1168111684 const min = try ty.minInt(sema.arena, mod);
11682 const max = try ty.maxInt(sema.arena, mod);
11685 const max = try ty.maxIntScalar(mod);
1168311686
1168411687 return RangeSetUnhandledIterator{
1168511688 .sema = sema,
......@@ -11693,19 +11696,19 @@ const RangeSetUnhandledIterator = struct {
1169311696 fn next(it: *RangeSetUnhandledIterator) !?Value {
1169411697 while (it.range_i < it.ranges.len) : (it.range_i += 1) {
1169511698 if (!it.first) {
11696 it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty);
11699 it.cur = try it.sema.intAddScalar(it.cur, Value.one, it.ty);
1169711700 }
1169811701 it.first = false;
11699 if (it.cur.compareAll(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) {
11702 if (it.cur.compareScalar(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) {
1170011703 return it.cur;
1170111704 }
1170211705 it.cur = it.ranges[it.range_i].last;
1170311706 }
1170411707 if (!it.first) {
11705 it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty);
11708 it.cur = try it.sema.intAddScalar(it.cur, Value.one, it.ty);
1170611709 }
1170711710 it.first = false;
11708 if (it.cur.compareAll(.lte, it.max, it.ty, it.sema.mod)) {
11711 if (it.cur.compareScalar(.lte, it.max, it.ty, it.sema.mod)) {
1170911712 return it.cur;
1171011713 }
1171111714 return null;
......@@ -11750,7 +11753,7 @@ fn validateSwitchRange(
1175011753) CompileError!void {
1175111754 const first_val = (try sema.resolveSwitchItemVal(block, first_ref, src_node_offset, switch_prong_src, .first)).val;
1175211755 const last_val = (try sema.resolveSwitchItemVal(block, last_ref, src_node_offset, switch_prong_src, .last)).val;
11753 if (first_val.compareAll(.gt, last_val, operand_ty, sema.mod)) {
11756 if (first_val.compareScalar(.gt, last_val, operand_ty, sema.mod)) {
1175411757 const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), src_node_offset, .first);
1175511758 return sema.fail(block, src, "range start value is greater than the end value", .{});
1175611759 }
......@@ -12208,16 +12211,11 @@ fn zirShl(
1220812211 return lhs;
1220912212 }
1221012213 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt and air_tag != .shl_sat) {
12211 var bits_payload = Value.Payload.U64{
12212 .base = .{ .tag = .int_u64 },
12213 .data = scalar_ty.intInfo(mod).bits,
12214 };
12215 const bit_value = Value.initPayload(&bits_payload.base);
12214 const bit_value = try mod.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);
1221612215 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1221712216 var i: usize = 0;
1221812217 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12219 var elem_value_buf: Value.ElemValueBuffer = undefined;
12220 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
12218 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
1222112219 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
1222212220 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
1222312221 rhs_elem.fmtValue(scalar_ty, sema.mod),
......@@ -12236,8 +12234,7 @@ fn zirShl(
1223612234 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1223712235 var i: usize = 0;
1223812236 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12239 var elem_value_buf: Value.ElemValueBuffer = undefined;
12240 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
12237 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
1224112238 if (rhs_elem.compareHetero(.lt, Value.zero, mod)) {
1224212239 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
1224312240 rhs_elem.fmtValue(scalar_ty, sema.mod),
......@@ -12309,7 +12306,7 @@ fn zirShl(
1230912306 if (block.wantSafety()) {
1231012307 const bit_count = scalar_ty.intInfo(mod).bits;
1231112308 if (!std.math.isPowerOfTwo(bit_count)) {
12312 const bit_count_val = try Value.Tag.int_u64.create(sema.arena, bit_count);
12309 const bit_count_val = try mod.intValue(scalar_ty, bit_count);
1231312310
1231412311 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
1231512312 const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val));
......@@ -12396,16 +12393,11 @@ fn zirShr(
1239612393 return lhs;
1239712394 }
1239812395 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt) {
12399 var bits_payload = Value.Payload.U64{
12400 .base = .{ .tag = .int_u64 },
12401 .data = scalar_ty.intInfo(mod).bits,
12402 };
12403 const bit_value = Value.initPayload(&bits_payload.base);
12396 const bit_value = try mod.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);
1240412397 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1240512398 var i: usize = 0;
1240612399 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12407 var elem_value_buf: Value.ElemValueBuffer = undefined;
12408 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
12400 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
1240912401 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
1241012402 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
1241112403 rhs_elem.fmtValue(scalar_ty, sema.mod),
......@@ -12424,8 +12416,7 @@ fn zirShr(
1242412416 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1242512417 var i: usize = 0;
1242612418 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12427 var elem_value_buf: Value.ElemValueBuffer = undefined;
12428 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
12419 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
1242912420 if (rhs_elem.compareHetero(.lt, Value.zero, mod)) {
1243012421 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
1243112422 rhs_elem.fmtValue(scalar_ty, sema.mod),
......@@ -12465,7 +12456,7 @@ fn zirShr(
1246512456 if (block.wantSafety()) {
1246612457 const bit_count = scalar_ty.intInfo(mod).bits;
1246712458 if (!std.math.isPowerOfTwo(bit_count)) {
12468 const bit_count_val = try Value.Tag.int_u64.create(sema.arena, bit_count);
12459 const bit_count_val = try mod.intValue(scalar_ty, bit_count);
1246912460
1247012461 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
1247112462 const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val));
......@@ -12587,10 +12578,9 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1258712578 return sema.addConstUndef(operand_type);
1258812579 } else if (operand_type.zigTypeTag(mod) == .Vector) {
1258912580 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
12590 var elem_val_buf: Value.ElemValueBuffer = undefined;
1259112581 const elems = try sema.arena.alloc(Value, vec_len);
1259212582 for (elems, 0..) |*elem, i| {
12593 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf);
12583 const elem_val = try val.elemValue(sema.mod, i);
1259412584 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod);
1259512585 }
1259612586 return sema.addConstant(
......@@ -12695,6 +12685,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1269512685 const tracy = trace(@src());
1269612686 defer tracy.end();
1269712687
12688 const mod = sema.mod;
1269812689 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1269912690 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1270012691 const lhs = try sema.resolveInst(extra.lhs);
......@@ -12714,11 +12705,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1271412705
1271512706 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
1271612707 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);
12717 return sema.fail(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(sema.mod)});
12708 return sema.fail(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
1271812709 };
1271912710 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {
1272012711 assert(!rhs_is_tuple);
12721 return sema.fail(block, rhs_src, "expected indexable; found '{}'", .{rhs_ty.fmt(sema.mod)});
12712 return sema.fail(block, rhs_src, "expected indexable; found '{}'", .{rhs_ty.fmt(mod)});
1272212713 };
1272312714
1272412715 const resolved_elem_ty = t: {
......@@ -12780,8 +12771,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1278012771 ),
1278112772 };
1278212773
12783 const result_ty = try Type.array(sema.arena, result_len, res_sent_val, resolved_elem_ty, sema.mod);
12784 const mod = sema.mod;
12774 const result_ty = try Type.array(sema.arena, result_len, res_sent_val, resolved_elem_ty, mod);
1278512775 const ptr_addrspace = p: {
1278612776 if (lhs_ty.zigTypeTag(mod) == .Pointer) break :p lhs_ty.ptrAddressSpace(mod);
1278712777 if (rhs_ty.zigTypeTag(mod) == .Pointer) break :p rhs_ty.ptrAddressSpace(mod);
......@@ -12815,7 +12805,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1281512805 const lhs_elem_i = elem_i;
1281612806 const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i) else lhs_info.elem_type;
1281712807 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i) else Value.@"unreachable";
12818 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try lhs_sub_val.elemValue(sema.mod, sema.arena, lhs_elem_i) else elem_default_val;
12808 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1281912809 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
1282012810 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
1282112811 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
......@@ -12825,7 +12815,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1282512815 const rhs_elem_i = elem_i - lhs_len;
1282612816 const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i) else rhs_info.elem_type;
1282712817 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i) else Value.@"unreachable";
12828 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try rhs_sub_val.elemValue(sema.mod, sema.arena, rhs_elem_i) else elem_default_val;
12818 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1282912819 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
1283012820 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
1283112821 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
......@@ -12842,12 +12832,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1284212832 try sema.requireRuntimeBlock(block, src, runtime_src);
1284312833
1284412834 if (ptr_addrspace) |ptr_as| {
12845 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
12835 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1284612836 .pointee_type = result_ty,
1284712837 .@"addrspace" = ptr_as,
1284812838 });
1284912839 const alloc = try block.addTy(.alloc, alloc_ty);
12850 const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
12840 const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{
1285112841 .pointee_type = resolved_elem_ty,
1285212842 .@"addrspace" = ptr_as,
1285312843 });
......@@ -13009,6 +12999,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1300912999 const tracy = trace(@src());
1301013000 defer tracy.end();
1301113001
13002 const mod = sema.mod;
1301213003 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1301313004 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1301413005 const lhs = try sema.resolveInst(extra.lhs);
......@@ -13025,10 +13016,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1302513016 }
1302613017
1302713018 // Analyze the lhs first, to catch the case that someone tried to do exponentiation
13028 const mod = sema.mod;
1302913019 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {
1303013020 const msg = msg: {
13031 const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(sema.mod)});
13021 const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
1303213022 errdefer msg.destroy(sema.gpa);
1303313023 switch (lhs_ty.zigTypeTag(mod)) {
1303413024 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
......@@ -13048,7 +13038,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1304813038 return sema.fail(block, rhs_src, "operation results in overflow", .{});
1304913039 const result_len = try sema.usizeCast(block, src, result_len_u64);
1305013040
13051 const result_ty = try Type.array(sema.arena, result_len, lhs_info.sentinel, lhs_info.elem_type, sema.mod);
13041 const result_ty = try Type.array(sema.arena, result_len, lhs_info.sentinel, lhs_info.elem_type, mod);
1305213042
1305313043 const ptr_addrspace = if (lhs_ty.zigTypeTag(mod) == .Pointer) lhs_ty.ptrAddressSpace(mod) else null;
1305413044 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);
......@@ -13065,7 +13055,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1306513055 // Optimization for the common pattern of a single element repeated N times, such
1306613056 // as zero-filling a byte array.
1306713057 if (lhs_len == 1) {
13068 const elem_val = try lhs_sub_val.elemValue(sema.mod, sema.arena, 0);
13058 const elem_val = try lhs_sub_val.elemValue(mod, 0);
1306913059 break :v try Value.Tag.repeated.create(sema.arena, elem_val);
1307013060 }
1307113061
......@@ -13074,7 +13064,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1307413064 while (elem_i < result_len) {
1307513065 var lhs_i: usize = 0;
1307613066 while (lhs_i < lhs_len) : (lhs_i += 1) {
13077 const elem_val = try lhs_sub_val.elemValue(sema.mod, sema.arena, lhs_i);
13067 const elem_val = try lhs_sub_val.elemValue(mod, lhs_i);
1307813068 element_vals[elem_i] = elem_val;
1307913069 elem_i += 1;
1308013070 }
......@@ -13090,12 +13080,12 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1309013080 try sema.requireRuntimeBlock(block, src, lhs_src);
1309113081
1309213082 if (ptr_addrspace) |ptr_as| {
13093 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
13083 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1309413084 .pointee_type = result_ty,
1309513085 .@"addrspace" = ptr_as,
1309613086 });
1309713087 const alloc = try block.addTy(.alloc, alloc_ty);
13098 const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
13088 const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{
1309913089 .pointee_type = lhs_info.elem_type,
1310013090 .@"addrspace" = ptr_as,
1310113091 });
......@@ -13797,7 +13787,7 @@ fn addDivIntOverflowSafety(
1379713787 }
1379813788
1379913789 const min_int = try resolved_type.minInt(sema.arena, mod);
13800 const neg_one_scalar = try Value.Tag.int_i64.create(sema.arena, -1);
13790 const neg_one_scalar = try mod.intValue(lhs_scalar_ty, -1);
1380113791 const neg_one = if (resolved_type.zigTypeTag(mod) == .Vector)
1380213792 try Value.Tag.repeated.create(sema.arena, neg_one_scalar)
1380313793 else
......@@ -13806,12 +13796,12 @@ fn addDivIntOverflowSafety(
1380613796 // If the LHS is comptime-known to be not equal to the min int,
1380713797 // no overflow is possible.
1380813798 if (maybe_lhs_val) |lhs_val| {
13809 if (lhs_val.compareAll(.neq, min_int, resolved_type, mod)) return;
13799 if (try lhs_val.compareAll(.neq, min_int, resolved_type, mod)) return;
1381013800 }
1381113801
1381213802 // If the RHS is comptime-known to not be equal to -1, no overflow is possible.
1381313803 if (maybe_rhs_val) |rhs_val| {
13814 if (rhs_val.compareAll(.neq, neg_one, resolved_type, mod)) return;
13804 if (try rhs_val.compareAll(.neq, neg_one, resolved_type, mod)) return;
1381513805 }
1381613806
1381713807 var ok: Air.Inst.Ref = .none;
......@@ -14038,23 +14028,18 @@ fn intRem(
1403814028 const mod = sema.mod;
1403914029 if (ty.zigTypeTag(mod) == .Vector) {
1404014030 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
14031 const scalar_ty = ty.scalarType(mod);
1404114032 for (result_data, 0..) |*scalar, i| {
14042 var lhs_buf: Value.ElemValueBuffer = undefined;
14043 var rhs_buf: Value.ElemValueBuffer = undefined;
14044 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
14045 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
14046 scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem);
14033 const lhs_elem = try lhs.elemValue(sema.mod, i);
14034 const rhs_elem = try rhs.elemValue(sema.mod, i);
14035 scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty);
1404714036 }
1404814037 return Value.Tag.aggregate.create(sema.arena, result_data);
1404914038 }
14050 return sema.intRemScalar(lhs, rhs);
14039 return sema.intRemScalar(lhs, rhs, ty);
1405114040}
1405214041
14053fn intRemScalar(
14054 sema: *Sema,
14055 lhs: Value,
14056 rhs: Value,
14057) CompileError!Value {
14042fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileError!Value {
1405814043 const mod = sema.mod;
1405914044 // TODO is this a performance issue? maybe we should try the operation without
1406014045 // resorting to BigInt first.
......@@ -14079,7 +14064,7 @@ fn intRemScalar(
1407914064 var result_q = math.big.int.Mutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
1408014065 var result_r = math.big.int.Mutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
1408114066 result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
14082 return Value.fromBigInt(sema.arena, result_r.toConst());
14067 return mod.intValue_big(scalar_ty, result_r.toConst());
1408314068}
1408414069
1408514070fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -15063,7 +15048,7 @@ fn analyzePtrArithmetic(
1506315048 .ptr_sub => addr - elem_size * offset_int,
1506415049 else => unreachable,
1506515050 };
15066 const new_ptr_val = try Value.Tag.int_u64.create(sema.arena, new_addr);
15051 const new_ptr_val = try mod.intValue(new_ptr_ty, new_addr);
1506715052 return sema.addConstant(new_ptr_ty, new_ptr_val);
1506815053 }
1506915054 if (air_tag == .ptr_sub) {
......@@ -15826,9 +15811,9 @@ fn zirBuiltinSrc(
1582615811 // fn_name: [:0]const u8,
1582715812 field_values[1] = func_name_val;
1582815813 // line: u32
15829 field_values[2] = try Value.Tag.runtime_value.create(sema.arena, try Value.Tag.int_u64.create(sema.arena, extra.line + 1));
15814 field_values[2] = try Value.Tag.runtime_value.create(sema.arena, try mod.intValue(Type.u32, extra.line + 1));
1583015815 // column: u32,
15831 field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1);
15816 field_values[3] = try mod.intValue(Type.u32, extra.column + 1);
1583215817
1583315818 return sema.addConstant(
1583415819 try sema.getBuiltinType("SourceLocation"),
......@@ -15977,7 +15962,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1597715962 );
1597815963 break :v try Value.Tag.slice.create(sema.arena, .{
1597915964 .ptr = try Value.Tag.decl_ref.create(sema.arena, new_decl),
15980 .len = try Value.Tag.int_u64.create(sema.arena, param_vals.len),
15965 .len = try mod.intValue(Type.usize, param_vals.len),
1598115966 });
1598215967 };
1598315968
......@@ -15994,7 +15979,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1599415979 // calling_convention: CallingConvention,
1599515980 try Value.Tag.enum_field_index.create(sema.arena, @enumToInt(info.cc)),
1599615981 // alignment: comptime_int,
15997 try Value.Tag.int_u64.create(sema.arena, ty.abiAlignment(mod)),
15982 try mod.intValue(Type.comptime_int, ty.abiAlignment(mod)),
1599815983 // is_generic: bool,
1599915984 Value.makeBool(info.is_generic),
1600015985 // is_var_args: bool,
......@@ -16022,7 +16007,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1602216007 @enumToInt(info.signedness),
1602316008 );
1602416009 // bits: comptime_int,
16025 field_values[1] = try Value.Tag.int_u64.create(sema.arena, info.bits);
16010 field_values[1] = try mod.intValue(Type.comptime_int, info.bits);
1602616011
1602716012 return sema.addConstant(
1602816013 type_info_ty,
......@@ -16035,7 +16020,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1603516020 .Float => {
1603616021 const field_values = try sema.arena.alloc(Value, 1);
1603716022 // bits: comptime_int,
16038 field_values[0] = try Value.Tag.int_u64.create(sema.arena, ty.bitSize(mod));
16023 field_values[0] = try mod.intValue(Type.comptime_int, ty.bitSize(mod));
1603916024
1604016025 return sema.addConstant(
1604116026 type_info_ty,
......@@ -16048,7 +16033,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1604816033 .Pointer => {
1604916034 const info = ty.ptrInfo(mod);
1605016035 const alignment = if (info.@"align" != 0)
16051 try Value.Tag.int_u64.create(sema.arena, info.@"align")
16036 try mod.intValue(Type.comptime_int, info.@"align")
1605216037 else
1605316038 try info.pointee_type.lazyAbiAlignment(mod, sema.arena);
1605416039
......@@ -16084,7 +16069,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1608416069 const info = ty.arrayInfo(mod);
1608516070 const field_values = try sema.arena.alloc(Value, 3);
1608616071 // len: comptime_int,
16087 field_values[0] = try Value.Tag.int_u64.create(sema.arena, info.len);
16072 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
1608816073 // child: type,
1608916074 field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
1609016075 // sentinel: ?*const anyopaque,
......@@ -16102,7 +16087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1610216087 const info = ty.arrayInfo(mod);
1610316088 const field_values = try sema.arena.alloc(Value, 2);
1610416089 // len: comptime_int,
16105 field_values[0] = try Value.Tag.int_u64.create(sema.arena, info.len);
16090 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
1610616091 // child: type,
1610716092 field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
1610816093
......@@ -16202,7 +16187,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1620216187 const new_decl_val = try Value.Tag.decl_ref.create(sema.arena, new_decl);
1620316188 const slice_val = try Value.Tag.slice.create(sema.arena, .{
1620416189 .ptr = new_decl_val,
16205 .len = try Value.Tag.int_u64.create(sema.arena, vals.len),
16190 .len = try mod.intValue(Type.usize, vals.len),
1620616191 });
1620716192 break :v try Value.Tag.opt_payload.create(sema.arena, slice_val);
1620816193 } else Value.null;
......@@ -16263,8 +16248,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1626316248 };
1626416249 const tag_val = Value.initPayload(&tag_val_payload.base);
1626516250
16266 var buffer: Value.Payload.U64 = undefined;
16267 const int_val = try tag_val.enumToInt(ty, &buffer).copy(fields_anon_decl.arena());
16251 const int_val = try tag_val.enumToInt(ty, mod);
1626816252
1626916253 const name = enum_fields.keys()[i];
1627016254 const name_val = v: {
......@@ -16379,7 +16363,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1637916363 // type: type,
1638016364 try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
1638116365 // alignment: comptime_int,
16382 try Value.Tag.int_u64.create(fields_anon_decl.arena(), alignment),
16366 try mod.intValue(Type.comptime_int, alignment),
1638316367 };
1638416368 field_val.* = try Value.Tag.aggregate.create(fields_anon_decl.arena(), union_field_fields);
1638516369 }
......@@ -16398,7 +16382,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1639816382 );
1639916383 break :v try Value.Tag.slice.create(sema.arena, .{
1640016384 .ptr = try Value.Tag.decl_ref.create(sema.arena, new_decl),
16401 .len = try Value.Tag.int_u64.create(sema.arena, union_field_vals.len),
16385 .len = try mod.intValue(Type.usize, union_field_vals.len),
1640216386 });
1640316387 };
1640416388
......@@ -16476,7 +16460,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1647616460 );
1647716461 break :v try Value.Tag.slice.create(fields_anon_decl.arena(), .{
1647816462 .ptr = try Value.Tag.decl_ref.create(fields_anon_decl.arena(), new_decl),
16479 .len = try Value.Tag.int_u64.create(fields_anon_decl.arena(), bytes.len),
16463 .len = try mod.intValue(Type.usize, bytes.len),
1648016464 });
1648116465 };
1648216466
......@@ -16518,7 +16502,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1651816502 );
1651916503 break :v try Value.Tag.slice.create(fields_anon_decl.arena(), .{
1652016504 .ptr = try Value.Tag.decl_ref.create(fields_anon_decl.arena(), new_decl),
16521 .len = try Value.Tag.int_u64.create(fields_anon_decl.arena(), bytes.len),
16505 .len = try mod.intValue(Type.usize, bytes.len),
1652216506 });
1652316507 };
1652416508
......@@ -16540,7 +16524,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1654016524 // is_comptime: bool,
1654116525 Value.makeBool(field.is_comptime),
1654216526 // alignment: comptime_int,
16543 try Value.Tag.int_u64.create(fields_anon_decl.arena(), alignment),
16527 try mod.intValue(Type.comptime_int, alignment),
1654416528 };
1654516529 field_val.* = try Value.Tag.aggregate.create(fields_anon_decl.arena(), struct_field_fields);
1654616530 }
......@@ -16561,7 +16545,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1656116545 );
1656216546 break :v try Value.Tag.slice.create(sema.arena, .{
1656316547 .ptr = try Value.Tag.decl_ref.create(sema.arena, new_decl),
16564 .len = try Value.Tag.int_u64.create(sema.arena, struct_field_vals.len),
16548 .len = try mod.intValue(Type.usize, struct_field_vals.len),
1656516549 });
1656616550 };
1656716551
......@@ -16636,6 +16620,7 @@ fn typeInfoDecls(
1663616620 type_info_ty: Type,
1663716621 opt_namespace: ?*Module.Namespace,
1663816622) CompileError!Value {
16623 const mod = sema.mod;
1663916624 var decls_anon_decl = try block.startAnonDecl();
1664016625 defer decls_anon_decl.deinit();
1664116626
......@@ -16646,9 +16631,9 @@ fn typeInfoDecls(
1664616631 type_info_ty.getNamespace().?,
1664716632 "Declaration",
1664816633 )).?;
16649 try sema.mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index);
16634 try mod.declareDeclDependency(sema.owner_decl_index, declaration_ty_decl_index);
1665016635 try sema.ensureDeclAnalyzed(declaration_ty_decl_index);
16651 const declaration_ty_decl = sema.mod.declPtr(declaration_ty_decl_index);
16636 const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index);
1665216637 break :t try declaration_ty_decl.val.toType().copy(decls_anon_decl.arena());
1665316638 };
1665416639 try sema.queueFullTypeResolution(try declaration_ty.copy(sema.arena));
......@@ -16676,7 +16661,7 @@ fn typeInfoDecls(
1667616661 );
1667716662 return try Value.Tag.slice.create(sema.arena, .{
1667816663 .ptr = try Value.Tag.decl_ref.create(sema.arena, new_decl),
16679 .len = try Value.Tag.int_u64.create(sema.arena, decl_vals.items.len),
16664 .len = try mod.intValue(Type.usize, decl_vals.items.len),
1668016665 });
1668116666}
1668216667
......@@ -16713,7 +16698,7 @@ fn typeInfoNamespaceDecls(
1671316698 );
1671416699 break :v try Value.Tag.slice.create(decls_anon_decl, .{
1671516700 .ptr = try Value.Tag.decl_ref.create(decls_anon_decl, new_decl),
16716 .len = try Value.Tag.int_u64.create(decls_anon_decl, bytes.len),
16701 .len = try mod.intValue(Type.usize, bytes.len),
1671716702 });
1671816703 };
1671916704
......@@ -18620,10 +18605,9 @@ fn zirUnaryMath(
1862018605 if (val.isUndef())
1862118606 return sema.addConstUndef(result_ty);
1862218607
18623 var elem_buf: Value.ElemValueBuffer = undefined;
1862418608 const elems = try sema.arena.alloc(Value, vec_len);
1862518609 for (elems, 0..) |*elem, i| {
18626 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
18610 const elem_val = try val.elemValue(sema.mod, i);
1862718611 elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod);
1862818612 }
1862918613 return sema.addConstant(
......@@ -18717,7 +18701,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1871718701 return block.addUnOp(.tag_name, casted_operand);
1871818702}
1871918703
18720fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18704fn zirReify(
18705 sema: *Sema,
18706 block: *Block,
18707 extended: Zir.Inst.Extended.InstData,
18708 inst: Zir.Inst.Index,
18709) CompileError!Air.Inst.Ref {
1872118710 const mod = sema.mod;
1872218711 const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small);
1872318712 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
......@@ -18730,7 +18719,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1873018719 const union_val = val.cast(Value.Payload.Union).?.data;
1873118720 const target = mod.getTarget();
1873218721 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag, mod).?;
18733 if (union_val.val.anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
18722 if (try union_val.val.anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
1873418723 switch (@intToEnum(std.builtin.TypeId, tag_index)) {
1873518724 .Type => return Air.Inst.Ref.type_type,
1873618725 .Void => return Air.Inst.Ref.void_type,
......@@ -18845,10 +18834,10 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1884518834 } else if (ptr_size == .C) {
1884618835 if (!try sema.validateExternType(elem_ty, .other)) {
1884718836 const msg = msg: {
18848 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)});
18837 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
1884918838 errdefer msg.destroy(sema.gpa);
1885018839
18851 const src_decl = sema.mod.declPtr(block.src_decl);
18840 const src_decl = mod.declPtr(block.src_decl);
1885218841 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), elem_ty, .other);
1885318842
1885418843 try sema.addDeclaredHereNote(msg, elem_ty);
......@@ -18893,7 +18882,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1889318882 break :blk (try sema.pointerDeref(block, src, p.data, ptr_ty)).?;
1889418883 } else null;
1889518884
18896 const ty = try Type.array(sema.arena, len, sentinel, child_ty, sema.mod);
18885 const ty = try Type.array(sema.arena, len, sentinel, child_ty, mod);
1889718886 return sema.addType(ty);
1889818887 },
1889918888 .Optional => {
......@@ -18938,13 +18927,12 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1893818927 try names.ensureUnusedCapacity(sema.arena, len);
1893918928 var i: usize = 0;
1894018929 while (i < len) : (i += 1) {
18941 var buf: Value.ElemValueBuffer = undefined;
18942 const elem_val = slice_val.ptr.elemValueBuffer(mod, i, &buf);
18930 const elem_val = try slice_val.ptr.elemValue(mod, i);
1894318931 const struct_val = elem_val.castTag(.aggregate).?.data;
1894418932 // TODO use reflection instead of magic numbers here
1894518933 // error_set: type,
1894618934 const name_val = struct_val[0];
18947 const name_str = try name_val.toAllocatedBytes(Type.const_slice_u8, sema.arena, sema.mod);
18935 const name_str = try name_val.toAllocatedBytes(Type.const_slice_u8, sema.arena, mod);
1894818936
1894918937 const kv = try mod.getErrorValue(name_str);
1895018938 const gop = names.getOrPutAssumeCapacity(kv.key);
......@@ -19061,7 +19049,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1906119049
1906219050 var field_i: usize = 0;
1906319051 while (field_i < fields_len) : (field_i += 1) {
19064 const elem_val = try fields_val.elemValue(sema.mod, sema.arena, field_i);
19052 const elem_val = try fields_val.elemValue(mod, field_i);
1906519053 const field_struct_val: []const Value = elem_val.castTag(.aggregate).?.data;
1906619054 // TODO use reflection instead of magic numbers here
1906719055 // name: []const u8
......@@ -19072,7 +19060,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1907219060 const field_name = try name_val.toAllocatedBytes(
1907319061 Type.const_slice_u8,
1907419062 new_decl_arena_allocator,
19075 sema.mod,
19063 mod,
1907619064 );
1907719065
1907819066 if (!try sema.intFitsInType(value_val, enum_obj.tag_ty, null)) {
......@@ -19183,7 +19171,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1918319171 Type.Tag.union_tagged
1918419172 else if (layout != .Auto)
1918519173 Type.Tag.@"union"
19186 else switch (block.sema.mod.optimizeMode()) {
19174 else switch (mod.optimizeMode()) {
1918719175 .Debug, .ReleaseSafe => Type.Tag.union_safety_tagged,
1918819176 .ReleaseFast, .ReleaseSmall => Type.Tag.@"union",
1918919177 };
......@@ -19236,7 +19224,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1923619224
1923719225 var i: usize = 0;
1923819226 while (i < fields_len) : (i += 1) {
19239 const elem_val = try fields_val.elemValue(sema.mod, sema.arena, i);
19227 const elem_val = try fields_val.elemValue(mod, i);
1924019228 const field_struct_val = elem_val.castTag(.aggregate).?.data;
1924119229 // TODO use reflection instead of magic numbers here
1924219230 // name: []const u8
......@@ -19249,7 +19237,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1924919237 const field_name = try name_val.toAllocatedBytes(
1925019238 Type.const_slice_u8,
1925119239 new_decl_arena_allocator,
19252 sema.mod,
19240 mod,
1925319241 );
1925419242
1925519243 if (enum_field_names) |set| {
......@@ -19260,7 +19248,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1926019248 const enum_has_field = names.orderedRemove(field_name);
1926119249 if (!enum_has_field) {
1926219250 const msg = msg: {
19263 const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(sema.mod) });
19251 const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(mod) });
1926419252 errdefer msg.destroy(sema.gpa);
1926519253 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
1926619254 break :msg msg;
......@@ -19293,10 +19281,10 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1929319281 }
1929419282 if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) {
1929519283 const msg = msg: {
19296 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
19284 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
1929719285 errdefer msg.destroy(sema.gpa);
1929819286
19299 const src_decl = sema.mod.declPtr(block.src_decl);
19287 const src_decl = mod.declPtr(block.src_decl);
1930019288 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field);
1930119289
1930219290 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -19305,10 +19293,10 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1930519293 return sema.failWithOwnedErrorMsg(msg);
1930619294 } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) {
1930719295 const msg = msg: {
19308 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
19296 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
1930919297 errdefer msg.destroy(sema.gpa);
1931019298
19311 const src_decl = sema.mod.declPtr(block.src_decl);
19299 const src_decl = mod.declPtr(block.src_decl);
1931219300 try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty);
1931319301
1931419302 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -19386,8 +19374,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1938619374 var noalias_bits: u32 = 0;
1938719375 var i: usize = 0;
1938819376 while (i < args_len) : (i += 1) {
19389 var arg_buf: Value.ElemValueBuffer = undefined;
19390 const arg = args_slice_val.ptr.elemValueBuffer(mod, i, &arg_buf);
19377 const arg = try args_slice_val.ptr.elemValue(mod, i);
1939119378 const arg_val = arg.castTag(.aggregate).?.data;
1939219379 // TODO use reflection instead of magic numbers here
1939319380 // is_generic: bool,
......@@ -19486,7 +19473,7 @@ fn reifyStruct(
1948619473 try struct_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);
1948719474 var i: usize = 0;
1948819475 while (i < fields_len) : (i += 1) {
19489 const elem_val = try fields_val.elemValue(sema.mod, sema.arena, i);
19476 const elem_val = try fields_val.elemValue(sema.mod, i);
1949019477 const field_struct_val = elem_val.castTag(.aggregate).?.data;
1949119478 // TODO use reflection instead of magic numbers here
1949219479 // name: []const u8
......@@ -19892,12 +19879,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1989219879 if (addr != 0 and ptr_align != 0 and addr % ptr_align != 0)
1989319880 return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)});
1989419881
19895 const val_payload = try sema.arena.create(Value.Payload.U64);
19896 val_payload.* = .{
19897 .base = .{ .tag = .int_u64 },
19898 .data = addr,
19899 };
19900 return sema.addConstant(ptr_ty, Value.initPayload(&val_payload.base));
19882 return sema.addConstant(ptr_ty, try mod.intValue(ptr_ty, addr));
1990119883 }
1990219884
1990319885 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -19908,14 +19890,9 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1990819890 }
1990919891
1991019892 if (ptr_align > 1) {
19911 const val_payload = try sema.arena.create(Value.Payload.U64);
19912 val_payload.* = .{
19913 .base = .{ .tag = .int_u64 },
19914 .data = ptr_align - 1,
19915 };
1991619893 const align_minus_1 = try sema.addConstant(
1991719894 Type.usize,
19918 Value.initPayload(&val_payload.base),
19895 try mod.intValue(Type.usize, ptr_align - 1),
1991919896 );
1992019897 const remainder = try block.addBinOp(.bit_and, operand_coerced, align_minus_1);
1992119898 const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
......@@ -20254,10 +20231,9 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2025420231 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod),
2025520232 );
2025620233 }
20257 var elem_buf: Value.ElemValueBuffer = undefined;
2025820234 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen(mod));
2025920235 for (elems, 0..) |*elem, i| {
20260 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
20236 const elem_val = try val.elemValue(sema.mod, i);
2026120237 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);
2026220238 }
2026320239 return sema.addConstant(
......@@ -20302,14 +20278,9 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2030220278 if (block.wantSafety() and dest_align > 1 and
2030320279 try sema.typeHasRuntimeBits(ptr_info.pointee_type))
2030420280 {
20305 const val_payload = try sema.arena.create(Value.Payload.U64);
20306 val_payload.* = .{
20307 .base = .{ .tag = .int_u64 },
20308 .data = dest_align - 1,
20309 };
2031020281 const align_minus_1 = try sema.addConstant(
2031120282 Type.usize,
20312 Value.initPayload(&val_payload.base),
20283 try mod.intValue(Type.usize, dest_align - 1),
2031320284 );
2031420285 const actual_ptr = if (ptr_ty.isSlice(mod))
2031520286 try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)
......@@ -20359,13 +20330,12 @@ fn zirBitCount(
2035920330 if (try sema.resolveMaybeUndefVal(operand)) |val| {
2036020331 if (val.isUndef()) return sema.addConstUndef(result_ty);
2036120332
20362 var elem_buf: Value.ElemValueBuffer = undefined;
2036320333 const elems = try sema.arena.alloc(Value, vec_len);
2036420334 const scalar_ty = operand_ty.scalarType(mod);
2036520335 for (elems, 0..) |*elem, i| {
20366 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
20336 const elem_val = try val.elemValue(sema.mod, i);
2036720337 const count = comptimeOp(elem_val, scalar_ty, mod);
20368 elem.* = try Value.Tag.int_u64.create(sema.arena, count);
20338 elem.* = try mod.intValue(scalar_ty, count);
2036920339 }
2037020340 return sema.addConstant(
2037120341 result_ty,
......@@ -20429,10 +20399,9 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2042920399 return sema.addConstUndef(operand_ty);
2043020400
2043120401 const vec_len = operand_ty.vectorLen(mod);
20432 var elem_buf: Value.ElemValueBuffer = undefined;
2043320402 const elems = try sema.arena.alloc(Value, vec_len);
2043420403 for (elems, 0..) |*elem, i| {
20435 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
20404 const elem_val = try val.elemValue(sema.mod, i);
2043620405 elem.* = try elem_val.byteSwap(operand_ty, mod, sema.arena);
2043720406 }
2043820407 return sema.addConstant(
......@@ -20478,10 +20447,9 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2047820447 return sema.addConstUndef(operand_ty);
2047920448
2048020449 const vec_len = operand_ty.vectorLen(mod);
20481 var elem_buf: Value.ElemValueBuffer = undefined;
2048220450 const elems = try sema.arena.alloc(Value, vec_len);
2048320451 for (elems, 0..) |*elem, i| {
20484 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
20452 const elem_val = try val.elemValue(sema.mod, i);
2048520453 elem.* = try elem_val.bitReverse(scalar_ty, mod, sema.arena);
2048620454 }
2048720455 return sema.addConstant(
......@@ -21241,11 +21209,10 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2124121209 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
2124221210 if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty);
2124321211
21244 var accum: Value = try operand_val.elemValue(mod, sema.arena, 0);
21245 var elem_buf: Value.ElemValueBuffer = undefined;
21212 var accum: Value = try operand_val.elemValue(mod, 0);
2124621213 var i: u32 = 1;
2124721214 while (i < vec_len) : (i += 1) {
21248 const elem_val = operand_val.elemValueBuffer(mod, i, &elem_buf);
21215 const elem_val = try operand_val.elemValue(mod, i);
2124921216 switch (operation) {
2125021217 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, mod),
2125121218 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, mod),
......@@ -21359,8 +21326,7 @@ fn analyzeShuffle(
2135921326
2136021327 var i: usize = 0;
2136121328 while (i < mask_len) : (i += 1) {
21362 var buf: Value.ElemValueBuffer = undefined;
21363 const elem = mask.elemValueBuffer(sema.mod, i, &buf);
21329 const elem = try mask.elemValue(sema.mod, i);
2136421330 if (elem.isUndef()) continue;
2136521331 const int = elem.toSignedInt(mod);
2136621332 var unsigned: u32 = undefined;
......@@ -21398,8 +21364,7 @@ fn analyzeShuffle(
2139821364
2139921365 i = 0;
2140021366 while (i < mask_len) : (i += 1) {
21401 var buf: Value.ElemValueBuffer = undefined;
21402 const mask_elem_val = mask.elemValueBuffer(sema.mod, i, &buf);
21367 const mask_elem_val = try mask.elemValue(sema.mod, i);
2140321368 if (mask_elem_val.isUndef()) {
2140421369 values[i] = Value.undef;
2140521370 continue;
......@@ -21407,9 +21372,9 @@ fn analyzeShuffle(
2140721372 const int = mask_elem_val.toSignedInt(mod);
2140821373 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);
2140921374 if (int >= 0) {
21410 values[i] = try a_val.elemValue(sema.mod, sema.arena, unsigned);
21375 values[i] = try a_val.elemValue(sema.mod, unsigned);
2141121376 } else {
21412 values[i] = try b_val.elemValue(sema.mod, sema.arena, unsigned);
21377 values[i] = try b_val.elemValue(sema.mod, unsigned);
2141321378 }
2141421379 }
2141521380 const res_val = try Value.Tag.aggregate.create(sema.arena, values);
......@@ -21430,7 +21395,7 @@ fn analyzeShuffle(
2143021395 const expand_mask_values = try sema.arena.alloc(Value, max_len);
2143121396 i = 0;
2143221397 while (i < min_len) : (i += 1) {
21433 expand_mask_values[i] = try Value.Tag.int_u64.create(sema.arena, i);
21398 expand_mask_values[i] = try mod.intValue(Type.comptime_int, i);
2143421399 }
2143521400 while (i < max_len) : (i += 1) {
2143621401 expand_mask_values[i] = Value.negative_one;
......@@ -21509,15 +21474,14 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2150921474 if (maybe_b) |b_val| {
2151021475 if (b_val.isUndef()) return sema.addConstUndef(vec_ty);
2151121476
21512 var buf: Value.ElemValueBuffer = undefined;
2151321477 const elems = try sema.gpa.alloc(Value, vec_len);
2151421478 for (elems, 0..) |*elem, i| {
21515 const pred_elem_val = pred_val.elemValueBuffer(sema.mod, i, &buf);
21479 const pred_elem_val = try pred_val.elemValue(sema.mod, i);
2151621480 const should_choose_a = pred_elem_val.toBool(mod);
2151721481 if (should_choose_a) {
21518 elem.* = a_val.elemValueBuffer(sema.mod, i, &buf);
21482 elem.* = try a_val.elemValue(sema.mod, i);
2151921483 } else {
21520 elem.* = b_val.elemValueBuffer(sema.mod, i, &buf);
21484 elem.* = try b_val.elemValue(sema.mod, i);
2152121485 }
2152221486 }
2152321487
......@@ -22067,12 +22031,10 @@ fn analyzeMinMax(
2206722031 cur_minmax = try sema.addConstant(simd_op.result_ty, result_val);
2206822032 continue;
2206922033 };
22070 var lhs_buf: Value.ElemValueBuffer = undefined;
22071 var rhs_buf: Value.ElemValueBuffer = undefined;
2207222034 const elems = try sema.arena.alloc(Value, vec_len);
2207322035 for (elems, 0..) |*elem, i| {
22074 const lhs_elem_val = cur_val.elemValueBuffer(mod, i, &lhs_buf);
22075 const rhs_elem_val = operand_val.elemValueBuffer(mod, i, &rhs_buf);
22036 const lhs_elem_val = try cur_val.elemValue(mod, i);
22037 const rhs_elem_val = try operand_val.elemValue(mod, i);
2207622038 elem.* = opFunc(lhs_elem_val, rhs_elem_val, mod);
2207722039 }
2207822040 cur_minmax = try sema.addConstant(
......@@ -22105,10 +22067,10 @@ fn analyzeMinMax(
2210522067 if (len == 0) break :blk orig_ty;
2210622068 if (elem_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats
2210722069
22108 var cur_min: Value = try val.elemValue(mod, sema.arena, 0);
22070 var cur_min: Value = try val.elemValue(mod, 0);
2210922071 var cur_max: Value = cur_min;
2211022072 for (1..len) |idx| {
22111 const elem_val = try val.elemValue(mod, sema.arena, idx);
22073 const elem_val = try val.elemValue(mod, idx);
2211222074 if (elem_val.isUndef()) break :blk orig_ty; // can't refine undef
2211322075 if (Value.order(elem_val, cur_min, mod).compare(.lt)) cur_min = elem_val;
2211422076 if (Value.order(elem_val, cur_max, mod).compare(.gt)) cur_max = elem_val;
......@@ -23987,7 +23949,7 @@ fn fieldVal(
2398723949 if (mem.eql(u8, field_name, "len")) {
2398823950 return sema.addConstant(
2398923951 Type.usize,
23990 try Value.Tag.int_u64.create(arena, inner_ty.arrayLen(mod)),
23952 try mod.intValue(Type.usize, inner_ty.arrayLen(mod)),
2399123953 );
2399223954 } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) {
2399323955 const ptr_info = object_ty.ptrInfo(mod);
......@@ -24179,7 +24141,7 @@ fn fieldPtr(
2417924141 defer anon_decl.deinit();
2418024142 return sema.analyzeDeclRef(try anon_decl.finish(
2418124143 Type.usize,
24182 try Value.Tag.int_u64.create(anon_decl.arena(), inner_ty.arrayLen(mod)),
24144 try mod.intValue(Type.usize, inner_ty.arrayLen(mod)),
2418324145 0, // default alignment
2418424146 ));
2418524147 } else {
......@@ -25352,7 +25314,7 @@ fn elemValArray(
2535225314 }
2535325315 if (maybe_index_val) |index_val| {
2535425316 const index = @intCast(usize, index_val.toUnsignedInt(mod));
25355 const elem_val = try array_val.elemValue(sema.mod, sema.arena, index);
25317 const elem_val = try array_val.elemValue(mod, index);
2535625318 return sema.addConstant(elem_ty, elem_val);
2535725319 }
2535825320 }
......@@ -25914,7 +25876,7 @@ fn coerceExtra(
2591425876 // we use a dummy pointer value with the required alignment.
2591525877 const slice_val = try Value.Tag.slice.create(sema.arena, .{
2591625878 .ptr = if (dest_info.@"align" != 0)
25917 try Value.Tag.int_u64.create(sema.arena, dest_info.@"align")
25879 try mod.intValue(Type.usize, dest_info.@"align")
2591825880 else
2591925881 try dest_info.pointee_type.lazyAbiAlignment(mod, sema.arena),
2592025882 .len = Value.zero,
......@@ -26022,7 +25984,7 @@ fn coerceExtra(
2602225984 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2602325985 .ComptimeFloat => {
2602425986 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
26025 const result_val = try val.floatCast(sema.arena, dest_ty, target);
25987 const result_val = try val.floatCast(sema.arena, dest_ty, mod);
2602625988 return try sema.addConstant(dest_ty, result_val);
2602725989 },
2602825990 .Float => {
......@@ -26030,7 +25992,7 @@ fn coerceExtra(
2603025992 return sema.addConstUndef(dest_ty);
2603125993 }
2603225994 if (try sema.resolveMaybeUndefVal(inst)) |val| {
26033 const result_val = try val.floatCast(sema.arena, dest_ty, target);
25995 const result_val = try val.floatCast(sema.arena, dest_ty, mod);
2603425996 if (!val.eql(result_val, inst_ty, sema.mod)) {
2603525997 return sema.fail(
2603625998 block,
......@@ -27431,11 +27393,13 @@ fn storePtrVal(
2743127393 const buffer = try sema.gpa.alloc(u8, abi_size);
2743227394 defer sema.gpa.free(buffer);
2743327395 reinterpret.val_ptr.*.writeToMemory(mut_kit.ty, sema.mod, buffer) catch |err| switch (err) {
27396 error.OutOfMemory => return error.OutOfMemory,
2743427397 error.ReinterpretDeclRef => unreachable,
2743527398 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
2743627399 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(sema.mod)}),
2743727400 };
2743827401 operand_val.writeToMemory(operand_ty, sema.mod, buffer[reinterpret.byte_offset..]) catch |err| switch (err) {
27402 error.OutOfMemory => return error.OutOfMemory,
2743927403 error.ReinterpretDeclRef => unreachable,
2744027404 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
2744127405 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{mut_kit.ty.fmt(sema.mod)}),
......@@ -27589,7 +27553,7 @@ fn beginComptimePtrMutation(
2758927553 assert(bytes.len >= dest_len);
2759027554 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
2759127555 for (elems, 0..) |*elem, i| {
27592 elem.* = try Value.Tag.int_u64.create(arena, bytes[i]);
27556 elem.* = try mod.intValue(elem_ty, bytes[i]);
2759327557 }
2759427558
2759527559 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
......@@ -27618,7 +27582,7 @@ fn beginComptimePtrMutation(
2761827582 const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
2761927583 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
2762027584 for (bytes, 0..) |byte, i| {
27621 elems[i] = try Value.Tag.int_u64.create(arena, byte);
27585 elems[i] = try mod.intValue(elem_ty, byte);
2762227586 }
2762327587 if (parent.ty.sentinel(mod)) |sent_val| {
2762427588 assert(elems.len == bytes.len + 1);
......@@ -28111,7 +28075,7 @@ fn beginComptimePtrLoad(
2811128075 maybe_array_ty: ?Type,
2811228076) ComptimePtrLoadError!ComptimePtrLoadKit {
2811328077 const mod = sema.mod;
28114 const target = sema.mod.getTarget();
28078 const target = mod.getTarget();
2811528079
2811628080 var deref: ComptimePtrLoadKit = switch (ptr_val.ip_index) {
2811728081 .null_value => {
......@@ -28128,7 +28092,7 @@ fn beginComptimePtrLoad(
2812828092 else => unreachable,
2812928093 };
2813028094 const is_mutable = ptr_val.tag() == .decl_ref_mut;
28131 const decl = sema.mod.declPtr(decl_index);
28095 const decl = mod.declPtr(decl_index);
2813228096 const decl_tv = try decl.typedValue();
2813328097 if (decl_tv.val.tagIsVariable()) return error.RuntimeLoad;
2813428098
......@@ -28150,7 +28114,7 @@ fn beginComptimePtrLoad(
2815028114 // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that
2815128115 // our parent is not an elem_ptr with the same elem_ty, since that would be "unflattened"
2815228116 if (elem_ptr.array_ptr.castTag(.elem_ptr)) |parent_elem_ptr| {
28153 assert(!(parent_elem_ptr.data.elem_ty.eql(elem_ty, sema.mod)));
28117 assert(!(parent_elem_ptr.data.elem_ty.eql(elem_ty, mod)));
2815428118 }
2815528119
2815628120 if (elem_ptr.index != 0) {
......@@ -28184,11 +28148,11 @@ fn beginComptimePtrLoad(
2818428148 if (maybe_array_ty) |load_ty| {
2818528149 // It's possible that we're loading a [N]T, in which case we'd like to slice
2818628150 // the pointee array directly from our parent array.
28187 if (load_ty.isArrayOrVector(mod) and load_ty.childType(mod).eql(elem_ty, sema.mod)) {
28151 if (load_ty.isArrayOrVector(mod) and load_ty.childType(mod).eql(elem_ty, mod)) {
2818828152 const N = try sema.usizeCast(block, src, load_ty.arrayLenIncludingSentinel(mod));
2818928153 deref.pointee = if (elem_ptr.index + N <= check_len) TypedValue{
28190 .ty = try Type.array(sema.arena, N, null, elem_ty, sema.mod),
28191 .val = try array_tv.val.sliceArray(sema.mod, sema.arena, elem_ptr.index, elem_ptr.index + N),
28154 .ty = try Type.array(sema.arena, N, null, elem_ty, mod),
28155 .val = try array_tv.val.sliceArray(mod, sema.arena, elem_ptr.index, elem_ptr.index + N),
2819228156 } else null;
2819328157 break :blk deref;
2819428158 }
......@@ -28209,7 +28173,7 @@ fn beginComptimePtrLoad(
2820928173 }
2821028174 deref.pointee = TypedValue{
2821128175 .ty = elem_ty,
28212 .val = try array_tv.val.elemValue(sema.mod, sema.arena, elem_ptr.index),
28176 .val = try array_tv.val.elemValue(mod, elem_ptr.index),
2821328177 };
2821428178 break :blk deref;
2821528179 },
......@@ -28329,12 +28293,6 @@ fn beginComptimePtrLoad(
2832928293 break :blk try sema.beginComptimePtrLoad(block, src, opt_payload, null);
2833028294 },
2833128295
28332 .zero,
28333 .one,
28334 .int_u64,
28335 .int_i64,
28336 .int_big_positive,
28337 .int_big_negative,
2833828296 .variable,
2833928297 .extern_fn,
2834028298 .function,
......@@ -28342,7 +28300,10 @@ fn beginComptimePtrLoad(
2834228300
2834328301 else => unreachable,
2834428302 },
28345 else => unreachable,
28303 else => switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {
28304 .int => return error.RuntimeLoad,
28305 else => unreachable,
28306 },
2834628307 };
2834728308
2834828309 if (deref.pointee) |tv| {
......@@ -28373,9 +28334,9 @@ fn bitCast(
2837328334
2837428335 if (old_bits != dest_bits) {
2837528336 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{
28376 dest_ty.fmt(sema.mod),
28337 dest_ty.fmt(mod),
2837728338 dest_bits,
28378 old_ty.fmt(sema.mod),
28339 old_ty.fmt(mod),
2837928340 old_bits,
2838028341 });
2838128342 }
......@@ -28407,6 +28368,7 @@ fn bitCastVal(
2840728368 const buffer = try sema.gpa.alloc(u8, abi_size);
2840828369 defer sema.gpa.free(buffer);
2840928370 val.writeToMemory(old_ty, mod, buffer) catch |err| switch (err) {
28371 error.OutOfMemory => return error.OutOfMemory,
2841028372 error.ReinterpretDeclRef => return null,
2841128373 error.IllDefinedMemoryLayout => unreachable, // Sema was supposed to emit a compile error already
2841228374 error.Unimplemented => return sema.fail(block, src, "TODO: implement writeToMemory for type '{}'", .{old_ty.fmt(mod)}),
......@@ -28427,7 +28389,7 @@ fn coerceArrayPtrToSlice(
2842728389 const array_ty = ptr_array_ty.childType(mod);
2842828390 const slice_val = try Value.Tag.slice.create(sema.arena, .{
2842928391 .ptr = val,
28430 .len = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen(mod)),
28392 .len = try mod.intValue(Type.usize, array_ty.arrayLen(mod)),
2843128393 });
2843228394 return sema.addConstant(dest_ty, slice_val);
2843328395 }
......@@ -28781,7 +28743,7 @@ fn coerceArrayLike(
2878128743 for (element_vals, 0..) |*elem, i| {
2878228744 const index_ref = try sema.addConstant(
2878328745 Type.usize,
28784 try Value.Tag.int_u64.create(sema.arena, i),
28746 try mod.intValue(Type.usize, i),
2878528747 );
2878628748 const src = inst_src; // TODO better source location
2878728749 const elem_src = inst_src; // TODO better source location
......@@ -29634,7 +29596,7 @@ fn analyzeSlice(
2963429596 var end_is_len = uncasted_end_opt == .none;
2963529597 const end = e: {
2963629598 if (array_ty.zigTypeTag(mod) == .Array) {
29637 const len_val = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen(mod));
29599 const len_val = try mod.intValue(Type.usize, array_ty.arrayLen(mod));
2963829600
2963929601 if (!end_is_len) {
2964029602 const end = if (by_length) end: {
......@@ -29643,8 +29605,8 @@ fn analyzeSlice(
2964329605 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
2964429606 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
2964529607 if (try sema.resolveMaybeUndefVal(end)) |end_val| {
29646 const len_s_val = try Value.Tag.int_u64.create(
29647 sema.arena,
29608 const len_s_val = try mod.intValue(
29609 Type.usize,
2964829610 array_ty.arrayLenIncludingSentinel(mod),
2964929611 );
2965029612 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
......@@ -29689,12 +29651,10 @@ fn analyzeSlice(
2968929651 return sema.fail(block, src, "slice of undefined", .{});
2969029652 }
2969129653 const has_sentinel = slice_ty.sentinel(mod) != null;
29692 var int_payload: Value.Payload.U64 = .{
29693 .base = .{ .tag = .int_u64 },
29694 .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel),
29695 };
29696 const slice_len_val = Value.initPayload(&int_payload.base);
29697 if (!(try sema.compareAll(end_val, .lte, slice_len_val, Type.usize))) {
29654 const slice_len = slice_val.sliceLen(mod);
29655 const len_plus_sent = slice_len + @boolToInt(has_sentinel);
29656 const slice_len_val_with_sentinel = try mod.intValue(Type.usize, len_plus_sent);
29657 if (!(try sema.compareAll(end_val, .lte, slice_len_val_with_sentinel, Type.usize))) {
2969829658 const sentinel_label: []const u8 = if (has_sentinel)
2969929659 " +1 (sentinel)"
2970029660 else
......@@ -29712,13 +29672,10 @@ fn analyzeSlice(
2971229672 );
2971329673 }
2971429674
29715 // If the slice has a sentinel, we subtract one so that
29716 // end_is_len is only true if it equals the length WITHOUT
29717 // the sentinel, so we don't add a sentinel type.
29718 if (has_sentinel) {
29719 int_payload.data -= 1;
29720 }
29721
29675 // If the slice has a sentinel, we consider end_is_len
29676 // is only true if it equals the length WITHOUT the
29677 // sentinel, so we don't add a sentinel type.
29678 const slice_len_val = try mod.intValue(Type.usize, slice_len);
2972229679 if (end_val.eql(slice_len_val, Type.usize, mod)) {
2972329680 end_is_len = true;
2972429681 }
......@@ -30134,7 +30091,7 @@ fn cmpNumeric(
3013430091 }
3013530092 }
3013630093
30137 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128));
30094 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, mod));
3013830095 defer bigint.deinit();
3013930096 if (lhs_val.floatHasFraction()) {
3014030097 if (lhs_is_signed) {
......@@ -30193,7 +30150,7 @@ fn cmpNumeric(
3019330150 }
3019430151 }
3019530152
30196 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128));
30153 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, mod));
3019730154 defer bigint.deinit();
3019830155 if (rhs_val.floatHasFraction()) {
3019930156 if (rhs_is_signed) {
......@@ -31835,6 +31792,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3183531792 .zero_u8 => unreachable,
3183631793 .one => unreachable,
3183731794 .one_usize => unreachable,
31795 .negative_one => unreachable,
3183831796 .calling_convention_c => unreachable,
3183931797 .calling_convention_inline => unreachable,
3184031798 .void_value => unreachable,
......@@ -32462,11 +32420,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3246232420 }
3246332421
3246432422 if (fields_len > 0) {
32465 var field_count_val: Value.Payload.U64 = .{
32466 .base = .{ .tag = .int_u64 },
32467 .data = fields_len - 1,
32468 };
32469 if (!(try sema.intFitsInType(Value.initPayload(&field_count_val.base), int_tag_ty, null))) {
32423 const field_count_val = try mod.intValue(int_tag_ty, fields_len - 1);
32424 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
3247032425 const msg = msg: {
3247132426 const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{});
3247232427 errdefer msg.destroy(sema.gpa);
......@@ -33207,7 +33162,8 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3320733162}
3320833163
3320933164fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
33210 return sema.addConstant(ty, try Value.Tag.int_u64.create(sema.arena, int));
33165 const mod = sema.mod;
33166 return sema.addConstant(ty, try mod.intValue(ty, int));
3321133167}
3321233168
3321333169fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {
......@@ -33223,7 +33179,11 @@ pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {
3322333179 .tag = .interned,
3322433180 .data = .{ .interned = val.ip_index },
3322533181 });
33226 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33182 const result = Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33183 // This assertion can be removed when the `ty` parameter is removed from
33184 // this function thanks to the InternPool transition being complete.
33185 assert(Type.eql(sema.typeOf(result), ty, sema.mod));
33186 return result;
3322733187 }
3322833188 const ty_inst = try sema.addType(ty);
3322933189 try sema.air_values.append(gpa, val);
......@@ -33833,19 +33793,18 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3383333793 const mod = sema.mod;
3383433794 if (ty.zigTypeTag(mod) == .Vector) {
3383533795 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
33796 const scalar_ty = ty.scalarType(mod);
3383633797 for (result_data, 0..) |*scalar, i| {
33837 var lhs_buf: Value.ElemValueBuffer = undefined;
33838 var rhs_buf: Value.ElemValueBuffer = undefined;
33839 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
33840 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
33841 scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem);
33798 const lhs_elem = try lhs.elemValue(mod, i);
33799 const rhs_elem = try rhs.elemValue(mod, i);
33800 scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem, scalar_ty);
3384233801 }
3384333802 return Value.Tag.aggregate.create(sema.arena, result_data);
3384433803 }
33845 return sema.intAddScalar(lhs, rhs);
33804 return sema.intAddScalar(lhs, rhs, ty);
3384633805}
3384733806
33848fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
33807fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3384933808 const mod = sema.mod;
3385033809 // TODO is this a performance issue? maybe we should try the operation without
3385133810 // resorting to BigInt first.
......@@ -33859,7 +33818,7 @@ fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
3385933818 );
3386033819 var result_bigint = std.math.big.int.Mutable{ .limbs = limbs, .positive = undefined, .len = undefined };
3386133820 result_bigint.add(lhs_bigint, rhs_bigint);
33862 return Value.fromBigInt(sema.arena, result_bigint.toConst());
33821 return mod.intValue_big(scalar_ty, result_bigint.toConst());
3386333822}
3386433823
3386533824/// Supports both floats and ints; handles undefined.
......@@ -33884,28 +33843,22 @@ fn numberAddWrapScalar(
3388433843 return overflow_result.wrapped_result;
3388533844}
3388633845
33887fn intSub(
33888 sema: *Sema,
33889 lhs: Value,
33890 rhs: Value,
33891 ty: Type,
33892) !Value {
33846fn intSub(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3389333847 const mod = sema.mod;
3389433848 if (ty.zigTypeTag(mod) == .Vector) {
3389533849 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
33850 const scalar_ty = ty.scalarType(mod);
3389633851 for (result_data, 0..) |*scalar, i| {
33897 var lhs_buf: Value.ElemValueBuffer = undefined;
33898 var rhs_buf: Value.ElemValueBuffer = undefined;
33899 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
33900 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
33901 scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem);
33852 const lhs_elem = try lhs.elemValue(sema.mod, i);
33853 const rhs_elem = try rhs.elemValue(sema.mod, i);
33854 scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem, scalar_ty);
3390233855 }
3390333856 return Value.Tag.aggregate.create(sema.arena, result_data);
3390433857 }
33905 return sema.intSubScalar(lhs, rhs);
33858 return sema.intSubScalar(lhs, rhs, ty);
3390633859}
3390733860
33908fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
33861fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3390933862 const mod = sema.mod;
3391033863 // TODO is this a performance issue? maybe we should try the operation without
3391133864 // resorting to BigInt first.
......@@ -33919,7 +33872,7 @@ fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
3391933872 );
3392033873 var result_bigint = std.math.big.int.Mutable{ .limbs = limbs, .positive = undefined, .len = undefined };
3392133874 result_bigint.sub(lhs_bigint, rhs_bigint);
33922 return Value.fromBigInt(sema.arena, result_bigint.toConst());
33875 return mod.intValue_big(scalar_ty, result_bigint.toConst());
3392333876}
3392433877
3392533878/// Supports both floats and ints; handles undefined.
......@@ -33954,10 +33907,8 @@ fn floatAdd(
3395433907 if (float_type.zigTypeTag(mod) == .Vector) {
3395533908 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
3395633909 for (result_data, 0..) |*scalar, i| {
33957 var lhs_buf: Value.ElemValueBuffer = undefined;
33958 var rhs_buf: Value.ElemValueBuffer = undefined;
33959 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
33960 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
33910 const lhs_elem = try lhs.elemValue(sema.mod, i);
33911 const rhs_elem = try rhs.elemValue(sema.mod, i);
3396133912 scalar.* = try sema.floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType(mod));
3396233913 }
3396333914 return Value.Tag.aggregate.create(sema.arena, result_data);
......@@ -33971,31 +33922,32 @@ fn floatAddScalar(
3397133922 rhs: Value,
3397233923 float_type: Type,
3397333924) !Value {
33925 const mod = sema.mod;
3397433926 const target = sema.mod.getTarget();
3397533927 switch (float_type.floatBits(target)) {
3397633928 16 => {
33977 const lhs_val = lhs.toFloat(f16);
33978 const rhs_val = rhs.toFloat(f16);
33929 const lhs_val = lhs.toFloat(f16, mod);
33930 const rhs_val = rhs.toFloat(f16, mod);
3397933931 return Value.Tag.float_16.create(sema.arena, lhs_val + rhs_val);
3398033932 },
3398133933 32 => {
33982 const lhs_val = lhs.toFloat(f32);
33983 const rhs_val = rhs.toFloat(f32);
33934 const lhs_val = lhs.toFloat(f32, mod);
33935 const rhs_val = rhs.toFloat(f32, mod);
3398433936 return Value.Tag.float_32.create(sema.arena, lhs_val + rhs_val);
3398533937 },
3398633938 64 => {
33987 const lhs_val = lhs.toFloat(f64);
33988 const rhs_val = rhs.toFloat(f64);
33939 const lhs_val = lhs.toFloat(f64, mod);
33940 const rhs_val = rhs.toFloat(f64, mod);
3398933941 return Value.Tag.float_64.create(sema.arena, lhs_val + rhs_val);
3399033942 },
3399133943 80 => {
33992 const lhs_val = lhs.toFloat(f80);
33993 const rhs_val = rhs.toFloat(f80);
33944 const lhs_val = lhs.toFloat(f80, mod);
33945 const rhs_val = rhs.toFloat(f80, mod);
3399433946 return Value.Tag.float_80.create(sema.arena, lhs_val + rhs_val);
3399533947 },
3399633948 128 => {
33997 const lhs_val = lhs.toFloat(f128);
33998 const rhs_val = rhs.toFloat(f128);
33949 const lhs_val = lhs.toFloat(f128, mod);
33950 const rhs_val = rhs.toFloat(f128, mod);
3399933951 return Value.Tag.float_128.create(sema.arena, lhs_val + rhs_val);
3400033952 },
3400133953 else => unreachable,
......@@ -34012,10 +33964,8 @@ fn floatSub(
3401233964 if (float_type.zigTypeTag(mod) == .Vector) {
3401333965 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
3401433966 for (result_data, 0..) |*scalar, i| {
34015 var lhs_buf: Value.ElemValueBuffer = undefined;
34016 var rhs_buf: Value.ElemValueBuffer = undefined;
34017 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
34018 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
33967 const lhs_elem = try lhs.elemValue(sema.mod, i);
33968 const rhs_elem = try rhs.elemValue(sema.mod, i);
3401933969 scalar.* = try sema.floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType(mod));
3402033970 }
3402133971 return Value.Tag.aggregate.create(sema.arena, result_data);
......@@ -34029,31 +33979,32 @@ fn floatSubScalar(
3402933979 rhs: Value,
3403033980 float_type: Type,
3403133981) !Value {
33982 const mod = sema.mod;
3403233983 const target = sema.mod.getTarget();
3403333984 switch (float_type.floatBits(target)) {
3403433985 16 => {
34035 const lhs_val = lhs.toFloat(f16);
34036 const rhs_val = rhs.toFloat(f16);
33986 const lhs_val = lhs.toFloat(f16, mod);
33987 const rhs_val = rhs.toFloat(f16, mod);
3403733988 return Value.Tag.float_16.create(sema.arena, lhs_val - rhs_val);
3403833989 },
3403933990 32 => {
34040 const lhs_val = lhs.toFloat(f32);
34041 const rhs_val = rhs.toFloat(f32);
33991 const lhs_val = lhs.toFloat(f32, mod);
33992 const rhs_val = rhs.toFloat(f32, mod);
3404233993 return Value.Tag.float_32.create(sema.arena, lhs_val - rhs_val);
3404333994 },
3404433995 64 => {
34045 const lhs_val = lhs.toFloat(f64);
34046 const rhs_val = rhs.toFloat(f64);
33996 const lhs_val = lhs.toFloat(f64, mod);
33997 const rhs_val = rhs.toFloat(f64, mod);
3404733998 return Value.Tag.float_64.create(sema.arena, lhs_val - rhs_val);
3404833999 },
3404934000 80 => {
34050 const lhs_val = lhs.toFloat(f80);
34051 const rhs_val = rhs.toFloat(f80);
34001 const lhs_val = lhs.toFloat(f80, mod);
34002 const rhs_val = rhs.toFloat(f80, mod);
3405234003 return Value.Tag.float_80.create(sema.arena, lhs_val - rhs_val);
3405334004 },
3405434005 128 => {
34055 const lhs_val = lhs.toFloat(f128);
34056 const rhs_val = rhs.toFloat(f128);
34006 const lhs_val = lhs.toFloat(f128, mod);
34007 const rhs_val = rhs.toFloat(f128, mod);
3405734008 return Value.Tag.float_128.create(sema.arena, lhs_val - rhs_val);
3405834009 },
3405934010 else => unreachable,
......@@ -34071,10 +34022,8 @@ fn intSubWithOverflow(
3407134022 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3407234023 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3407334024 for (result_data, 0..) |*scalar, i| {
34074 var lhs_buf: Value.ElemValueBuffer = undefined;
34075 var rhs_buf: Value.ElemValueBuffer = undefined;
34076 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
34077 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
34025 const lhs_elem = try lhs.elemValue(sema.mod, i);
34026 const rhs_elem = try rhs.elemValue(sema.mod, i);
3407834027 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));
3407934028 overflowed_data[i] = of_math_result.overflow_bit;
3408034029 scalar.* = of_math_result.wrapped_result;
......@@ -34106,7 +34055,7 @@ fn intSubWithOverflowScalar(
3410634055 );
3410734056 var result_bigint = std.math.big.int.Mutable{ .limbs = limbs, .positive = undefined, .len = undefined };
3410834057 const overflowed = result_bigint.subWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits);
34109 const wrapped_result = try Value.fromBigInt(sema.arena, result_bigint.toConst());
34058 const wrapped_result = try mod.intValue_big(ty, result_bigint.toConst());
3411034059 return Value.OverflowArithmeticResult{
3411134060 .overflow_bit = Value.boolToInt(overflowed),
3411234061 .wrapped_result = wrapped_result,
......@@ -34126,8 +34075,7 @@ fn floatToInt(
3412634075 const elem_ty = float_ty.childType(mod);
3412734076 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen(mod));
3412834077 for (result_data, 0..) |*scalar, i| {
34129 var buf: Value.ElemValueBuffer = undefined;
34130 const elem_val = val.elemValueBuffer(sema.mod, i, &buf);
34078 const elem_val = try val.elemValue(sema.mod, i);
3413134079 scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod));
3413234080 }
3413334081 return Value.Tag.aggregate.create(sema.arena, result_data);
......@@ -34168,9 +34116,9 @@ fn floatToIntScalar(
3416834116 float_ty: Type,
3416934117 int_ty: Type,
3417034118) CompileError!Value {
34171 const Limb = std.math.big.Limb;
34119 const mod = sema.mod;
3417234120
34173 const float = val.toFloat(f128);
34121 const float = val.toFloat(f128, mod);
3417434122 if (std.math.isNan(float)) {
3417534123 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{}'", .{
3417634124 int_ty.fmt(sema.mod),
......@@ -34185,11 +34133,7 @@ fn floatToIntScalar(
3418534133 var big_int = try float128IntPartToBigInt(sema.arena, float);
3418634134 defer big_int.deinit();
3418734135
34188 const result_limbs = try sema.arena.dupe(Limb, big_int.toConst().limbs);
34189 const result = if (!big_int.isPositive())
34190 try Value.Tag.int_big_negative.create(sema.arena, result_limbs)
34191 else
34192 try Value.Tag.int_big_positive.create(sema.arena, result_limbs);
34136 const result = try mod.intValue_big(int_ty, big_int.toConst());
3419334137
3419434138 if (!(try sema.intFitsInType(result, int_ty, null))) {
3419534139 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{
......@@ -34209,8 +34153,8 @@ fn intFitsInType(
3420934153 ty: Type,
3421034154 vector_index: ?*usize,
3421134155) CompileError!bool {
34156 if (ty.ip_index == .comptime_int_type) return true;
3421234157 const mod = sema.mod;
34213 const target = mod.getTarget();
3421434158 switch (val.ip_index) {
3421534159 .undef,
3421634160 .zero,
......@@ -34218,103 +34162,26 @@ fn intFitsInType(
3421834162 .zero_u8,
3421934163 => return true,
3422034164
34221 .one,
34222 .one_usize,
34223 => switch (ty.zigTypeTag(mod)) {
34224 .Int => {
34225 const info = ty.intInfo(mod);
34226 return switch (info.signedness) {
34227 .signed => info.bits >= 2,
34228 .unsigned => info.bits >= 1,
34229 };
34230 },
34231 .ComptimeInt => return true,
34232 else => unreachable,
34233 },
34234
3423534165 .none => switch (val.tag()) {
34236 .zero => return true,
34237
34238 .one => switch (ty.zigTypeTag(mod)) {
34239 .Int => {
34240 const info = ty.intInfo(mod);
34241 return switch (info.signedness) {
34242 .signed => info.bits >= 2,
34243 .unsigned => info.bits >= 1,
34244 };
34245 },
34246 .ComptimeInt => return true,
34247 else => unreachable,
34248 },
34249
34250 .lazy_align => switch (ty.zigTypeTag(mod)) {
34251 .Int => {
34252 const info = ty.intInfo(mod);
34253 const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed);
34254 // If it is u16 or bigger we know the alignment fits without resolving it.
34255 if (info.bits >= max_needed_bits) return true;
34256 const x = try sema.typeAbiAlignment(val.castTag(.lazy_align).?.data);
34257 if (x == 0) return true;
34258 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
34259 return info.bits >= actual_needed_bits;
34260 },
34261 .ComptimeInt => return true,
34262 else => unreachable,
34263 },
34264 .lazy_size => switch (ty.zigTypeTag(mod)) {
34265 .Int => {
34266 const info = ty.intInfo(mod);
34267 const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed);
34268 // If it is u64 or bigger we know the size fits without resolving it.
34269 if (info.bits >= max_needed_bits) return true;
34270 const x = try sema.typeAbiSize(val.castTag(.lazy_size).?.data);
34271 if (x == 0) return true;
34272 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
34273 return info.bits >= actual_needed_bits;
34274 },
34275 .ComptimeInt => return true,
34276 else => unreachable,
34277 },
34278
34279 .int_u64 => switch (ty.zigTypeTag(mod)) {
34280 .Int => {
34281 const x = val.castTag(.int_u64).?.data;
34282 if (x == 0) return true;
34283 const info = ty.intInfo(mod);
34284 const needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
34285 return info.bits >= needed_bits;
34286 },
34287 .ComptimeInt => return true,
34288 else => unreachable,
34289 },
34290 .int_i64 => switch (ty.zigTypeTag(mod)) {
34291 .Int => {
34292 const x = val.castTag(.int_i64).?.data;
34293 if (x == 0) return true;
34294 const info = ty.intInfo(mod);
34295 if (info.signedness == .unsigned and x < 0)
34296 return false;
34297 var buffer: Value.BigIntSpace = undefined;
34298 return (try val.toBigIntAdvanced(&buffer, mod, sema)).fitsInTwosComp(info.signedness, info.bits);
34299 },
34300 .ComptimeInt => return true,
34301 else => unreachable,
34302 },
34303 .int_big_positive => switch (ty.zigTypeTag(mod)) {
34304 .Int => {
34305 const info = ty.intInfo(mod);
34306 return val.castTag(.int_big_positive).?.asBigInt().fitsInTwosComp(info.signedness, info.bits);
34307 },
34308 .ComptimeInt => return true,
34309 else => unreachable,
34166 .lazy_align => {
34167 const info = ty.intInfo(mod);
34168 const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed);
34169 // If it is u16 or bigger we know the alignment fits without resolving it.
34170 if (info.bits >= max_needed_bits) return true;
34171 const x = try sema.typeAbiAlignment(val.castTag(.lazy_align).?.data);
34172 if (x == 0) return true;
34173 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
34174 return info.bits >= actual_needed_bits;
3431034175 },
34311 .int_big_negative => switch (ty.zigTypeTag(mod)) {
34312 .Int => {
34313 const info = ty.intInfo(mod);
34314 return val.castTag(.int_big_negative).?.asBigInt().fitsInTwosComp(info.signedness, info.bits);
34315 },
34316 .ComptimeInt => return true,
34317 else => unreachable,
34176 .lazy_size => {
34177 const info = ty.intInfo(mod);
34178 const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed);
34179 // If it is u64 or bigger we know the size fits without resolving it.
34180 if (info.bits >= max_needed_bits) return true;
34181 const x = try sema.typeAbiSize(val.castTag(.lazy_size).?.data);
34182 if (x == 0) return true;
34183 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
34184 return info.bits >= actual_needed_bits;
3431834185 },
3431934186
3432034187 .the_only_possible_value => {
......@@ -34327,17 +34194,14 @@ fn intFitsInType(
3432734194 .decl_ref,
3432834195 .function,
3432934196 .variable,
34330 => switch (ty.zigTypeTag(mod)) {
34331 .Int => {
34332 const info = ty.intInfo(mod);
34333 const ptr_bits = target.ptrBitWidth();
34334 return switch (info.signedness) {
34335 .signed => info.bits > ptr_bits,
34336 .unsigned => info.bits >= ptr_bits,
34337 };
34338 },
34339 .ComptimeInt => return true,
34340 else => unreachable,
34197 => {
34198 const info = ty.intInfo(mod);
34199 const target = mod.getTarget();
34200 const ptr_bits = target.ptrBitWidth();
34201 return switch (info.signedness) {
34202 .signed => info.bits > ptr_bits,
34203 .unsigned => info.bits >= ptr_bits,
34204 };
3434134205 },
3434234206
3434334207 .aggregate => {
......@@ -34354,22 +34218,22 @@ fn intFitsInType(
3435434218 else => unreachable,
3435534219 },
3435634220
34357 else => @panic("TODO"),
34221 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
34222 .int => |int| {
34223 const info = ty.intInfo(mod);
34224 var buffer: InternPool.Key.Int.Storage.BigIntSpace = undefined;
34225 const big_int = int.storage.toBigInt(&buffer);
34226 return big_int.fitsInTwosComp(info.signedness, info.bits);
34227 },
34228 else => unreachable,
34229 },
3435834230 }
3435934231}
3436034232
34361fn intInRange(
34362 sema: *Sema,
34363 tag_ty: Type,
34364 int_val: Value,
34365 end: usize,
34366) !bool {
34233fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
34234 const mod = sema.mod;
3436734235 if (!(try int_val.compareAllWithZeroAdvanced(.gte, sema))) return false;
34368 var end_payload: Value.Payload.U64 = .{
34369 .base = .{ .tag = .int_u64 },
34370 .data = end,
34371 };
34372 const end_val = Value.initPayload(&end_payload.base);
34236 const end_val = try mod.intValue(tag_ty, end);
3437334237 if (!(try sema.compareAll(int_val, .lt, end_val, tag_ty))) return false;
3437434238 return true;
3437534239}
......@@ -34426,10 +34290,8 @@ fn intAddWithOverflow(
3442634290 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3442734291 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3442834292 for (result_data, 0..) |*scalar, i| {
34429 var lhs_buf: Value.ElemValueBuffer = undefined;
34430 var rhs_buf: Value.ElemValueBuffer = undefined;
34431 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
34432 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
34293 const lhs_elem = try lhs.elemValue(sema.mod, i);
34294 const rhs_elem = try rhs.elemValue(sema.mod, i);
3443334295 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));
3443434296 overflowed_data[i] = of_math_result.overflow_bit;
3443534297 scalar.* = of_math_result.wrapped_result;
......@@ -34461,7 +34323,7 @@ fn intAddWithOverflowScalar(
3446134323 );
3446234324 var result_bigint = std.math.big.int.Mutable{ .limbs = limbs, .positive = undefined, .len = undefined };
3446334325 const overflowed = result_bigint.addWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits);
34464 const result = try Value.fromBigInt(sema.arena, result_bigint.toConst());
34326 const result = try mod.intValue_big(ty, result_bigint.toConst());
3446534327 return Value.OverflowArithmeticResult{
3446634328 .overflow_bit = Value.boolToInt(overflowed),
3446734329 .wrapped_result = result,
......@@ -34483,10 +34345,8 @@ fn compareAll(
3448334345 if (ty.zigTypeTag(mod) == .Vector) {
3448434346 var i: usize = 0;
3448534347 while (i < ty.vectorLen(mod)) : (i += 1) {
34486 var lhs_buf: Value.ElemValueBuffer = undefined;
34487 var rhs_buf: Value.ElemValueBuffer = undefined;
34488 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
34489 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
34348 const lhs_elem = try lhs.elemValue(sema.mod, i);
34349 const rhs_elem = try rhs.elemValue(sema.mod, i);
3449034350 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod)))) {
3449134351 return false;
3449234352 }
......@@ -34532,10 +34392,8 @@ fn compareVector(
3453234392 assert(ty.zigTypeTag(mod) == .Vector);
3453334393 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3453434394 for (result_data, 0..) |*scalar, i| {
34535 var lhs_buf: Value.ElemValueBuffer = undefined;
34536 var rhs_buf: Value.ElemValueBuffer = undefined;
34537 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
34538 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
34395 const lhs_elem = try lhs.elemValue(sema.mod, i);
34396 const rhs_elem = try rhs.elemValue(sema.mod, i);
3453934397 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
3454034398 scalar.* = Value.makeBool(res_bool);
3454134399 }
src/TypedValue.zig+9-12
......@@ -41,8 +41,8 @@ pub fn hash(tv: TypedValue, hasher: *std.hash.Wyhash, mod: *Module) void {
4141 return tv.val.hash(tv.ty, hasher, mod);
4242}
4343
44pub fn enumToInt(tv: TypedValue, buffer: *Value.Payload.U64) Value {
45 return tv.val.enumToInt(tv.ty, buffer);
44pub fn enumToInt(tv: TypedValue, mod: *Module) Allocator.Error!Value {
45 return tv.val.enumToInt(tv.ty, mod);
4646}
4747
4848const max_aggregate_items = 100;
......@@ -157,14 +157,8 @@ pub fn print(
157157
158158 return writer.writeAll(" }");
159159 },
160 .zero => return writer.writeAll("0"),
161 .one => return writer.writeAll("1"),
162160 .the_only_possible_value => return writer.writeAll("0"),
163161 .ty => return val.castTag(.ty).?.data.print(writer, mod),
164 .int_u64 => return std.fmt.formatIntValue(val.castTag(.int_u64).?.data, "", .{}, writer),
165 .int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", .{}, writer),
166 .int_big_positive => return writer.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}),
167 .int_big_negative => return writer.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}),
168162 .lazy_align => {
169163 const sub_ty = val.castTag(.lazy_align).?.data;
170164 const x = sub_ty.abiAlignment(mod);
......@@ -313,8 +307,9 @@ pub fn print(
313307
314308 var i: u32 = 0;
315309 while (i < max_len) : (i += 1) {
316 var elem_buf: Value.ElemValueBuffer = undefined;
317 const elem_val = payload.ptr.elemValueBuffer(mod, i, &elem_buf);
310 const elem_val = payload.ptr.elemValue(mod, i) catch |err| switch (err) {
311 error.OutOfMemory => @panic("OOM"), // TODO: eliminate this panic
312 };
318313 if (elem_val.isUndef()) break :str;
319314 buf[i] = std.math.cast(u8, elem_val.toUnsignedInt(mod)) orelse break :str;
320315 }
......@@ -330,10 +325,12 @@ pub fn print(
330325 var i: u32 = 0;
331326 while (i < max_len) : (i += 1) {
332327 if (i != 0) try writer.writeAll(", ");
333 var buf: Value.ElemValueBuffer = undefined;
328 const elem_val = payload.ptr.elemValue(mod, i) catch |err| switch (err) {
329 error.OutOfMemory => @panic("OOM"), // TODO: eliminate this panic
330 };
334331 try print(.{
335332 .ty = elem_ty,
336 .val = payload.ptr.elemValueBuffer(mod, i, &buf),
333 .val = elem_val,
337334 }, writer, level - 1, mod);
338335 }
339336 if (len > max_aggregate_items) {
src/Zir.zig+1
......@@ -2120,6 +2120,7 @@ pub const Inst = struct {
21202120 zero_u8 = @enumToInt(InternPool.Index.zero_u8),
21212121 one = @enumToInt(InternPool.Index.one),
21222122 one_usize = @enumToInt(InternPool.Index.one_usize),
2123 negative_one = @enumToInt(InternPool.Index.negative_one),
21232124 calling_convention_c = @enumToInt(InternPool.Index.calling_convention_c),
21242125 calling_convention_inline = @enumToInt(InternPool.Index.calling_convention_inline),
21252126 void_value = @enumToInt(InternPool.Index.void_value),
src/arch/wasm/CodeGen.zig+17-19
......@@ -3083,20 +3083,21 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
30833083 },
30843084 .Bool => return WValue{ .imm32 = @intCast(u32, val.toUnsignedInt(mod)) },
30853085 .Float => switch (ty.floatBits(func.target)) {
3086 16 => return WValue{ .imm32 = @bitCast(u16, val.toFloat(f16)) },
3087 32 => return WValue{ .float32 = val.toFloat(f32) },
3088 64 => return WValue{ .float64 = val.toFloat(f64) },
3086 16 => return WValue{ .imm32 = @bitCast(u16, val.toFloat(f16, mod)) },
3087 32 => return WValue{ .float32 = val.toFloat(f32, mod) },
3088 64 => return WValue{ .float64 = val.toFloat(f64, mod) },
30893089 else => unreachable,
30903090 },
3091 .Pointer => switch (val.ip_index) {
3092 .null_value => return WValue{ .imm32 = 0 },
3091 .Pointer => return switch (val.ip_index) {
3092 .null_value => WValue{ .imm32 = 0 },
30933093 .none => switch (val.tag()) {
3094 .field_ptr, .elem_ptr, .opt_payload_ptr => return func.lowerParentPtr(val, 0),
3095 .int_u64, .one => return WValue{ .imm32 = @intCast(u32, val.toUnsignedInt(mod)) },
3096 .zero => return WValue{ .imm32 = 0 },
3094 .field_ptr, .elem_ptr, .opt_payload_ptr => func.lowerParentPtr(val, 0),
30973095 else => return func.fail("Wasm TODO: lowerConstant for other const pointer tag {}", .{val.tag()}),
30983096 },
3099 else => unreachable,
3097 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
3098 .int => |int| WValue{ .imm32 = @intCast(u32, int.storage.u64) },
3099 else => unreachable,
3100 },
31003101 },
31013102 .Enum => {
31023103 if (val.castTag(.enum_field_index)) |field_index| {
......@@ -3137,7 +3138,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
31373138 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
31383139 // We use the error type directly as the type.
31393140 const is_pl = val.errorUnionIsPayload();
3140 const err_val = if (!is_pl) val else Value.initTag(.zero);
3141 const err_val = if (!is_pl) val else Value.zero;
31413142 return func.lowerConstant(err_val, error_type);
31423143 }
31433144 return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
......@@ -3160,11 +3161,10 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
31603161 assert(struct_obj.layout == .Packed);
31613162 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
31623163 val.writeToPackedMemory(ty, func.bin_file.base.options.module.?, &buf, 0) catch unreachable;
3163 var payload: Value.Payload.U64 = .{
3164 .base = .{ .tag = .int_u64 },
3165 .data = std.mem.readIntLittle(u64, &buf),
3166 };
3167 const int_val = Value.initPayload(&payload.base);
3164 const int_val = try mod.intValue(
3165 struct_obj.backing_int_ty,
3166 std.mem.readIntLittle(u64, &buf),
3167 );
31683168 return func.lowerConstant(int_val, struct_obj.backing_int_ty);
31693169 },
31703170 .Vector => {
......@@ -4899,8 +4899,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48994899 const result = try func.allocStack(inst_ty);
49004900
49014901 for (0..mask_len) |index| {
4902 var buf: Value.ElemValueBuffer = undefined;
4903 const value = mask.elemValueBuffer(mod, index, &buf).toSignedInt(mod);
4902 const value = (try mask.elemValue(mod, index)).toSignedInt(mod);
49044903
49054904 try func.emitWValue(result);
49064905
......@@ -4920,8 +4919,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49204919
49214920 var lanes = std.mem.asBytes(operands[1..]);
49224921 for (0..@intCast(usize, mask_len)) |index| {
4923 var buf: Value.ElemValueBuffer = undefined;
4924 const mask_elem = mask.elemValueBuffer(mod, index, &buf).toSignedInt(mod);
4922 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);
49254923 const base_index = if (mask_elem >= 0)
49264924 @intCast(u8, @intCast(i64, elem_size) * mask_elem)
49274925 else
src/arch/x86_64/CodeGen.zig+3-19
......@@ -2757,11 +2757,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27572757 dst_ty.fmt(self.bin_file.options.module.?),
27582758 });
27592759
2760 var mask_pl = Value.Payload.U64{
2761 .base = .{ .tag = .int_u64 },
2762 .data = @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - dst_info.bits),
2763 };
2764 const mask_val = Value.initPayload(&mask_pl.base);
2760 const elem_ty = src_ty.childType(mod);
2761 const mask_val = try mod.intValue(elem_ty, @as(u64, math.maxInt(u64)) >> @intCast(u6, 64 - dst_info.bits));
27652762
27662763 var splat_pl = Value.Payload.SubValue{
27672764 .base = .{ .tag = .repeated },
......@@ -4906,18 +4903,6 @@ fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
49064903 defer arena.deinit();
49074904
49084905 const ExpectedContents = struct {
4909 scalar: union {
4910 i64: Value.Payload.I64,
4911 big: struct {
4912 limbs: [
4913 @max(
4914 std.math.big.int.Managed.default_capacity,
4915 std.math.big.int.calcTwosCompLimbCount(128),
4916 )
4917 ]std.math.big.Limb,
4918 pl: Value.Payload.BigInt,
4919 },
4920 },
49214906 repeated: Value.Payload.SubValue,
49224907 };
49234908 var stack align(@alignOf(ExpectedContents)) =
......@@ -11429,8 +11414,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1142911414 const field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name).?);
1143011415 var tag_pl = Value.Payload.U32{ .base = .{ .tag = .enum_field_index }, .data = field_index };
1143111416 const tag_val = Value.initPayload(&tag_pl.base);
11432 var tag_int_pl: Value.Payload.U64 = undefined;
11433 const tag_int_val = tag_val.enumToInt(tag_ty, &tag_int_pl);
11417 const tag_int_val = try tag_val.enumToInt(tag_ty, mod);
1143411418 const tag_int = tag_int_val.toUnsignedInt(mod);
1143511419 const tag_off = if (layout.tag_align < layout.payload_align)
1143611420 @intCast(i32, layout.payload_size)
src/codegen.zig+31-34
......@@ -214,15 +214,15 @@ pub fn generateSymbol(
214214 },
215215 .Float => {
216216 switch (typed_value.ty.floatBits(target)) {
217 16 => writeFloat(f16, typed_value.val.toFloat(f16), target, endian, try code.addManyAsArray(2)),
218 32 => writeFloat(f32, typed_value.val.toFloat(f32), target, endian, try code.addManyAsArray(4)),
219 64 => writeFloat(f64, typed_value.val.toFloat(f64), target, endian, try code.addManyAsArray(8)),
217 16 => writeFloat(f16, typed_value.val.toFloat(f16, mod), target, endian, try code.addManyAsArray(2)),
218 32 => writeFloat(f32, typed_value.val.toFloat(f32, mod), target, endian, try code.addManyAsArray(4)),
219 64 => writeFloat(f64, typed_value.val.toFloat(f64, mod), target, endian, try code.addManyAsArray(8)),
220220 80 => {
221 writeFloat(f80, typed_value.val.toFloat(f80), target, endian, try code.addManyAsArray(10));
221 writeFloat(f80, typed_value.val.toFloat(f80, mod), target, endian, try code.addManyAsArray(10));
222222 const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow;
223223 try code.appendNTimes(0, abi_size - 10);
224224 },
225 128 => writeFloat(f128, typed_value.val.toFloat(f128), target, endian, try code.addManyAsArray(16)),
225 128 => writeFloat(f128, typed_value.val.toFloat(f128, mod), target, endian, try code.addManyAsArray(16)),
226226 else => unreachable,
227227 }
228228 return Result.ok;
......@@ -328,20 +328,6 @@ pub fn generateSymbol(
328328 return Result.ok;
329329 },
330330 .none => switch (typed_value.val.tag()) {
331 .zero, .one, .int_u64, .int_big_positive => {
332 switch (target.ptrBitWidth()) {
333 32 => {
334 const x = typed_value.val.toUnsignedInt(mod);
335 mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, x), endian);
336 },
337 64 => {
338 const x = typed_value.val.toUnsignedInt(mod);
339 mem.writeInt(u64, try code.addManyAsArray(8), x, endian);
340 },
341 else => unreachable,
342 }
343 return Result.ok;
344 },
345331 .variable, .decl_ref, .decl_ref_mut => |tag| return lowerDeclRef(
346332 bin_file,
347333 src_loc,
......@@ -399,7 +385,23 @@ pub fn generateSymbol(
399385 ),
400386 },
401387 },
402 else => unreachable,
388 else => switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {
389 .int => {
390 switch (target.ptrBitWidth()) {
391 32 => {
392 const x = typed_value.val.toUnsignedInt(mod);
393 mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, x), endian);
394 },
395 64 => {
396 const x = typed_value.val.toUnsignedInt(mod);
397 mem.writeInt(u64, try code.addManyAsArray(8), x, endian);
398 },
399 else => unreachable,
400 }
401 return Result.ok;
402 },
403 else => unreachable,
404 },
403405 },
404406 .Int => {
405407 const info = typed_value.ty.intInfo(mod);
......@@ -449,8 +451,7 @@ pub fn generateSymbol(
449451 return Result.ok;
450452 },
451453 .Enum => {
452 var int_buffer: Value.Payload.U64 = undefined;
453 const int_val = typed_value.enumToInt(&int_buffer);
454 const int_val = try typed_value.enumToInt(mod);
454455
455456 const info = typed_value.ty.intInfo(mod);
456457 if (info.bits <= 8) {
......@@ -674,7 +675,7 @@ pub fn generateSymbol(
674675 const is_payload = typed_value.val.errorUnionIsPayload();
675676
676677 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
677 const err_val = if (is_payload) Value.initTag(.zero) else typed_value.val;
678 const err_val = if (is_payload) Value.zero else typed_value.val;
678679 return generateSymbol(bin_file, src_loc, .{
679680 .ty = error_ty,
680681 .val = err_val,
......@@ -689,7 +690,7 @@ pub fn generateSymbol(
689690 if (error_align > payload_align) {
690691 switch (try generateSymbol(bin_file, src_loc, .{
691692 .ty = error_ty,
692 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
693 .val = if (is_payload) Value.zero else typed_value.val,
693694 }, code, debug_output, reloc_info)) {
694695 .ok => {},
695696 .fail => |em| return Result{ .fail = em },
......@@ -721,7 +722,7 @@ pub fn generateSymbol(
721722 const begin = code.items.len;
722723 switch (try generateSymbol(bin_file, src_loc, .{
723724 .ty = error_ty,
724 .val = if (is_payload) Value.initTag(.zero) else typed_value.val,
725 .val = if (is_payload) Value.zero else typed_value.val,
725726 }, code, debug_output, reloc_info)) {
726727 .ok => {},
727728 .fail => |em| return Result{ .fail = em },
......@@ -961,13 +962,9 @@ fn lowerDeclRef(
961962 }
962963
963964 // generate length
964 var slice_len: Value.Payload.U64 = .{
965 .base = .{ .tag = .int_u64 },
966 .data = typed_value.val.sliceLen(mod),
967 };
968965 switch (try generateSymbol(bin_file, src_loc, .{
969966 .ty = Type.usize,
970 .val = Value.initPayload(&slice_len.base),
967 .val = try mod.intValue(Type.usize, typed_value.val.sliceLen(mod)),
971968 }, code, debug_output, reloc_info)) {
972969 .ok => {},
973970 .fail => |em| return Result{ .fail = em },
......@@ -1196,13 +1193,13 @@ pub fn genTypedValue(
11961193 .null_value => {
11971194 return GenResult.mcv(.{ .immediate = 0 });
11981195 },
1199 .none => switch (typed_value.val.tag()) {
1200 .int_u64 => {
1196 .none => {},
1197 else => switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {
1198 .int => {
12011199 return GenResult.mcv(.{ .immediate = typed_value.val.toUnsignedInt(mod) });
12021200 },
12031201 else => {},
12041202 },
1205 else => {},
12061203 },
12071204 },
12081205 .Int => {
......@@ -1283,7 +1280,7 @@ pub fn genTypedValue(
12831280
12841281 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
12851282 // We use the error type directly as the type.
1286 const err_val = if (!is_pl) typed_value.val else Value.initTag(.zero);
1283 const err_val = if (!is_pl) typed_value.val else Value.zero;
12871284 return genTypedValue(bin_file, src_loc, .{
12881285 .ty = error_type,
12891286 .val = err_val,
src/codegen/c.zig+85-155
......@@ -568,11 +568,7 @@ pub const DeclGen = struct {
568568 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
569569 try dg.renderValue(writer, ty.slicePtrFieldType(&buf, mod), val.slicePtr(), .Initializer);
570570
571 var len_pl: Value.Payload.U64 = .{
572 .base = .{ .tag = .int_u64 },
573 .data = val.sliceLen(mod),
574 };
575 const len_val = Value.initPayload(&len_pl.base);
571 const len_val = try mod.intValue(Type.usize, val.sliceLen(mod));
576572
577573 if (location == .StaticInitializer) {
578574 return writer.print(", {} }}", .{try dg.fmtIntLiteral(Type.usize, len_val, .Other)});
......@@ -596,11 +592,17 @@ pub const DeclGen = struct {
596592 if (need_typecast) try writer.writeByte(')');
597593 }
598594
599 // Renders a "parent" pointer by recursing to the root decl/variable
600 // that its contents are defined with respect to.
601 //
602 // Used for .elem_ptr, .field_ptr, .opt_payload_ptr, .eu_payload_ptr
603 fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void {
595 /// Renders a "parent" pointer by recursing to the root decl/variable
596 /// that its contents are defined with respect to.
597 ///
598 /// Used for .elem_ptr, .field_ptr, .opt_payload_ptr, .eu_payload_ptr
599 fn renderParentPtr(
600 dg: *DeclGen,
601 writer: anytype,
602 ptr_val: Value,
603 ptr_ty: Type,
604 location: ValueRenderLocation,
605 ) error{ OutOfMemory, AnalysisFail }!void {
604606 const mod = dg.module;
605607
606608 if (!ptr_ty.isSlice(mod)) {
......@@ -608,8 +610,11 @@ pub const DeclGen = struct {
608610 try dg.renderType(writer, ptr_ty);
609611 try writer.writeByte(')');
610612 }
613 if (ptr_val.ip_index != .none) switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {
614 .int => try writer.print("{x}", .{try dg.fmtIntLiteral(Type.usize, ptr_val, .Other)}),
615 else => unreachable,
616 };
611617 switch (ptr_val.tag()) {
612 .int_u64, .one => try writer.print("{x}", .{try dg.fmtIntLiteral(Type.usize, ptr_val, .Other)}),
613618 .decl_ref_mut, .decl_ref, .variable => {
614619 const decl_index = switch (ptr_val.tag()) {
615620 .decl_ref => ptr_val.castTag(.decl_ref).?.data,
......@@ -661,11 +666,7 @@ pub const DeclGen = struct {
661666 u8_ptr_pl.data.pointee_type = Type.u8;
662667 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
663668
664 var byte_offset_pl = Value.Payload.U64{
665 .base = .{ .tag = .int_u64 },
666 .data = byte_offset,
667 };
668 const byte_offset_val = Value.initPayload(&byte_offset_pl.base);
669 const byte_offset_val = try mod.intValue(Type.usize, byte_offset);
669670
670671 try writer.writeAll("((");
671672 try dg.renderType(writer, u8_ptr_ty);
......@@ -891,7 +892,7 @@ pub const DeclGen = struct {
891892 },
892893 .Array, .Vector => {
893894 const ai = ty.arrayInfo(mod);
894 if (ai.elem_type.eql(Type.u8, dg.module)) {
895 if (ai.elem_type.eql(Type.u8, mod)) {
895896 var literal = stringLiteral(writer);
896897 try literal.start();
897898 const c_len = ty.arrayLenIncludingSentinel(mod);
......@@ -949,7 +950,7 @@ pub const DeclGen = struct {
949950 },
950951 .Float => {
951952 const bits = ty.floatBits(target);
952 const f128_val = val.toFloat(f128);
953 const f128_val = val.toFloat(f128, mod);
953954
954955 // All unsigned ints matching float types are pre-allocated.
955956 const repr_ty = mod.intType(.unsigned, bits) catch unreachable;
......@@ -963,21 +964,15 @@ pub const DeclGen = struct {
963964 };
964965
965966 switch (bits) {
966 16 => repr_val_big.set(@bitCast(u16, val.toFloat(f16))),
967 32 => repr_val_big.set(@bitCast(u32, val.toFloat(f32))),
968 64 => repr_val_big.set(@bitCast(u64, val.toFloat(f64))),
969 80 => repr_val_big.set(@bitCast(u80, val.toFloat(f80))),
967 16 => repr_val_big.set(@bitCast(u16, val.toFloat(f16, mod))),
968 32 => repr_val_big.set(@bitCast(u32, val.toFloat(f32, mod))),
969 64 => repr_val_big.set(@bitCast(u64, val.toFloat(f64, mod))),
970 80 => repr_val_big.set(@bitCast(u80, val.toFloat(f80, mod))),
970971 128 => repr_val_big.set(@bitCast(u128, f128_val)),
971972 else => unreachable,
972973 }
973974
974 var repr_val_pl = Value.Payload.BigInt{
975 .base = .{
976 .tag = if (repr_val_big.positive) .int_big_positive else .int_big_negative,
977 },
978 .data = repr_val_big.limbs[0..repr_val_big.len],
979 };
980 const repr_val = Value.initPayload(&repr_val_pl.base);
975 const repr_val = try mod.intValue_big(repr_ty, repr_val_big.toConst());
981976
982977 try writer.writeAll("zig_cast_");
983978 try dg.renderTypeForBuiltinFnName(writer, ty);
......@@ -988,10 +983,10 @@ pub const DeclGen = struct {
988983 try dg.renderTypeForBuiltinFnName(writer, ty);
989984 try writer.writeByte('(');
990985 switch (bits) {
991 16 => try writer.print("{x}", .{val.toFloat(f16)}),
992 32 => try writer.print("{x}", .{val.toFloat(f32)}),
993 64 => try writer.print("{x}", .{val.toFloat(f64)}),
994 80 => try writer.print("{x}", .{val.toFloat(f80)}),
986 16 => try writer.print("{x}", .{val.toFloat(f16, mod)}),
987 32 => try writer.print("{x}", .{val.toFloat(f32, mod)}),
988 64 => try writer.print("{x}", .{val.toFloat(f64, mod)}),
989 80 => try writer.print("{x}", .{val.toFloat(f80, mod)}),
995990 128 => try writer.print("{x}", .{f128_val}),
996991 else => unreachable,
997992 }
......@@ -1031,10 +1026,10 @@ pub const DeclGen = struct {
10311026 if (std.math.isNan(f128_val)) switch (bits) {
10321027 // We only actually need to pass the significand, but it will get
10331028 // properly masked anyway, so just pass the whole value.
1034 16 => try writer.print("\"0x{x}\"", .{@bitCast(u16, val.toFloat(f16))}),
1035 32 => try writer.print("\"0x{x}\"", .{@bitCast(u32, val.toFloat(f32))}),
1036 64 => try writer.print("\"0x{x}\"", .{@bitCast(u64, val.toFloat(f64))}),
1037 80 => try writer.print("\"0x{x}\"", .{@bitCast(u80, val.toFloat(f80))}),
1029 16 => try writer.print("\"0x{x}\"", .{@bitCast(u16, val.toFloat(f16, mod))}),
1030 32 => try writer.print("\"0x{x}\"", .{@bitCast(u32, val.toFloat(f32, mod))}),
1031 64 => try writer.print("\"0x{x}\"", .{@bitCast(u64, val.toFloat(f64, mod))}),
1032 80 => try writer.print("\"0x{x}\"", .{@bitCast(u80, val.toFloat(f80, mod))}),
10381033 128 => try writer.print("\"0x{x}\"", .{@bitCast(u128, f128_val)}),
10391034 else => unreachable,
10401035 };
......@@ -1060,19 +1055,6 @@ pub const DeclGen = struct {
10601055 try writer.writeAll(")NULL)");
10611056 },
10621057 .none => switch (val.tag()) {
1063 .zero => if (ty.isSlice(mod)) {
1064 var slice_pl = Value.Payload.Slice{
1065 .base = .{ .tag = .slice },
1066 .data = .{ .ptr = val, .len = Value.undef },
1067 };
1068 const slice_val = Value.initPayload(&slice_pl.base);
1069
1070 return dg.renderValue(writer, ty, slice_val, location);
1071 } else {
1072 try writer.writeAll("((");
1073 try dg.renderType(writer, ty);
1074 try writer.writeAll(")NULL)");
1075 },
10761058 .variable => {
10771059 const decl = val.castTag(.variable).?.data.owner_decl;
10781060 return dg.renderDeclValue(writer, ty, val, decl, location);
......@@ -1101,7 +1083,7 @@ pub const DeclGen = struct {
11011083 const extern_fn = val.castTag(.extern_fn).?.data;
11021084 try dg.renderDeclName(writer, extern_fn.owner_decl, 0);
11031085 },
1104 .int_u64, .one, .int_big_positive, .lazy_align, .lazy_size => {
1086 .lazy_align, .lazy_size => {
11051087 try writer.writeAll("((");
11061088 try dg.renderType(writer, ty);
11071089 return writer.print("){x})", .{try dg.fmtIntLiteral(Type.usize, val, .Other)});
......@@ -1116,7 +1098,14 @@ pub const DeclGen = struct {
11161098
11171099 else => unreachable,
11181100 },
1119 else => unreachable,
1101 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
1102 .int => {
1103 try writer.writeAll("((");
1104 try dg.renderType(writer, ty);
1105 return writer.print("){x})", .{try dg.fmtIntLiteral(Type.usize, val, .Other)});
1106 },
1107 else => unreachable,
1108 },
11201109 },
11211110 .Array, .Vector => {
11221111 if (location == .FunctionArgument) {
......@@ -1155,7 +1144,7 @@ pub const DeclGen = struct {
11551144 .bytes => val.castTag(.bytes).?.data,
11561145 .str_lit => bytes: {
11571146 const str_lit = val.castTag(.str_lit).?.data;
1158 break :bytes dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
1147 break :bytes mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
11591148 },
11601149 else => unreachable,
11611150 };
......@@ -1170,21 +1159,18 @@ pub const DeclGen = struct {
11701159 else => {},
11711160 }
11721161 // Fall back to generic implementation.
1173 var arena = std.heap.ArenaAllocator.init(dg.gpa);
1174 defer arena.deinit();
1175 const arena_allocator = arena.allocator();
11761162
11771163 // MSVC throws C2078 if an array of size 65536 or greater is initialized with a string literal
11781164 const max_string_initializer_len = 65535;
11791165
11801166 const ai = ty.arrayInfo(mod);
1181 if (ai.elem_type.eql(Type.u8, dg.module)) {
1167 if (ai.elem_type.eql(Type.u8, mod)) {
11821168 if (ai.len <= max_string_initializer_len) {
11831169 var literal = stringLiteral(writer);
11841170 try literal.start();
11851171 var index: usize = 0;
11861172 while (index < ai.len) : (index += 1) {
1187 const elem_val = try val.elemValue(dg.module, arena_allocator, index);
1173 const elem_val = try val.elemValue(mod, index);
11881174 const elem_val_u8 = if (elem_val.isUndef()) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(mod));
11891175 try literal.writeChar(elem_val_u8);
11901176 }
......@@ -1198,7 +1184,7 @@ pub const DeclGen = struct {
11981184 var index: usize = 0;
11991185 while (index < ai.len) : (index += 1) {
12001186 if (index != 0) try writer.writeByte(',');
1201 const elem_val = try val.elemValue(dg.module, arena_allocator, index);
1187 const elem_val = try val.elemValue(mod, index);
12021188 const elem_val_u8 = if (elem_val.isUndef()) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(mod));
12031189 try writer.print("'\\x{x}'", .{elem_val_u8});
12041190 }
......@@ -1213,7 +1199,7 @@ pub const DeclGen = struct {
12131199 var index: usize = 0;
12141200 while (index < ai.len) : (index += 1) {
12151201 if (index != 0) try writer.writeByte(',');
1216 const elem_val = try val.elemValue(dg.module, arena_allocator, index);
1202 const elem_val = try val.elemValue(mod, index);
12171203 try dg.renderValue(writer, ai.elem_type, elem_val, initializer_type);
12181204 }
12191205 if (ai.sentinel) |s| {
......@@ -1361,8 +1347,7 @@ pub const DeclGen = struct {
13611347 const bits = Type.smallestUnsignedBits(int_info.bits - 1);
13621348 const bit_offset_ty = try mod.intType(.unsigned, bits);
13631349
1364 var bit_offset_val_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = 0 };
1365 const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base);
1350 var bit_offset: u64 = 0;
13661351
13671352 var eff_num_fields: usize = 0;
13681353 for (0..field_vals.len) |field_i| {
......@@ -1394,12 +1379,13 @@ pub const DeclGen = struct {
13941379 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
13951380
13961381 const cast_context = IntCastContext{ .value = .{ .value = field_val } };
1397 if (bit_offset_val_pl.data != 0) {
1382 if (bit_offset != 0) {
13981383 try writer.writeAll("zig_shl_");
13991384 try dg.renderTypeForBuiltinFnName(writer, ty);
14001385 try writer.writeByte('(');
14011386 try dg.renderIntCast(writer, ty, cast_context, field_ty, .FunctionArgument);
14021387 try writer.writeAll(", ");
1388 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
14031389 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
14041390 try writer.writeByte(')');
14051391 } else {
......@@ -1409,7 +1395,7 @@ pub const DeclGen = struct {
14091395 if (needs_closing_paren) try writer.writeByte(')');
14101396 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");
14111397
1412 bit_offset_val_pl.data += field_ty.bitSize(mod);
1398 bit_offset += field_ty.bitSize(mod);
14131399 needs_closing_paren = true;
14141400 eff_index += 1;
14151401 }
......@@ -1427,15 +1413,16 @@ pub const DeclGen = struct {
14271413 try dg.renderType(writer, ty);
14281414 try writer.writeByte(')');
14291415
1430 if (bit_offset_val_pl.data != 0) {
1416 if (bit_offset != 0) {
14311417 try dg.renderValue(writer, field_ty, field_val, .Other);
14321418 try writer.writeAll(" << ");
1419 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
14331420 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
14341421 } else {
14351422 try dg.renderValue(writer, field_ty, field_val, .Other);
14361423 }
14371424
1438 bit_offset_val_pl.data += field_ty.bitSize(mod);
1425 bit_offset += field_ty.bitSize(mod);
14391426 empty = false;
14401427 }
14411428 try writer.writeByte(')');
......@@ -1451,7 +1438,7 @@ pub const DeclGen = struct {
14511438 try writer.writeByte(')');
14521439 }
14531440
1454 const field_i = ty.unionTagFieldIndex(union_obj.tag, dg.module).?;
1441 const field_i = ty.unionTagFieldIndex(union_obj.tag, mod).?;
14551442 const field_ty = ty.unionFields().values()[field_i].ty;
14561443 const field_name = ty.unionFields().keys()[field_i];
14571444 if (ty.containerLayout() == .Packed) {
......@@ -1951,10 +1938,10 @@ pub const DeclGen = struct {
19511938
19521939 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
19531940
1954 var bits_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = int_info.bits };
1941 const bits_ty = if (is_big) Type.u16 else Type.u8;
19551942 try writer.print(", {}", .{try dg.fmtIntLiteral(
1956 if (is_big) Type.u16 else Type.u8,
1957 Value.initPayload(&bits_pl.base),
1943 bits_ty,
1944 try mod.intValue(bits_ty, int_info.bits),
19581945 .FunctionArgument,
19591946 )});
19601947 }
......@@ -2495,8 +2482,7 @@ pub fn genErrDecls(o: *Object) !void {
24952482 for (mod.error_name_list.items, 0..) |name, value| {
24962483 if (value != 0) try writer.writeByte(',');
24972484
2498 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = name.len };
2499 const len_val = Value.initPayload(&len_pl.base);
2485 const len_val = try mod.intValue(Type.usize, name.len);
25002486
25012487 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
25022488 fmtIdent(name), try o.dg.fmtIntLiteral(Type.usize, len_val, .Other),
......@@ -2548,8 +2534,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
25482534 };
25492535 const tag_val = Value.initPayload(&tag_pl.base);
25502536
2551 var int_pl: Value.Payload.U64 = undefined;
2552 const int_val = tag_val.enumToInt(enum_ty, &int_pl);
2537 const int_val = try tag_val.enumToInt(enum_ty, mod);
25532538
25542539 const name_ty = try mod.arrayType(.{
25552540 .len = name.len,
......@@ -2560,8 +2545,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
25602545 var name_pl = Value.Payload.Bytes{ .base = .{ .tag = .bytes }, .data = name };
25612546 const name_val = Value.initPayload(&name_pl.base);
25622547
2563 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = name.len };
2564 const len_val = Value.initPayload(&len_pl.base);
2548 const len_val = try mod.intValue(Type.usize, name.len);
25652549
25662550 try w.print(" case {}: {{\n static ", .{
25672551 try o.dg.fmtIntLiteral(enum_ty, int_val, .Other),
......@@ -3396,12 +3380,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
33963380 const host_ty = try mod.intType(.unsigned, host_bits);
33973381
33983382 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
3399
3400 var bit_offset_val_pl: Value.Payload.U64 = .{
3401 .base = .{ .tag = .int_u64 },
3402 .data = ptr_info.bit_offset,
3403 };
3404 const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base);
3383 const bit_offset_val = try mod.intValue(bit_offset_ty, ptr_info.bit_offset);
34053384
34063385 const field_ty = try mod.intType(.unsigned, @intCast(u16, src_ty.bitSize(mod)));
34073386
......@@ -3563,14 +3542,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
35633542 try v.elem(f, writer);
35643543 } else switch (dest_int_info.signedness) {
35653544 .unsigned => {
3566 var arena = std.heap.ArenaAllocator.init(f.object.dg.gpa);
3567 defer arena.deinit();
3568
3569 const ExpectedContents = union { u: Value.Payload.U64, i: Value.Payload.I64 };
3570 var stack align(@alignOf(ExpectedContents)) =
3571 std.heap.stackFallback(@sizeOf(ExpectedContents), arena.allocator());
3572
3573 const mask_val = try inst_scalar_ty.maxInt(stack.get(), mod);
3545 const mask_val = try inst_scalar_ty.maxIntScalar(mod);
35743546 try writer.writeAll("zig_and_");
35753547 try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);
35763548 try writer.writeByte('(');
......@@ -3581,11 +3553,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
35813553 .signed => {
35823554 const c_bits = toCIntBits(scalar_int_info.bits) orelse
35833555 return f.fail("TODO: C backend: implement integer types larger than 128 bits", .{});
3584 var shift_pl = Value.Payload.U64{
3585 .base = .{ .tag = .int_u64 },
3586 .data = c_bits - dest_bits,
3587 };
3588 const shift_val = Value.initPayload(&shift_pl.base);
3556 const shift_val = try mod.intValue(Type.u8, c_bits - dest_bits);
35893557
35903558 try writer.writeAll("zig_shr_");
35913559 try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty);
......@@ -3705,12 +3673,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37053673 const host_ty = try mod.intType(.unsigned, host_bits);
37063674
37073675 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
3708
3709 var bit_offset_val_pl: Value.Payload.U64 = .{
3710 .base = .{ .tag = .int_u64 },
3711 .data = ptr_info.bit_offset,
3712 };
3713 const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base);
3676 const bit_offset_val = try mod.intValue(bit_offset_ty, ptr_info.bit_offset);
37143677
37153678 const src_bits = src_ty.bitSize(mod);
37163679
......@@ -3725,11 +3688,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37253688 try mask.shiftLeft(&mask, ptr_info.bit_offset);
37263689 try mask.bitNotWrap(&mask, .unsigned, host_bits);
37273690
3728 var mask_pl = Value.Payload.BigInt{
3729 .base = .{ .tag = .int_big_positive },
3730 .data = mask.limbs[0..mask.len()],
3731 };
3732 const mask_val = Value.initPayload(&mask_pl.base);
3691 const mask_val = try mod.intValue_big(host_ty, mask.toConst());
37333692
37343693 try f.writeCValueDeref(writer, ptr_val);
37353694 try v.elem(f, writer);
......@@ -5356,11 +5315,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
53565315 u8_ptr_pl.data.pointee_type = Type.u8;
53575316 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
53585317
5359 var byte_offset_pl = Value.Payload.U64{
5360 .base = .{ .tag = .int_u64 },
5361 .data = byte_offset,
5362 };
5363 const byte_offset_val = Value.initPayload(&byte_offset_pl.base);
5318 const byte_offset_val = try mod.intValue(Type.usize, byte_offset);
53645319
53655320 try writer.writeAll("((");
53665321 try f.renderType(writer, u8_ptr_ty);
......@@ -5412,11 +5367,7 @@ fn fieldPtr(
54125367 u8_ptr_pl.data.pointee_type = Type.u8;
54135368 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
54145369
5415 var byte_offset_pl = Value.Payload.U64{
5416 .base = .{ .tag = .int_u64 },
5417 .data = byte_offset,
5418 };
5419 const byte_offset_val = Value.initPayload(&byte_offset_pl.base);
5370 const byte_offset_val = try mod.intValue(Type.usize, byte_offset);
54205371
54215372 try writer.writeAll("((");
54225373 try f.renderType(writer, u8_ptr_ty);
......@@ -5466,11 +5417,8 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
54665417
54675418 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(int_info.bits - 1));
54685419
5469 var bit_offset_val_pl: Value.Payload.U64 = .{
5470 .base = .{ .tag = .int_u64 },
5471 .data = struct_obj.packedFieldBitOffset(mod, extra.field_index),
5472 };
5473 const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base);
5420 const bit_offset = struct_obj.packedFieldBitOffset(mod, extra.field_index);
5421 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
54745422
54755423 const field_int_signedness = if (inst_ty.isAbiInt(mod))
54765424 inst_ty.intInfo(mod).signedness
......@@ -5492,13 +5440,13 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
54925440 try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty);
54935441 try writer.writeByte('(');
54945442 }
5495 if (bit_offset_val_pl.data > 0) {
5443 if (bit_offset > 0) {
54965444 try writer.writeAll("zig_shr_");
54975445 try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty);
54985446 try writer.writeByte('(');
54995447 }
55005448 try f.writeCValue(writer, struct_byval, .Other);
5501 if (bit_offset_val_pl.data > 0) {
5449 if (bit_offset > 0) {
55025450 try writer.writeAll(", ");
55035451 try f.object.dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
55045452 try writer.writeByte(')');
......@@ -5854,9 +5802,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
58545802 } else try f.writeCValue(writer, operand, .Initializer);
58555803 try writer.writeAll("; ");
58565804
5857 const array_len = array_ty.arrayLen(mod);
5858 var len_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = array_len };
5859 const len_val = Value.initPayload(&len_pl.base);
5805 const len_val = try mod.intValue(Type.usize, array_ty.arrayLen(mod));
58605806 try f.writeCValueMember(writer, local, .{ .identifier = "len" });
58615807 try writer.print(" = {};\n", .{try f.fmtIntLiteral(Type.usize, len_val)});
58625808
......@@ -6632,26 +6578,17 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
66326578 const local = try f.allocLocal(inst, inst_ty);
66336579 try reap(f, inst, &.{ extra.a, extra.b }); // local cannot alias operands
66346580 for (0..extra.mask_len) |index| {
6635 var dst_pl = Value.Payload.U64{
6636 .base = .{ .tag = .int_u64 },
6637 .data = @intCast(u64, index),
6638 };
6639
66406581 try f.writeCValue(writer, local, .Other);
66416582 try writer.writeByte('[');
6642 try f.object.dg.renderValue(writer, Type.usize, Value.initPayload(&dst_pl.base), .Other);
6583 try f.object.dg.renderValue(writer, Type.usize, try mod.intValue(Type.usize, index), .Other);
66436584 try writer.writeAll("] = ");
66446585
6645 var buf: Value.ElemValueBuffer = undefined;
6646 const mask_elem = mask.elemValueBuffer(mod, index, &buf).toSignedInt(mod);
6647 var src_pl = Value.Payload.U64{
6648 .base = .{ .tag = .int_u64 },
6649 .data = @intCast(u64, mask_elem ^ mask_elem >> 63),
6650 };
6586 const mask_elem = (try mask.elemValue(mod, index)).toSignedInt(mod);
6587 const src_val = try mod.intValue(Type.usize, @intCast(u64, mask_elem ^ mask_elem >> 63));
66516588
66526589 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);
66536590 try writer.writeByte('[');
6654 try f.object.dg.renderValue(writer, Type.usize, Value.initPayload(&src_pl.base), .Other);
6591 try f.object.dg.renderValue(writer, Type.usize, src_val, .Other);
66556592 try writer.writeAll("];\n");
66566593 }
66576594
......@@ -6730,8 +6667,6 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
67306667 defer arena.deinit();
67316668
67326669 const ExpectedContents = union {
6733 u: Value.Payload.U64,
6734 i: Value.Payload.I64,
67356670 f16: Value.Payload.Float_16,
67366671 f32: Value.Payload.Float_32,
67376672 f64: Value.Payload.Float_64,
......@@ -6746,13 +6681,13 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
67466681 .And => switch (scalar_ty.zigTypeTag(mod)) {
67476682 .Bool => Value.one,
67486683 else => switch (scalar_ty.intInfo(mod).signedness) {
6749 .unsigned => try scalar_ty.maxInt(stack.get(), mod),
6684 .unsigned => try scalar_ty.maxIntScalar(mod),
67506685 .signed => Value.negative_one,
67516686 },
67526687 },
67536688 .Min => switch (scalar_ty.zigTypeTag(mod)) {
67546689 .Bool => Value.one,
6755 .Int => try scalar_ty.maxInt(stack.get(), mod),
6690 .Int => try scalar_ty.maxIntScalar(mod),
67566691 .Float => try Value.floatToValue(std.math.nan(f128), stack.get(), scalar_ty, target),
67576692 else => unreachable,
67586693 },
......@@ -6879,8 +6814,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
68796814
68806815 const bit_offset_ty = try mod.intType(.unsigned, Type.smallestUnsignedBits(int_info.bits - 1));
68816816
6882 var bit_offset_val_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = 0 };
6883 const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base);
6817 var bit_offset: u64 = 0;
68846818
68856819 var empty = true;
68866820 for (0..elements.len) |field_i| {
......@@ -6925,12 +6859,13 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
69256859 }
69266860
69276861 try writer.writeAll(", ");
6862 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
69286863 try f.object.dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
69296864 try f.object.dg.renderBuiltinInfo(writer, inst_ty, .bits);
69306865 try writer.writeByte(')');
69316866 if (!empty) try writer.writeByte(')');
69326867
6933 bit_offset_val_pl.data += field_ty.bitSize(mod);
6868 bit_offset += field_ty.bitSize(mod);
69346869 empty = false;
69356870 }
69366871
......@@ -6976,8 +6911,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
69766911 };
69776912 const tag_val = Value.initPayload(&tag_pl.base);
69786913
6979 var int_pl: Value.Payload.U64 = undefined;
6980 const int_val = tag_val.enumToInt(tag_ty, &int_pl);
6914 const int_val = try tag_val.enumToInt(tag_ty, mod);
69816915
69826916 const a = try Assignment.start(f, writer, tag_ty);
69836917 try f.writeCValueMember(writer, local, .{ .identifier = "tag" });
......@@ -7640,10 +7574,6 @@ fn formatIntLiteral(
76407574 c_limb_int_info.signedness = .unsigned;
76417575 c_limb_cty = c_limb_info.cty;
76427576 }
7643 var c_limb_val_pl = Value.Payload.BigInt{
7644 .base = .{ .tag = if (c_limb_mut.positive) .int_big_positive else .int_big_negative },
7645 .data = c_limb_mut.limbs[0..c_limb_mut.len],
7646 };
76477577
76487578 if (limb_offset > 0) try writer.writeAll(", ");
76497579 try formatIntLiteral(.{
......@@ -7651,7 +7581,7 @@ fn formatIntLiteral(
76517581 .int_info = c_limb_int_info,
76527582 .kind = data.kind,
76537583 .cty = c_limb_cty,
7654 .val = Value.initPayload(&c_limb_val_pl.base),
7584 .val = try mod.intValue_big(Type.comptime_int, c_limb_mut.toConst()),
76557585 }, fmt, options, writer);
76567586 }
76577587 }
......@@ -7750,7 +7680,7 @@ const Vectorize = struct {
77507680 pub fn start(f: *Function, inst: Air.Inst.Index, writer: anytype, ty: Type) !Vectorize {
77517681 const mod = f.object.dg.module;
77527682 return if (ty.zigTypeTag(mod) == .Vector) index: {
7753 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = ty.vectorLen(mod) };
7683 const len_val = try mod.intValue(Type.usize, ty.vectorLen(mod));
77547684
77557685 const local = try f.allocLocal(inst, Type.usize);
77567686
......@@ -7759,7 +7689,7 @@ const Vectorize = struct {
77597689 try writer.print(" = {d}; ", .{try f.fmtIntLiteral(Type.usize, Value.zero)});
77607690 try f.writeCValue(writer, local, .Other);
77617691 try writer.print(" < {d}; ", .{
7762 try f.fmtIntLiteral(Type.usize, Value.initPayload(&len_pl.base)),
7692 try f.fmtIntLiteral(Type.usize, len_val),
77637693 });
77647694 try f.writeCValue(writer, local, .Other);
77657695 try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(Type.usize, Value.one)});
src/codegen/llvm.zig+38-67
......@@ -12,6 +12,7 @@ const link = @import("../link.zig");
1212const Compilation = @import("../Compilation.zig");
1313const build_options = @import("build_options");
1414const Module = @import("../Module.zig");
15const InternPool = @import("../InternPool.zig");
1516const Package = @import("../Package.zig");
1617const TypedValue = @import("../TypedValue.zig");
1718const Air = @import("../Air.zig");
......@@ -1535,8 +1536,7 @@ pub const Object = struct {
15351536 defer gpa.free(field_name_z);
15361537
15371538 buf_field_index.data = @intCast(u32, i);
1538 var buf_u64: Value.Payload.U64 = undefined;
1539 const field_int_val = field_index_val.enumToInt(ty, &buf_u64);
1539 const field_int_val = try field_index_val.enumToInt(ty, mod);
15401540
15411541 var bigint_space: Value.BigIntSpace = undefined;
15421542 const bigint = field_int_val.toBigInt(&bigint_space, mod);
......@@ -3255,8 +3255,6 @@ pub const DeclGen = struct {
32553255 const llvm_type = try dg.lowerType(tv.ty);
32563256 return if (tv.val.toBool(mod)) llvm_type.constAllOnes() else llvm_type.constNull();
32573257 },
3258 // TODO this duplicates code with Pointer but they should share the handling
3259 // of the tv.val.tag() and then Int should do extra constPtrToInt on top
32603258 .Int => switch (tv.val.ip_index) {
32613259 .none => switch (tv.val.tag()) {
32623260 .decl_ref_mut => return lowerDeclRefValue(dg, tv, tv.val.castTag(.decl_ref_mut).?.data.decl_index),
......@@ -3277,8 +3275,7 @@ pub const DeclGen = struct {
32773275 },
32783276 },
32793277 .Enum => {
3280 var int_buffer: Value.Payload.U64 = undefined;
3281 const int_val = tv.enumToInt(&int_buffer);
3278 const int_val = try tv.enumToInt(mod);
32823279
32833280 var bigint_space: Value.BigIntSpace = undefined;
32843281 const bigint = int_val.toBigInt(&bigint_space, mod);
......@@ -3307,25 +3304,25 @@ pub const DeclGen = struct {
33073304 const llvm_ty = try dg.lowerType(tv.ty);
33083305 switch (tv.ty.floatBits(target)) {
33093306 16 => {
3310 const repr = @bitCast(u16, tv.val.toFloat(f16));
3307 const repr = @bitCast(u16, tv.val.toFloat(f16, mod));
33113308 const llvm_i16 = dg.context.intType(16);
33123309 const int = llvm_i16.constInt(repr, .False);
33133310 return int.constBitCast(llvm_ty);
33143311 },
33153312 32 => {
3316 const repr = @bitCast(u32, tv.val.toFloat(f32));
3313 const repr = @bitCast(u32, tv.val.toFloat(f32, mod));
33173314 const llvm_i32 = dg.context.intType(32);
33183315 const int = llvm_i32.constInt(repr, .False);
33193316 return int.constBitCast(llvm_ty);
33203317 },
33213318 64 => {
3322 const repr = @bitCast(u64, tv.val.toFloat(f64));
3319 const repr = @bitCast(u64, tv.val.toFloat(f64, mod));
33233320 const llvm_i64 = dg.context.intType(64);
33243321 const int = llvm_i64.constInt(repr, .False);
33253322 return int.constBitCast(llvm_ty);
33263323 },
33273324 80 => {
3328 const float = tv.val.toFloat(f80);
3325 const float = tv.val.toFloat(f80, mod);
33293326 const repr = std.math.break_f80(float);
33303327 const llvm_i80 = dg.context.intType(80);
33313328 var x = llvm_i80.constInt(repr.exp, .False);
......@@ -3338,7 +3335,7 @@ pub const DeclGen = struct {
33383335 }
33393336 },
33403337 128 => {
3341 var buf: [2]u64 = @bitCast([2]u64, tv.val.toFloat(f128));
3338 var buf: [2]u64 = @bitCast([2]u64, tv.val.toFloat(f128, mod));
33423339 // LLVM seems to require that the lower half of the f128 be placed first
33433340 // in the buffer.
33443341 if (native_endian == .Big) {
......@@ -3388,7 +3385,7 @@ pub const DeclGen = struct {
33883385 };
33893386 return dg.context.constStruct(&fields, fields.len, .False);
33903387 },
3391 .int_u64, .one, .int_big_positive, .lazy_align, .lazy_size => {
3388 .lazy_align, .lazy_size => {
33923389 const llvm_usize = try dg.lowerType(Type.usize);
33933390 const llvm_int = llvm_usize.constInt(tv.val.toUnsignedInt(mod), .False);
33943391 return llvm_int.constIntToPtr(try dg.lowerType(tv.ty));
......@@ -3396,10 +3393,6 @@ pub const DeclGen = struct {
33963393 .field_ptr, .opt_payload_ptr, .eu_payload_ptr, .elem_ptr => {
33973394 return dg.lowerParentPtr(tv.val, tv.ty.ptrInfo(mod).bit_offset % 8 == 0);
33983395 },
3399 .zero => {
3400 const llvm_type = try dg.lowerType(tv.ty);
3401 return llvm_type.constNull();
3402 },
34033396 .opt_payload => {
34043397 const payload = tv.val.castTag(.opt_payload).?.data;
34053398 return dg.lowerParentPtr(payload, tv.ty.ptrInfo(mod).bit_offset % 8 == 0);
......@@ -3408,7 +3401,10 @@ pub const DeclGen = struct {
34083401 tv.ty.fmtDebug(), tag,
34093402 }),
34103403 },
3411 else => unreachable,
3404 else => switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {
3405 .int => |int| return lowerIntAsPtr(dg, int),
3406 else => unreachable,
3407 },
34123408 },
34133409 .Array => switch (tv.val.tag()) {
34143410 .bytes => {
......@@ -3592,7 +3588,7 @@ pub const DeclGen = struct {
35923588
35933589 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
35943590 // We use the error type directly as the type.
3595 const err_val = if (!is_pl) tv.val else Value.initTag(.zero);
3591 const err_val = if (!is_pl) tv.val else Value.zero;
35963592 return dg.lowerValue(.{ .ty = Type.anyerror, .val = err_val });
35973593 }
35983594
......@@ -3600,7 +3596,7 @@ pub const DeclGen = struct {
36003596 const error_align = Type.anyerror.abiAlignment(mod);
36013597 const llvm_error_value = try dg.lowerValue(.{
36023598 .ty = Type.anyerror,
3603 .val = if (is_pl) Value.initTag(.zero) else tv.val,
3599 .val = if (is_pl) Value.zero else tv.val,
36043600 });
36053601 const llvm_payload_value = try dg.lowerValue(.{
36063602 .ty = payload_type,
......@@ -3882,14 +3878,9 @@ pub const DeclGen = struct {
38823878 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
38833879 defer dg.gpa.free(llvm_elems);
38843880 for (llvm_elems, 0..) |*elem, i| {
3885 var byte_payload: Value.Payload.U64 = .{
3886 .base = .{ .tag = .int_u64 },
3887 .data = bytes[i],
3888 };
3889
38903881 elem.* = try dg.lowerValue(.{
38913882 .ty = elem_ty,
3892 .val = Value.initPayload(&byte_payload.base),
3883 .val = try mod.intValue(elem_ty, bytes[i]),
38933884 });
38943885 }
38953886 return llvm.constVector(
......@@ -3940,14 +3931,9 @@ pub const DeclGen = struct {
39403931 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
39413932 defer dg.gpa.free(llvm_elems);
39423933 for (llvm_elems, 0..) |*elem, i| {
3943 var byte_payload: Value.Payload.U64 = .{
3944 .base = .{ .tag = .int_u64 },
3945 .data = bytes[i],
3946 };
3947
39483934 elem.* = try dg.lowerValue(.{
39493935 .ty = elem_ty,
3950 .val = Value.initPayload(&byte_payload.base),
3936 .val = try mod.intValue(elem_ty, bytes[i]),
39513937 });
39523938 }
39533939 return llvm.constVector(
......@@ -3974,6 +3960,13 @@ pub const DeclGen = struct {
39743960 }
39753961 }
39763962
3963 fn lowerIntAsPtr(dg: *DeclGen, int: InternPool.Key.Int) *llvm.Value {
3964 var bigint_space: Value.BigIntSpace = undefined;
3965 const bigint = int.storage.toBigInt(&bigint_space);
3966 const llvm_int = lowerBigInt(dg, Type.usize, bigint);
3967 return llvm_int.constIntToPtr(dg.context.pointerType(0));
3968 }
3969
39773970 fn lowerBigInt(dg: *DeclGen, ty: Type, bigint: std.math.big.int.Const) *llvm.Value {
39783971 const mod = dg.module;
39793972 const int_info = ty.intInfo(mod);
......@@ -4018,6 +4011,10 @@ pub const DeclGen = struct {
40184011 fn lowerParentPtr(dg: *DeclGen, ptr_val: Value, byte_aligned: bool) Error!*llvm.Value {
40194012 const mod = dg.module;
40204013 const target = mod.getTarget();
4014 if (ptr_val.ip_index != .none) switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {
4015 .int => |int| return lowerIntAsPtr(dg, int),
4016 else => unreachable,
4017 };
40214018 switch (ptr_val.tag()) {
40224019 .decl_ref_mut => {
40234020 const decl = ptr_val.castTag(.decl_ref_mut).?.data.decl_index;
......@@ -4031,18 +4028,6 @@ pub const DeclGen = struct {
40314028 const decl = ptr_val.castTag(.variable).?.data.owner_decl;
40324029 return dg.lowerParentPtrDecl(ptr_val, decl);
40334030 },
4034 .int_i64 => {
4035 const int = ptr_val.castTag(.int_i64).?.data;
4036 const llvm_usize = try dg.lowerType(Type.usize);
4037 const llvm_int = llvm_usize.constInt(@bitCast(u64, int), .False);
4038 return llvm_int.constIntToPtr(dg.context.pointerType(0));
4039 },
4040 .int_u64 => {
4041 const int = ptr_val.castTag(.int_u64).?.data;
4042 const llvm_usize = try dg.lowerType(Type.usize);
4043 const llvm_int = llvm_usize.constInt(int, .False);
4044 return llvm_int.constIntToPtr(dg.context.pointerType(0));
4045 },
40464031 .field_ptr => {
40474032 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
40484033 const parent_llvm_ptr = try dg.lowerParentPtr(field_ptr.container_ptr, byte_aligned);
......@@ -4185,10 +4170,6 @@ pub const DeclGen = struct {
41854170 if (tv.ty.isSlice(mod)) {
41864171 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
41874172 const ptr_ty = tv.ty.slicePtrFieldType(&buf, mod);
4188 var slice_len: Value.Payload.U64 = .{
4189 .base = .{ .tag = .int_u64 },
4190 .data = tv.val.sliceLen(mod),
4191 };
41924173 const fields: [2]*llvm.Value = .{
41934174 try self.lowerValue(.{
41944175 .ty = ptr_ty,
......@@ -4196,7 +4177,7 @@ pub const DeclGen = struct {
41964177 }),
41974178 try self.lowerValue(.{
41984179 .ty = Type.usize,
4199 .val = Value.initPayload(&slice_len.base),
4180 .val = try mod.intValue(Type.usize, tv.val.sliceLen(mod)),
42004181 }),
42014182 };
42024183 return self.context.constStruct(&fields, fields.len, .False);
......@@ -8507,8 +8488,7 @@ pub const FuncGen = struct {
85078488 const dest_slice = try self.resolveInst(bin_op.lhs);
85088489 const ptr_ty = self.typeOf(bin_op.lhs);
85098490 const elem_ty = self.typeOf(bin_op.rhs);
8510 const module = self.dg.module;
8511 const target = module.getTarget();
8491 const target = mod.getTarget();
85128492 const dest_ptr_align = ptr_ty.ptrAlignment(mod);
85138493 const u8_llvm_ty = self.context.intType(8);
85148494 const dest_ptr = self.sliceOrArrayPtr(dest_slice, ptr_ty);
......@@ -8526,7 +8506,7 @@ pub const FuncGen = struct {
85268506 const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
85278507 _ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
85288508
8529 if (safety and module.comp.bin_file.options.valgrind) {
8509 if (safety and mod.comp.bin_file.options.valgrind) {
85308510 self.valgrindMarkUndef(dest_ptr, len);
85318511 }
85328512 return null;
......@@ -8536,8 +8516,7 @@ pub const FuncGen = struct {
85368516 // repeating byte pattern, for example, `@as(u64, 0)` has a
85378517 // repeating byte pattern of 0 bytes. In such case, the memset
85388518 // intrinsic can be used.
8539 var value_buffer: Value.Payload.U64 = undefined;
8540 if (try elem_val.hasRepeatedByteRepr(elem_ty, module, &value_buffer)) |byte_val| {
8519 if (try elem_val.hasRepeatedByteRepr(elem_ty, mod)) |byte_val| {
85418520 const fill_byte = try self.resolveValue(.{
85428521 .ty = Type.u8,
85438522 .val = byte_val,
......@@ -8829,16 +8808,10 @@ pub const FuncGen = struct {
88298808
88308809 for (names) |name| {
88318810 const err_int = mod.global_error_set.get(name).?;
8832 const this_tag_int_value = int: {
8833 var tag_val_payload: Value.Payload.U64 = .{
8834 .base = .{ .tag = .int_u64 },
8835 .data = err_int,
8836 };
8837 break :int try self.dg.lowerValue(.{
8838 .ty = Type.err_int,
8839 .val = Value.initPayload(&tag_val_payload.base),
8840 });
8841 };
8811 const this_tag_int_value = try self.dg.lowerValue(.{
8812 .ty = Type.err_int,
8813 .val = try mod.intValue(Type.err_int, err_int),
8814 });
88428815 switch_instr.addCase(this_tag_int_value, valid_block);
88438816 }
88448817 self.builder.positionBuilderAtEnd(valid_block);
......@@ -9122,8 +9095,7 @@ pub const FuncGen = struct {
91229095 const llvm_i32 = self.context.intType(32);
91239096
91249097 for (values, 0..) |*val, i| {
9125 var buf: Value.ElemValueBuffer = undefined;
9126 const elem = mask.elemValueBuffer(mod, i, &buf);
9098 const elem = try mask.elemValue(mod, i);
91279099 if (elem.isUndef()) {
91289100 val.* = llvm_i32.getUndef();
91299101 } else {
......@@ -9457,8 +9429,7 @@ pub const FuncGen = struct {
94579429 .data = @intCast(u32, enum_field_index),
94589430 };
94599431 const tag_val = Value.initPayload(&tag_val_payload.base);
9460 var int_payload: Value.Payload.U64 = undefined;
9461 const tag_int_val = tag_val.enumToInt(tag_ty, &int_payload);
9432 const tag_int_val = try tag_val.enumToInt(tag_ty, mod);
94629433 break :blk tag_int_val.toUnsignedInt(mod);
94639434 };
94649435 if (layout.payload_size == 0) {
src/codegen/spirv.zig+23-23
......@@ -555,15 +555,15 @@ pub const DeclGen = struct {
555555 // TODO: Swap endianess if the compiler is big endian.
556556 switch (ty.floatBits(target)) {
557557 16 => {
558 const float_bits = val.toFloat(f16);
558 const float_bits = val.toFloat(f16, mod);
559559 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
560560 },
561561 32 => {
562 const float_bits = val.toFloat(f32);
562 const float_bits = val.toFloat(f32, mod);
563563 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
564564 },
565565 64 => {
566 const float_bits = val.toFloat(f64);
566 const float_bits = val.toFloat(f64, mod);
567567 try self.addBytes(std.mem.asBytes(&float_bits)[0..@intCast(usize, len)]);
568568 },
569569 else => unreachable,
......@@ -584,7 +584,7 @@ pub const DeclGen = struct {
584584 // TODO: Properly lower function pointers. For now we are going to hack around it and
585585 // just generate an empty pointer. Function pointers are represented by usize for now,
586586 // though.
587 try self.addInt(Type.usize, Value.initTag(.zero));
587 try self.addInt(Type.usize, Value.zero);
588588 // TODO: Add dependency
589589 return;
590590 },
......@@ -743,8 +743,7 @@ pub const DeclGen = struct {
743743 try self.addUndef(padding);
744744 },
745745 .Enum => {
746 var int_val_buffer: Value.Payload.U64 = undefined;
747 const int_val = val.enumToInt(ty, &int_val_buffer);
746 const int_val = try val.enumToInt(ty, mod);
748747
749748 const int_ty = ty.intTagType();
750749
......@@ -787,22 +786,24 @@ pub const DeclGen = struct {
787786
788787 try self.addUndef(layout.padding);
789788 },
790 .ErrorSet => switch (val.tag()) {
791 .@"error" => {
792 const err_name = val.castTag(.@"error").?.data.name;
793 const kv = try dg.module.getErrorValue(err_name);
794 try self.addConstInt(u16, @intCast(u16, kv.value));
789 .ErrorSet => switch (val.ip_index) {
790 .none => switch (val.tag()) {
791 .@"error" => {
792 const err_name = val.castTag(.@"error").?.data.name;
793 const kv = try dg.module.getErrorValue(err_name);
794 try self.addConstInt(u16, @intCast(u16, kv.value));
795 },
796 else => unreachable,
795797 },
796 .zero => {
797 // Unactivated error set.
798 try self.addConstInt(u16, 0);
798 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
799 .int => |int| try self.addConstInt(u16, @intCast(u16, int.storage.u64)),
800 else => unreachable,
799801 },
800 else => unreachable,
801802 },
802803 .ErrorUnion => {
803804 const payload_ty = ty.errorUnionPayload();
804805 const is_pl = val.errorUnionIsPayload();
805 const error_val = if (!is_pl) val else Value.initTag(.zero);
806 const error_val = if (!is_pl) val else Value.zero;
806807
807808 const eu_layout = dg.errorUnionLayout(payload_ty);
808809 if (!eu_layout.payload_has_bits) {
......@@ -993,9 +994,9 @@ pub const DeclGen = struct {
993994 .indirect => return try self.spv.constInt(result_ty_ref, @boolToInt(val.toBool(mod))),
994995 },
995996 .Float => return switch (ty.floatBits(target)) {
996 16 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float16 = val.toFloat(f16) } } }),
997 32 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float32 = val.toFloat(f32) } } }),
998 64 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float64 = val.toFloat(f64) } } }),
997 16 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float16 = val.toFloat(f16, mod) } } }),
998 32 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float32 = val.toFloat(f32, mod) } } }),
999 64 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float64 = val.toFloat(f64, mod) } } }),
9991000 80, 128 => unreachable, // TODO
10001001 else => unreachable,
10011002 },
......@@ -1531,6 +1532,7 @@ pub const DeclGen = struct {
15311532 }
15321533
15331534 fn genDecl(self: *DeclGen) !void {
1535 if (true) @panic("TODO: update SPIR-V backend for InternPool changes");
15341536 const mod = self.module;
15351537 const decl = mod.declPtr(self.decl_index);
15361538 const spv_decl_index = try self.resolveDecl(self.decl_index);
......@@ -2087,8 +2089,7 @@ pub const DeclGen = struct {
20872089
20882090 var i: usize = 0;
20892091 while (i < mask_len) : (i += 1) {
2090 var buf: Value.ElemValueBuffer = undefined;
2091 const elem = mask.elemValueBuffer(self.module, i, &buf);
2092 const elem = try mask.elemValue(self.module, i);
20922093 if (elem.isUndef()) {
20932094 self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);
20942095 } else {
......@@ -3146,9 +3147,8 @@ pub const DeclGen = struct {
31463147 const int_val = switch (cond_ty.zigTypeTag(mod)) {
31473148 .Int => if (cond_ty.isSignedInt(mod)) @bitCast(u64, value.toSignedInt(mod)) else value.toUnsignedInt(mod),
31483149 .Enum => blk: {
3149 var int_buffer: Value.Payload.U64 = undefined;
31503150 // TODO: figure out of cond_ty is correct (something with enum literals)
3151 break :blk value.enumToInt(cond_ty, &int_buffer).toUnsignedInt(mod); // TODO: composite integer constants
3151 break :blk (try value.enumToInt(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
31523152 },
31533153 else => unreachable,
31543154 };
src/link/Dwarf.zig+1-2
......@@ -421,8 +421,7 @@ pub const DeclState = struct {
421421 const value = vals.keys()[field_i];
422422 // TODO do not assume a 64bit enum value - could be bigger.
423423 // See https://github.com/ziglang/zig/issues/645
424 var int_buffer: Value.Payload.U64 = undefined;
425 const field_int_val = value.enumToInt(ty, &int_buffer);
424 const field_int_val = try value.enumToInt(ty, mod);
426425 break :value @bitCast(u64, field_int_val.toSignedInt(mod));
427426 } else @intCast(u64, field_i);
428427 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
src/type.zig+38-51
......@@ -2077,10 +2077,10 @@ pub const Type = struct {
20772077 }
20782078
20792079 /// May capture a reference to `ty`.
2080 pub fn lazyAbiAlignment(ty: Type, mod: *const Module, arena: Allocator) !Value {
2080 pub fn lazyAbiAlignment(ty: Type, mod: *Module, arena: Allocator) !Value {
20812081 switch (try ty.abiAlignmentAdvanced(mod, .{ .lazy = arena })) {
20822082 .val => |val| return val,
2083 .scalar => |x| return Value.Tag.int_u64.create(arena, x),
2083 .scalar => |x| return mod.intValue(ty, x),
20842084 }
20852085 }
20862086
......@@ -2468,10 +2468,10 @@ pub const Type = struct {
24682468 }
24692469
24702470 /// May capture a reference to `ty`.
2471 pub fn lazyAbiSize(ty: Type, mod: *const Module, arena: Allocator) !Value {
2471 pub fn lazyAbiSize(ty: Type, mod: *Module, arena: Allocator) !Value {
24722472 switch (try ty.abiSizeAdvanced(mod, .{ .lazy = arena })) {
24732473 .val => |val| return val,
2474 .scalar => |x| return Value.Tag.int_u64.create(arena, x),
2474 .scalar => |x| return mod.intValue(ty, x),
24752475 }
24762476 }
24772477
......@@ -4310,8 +4310,8 @@ pub const Type = struct {
43104310 }
43114311
43124312 // Works for vectors and vectors of integers.
4313 pub fn minInt(ty: Type, arena: Allocator, mod: *const Module) !Value {
4314 const scalar = try minIntScalar(ty.scalarType(mod), arena, mod);
4313 pub fn minInt(ty: Type, arena: Allocator, mod: *Module) !Value {
4314 const scalar = try minIntScalar(ty.scalarType(mod), mod);
43154315 if (ty.zigTypeTag(mod) == .Vector and scalar.tag() != .the_only_possible_value) {
43164316 return Value.Tag.repeated.create(arena, scalar);
43174317 } else {
......@@ -4319,38 +4319,28 @@ pub const Type = struct {
43194319 }
43204320 }
43214321
4322 /// Asserts that self.zigTypeTag(mod) == .Int.
4323 pub fn minIntScalar(ty: Type, arena: Allocator, mod: *const Module) !Value {
4324 assert(ty.zigTypeTag(mod) == .Int);
4322 /// Asserts that the type is an integer.
4323 pub fn minIntScalar(ty: Type, mod: *Module) !Value {
43254324 const info = ty.intInfo(mod);
4326
4327 if (info.bits == 0) {
4328 return Value.initTag(.the_only_possible_value);
4329 }
4330
4331 if (info.signedness == .unsigned) {
4332 return Value.zero;
4333 }
4325 if (info.signedness == .unsigned) return Value.zero;
4326 if (info.bits == 0) return Value.negative_one;
43344327
43354328 if (std.math.cast(u6, info.bits - 1)) |shift| {
43364329 const n = @as(i64, std.math.minInt(i64)) >> (63 - shift);
4337 return Value.Tag.int_i64.create(arena, n);
4330 return mod.intValue(Type.comptime_int, n);
43384331 }
43394332
4340 var res = try std.math.big.int.Managed.init(arena);
4333 var res = try std.math.big.int.Managed.init(mod.gpa);
4334 defer res.deinit();
4335
43414336 try res.setTwosCompIntLimit(.min, info.signedness, info.bits);
43424337
4343 const res_const = res.toConst();
4344 if (res_const.positive) {
4345 return Value.Tag.int_big_positive.create(arena, res_const.limbs);
4346 } else {
4347 return Value.Tag.int_big_negative.create(arena, res_const.limbs);
4348 }
4338 return mod.intValue_big(Type.comptime_int, res.toConst());
43494339 }
43504340
43514341 // Works for vectors and vectors of integers.
4352 pub fn maxInt(ty: Type, arena: Allocator, mod: *const Module) !Value {
4353 const scalar = try maxIntScalar(ty.scalarType(mod), arena, mod);
4342 pub fn maxInt(ty: Type, arena: Allocator, mod: *Module) !Value {
4343 const scalar = try maxIntScalar(ty.scalarType(mod), mod);
43544344 if (ty.zigTypeTag(mod) == .Vector and scalar.tag() != .the_only_possible_value) {
43554345 return Value.Tag.repeated.create(arena, scalar);
43564346 } else {
......@@ -4358,41 +4348,39 @@ pub const Type = struct {
43584348 }
43594349 }
43604350
4361 /// Asserts that self.zigTypeTag() == .Int.
4362 pub fn maxIntScalar(self: Type, arena: Allocator, mod: *const Module) !Value {
4363 assert(self.zigTypeTag(mod) == .Int);
4351 /// Asserts that the type is an integer.
4352 pub fn maxIntScalar(self: Type, mod: *Module) !Value {
43644353 const info = self.intInfo(mod);
43654354
4366 if (info.bits == 0) {
4367 return Value.initTag(.the_only_possible_value);
4368 }
4369
4370 switch (info.bits - @boolToInt(info.signedness == .signed)) {
4371 0 => return Value.zero,
4372 1 => return Value.one,
4355 switch (info.bits) {
4356 0 => return switch (info.signedness) {
4357 .signed => Value.negative_one,
4358 .unsigned => Value.zero,
4359 },
4360 1 => return switch (info.signedness) {
4361 .signed => Value.zero,
4362 .unsigned => Value.one,
4363 },
43734364 else => {},
43744365 }
43754366
43764367 if (std.math.cast(u6, info.bits - 1)) |shift| switch (info.signedness) {
43774368 .signed => {
43784369 const n = @as(i64, std.math.maxInt(i64)) >> (63 - shift);
4379 return Value.Tag.int_i64.create(arena, n);
4370 return mod.intValue(Type.comptime_int, n);
43804371 },
43814372 .unsigned => {
43824373 const n = @as(u64, std.math.maxInt(u64)) >> (63 - shift);
4383 return Value.Tag.int_u64.create(arena, n);
4374 return mod.intValue(Type.comptime_int, n);
43844375 },
43854376 };
43864377
4387 var res = try std.math.big.int.Managed.init(arena);
4378 var res = try std.math.big.int.Managed.init(mod.gpa);
4379 defer res.deinit();
4380
43884381 try res.setTwosCompIntLimit(.max, info.signedness, info.bits);
43894382
4390 const res_const = res.toConst();
4391 if (res_const.positive) {
4392 return Value.Tag.int_big_positive.create(arena, res_const.limbs);
4393 } else {
4394 return Value.Tag.int_big_negative.create(arena, res_const.limbs);
4395 }
4383 return mod.intValue_big(Type.comptime_int, res.toConst());
43964384 }
43974385
43984386 /// Asserts the type is an enum or a union.
......@@ -4497,12 +4485,11 @@ pub const Type = struct {
44974485 const S = struct {
44984486 fn fieldWithRange(int_ty: Type, int_val: Value, end: usize, m: *Module) ?usize {
44994487 if (int_val.compareAllWithZero(.lt, m)) return null;
4500 var end_payload: Value.Payload.U64 = .{
4501 .base = .{ .tag = .int_u64 },
4502 .data = end,
4488 const end_val = m.intValue(int_ty, end) catch |err| switch (err) {
4489 // TODO: eliminate this failure condition
4490 error.OutOfMemory => @panic("OOM"),
45034491 };
4504 const end_val = Value.initPayload(&end_payload.base);
4505 if (int_val.compareAll(.gte, end_val, int_ty, m)) return null;
4492 if (int_val.compareScalar(.gte, end_val, int_ty, m)) return null;
45064493 return @intCast(usize, int_val.toUnsignedInt(m));
45074494 }
45084495 };
src/value.zig+557-874
......@@ -33,8 +33,6 @@ pub const Value = struct {
3333 // Keep in sync with tools/stage2_pretty_printers_common.py
3434 pub const Tag = enum(usize) {
3535 // The first section of this enum are tags that require no payload.
36 zero,
37 one,
3836 /// The only possible value for a particular type, which is stored externally.
3937 the_only_possible_value,
4038
......@@ -43,10 +41,6 @@ pub const Value = struct {
4341 // After this, the tag requires a payload.
4442
4543 ty,
46 int_u64,
47 int_i64,
48 int_big_positive,
49 int_big_negative,
5044 function,
5145 extern_fn,
5246 /// A comptime-known pointer can point to the address of a global
......@@ -129,17 +123,11 @@ pub const Value = struct {
129123
130124 pub fn Type(comptime t: Tag) type {
131125 return switch (t) {
132 .zero,
133 .one,
134126 .the_only_possible_value,
135127 .empty_struct_value,
136128 .empty_array,
137129 => @compileError("Value Tag " ++ @tagName(t) ++ " has no payload"),
138130
139 .int_big_positive,
140 .int_big_negative,
141 => Payload.BigInt,
142
143131 .extern_fn => Payload.ExternFn,
144132
145133 .decl_ref => Payload.Decl,
......@@ -169,8 +157,6 @@ pub const Value = struct {
169157 .lazy_size,
170158 => Payload.Ty,
171159
172 .int_u64 => Payload.U64,
173 .int_i64 => Payload.I64,
174160 .function => Payload.Function,
175161 .variable => Payload.Variable,
176162 .decl_ref_mut => Payload.DeclRefMut,
......@@ -281,8 +267,6 @@ pub const Value = struct {
281267 .legacy = .{ .tag_if_small_enough = self.legacy.tag_if_small_enough },
282268 };
283269 } else switch (self.legacy.ptr_otherwise.tag) {
284 .zero,
285 .one,
286270 .the_only_possible_value,
287271 .empty_array,
288272 .empty_struct_value,
......@@ -300,20 +284,6 @@ pub const Value = struct {
300284 .legacy = .{ .ptr_otherwise = &new_payload.base },
301285 };
302286 },
303 .int_u64 => return self.copyPayloadShallow(arena, Payload.U64),
304 .int_i64 => return self.copyPayloadShallow(arena, Payload.I64),
305 .int_big_positive, .int_big_negative => {
306 const old_payload = self.cast(Payload.BigInt).?;
307 const new_payload = try arena.create(Payload.BigInt);
308 new_payload.* = .{
309 .base = .{ .tag = self.legacy.ptr_otherwise.tag },
310 .data = try arena.dupe(std.math.big.Limb, old_payload.data),
311 };
312 return Value{
313 .ip_index = .none,
314 .legacy = .{ .ptr_otherwise = &new_payload.base },
315 };
316 },
317287 .function => return self.copyPayloadShallow(arena, Payload.Function),
318288 .extern_fn => return self.copyPayloadShallow(arena, Payload.ExternFn),
319289 .variable => return self.copyPayloadShallow(arena, Payload.Variable),
......@@ -525,8 +495,6 @@ pub const Value = struct {
525495 .@"union" => {
526496 return out_stream.writeAll("(union value)");
527497 },
528 .zero => return out_stream.writeAll("0"),
529 .one => return out_stream.writeAll("1"),
530498 .the_only_possible_value => return out_stream.writeAll("(the only possible value)"),
531499 .ty => return val.castTag(.ty).?.data.dump("", options, out_stream),
532500 .lazy_align => {
......@@ -539,10 +507,6 @@ pub const Value = struct {
539507 try val.castTag(.lazy_size).?.data.dump("", options, out_stream);
540508 return try out_stream.writeAll(")");
541509 },
542 .int_u64 => return std.fmt.formatIntValue(val.castTag(.int_u64).?.data, "", options, out_stream),
543 .int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", options, out_stream),
544 .int_big_positive => return out_stream.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}),
545 .int_big_negative => return out_stream.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}),
546510 .runtime_value => return out_stream.writeAll("[runtime value]"),
547511 .function => return out_stream.print("(function decl={d})", .{val.castTag(.function).?.data.owner_decl}),
548512 .extern_fn => return out_stream.writeAll("(extern function)"),
......@@ -661,9 +625,8 @@ pub const Value = struct {
661625
662626 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {
663627 const result = try allocator.alloc(u8, @intCast(usize, len));
664 var elem_value_buf: ElemValueBuffer = undefined;
665628 for (result, 0..) |*elem, i| {
666 const elem_val = val.elemValueBuffer(mod, i, &elem_value_buf);
629 const elem_val = try val.elemValue(mod, i);
667630 elem.* = @intCast(u8, elem_val.toUnsignedInt(mod));
668631 }
669632 return result;
......@@ -695,7 +658,7 @@ pub const Value = struct {
695658 }
696659 }
697660
698 pub fn enumToInt(val: Value, ty: Type, buffer: *Payload.U64) Value {
661 pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {
699662 const field_index = switch (val.tag()) {
700663 .enum_field_index => val.castTag(.enum_field_index).?.data,
701664 .the_only_possible_value => blk: {
......@@ -717,11 +680,7 @@ pub const Value = struct {
717680 return enum_full.values.keys()[field_index];
718681 } else {
719682 // Field index and integer values are the same.
720 buffer.* = .{
721 .base = .{ .tag = .int_u64 },
722 .data = field_index,
723 };
724 return Value.initPayload(&buffer.base);
683 return mod.intValue(enum_full.tag_ty, field_index);
725684 }
726685 },
727686 .enum_numbered => {
......@@ -730,20 +689,13 @@ pub const Value = struct {
730689 return enum_obj.values.keys()[field_index];
731690 } else {
732691 // Field index and integer values are the same.
733 buffer.* = .{
734 .base = .{ .tag = .int_u64 },
735 .data = field_index,
736 };
737 return Value.initPayload(&buffer.base);
692 return mod.intValue(enum_obj.tag_ty, field_index);
738693 }
739694 },
740695 .enum_simple => {
741696 // Field index and integer values are the same.
742 buffer.* = .{
743 .base = .{ .tag = .int_u64 },
744 .data = field_index,
745 };
746 return Value.initPayload(&buffer.base);
697 const tag_ty = ty.intTagType();
698 return mod.intValue(tag_ty, field_index);
747699 },
748700 else => unreachable,
749701 }
......@@ -802,12 +754,9 @@ pub const Value = struct {
802754 .undef => unreachable,
803755 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),
804756 .none => switch (val.tag()) {
805 .zero,
806757 .the_only_possible_value, // i0, u0
807758 => BigIntMutable.init(&space.limbs, 0).toConst(),
808759
809 .one => BigIntMutable.init(&space.limbs, 1).toConst(),
810
811760 .enum_field_index => {
812761 const index = val.castTag(.enum_field_index).?.data;
813762 return BigIntMutable.init(&space.limbs, index).toConst();
......@@ -816,11 +765,6 @@ pub const Value = struct {
816765 const sub_val = val.castTag(.runtime_value).?.data;
817766 return sub_val.toBigIntAdvanced(space, mod, opt_sema);
818767 },
819 .int_u64 => BigIntMutable.init(&space.limbs, val.castTag(.int_u64).?.data).toConst(),
820 .int_i64 => BigIntMutable.init(&space.limbs, val.castTag(.int_i64).?.data).toConst(),
821 .int_big_positive => val.castTag(.int_big_positive).?.asBigInt(),
822 .int_big_negative => val.castTag(.int_big_negative).?.asBigInt(),
823
824768 .lazy_align => {
825769 const ty = val.castTag(.lazy_align).?.data;
826770 if (opt_sema) |sema| {
......@@ -869,17 +813,9 @@ pub const Value = struct {
869813 .bool_true => return 1,
870814 .undef => unreachable,
871815 .none => switch (val.tag()) {
872 .zero,
873816 .the_only_possible_value, // i0, u0
874817 => return 0,
875818
876 .one => return 1,
877
878 .int_u64 => return val.castTag(.int_u64).?.data,
879 .int_i64 => return @intCast(u64, val.castTag(.int_i64).?.data),
880 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(u64) catch null,
881 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(u64) catch null,
882
883819 .lazy_align => {
884820 const ty = val.castTag(.lazy_align).?.data;
885821 if (opt_sema) |sema| {
......@@ -922,17 +858,9 @@ pub const Value = struct {
922858 .bool_true => return 1,
923859 .undef => unreachable,
924860 .none => switch (val.tag()) {
925 .zero,
926861 .the_only_possible_value, // i0, u0
927862 => return 0,
928863
929 .one => return 1,
930
931 .int_u64 => return @intCast(i64, val.castTag(.int_u64).?.data),
932 .int_i64 => return val.castTag(.int_i64).?.data,
933 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(i64) catch unreachable,
934 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(i64) catch unreachable,
935
936864 .lazy_align => {
937865 const ty = val.castTag(.lazy_align).?.data;
938866 return @intCast(i64, ty.abiAlignment(mod));
......@@ -959,22 +887,7 @@ pub const Value = struct {
959887 return switch (val.ip_index) {
960888 .bool_true => true,
961889 .bool_false => false,
962 .none => switch (val.tag()) {
963 .one => true,
964 .zero => false,
965
966 .int_u64 => switch (val.castTag(.int_u64).?.data) {
967 0 => false,
968 1 => true,
969 else => unreachable,
970 },
971 .int_i64 => switch (val.castTag(.int_i64).?.data) {
972 0 => false,
973 1 => true,
974 else => unreachable,
975 },
976 else => unreachable,
977 },
890 .none => unreachable,
978891 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
979892 .int => |int| switch (int.storage) {
980893 .big_int => |big_int| !big_int.eqZero(),
......@@ -1004,6 +917,7 @@ pub const Value = struct {
1004917 ReinterpretDeclRef,
1005918 IllDefinedMemoryLayout,
1006919 Unimplemented,
920 OutOfMemory,
1007921 }!void {
1008922 const target = mod.getTarget();
1009923 const endian = target.cpu.arch.endian();
......@@ -1022,16 +936,14 @@ pub const Value = struct {
1022936 const bits = int_info.bits;
1023937 const byte_count = (bits + 7) / 8;
1024938
1025 var enum_buffer: Payload.U64 = undefined;
1026 const int_val = val.enumToInt(ty, &enum_buffer);
939 const int_val = try val.enumToInt(ty, mod);
1027940
1028941 if (byte_count <= @sizeOf(u64)) {
1029 const int: u64 = switch (int_val.tag()) {
1030 .zero => 0,
1031 .one => 1,
1032 .int_u64 => int_val.castTag(.int_u64).?.data,
1033 .int_i64 => @bitCast(u64, int_val.castTag(.int_i64).?.data),
1034 else => unreachable,
942 const ip_key = mod.intern_pool.indexToKey(int_val.ip_index);
943 const int: u64 = switch (ip_key.int.storage) {
944 .u64 => |x| x,
945 .i64 => |x| @bitCast(u64, x),
946 .big_int => unreachable,
1035947 };
1036948 for (buffer[0..byte_count], 0..) |_, i| switch (endian) {
1037949 .Little => buffer[i] = @truncate(u8, (int >> @intCast(u6, (8 * i)))),
......@@ -1044,11 +956,11 @@ pub const Value = struct {
1044956 }
1045957 },
1046958 .Float => switch (ty.floatBits(target)) {
1047 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(u16, val.toFloat(f16)), endian),
1048 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(u32, val.toFloat(f32)), endian),
1049 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(u64, val.toFloat(f64)), endian),
1050 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(u80, val.toFloat(f80)), endian),
1051 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(u128, val.toFloat(f128)), endian),
959 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(u16, val.toFloat(f16, mod)), endian),
960 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(u32, val.toFloat(f32, mod)), endian),
961 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(u64, val.toFloat(f64, mod)), endian),
962 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(u80, val.toFloat(f80, mod)), endian),
963 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(u128, val.toFloat(f128, mod)), endian),
1052964 else => unreachable,
1053965 },
1054966 .Array => {
......@@ -1056,10 +968,9 @@ pub const Value = struct {
1056968 const elem_ty = ty.childType(mod);
1057969 const elem_size = @intCast(usize, elem_ty.abiSize(mod));
1058970 var elem_i: usize = 0;
1059 var elem_value_buf: ElemValueBuffer = undefined;
1060971 var buf_off: usize = 0;
1061972 while (elem_i < len) : (elem_i += 1) {
1062 const elem_val = val.elemValueBuffer(mod, elem_i, &elem_value_buf);
973 const elem_val = try val.elemValue(mod, elem_i);
1063974 try elem_val.writeToMemory(elem_ty, mod, buffer[buf_off..]);
1064975 buf_off += elem_size;
1065976 }
......@@ -1122,7 +1033,13 @@ pub const Value = struct {
11221033 ///
11231034 /// Both the start and the end of the provided buffer must be tight, since
11241035 /// big-endian packed memory layouts start at the end of the buffer.
1125 pub fn writeToPackedMemory(val: Value, ty: Type, mod: *Module, buffer: []u8, bit_offset: usize) error{ReinterpretDeclRef}!void {
1036 pub fn writeToPackedMemory(
1037 val: Value,
1038 ty: Type,
1039 mod: *Module,
1040 buffer: []u8,
1041 bit_offset: usize,
1042 ) error{ ReinterpretDeclRef, OutOfMemory }!void {
11261043 const target = mod.getTarget();
11271044 const endian = target.cpu.arch.endian();
11281045 if (val.isUndef()) {
......@@ -1147,16 +1064,14 @@ pub const Value = struct {
11471064 const bits = ty.intInfo(mod).bits;
11481065 const abi_size = @intCast(usize, ty.abiSize(mod));
11491066
1150 var enum_buffer: Payload.U64 = undefined;
1151 const int_val = val.enumToInt(ty, &enum_buffer);
1067 const int_val = try val.enumToInt(ty, mod);
11521068
11531069 if (abi_size == 0) return;
11541070 if (abi_size <= @sizeOf(u64)) {
1155 const int: u64 = switch (int_val.tag()) {
1156 .zero => 0,
1157 .one => 1,
1158 .int_u64 => int_val.castTag(.int_u64).?.data,
1159 .int_i64 => @bitCast(u64, int_val.castTag(.int_i64).?.data),
1071 const ip_key = mod.intern_pool.indexToKey(int_val.ip_index);
1072 const int: u64 = switch (ip_key.int.storage) {
1073 .u64 => |x| x,
1074 .i64 => |x| @bitCast(u64, x),
11601075 else => unreachable,
11611076 };
11621077 std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian);
......@@ -1167,11 +1082,11 @@ pub const Value = struct {
11671082 }
11681083 },
11691084 .Float => switch (ty.floatBits(target)) {
1170 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(u16, val.toFloat(f16)), endian),
1171 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(u32, val.toFloat(f32)), endian),
1172 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(u64, val.toFloat(f64)), endian),
1173 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(u80, val.toFloat(f80)), endian),
1174 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(u128, val.toFloat(f128)), endian),
1085 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(u16, val.toFloat(f16, mod)), endian),
1086 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(u32, val.toFloat(f32, mod)), endian),
1087 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(u64, val.toFloat(f64, mod)), endian),
1088 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(u80, val.toFloat(f80, mod)), endian),
1089 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(u128, val.toFloat(f128, mod)), endian),
11751090 else => unreachable,
11761091 },
11771092 .Vector => {
......@@ -1181,11 +1096,10 @@ pub const Value = struct {
11811096
11821097 var bits: u16 = 0;
11831098 var elem_i: usize = 0;
1184 var elem_value_buf: ElemValueBuffer = undefined;
11851099 while (elem_i < len) : (elem_i += 1) {
11861100 // On big-endian systems, LLVM reverses the element order of vectors by default
11871101 const tgt_elem_i = if (endian == .Big) len - elem_i - 1 else elem_i;
1188 const elem_val = val.elemValueBuffer(mod, tgt_elem_i, &elem_value_buf);
1102 const elem_val = try val.elemValue(mod, tgt_elem_i);
11891103 try elem_val.writeToPackedMemory(elem_ty, mod, buffer, bit_offset + bits);
11901104 bits += elem_bit_size;
11911105 }
......@@ -1264,11 +1178,13 @@ pub const Value = struct {
12641178 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
12651179 .signed => {
12661180 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);
1267 return Value.Tag.int_i64.create(arena, (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits));
1181 const result = (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits);
1182 return mod.intValue(ty, result);
12681183 },
12691184 .unsigned => {
12701185 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
1271 return Value.Tag.int_u64.create(arena, (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits));
1186 const result = (val << @intCast(u6, 64 - bits)) >> @intCast(u6, 64 - bits);
1187 return mod.intValue(ty, result);
12721188 },
12731189 } else { // Slow path, we have to construct a big-int
12741190 const Limb = std.math.big.Limb;
......@@ -1277,7 +1193,7 @@ pub const Value = struct {
12771193
12781194 var bigint = BigIntMutable.init(limbs_buffer, 0);
12791195 bigint.readTwosComplement(buffer[0..byte_count], bits, endian, int_info.signedness);
1280 return fromBigInt(arena, bigint.toConst());
1196 return mod.intValue_big(ty, bigint.toConst());
12811197 }
12821198 },
12831199 .Float => switch (ty.floatBits(target)) {
......@@ -1381,8 +1297,8 @@ pub const Value = struct {
13811297 const bits = int_info.bits;
13821298 if (bits == 0) return Value.zero;
13831299 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
1384 .signed => return Value.Tag.int_i64.create(arena, std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, .signed)),
1385 .unsigned => return Value.Tag.int_u64.create(arena, std.mem.readVarPackedInt(u64, buffer, bit_offset, bits, endian, .unsigned)),
1300 .signed => return mod.intValue(ty, std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, .signed)),
1301 .unsigned => return mod.intValue(ty, std.mem.readVarPackedInt(u64, buffer, bit_offset, bits, endian, .unsigned)),
13861302 } else { // Slow path, we have to construct a big-int
13871303 const Limb = std.math.big.Limb;
13881304 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
......@@ -1390,7 +1306,7 @@ pub const Value = struct {
13901306
13911307 var bigint = BigIntMutable.init(limbs_buffer, 0);
13921308 bigint.readPackedTwosComplement(buffer, bit_offset, bits, endian, int_info.signedness);
1393 return fromBigInt(arena, bigint.toConst());
1309 return mod.intValue_big(ty, bigint.toConst());
13941310 }
13951311 },
13961312 .Float => switch (ty.floatBits(target)) {
......@@ -1444,32 +1360,29 @@ pub const Value = struct {
14441360 }
14451361
14461362 /// Asserts that the value is a float or an integer.
1447 pub fn toFloat(val: Value, comptime T: type) T {
1448 return switch (val.tag()) {
1449 .float_16 => @floatCast(T, val.castTag(.float_16).?.data),
1450 .float_32 => @floatCast(T, val.castTag(.float_32).?.data),
1451 .float_64 => @floatCast(T, val.castTag(.float_64).?.data),
1452 .float_80 => @floatCast(T, val.castTag(.float_80).?.data),
1453 .float_128 => @floatCast(T, val.castTag(.float_128).?.data),
1454
1455 .zero => 0,
1456 .one => 1,
1457 .int_u64 => {
1458 if (T == f80) {
1459 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1460 }
1461 return @intToFloat(T, val.castTag(.int_u64).?.data);
1363 pub fn toFloat(val: Value, comptime T: type, mod: *const Module) T {
1364 return switch (val.ip_index) {
1365 .none => switch (val.tag()) {
1366 .float_16 => @floatCast(T, val.castTag(.float_16).?.data),
1367 .float_32 => @floatCast(T, val.castTag(.float_32).?.data),
1368 .float_64 => @floatCast(T, val.castTag(.float_64).?.data),
1369 .float_80 => @floatCast(T, val.castTag(.float_80).?.data),
1370 .float_128 => @floatCast(T, val.castTag(.float_128).?.data),
1371
1372 else => unreachable,
14621373 },
1463 .int_i64 => {
1464 if (T == f80) {
1465 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1466 }
1467 return @intToFloat(T, val.castTag(.int_i64).?.data);
1374 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
1375 .int => |int| switch (int.storage) {
1376 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),
1377 inline .u64, .i64 => |x| {
1378 if (T == f80) {
1379 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1380 }
1381 return @intToFloat(T, x);
1382 },
1383 },
1384 else => unreachable,
14681385 },
1469
1470 .int_big_positive => @floatCast(T, bigIntToFloat(val.castTag(.int_big_positive).?.data, true)),
1471 .int_big_negative => @floatCast(T, bigIntToFloat(val.castTag(.int_big_negative).?.data, false)),
1472 else => unreachable,
14731386 };
14741387 }
14751388
......@@ -1498,24 +1411,6 @@ pub const Value = struct {
14981411 .bool_false => ty_bits,
14991412 .bool_true => ty_bits - 1,
15001413 .none => switch (val.tag()) {
1501 .zero => ty_bits,
1502 .one => ty_bits - 1,
1503
1504 .int_u64 => {
1505 const big = @clz(val.castTag(.int_u64).?.data);
1506 return big + ty_bits - 64;
1507 },
1508 .int_i64 => {
1509 @panic("TODO implement i64 Value clz");
1510 },
1511 .int_big_positive => {
1512 const bigint = val.castTag(.int_big_positive).?.asBigInt();
1513 return bigint.clz(ty_bits);
1514 },
1515 .int_big_negative => {
1516 @panic("TODO implement int_big_negative Value clz");
1517 },
1518
15191414 .the_only_possible_value => {
15201415 assert(ty_bits == 0);
15211416 return ty_bits;
......@@ -1546,24 +1441,6 @@ pub const Value = struct {
15461441 .bool_false => ty_bits,
15471442 .bool_true => 0,
15481443 .none => switch (val.tag()) {
1549 .zero => ty_bits,
1550 .one => 0,
1551
1552 .int_u64 => {
1553 const big = @ctz(val.castTag(.int_u64).?.data);
1554 return if (big == 64) ty_bits else big;
1555 },
1556 .int_i64 => {
1557 @panic("TODO implement i64 Value ctz");
1558 },
1559 .int_big_positive => {
1560 const bigint = val.castTag(.int_big_positive).?.asBigInt();
1561 return bigint.ctz();
1562 },
1563 .int_big_negative => {
1564 @panic("TODO implement int_big_negative Value ctz");
1565 },
1566
15671444 .the_only_possible_value => {
15681445 assert(ty_bits == 0);
15691446 return ty_bits;
......@@ -1596,20 +1473,7 @@ pub const Value = struct {
15961473 switch (val.ip_index) {
15971474 .bool_false => return 0,
15981475 .bool_true => return 1,
1599 .none => switch (val.tag()) {
1600 .zero => return 0,
1601 .one => return 1,
1602
1603 .int_u64 => return @popCount(val.castTag(.int_u64).?.data),
1604
1605 else => {
1606 const info = ty.intInfo(mod);
1607
1608 var buffer: Value.BigIntSpace = undefined;
1609 const int = val.toBigInt(&buffer, mod);
1610 return @intCast(u64, int.popCount(info.bits));
1611 },
1612 },
1476 .none => unreachable,
16131477 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
16141478 .int => |int| {
16151479 const info = ty.intInfo(mod);
......@@ -1622,7 +1486,7 @@ pub const Value = struct {
16221486 }
16231487 }
16241488
1625 pub fn bitReverse(val: Value, ty: Type, mod: *const Module, arena: Allocator) !Value {
1489 pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
16261490 assert(!val.isUndef());
16271491
16281492 const info = ty.intInfo(mod);
......@@ -1637,10 +1501,10 @@ pub const Value = struct {
16371501 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
16381502 result_bigint.bitReverse(operand_bigint, info.signedness, info.bits);
16391503
1640 return fromBigInt(arena, result_bigint.toConst());
1504 return mod.intValue_big(ty, result_bigint.toConst());
16411505 }
16421506
1643 pub fn byteSwap(val: Value, ty: Type, mod: *const Module, arena: Allocator) !Value {
1507 pub fn byteSwap(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
16441508 assert(!val.isUndef());
16451509
16461510 const info = ty.intInfo(mod);
......@@ -1658,7 +1522,7 @@ pub const Value = struct {
16581522 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
16591523 result_bigint.byteSwap(operand_bigint, info.signedness, info.bits / 8);
16601524
1661 return fromBigInt(arena, result_bigint.toConst());
1525 return mod.intValue_big(ty, result_bigint.toConst());
16621526 }
16631527
16641528 /// Asserts the value is an integer and not undefined.
......@@ -1669,19 +1533,7 @@ pub const Value = struct {
16691533 .bool_false => 0,
16701534 .bool_true => 1,
16711535 .none => switch (self.tag()) {
1672 .zero,
1673 .the_only_possible_value,
1674 => 0,
1675
1676 .one => 1,
1677
1678 .int_u64 => {
1679 const x = self.castTag(.int_u64).?.data;
1680 if (x == 0) return 0;
1681 return @intCast(usize, std.math.log2(x) + 1);
1682 },
1683 .int_big_positive => self.castTag(.int_big_positive).?.asBigInt().bitCountTwosComp(),
1684 .int_big_negative => self.castTag(.int_big_negative).?.asBigInt().bitCountTwosComp(),
1536 .the_only_possible_value => 0,
16851537
16861538 .decl_ref_mut,
16871539 .comptime_field_ptr,
......@@ -1715,13 +1567,14 @@ pub const Value = struct {
17151567
17161568 /// Converts an integer or a float to a float. May result in a loss of information.
17171569 /// Caller can find out by equality checking the result against the operand.
1718 pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type, target: Target) !Value {
1570 pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type, mod: *const Module) !Value {
1571 const target = mod.getTarget();
17191572 switch (dest_ty.floatBits(target)) {
1720 16 => return Value.Tag.float_16.create(arena, self.toFloat(f16)),
1721 32 => return Value.Tag.float_32.create(arena, self.toFloat(f32)),
1722 64 => return Value.Tag.float_64.create(arena, self.toFloat(f64)),
1723 80 => return Value.Tag.float_80.create(arena, self.toFloat(f80)),
1724 128 => return Value.Tag.float_128.create(arena, self.toFloat(f128)),
1573 16 => return Value.Tag.float_16.create(arena, self.toFloat(f16, mod)),
1574 32 => return Value.Tag.float_32.create(arena, self.toFloat(f32, mod)),
1575 64 => return Value.Tag.float_64.create(arena, self.toFloat(f64, mod)),
1576 80 => return Value.Tag.float_80.create(arena, self.toFloat(f80, mod)),
1577 128 => return Value.Tag.float_128.create(arena, self.toFloat(f128, mod)),
17251578 else => unreachable,
17261579 }
17271580 }
......@@ -1729,10 +1582,6 @@ pub const Value = struct {
17291582 /// Asserts the value is a float
17301583 pub fn floatHasFraction(self: Value) bool {
17311584 return switch (self.tag()) {
1732 .zero,
1733 .one,
1734 => false,
1735
17361585 .float_16 => @rem(self.castTag(.float_16).?.data, 1) != 0,
17371586 .float_32 => @rem(self.castTag(.float_32).?.data, 1) != 0,
17381587 .float_64 => @rem(self.castTag(.float_64).?.data, 1) != 0,
......@@ -1757,11 +1606,8 @@ pub const Value = struct {
17571606 .bool_false => return .eq,
17581607 .bool_true => return .gt,
17591608 .none => return switch (lhs.tag()) {
1760 .zero,
1761 .the_only_possible_value,
1762 => .eq,
1609 .the_only_possible_value => .eq,
17631610
1764 .one,
17651611 .decl_ref,
17661612 .decl_ref_mut,
17671613 .comptime_field_ptr,
......@@ -1777,10 +1623,6 @@ pub const Value = struct {
17771623 const val = lhs.castTag(.runtime_value).?.data;
17781624 return val.orderAgainstZeroAdvanced(mod, opt_sema);
17791625 },
1780 .int_u64 => std.math.order(lhs.castTag(.int_u64).?.data, 0),
1781 .int_i64 => std.math.order(lhs.castTag(.int_i64).?.data, 0),
1782 .int_big_positive => lhs.castTag(.int_big_positive).?.asBigInt().orderAgainstScalar(0),
1783 .int_big_negative => lhs.castTag(.int_big_negative).?.asBigInt().orderAgainstScalar(0),
17841626
17851627 .lazy_align => {
17861628 const ty = lhs.castTag(.lazy_align).?.data;
......@@ -1878,8 +1720,8 @@ pub const Value = struct {
18781720 }
18791721 }
18801722 if (lhs_float or rhs_float) {
1881 const lhs_f128 = lhs.toFloat(f128);
1882 const rhs_f128 = rhs.toFloat(f128);
1723 const lhs_f128 = lhs.toFloat(f128, mod);
1724 const rhs_f128 = rhs.toFloat(f128, mod);
18831725 return std.math.order(lhs_f128, rhs_f128);
18841726 }
18851727
......@@ -1929,15 +1771,13 @@ pub const Value = struct {
19291771
19301772 /// Asserts the values are comparable. Both operands have type `ty`.
19311773 /// For vectors, returns true if comparison is true for ALL elements.
1932 pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, mod: *Module) bool {
1774 pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, mod: *Module) !bool {
19331775 if (ty.zigTypeTag(mod) == .Vector) {
1934 var i: usize = 0;
1935 while (i < ty.vectorLen(mod)) : (i += 1) {
1936 var lhs_buf: Value.ElemValueBuffer = undefined;
1937 var rhs_buf: Value.ElemValueBuffer = undefined;
1938 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
1939 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
1940 if (!compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod), mod)) {
1776 const scalar_ty = ty.scalarType(mod);
1777 for (0..ty.vectorLen(mod)) |i| {
1778 const lhs_elem = try lhs.elemValue(mod, i);
1779 const rhs_elem = try rhs.elemValue(mod, i);
1780 if (!compareScalar(lhs_elem, op, rhs_elem, scalar_ty, mod)) {
19411781 return false;
19421782 }
19431783 }
......@@ -2203,10 +2043,8 @@ pub const Value = struct {
22032043 return a_type.eql(b_type, mod);
22042044 },
22052045 .Enum => {
2206 var buf_a: Payload.U64 = undefined;
2207 var buf_b: Payload.U64 = undefined;
2208 const a_val = a.enumToInt(ty, &buf_a);
2209 const b_val = b.enumToInt(ty, &buf_b);
2046 const a_val = try a.enumToInt(ty, mod);
2047 const b_val = try b.enumToInt(ty, mod);
22102048 const int_ty = ty.intTagType();
22112049 return eqlAdvanced(a_val, int_ty, b_val, int_ty, mod, opt_sema);
22122050 },
......@@ -2214,11 +2052,9 @@ pub const Value = struct {
22142052 const len = ty.arrayLen(mod);
22152053 const elem_ty = ty.childType(mod);
22162054 var i: usize = 0;
2217 var a_buf: ElemValueBuffer = undefined;
2218 var b_buf: ElemValueBuffer = undefined;
22192055 while (i < len) : (i += 1) {
2220 const a_elem = elemValueBuffer(a, mod, i, &a_buf);
2221 const b_elem = elemValueBuffer(b, mod, i, &b_buf);
2056 const a_elem = try elemValue(a, mod, i);
2057 const b_elem = try elemValue(b, mod, i);
22222058 if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, opt_sema))) {
22232059 return false;
22242060 }
......@@ -2282,17 +2118,17 @@ pub const Value = struct {
22822118 },
22832119 .Float => {
22842120 switch (ty.floatBits(target)) {
2285 16 => return @bitCast(u16, a.toFloat(f16)) == @bitCast(u16, b.toFloat(f16)),
2286 32 => return @bitCast(u32, a.toFloat(f32)) == @bitCast(u32, b.toFloat(f32)),
2287 64 => return @bitCast(u64, a.toFloat(f64)) == @bitCast(u64, b.toFloat(f64)),
2288 80 => return @bitCast(u80, a.toFloat(f80)) == @bitCast(u80, b.toFloat(f80)),
2289 128 => return @bitCast(u128, a.toFloat(f128)) == @bitCast(u128, b.toFloat(f128)),
2121 16 => return @bitCast(u16, a.toFloat(f16, mod)) == @bitCast(u16, b.toFloat(f16, mod)),
2122 32 => return @bitCast(u32, a.toFloat(f32, mod)) == @bitCast(u32, b.toFloat(f32, mod)),
2123 64 => return @bitCast(u64, a.toFloat(f64, mod)) == @bitCast(u64, b.toFloat(f64, mod)),
2124 80 => return @bitCast(u80, a.toFloat(f80, mod)) == @bitCast(u80, b.toFloat(f80, mod)),
2125 128 => return @bitCast(u128, a.toFloat(f128, mod)) == @bitCast(u128, b.toFloat(f128, mod)),
22902126 else => unreachable,
22912127 }
22922128 },
22932129 .ComptimeFloat => {
2294 const a_float = a.toFloat(f128);
2295 const b_float = b.toFloat(f128);
2130 const a_float = a.toFloat(f128, mod);
2131 const b_float = b.toFloat(f128, mod);
22962132
22972133 const a_nan = std.math.isNan(a_float);
22982134 const b_nan = std.math.isNan(b_float);
......@@ -2354,16 +2190,16 @@ pub const Value = struct {
23542190 .Float => {
23552191 // For hash/eql purposes, we treat floats as their IEEE integer representation.
23562192 switch (ty.floatBits(mod.getTarget())) {
2357 16 => std.hash.autoHash(hasher, @bitCast(u16, val.toFloat(f16))),
2358 32 => std.hash.autoHash(hasher, @bitCast(u32, val.toFloat(f32))),
2359 64 => std.hash.autoHash(hasher, @bitCast(u64, val.toFloat(f64))),
2360 80 => std.hash.autoHash(hasher, @bitCast(u80, val.toFloat(f80))),
2361 128 => std.hash.autoHash(hasher, @bitCast(u128, val.toFloat(f128))),
2193 16 => std.hash.autoHash(hasher, @bitCast(u16, val.toFloat(f16, mod))),
2194 32 => std.hash.autoHash(hasher, @bitCast(u32, val.toFloat(f32, mod))),
2195 64 => std.hash.autoHash(hasher, @bitCast(u64, val.toFloat(f64, mod))),
2196 80 => std.hash.autoHash(hasher, @bitCast(u80, val.toFloat(f80, mod))),
2197 128 => std.hash.autoHash(hasher, @bitCast(u128, val.toFloat(f128, mod))),
23622198 else => unreachable,
23632199 }
23642200 },
23652201 .ComptimeFloat => {
2366 const float = val.toFloat(f128);
2202 const float = val.toFloat(f128, mod);
23672203 const is_nan = std.math.isNan(float);
23682204 std.hash.autoHash(hasher, is_nan);
23692205 if (!is_nan) {
......@@ -2387,9 +2223,11 @@ pub const Value = struct {
23872223 const len = ty.arrayLen(mod);
23882224 const elem_ty = ty.childType(mod);
23892225 var index: usize = 0;
2390 var elem_value_buf: ElemValueBuffer = undefined;
23912226 while (index < len) : (index += 1) {
2392 const elem_val = val.elemValueBuffer(mod, index, &elem_value_buf);
2227 const elem_val = val.elemValue(mod, index) catch |err| switch (err) {
2228 // Will be solved when arrays and vectors get migrated to the intern pool.
2229 error.OutOfMemory => @panic("OOM"),
2230 };
23932231 elem_val.hash(elem_ty, hasher, mod);
23942232 }
23952233 },
......@@ -2438,8 +2276,8 @@ pub const Value = struct {
24382276 hasher.update(val.getError().?);
24392277 },
24402278 .Enum => {
2441 var enum_space: Payload.U64 = undefined;
2442 const int_val = val.enumToInt(ty, &enum_space);
2279 // This panic will go away when enum values move to be stored in the intern pool.
2280 const int_val = val.enumToInt(ty, mod) catch @panic("OOM");
24432281 hashInt(int_val, hasher, mod);
24442282 },
24452283 .Union => {
......@@ -2494,7 +2332,7 @@ pub const Value = struct {
24942332 .Type => {
24952333 val.toType().hashWithHasher(hasher, mod);
24962334 },
2497 .Float, .ComptimeFloat => std.hash.autoHash(hasher, @bitCast(u128, val.toFloat(f128))),
2335 .Float, .ComptimeFloat => std.hash.autoHash(hasher, @bitCast(u128, val.toFloat(f128, mod))),
24982336 .Bool, .Int, .ComptimeInt, .Pointer, .Fn => switch (val.tag()) {
24992337 .slice => {
25002338 const slice = val.castTag(.slice).?.data;
......@@ -2508,9 +2346,11 @@ pub const Value = struct {
25082346 const len = ty.arrayLen(mod);
25092347 const elem_ty = ty.childType(mod);
25102348 var index: usize = 0;
2511 var elem_value_buf: ElemValueBuffer = undefined;
25122349 while (index < len) : (index += 1) {
2513 const elem_val = val.elemValueBuffer(mod, index, &elem_value_buf);
2350 const elem_val = val.elemValue(mod, index) catch |err| switch (err) {
2351 // Will be solved when arrays and vectors get migrated to the intern pool.
2352 error.OutOfMemory => @panic("OOM"),
2353 };
25142354 elem_val.hashUncoerced(elem_ty, hasher, mod);
25152355 }
25162356 },
......@@ -2661,12 +2501,6 @@ pub const Value = struct {
26612501 hashPtr(opt_ptr.container_ptr, hasher, mod);
26622502 },
26632503
2664 .zero,
2665 .one,
2666 .int_u64,
2667 .int_i64,
2668 .int_big_positive,
2669 .int_big_negative,
26702504 .the_only_possible_value,
26712505 .lazy_align,
26722506 .lazy_size,
......@@ -2720,23 +2554,7 @@ pub const Value = struct {
27202554
27212555 /// Asserts the value is a single-item pointer to an array, or an array,
27222556 /// or an unknown-length pointer, and returns the element value at the index.
2723 pub fn elemValue(val: Value, mod: *Module, arena: Allocator, index: usize) !Value {
2724 return elemValueAdvanced(val, mod, index, arena, undefined);
2725 }
2726
2727 pub const ElemValueBuffer = Payload.U64;
2728
2729 pub fn elemValueBuffer(val: Value, mod: *Module, index: usize, buffer: *ElemValueBuffer) Value {
2730 return elemValueAdvanced(val, mod, index, null, buffer) catch unreachable;
2731 }
2732
2733 pub fn elemValueAdvanced(
2734 val: Value,
2735 mod: *Module,
2736 index: usize,
2737 arena: ?Allocator,
2738 buffer: *ElemValueBuffer,
2739 ) error{OutOfMemory}!Value {
2557 pub fn elemValue(val: Value, mod: *Module, index: usize) Allocator.Error!Value {
27402558 switch (val.ip_index) {
27412559 .undef => return Value.undef,
27422560 .none => switch (val.tag()) {
......@@ -2751,43 +2569,27 @@ pub const Value = struct {
27512569
27522570 .bytes => {
27532571 const byte = val.castTag(.bytes).?.data[index];
2754 if (arena) |a| {
2755 return Tag.int_u64.create(a, byte);
2756 } else {
2757 buffer.* = .{
2758 .base = .{ .tag = .int_u64 },
2759 .data = byte,
2760 };
2761 return initPayload(&buffer.base);
2762 }
2572 return mod.intValue(Type.u8, byte);
27632573 },
27642574 .str_lit => {
27652575 const str_lit = val.castTag(.str_lit).?.data;
27662576 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
27672577 const byte = bytes[index];
2768 if (arena) |a| {
2769 return Tag.int_u64.create(a, byte);
2770 } else {
2771 buffer.* = .{
2772 .base = .{ .tag = .int_u64 },
2773 .data = byte,
2774 };
2775 return initPayload(&buffer.base);
2776 }
2578 return mod.intValue(Type.u8, byte);
27772579 },
27782580
27792581 // No matter the index; all the elements are the same!
27802582 .repeated => return val.castTag(.repeated).?.data,
27812583
27822584 .aggregate => return val.castTag(.aggregate).?.data[index],
2783 .slice => return val.castTag(.slice).?.data.ptr.elemValueAdvanced(mod, index, arena, buffer),
2585 .slice => return val.castTag(.slice).?.data.ptr.elemValue(mod, index),
27842586
2785 .decl_ref => return mod.declPtr(val.castTag(.decl_ref).?.data).val.elemValueAdvanced(mod, index, arena, buffer),
2786 .decl_ref_mut => return mod.declPtr(val.castTag(.decl_ref_mut).?.data.decl_index).val.elemValueAdvanced(mod, index, arena, buffer),
2787 .comptime_field_ptr => return val.castTag(.comptime_field_ptr).?.data.field_val.elemValueAdvanced(mod, index, arena, buffer),
2587 .decl_ref => return mod.declPtr(val.castTag(.decl_ref).?.data).val.elemValue(mod, index),
2588 .decl_ref_mut => return mod.declPtr(val.castTag(.decl_ref_mut).?.data.decl_index).val.elemValue(mod, index),
2589 .comptime_field_ptr => return val.castTag(.comptime_field_ptr).?.data.field_val.elemValue(mod, index),
27882590 .elem_ptr => {
27892591 const data = val.castTag(.elem_ptr).?.data;
2790 return data.array_ptr.elemValueAdvanced(mod, index + data.index, arena, buffer);
2592 return data.array_ptr.elemValue(mod, index + data.index);
27912593 },
27922594 .field_ptr => {
27932595 const data = val.castTag(.field_ptr).?.data;
......@@ -2795,7 +2597,7 @@ pub const Value = struct {
27952597 const container_decl = mod.declPtr(decl_index);
27962598 const field_type = data.container_ty.structFieldType(data.field_index);
27972599 const field_val = container_decl.val.fieldValue(field_type, mod, data.field_index);
2798 return field_val.elemValueAdvanced(mod, index, arena, buffer);
2600 return field_val.elemValue(mod, index);
27992601 } else unreachable;
28002602 },
28012603
......@@ -2803,11 +2605,11 @@ pub const Value = struct {
28032605 // to have only one possible value itself.
28042606 .the_only_possible_value => return val,
28052607
2806 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
2807 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
2608 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValue(mod, index),
2609 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValue(mod, index),
28082610
2809 .opt_payload => return val.castTag(.opt_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
2810 .eu_payload => return val.castTag(.eu_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
2611 .opt_payload => return val.castTag(.opt_payload).?.data.elemValue(mod, index),
2612 .eu_payload => return val.castTag(.eu_payload).?.data.elemValue(mod, index),
28112613
28122614 else => unreachable,
28132615 },
......@@ -3004,7 +2806,7 @@ pub const Value = struct {
30042806 /// TODO: check for cases such as array that is not marked undef but all the element
30052807 /// values are marked undef, or struct that is not marked undef but all fields are marked
30062808 /// undef, etc.
3007 pub fn anyUndef(self: Value, mod: *Module) bool {
2809 pub fn anyUndef(self: Value, mod: *Module) !bool {
30082810 switch (self.ip_index) {
30092811 .undef => return true,
30102812 .none => switch (self.tag()) {
......@@ -3012,18 +2814,16 @@ pub const Value = struct {
30122814 const payload = self.castTag(.slice).?;
30132815 const len = payload.data.len.toUnsignedInt(mod);
30142816
3015 var elem_value_buf: ElemValueBuffer = undefined;
3016 var i: usize = 0;
3017 while (i < len) : (i += 1) {
3018 const elem_val = payload.data.ptr.elemValueBuffer(mod, i, &elem_value_buf);
3019 if (elem_val.anyUndef(mod)) return true;
2817 for (0..len) |i| {
2818 const elem_val = try payload.data.ptr.elemValue(mod, i);
2819 if (try elem_val.anyUndef(mod)) return true;
30202820 }
30212821 },
30222822
30232823 .aggregate => {
30242824 const payload = self.castTag(.aggregate).?;
30252825 for (payload.data) |val| {
3026 if (val.anyUndef(mod)) return true;
2826 if (try val.anyUndef(mod)) return true;
30272827 }
30282828 },
30292829 else => {},
......@@ -3036,35 +2836,37 @@ pub const Value = struct {
30362836
30372837 /// Asserts the value is not undefined and not unreachable.
30382838 /// Integer value 0 is considered null because of C pointers.
3039 pub fn isNull(self: Value, mod: *const Module) bool {
3040 return switch (self.ip_index) {
2839 pub fn isNull(val: Value, mod: *const Module) bool {
2840 return switch (val.ip_index) {
30412841 .undef => unreachable,
30422842 .unreachable_value => unreachable,
3043 .null_value => true,
3044 .none => switch (self.tag()) {
2843
2844 .null_value,
2845 .zero,
2846 .zero_usize,
2847 .zero_u8,
2848 => true,
2849
2850 .none => switch (val.tag()) {
30452851 .opt_payload => false,
30462852
30472853 // If it's not one of those two tags then it must be a C pointer value,
30482854 // in which case the value 0 is null and other values are non-null.
30492855
3050 .zero,
3051 .the_only_possible_value,
3052 => true,
3053
3054 .one => false,
3055
3056 .int_u64,
3057 .int_i64,
3058 .int_big_positive,
3059 .int_big_negative,
3060 => self.orderAgainstZero(mod).compare(.eq),
2856 .the_only_possible_value => true,
30612857
30622858 .inferred_alloc => unreachable,
30632859 .inferred_alloc_comptime => unreachable,
30642860
30652861 else => false,
30662862 },
3067 else => false,
2863 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
2864 .int => |int| switch (int.storage) {
2865 .big_int => |big_int| big_int.eqZero(),
2866 inline .u64, .i64 => |x| x == 0,
2867 },
2868 else => unreachable,
2869 },
30682870 };
30692871 }
30702872
......@@ -3078,17 +2880,13 @@ pub const Value = struct {
30782880 .unreachable_value => unreachable,
30792881 .none => switch (self.tag()) {
30802882 .@"error" => self.castTag(.@"error").?.data.name,
3081 .int_u64 => @panic("TODO"),
3082 .int_i64 => @panic("TODO"),
3083 .int_big_positive => @panic("TODO"),
3084 .int_big_negative => @panic("TODO"),
3085 .one => @panic("TODO"),
2883 .eu_payload => null,
2884
30862885 .inferred_alloc => unreachable,
30872886 .inferred_alloc_comptime => unreachable,
3088
3089 else => null,
2887 else => unreachable,
30902888 },
3091 else => null,
2889 else => unreachable,
30922890 };
30932891 }
30942892
......@@ -3147,10 +2945,10 @@ pub const Value = struct {
31472945 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
31482946 if (int_ty.zigTypeTag(mod) == .Vector) {
31492947 const result_data = try arena.alloc(Value, int_ty.vectorLen(mod));
2948 const scalar_ty = float_ty.scalarType(mod);
31502949 for (result_data, 0..) |*scalar, i| {
3151 var buf: Value.ElemValueBuffer = undefined;
3152 const elem_val = val.elemValueBuffer(mod, i, &buf);
3153 scalar.* = try intToFloatScalar(elem_val, arena, float_ty.scalarType(mod), mod, opt_sema);
2950 const elem_val = try val.elemValue(mod, i);
2951 scalar.* = try intToFloatScalar(elem_val, arena, scalar_ty, mod, opt_sema);
31542952 }
31552953 return Value.Tag.aggregate.create(arena, result_data);
31562954 }
......@@ -3162,24 +2960,7 @@ pub const Value = struct {
31622960 switch (val.ip_index) {
31632961 .undef => return val,
31642962 .none => switch (val.tag()) {
3165 .zero, .one => return val,
3166 .the_only_possible_value => return Value.initTag(.zero), // for i0, u0
3167 .int_u64 => {
3168 return intToFloatInner(val.castTag(.int_u64).?.data, arena, float_ty, target);
3169 },
3170 .int_i64 => {
3171 return intToFloatInner(val.castTag(.int_i64).?.data, arena, float_ty, target);
3172 },
3173 .int_big_positive => {
3174 const limbs = val.castTag(.int_big_positive).?.data;
3175 const float = bigIntToFloat(limbs, true);
3176 return floatToValue(float, arena, float_ty, target);
3177 },
3178 .int_big_negative => {
3179 const limbs = val.castTag(.int_big_negative).?.data;
3180 const float = bigIntToFloat(limbs, false);
3181 return floatToValue(float, arena, float_ty, target);
3182 },
2963 .the_only_possible_value => return Value.zero, // for i0, u0
31832964 .lazy_align => {
31842965 const ty = val.castTag(.lazy_align).?.data;
31852966 if (opt_sema) |sema| {
......@@ -3198,7 +2979,16 @@ pub const Value = struct {
31982979 },
31992980 else => unreachable,
32002981 },
3201 else => unreachable,
2982 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
2983 .int => |int| switch (int.storage) {
2984 .big_int => |big_int| {
2985 const float = bigIntToFloat(big_int.limbs, big_int.positive);
2986 return floatToValue(float, arena, float_ty, target);
2987 },
2988 inline .u64, .i64 => |x| intToFloatInner(x, arena, float_ty, target),
2989 },
2990 else => unreachable,
2991 },
32022992 }
32032993 }
32042994
......@@ -3238,22 +3028,6 @@ pub const Value = struct {
32383028 wrapped_result: Value,
32393029 };
32403030
3241 pub fn fromBigInt(arena: Allocator, big_int: BigIntConst) !Value {
3242 if (big_int.positive) {
3243 if (big_int.to(u64)) |x| {
3244 return Value.Tag.int_u64.create(arena, x);
3245 } else |_| {
3246 return Value.Tag.int_big_positive.create(arena, big_int.limbs);
3247 }
3248 } else {
3249 if (big_int.to(i64)) |x| {
3250 return Value.Tag.int_i64.create(arena, x);
3251 } else |_| {
3252 return Value.Tag.int_big_negative.create(arena, big_int.limbs);
3253 }
3254 }
3255 }
3256
32573031 /// Supports (vectors of) integers only; asserts neither operand is undefined.
32583032 pub fn intAddSat(
32593033 lhs: Value,
......@@ -3264,12 +3038,11 @@ pub const Value = struct {
32643038 ) !Value {
32653039 if (ty.zigTypeTag(mod) == .Vector) {
32663040 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
3041 const scalar_ty = ty.scalarType(mod);
32673042 for (result_data, 0..) |*scalar, i| {
3268 var lhs_buf: Value.ElemValueBuffer = undefined;
3269 var rhs_buf: Value.ElemValueBuffer = undefined;
3270 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3271 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3272 scalar.* = try intAddSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
3043 const lhs_elem = try lhs.elemValue(mod, i);
3044 const rhs_elem = try rhs.elemValue(mod, i);
3045 scalar.* = try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);
32733046 }
32743047 return Value.Tag.aggregate.create(arena, result_data);
32753048 }
......@@ -3299,7 +3072,7 @@ pub const Value = struct {
32993072 );
33003073 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
33013074 result_bigint.addSat(lhs_bigint, rhs_bigint, info.signedness, info.bits);
3302 return fromBigInt(arena, result_bigint.toConst());
3075 return mod.intValue_big(ty, result_bigint.toConst());
33033076 }
33043077
33053078 /// Supports (vectors of) integers only; asserts neither operand is undefined.
......@@ -3312,12 +3085,11 @@ pub const Value = struct {
33123085 ) !Value {
33133086 if (ty.zigTypeTag(mod) == .Vector) {
33143087 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
3088 const scalar_ty = ty.scalarType(mod);
33153089 for (result_data, 0..) |*scalar, i| {
3316 var lhs_buf: Value.ElemValueBuffer = undefined;
3317 var rhs_buf: Value.ElemValueBuffer = undefined;
3318 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3319 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3320 scalar.* = try intSubSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
3090 const lhs_elem = try lhs.elemValue(mod, i);
3091 const rhs_elem = try rhs.elemValue(mod, i);
3092 scalar.* = try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);
33213093 }
33223094 return Value.Tag.aggregate.create(arena, result_data);
33233095 }
......@@ -3347,7 +3119,7 @@ pub const Value = struct {
33473119 );
33483120 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
33493121 result_bigint.subSat(lhs_bigint, rhs_bigint, info.signedness, info.bits);
3350 return fromBigInt(arena, result_bigint.toConst());
3122 return mod.intValue_big(ty, result_bigint.toConst());
33513123 }
33523124
33533125 pub fn intMulWithOverflow(
......@@ -3360,12 +3132,11 @@ pub const Value = struct {
33603132 if (ty.zigTypeTag(mod) == .Vector) {
33613133 const overflowed_data = try arena.alloc(Value, ty.vectorLen(mod));
33623134 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
3135 const scalar_ty = ty.scalarType(mod);
33633136 for (result_data, 0..) |*scalar, i| {
3364 var lhs_buf: Value.ElemValueBuffer = undefined;
3365 var rhs_buf: Value.ElemValueBuffer = undefined;
3366 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3367 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3368 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
3137 const lhs_elem = try lhs.elemValue(mod, i);
3138 const rhs_elem = try rhs.elemValue(mod, i);
3139 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);
33693140 overflowed_data[i] = of_math_result.overflow_bit;
33703141 scalar.* = of_math_result.wrapped_result;
33713142 }
......@@ -3408,7 +3179,7 @@ pub const Value = struct {
34083179
34093180 return OverflowArithmeticResult{
34103181 .overflow_bit = boolToInt(overflowed),
3411 .wrapped_result = try fromBigInt(arena, result_bigint.toConst()),
3182 .wrapped_result = try mod.intValue_big(ty, result_bigint.toConst()),
34123183 };
34133184 }
34143185
......@@ -3423,10 +3194,8 @@ pub const Value = struct {
34233194 if (ty.zigTypeTag(mod) == .Vector) {
34243195 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
34253196 for (result_data, 0..) |*scalar, i| {
3426 var lhs_buf: Value.ElemValueBuffer = undefined;
3427 var rhs_buf: Value.ElemValueBuffer = undefined;
3428 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3429 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3197 const lhs_elem = try lhs.elemValue(mod, i);
3198 const rhs_elem = try rhs.elemValue(mod, i);
34303199 scalar.* = try numberMulWrapScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
34313200 }
34323201 return Value.Tag.aggregate.create(arena, result_data);
......@@ -3467,10 +3236,8 @@ pub const Value = struct {
34673236 if (ty.zigTypeTag(mod) == .Vector) {
34683237 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
34693238 for (result_data, 0..) |*scalar, i| {
3470 var lhs_buf: Value.ElemValueBuffer = undefined;
3471 var rhs_buf: Value.ElemValueBuffer = undefined;
3472 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3473 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3239 const lhs_elem = try lhs.elemValue(mod, i);
3240 const rhs_elem = try rhs.elemValue(mod, i);
34743241 scalar.* = try intMulSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
34753242 }
34763243 return Value.Tag.aggregate.create(arena, result_data);
......@@ -3510,7 +3277,7 @@ pub const Value = struct {
35103277 );
35113278 result_bigint.mul(lhs_bigint, rhs_bigint, limbs_buffer, arena);
35123279 result_bigint.saturate(result_bigint.toConst(), info.signedness, info.bits);
3513 return fromBigInt(arena, result_bigint.toConst());
3280 return mod.intValue_big(ty, result_bigint.toConst());
35143281 }
35153282
35163283 /// Supports both floats and ints; handles undefined.
......@@ -3542,8 +3309,7 @@ pub const Value = struct {
35423309 if (ty.zigTypeTag(mod) == .Vector) {
35433310 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
35443311 for (result_data, 0..) |*scalar, i| {
3545 var buf: Value.ElemValueBuffer = undefined;
3546 const elem_val = val.elemValueBuffer(mod, i, &buf);
3312 const elem_val = try val.elemValue(mod, i);
35473313 scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(mod), arena, mod);
35483314 }
35493315 return Value.Tag.aggregate.create(arena, result_data);
......@@ -3572,7 +3338,7 @@ pub const Value = struct {
35723338
35733339 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
35743340 result_bigint.bitNotWrap(val_bigint, info.signedness, info.bits);
3575 return fromBigInt(arena, result_bigint.toConst());
3341 return mod.intValue_big(ty, result_bigint.toConst());
35763342 }
35773343
35783344 /// operands must be (vectors of) integers; handles undefined scalars.
......@@ -3580,19 +3346,17 @@ pub const Value = struct {
35803346 if (ty.zigTypeTag(mod) == .Vector) {
35813347 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
35823348 for (result_data, 0..) |*scalar, i| {
3583 var lhs_buf: Value.ElemValueBuffer = undefined;
3584 var rhs_buf: Value.ElemValueBuffer = undefined;
3585 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3586 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3587 scalar.* = try bitwiseAndScalar(lhs_elem, rhs_elem, allocator, mod);
3349 const lhs_elem = try lhs.elemValue(mod, i);
3350 const rhs_elem = try rhs.elemValue(mod, i);
3351 scalar.* = try bitwiseAndScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);
35883352 }
35893353 return Value.Tag.aggregate.create(allocator, result_data);
35903354 }
3591 return bitwiseAndScalar(lhs, rhs, allocator, mod);
3355 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);
35923356 }
35933357
35943358 /// operands must be integers; handles undefined.
3595 pub fn bitwiseAndScalar(lhs: Value, rhs: Value, arena: Allocator, mod: *Module) !Value {
3359 pub fn bitwiseAndScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
35963360 if (lhs.isUndef() or rhs.isUndef()) return Value.undef;
35973361
35983362 // TODO is this a performance issue? maybe we should try the operation without
......@@ -3608,7 +3372,7 @@ pub const Value = struct {
36083372 );
36093373 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
36103374 result_bigint.bitAnd(lhs_bigint, rhs_bigint);
3611 return fromBigInt(arena, result_bigint.toConst());
3375 return mod.intValue_big(ty, result_bigint.toConst());
36123376 }
36133377
36143378 /// operands must be (vectors of) integers; handles undefined scalars.
......@@ -3616,10 +3380,8 @@ pub const Value = struct {
36163380 if (ty.zigTypeTag(mod) == .Vector) {
36173381 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
36183382 for (result_data, 0..) |*scalar, i| {
3619 var lhs_buf: Value.ElemValueBuffer = undefined;
3620 var rhs_buf: Value.ElemValueBuffer = undefined;
3621 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3622 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3383 const lhs_elem = try lhs.elemValue(mod, i);
3384 const rhs_elem = try rhs.elemValue(mod, i);
36233385 scalar.* = try bitwiseNandScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
36243386 }
36253387 return Value.Tag.aggregate.create(arena, result_data);
......@@ -3632,12 +3394,7 @@ pub const Value = struct {
36323394 if (lhs.isUndef() or rhs.isUndef()) return Value.undef;
36333395
36343396 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);
3635
3636 const all_ones = if (ty.isSignedInt(mod))
3637 try Value.Tag.int_i64.create(arena, -1)
3638 else
3639 try ty.maxInt(arena, mod);
3640
3397 const all_ones = if (ty.isSignedInt(mod)) Value.negative_one else try ty.maxIntScalar(mod);
36413398 return bitwiseXor(anded, all_ones, ty, arena, mod);
36423399 }
36433400
......@@ -3646,19 +3403,17 @@ pub const Value = struct {
36463403 if (ty.zigTypeTag(mod) == .Vector) {
36473404 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
36483405 for (result_data, 0..) |*scalar, i| {
3649 var lhs_buf: Value.ElemValueBuffer = undefined;
3650 var rhs_buf: Value.ElemValueBuffer = undefined;
3651 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3652 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3653 scalar.* = try bitwiseOrScalar(lhs_elem, rhs_elem, allocator, mod);
3406 const lhs_elem = try lhs.elemValue(mod, i);
3407 const rhs_elem = try rhs.elemValue(mod, i);
3408 scalar.* = try bitwiseOrScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);
36543409 }
36553410 return Value.Tag.aggregate.create(allocator, result_data);
36563411 }
3657 return bitwiseOrScalar(lhs, rhs, allocator, mod);
3412 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);
36583413 }
36593414
36603415 /// operands must be integers; handles undefined.
3661 pub fn bitwiseOrScalar(lhs: Value, rhs: Value, arena: Allocator, mod: *Module) !Value {
3416 pub fn bitwiseOrScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
36623417 if (lhs.isUndef() or rhs.isUndef()) return Value.undef;
36633418
36643419 // TODO is this a performance issue? maybe we should try the operation without
......@@ -3673,27 +3428,26 @@ pub const Value = struct {
36733428 );
36743429 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
36753430 result_bigint.bitOr(lhs_bigint, rhs_bigint);
3676 return fromBigInt(arena, result_bigint.toConst());
3431 return mod.intValue_big(ty, result_bigint.toConst());
36773432 }
36783433
36793434 /// operands must be (vectors of) integers; handles undefined scalars.
36803435 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
36813436 if (ty.zigTypeTag(mod) == .Vector) {
36823437 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3438 const scalar_ty = ty.scalarType(mod);
36833439 for (result_data, 0..) |*scalar, i| {
3684 var lhs_buf: Value.ElemValueBuffer = undefined;
3685 var rhs_buf: Value.ElemValueBuffer = undefined;
3686 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3687 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3688 scalar.* = try bitwiseXorScalar(lhs_elem, rhs_elem, allocator, mod);
3440 const lhs_elem = try lhs.elemValue(mod, i);
3441 const rhs_elem = try rhs.elemValue(mod, i);
3442 scalar.* = try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
36893443 }
36903444 return Value.Tag.aggregate.create(allocator, result_data);
36913445 }
3692 return bitwiseXorScalar(lhs, rhs, allocator, mod);
3446 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);
36933447 }
36943448
36953449 /// operands must be integers; handles undefined.
3696 pub fn bitwiseXorScalar(lhs: Value, rhs: Value, arena: Allocator, mod: *Module) !Value {
3450 pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
36973451 if (lhs.isUndef() or rhs.isUndef()) return Value.undef;
36983452
36993453 // TODO is this a performance issue? maybe we should try the operation without
......@@ -3709,25 +3463,24 @@ pub const Value = struct {
37093463 );
37103464 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
37113465 result_bigint.bitXor(lhs_bigint, rhs_bigint);
3712 return fromBigInt(arena, result_bigint.toConst());
3466 return mod.intValue_big(ty, result_bigint.toConst());
37133467 }
37143468
37153469 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37163470 if (ty.zigTypeTag(mod) == .Vector) {
37173471 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3472 const scalar_ty = ty.scalarType(mod);
37183473 for (result_data, 0..) |*scalar, i| {
3719 var lhs_buf: Value.ElemValueBuffer = undefined;
3720 var rhs_buf: Value.ElemValueBuffer = undefined;
3721 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3722 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3723 scalar.* = try intDivScalar(lhs_elem, rhs_elem, allocator, mod);
3474 const lhs_elem = try lhs.elemValue(mod, i);
3475 const rhs_elem = try rhs.elemValue(mod, i);
3476 scalar.* = try intDivScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
37243477 }
37253478 return Value.Tag.aggregate.create(allocator, result_data);
37263479 }
3727 return intDivScalar(lhs, rhs, allocator, mod);
3480 return intDivScalar(lhs, rhs, ty, allocator, mod);
37283481 }
37293482
3730 pub fn intDivScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3483 pub fn intDivScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37313484 // TODO is this a performance issue? maybe we should try the operation without
37323485 // resorting to BigInt first.
37333486 var lhs_space: Value.BigIntSpace = undefined;
......@@ -3749,25 +3502,24 @@ pub const Value = struct {
37493502 var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
37503503 var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
37513504 result_q.divTrunc(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
3752 return fromBigInt(allocator, result_q.toConst());
3505 return mod.intValue_big(ty, result_q.toConst());
37533506 }
37543507
37553508 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37563509 if (ty.zigTypeTag(mod) == .Vector) {
37573510 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3511 const scalar_ty = ty.scalarType(mod);
37583512 for (result_data, 0..) |*scalar, i| {
3759 var lhs_buf: Value.ElemValueBuffer = undefined;
3760 var rhs_buf: Value.ElemValueBuffer = undefined;
3761 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3762 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3763 scalar.* = try intDivFloorScalar(lhs_elem, rhs_elem, allocator, mod);
3513 const lhs_elem = try lhs.elemValue(mod, i);
3514 const rhs_elem = try rhs.elemValue(mod, i);
3515 scalar.* = try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
37643516 }
37653517 return Value.Tag.aggregate.create(allocator, result_data);
37663518 }
3767 return intDivFloorScalar(lhs, rhs, allocator, mod);
3519 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);
37683520 }
37693521
3770 pub fn intDivFloorScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3522 pub fn intDivFloorScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37713523 // TODO is this a performance issue? maybe we should try the operation without
37723524 // resorting to BigInt first.
37733525 var lhs_space: Value.BigIntSpace = undefined;
......@@ -3789,25 +3541,24 @@ pub const Value = struct {
37893541 var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
37903542 var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
37913543 result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
3792 return fromBigInt(allocator, result_q.toConst());
3544 return mod.intValue_big(ty, result_q.toConst());
37933545 }
37943546
37953547 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37963548 if (ty.zigTypeTag(mod) == .Vector) {
37973549 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3550 const scalar_ty = ty.scalarType(mod);
37983551 for (result_data, 0..) |*scalar, i| {
3799 var lhs_buf: Value.ElemValueBuffer = undefined;
3800 var rhs_buf: Value.ElemValueBuffer = undefined;
3801 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3802 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3803 scalar.* = try intModScalar(lhs_elem, rhs_elem, allocator, mod);
3552 const lhs_elem = try lhs.elemValue(mod, i);
3553 const rhs_elem = try rhs.elemValue(mod, i);
3554 scalar.* = try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
38043555 }
38053556 return Value.Tag.aggregate.create(allocator, result_data);
38063557 }
3807 return intModScalar(lhs, rhs, allocator, mod);
3558 return intModScalar(lhs, rhs, ty, allocator, mod);
38083559 }
38093560
3810 pub fn intModScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3561 pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
38113562 // TODO is this a performance issue? maybe we should try the operation without
38123563 // resorting to BigInt first.
38133564 var lhs_space: Value.BigIntSpace = undefined;
......@@ -3829,7 +3580,7 @@ pub const Value = struct {
38293580 var result_q = BigIntMutable{ .limbs = limbs_q, .positive = undefined, .len = undefined };
38303581 var result_r = BigIntMutable{ .limbs = limbs_r, .positive = undefined, .len = undefined };
38313582 result_q.divFloor(&result_r, lhs_bigint, rhs_bigint, limbs_buffer);
3832 return fromBigInt(allocator, result_r.toConst());
3583 return mod.intValue_big(ty, result_r.toConst());
38333584 }
38343585
38353586 /// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
......@@ -3877,46 +3628,44 @@ pub const Value = struct {
38773628 }
38783629
38793630 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3880 const target = mod.getTarget();
38813631 if (float_type.zigTypeTag(mod) == .Vector) {
38823632 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
38833633 for (result_data, 0..) |*scalar, i| {
3884 var lhs_buf: Value.ElemValueBuffer = undefined;
3885 var rhs_buf: Value.ElemValueBuffer = undefined;
3886 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3887 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3888 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
3634 const lhs_elem = try lhs.elemValue(mod, i);
3635 const rhs_elem = try rhs.elemValue(mod, i);
3636 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
38893637 }
38903638 return Value.Tag.aggregate.create(arena, result_data);
38913639 }
3892 return floatRemScalar(lhs, rhs, float_type, arena, target);
3640 return floatRemScalar(lhs, rhs, float_type, arena, mod);
38933641 }
38943642
3895 pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {
3643 pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *const Module) !Value {
3644 const target = mod.getTarget();
38963645 switch (float_type.floatBits(target)) {
38973646 16 => {
3898 const lhs_val = lhs.toFloat(f16);
3899 const rhs_val = rhs.toFloat(f16);
3647 const lhs_val = lhs.toFloat(f16, mod);
3648 const rhs_val = rhs.toFloat(f16, mod);
39003649 return Value.Tag.float_16.create(arena, @rem(lhs_val, rhs_val));
39013650 },
39023651 32 => {
3903 const lhs_val = lhs.toFloat(f32);
3904 const rhs_val = rhs.toFloat(f32);
3652 const lhs_val = lhs.toFloat(f32, mod);
3653 const rhs_val = rhs.toFloat(f32, mod);
39053654 return Value.Tag.float_32.create(arena, @rem(lhs_val, rhs_val));
39063655 },
39073656 64 => {
3908 const lhs_val = lhs.toFloat(f64);
3909 const rhs_val = rhs.toFloat(f64);
3657 const lhs_val = lhs.toFloat(f64, mod);
3658 const rhs_val = rhs.toFloat(f64, mod);
39103659 return Value.Tag.float_64.create(arena, @rem(lhs_val, rhs_val));
39113660 },
39123661 80 => {
3913 const lhs_val = lhs.toFloat(f80);
3914 const rhs_val = rhs.toFloat(f80);
3662 const lhs_val = lhs.toFloat(f80, mod);
3663 const rhs_val = rhs.toFloat(f80, mod);
39153664 return Value.Tag.float_80.create(arena, @rem(lhs_val, rhs_val));
39163665 },
39173666 128 => {
3918 const lhs_val = lhs.toFloat(f128);
3919 const rhs_val = rhs.toFloat(f128);
3667 const lhs_val = lhs.toFloat(f128, mod);
3668 const rhs_val = rhs.toFloat(f128, mod);
39203669 return Value.Tag.float_128.create(arena, @rem(lhs_val, rhs_val));
39213670 },
39223671 else => unreachable,
......@@ -3924,46 +3673,44 @@ pub const Value = struct {
39243673 }
39253674
39263675 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3927 const target = mod.getTarget();
39283676 if (float_type.zigTypeTag(mod) == .Vector) {
39293677 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
39303678 for (result_data, 0..) |*scalar, i| {
3931 var lhs_buf: Value.ElemValueBuffer = undefined;
3932 var rhs_buf: Value.ElemValueBuffer = undefined;
3933 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3934 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3935 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
3679 const lhs_elem = try lhs.elemValue(mod, i);
3680 const rhs_elem = try rhs.elemValue(mod, i);
3681 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
39363682 }
39373683 return Value.Tag.aggregate.create(arena, result_data);
39383684 }
3939 return floatModScalar(lhs, rhs, float_type, arena, target);
3685 return floatModScalar(lhs, rhs, float_type, arena, mod);
39403686 }
39413687
3942 pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {
3688 pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *const Module) !Value {
3689 const target = mod.getTarget();
39433690 switch (float_type.floatBits(target)) {
39443691 16 => {
3945 const lhs_val = lhs.toFloat(f16);
3946 const rhs_val = rhs.toFloat(f16);
3692 const lhs_val = lhs.toFloat(f16, mod);
3693 const rhs_val = rhs.toFloat(f16, mod);
39473694 return Value.Tag.float_16.create(arena, @mod(lhs_val, rhs_val));
39483695 },
39493696 32 => {
3950 const lhs_val = lhs.toFloat(f32);
3951 const rhs_val = rhs.toFloat(f32);
3697 const lhs_val = lhs.toFloat(f32, mod);
3698 const rhs_val = rhs.toFloat(f32, mod);
39523699 return Value.Tag.float_32.create(arena, @mod(lhs_val, rhs_val));
39533700 },
39543701 64 => {
3955 const lhs_val = lhs.toFloat(f64);
3956 const rhs_val = rhs.toFloat(f64);
3702 const lhs_val = lhs.toFloat(f64, mod);
3703 const rhs_val = rhs.toFloat(f64, mod);
39573704 return Value.Tag.float_64.create(arena, @mod(lhs_val, rhs_val));
39583705 },
39593706 80 => {
3960 const lhs_val = lhs.toFloat(f80);
3961 const rhs_val = rhs.toFloat(f80);
3707 const lhs_val = lhs.toFloat(f80, mod);
3708 const rhs_val = rhs.toFloat(f80, mod);
39623709 return Value.Tag.float_80.create(arena, @mod(lhs_val, rhs_val));
39633710 },
39643711 128 => {
3965 const lhs_val = lhs.toFloat(f128);
3966 const rhs_val = rhs.toFloat(f128);
3712 const lhs_val = lhs.toFloat(f128, mod);
3713 const rhs_val = rhs.toFloat(f128, mod);
39673714 return Value.Tag.float_128.create(arena, @mod(lhs_val, rhs_val));
39683715 },
39693716 else => unreachable,
......@@ -3973,19 +3720,18 @@ pub const Value = struct {
39733720 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
39743721 if (ty.zigTypeTag(mod) == .Vector) {
39753722 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3723 const scalar_ty = ty.scalarType(mod);
39763724 for (result_data, 0..) |*scalar, i| {
3977 var lhs_buf: Value.ElemValueBuffer = undefined;
3978 var rhs_buf: Value.ElemValueBuffer = undefined;
3979 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3980 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3981 scalar.* = try intMulScalar(lhs_elem, rhs_elem, allocator, mod);
3725 const lhs_elem = try lhs.elemValue(mod, i);
3726 const rhs_elem = try rhs.elemValue(mod, i);
3727 scalar.* = try intMulScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
39823728 }
39833729 return Value.Tag.aggregate.create(allocator, result_data);
39843730 }
3985 return intMulScalar(lhs, rhs, allocator, mod);
3731 return intMulScalar(lhs, rhs, ty, allocator, mod);
39863732 }
39873733
3988 pub fn intMulScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3734 pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
39893735 // TODO is this a performance issue? maybe we should try the operation without
39903736 // resorting to BigInt first.
39913737 var lhs_space: Value.BigIntSpace = undefined;
......@@ -4003,20 +3749,20 @@ pub const Value = struct {
40033749 );
40043750 defer allocator.free(limbs_buffer);
40053751 result_bigint.mul(lhs_bigint, rhs_bigint, limbs_buffer, allocator);
4006 return fromBigInt(allocator, result_bigint.toConst());
3752 return mod.intValue_big(ty, result_bigint.toConst());
40073753 }
40083754
40093755 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
40103756 if (ty.zigTypeTag(mod) == .Vector) {
40113757 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3758 const scalar_ty = ty.scalarType(mod);
40123759 for (result_data, 0..) |*scalar, i| {
4013 var buf: Value.ElemValueBuffer = undefined;
4014 const elem_val = val.elemValueBuffer(mod, i, &buf);
4015 scalar.* = try intTruncScalar(elem_val, allocator, signedness, bits, mod);
3760 const elem_val = try val.elemValue(mod, i);
3761 scalar.* = try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod);
40163762 }
40173763 return Value.Tag.aggregate.create(allocator, result_data);
40183764 }
4019 return intTruncScalar(val, allocator, signedness, bits, mod);
3765 return intTruncScalar(val, ty, allocator, signedness, bits, mod);
40203766 }
40213767
40223768 /// This variant may vectorize on `bits`. Asserts that `bits` is a (vector of) `u16`.
......@@ -4030,19 +3776,25 @@ pub const Value = struct {
40303776 ) !Value {
40313777 if (ty.zigTypeTag(mod) == .Vector) {
40323778 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3779 const scalar_ty = ty.scalarType(mod);
40333780 for (result_data, 0..) |*scalar, i| {
4034 var buf: Value.ElemValueBuffer = undefined;
4035 const elem_val = val.elemValueBuffer(mod, i, &buf);
4036 var bits_buf: Value.ElemValueBuffer = undefined;
4037 const bits_elem = bits.elemValueBuffer(mod, i, &bits_buf);
4038 scalar.* = try intTruncScalar(elem_val, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(mod)), mod);
3781 const elem_val = try val.elemValue(mod, i);
3782 const bits_elem = try bits.elemValue(mod, i);
3783 scalar.* = try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(mod)), mod);
40393784 }
40403785 return Value.Tag.aggregate.create(allocator, result_data);
40413786 }
4042 return intTruncScalar(val, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);
3787 return intTruncScalar(val, ty, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);
40433788 }
40443789
4045 pub fn intTruncScalar(val: Value, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
3790 pub fn intTruncScalar(
3791 val: Value,
3792 ty: Type,
3793 allocator: Allocator,
3794 signedness: std.builtin.Signedness,
3795 bits: u16,
3796 mod: *Module,
3797 ) !Value {
40463798 if (bits == 0) return Value.zero;
40473799
40483800 var val_space: Value.BigIntSpace = undefined;
......@@ -4055,25 +3807,24 @@ pub const Value = struct {
40553807 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
40563808
40573809 result_bigint.truncate(val_bigint, signedness, bits);
4058 return fromBigInt(allocator, result_bigint.toConst());
3810 return mod.intValue_big(ty, result_bigint.toConst());
40593811 }
40603812
40613813 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
40623814 if (ty.zigTypeTag(mod) == .Vector) {
40633815 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3816 const scalar_ty = ty.scalarType(mod);
40643817 for (result_data, 0..) |*scalar, i| {
4065 var lhs_buf: Value.ElemValueBuffer = undefined;
4066 var rhs_buf: Value.ElemValueBuffer = undefined;
4067 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4068 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4069 scalar.* = try shlScalar(lhs_elem, rhs_elem, allocator, mod);
3818 const lhs_elem = try lhs.elemValue(mod, i);
3819 const rhs_elem = try rhs.elemValue(mod, i);
3820 scalar.* = try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
40703821 }
40713822 return Value.Tag.aggregate.create(allocator, result_data);
40723823 }
4073 return shlScalar(lhs, rhs, allocator, mod);
3824 return shlScalar(lhs, rhs, ty, allocator, mod);
40743825 }
40753826
4076 pub fn shlScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3827 pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
40773828 // TODO is this a performance issue? maybe we should try the operation without
40783829 // resorting to BigInt first.
40793830 var lhs_space: Value.BigIntSpace = undefined;
......@@ -4089,7 +3840,7 @@ pub const Value = struct {
40893840 .len = undefined,
40903841 };
40913842 result_bigint.shiftLeft(lhs_bigint, shift);
4092 return fromBigInt(allocator, result_bigint.toConst());
3843 return mod.intValue_big(ty, result_bigint.toConst());
40933844 }
40943845
40953846 pub fn shlWithOverflow(
......@@ -4103,10 +3854,8 @@ pub const Value = struct {
41033854 const overflowed_data = try allocator.alloc(Value, ty.vectorLen(mod));
41043855 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
41053856 for (result_data, 0..) |*scalar, i| {
4106 var lhs_buf: Value.ElemValueBuffer = undefined;
4107 var rhs_buf: Value.ElemValueBuffer = undefined;
4108 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4109 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3857 const lhs_elem = try lhs.elemValue(mod, i);
3858 const rhs_elem = try rhs.elemValue(mod, i);
41103859 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);
41113860 overflowed_data[i] = of_math_result.overflow_bit;
41123861 scalar.* = of_math_result.wrapped_result;
......@@ -4146,7 +3895,7 @@ pub const Value = struct {
41463895 }
41473896 return OverflowArithmeticResult{
41483897 .overflow_bit = boolToInt(overflowed),
4149 .wrapped_result = try fromBigInt(allocator, result_bigint.toConst()),
3898 .wrapped_result = try mod.intValue_big(ty, result_bigint.toConst()),
41503899 };
41513900 }
41523901
......@@ -4160,10 +3909,8 @@ pub const Value = struct {
41603909 if (ty.zigTypeTag(mod) == .Vector) {
41613910 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
41623911 for (result_data, 0..) |*scalar, i| {
4163 var lhs_buf: Value.ElemValueBuffer = undefined;
4164 var rhs_buf: Value.ElemValueBuffer = undefined;
4165 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4166 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3912 const lhs_elem = try lhs.elemValue(mod, i);
3913 const rhs_elem = try rhs.elemValue(mod, i);
41673914 scalar.* = try shlSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
41683915 }
41693916 return Value.Tag.aggregate.create(arena, result_data);
......@@ -4195,7 +3942,7 @@ pub const Value = struct {
41953942 .len = undefined,
41963943 };
41973944 result_bigint.shiftLeftSat(lhs_bigint, shift, info.signedness, info.bits);
4198 return fromBigInt(arena, result_bigint.toConst());
3945 return mod.intValue_big(ty, result_bigint.toConst());
41993946 }
42003947
42013948 pub fn shlTrunc(
......@@ -4208,10 +3955,8 @@ pub const Value = struct {
42083955 if (ty.zigTypeTag(mod) == .Vector) {
42093956 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
42103957 for (result_data, 0..) |*scalar, i| {
4211 var lhs_buf: Value.ElemValueBuffer = undefined;
4212 var rhs_buf: Value.ElemValueBuffer = undefined;
4213 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4214 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3958 const lhs_elem = try lhs.elemValue(mod, i);
3959 const rhs_elem = try rhs.elemValue(mod, i);
42153960 scalar.* = try shlTruncScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);
42163961 }
42173962 return Value.Tag.aggregate.create(arena, result_data);
......@@ -4235,19 +3980,18 @@ pub const Value = struct {
42353980 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
42363981 if (ty.zigTypeTag(mod) == .Vector) {
42373982 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3983 const scalar_ty = ty.scalarType(mod);
42383984 for (result_data, 0..) |*scalar, i| {
4239 var lhs_buf: Value.ElemValueBuffer = undefined;
4240 var rhs_buf: Value.ElemValueBuffer = undefined;
4241 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4242 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4243 scalar.* = try shrScalar(lhs_elem, rhs_elem, allocator, mod);
3985 const lhs_elem = try lhs.elemValue(mod, i);
3986 const rhs_elem = try rhs.elemValue(mod, i);
3987 scalar.* = try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
42443988 }
42453989 return Value.Tag.aggregate.create(allocator, result_data);
42463990 }
4247 return shrScalar(lhs, rhs, allocator, mod);
3991 return shrScalar(lhs, rhs, ty, allocator, mod);
42483992 }
42493993
4250 pub fn shrScalar(lhs: Value, rhs: Value, allocator: Allocator, mod: *Module) !Value {
3994 pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
42513995 // TODO is this a performance issue? maybe we should try the operation without
42523996 // resorting to BigInt first.
42533997 var lhs_space: Value.BigIntSpace = undefined;
......@@ -4275,7 +4019,7 @@ pub const Value = struct {
42754019 .len = undefined,
42764020 };
42774021 result_bigint.shiftRight(lhs_bigint, shift);
4278 return fromBigInt(allocator, result_bigint.toConst());
4022 return mod.intValue_big(ty, result_bigint.toConst());
42794023 }
42804024
42814025 pub fn floatNeg(
......@@ -4284,31 +4028,30 @@ pub const Value = struct {
42844028 arena: Allocator,
42854029 mod: *Module,
42864030 ) !Value {
4287 const target = mod.getTarget();
42884031 if (float_type.zigTypeTag(mod) == .Vector) {
42894032 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
42904033 for (result_data, 0..) |*scalar, i| {
4291 var buf: Value.ElemValueBuffer = undefined;
4292 const elem_val = val.elemValueBuffer(mod, i, &buf);
4293 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(mod), arena, target);
4034 const elem_val = try val.elemValue(mod, i);
4035 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(mod), arena, mod);
42944036 }
42954037 return Value.Tag.aggregate.create(arena, result_data);
42964038 }
4297 return floatNegScalar(val, float_type, arena, target);
4039 return floatNegScalar(val, float_type, arena, mod);
42984040 }
42994041
43004042 pub fn floatNegScalar(
43014043 val: Value,
43024044 float_type: Type,
43034045 arena: Allocator,
4304 target: Target,
4046 mod: *const Module,
43054047 ) !Value {
4048 const target = mod.getTarget();
43064049 switch (float_type.floatBits(target)) {
4307 16 => return Value.Tag.float_16.create(arena, -val.toFloat(f16)),
4308 32 => return Value.Tag.float_32.create(arena, -val.toFloat(f32)),
4309 64 => return Value.Tag.float_64.create(arena, -val.toFloat(f64)),
4310 80 => return Value.Tag.float_80.create(arena, -val.toFloat(f80)),
4311 128 => return Value.Tag.float_128.create(arena, -val.toFloat(f128)),
4050 16 => return Value.Tag.float_16.create(arena, -val.toFloat(f16, mod)),
4051 32 => return Value.Tag.float_32.create(arena, -val.toFloat(f32, mod)),
4052 64 => return Value.Tag.float_64.create(arena, -val.toFloat(f64, mod)),
4053 80 => return Value.Tag.float_80.create(arena, -val.toFloat(f80, mod)),
4054 128 => return Value.Tag.float_128.create(arena, -val.toFloat(f128, mod)),
43124055 else => unreachable,
43134056 }
43144057 }
......@@ -4320,19 +4063,16 @@ pub const Value = struct {
43204063 arena: Allocator,
43214064 mod: *Module,
43224065 ) !Value {
4323 const target = mod.getTarget();
43244066 if (float_type.zigTypeTag(mod) == .Vector) {
43254067 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43264068 for (result_data, 0..) |*scalar, i| {
4327 var lhs_buf: Value.ElemValueBuffer = undefined;
4328 var rhs_buf: Value.ElemValueBuffer = undefined;
4329 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4330 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4331 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
4069 const lhs_elem = try lhs.elemValue(mod, i);
4070 const rhs_elem = try rhs.elemValue(mod, i);
4071 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
43324072 }
43334073 return Value.Tag.aggregate.create(arena, result_data);
43344074 }
4335 return floatDivScalar(lhs, rhs, float_type, arena, target);
4075 return floatDivScalar(lhs, rhs, float_type, arena, mod);
43364076 }
43374077
43384078 pub fn floatDivScalar(
......@@ -4340,32 +4080,33 @@ pub const Value = struct {
43404080 rhs: Value,
43414081 float_type: Type,
43424082 arena: Allocator,
4343 target: Target,
4083 mod: *const Module,
43444084 ) !Value {
4085 const target = mod.getTarget();
43454086 switch (float_type.floatBits(target)) {
43464087 16 => {
4347 const lhs_val = lhs.toFloat(f16);
4348 const rhs_val = rhs.toFloat(f16);
4088 const lhs_val = lhs.toFloat(f16, mod);
4089 const rhs_val = rhs.toFloat(f16, mod);
43494090 return Value.Tag.float_16.create(arena, lhs_val / rhs_val);
43504091 },
43514092 32 => {
4352 const lhs_val = lhs.toFloat(f32);
4353 const rhs_val = rhs.toFloat(f32);
4093 const lhs_val = lhs.toFloat(f32, mod);
4094 const rhs_val = rhs.toFloat(f32, mod);
43544095 return Value.Tag.float_32.create(arena, lhs_val / rhs_val);
43554096 },
43564097 64 => {
4357 const lhs_val = lhs.toFloat(f64);
4358 const rhs_val = rhs.toFloat(f64);
4098 const lhs_val = lhs.toFloat(f64, mod);
4099 const rhs_val = rhs.toFloat(f64, mod);
43594100 return Value.Tag.float_64.create(arena, lhs_val / rhs_val);
43604101 },
43614102 80 => {
4362 const lhs_val = lhs.toFloat(f80);
4363 const rhs_val = rhs.toFloat(f80);
4103 const lhs_val = lhs.toFloat(f80, mod);
4104 const rhs_val = rhs.toFloat(f80, mod);
43644105 return Value.Tag.float_80.create(arena, lhs_val / rhs_val);
43654106 },
43664107 128 => {
4367 const lhs_val = lhs.toFloat(f128);
4368 const rhs_val = rhs.toFloat(f128);
4108 const lhs_val = lhs.toFloat(f128, mod);
4109 const rhs_val = rhs.toFloat(f128, mod);
43694110 return Value.Tag.float_128.create(arena, lhs_val / rhs_val);
43704111 },
43714112 else => unreachable,
......@@ -4379,19 +4120,16 @@ pub const Value = struct {
43794120 arena: Allocator,
43804121 mod: *Module,
43814122 ) !Value {
4382 const target = mod.getTarget();
43834123 if (float_type.zigTypeTag(mod) == .Vector) {
43844124 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43854125 for (result_data, 0..) |*scalar, i| {
4386 var lhs_buf: Value.ElemValueBuffer = undefined;
4387 var rhs_buf: Value.ElemValueBuffer = undefined;
4388 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4389 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4390 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
4126 const lhs_elem = try lhs.elemValue(mod, i);
4127 const rhs_elem = try rhs.elemValue(mod, i);
4128 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
43914129 }
43924130 return Value.Tag.aggregate.create(arena, result_data);
43934131 }
4394 return floatDivFloorScalar(lhs, rhs, float_type, arena, target);
4132 return floatDivFloorScalar(lhs, rhs, float_type, arena, mod);
43954133 }
43964134
43974135 pub fn floatDivFloorScalar(
......@@ -4399,32 +4137,33 @@ pub const Value = struct {
43994137 rhs: Value,
44004138 float_type: Type,
44014139 arena: Allocator,
4402 target: Target,
4140 mod: *const Module,
44034141 ) !Value {
4142 const target = mod.getTarget();
44044143 switch (float_type.floatBits(target)) {
44054144 16 => {
4406 const lhs_val = lhs.toFloat(f16);
4407 const rhs_val = rhs.toFloat(f16);
4145 const lhs_val = lhs.toFloat(f16, mod);
4146 const rhs_val = rhs.toFloat(f16, mod);
44084147 return Value.Tag.float_16.create(arena, @divFloor(lhs_val, rhs_val));
44094148 },
44104149 32 => {
4411 const lhs_val = lhs.toFloat(f32);
4412 const rhs_val = rhs.toFloat(f32);
4150 const lhs_val = lhs.toFloat(f32, mod);
4151 const rhs_val = rhs.toFloat(f32, mod);
44134152 return Value.Tag.float_32.create(arena, @divFloor(lhs_val, rhs_val));
44144153 },
44154154 64 => {
4416 const lhs_val = lhs.toFloat(f64);
4417 const rhs_val = rhs.toFloat(f64);
4155 const lhs_val = lhs.toFloat(f64, mod);
4156 const rhs_val = rhs.toFloat(f64, mod);
44184157 return Value.Tag.float_64.create(arena, @divFloor(lhs_val, rhs_val));
44194158 },
44204159 80 => {
4421 const lhs_val = lhs.toFloat(f80);
4422 const rhs_val = rhs.toFloat(f80);
4160 const lhs_val = lhs.toFloat(f80, mod);
4161 const rhs_val = rhs.toFloat(f80, mod);
44234162 return Value.Tag.float_80.create(arena, @divFloor(lhs_val, rhs_val));
44244163 },
44254164 128 => {
4426 const lhs_val = lhs.toFloat(f128);
4427 const rhs_val = rhs.toFloat(f128);
4165 const lhs_val = lhs.toFloat(f128, mod);
4166 const rhs_val = rhs.toFloat(f128, mod);
44284167 return Value.Tag.float_128.create(arena, @divFloor(lhs_val, rhs_val));
44294168 },
44304169 else => unreachable,
......@@ -4438,19 +4177,16 @@ pub const Value = struct {
44384177 arena: Allocator,
44394178 mod: *Module,
44404179 ) !Value {
4441 const target = mod.getTarget();
44424180 if (float_type.zigTypeTag(mod) == .Vector) {
44434181 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44444182 for (result_data, 0..) |*scalar, i| {
4445 var lhs_buf: Value.ElemValueBuffer = undefined;
4446 var rhs_buf: Value.ElemValueBuffer = undefined;
4447 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4448 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4449 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
4183 const lhs_elem = try lhs.elemValue(mod, i);
4184 const rhs_elem = try rhs.elemValue(mod, i);
4185 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
44504186 }
44514187 return Value.Tag.aggregate.create(arena, result_data);
44524188 }
4453 return floatDivTruncScalar(lhs, rhs, float_type, arena, target);
4189 return floatDivTruncScalar(lhs, rhs, float_type, arena, mod);
44544190 }
44554191
44564192 pub fn floatDivTruncScalar(
......@@ -4458,32 +4194,33 @@ pub const Value = struct {
44584194 rhs: Value,
44594195 float_type: Type,
44604196 arena: Allocator,
4461 target: Target,
4197 mod: *const Module,
44624198 ) !Value {
4199 const target = mod.getTarget();
44634200 switch (float_type.floatBits(target)) {
44644201 16 => {
4465 const lhs_val = lhs.toFloat(f16);
4466 const rhs_val = rhs.toFloat(f16);
4202 const lhs_val = lhs.toFloat(f16, mod);
4203 const rhs_val = rhs.toFloat(f16, mod);
44674204 return Value.Tag.float_16.create(arena, @divTrunc(lhs_val, rhs_val));
44684205 },
44694206 32 => {
4470 const lhs_val = lhs.toFloat(f32);
4471 const rhs_val = rhs.toFloat(f32);
4207 const lhs_val = lhs.toFloat(f32, mod);
4208 const rhs_val = rhs.toFloat(f32, mod);
44724209 return Value.Tag.float_32.create(arena, @divTrunc(lhs_val, rhs_val));
44734210 },
44744211 64 => {
4475 const lhs_val = lhs.toFloat(f64);
4476 const rhs_val = rhs.toFloat(f64);
4212 const lhs_val = lhs.toFloat(f64, mod);
4213 const rhs_val = rhs.toFloat(f64, mod);
44774214 return Value.Tag.float_64.create(arena, @divTrunc(lhs_val, rhs_val));
44784215 },
44794216 80 => {
4480 const lhs_val = lhs.toFloat(f80);
4481 const rhs_val = rhs.toFloat(f80);
4217 const lhs_val = lhs.toFloat(f80, mod);
4218 const rhs_val = rhs.toFloat(f80, mod);
44824219 return Value.Tag.float_80.create(arena, @divTrunc(lhs_val, rhs_val));
44834220 },
44844221 128 => {
4485 const lhs_val = lhs.toFloat(f128);
4486 const rhs_val = rhs.toFloat(f128);
4222 const lhs_val = lhs.toFloat(f128, mod);
4223 const rhs_val = rhs.toFloat(f128, mod);
44874224 return Value.Tag.float_128.create(arena, @divTrunc(lhs_val, rhs_val));
44884225 },
44894226 else => unreachable,
......@@ -4497,19 +4234,16 @@ pub const Value = struct {
44974234 arena: Allocator,
44984235 mod: *Module,
44994236 ) !Value {
4500 const target = mod.getTarget();
45014237 if (float_type.zigTypeTag(mod) == .Vector) {
45024238 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45034239 for (result_data, 0..) |*scalar, i| {
4504 var lhs_buf: Value.ElemValueBuffer = undefined;
4505 var rhs_buf: Value.ElemValueBuffer = undefined;
4506 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4507 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4508 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, target);
4240 const lhs_elem = try lhs.elemValue(mod, i);
4241 const rhs_elem = try rhs.elemValue(mod, i);
4242 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
45094243 }
45104244 return Value.Tag.aggregate.create(arena, result_data);
45114245 }
4512 return floatMulScalar(lhs, rhs, float_type, arena, target);
4246 return floatMulScalar(lhs, rhs, float_type, arena, mod);
45134247 }
45144248
45154249 pub fn floatMulScalar(
......@@ -4517,32 +4251,33 @@ pub const Value = struct {
45174251 rhs: Value,
45184252 float_type: Type,
45194253 arena: Allocator,
4520 target: Target,
4254 mod: *const Module,
45214255 ) !Value {
4256 const target = mod.getTarget();
45224257 switch (float_type.floatBits(target)) {
45234258 16 => {
4524 const lhs_val = lhs.toFloat(f16);
4525 const rhs_val = rhs.toFloat(f16);
4259 const lhs_val = lhs.toFloat(f16, mod);
4260 const rhs_val = rhs.toFloat(f16, mod);
45264261 return Value.Tag.float_16.create(arena, lhs_val * rhs_val);
45274262 },
45284263 32 => {
4529 const lhs_val = lhs.toFloat(f32);
4530 const rhs_val = rhs.toFloat(f32);
4264 const lhs_val = lhs.toFloat(f32, mod);
4265 const rhs_val = rhs.toFloat(f32, mod);
45314266 return Value.Tag.float_32.create(arena, lhs_val * rhs_val);
45324267 },
45334268 64 => {
4534 const lhs_val = lhs.toFloat(f64);
4535 const rhs_val = rhs.toFloat(f64);
4269 const lhs_val = lhs.toFloat(f64, mod);
4270 const rhs_val = rhs.toFloat(f64, mod);
45364271 return Value.Tag.float_64.create(arena, lhs_val * rhs_val);
45374272 },
45384273 80 => {
4539 const lhs_val = lhs.toFloat(f80);
4540 const rhs_val = rhs.toFloat(f80);
4274 const lhs_val = lhs.toFloat(f80, mod);
4275 const rhs_val = rhs.toFloat(f80, mod);
45414276 return Value.Tag.float_80.create(arena, lhs_val * rhs_val);
45424277 },
45434278 128 => {
4544 const lhs_val = lhs.toFloat(f128);
4545 const rhs_val = rhs.toFloat(f128);
4279 const lhs_val = lhs.toFloat(f128, mod);
4280 const rhs_val = rhs.toFloat(f128, mod);
45464281 return Value.Tag.float_128.create(arena, lhs_val * rhs_val);
45474282 },
45484283 else => unreachable,
......@@ -4550,39 +4285,38 @@ pub const Value = struct {
45504285 }
45514286
45524287 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4553 const target = mod.getTarget();
45544288 if (float_type.zigTypeTag(mod) == .Vector) {
45554289 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45564290 for (result_data, 0..) |*scalar, i| {
4557 var buf: Value.ElemValueBuffer = undefined;
4558 const elem_val = val.elemValueBuffer(mod, i, &buf);
4559 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(mod), arena, target);
4291 const elem_val = try val.elemValue(mod, i);
4292 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(mod), arena, mod);
45604293 }
45614294 return Value.Tag.aggregate.create(arena, result_data);
45624295 }
4563 return sqrtScalar(val, float_type, arena, target);
4296 return sqrtScalar(val, float_type, arena, mod);
45644297 }
45654298
4566 pub fn sqrtScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4299 pub fn sqrtScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4300 const target = mod.getTarget();
45674301 switch (float_type.floatBits(target)) {
45684302 16 => {
4569 const f = val.toFloat(f16);
4303 const f = val.toFloat(f16, mod);
45704304 return Value.Tag.float_16.create(arena, @sqrt(f));
45714305 },
45724306 32 => {
4573 const f = val.toFloat(f32);
4307 const f = val.toFloat(f32, mod);
45744308 return Value.Tag.float_32.create(arena, @sqrt(f));
45754309 },
45764310 64 => {
4577 const f = val.toFloat(f64);
4311 const f = val.toFloat(f64, mod);
45784312 return Value.Tag.float_64.create(arena, @sqrt(f));
45794313 },
45804314 80 => {
4581 const f = val.toFloat(f80);
4315 const f = val.toFloat(f80, mod);
45824316 return Value.Tag.float_80.create(arena, @sqrt(f));
45834317 },
45844318 128 => {
4585 const f = val.toFloat(f128);
4319 const f = val.toFloat(f128, mod);
45864320 return Value.Tag.float_128.create(arena, @sqrt(f));
45874321 },
45884322 else => unreachable,
......@@ -4590,39 +4324,38 @@ pub const Value = struct {
45904324 }
45914325
45924326 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4593 const target = mod.getTarget();
45944327 if (float_type.zigTypeTag(mod) == .Vector) {
45954328 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45964329 for (result_data, 0..) |*scalar, i| {
4597 var buf: Value.ElemValueBuffer = undefined;
4598 const elem_val = val.elemValueBuffer(mod, i, &buf);
4599 scalar.* = try sinScalar(elem_val, float_type.scalarType(mod), arena, target);
4330 const elem_val = try val.elemValue(mod, i);
4331 scalar.* = try sinScalar(elem_val, float_type.scalarType(mod), arena, mod);
46004332 }
46014333 return Value.Tag.aggregate.create(arena, result_data);
46024334 }
4603 return sinScalar(val, float_type, arena, target);
4335 return sinScalar(val, float_type, arena, mod);
46044336 }
46054337
4606 pub fn sinScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4338 pub fn sinScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4339 const target = mod.getTarget();
46074340 switch (float_type.floatBits(target)) {
46084341 16 => {
4609 const f = val.toFloat(f16);
4342 const f = val.toFloat(f16, mod);
46104343 return Value.Tag.float_16.create(arena, @sin(f));
46114344 },
46124345 32 => {
4613 const f = val.toFloat(f32);
4346 const f = val.toFloat(f32, mod);
46144347 return Value.Tag.float_32.create(arena, @sin(f));
46154348 },
46164349 64 => {
4617 const f = val.toFloat(f64);
4350 const f = val.toFloat(f64, mod);
46184351 return Value.Tag.float_64.create(arena, @sin(f));
46194352 },
46204353 80 => {
4621 const f = val.toFloat(f80);
4354 const f = val.toFloat(f80, mod);
46224355 return Value.Tag.float_80.create(arena, @sin(f));
46234356 },
46244357 128 => {
4625 const f = val.toFloat(f128);
4358 const f = val.toFloat(f128, mod);
46264359 return Value.Tag.float_128.create(arena, @sin(f));
46274360 },
46284361 else => unreachable,
......@@ -4630,39 +4363,38 @@ pub const Value = struct {
46304363 }
46314364
46324365 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4633 const target = mod.getTarget();
46344366 if (float_type.zigTypeTag(mod) == .Vector) {
46354367 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46364368 for (result_data, 0..) |*scalar, i| {
4637 var buf: Value.ElemValueBuffer = undefined;
4638 const elem_val = val.elemValueBuffer(mod, i, &buf);
4639 scalar.* = try cosScalar(elem_val, float_type.scalarType(mod), arena, target);
4369 const elem_val = try val.elemValue(mod, i);
4370 scalar.* = try cosScalar(elem_val, float_type.scalarType(mod), arena, mod);
46404371 }
46414372 return Value.Tag.aggregate.create(arena, result_data);
46424373 }
4643 return cosScalar(val, float_type, arena, target);
4374 return cosScalar(val, float_type, arena, mod);
46444375 }
46454376
4646 pub fn cosScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4377 pub fn cosScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4378 const target = mod.getTarget();
46474379 switch (float_type.floatBits(target)) {
46484380 16 => {
4649 const f = val.toFloat(f16);
4381 const f = val.toFloat(f16, mod);
46504382 return Value.Tag.float_16.create(arena, @cos(f));
46514383 },
46524384 32 => {
4653 const f = val.toFloat(f32);
4385 const f = val.toFloat(f32, mod);
46544386 return Value.Tag.float_32.create(arena, @cos(f));
46554387 },
46564388 64 => {
4657 const f = val.toFloat(f64);
4389 const f = val.toFloat(f64, mod);
46584390 return Value.Tag.float_64.create(arena, @cos(f));
46594391 },
46604392 80 => {
4661 const f = val.toFloat(f80);
4393 const f = val.toFloat(f80, mod);
46624394 return Value.Tag.float_80.create(arena, @cos(f));
46634395 },
46644396 128 => {
4665 const f = val.toFloat(f128);
4397 const f = val.toFloat(f128, mod);
46664398 return Value.Tag.float_128.create(arena, @cos(f));
46674399 },
46684400 else => unreachable,
......@@ -4670,39 +4402,38 @@ pub const Value = struct {
46704402 }
46714403
46724404 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4673 const target = mod.getTarget();
46744405 if (float_type.zigTypeTag(mod) == .Vector) {
46754406 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46764407 for (result_data, 0..) |*scalar, i| {
4677 var buf: Value.ElemValueBuffer = undefined;
4678 const elem_val = val.elemValueBuffer(mod, i, &buf);
4679 scalar.* = try tanScalar(elem_val, float_type.scalarType(mod), arena, target);
4408 const elem_val = try val.elemValue(mod, i);
4409 scalar.* = try tanScalar(elem_val, float_type.scalarType(mod), arena, mod);
46804410 }
46814411 return Value.Tag.aggregate.create(arena, result_data);
46824412 }
4683 return tanScalar(val, float_type, arena, target);
4413 return tanScalar(val, float_type, arena, mod);
46844414 }
46854415
4686 pub fn tanScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4416 pub fn tanScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4417 const target = mod.getTarget();
46874418 switch (float_type.floatBits(target)) {
46884419 16 => {
4689 const f = val.toFloat(f16);
4420 const f = val.toFloat(f16, mod);
46904421 return Value.Tag.float_16.create(arena, @tan(f));
46914422 },
46924423 32 => {
4693 const f = val.toFloat(f32);
4424 const f = val.toFloat(f32, mod);
46944425 return Value.Tag.float_32.create(arena, @tan(f));
46954426 },
46964427 64 => {
4697 const f = val.toFloat(f64);
4428 const f = val.toFloat(f64, mod);
46984429 return Value.Tag.float_64.create(arena, @tan(f));
46994430 },
47004431 80 => {
4701 const f = val.toFloat(f80);
4432 const f = val.toFloat(f80, mod);
47024433 return Value.Tag.float_80.create(arena, @tan(f));
47034434 },
47044435 128 => {
4705 const f = val.toFloat(f128);
4436 const f = val.toFloat(f128, mod);
47064437 return Value.Tag.float_128.create(arena, @tan(f));
47074438 },
47084439 else => unreachable,
......@@ -4710,39 +4441,38 @@ pub const Value = struct {
47104441 }
47114442
47124443 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4713 const target = mod.getTarget();
47144444 if (float_type.zigTypeTag(mod) == .Vector) {
47154445 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47164446 for (result_data, 0..) |*scalar, i| {
4717 var buf: Value.ElemValueBuffer = undefined;
4718 const elem_val = val.elemValueBuffer(mod, i, &buf);
4719 scalar.* = try expScalar(elem_val, float_type.scalarType(mod), arena, target);
4447 const elem_val = try val.elemValue(mod, i);
4448 scalar.* = try expScalar(elem_val, float_type.scalarType(mod), arena, mod);
47204449 }
47214450 return Value.Tag.aggregate.create(arena, result_data);
47224451 }
4723 return expScalar(val, float_type, arena, target);
4452 return expScalar(val, float_type, arena, mod);
47244453 }
47254454
4726 pub fn expScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4455 pub fn expScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4456 const target = mod.getTarget();
47274457 switch (float_type.floatBits(target)) {
47284458 16 => {
4729 const f = val.toFloat(f16);
4459 const f = val.toFloat(f16, mod);
47304460 return Value.Tag.float_16.create(arena, @exp(f));
47314461 },
47324462 32 => {
4733 const f = val.toFloat(f32);
4463 const f = val.toFloat(f32, mod);
47344464 return Value.Tag.float_32.create(arena, @exp(f));
47354465 },
47364466 64 => {
4737 const f = val.toFloat(f64);
4467 const f = val.toFloat(f64, mod);
47384468 return Value.Tag.float_64.create(arena, @exp(f));
47394469 },
47404470 80 => {
4741 const f = val.toFloat(f80);
4471 const f = val.toFloat(f80, mod);
47424472 return Value.Tag.float_80.create(arena, @exp(f));
47434473 },
47444474 128 => {
4745 const f = val.toFloat(f128);
4475 const f = val.toFloat(f128, mod);
47464476 return Value.Tag.float_128.create(arena, @exp(f));
47474477 },
47484478 else => unreachable,
......@@ -4750,39 +4480,38 @@ pub const Value = struct {
47504480 }
47514481
47524482 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4753 const target = mod.getTarget();
47544483 if (float_type.zigTypeTag(mod) == .Vector) {
47554484 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47564485 for (result_data, 0..) |*scalar, i| {
4757 var buf: Value.ElemValueBuffer = undefined;
4758 const elem_val = val.elemValueBuffer(mod, i, &buf);
4759 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(mod), arena, target);
4486 const elem_val = try val.elemValue(mod, i);
4487 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(mod), arena, mod);
47604488 }
47614489 return Value.Tag.aggregate.create(arena, result_data);
47624490 }
4763 return exp2Scalar(val, float_type, arena, target);
4491 return exp2Scalar(val, float_type, arena, mod);
47644492 }
47654493
4766 pub fn exp2Scalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4494 pub fn exp2Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4495 const target = mod.getTarget();
47674496 switch (float_type.floatBits(target)) {
47684497 16 => {
4769 const f = val.toFloat(f16);
4498 const f = val.toFloat(f16, mod);
47704499 return Value.Tag.float_16.create(arena, @exp2(f));
47714500 },
47724501 32 => {
4773 const f = val.toFloat(f32);
4502 const f = val.toFloat(f32, mod);
47744503 return Value.Tag.float_32.create(arena, @exp2(f));
47754504 },
47764505 64 => {
4777 const f = val.toFloat(f64);
4506 const f = val.toFloat(f64, mod);
47784507 return Value.Tag.float_64.create(arena, @exp2(f));
47794508 },
47804509 80 => {
4781 const f = val.toFloat(f80);
4510 const f = val.toFloat(f80, mod);
47824511 return Value.Tag.float_80.create(arena, @exp2(f));
47834512 },
47844513 128 => {
4785 const f = val.toFloat(f128);
4514 const f = val.toFloat(f128, mod);
47864515 return Value.Tag.float_128.create(arena, @exp2(f));
47874516 },
47884517 else => unreachable,
......@@ -4790,39 +4519,38 @@ pub const Value = struct {
47904519 }
47914520
47924521 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4793 const target = mod.getTarget();
47944522 if (float_type.zigTypeTag(mod) == .Vector) {
47954523 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47964524 for (result_data, 0..) |*scalar, i| {
4797 var buf: Value.ElemValueBuffer = undefined;
4798 const elem_val = val.elemValueBuffer(mod, i, &buf);
4799 scalar.* = try logScalar(elem_val, float_type.scalarType(mod), arena, target);
4525 const elem_val = try val.elemValue(mod, i);
4526 scalar.* = try logScalar(elem_val, float_type.scalarType(mod), arena, mod);
48004527 }
48014528 return Value.Tag.aggregate.create(arena, result_data);
48024529 }
4803 return logScalar(val, float_type, arena, target);
4530 return logScalar(val, float_type, arena, mod);
48044531 }
48054532
4806 pub fn logScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4533 pub fn logScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4534 const target = mod.getTarget();
48074535 switch (float_type.floatBits(target)) {
48084536 16 => {
4809 const f = val.toFloat(f16);
4537 const f = val.toFloat(f16, mod);
48104538 return Value.Tag.float_16.create(arena, @log(f));
48114539 },
48124540 32 => {
4813 const f = val.toFloat(f32);
4541 const f = val.toFloat(f32, mod);
48144542 return Value.Tag.float_32.create(arena, @log(f));
48154543 },
48164544 64 => {
4817 const f = val.toFloat(f64);
4545 const f = val.toFloat(f64, mod);
48184546 return Value.Tag.float_64.create(arena, @log(f));
48194547 },
48204548 80 => {
4821 const f = val.toFloat(f80);
4549 const f = val.toFloat(f80, mod);
48224550 return Value.Tag.float_80.create(arena, @log(f));
48234551 },
48244552 128 => {
4825 const f = val.toFloat(f128);
4553 const f = val.toFloat(f128, mod);
48264554 return Value.Tag.float_128.create(arena, @log(f));
48274555 },
48284556 else => unreachable,
......@@ -4830,39 +4558,38 @@ pub const Value = struct {
48304558 }
48314559
48324560 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4833 const target = mod.getTarget();
48344561 if (float_type.zigTypeTag(mod) == .Vector) {
48354562 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48364563 for (result_data, 0..) |*scalar, i| {
4837 var buf: Value.ElemValueBuffer = undefined;
4838 const elem_val = val.elemValueBuffer(mod, i, &buf);
4839 scalar.* = try log2Scalar(elem_val, float_type.scalarType(mod), arena, target);
4564 const elem_val = try val.elemValue(mod, i);
4565 scalar.* = try log2Scalar(elem_val, float_type.scalarType(mod), arena, mod);
48404566 }
48414567 return Value.Tag.aggregate.create(arena, result_data);
48424568 }
4843 return log2Scalar(val, float_type, arena, target);
4569 return log2Scalar(val, float_type, arena, mod);
48444570 }
48454571
4846 pub fn log2Scalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4572 pub fn log2Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4573 const target = mod.getTarget();
48474574 switch (float_type.floatBits(target)) {
48484575 16 => {
4849 const f = val.toFloat(f16);
4576 const f = val.toFloat(f16, mod);
48504577 return Value.Tag.float_16.create(arena, @log2(f));
48514578 },
48524579 32 => {
4853 const f = val.toFloat(f32);
4580 const f = val.toFloat(f32, mod);
48544581 return Value.Tag.float_32.create(arena, @log2(f));
48554582 },
48564583 64 => {
4857 const f = val.toFloat(f64);
4584 const f = val.toFloat(f64, mod);
48584585 return Value.Tag.float_64.create(arena, @log2(f));
48594586 },
48604587 80 => {
4861 const f = val.toFloat(f80);
4588 const f = val.toFloat(f80, mod);
48624589 return Value.Tag.float_80.create(arena, @log2(f));
48634590 },
48644591 128 => {
4865 const f = val.toFloat(f128);
4592 const f = val.toFloat(f128, mod);
48664593 return Value.Tag.float_128.create(arena, @log2(f));
48674594 },
48684595 else => unreachable,
......@@ -4870,39 +4597,38 @@ pub const Value = struct {
48704597 }
48714598
48724599 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4873 const target = mod.getTarget();
48744600 if (float_type.zigTypeTag(mod) == .Vector) {
48754601 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48764602 for (result_data, 0..) |*scalar, i| {
4877 var buf: Value.ElemValueBuffer = undefined;
4878 const elem_val = val.elemValueBuffer(mod, i, &buf);
4879 scalar.* = try log10Scalar(elem_val, float_type.scalarType(mod), arena, target);
4603 const elem_val = try val.elemValue(mod, i);
4604 scalar.* = try log10Scalar(elem_val, float_type.scalarType(mod), arena, mod);
48804605 }
48814606 return Value.Tag.aggregate.create(arena, result_data);
48824607 }
4883 return log10Scalar(val, float_type, arena, target);
4608 return log10Scalar(val, float_type, arena, mod);
48844609 }
48854610
4886 pub fn log10Scalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4611 pub fn log10Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4612 const target = mod.getTarget();
48874613 switch (float_type.floatBits(target)) {
48884614 16 => {
4889 const f = val.toFloat(f16);
4615 const f = val.toFloat(f16, mod);
48904616 return Value.Tag.float_16.create(arena, @log10(f));
48914617 },
48924618 32 => {
4893 const f = val.toFloat(f32);
4619 const f = val.toFloat(f32, mod);
48944620 return Value.Tag.float_32.create(arena, @log10(f));
48954621 },
48964622 64 => {
4897 const f = val.toFloat(f64);
4623 const f = val.toFloat(f64, mod);
48984624 return Value.Tag.float_64.create(arena, @log10(f));
48994625 },
49004626 80 => {
4901 const f = val.toFloat(f80);
4627 const f = val.toFloat(f80, mod);
49024628 return Value.Tag.float_80.create(arena, @log10(f));
49034629 },
49044630 128 => {
4905 const f = val.toFloat(f128);
4631 const f = val.toFloat(f128, mod);
49064632 return Value.Tag.float_128.create(arena, @log10(f));
49074633 },
49084634 else => unreachable,
......@@ -4910,39 +4636,38 @@ pub const Value = struct {
49104636 }
49114637
49124638 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4913 const target = mod.getTarget();
49144639 if (float_type.zigTypeTag(mod) == .Vector) {
49154640 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
49164641 for (result_data, 0..) |*scalar, i| {
4917 var buf: Value.ElemValueBuffer = undefined;
4918 const elem_val = val.elemValueBuffer(mod, i, &buf);
4919 scalar.* = try fabsScalar(elem_val, float_type.scalarType(mod), arena, target);
4642 const elem_val = try val.elemValue(mod, i);
4643 scalar.* = try fabsScalar(elem_val, float_type.scalarType(mod), arena, mod);
49204644 }
49214645 return Value.Tag.aggregate.create(arena, result_data);
49224646 }
4923 return fabsScalar(val, float_type, arena, target);
4647 return fabsScalar(val, float_type, arena, mod);
49244648 }
49254649
4926 pub fn fabsScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4650 pub fn fabsScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4651 const target = mod.getTarget();
49274652 switch (float_type.floatBits(target)) {
49284653 16 => {
4929 const f = val.toFloat(f16);
4654 const f = val.toFloat(f16, mod);
49304655 return Value.Tag.float_16.create(arena, @fabs(f));
49314656 },
49324657 32 => {
4933 const f = val.toFloat(f32);
4658 const f = val.toFloat(f32, mod);
49344659 return Value.Tag.float_32.create(arena, @fabs(f));
49354660 },
49364661 64 => {
4937 const f = val.toFloat(f64);
4662 const f = val.toFloat(f64, mod);
49384663 return Value.Tag.float_64.create(arena, @fabs(f));
49394664 },
49404665 80 => {
4941 const f = val.toFloat(f80);
4666 const f = val.toFloat(f80, mod);
49424667 return Value.Tag.float_80.create(arena, @fabs(f));
49434668 },
49444669 128 => {
4945 const f = val.toFloat(f128);
4670 const f = val.toFloat(f128, mod);
49464671 return Value.Tag.float_128.create(arena, @fabs(f));
49474672 },
49484673 else => unreachable,
......@@ -4950,39 +4675,38 @@ pub const Value = struct {
49504675 }
49514676
49524677 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4953 const target = mod.getTarget();
49544678 if (float_type.zigTypeTag(mod) == .Vector) {
49554679 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
49564680 for (result_data, 0..) |*scalar, i| {
4957 var buf: Value.ElemValueBuffer = undefined;
4958 const elem_val = val.elemValueBuffer(mod, i, &buf);
4959 scalar.* = try floorScalar(elem_val, float_type.scalarType(mod), arena, target);
4681 const elem_val = try val.elemValue(mod, i);
4682 scalar.* = try floorScalar(elem_val, float_type.scalarType(mod), arena, mod);
49604683 }
49614684 return Value.Tag.aggregate.create(arena, result_data);
49624685 }
4963 return floorScalar(val, float_type, arena, target);
4686 return floorScalar(val, float_type, arena, mod);
49644687 }
49654688
4966 pub fn floorScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4689 pub fn floorScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4690 const target = mod.getTarget();
49674691 switch (float_type.floatBits(target)) {
49684692 16 => {
4969 const f = val.toFloat(f16);
4693 const f = val.toFloat(f16, mod);
49704694 return Value.Tag.float_16.create(arena, @floor(f));
49714695 },
49724696 32 => {
4973 const f = val.toFloat(f32);
4697 const f = val.toFloat(f32, mod);
49744698 return Value.Tag.float_32.create(arena, @floor(f));
49754699 },
49764700 64 => {
4977 const f = val.toFloat(f64);
4701 const f = val.toFloat(f64, mod);
49784702 return Value.Tag.float_64.create(arena, @floor(f));
49794703 },
49804704 80 => {
4981 const f = val.toFloat(f80);
4705 const f = val.toFloat(f80, mod);
49824706 return Value.Tag.float_80.create(arena, @floor(f));
49834707 },
49844708 128 => {
4985 const f = val.toFloat(f128);
4709 const f = val.toFloat(f128, mod);
49864710 return Value.Tag.float_128.create(arena, @floor(f));
49874711 },
49884712 else => unreachable,
......@@ -4990,39 +4714,38 @@ pub const Value = struct {
49904714 }
49914715
49924716 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4993 const target = mod.getTarget();
49944717 if (float_type.zigTypeTag(mod) == .Vector) {
49954718 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
49964719 for (result_data, 0..) |*scalar, i| {
4997 var buf: Value.ElemValueBuffer = undefined;
4998 const elem_val = val.elemValueBuffer(mod, i, &buf);
4999 scalar.* = try ceilScalar(elem_val, float_type.scalarType(mod), arena, target);
4720 const elem_val = try val.elemValue(mod, i);
4721 scalar.* = try ceilScalar(elem_val, float_type.scalarType(mod), arena, mod);
50004722 }
50014723 return Value.Tag.aggregate.create(arena, result_data);
50024724 }
5003 return ceilScalar(val, float_type, arena, target);
4725 return ceilScalar(val, float_type, arena, mod);
50044726 }
50054727
5006 pub fn ceilScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4728 pub fn ceilScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4729 const target = mod.getTarget();
50074730 switch (float_type.floatBits(target)) {
50084731 16 => {
5009 const f = val.toFloat(f16);
4732 const f = val.toFloat(f16, mod);
50104733 return Value.Tag.float_16.create(arena, @ceil(f));
50114734 },
50124735 32 => {
5013 const f = val.toFloat(f32);
4736 const f = val.toFloat(f32, mod);
50144737 return Value.Tag.float_32.create(arena, @ceil(f));
50154738 },
50164739 64 => {
5017 const f = val.toFloat(f64);
4740 const f = val.toFloat(f64, mod);
50184741 return Value.Tag.float_64.create(arena, @ceil(f));
50194742 },
50204743 80 => {
5021 const f = val.toFloat(f80);
4744 const f = val.toFloat(f80, mod);
50224745 return Value.Tag.float_80.create(arena, @ceil(f));
50234746 },
50244747 128 => {
5025 const f = val.toFloat(f128);
4748 const f = val.toFloat(f128, mod);
50264749 return Value.Tag.float_128.create(arena, @ceil(f));
50274750 },
50284751 else => unreachable,
......@@ -5030,39 +4753,38 @@ pub const Value = struct {
50304753 }
50314754
50324755 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5033 const target = mod.getTarget();
50344756 if (float_type.zigTypeTag(mod) == .Vector) {
50354757 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
50364758 for (result_data, 0..) |*scalar, i| {
5037 var buf: Value.ElemValueBuffer = undefined;
5038 const elem_val = val.elemValueBuffer(mod, i, &buf);
5039 scalar.* = try roundScalar(elem_val, float_type.scalarType(mod), arena, target);
4759 const elem_val = try val.elemValue(mod, i);
4760 scalar.* = try roundScalar(elem_val, float_type.scalarType(mod), arena, mod);
50404761 }
50414762 return Value.Tag.aggregate.create(arena, result_data);
50424763 }
5043 return roundScalar(val, float_type, arena, target);
4764 return roundScalar(val, float_type, arena, mod);
50444765 }
50454766
5046 pub fn roundScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4767 pub fn roundScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4768 const target = mod.getTarget();
50474769 switch (float_type.floatBits(target)) {
50484770 16 => {
5049 const f = val.toFloat(f16);
4771 const f = val.toFloat(f16, mod);
50504772 return Value.Tag.float_16.create(arena, @round(f));
50514773 },
50524774 32 => {
5053 const f = val.toFloat(f32);
4775 const f = val.toFloat(f32, mod);
50544776 return Value.Tag.float_32.create(arena, @round(f));
50554777 },
50564778 64 => {
5057 const f = val.toFloat(f64);
4779 const f = val.toFloat(f64, mod);
50584780 return Value.Tag.float_64.create(arena, @round(f));
50594781 },
50604782 80 => {
5061 const f = val.toFloat(f80);
4783 const f = val.toFloat(f80, mod);
50624784 return Value.Tag.float_80.create(arena, @round(f));
50634785 },
50644786 128 => {
5065 const f = val.toFloat(f128);
4787 const f = val.toFloat(f128, mod);
50664788 return Value.Tag.float_128.create(arena, @round(f));
50674789 },
50684790 else => unreachable,
......@@ -5070,39 +4792,38 @@ pub const Value = struct {
50704792 }
50714793
50724794 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5073 const target = mod.getTarget();
50744795 if (float_type.zigTypeTag(mod) == .Vector) {
50754796 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
50764797 for (result_data, 0..) |*scalar, i| {
5077 var buf: Value.ElemValueBuffer = undefined;
5078 const elem_val = val.elemValueBuffer(mod, i, &buf);
5079 scalar.* = try truncScalar(elem_val, float_type.scalarType(mod), arena, target);
4798 const elem_val = try val.elemValue(mod, i);
4799 scalar.* = try truncScalar(elem_val, float_type.scalarType(mod), arena, mod);
50804800 }
50814801 return Value.Tag.aggregate.create(arena, result_data);
50824802 }
5083 return truncScalar(val, float_type, arena, target);
4803 return truncScalar(val, float_type, arena, mod);
50844804 }
50854805
5086 pub fn truncScalar(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4806 pub fn truncScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4807 const target = mod.getTarget();
50874808 switch (float_type.floatBits(target)) {
50884809 16 => {
5089 const f = val.toFloat(f16);
4810 const f = val.toFloat(f16, mod);
50904811 return Value.Tag.float_16.create(arena, @trunc(f));
50914812 },
50924813 32 => {
5093 const f = val.toFloat(f32);
4814 const f = val.toFloat(f32, mod);
50944815 return Value.Tag.float_32.create(arena, @trunc(f));
50954816 },
50964817 64 => {
5097 const f = val.toFloat(f64);
4818 const f = val.toFloat(f64, mod);
50984819 return Value.Tag.float_64.create(arena, @trunc(f));
50994820 },
51004821 80 => {
5101 const f = val.toFloat(f80);
4822 const f = val.toFloat(f80, mod);
51024823 return Value.Tag.float_80.create(arena, @trunc(f));
51034824 },
51044825 128 => {
5105 const f = val.toFloat(f128);
4826 const f = val.toFloat(f128, mod);
51064827 return Value.Tag.float_128.create(arena, @trunc(f));
51074828 },
51084829 else => unreachable,
......@@ -5117,28 +4838,24 @@ pub const Value = struct {
51174838 arena: Allocator,
51184839 mod: *Module,
51194840 ) !Value {
5120 const target = mod.getTarget();
51214841 if (float_type.zigTypeTag(mod) == .Vector) {
51224842 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
51234843 for (result_data, 0..) |*scalar, i| {
5124 var mulend1_buf: Value.ElemValueBuffer = undefined;
5125 const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf);
5126 var mulend2_buf: Value.ElemValueBuffer = undefined;
5127 const mulend2_elem = mulend2.elemValueBuffer(mod, i, &mulend2_buf);
5128 var addend_buf: Value.ElemValueBuffer = undefined;
5129 const addend_elem = addend.elemValueBuffer(mod, i, &addend_buf);
4844 const mulend1_elem = try mulend1.elemValue(mod, i);
4845 const mulend2_elem = try mulend2.elemValue(mod, i);
4846 const addend_elem = try addend.elemValue(mod, i);
51304847 scalar.* = try mulAddScalar(
51314848 float_type.scalarType(mod),
51324849 mulend1_elem,
51334850 mulend2_elem,
51344851 addend_elem,
51354852 arena,
5136 target,
4853 mod,
51374854 );
51384855 }
51394856 return Value.Tag.aggregate.create(arena, result_data);
51404857 }
5141 return mulAddScalar(float_type, mulend1, mulend2, addend, arena, target);
4858 return mulAddScalar(float_type, mulend1, mulend2, addend, arena, mod);
51424859 }
51434860
51444861 pub fn mulAddScalar(
......@@ -5147,37 +4864,38 @@ pub const Value = struct {
51474864 mulend2: Value,
51484865 addend: Value,
51494866 arena: Allocator,
5150 target: Target,
4867 mod: *const Module,
51514868 ) Allocator.Error!Value {
4869 const target = mod.getTarget();
51524870 switch (float_type.floatBits(target)) {
51534871 16 => {
5154 const m1 = mulend1.toFloat(f16);
5155 const m2 = mulend2.toFloat(f16);
5156 const a = addend.toFloat(f16);
4872 const m1 = mulend1.toFloat(f16, mod);
4873 const m2 = mulend2.toFloat(f16, mod);
4874 const a = addend.toFloat(f16, mod);
51574875 return Value.Tag.float_16.create(arena, @mulAdd(f16, m1, m2, a));
51584876 },
51594877 32 => {
5160 const m1 = mulend1.toFloat(f32);
5161 const m2 = mulend2.toFloat(f32);
5162 const a = addend.toFloat(f32);
4878 const m1 = mulend1.toFloat(f32, mod);
4879 const m2 = mulend2.toFloat(f32, mod);
4880 const a = addend.toFloat(f32, mod);
51634881 return Value.Tag.float_32.create(arena, @mulAdd(f32, m1, m2, a));
51644882 },
51654883 64 => {
5166 const m1 = mulend1.toFloat(f64);
5167 const m2 = mulend2.toFloat(f64);
5168 const a = addend.toFloat(f64);
4884 const m1 = mulend1.toFloat(f64, mod);
4885 const m2 = mulend2.toFloat(f64, mod);
4886 const a = addend.toFloat(f64, mod);
51694887 return Value.Tag.float_64.create(arena, @mulAdd(f64, m1, m2, a));
51704888 },
51714889 80 => {
5172 const m1 = mulend1.toFloat(f80);
5173 const m2 = mulend2.toFloat(f80);
5174 const a = addend.toFloat(f80);
4890 const m1 = mulend1.toFloat(f80, mod);
4891 const m2 = mulend2.toFloat(f80, mod);
4892 const a = addend.toFloat(f80, mod);
51754893 return Value.Tag.float_80.create(arena, @mulAdd(f80, m1, m2, a));
51764894 },
51774895 128 => {
5178 const m1 = mulend1.toFloat(f128);
5179 const m2 = mulend2.toFloat(f128);
5180 const a = addend.toFloat(f128);
4896 const m1 = mulend1.toFloat(f128, mod);
4897 const m2 = mulend2.toFloat(f128, mod);
4898 const a = addend.toFloat(f128, mod);
51814899 return Value.Tag.float_128.create(arena, @mulAdd(f128, m1, m2, a));
51824900 },
51834901 else => unreachable,
......@@ -5186,13 +4904,14 @@ pub const Value = struct {
51864904
51874905 /// If the value is represented in-memory as a series of bytes that all
51884906 /// have the same value, return that byte value, otherwise null.
5189 pub fn hasRepeatedByteRepr(val: Value, ty: Type, mod: *Module, value_buffer: *Payload.U64) !?Value {
4907 pub fn hasRepeatedByteRepr(val: Value, ty: Type, mod: *Module) !?Value {
51904908 const abi_size = std.math.cast(usize, ty.abiSize(mod)) orelse return null;
51914909 assert(abi_size >= 1);
51924910 const byte_buffer = try mod.gpa.alloc(u8, abi_size);
51934911 defer mod.gpa.free(byte_buffer);
51944912
51954913 writeToMemory(val, ty, mod, byte_buffer) catch |err| switch (err) {
4914 error.OutOfMemory => return error.OutOfMemory,
51964915 error.ReinterpretDeclRef => return null,
51974916 // TODO: The writeToMemory function was originally created for the purpose
51984917 // of comptime pointer casting. However, it is now additionally being used
......@@ -5206,11 +4925,7 @@ pub const Value = struct {
52064925 for (byte_buffer[1..]) |byte| {
52074926 if (byte != first_byte) return null;
52084927 }
5209 value_buffer.* = .{
5210 .base = .{ .tag = .int_u64 },
5211 .data = first_byte,
5212 };
5213 return initPayload(&value_buffer.base);
4928 return try mod.intValue(Type.u8, first_byte);
52144929 }
52154930
52164931 pub fn isGenericPoison(val: Value) bool {
......@@ -5226,30 +4941,6 @@ pub const Value = struct {
52264941 data: u32,
52274942 };
52284943
5229 pub const U64 = struct {
5230 base: Payload,
5231 data: u64,
5232 };
5233
5234 pub const I64 = struct {
5235 base: Payload,
5236 data: i64,
5237 };
5238
5239 pub const BigInt = struct {
5240 base: Payload,
5241 data: []const std.math.big.Limb,
5242
5243 pub fn asBigInt(self: BigInt) BigIntConst {
5244 const positive = switch (self.base.tag) {
5245 .int_big_positive => true,
5246 .int_big_negative => false,
5247 else => unreachable,
5248 };
5249 return BigIntConst{ .limbs = self.data, .positive = positive };
5250 }
5251 };
5252
52534944 pub const Function = struct {
52544945 base: Payload,
52554946 data: *Module.Fn,
......@@ -5452,12 +5143,9 @@ pub const Value = struct {
54525143
54535144 pub const BigIntSpace = InternPool.Key.Int.Storage.BigIntSpace;
54545145
5455 pub const zero = initTag(.zero);
5456 pub const one = initTag(.one);
5457 pub const negative_one: Value = .{
5458 .ip_index = .none,
5459 .legacy = .{ .ptr_otherwise = &negative_one_payload.base },
5460 };
5146 pub const zero: Value = .{ .ip_index = .zero, .legacy = undefined };
5147 pub const one: Value = .{ .ip_index = .one, .legacy = undefined };
5148 pub const negative_one: Value = .{ .ip_index = .negative_one, .legacy = undefined };
54615149 pub const undef: Value = .{ .ip_index = .undef, .legacy = undefined };
54625150 pub const @"void": Value = .{ .ip_index = .void_value, .legacy = undefined };
54635151 pub const @"null": Value = .{ .ip_index = .null_value, .legacy = undefined };
......@@ -5515,8 +5203,3 @@ pub const Value = struct {
55155203 }
55165204 }
55175205};
5518
5519var negative_one_payload: Value.Payload.I64 = .{
5520 .base = .{ .tag = .int_i64 },
5521 .data = -1,
5522};