@@ -3755,7 +3755,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3755
3755
const idx_val = (try sema.resolveValue(data.rhs)).?;
3756
3756
break :blk .{
3757
3757
data.lhs,
3758
- .{ .elem = idx_val.toUnsignedInt(mod ) },
3758
+ .{ .elem = try idx_val.toUnsignedIntAdvanced(sema ) },
3759
3759
};
3760
3760
},
3761
3761
.bitcast => .{
@@ -8399,7 +8399,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8399
8399
const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);
8400
8400
8401
8401
if (try sema.resolveDefinedValue(block, operand_src, operand)) |value| {
8402
- const int = try sema.usizeCast(block, operand_src, value.toUnsignedInt(mod ));
8402
+ const int = try sema.usizeCast(block, operand_src, try value.toUnsignedIntAdvanced(sema ));
8403
8403
if (int > mod.global_error_set.count() or int == 0)
8404
8404
return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int});
8405
8405
return Air.internedToRef((try mod.intern(.{ .err = .{
@@ -16522,7 +16522,7 @@ fn analyzePtrArithmetic(
16522
16522
// it being a multiple of the type size.
16523
16523
const elem_size = Type.fromInterned(ptr_info.child).abiSize(mod);
16524
16524
const addend = if (opt_off_val) |off_val| a: {
16525
- const off_int = try sema.usizeCast(block, offset_src, off_val.toUnsignedInt(mod ));
16525
+ const off_int = try sema.usizeCast(block, offset_src, try off_val.toUnsignedIntAdvanced(sema ));
16526
16526
break :a elem_size * off_int;
16527
16527
} else elem_size;
16528
16528
@@ -16554,7 +16554,7 @@ fn analyzePtrArithmetic(
16554
16554
if (opt_off_val) |offset_val| {
16555
16555
if (ptr_val.isUndef(mod)) return mod.undefRef(new_ptr_ty);
16556
16556
16557
- const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod ));
16557
+ const offset_int = try sema.usizeCast(block, offset_src, try offset_val.toUnsignedIntAdvanced(sema ));
16558
16558
if (offset_int == 0) return ptr;
16559
16559
if (try ptr_val.getUnsignedIntAdvanced(mod, sema)) |addr| {
16560
16560
const elem_size = Type.fromInterned(ptr_info.child).abiSize(mod);
@@ -20815,7 +20815,7 @@ fn zirReify(
20815
20815
);
20816
20816
20817
20817
const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
20818
- const bits: u16 = @intCast(bits_val.toUnsignedInt(mod ));
20818
+ const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema ));
20819
20819
const ty = try mod.intType(signedness, bits);
20820
20820
return Air.internedToRef(ty.toIntern());
20821
20821
},
@@ -20830,7 +20830,7 @@ fn zirReify(
20830
20830
try ip.getOrPutString(gpa, "child"),
20831
20831
).?);
20832
20832
20833
- const len: u32 = @intCast(len_val.toUnsignedInt(mod ));
20833
+ const len: u32 = @intCast(try len_val.toUnsignedIntAdvanced(sema ));
20834
20834
const child_ty = child_val.toType();
20835
20835
20836
20836
try sema.checkVectorElemType(block, src, child_ty);
@@ -20848,7 +20848,7 @@ fn zirReify(
20848
20848
try ip.getOrPutString(gpa, "bits"),
20849
20849
).?);
20850
20850
20851
- const bits: u16 = @intCast(bits_val.toUnsignedInt(mod ));
20851
+ const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema ));
20852
20852
const ty = switch (bits) {
20853
20853
16 => Type.f16,
20854
20854
32 => Type.f32,
@@ -20986,7 +20986,7 @@ fn zirReify(
20986
20986
try ip.getOrPutString(gpa, "sentinel"),
20987
20987
).?);
20988
20988
20989
- const len = len_val.toUnsignedInt(mod );
20989
+ const len = try len_val.toUnsignedIntAdvanced(sema );
20990
20990
const child_ty = child_val.toType();
20991
20991
const sentinel = if (sentinel_val.optionalValue(mod)) |p| blk: {
20992
20992
const ptr_ty = try mod.singleMutPtrType(child_ty);
@@ -21537,7 +21537,7 @@ fn zirReify(
21537
21537
}
21538
21538
21539
21539
const alignment = alignment: {
21540
- const alignment = try sema.validateAlignAllowZero(block, src, alignment_val.toUnsignedInt(mod ));
21540
+ const alignment = try sema.validateAlignAllowZero(block, src, try alignment_val.toUnsignedIntAdvanced(sema ));
21541
21541
const default = target_util.defaultFunctionAlignment(target);
21542
21542
break :alignment if (alignment == default) .none else alignment;
21543
21543
};
@@ -22148,7 +22148,7 @@ fn ptrFromIntVal(
22148
22148
ptr_align: Alignment,
22149
22149
) !Value {
22150
22150
const mod = sema.mod;
22151
- const addr = operand_val.toUnsignedInt(mod );
22151
+ const addr = try operand_val.toUnsignedIntAdvanced(sema );
22152
22152
if (!ptr_ty.isAllowzeroPtr(mod) and addr == 0)
22153
22153
return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{ptr_ty.fmt(sema.mod)});
22154
22154
if (addr != 0 and ptr_align != .none and !ptr_align.check(addr))
@@ -23878,7 +23878,8 @@ fn analyzeShuffle(
23878
23878
for (0..@intCast(mask_len)) |i| {
23879
23879
const elem = try mask.elemValue(sema.mod, i);
23880
23880
if (elem.isUndef(mod)) continue;
23881
- const int = elem.toSignedInt(mod);
23881
+ const elem_resolved = try sema.resolveLazyValue(elem);
23882
+ const int = elem_resolved.toSignedInt(mod);
23882
23883
var unsigned: u32 = undefined;
23883
23884
var chosen: u32 = undefined;
23884
23885
if (int >= 0) {
@@ -24952,7 +24953,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24952
24953
var new_dest_ptr = dest_ptr;
24953
24954
var new_src_ptr = src_ptr;
24954
24955
if (len_val) |val| {
24955
- const len = val.toUnsignedInt(mod );
24956
+ const len = try val.toUnsignedIntAdvanced(sema );
24956
24957
if (len == 0) {
24957
24958
// This AIR instruction guarantees length > 0 if it is comptime-known.
24958
24959
return;
@@ -25257,7 +25258,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
25257
25258
if (val.isGenericPoison()) {
25258
25259
break :blk null;
25259
25260
}
25260
- const alignment = try sema.validateAlignAllowZero(block, align_src, val.toUnsignedInt(mod ));
25261
+ const alignment = try sema.validateAlignAllowZero(block, align_src, try val.toUnsignedIntAdvanced(sema ));
25261
25262
const default = target_util.defaultFunctionAlignment(target);
25262
25263
break :blk if (alignment == default) .none else alignment;
25263
25264
} else if (extra.data.bits.has_align_ref) blk: {
@@ -25271,7 +25272,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
25271
25272
},
25272
25273
else => |e| return e,
25273
25274
};
25274
- const alignment = try sema.validateAlignAllowZero(block, align_src, align_tv.val.toUnsignedInt(mod ));
25275
+ const alignment = try sema.validateAlignAllowZero(block, align_src, try align_tv.val.toUnsignedIntAdvanced(sema ));
25275
25276
const default = target_util.defaultFunctionAlignment(target);
25276
25277
break :blk if (alignment == default) .none else alignment;
25277
25278
} else .none;
@@ -25569,7 +25570,7 @@ fn resolvePrefetchOptions(
25569
25570
25570
25571
return std.builtin.PrefetchOptions{
25571
25572
.rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
25572
- .locality = @intCast(locality_val.toUnsignedInt(mod )),
25573
+ .locality = @intCast(try locality_val.toUnsignedIntAdvanced(sema )),
25573
25574
.cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
25574
25575
};
25575
25576
}
@@ -27757,7 +27758,7 @@ fn elemPtr(
27757
27758
const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
27758
27759
.needed_comptime_reason = "tuple field access index must be comptime-known",
27759
27760
});
27760
- const index: u32 = @intCast(index_val.toUnsignedInt(mod ));
27761
+ const index: u32 = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
27761
27762
break :blk try sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);
27762
27763
},
27763
27764
else => {
@@ -27795,7 +27796,7 @@ fn elemPtrOneLayerOnly(
27795
27796
const runtime_src = rs: {
27796
27797
const ptr_val = maybe_ptr_val orelse break :rs indexable_src;
27797
27798
const index_val = maybe_index_val orelse break :rs elem_index_src;
27798
- const index: usize = @intCast(index_val.toUnsignedInt(mod ));
27799
+ const index: usize = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
27799
27800
const result_ty = try sema.elemPtrType(indexable_ty, index);
27800
27801
const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod);
27801
27802
return Air.internedToRef(elem_ptr.toIntern());
@@ -27814,7 +27815,7 @@ fn elemPtrOneLayerOnly(
27814
27815
const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
27815
27816
.needed_comptime_reason = "tuple field access index must be comptime-known",
27816
27817
});
27817
- const index: u32 = @intCast(index_val.toUnsignedInt(mod ));
27818
+ const index: u32 = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
27818
27819
break :blk try sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);
27819
27820
},
27820
27821
else => unreachable, // Guaranteed by checkIndexable
@@ -27854,7 +27855,7 @@ fn elemVal(
27854
27855
const runtime_src = rs: {
27855
27856
const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
27856
27857
const index_val = maybe_index_val orelse break :rs elem_index_src;
27857
- const index: usize = @intCast(index_val.toUnsignedInt(mod ));
27858
+ const index: usize = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
27858
27859
const elem_ty = indexable_ty.elemType2(mod);
27859
27860
const many_ptr_ty = try mod.manyConstPtrType(elem_ty);
27860
27861
const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty);
@@ -27875,7 +27876,7 @@ fn elemVal(
27875
27876
if (inner_ty.zigTypeTag(mod) != .Array) break :arr_sent;
27876
27877
const sentinel = inner_ty.sentinel(mod) orelse break :arr_sent;
27877
27878
const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent;
27878
- const index = try sema.usizeCast(block, src, index_val.toUnsignedInt(mod ));
27879
+ const index = try sema.usizeCast(block, src, try index_val.toUnsignedIntAdvanced(sema ));
27879
27880
if (index != inner_ty.arrayLen(mod)) break :arr_sent;
27880
27881
return Air.internedToRef(sentinel.toIntern());
27881
27882
}
@@ -27893,7 +27894,7 @@ fn elemVal(
27893
27894
const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
27894
27895
.needed_comptime_reason = "tuple field access index must be comptime-known",
27895
27896
});
27896
- const index: u32 = @intCast(index_val.toUnsignedInt(mod ));
27897
+ const index: u32 = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
27897
27898
return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
27898
27899
},
27899
27900
else => unreachable,
@@ -28059,7 +28060,7 @@ fn elemValArray(
28059
28060
const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
28060
28061
28061
28062
if (maybe_index_val) |index_val| {
28062
- const index: usize = @intCast(index_val.toUnsignedInt(mod ));
28063
+ const index: usize = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
28063
28064
if (array_sent) |s| {
28064
28065
if (index == array_len) {
28065
28066
return Air.internedToRef(s.toIntern());
@@ -28075,7 +28076,7 @@ fn elemValArray(
28075
28076
return mod.undefRef(elem_ty);
28076
28077
}
28077
28078
if (maybe_index_val) |index_val| {
28078
- const index: usize = @intCast(index_val.toUnsignedInt(mod ));
28079
+ const index: usize = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
28079
28080
const elem_val = try array_val.elemValue(mod, index);
28080
28081
return Air.internedToRef(elem_val.toIntern());
28081
28082
}
@@ -28122,7 +28123,7 @@ fn elemPtrArray(
28122
28123
const maybe_undef_array_ptr_val = try sema.resolveValue(array_ptr);
28123
28124
// The index must not be undefined since it can be out of bounds.
28124
28125
const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
28125
- const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod ));
28126
+ const index = try sema.usizeCast(block, elem_index_src, try index_val.toUnsignedIntAdvanced(sema ));
28126
28127
if (index >= array_len_s) {
28127
28128
const sentinel_label: []const u8 = if (array_sent) " +1 (sentinel)" else "";
28128
28129
return sema.fail(block, elem_index_src, "index {d} outside array of length {d}{s}", .{ index, array_len, sentinel_label });
@@ -28188,7 +28189,7 @@ fn elemValSlice(
28188
28189
return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
28189
28190
}
28190
28191
if (maybe_index_val) |index_val| {
28191
- const index: usize = @intCast(index_val.toUnsignedInt(mod ));
28192
+ const index: usize = @intCast(try index_val.toUnsignedIntAdvanced(sema ));
28192
28193
if (index >= slice_len_s) {
28193
28194
const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
28194
28195
return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
@@ -28234,7 +28235,7 @@ fn elemPtrSlice(
28234
28235
const maybe_undef_slice_val = try sema.resolveValue(slice);
28235
28236
// The index must not be undefined since it can be out of bounds.
28236
28237
const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
28237
- const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod ));
28238
+ const index = try sema.usizeCast(block, elem_index_src, try index_val.toUnsignedIntAdvanced(sema ));
28238
28239
break :o index;
28239
28240
} else null;
28240
28241
@@ -32931,7 +32932,7 @@ fn analyzeSlice(
32931
32932
const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(mod) != .C;
32932
32933
32933
32934
if (opt_new_len_val) |new_len_val| {
32934
- const new_len_int = new_len_val.toUnsignedInt(mod );
32935
+ const new_len_int = try new_len_val.toUnsignedIntAdvanced(sema );
32935
32936
32936
32937
const return_ty = try sema.ptrType(.{
32937
32938
.child = (try mod.arrayType(.{
@@ -36279,6 +36280,7 @@ fn semaStructFields(
36279
36280
return;
36280
36281
},
36281
36282
.Auto, .Extern => {
36283
+ struct_type.size(ip).* = 0;
36282
36284
struct_type.flagsPtr(ip).layout_resolved = true;
36283
36285
return;
36284
36286
},
0 commit comments