authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-05-30 00:22:45-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-05-31 18:54:28-04:00
logb483defc5a5c2f93eb8a445974ab831ae4e4b321
tree0fa6fa6721e8731b294f8aafed6ca8f02a0242ae
parentc1e9ef9eaabb2219a3762c5957b1c63ad20bf1ed

Legalize: implement scalarization of binary operations


39 files changed, 1384 insertions(+), 835 deletions(-)

lib/std/zig/AstGen.zig+21-1
......@@ -11194,6 +11194,7 @@ fn rvalueInner(
1119411194 const as_void = @as(u64, @intFromEnum(Zir.Inst.Ref.void_type)) << 32;
1119511195 const as_comptime_int = @as(u64, @intFromEnum(Zir.Inst.Ref.comptime_int_type)) << 32;
1119611196 const as_usize = @as(u64, @intFromEnum(Zir.Inst.Ref.usize_type)) << 32;
11197 const as_u1 = @as(u64, @intFromEnum(Zir.Inst.Ref.u1_type)) << 32;
1119711198 const as_u8 = @as(u64, @intFromEnum(Zir.Inst.Ref.u8_type)) << 32;
1119811199 switch ((@as(u64, @intFromEnum(ty_inst)) << 32) | @as(u64, @intFromEnum(result))) {
1119911200 as_ty | @intFromEnum(Zir.Inst.Ref.u1_type),
......@@ -11237,10 +11238,11 @@ fn rvalueInner(
1123711238 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),
1123811239 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),
1123911240 as_ty | @intFromEnum(Zir.Inst.Ref.enum_literal_type),
11241 as_ty | @intFromEnum(Zir.Inst.Ref.ptr_usize_type),
11242 as_ty | @intFromEnum(Zir.Inst.Ref.ptr_const_comptime_int_type),
1124011243 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),
1124111244 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),
1124211245 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),
11243 as_ty | @intFromEnum(Zir.Inst.Ref.single_const_pointer_to_comptime_int_type),
1124411246 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_type),
1124511247 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_sentinel_0_type),
1124611248 as_ty | @intFromEnum(Zir.Inst.Ref.anyerror_void_error_union_type),
......@@ -11249,27 +11251,45 @@ fn rvalueInner(
1124911251 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero),
1125011252 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one),
1125111253 as_comptime_int | @intFromEnum(Zir.Inst.Ref.negative_one),
11254 as_usize | @intFromEnum(Zir.Inst.Ref.undef_usize),
1125211255 as_usize | @intFromEnum(Zir.Inst.Ref.zero_usize),
1125311256 as_usize | @intFromEnum(Zir.Inst.Ref.one_usize),
11257 as_u1 | @intFromEnum(Zir.Inst.Ref.undef_u1),
11258 as_u1 | @intFromEnum(Zir.Inst.Ref.zero_u1),
11259 as_u1 | @intFromEnum(Zir.Inst.Ref.one_u1),
1125411260 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_u8),
1125511261 as_u8 | @intFromEnum(Zir.Inst.Ref.one_u8),
1125611262 as_u8 | @intFromEnum(Zir.Inst.Ref.four_u8),
11263 as_bool | @intFromEnum(Zir.Inst.Ref.undef_bool),
1125711264 as_bool | @intFromEnum(Zir.Inst.Ref.bool_true),
1125811265 as_bool | @intFromEnum(Zir.Inst.Ref.bool_false),
1125911266 as_void | @intFromEnum(Zir.Inst.Ref.void_value),
1126011267 => return result, // type of result is already correct
1126111268
11269 as_bool | @intFromEnum(Zir.Inst.Ref.undef) => return .undef_bool,
11270 as_usize | @intFromEnum(Zir.Inst.Ref.undef) => return .undef_usize,
11271 as_usize | @intFromEnum(Zir.Inst.Ref.undef_u1) => return .undef_usize,
11272 as_u1 | @intFromEnum(Zir.Inst.Ref.undef) => return .undef_u1,
11273
1126211274 as_usize | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_usize,
11275 as_u1 | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_u1,
1126311276 as_u8 | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_u8,
1126411277 as_usize | @intFromEnum(Zir.Inst.Ref.one) => return .one_usize,
11278 as_u1 | @intFromEnum(Zir.Inst.Ref.one) => return .one_u1,
1126511279 as_u8 | @intFromEnum(Zir.Inst.Ref.one) => return .one_u8,
1126611280 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero,
11281 as_u1 | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero_u1,
1126711282 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero_u8,
1126811283 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one,
11284 as_u1 | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one_u1,
1126911285 as_u8 | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one_u8,
11286 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_u1) => return .zero,
1127011287 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero,
11288 as_usize | @intFromEnum(Zir.Inst.Ref.zero_u1) => return .zero_usize,
1127111289 as_usize | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero_usize,
11290 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_u1) => return .one,
1127211291 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one,
11292 as_usize | @intFromEnum(Zir.Inst.Ref.one_u1) => return .one_usize,
1127311293 as_usize | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one_usize,
1127411294
1127511295 // Need an explicit type coercion instruction.
lib/std/zig/Zir.zig+8-2
......@@ -2142,7 +2142,7 @@ pub const Inst = struct {
21422142 ref_start_index = static_len,
21432143 _,
21442144
2145 pub const static_len = 118;
2145 pub const static_len = 124;
21462146
21472147 pub fn toRef(i: Index) Inst.Ref {
21482148 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
......@@ -2220,10 +2220,11 @@ pub const Inst = struct {
22202220 null_type,
22212221 undefined_type,
22222222 enum_literal_type,
2223 ptr_usize_type,
2224 ptr_const_comptime_int_type,
22232225 manyptr_u8_type,
22242226 manyptr_const_u8_type,
22252227 manyptr_const_u8_sentinel_0_type,
2226 single_const_pointer_to_comptime_int_type,
22272228 slice_const_u8_type,
22282229 slice_const_u8_sentinel_0_type,
22292230 vector_8_i8_type,
......@@ -2279,11 +2280,16 @@ pub const Inst = struct {
22792280 generic_poison_type,
22802281 empty_tuple_type,
22812282 undef,
2283 undef_bool,
2284 undef_usize,
2285 undef_u1,
22822286 zero,
22832287 zero_usize,
2288 zero_u1,
22842289 zero_u8,
22852290 one,
22862291 one_usize,
2292 one_u1,
22872293 one_u8,
22882294 four_u8,
22892295 negative_one,
src/Air.zig+21-15
......@@ -1011,10 +1011,11 @@ pub const Inst = struct {
10111011 null_type = @intFromEnum(InternPool.Index.null_type),
10121012 undefined_type = @intFromEnum(InternPool.Index.undefined_type),
10131013 enum_literal_type = @intFromEnum(InternPool.Index.enum_literal_type),
1014 ptr_usize_type = @intFromEnum(InternPool.Index.ptr_usize_type),
1015 ptr_const_comptime_int_type = @intFromEnum(InternPool.Index.ptr_const_comptime_int_type),
10141016 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),
10151017 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),
10161018 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),
1017 single_const_pointer_to_comptime_int_type = @intFromEnum(InternPool.Index.single_const_pointer_to_comptime_int_type),
10181019 slice_const_u8_type = @intFromEnum(InternPool.Index.slice_const_u8_type),
10191020 slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
10201021 vector_8_i8_type = @intFromEnum(InternPool.Index.vector_8_i8_type),
......@@ -1070,11 +1071,16 @@ pub const Inst = struct {
10701071 generic_poison_type = @intFromEnum(InternPool.Index.generic_poison_type),
10711072 empty_tuple_type = @intFromEnum(InternPool.Index.empty_tuple_type),
10721073 undef = @intFromEnum(InternPool.Index.undef),
1074 undef_bool = @intFromEnum(InternPool.Index.undef_bool),
1075 undef_usize = @intFromEnum(InternPool.Index.undef_usize),
1076 undef_u1 = @intFromEnum(InternPool.Index.undef_u1),
10731077 zero = @intFromEnum(InternPool.Index.zero),
10741078 zero_usize = @intFromEnum(InternPool.Index.zero_usize),
1079 zero_u1 = @intFromEnum(InternPool.Index.zero_u1),
10751080 zero_u8 = @intFromEnum(InternPool.Index.zero_u8),
10761081 one = @intFromEnum(InternPool.Index.one),
10771082 one_usize = @intFromEnum(InternPool.Index.one_usize),
1083 one_u1 = @intFromEnum(InternPool.Index.one_u1),
10781084 one_u8 = @intFromEnum(InternPool.Index.one_u8),
10791085 four_u8 = @intFromEnum(InternPool.Index.four_u8),
10801086 negative_one = @intFromEnum(InternPool.Index.negative_one),
......@@ -1121,7 +1127,7 @@ pub const Inst = struct {
11211127 }
11221128
11231129 pub fn toType(ref: Ref) Type {
1124 return Type.fromInterned(ref.toInterned().?);
1130 return .fromInterned(ref.toInterned().?);
11251131 }
11261132 };
11271133
......@@ -1393,7 +1399,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
13931399
13941400pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
13951401 if (inst.toInterned()) |ip_index| {
1396 return Type.fromInterned(ip.typeOf(ip_index));
1402 return .fromInterned(ip.typeOf(ip_index));
13971403 } else {
13981404 return air.typeOfIndex(inst.toIndex().?, ip);
13991405 }
......@@ -1483,7 +1489,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14831489 .is_non_err_ptr,
14841490 .is_named_enum_value,
14851491 .error_set_has_value,
1486 => return Type.bool,
1492 => return .bool,
14871493
14881494 .alloc,
14891495 .ret_ptr,
......@@ -1574,7 +1580,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
15741580 .ret_load,
15751581 .unreach,
15761582 .trap,
1577 => return Type.noreturn,
1583 => return .noreturn,
15781584
15791585 .breakpoint,
15801586 .dbg_stmt,
......@@ -1597,22 +1603,22 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
15971603 .set_err_return_trace,
15981604 .vector_store_elem,
15991605 .c_va_end,
1600 => return Type.void,
1606 => return .void,
16011607
16021608 .slice_len,
16031609 .ret_addr,
16041610 .frame_addr,
16051611 .save_err_return_trace_index,
1606 => return Type.usize,
1612 => return .usize,
16071613
1608 .wasm_memory_grow => return Type.isize,
1609 .wasm_memory_size => return Type.usize,
1614 .wasm_memory_grow => return .isize,
1615 .wasm_memory_size => return .usize,
16101616
1611 .tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
1617 .tag_name, .error_name => return .slice_const_u8_sentinel_0,
16121618
16131619 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
16141620 const callee_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);
1615 return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));
1621 return .fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));
16161622 },
16171623
16181624 .slice_elem_val, .ptr_elem_val, .array_elem_val => {
......@@ -1630,7 +1636,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
16301636
16311637 .reduce, .reduce_optimized => {
16321638 const operand_ty = air.typeOf(datas[@intFromEnum(inst)].reduce.operand, ip);
1633 return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);
1639 return .fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);
16341640 },
16351641
16361642 .mul_add => return air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip),
......@@ -1641,7 +1647,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
16411647
16421648 .@"try", .try_cold => {
16431649 const err_union_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);
1644 return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);
1650 return .fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);
16451651 },
16461652
16471653 .tlv_dllimport_ptr => return .fromInterned(datas[@intFromEnum(inst)].ty_nav.ty),
......@@ -1649,7 +1655,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
16491655 .work_item_id,
16501656 .work_group_size,
16511657 .work_group_id,
1652 => return Type.u32,
1658 => return .u32,
16531659
16541660 .inferred_alloc => unreachable,
16551661 .inferred_alloc_comptime => unreachable,
......@@ -1696,7 +1702,7 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
16961702/// Returns `null` if runtime-known.
16971703pub fn value(air: Air, inst: Inst.Ref, pt: Zcu.PerThread) !?Value {
16981704 if (inst.toInterned()) |ip_index| {
1699 return Value.fromInterned(ip_index);
1705 return .fromInterned(ip_index);
17001706 }
17011707 const index = inst.toIndex().?;
17021708 return air.typeOfIndex(index, &pt.zcu.intern_pool).onePossibleValue(pt);
src/Air/Legalize.zig+653-230
......@@ -4,6 +4,43 @@ air_extra: std.ArrayListUnmanaged(u32),
44features: *const Features,
55
66pub const Feature = enum {
7 scalarize_add,
8 scalarize_add_safe,
9 scalarize_add_optimized,
10 scalarize_add_wrap,
11 scalarize_add_sat,
12 scalarize_sub,
13 scalarize_sub_safe,
14 scalarize_sub_optimized,
15 scalarize_sub_wrap,
16 scalarize_sub_sat,
17 scalarize_mul,
18 scalarize_mul_safe,
19 scalarize_mul_optimized,
20 scalarize_mul_wrap,
21 scalarize_mul_sat,
22 scalarize_div_float,
23 scalarize_div_float_optimized,
24 scalarize_div_trunc,
25 scalarize_div_trunc_optimized,
26 scalarize_div_floor,
27 scalarize_div_floor_optimized,
28 scalarize_div_exact,
29 scalarize_div_exact_optimized,
30 scalarize_rem,
31 scalarize_rem_optimized,
32 scalarize_mod,
33 scalarize_mod_optimized,
34 scalarize_max,
35 scalarize_min,
36 scalarize_bit_and,
37 scalarize_bit_or,
38 scalarize_shr,
39 scalarize_shr_exact,
40 scalarize_shl,
41 scalarize_shl_exact,
42 scalarize_shl_sat,
43 scalarize_xor,
744 scalarize_not,
845 scalarize_clz,
946 scalarize_ctz,
......@@ -26,41 +63,110 @@ pub const Feature = enum {
2663 scalarize_trunc_float,
2764 scalarize_neg,
2865 scalarize_neg_optimized,
66 scalarize_cmp_vector,
67 scalarize_cmp_vector_optimized,
68 scalarize_fptrunc,
69 scalarize_fpext,
70 scalarize_intcast,
71 scalarize_intcast_safe,
72 scalarize_trunc,
73 scalarize_int_from_float,
74 scalarize_int_from_float_optimized,
75 scalarize_float_from_int,
76 scalarize_mul_add,
2977
3078 /// Legalize (shift lhs, (splat rhs)) -> (shift lhs, rhs)
3179 remove_shift_vector_rhs_splat,
3280 /// Legalize reduce of a one element vector to a bitcast
3381 reduce_one_elem_to_bitcast,
82
83 fn scalarize(tag: Air.Inst.Tag) Feature {
84 return switch (tag) {
85 else => unreachable,
86 .add => .scalarize_add,
87 .add_safe => .scalarize_add_safe,
88 .add_optimized => .scalarize_add_optimized,
89 .add_wrap => .scalarize_add_wrap,
90 .add_sat => .scalarize_add_sat,
91 .sub => .scalarize_sub,
92 .sub_safe => .scalarize_sub_safe,
93 .sub_optimized => .scalarize_sub_optimized,
94 .sub_wrap => .scalarize_sub_wrap,
95 .sub_sat => .scalarize_sub_sat,
96 .mul => .scalarize_mul,
97 .mul_safe => .scalarize_mul_safe,
98 .mul_optimized => .scalarize_mul_optimized,
99 .mul_wrap => .scalarize_mul_wrap,
100 .mul_sat => .scalarize_mul_sat,
101 .div_float => .scalarize_div_float,
102 .div_float_optimized => .scalarize_div_float_optimized,
103 .div_trunc => .scalarize_div_trunc,
104 .div_trunc_optimized => .scalarize_div_trunc_optimized,
105 .div_floor => .scalarize_div_floor,
106 .div_floor_optimized => .scalarize_div_floor_optimized,
107 .div_exact => .scalarize_div_exact,
108 .div_exact_optimized => .scalarize_div_exact_optimized,
109 .rem => .scalarize_rem,
110 .rem_optimized => .scalarize_rem_optimized,
111 .mod => .scalarize_mod,
112 .mod_optimized => .scalarize_mod_optimized,
113 .max => .scalarize_max,
114 .min => .scalarize_min,
115 .bit_and => .scalarize_bit_and,
116 .bit_or => .scalarize_bit_or,
117 .shr => .scalarize_shr,
118 .shr_exact => .scalarize_shr_exact,
119 .shl => .scalarize_shl,
120 .shl_exact => .scalarize_shl_exact,
121 .shl_sat => .scalarize_shl_sat,
122 .xor => .scalarize_xor,
123 .not => .scalarize_not,
124 .clz => .scalarize_clz,
125 .ctz => .scalarize_ctz,
126 .popcount => .scalarize_popcount,
127 .byte_swap => .scalarize_byte_swap,
128 .bit_reverse => .scalarize_bit_reverse,
129 .sqrt => .scalarize_sqrt,
130 .sin => .scalarize_sin,
131 .cos => .scalarize_cos,
132 .tan => .scalarize_tan,
133 .exp => .scalarize_exp,
134 .exp2 => .scalarize_exp2,
135 .log => .scalarize_log,
136 .log2 => .scalarize_log2,
137 .log10 => .scalarize_log10,
138 .abs => .scalarize_abs,
139 .floor => .scalarize_floor,
140 .ceil => .scalarize_ceil,
141 .round => .scalarize_round,
142 .trunc_float => .scalarize_trunc_float,
143 .neg => .scalarize_neg,
144 .neg_optimized => .scalarize_neg_optimized,
145 .cmp_vector => .scalarize_cmp_vector,
146 .cmp_vector_optimized => .scalarize_cmp_vector_optimized,
147 .fptrunc => .scalarize_fptrunc,
148 .fpext => .scalarize_fpext,
149 .intcast => .scalarize_intcast,
150 .intcast_safe => .scalarize_intcast_safe,
151 .trunc => .scalarize_trunc,
152 .int_from_float => .scalarize_int_from_float,
153 .int_from_float_optimized => .scalarize_int_from_float_optimized,
154 .float_from_int => .scalarize_float_from_int,
155 .mul_add => .scalarize_mul_add,
156 };
157 }
34158};
35159
36160pub const Features = std.enums.EnumSet(Feature);
37161
38162pub const Error = std.mem.Allocator.Error;
39163
40pub fn legalize(air: *Air, backend: std.builtin.CompilerBackend, pt: Zcu.PerThread) Error!void {
164pub fn legalize(air: *Air, pt: Zcu.PerThread, features: *const Features) Error!void {
41165 var l: Legalize = .{
42166 .pt = pt,
43167 .air_instructions = air.instructions.toMultiArrayList(),
44168 .air_extra = air.extra,
45 .features = &features: switch (backend) {
46 .other, .stage1 => unreachable,
47 inline .stage2_llvm,
48 .stage2_c,
49 .stage2_wasm,
50 .stage2_arm,
51 .stage2_x86_64,
52 .stage2_aarch64,
53 .stage2_x86,
54 .stage2_riscv64,
55 .stage2_sparc64,
56 .stage2_spirv64,
57 .stage2_powerpc,
58 => |ct_backend| {
59 const Backend = codegen.importBackend(ct_backend) orelse break :features .initEmpty();
60 break :features if (@hasDecl(Backend, "legalize_features")) Backend.legalize_features else .initEmpty();
61 },
62 _ => unreachable,
63 },
169 .features = features,
64170 };
65171 if (l.features.bits.eql(.initEmpty())) return;
66172 defer air.* = l.getTmpAir();
......@@ -90,11 +196,93 @@ fn extraData(l: *const Legalize, comptime T: type, index: usize) @TypeOf(Air.ext
90196fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
91197 const zcu = l.pt.zcu;
92198 const ip = &zcu.intern_pool;
93 for (body_start..body_start + body_len) |inst_extra_index| {
94 const inst: Air.Inst.Index = @enumFromInt(l.air_extra.items[inst_extra_index]);
199 for (0..body_len) |body_index| {
200 const inst: Air.Inst.Index = @enumFromInt(l.air_extra.items[body_start + body_index]);
95201 inst: switch (l.air_instructions.items(.tag)[@intFromEnum(inst)]) {
96 else => {},
97
202 .arg,
203 => {},
204 inline .add,
205 .add_safe,
206 .add_optimized,
207 .add_wrap,
208 .add_sat,
209 .sub,
210 .sub_safe,
211 .sub_optimized,
212 .sub_wrap,
213 .sub_sat,
214 .mul,
215 .mul_safe,
216 .mul_optimized,
217 .mul_wrap,
218 .mul_sat,
219 .div_float,
220 .div_float_optimized,
221 .div_trunc,
222 .div_trunc_optimized,
223 .div_floor,
224 .div_floor_optimized,
225 .div_exact,
226 .div_exact_optimized,
227 .rem,
228 .rem_optimized,
229 .mod,
230 .mod_optimized,
231 .max,
232 .min,
233 .bit_and,
234 .bit_or,
235 .xor,
236 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
237 const bin_op = l.air_instructions.items(.data)[@intFromEnum(inst)].bin_op;
238 if (l.typeOf(bin_op.lhs).isVector(zcu)) continue :inst try l.scalarize(inst, .bin_op);
239 },
240 .ptr_add,
241 .ptr_sub,
242 .add_with_overflow,
243 .sub_with_overflow,
244 .mul_with_overflow,
245 .shl_with_overflow,
246 .alloc,
247 => {},
248 .inferred_alloc,
249 .inferred_alloc_comptime,
250 => unreachable,
251 .ret_ptr,
252 .assembly,
253 => {},
254 inline .shr,
255 .shr_exact,
256 .shl,
257 .shl_exact,
258 .shl_sat,
259 => |air_tag| done: {
260 const bin_op = l.air_instructions.items(.data)[@intFromEnum(inst)].bin_op;
261 if (!l.typeOf(bin_op.rhs).isVector(zcu)) break :done;
262 if (l.features.contains(comptime .scalarize(air_tag))) {
263 continue :inst try l.scalarize(inst, .bin_op);
264 } else if (l.features.contains(.remove_shift_vector_rhs_splat)) {
265 if (bin_op.rhs.toInterned()) |rhs_ip_index| switch (ip.indexToKey(rhs_ip_index)) {
266 else => {},
267 .aggregate => |aggregate| switch (aggregate.storage) {
268 else => {},
269 .repeated_elem => |splat| continue :inst l.replaceInst(inst, air_tag, .{ .bin_op = .{
270 .lhs = bin_op.lhs,
271 .rhs = Air.internedToRef(splat),
272 } }),
273 },
274 } else {
275 const rhs_inst = bin_op.rhs.toIndex().?;
276 switch (l.air_instructions.items(.tag)[@intFromEnum(rhs_inst)]) {
277 else => {},
278 .splat => continue :inst l.replaceInst(inst, air_tag, .{ .bin_op = .{
279 .lhs = bin_op.lhs,
280 .rhs = l.air_instructions.items(.data)[@intFromEnum(rhs_inst)].ty_op.operand,
281 } }),
282 }
283 }
284 }
285 },
98286 inline .not,
99287 .clz,
100288 .ctz,
......@@ -102,11 +290,38 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
102290 .byte_swap,
103291 .bit_reverse,
104292 .abs,
105 => |air_tag| if (l.features.contains(@field(Feature, "scalarize_" ++ @tagName(air_tag)))) done: {
293 .fptrunc,
294 .fpext,
295 .intcast,
296 .intcast_safe,
297 .trunc,
298 .int_from_float,
299 .int_from_float_optimized,
300 .float_from_int,
301 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
106302 const ty_op = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_op;
107 if (!ty_op.ty.toType().isVector(zcu)) break :done;
108 continue :inst try l.scalarizeUnary(inst, .ty_op, ty_op.operand);
303 if (ty_op.ty.toType().isVector(zcu)) continue :inst try l.scalarize(inst, .ty_op);
109304 },
305 .bitcast,
306 => {},
307 .block,
308 .loop,
309 => {
310 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
311 const extra = l.extraData(Air.Block, ty_pl.payload);
312 try l.legalizeBody(extra.end, extra.data.body_len);
313 },
314 .repeat,
315 .br,
316 .trap,
317 .breakpoint,
318 .ret_addr,
319 .frame_addr,
320 .call,
321 .call_always_tail,
322 .call_never_tail,
323 .call_never_inline,
324 => {},
110325 inline .sqrt,
111326 .sin,
112327 .cos,
......@@ -122,84 +337,39 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
122337 .trunc_float,
123338 .neg,
124339 .neg_optimized,
125 => |air_tag| if (l.features.contains(@field(Feature, "scalarize_" ++ @tagName(air_tag)))) done: {
340 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
126341 const un_op = l.air_instructions.items(.data)[@intFromEnum(inst)].un_op;
127 if (!l.typeOf(un_op).isVector(zcu)) break :done;
128 continue :inst try l.scalarizeUnary(inst, .un_op, un_op);
129 },
130
131 .shl,
132 .shl_exact,
133 .shl_sat,
134 .shr,
135 .shr_exact,
136 => |air_tag| if (l.features.contains(.remove_shift_vector_rhs_splat)) done: {
137 const bin_op = l.air_instructions.items(.data)[@intFromEnum(inst)].bin_op;
138 const ty = l.typeOf(bin_op.rhs);
139 if (!ty.isVector(zcu)) break :done;
140 if (bin_op.rhs.toInterned()) |rhs_ip_index| switch (ip.indexToKey(rhs_ip_index)) {
141 else => {},
142 .aggregate => |aggregate| switch (aggregate.storage) {
143 else => {},
144 .repeated_elem => |splat| continue :inst l.replaceInst(inst, air_tag, .{ .bin_op = .{
145 .lhs = bin_op.lhs,
146 .rhs = Air.internedToRef(splat),
147 } }),
148 },
149 } else {
150 const rhs_inst = bin_op.rhs.toIndex().?;
151 switch (l.air_instructions.items(.tag)[@intFromEnum(rhs_inst)]) {
152 else => {},
153 .splat => continue :inst l.replaceInst(inst, air_tag, .{ .bin_op = .{
154 .lhs = bin_op.lhs,
155 .rhs = l.air_instructions.items(.data)[@intFromEnum(rhs_inst)].ty_op.operand,
156 } }),
157 }
158 }
342 if (l.typeOf(un_op).isVector(zcu)) continue :inst try l.scalarize(inst, .un_op);
159343 },
160
161 .reduce,
162 .reduce_optimized,
163 => if (l.features.contains(.reduce_one_elem_to_bitcast)) done: {
164 const reduce = l.air_instructions.items(.data)[@intFromEnum(inst)].reduce;
165 const vector_ty = l.typeOf(reduce.operand);
166 switch (vector_ty.vectorLen(zcu)) {
167 0 => unreachable,
168 1 => continue :inst l.replaceInst(inst, .bitcast, .{ .ty_op = .{
169 .ty = Air.internedToRef(vector_ty.scalarType(zcu).toIntern()),
170 .operand = reduce.operand,
171 } }),
172 else => break :done,
173 }
174 },
175
176 .@"try", .try_cold => {
177 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
178 const extra = l.extraData(Air.Try, pl_op.payload);
179 try l.legalizeBody(extra.end, extra.data.body_len);
180 },
181 .try_ptr, .try_ptr_cold => {
344 .cmp_lt,
345 .cmp_lt_optimized,
346 .cmp_lte,
347 .cmp_lte_optimized,
348 .cmp_eq,
349 .cmp_eq_optimized,
350 .cmp_gte,
351 .cmp_gte_optimized,
352 .cmp_gt,
353 .cmp_gt_optimized,
354 .cmp_neq,
355 .cmp_neq_optimized,
356 => {},
357 inline .cmp_vector,
358 .cmp_vector_optimized,
359 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
182360 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
183 const extra = l.extraData(Air.TryPtr, ty_pl.payload);
184 try l.legalizeBody(extra.end, extra.data.body_len);
185 },
186 .block, .loop => {
187 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
188 const extra = l.extraData(Air.Block, ty_pl.payload);
189 try l.legalizeBody(extra.end, extra.data.body_len);
190 },
191 .dbg_inline_block => {
192 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
193 const extra = l.extraData(Air.DbgInlineBlock, ty_pl.payload);
194 try l.legalizeBody(extra.end, extra.data.body_len);
361 if (ty_pl.ty.toType().isVector(zcu)) continue :inst try l.scalarize(inst, .ty_pl_vector_cmp);
195362 },
196 .cond_br => {
363 .cond_br,
364 => {
197365 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
198366 const extra = l.extraData(Air.CondBr, pl_op.payload);
199367 try l.legalizeBody(extra.end, extra.data.then_body_len);
200368 try l.legalizeBody(extra.end + extra.data.then_body_len, extra.data.else_body_len);
201369 },
202 .switch_br, .loop_switch_br => {
370 .switch_br,
371 .loop_switch_br,
372 => {
203373 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
204374 const extra = l.extraData(Air.SwitchBr, pl_op.payload);
205375 const hint_bag_count = std.math.divCeil(usize, extra.data.cases_len + 1, 10) catch unreachable;
......@@ -212,154 +382,408 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
212382 }
213383 try l.legalizeBody(extra_index, extra.data.else_body_len);
214384 },
385 .switch_dispatch,
386 => {},
387 .@"try",
388 .try_cold,
389 => {
390 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
391 const extra = l.extraData(Air.Try, pl_op.payload);
392 try l.legalizeBody(extra.end, extra.data.body_len);
393 },
394 .try_ptr,
395 .try_ptr_cold,
396 => {
397 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
398 const extra = l.extraData(Air.TryPtr, ty_pl.payload);
399 try l.legalizeBody(extra.end, extra.data.body_len);
400 },
401 .dbg_stmt,
402 .dbg_empty_stmt,
403 => {},
404 .dbg_inline_block,
405 => {
406 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
407 const extra = l.extraData(Air.DbgInlineBlock, ty_pl.payload);
408 try l.legalizeBody(extra.end, extra.data.body_len);
409 },
410 .dbg_var_ptr,
411 .dbg_var_val,
412 .dbg_arg_inline,
413 .is_null,
414 .is_non_null,
415 .is_null_ptr,
416 .is_non_null_ptr,
417 .is_err,
418 .is_non_err,
419 .is_err_ptr,
420 .is_non_err_ptr,
421 .bool_and,
422 .bool_or,
423 .load,
424 .ret,
425 .ret_safe,
426 .ret_load,
427 .store,
428 .store_safe,
429 .unreach,
430 => {},
431 .optional_payload,
432 .optional_payload_ptr,
433 .optional_payload_ptr_set,
434 .wrap_optional,
435 .unwrap_errunion_payload,
436 .unwrap_errunion_err,
437 .unwrap_errunion_payload_ptr,
438 .unwrap_errunion_err_ptr,
439 .errunion_payload_ptr_set,
440 .wrap_errunion_payload,
441 .wrap_errunion_err,
442 .struct_field_ptr,
443 .struct_field_ptr_index_0,
444 .struct_field_ptr_index_1,
445 .struct_field_ptr_index_2,
446 .struct_field_ptr_index_3,
447 .struct_field_val,
448 .set_union_tag,
449 .get_union_tag,
450 .slice,
451 .slice_len,
452 .slice_ptr,
453 .ptr_slice_len_ptr,
454 .ptr_slice_ptr_ptr,
455 .array_elem_val,
456 .slice_elem_val,
457 .slice_elem_ptr,
458 .ptr_elem_val,
459 .ptr_elem_ptr,
460 .array_to_slice,
461 => {},
462 .reduce,
463 .reduce_optimized,
464 => if (l.features.contains(.reduce_one_elem_to_bitcast)) done: {
465 const reduce = l.air_instructions.items(.data)[@intFromEnum(inst)].reduce;
466 const vector_ty = l.typeOf(reduce.operand);
467 switch (vector_ty.vectorLen(zcu)) {
468 0 => unreachable,
469 1 => continue :inst l.replaceInst(inst, .bitcast, .{ .ty_op = .{
470 .ty = Air.internedToRef(vector_ty.scalarType(zcu).toIntern()),
471 .operand = reduce.operand,
472 } }),
473 else => break :done,
474 }
475 },
476 .splat,
477 .shuffle,
478 .select,
479 .memset,
480 .memset_safe,
481 .memcpy,
482 .memmove,
483 .cmpxchg_weak,
484 .cmpxchg_strong,
485 .atomic_load,
486 .atomic_store_unordered,
487 .atomic_store_monotonic,
488 .atomic_store_release,
489 .atomic_store_seq_cst,
490 .atomic_rmw,
491 .is_named_enum_value,
492 .tag_name,
493 .error_name,
494 .error_set_has_value,
495 .aggregate_init,
496 .union_init,
497 .prefetch,
498 => {},
499 inline .mul_add,
500 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
501 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
502 if (l.typeOf(pl_op.operand).isVector(zcu)) continue :inst try l.scalarize(inst, .pl_op_bin);
503 },
504 .field_parent_ptr,
505 .wasm_memory_size,
506 .wasm_memory_grow,
507 .cmp_lt_errors_len,
508 .err_return_trace,
509 .set_err_return_trace,
510 .addrspace_cast,
511 .save_err_return_trace_index,
512 .vector_store_elem,
513 .tlv_dllimport_ptr,
514 .c_va_arg,
515 .c_va_copy,
516 .c_va_end,
517 .c_va_start,
518 .work_item_id,
519 .work_group_size,
520 .work_group_id,
521 => {},
215522 }
216523 }
217524}
218525
219const UnaryDataTag = enum { un_op, ty_op };
220inline fn scalarizeUnary(l: *Legalize, inst: Air.Inst.Index, data_tag: UnaryDataTag, un_op: Air.Inst.Ref) Error!Air.Inst.Tag {
221 return l.replaceInst(inst, .block, try l.scalarizeUnaryBlockPayload(inst, data_tag, un_op));
526const ScalarizeDataTag = enum { un_op, ty_op, bin_op, ty_pl_vector_cmp, pl_op_bin };
527inline fn scalarize(l: *Legalize, orig_inst: Air.Inst.Index, comptime data_tag: ScalarizeDataTag) Error!Air.Inst.Tag {
528 return l.replaceInst(orig_inst, .block, try l.scalarizeBlockPayload(orig_inst, data_tag));
222529}
223fn scalarizeUnaryBlockPayload(
224 l: *Legalize,
225 inst: Air.Inst.Index,
226 data_tag: UnaryDataTag,
227 un_op: Air.Inst.Ref,
228) Error!Air.Inst.Data {
530fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime data_tag: ScalarizeDataTag) Error!Air.Inst.Data {
229531 const pt = l.pt;
230532 const zcu = pt.zcu;
231533 const gpa = zcu.gpa;
232534
233 const res_ty = l.typeOfIndex(inst);
234 try l.air_instructions.ensureUnusedCapacity(gpa, 15);
235 const res_alloc_inst = l.addInstAssumeCapacity(.{
236 .tag = .alloc,
237 .data = .{ .ty = try pt.singleMutPtrType(res_ty) },
238 });
239 const index_alloc_inst = l.addInstAssumeCapacity(.{
240 .tag = .alloc,
241 .data = .{ .ty = try pt.singleMutPtrType(.usize) },
242 });
243 const index_init_inst = l.addInstAssumeCapacity(.{
244 .tag = .store,
245 .data = .{ .bin_op = .{
246 .lhs = index_alloc_inst.toRef(),
247 .rhs = try pt.intRef(.usize, 0),
248 } },
249 });
250 const cur_index_inst = l.addInstAssumeCapacity(.{
251 .tag = .load,
252 .data = .{ .ty_op = .{
253 .ty = .usize_type,
254 .operand = index_alloc_inst.toRef(),
255 } },
256 });
257 const get_elem_inst = l.addInstAssumeCapacity(.{
258 .tag = .array_elem_val,
259 .data = .{ .bin_op = .{
260 .lhs = un_op,
261 .rhs = cur_index_inst.toRef(),
262 } },
263 });
264 const op_elem_inst = l.addInstAssumeCapacity(.{
265 .tag = l.air_instructions.items(.tag)[@intFromEnum(inst)],
266 .data = switch (data_tag) {
267 .un_op => .{ .un_op = get_elem_inst.toRef() },
268 .ty_op => .{ .ty_op = .{
269 .ty = Air.internedToRef(res_ty.scalarType(zcu).toIntern()),
270 .operand = get_elem_inst.toRef(),
535 const orig = l.air_instructions.get(@intFromEnum(orig_inst));
536 const res_ty = l.typeOfIndex(orig_inst);
537 const arity = switch (data_tag) {
538 .un_op, .ty_op => 1,
539 .bin_op, .ty_pl_vector_cmp => 2,
540 .pl_op_bin => 3,
541 };
542 const expected_instructions_len = l.air_instructions.len + (6 + arity + 8);
543 try l.air_instructions.ensureTotalCapacity(gpa, expected_instructions_len);
544
545 var res_block: Block(4) = .empty;
546 {
547 const res_alloc_inst = res_block.add(l.addInstAssumeCapacity(.{
548 .tag = .alloc,
549 .data = .{ .ty = try pt.singleMutPtrType(res_ty) },
550 }));
551 const index_alloc_inst = res_block.add(l.addInstAssumeCapacity(.{
552 .tag = .alloc,
553 .data = .{ .ty = .ptr_usize },
554 }));
555 _ = res_block.add(l.addInstAssumeCapacity(.{
556 .tag = .store,
557 .data = .{ .bin_op = .{
558 .lhs = index_alloc_inst.toRef(),
559 .rhs = .zero_usize,
271560 } },
272 },
273 });
274 const set_elem_inst = l.addInstAssumeCapacity(.{
275 .tag = .vector_store_elem,
276 .data = .{ .vector_store_elem = .{
277 .vector_ptr = res_alloc_inst.toRef(),
278 .payload = try l.addExtra(Air.Bin, .{
279 .lhs = cur_index_inst.toRef(),
280 .rhs = op_elem_inst.toRef(),
281 }),
282 } },
283 });
284 const not_done_inst = l.addInstAssumeCapacity(.{
285 .tag = .cmp_lt,
286 .data = .{ .bin_op = .{
287 .lhs = cur_index_inst.toRef(),
288 .rhs = try pt.intRef(.usize, res_ty.vectorLen(zcu)),
289 } },
290 });
291 const next_index_inst = l.addInstAssumeCapacity(.{
292 .tag = .add,
293 .data = .{ .bin_op = .{
294 .lhs = cur_index_inst.toRef(),
295 .rhs = try pt.intRef(.usize, 1),
296 } },
297 });
298 const set_index_inst = l.addInstAssumeCapacity(.{
299 .tag = .store,
300 .data = .{ .bin_op = .{
301 .lhs = index_alloc_inst.toRef(),
302 .rhs = next_index_inst.toRef(),
303 } },
304 });
305 const loop_inst: Air.Inst.Index = @enumFromInt(l.air_instructions.len + 4);
306 const repeat_inst = l.addInstAssumeCapacity(.{
307 .tag = .repeat,
308 .data = .{ .repeat = .{ .loop_inst = loop_inst } },
309 });
310 const final_res_inst = l.addInstAssumeCapacity(.{
311 .tag = .load,
312 .data = .{ .ty_op = .{
313 .ty = Air.internedToRef(res_ty.toIntern()),
314 .operand = res_alloc_inst.toRef(),
315 } },
316 });
317 const br_res_inst = l.addInstAssumeCapacity(.{
318 .tag = .br,
319 .data = .{ .br = .{
320 .block_inst = inst,
321 .operand = final_res_inst.toRef(),
322 } },
323 });
324 const done_br_inst = l.addInstAssumeCapacity(.{
325 .tag = .cond_br,
326 .data = .{ .pl_op = .{
327 .operand = not_done_inst.toRef(),
328 .payload = try l.addCondBrBodies(&.{
329 next_index_inst,
330 set_index_inst,
331 repeat_inst,
332 }, &.{
333 final_res_inst,
334 br_res_inst,
335 }),
336 } },
337 });
338 assert(loop_inst == l.addInstAssumeCapacity(.{
339 .tag = .loop,
340 .data = .{ .ty_pl = .{
341 .ty = .noreturn_type,
342 .payload = try l.addBlockBody(&.{
343 cur_index_inst,
344 get_elem_inst,
345 op_elem_inst,
346 set_elem_inst,
347 not_done_inst,
348 done_br_inst,
349 }),
350 } },
351 }));
561 }));
562
563 const loop_inst: Air.Inst.Index = @enumFromInt(l.air_instructions.len + (3 + arity + 7));
564 var loop_block: Block(3 + arity + 2) = .empty;
565 {
566 const cur_index_inst = loop_block.add(l.addInstAssumeCapacity(.{
567 .tag = .load,
568 .data = .{ .ty_op = .{
569 .ty = .usize_type,
570 .operand = index_alloc_inst.toRef(),
571 } },
572 }));
573 _ = loop_block.add(l.addInstAssumeCapacity(.{
574 .tag = .vector_store_elem,
575 .data = .{ .vector_store_elem = .{
576 .vector_ptr = res_alloc_inst.toRef(),
577 .payload = try l.addExtra(Air.Bin, .{
578 .lhs = cur_index_inst.toRef(),
579 .rhs = loop_block.add(l.addInstAssumeCapacity(res_elem: switch (data_tag) {
580 .un_op => .{
581 .tag = orig.tag,
582 .data = .{ .un_op = loop_block.add(l.addInstAssumeCapacity(.{
583 .tag = .array_elem_val,
584 .data = .{ .bin_op = .{
585 .lhs = orig.data.un_op,
586 .rhs = cur_index_inst.toRef(),
587 } },
588 })).toRef() },
589 },
590 .ty_op => .{
591 .tag = orig.tag,
592 .data = .{ .ty_op = .{
593 .ty = Air.internedToRef(orig.data.ty_op.ty.toType().scalarType(zcu).toIntern()),
594 .operand = loop_block.add(l.addInstAssumeCapacity(.{
595 .tag = .array_elem_val,
596 .data = .{ .bin_op = .{
597 .lhs = orig.data.ty_op.operand,
598 .rhs = cur_index_inst.toRef(),
599 } },
600 })).toRef(),
601 } },
602 },
603 .bin_op => .{
604 .tag = orig.tag,
605 .data = .{ .bin_op = .{
606 .lhs = loop_block.add(l.addInstAssumeCapacity(.{
607 .tag = .array_elem_val,
608 .data = .{ .bin_op = .{
609 .lhs = orig.data.bin_op.lhs,
610 .rhs = cur_index_inst.toRef(),
611 } },
612 })).toRef(),
613 .rhs = loop_block.add(l.addInstAssumeCapacity(.{
614 .tag = .array_elem_val,
615 .data = .{ .bin_op = .{
616 .lhs = orig.data.bin_op.rhs,
617 .rhs = cur_index_inst.toRef(),
618 } },
619 })).toRef(),
620 } },
621 },
622 .ty_pl_vector_cmp => {
623 const extra = l.extraData(Air.VectorCmp, orig.data.ty_pl.payload).data;
624 break :res_elem .{
625 .tag = switch (orig.tag) {
626 else => unreachable,
627 .cmp_vector => switch (extra.compareOperator()) {
628 .lt => .cmp_lt,
629 .lte => .cmp_lte,
630 .eq => .cmp_eq,
631 .gte => .cmp_gte,
632 .gt => .cmp_gt,
633 .neq => .cmp_neq,
634 },
635 .cmp_vector_optimized => switch (extra.compareOperator()) {
636 .lt => .cmp_lt_optimized,
637 .lte => .cmp_lte_optimized,
638 .eq => .cmp_eq_optimized,
639 .gte => .cmp_gte_optimized,
640 .gt => .cmp_gt_optimized,
641 .neq => .cmp_neq_optimized,
642 },
643 },
644 .data = .{ .bin_op = .{
645 .lhs = loop_block.add(l.addInstAssumeCapacity(.{
646 .tag = .array_elem_val,
647 .data = .{ .bin_op = .{
648 .lhs = extra.lhs,
649 .rhs = cur_index_inst.toRef(),
650 } },
651 })).toRef(),
652 .rhs = loop_block.add(l.addInstAssumeCapacity(.{
653 .tag = .array_elem_val,
654 .data = .{ .bin_op = .{
655 .lhs = extra.rhs,
656 .rhs = cur_index_inst.toRef(),
657 } },
658 })).toRef(),
659 } },
660 };
661 },
662 .pl_op_bin => {
663 const extra = l.extraData(Air.Bin, orig.data.pl_op.payload).data;
664 break :res_elem .{
665 .tag = orig.tag,
666 .data = .{ .pl_op = .{
667 .payload = try l.addExtra(Air.Bin, .{
668 .lhs = loop_block.add(l.addInstAssumeCapacity(.{
669 .tag = .array_elem_val,
670 .data = .{ .bin_op = .{
671 .lhs = extra.lhs,
672 .rhs = cur_index_inst.toRef(),
673 } },
674 })).toRef(),
675 .rhs = loop_block.add(l.addInstAssumeCapacity(.{
676 .tag = .array_elem_val,
677 .data = .{ .bin_op = .{
678 .lhs = extra.rhs,
679 .rhs = cur_index_inst.toRef(),
680 } },
681 })).toRef(),
682 }),
683 .operand = loop_block.add(l.addInstAssumeCapacity(.{
684 .tag = .array_elem_val,
685 .data = .{ .bin_op = .{
686 .lhs = orig.data.pl_op.operand,
687 .rhs = cur_index_inst.toRef(),
688 } },
689 })).toRef(),
690 } },
691 };
692 },
693 })).toRef(),
694 }),
695 } },
696 }));
697 const not_done_inst = loop_block.add(l.addInstAssumeCapacity(.{
698 .tag = .cmp_lt,
699 .data = .{ .bin_op = .{
700 .lhs = cur_index_inst.toRef(),
701 .rhs = try pt.intRef(.usize, res_ty.vectorLen(zcu) - 1),
702 } },
703 }));
704
705 var not_done_block: Block(3) = .empty;
706 {
707 _ = not_done_block.add(l.addInstAssumeCapacity(.{
708 .tag = .store,
709 .data = .{ .bin_op = .{
710 .lhs = index_alloc_inst.toRef(),
711 .rhs = not_done_block.add(l.addInstAssumeCapacity(.{
712 .tag = .add,
713 .data = .{ .bin_op = .{
714 .lhs = cur_index_inst.toRef(),
715 .rhs = .one_usize,
716 } },
717 })).toRef(),
718 } },
719 }));
720 _ = not_done_block.add(l.addInstAssumeCapacity(.{
721 .tag = .repeat,
722 .data = .{ .repeat = .{ .loop_inst = loop_inst } },
723 }));
724 }
725 var done_block: Block(2) = .empty;
726 {
727 _ = done_block.add(l.addInstAssumeCapacity(.{
728 .tag = .br,
729 .data = .{ .br = .{
730 .block_inst = orig_inst,
731 .operand = done_block.add(l.addInstAssumeCapacity(.{
732 .tag = .load,
733 .data = .{ .ty_op = .{
734 .ty = Air.internedToRef(res_ty.toIntern()),
735 .operand = res_alloc_inst.toRef(),
736 } },
737 })).toRef(),
738 } },
739 }));
740 }
741 _ = loop_block.add(l.addInstAssumeCapacity(.{
742 .tag = .cond_br,
743 .data = .{ .pl_op = .{
744 .operand = not_done_inst.toRef(),
745 .payload = try l.addCondBrBodies(not_done_block.body(), done_block.body()),
746 } },
747 }));
748 }
749 assert(loop_inst == res_block.add(l.addInstAssumeCapacity(.{
750 .tag = .loop,
751 .data = .{ .ty_pl = .{
752 .ty = .noreturn_type,
753 .payload = try l.addBlockBody(loop_block.body()),
754 } },
755 })));
756 }
757 assert(l.air_instructions.len == expected_instructions_len);
352758 return .{ .ty_pl = .{
353759 .ty = Air.internedToRef(res_ty.toIntern()),
354 .payload = try l.addBlockBody(&.{
355 res_alloc_inst,
356 index_alloc_inst,
357 index_init_inst,
358 loop_inst,
359 }),
760 .payload = try l.addBlockBody(res_block.body()),
360761 } };
361762}
362763
764fn Block(comptime capacity: usize) type {
765 return struct {
766 instructions: [capacity]Air.Inst.Index,
767 len: usize,
768
769 const empty: @This() = .{
770 .instructions = undefined,
771 .len = 0,
772 };
773
774 fn add(b: *@This(), inst: Air.Inst.Index) Air.Inst.Index {
775 b.instructions[b.len] = inst;
776 b.len += 1;
777 return inst;
778 }
779
780 fn body(b: *const @This()) []const Air.Inst.Index {
781 assert(b.len == b.instructions.len);
782 return &b.instructions;
783 }
784 };
785}
786
363787fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {
364788 defer l.air_instructions.appendAssumeCapacity(inst);
365789 return @enumFromInt(l.air_instructions.len);
......@@ -414,7 +838,6 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat
414838
415839const Air = @import("../Air.zig");
416840const assert = std.debug.assert;
417const codegen = @import("../codegen.zig");
418841const Legalize = @This();
419842const std = @import("std");
420843const Type = @import("../Type.zig");
src/InternPool.zig+60-24
......@@ -4579,10 +4579,11 @@ pub const Index = enum(u32) {
45794579 undefined_type,
45804580 enum_literal_type,
45814581
4582 ptr_usize_type,
4583 ptr_const_comptime_int_type,
45824584 manyptr_u8_type,
45834585 manyptr_const_u8_type,
45844586 manyptr_const_u8_sentinel_0_type,
4585 single_const_pointer_to_comptime_int_type,
45864587 slice_const_u8_type,
45874588 slice_const_u8_sentinel_0_type,
45884589
......@@ -4649,19 +4650,29 @@ pub const Index = enum(u32) {
46494650
46504651 /// `undefined` (untyped)
46514652 undef,
4653 /// `@as(bool, undefined)`
4654 undef_bool,
4655 /// `@as(usize, undefined)`
4656 undef_usize,
4657 /// `@as(u1, undefined)`
4658 undef_u1,
46524659 /// `0` (comptime_int)
46534660 zero,
4654 /// `0` (usize)
4661 /// `@as(usize, 0)`
46554662 zero_usize,
4656 /// `0` (u8)
4663 /// `@as(u1, 0)`
4664 zero_u1,
4665 /// `@as(u8, 0)`
46574666 zero_u8,
46584667 /// `1` (comptime_int)
46594668 one,
4660 /// `1` (usize)
4669 /// `@as(usize, 1)`
46614670 one_usize,
4662 /// `1` (u8)
4671 /// `@as(u1, 1)`
4672 one_u1,
4673 /// `@as(u8, 1)`
46634674 one_u8,
4664 /// `4` (u8)
4675 /// `@as(u8, 4)`
46654676 four_u8,
46664677 /// `-1` (comptime_int)
46674678 negative_one,
......@@ -5074,6 +5085,20 @@ pub const static_keys: [static_len]Key = .{
50745085 .{ .simple_type = .undefined },
50755086 .{ .simple_type = .enum_literal },
50765087
5088 // *usize
5089 .{ .ptr_type = .{
5090 .child = .usize_type,
5091 .flags = .{},
5092 } },
5093
5094 // *const comptime_int
5095 .{ .ptr_type = .{
5096 .child = .comptime_int_type,
5097 .flags = .{
5098 .is_const = true,
5099 },
5100 } },
5101
50775102 // [*]u8
50785103 .{ .ptr_type = .{
50795104 .child = .u8_type,
......@@ -5101,15 +5126,6 @@ pub const static_keys: [static_len]Key = .{
51015126 },
51025127 } },
51035128
5104 // *const comptime_int
5105 .{ .ptr_type = .{
5106 .child = .comptime_int_type,
5107 .flags = .{
5108 .size = .one,
5109 .is_const = true,
5110 },
5111 } },
5112
51135129 // []const u8
51145130 .{ .ptr_type = .{
51155131 .child = .u8_type,
......@@ -5245,6 +5261,9 @@ pub const static_keys: [static_len]Key = .{
52455261 } },
52465262
52475263 .{ .simple_value = .undefined },
5264 .{ .undef = .bool_type },
5265 .{ .undef = .usize_type },
5266 .{ .undef = .u1_type },
52485267
52495268 .{ .int = .{
52505269 .ty = .comptime_int_type,
......@@ -5256,6 +5275,11 @@ pub const static_keys: [static_len]Key = .{
52565275 .storage = .{ .u64 = 0 },
52575276 } },
52585277
5278 .{ .int = .{
5279 .ty = .u1_type,
5280 .storage = .{ .u64 = 0 },
5281 } },
5282
52595283 .{ .int = .{
52605284 .ty = .u8_type,
52615285 .storage = .{ .u64 = 0 },
......@@ -5271,17 +5295,21 @@ pub const static_keys: [static_len]Key = .{
52715295 .storage = .{ .u64 = 1 },
52725296 } },
52735297
5274 // one_u8
5298 .{ .int = .{
5299 .ty = .u1_type,
5300 .storage = .{ .u64 = 1 },
5301 } },
5302
52755303 .{ .int = .{
52765304 .ty = .u8_type,
52775305 .storage = .{ .u64 = 1 },
52785306 } },
5279 // four_u8
5307
52805308 .{ .int = .{
52815309 .ty = .u8_type,
52825310 .storage = .{ .u64 = 4 },
52835311 } },
5284 // negative_one
5312
52855313 .{ .int = .{
52865314 .ty = .comptime_int_type,
52875315 .storage = .{ .i64 = -1 },
......@@ -10482,7 +10510,7 @@ pub fn getCoerced(
1048210510 .base_addr = .int,
1048310511 .byte_offset = 0,
1048410512 } }),
10485 .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),
10513 .len = .undef_usize,
1048610514 } }),
1048710515 };
1048810516 },
......@@ -10601,7 +10629,7 @@ pub fn getCoerced(
1060110629 .base_addr = .int,
1060210630 .byte_offset = 0,
1060310631 } }),
10604 .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),
10632 .len = .undef_usize,
1060510633 } }),
1060610634 },
1060710635 else => |payload| try ip.getCoerced(gpa, tid, payload, new_ty),
......@@ -11847,10 +11875,11 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1184711875 .null_type,
1184811876 .undefined_type,
1184911877 .enum_literal_type,
11878 .ptr_usize_type,
11879 .ptr_const_comptime_int_type,
1185011880 .manyptr_u8_type,
1185111881 .manyptr_const_u8_type,
1185211882 .manyptr_const_u8_sentinel_0_type,
11853 .single_const_pointer_to_comptime_int_type,
1185411883 .slice_const_u8_type,
1185511884 .slice_const_u8_sentinel_0_type,
1185611885 .vector_8_i8_type,
......@@ -11909,12 +11938,13 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1190911938
1191011939 .undef => .undefined_type,
1191111940 .zero, .one, .negative_one => .comptime_int_type,
11912 .zero_usize, .one_usize => .usize_type,
11941 .undef_usize, .zero_usize, .one_usize => .usize_type,
11942 .undef_u1, .zero_u1, .one_u1 => .u1_type,
1191311943 .zero_u8, .one_u8, .four_u8 => .u8_type,
1191411944 .void_value => .void_type,
1191511945 .unreachable_value => .noreturn_type,
1191611946 .null_value => .null_type,
11917 .bool_true, .bool_false => .bool_type,
11947 .undef_bool, .bool_true, .bool_false => .bool_type,
1191811948 .empty_tuple => .empty_tuple_type,
1191911949
1192011950 // This optimization on tags is needed so that indexToKey can call
......@@ -12186,10 +12216,11 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
1218612216 .undefined_type => .undefined,
1218712217 .enum_literal_type => .enum_literal,
1218812218
12219 .ptr_usize_type,
12220 .ptr_const_comptime_int_type,
1218912221 .manyptr_u8_type,
1219012222 .manyptr_const_u8_type,
1219112223 .manyptr_const_u8_sentinel_0_type,
12192 .single_const_pointer_to_comptime_int_type,
1219312224 .slice_const_u8_type,
1219412225 .slice_const_u8_sentinel_0_type,
1219512226 => .pointer,
......@@ -12251,11 +12282,16 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
1225112282
1225212283 // values, not types
1225312284 .undef => unreachable,
12285 .undef_bool => unreachable,
12286 .undef_usize => unreachable,
12287 .undef_u1 => unreachable,
1225412288 .zero => unreachable,
1225512289 .zero_usize => unreachable,
12290 .zero_u1 => unreachable,
1225612291 .zero_u8 => unreachable,
1225712292 .one => unreachable,
1225812293 .one_usize => unreachable,
12294 .one_u1 => unreachable,
1225912295 .one_u8 => unreachable,
1226012296 .four_u8 => unreachable,
1226112297 .negative_one => unreachable,
src/Sema.zig+372-382
......@@ -1881,7 +1881,7 @@ fn analyzeBodyInner(
18811881 extra.data.else_body_len,
18821882 );
18831883 const uncasted_cond = try sema.resolveInst(extra.data.condition);
1884 const cond = try sema.coerce(block, Type.bool, uncasted_cond, cond_src);
1884 const cond = try sema.coerce(block, .bool, uncasted_cond, cond_src);
18851885 const cond_val = try sema.resolveConstDefinedValue(
18861886 block,
18871887 cond_src,
......@@ -2012,7 +2012,7 @@ fn resolveConstBool(
20122012 reason: ComptimeReason,
20132013) !bool {
20142014 const air_inst = try sema.resolveInst(zir_ref);
2015 const wanted_type = Type.bool;
2015 const wanted_type: Type = .bool;
20162016 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
20172017 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
20182018 return val.toBool();
......@@ -2037,7 +2037,7 @@ pub fn toConstString(
20372037 reason: ComptimeReason,
20382038) ![]u8 {
20392039 const pt = sema.pt;
2040 const coerced_inst = try sema.coerce(block, Type.slice_const_u8, air_inst, src);
2040 const coerced_inst = try sema.coerce(block, .slice_const_u8, air_inst, src);
20412041 const slice_val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
20422042 const arr_val = try sema.derefSliceAsArray(block, src, slice_val, reason);
20432043 return arr_val.toAllocatedBytes(arr_val.typeOf(pt.zcu), sema.arena, pt);
......@@ -2051,7 +2051,7 @@ pub fn resolveConstStringIntern(
20512051 reason: ComptimeReason,
20522052) !InternPool.NullTerminatedString {
20532053 const air_inst = try sema.resolveInst(zir_ref);
2054 const wanted_type = Type.slice_const_u8;
2054 const wanted_type: Type = .slice_const_u8;
20552055 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
20562056 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
20572057 return sema.sliceToIpString(block, src, val, reason);
......@@ -2180,7 +2180,7 @@ fn analyzeAsType(
21802180 src: LazySrcLoc,
21812181 air_inst: Air.Inst.Ref,
21822182) !Type {
2183 const wanted_type = Type.type;
2183 const wanted_type: Type = .type;
21842184 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
21852185 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{ .simple = .type });
21862186 return val.toType();
......@@ -2641,7 +2641,7 @@ fn reparentOwnedErrorMsg(
26412641 msg.msg = msg_str;
26422642}
26432643
2644const align_ty = Type.u29;
2644const align_ty: Type = .u29;
26452645
26462646pub fn analyzeAsAlign(
26472647 sema: *Sema,
......@@ -2819,7 +2819,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
28192819 const pt = sema.pt;
28202820 const zcu = pt.zcu;
28212821 const ip = &zcu.intern_pool;
2822 const parent_ty = Type.fromInterned(zcu.namespacePtr(block.namespace).owner_type);
2822 const parent_ty: Type = .fromInterned(zcu.namespacePtr(block.namespace).owner_type);
28232823 const parent_captures: InternPool.CaptureValue.Slice = parent_ty.getCaptures(zcu);
28242824
28252825 const captures = try sema.arena.alloc(InternPool.CaptureValue, captures_len);
......@@ -3777,7 +3777,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
37773777 const alloc = try sema.resolveInst(inst_data.operand);
37783778 const alloc_ty = sema.typeOf(alloc);
37793779 const ptr_info = alloc_ty.ptrInfo(zcu);
3780 const elem_ty = Type.fromInterned(ptr_info.child);
3780 const elem_ty: Type = .fromInterned(ptr_info.child);
37813781
37823782 // If the alloc was created in a comptime scope, we already created a comptime alloc for it.
37833783 // However, if the final constructed value does not reference comptime-mutable memory, we wish
......@@ -3848,7 +3848,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
38483848
38493849 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);
38503850 const ptr_info = alloc_ty.ptrInfo(zcu);
3851 const elem_ty = Type.fromInterned(ptr_info.child);
3851 const elem_ty: Type = .fromInterned(ptr_info.child);
38523852
38533853 const alloc_inst = alloc.toIndex() orelse return null;
38543854 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;
......@@ -4024,9 +4024,9 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40244024 // As this is a union field, we must store to the pointer now to set the tag.
40254025 // If the payload is OPV, there will not be a payload store, so we store that value.
40264026 // Otherwise, there will be a payload store to process later, so undef will suffice.
4027 const payload_ty = Type.fromInterned(union_obj.field_types.get(&zcu.intern_pool)[idx]);
4027 const payload_ty: Type = .fromInterned(union_obj.field_types.get(&zcu.intern_pool)[idx]);
40284028 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try pt.undefValue(payload_ty);
4029 const tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);
4029 const tag_val = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), idx);
40304030 const store_val = try pt.unionValue(maybe_union_ty, tag_val, payload_val);
40314031 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
40324032 }
......@@ -4050,7 +4050,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40504050 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
40514051 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
40524052 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
4053 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
4053 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, .fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
40544054 },
40554055 else => unreachable,
40564056 }
......@@ -4284,7 +4284,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
42844284 else => unreachable,
42854285 };
42864286 if (zcu.intern_pool.isFuncBody(val)) {
4287 const ty = Type.fromInterned(zcu.intern_pool.typeOf(val));
4287 const ty: Type = .fromInterned(zcu.intern_pool.typeOf(val));
42884288 if (try ty.fnHasRuntimeBitsSema(pt)) {
42894289 try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = val }));
42904290 try zcu.ensureFuncBodyAnalysisQueued(val);
......@@ -4447,14 +4447,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44474447 const range_end = try sema.resolveInst(zir_arg_pair[1]);
44484448 break :l try sema.analyzeArithmetic(block, .sub, range_end, range_start, arg_src, arg_src, arg_src, true);
44494449 };
4450 const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src);
4450 const arg_len = try sema.coerce(block, .usize, arg_len_uncoerced, arg_src);
44514451 if (len == .none) {
44524452 len = arg_len;
44534453 len_idx = i;
44544454 }
44554455 if (try sema.resolveDefinedValue(block, src, arg_len)) |arg_val| {
44564456 if (len_val) |v| {
4457 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {
4457 if (!(try sema.valuesEqual(arg_val, v, .usize))) {
44584458 const msg = msg: {
44594459 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});
44604460 errdefer msg.destroy(gpa);
......@@ -5343,7 +5343,7 @@ fn zirValidatePtrArrayInit(
53435343 // sentinel-terminated array, the sentinel will not have been populated by
53445344 // any ZIR instructions at comptime; we need to do that here.
53455345 if (array_ty.sentinel(zcu)) |sentinel_val| {
5346 const array_len_ref = try pt.intRef(Type.usize, array_len);
5346 const array_len_ref = try pt.intRef(.usize, array_len);
53475347 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);
53485348 const sentinel = Air.internedToRef(sentinel_val.toIntern());
53495349 try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store);
......@@ -5828,7 +5828,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
58285828 defer tracy.end();
58295829
58305830 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].int;
5831 return sema.pt.intRef(Type.comptime_int, int);
5831 return sema.pt.intRef(.comptime_int, int);
58325832}
58335833
58345834fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -5846,7 +5846,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
58465846 const limbs = try sema.arena.alloc(std.math.big.Limb, int.len);
58475847 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
58485848
5849 return Air.internedToRef((try sema.pt.intValue_big(Type.comptime_int, .{
5849 return Air.internedToRef((try sema.pt.intValue_big(.comptime_int, .{
58505850 .limbs = limbs,
58515851 .positive = true,
58525852 })).toIntern());
......@@ -5856,7 +5856,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
58565856 _ = block;
58575857 const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float;
58585858 return Air.internedToRef((try sema.pt.floatValue(
5859 Type.comptime_float,
5859 .comptime_float,
58605860 number,
58615861 )).toIntern());
58625862}
......@@ -5866,7 +5866,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
58665866 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
58675867 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
58685868 const number = extra.get();
5869 return Air.internedToRef((try sema.pt.floatValue(Type.comptime_float, number)).toIntern());
5869 return Air.internedToRef((try sema.pt.floatValue(.comptime_float, number)).toIntern());
58705870}
58715871
58725872fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -6641,7 +6641,7 @@ pub fn analyzeExport(
66416641 };
66426642
66436643 const exported_nav = ip.getNav(exported_nav_index);
6644 const export_ty = Type.fromInterned(exported_nav.typeOf(ip));
6644 const export_ty: Type = .fromInterned(exported_nav.typeOf(ip));
66456645
66466646 if (!try sema.validateExternType(export_ty, .other)) {
66476647 return sema.failWithOwnedErrorMsg(block, msg: {
......@@ -7005,7 +7005,7 @@ fn lookupInNamespace(
70057005
70067006 for (usingnamespaces.items) |sub_ns_nav| {
70077007 try sema.ensureNavResolved(block, src, sub_ns_nav, .fully);
7008 const sub_ns_ty = Type.fromInterned(ip.getNav(sub_ns_nav).status.fully_resolved.val);
7008 const sub_ns_ty: Type = .fromInterned(ip.getNav(sub_ns_nav).status.fully_resolved.val);
70097009 const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu));
70107010 try checked_namespaces.put(gpa, sub_ns, {});
70117011 }
......@@ -7081,7 +7081,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
70817081 const gpa = sema.gpa;
70827082
70837083 if (block.isComptime() or block.is_typeof) {
7084 const index_val = try pt.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len);
7084 const index_val = try pt.intValue_u64(.usize, sema.comptime_err_ret_trace.items.len);
70857085 return Air.internedToRef(index_val.toIntern());
70867086 }
70877087
......@@ -7326,13 +7326,13 @@ fn checkCallArgumentCount(
73267326) !Type {
73277327 const pt = sema.pt;
73287328 const zcu = pt.zcu;
7329 const func_ty = func_ty: {
7329 const func_ty: Type = func_ty: {
73307330 switch (callee_ty.zigTypeTag(zcu)) {
73317331 .@"fn" => break :func_ty callee_ty,
73327332 .pointer => {
73337333 const ptr_info = callee_ty.ptrInfo(zcu);
73347334 if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") {
7335 break :func_ty Type.fromInterned(ptr_info.child);
7335 break :func_ty .fromInterned(ptr_info.child);
73367336 }
73377337 },
73387338 .optional => {
......@@ -7405,13 +7405,13 @@ fn callBuiltin(
74057405 const pt = sema.pt;
74067406 const zcu = pt.zcu;
74077407 const callee_ty = sema.typeOf(builtin_fn);
7408 const func_ty = func_ty: {
7408 const func_ty: Type = func_ty: {
74097409 switch (callee_ty.zigTypeTag(zcu)) {
74107410 .@"fn" => break :func_ty callee_ty,
74117411 .pointer => {
74127412 const ptr_info = callee_ty.ptrInfo(zcu);
74137413 if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") {
7414 break :func_ty Type.fromInterned(ptr_info.child);
7414 break :func_ty .fromInterned(ptr_info.child);
74157415 }
74167416 },
74177417 else => {},
......@@ -7568,7 +7568,7 @@ const CallArgsInfo = union(enum) {
75687568 }
75697569 }
75707570 // Give the arg its result type
7571 const provide_param_ty = if (maybe_param_ty) |t| t else Type.generic_poison;
7571 const provide_param_ty: Type = maybe_param_ty orelse .generic_poison;
75727572 sema.inst_map.putAssumeCapacity(zir_call.call_inst, Air.internedToRef(provide_param_ty.toIntern()));
75737573 // Resolve the arg!
75747574 const uncoerced_arg = try sema.resolveInlineBody(block, arg_body, zir_call.call_inst);
......@@ -8353,7 +8353,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
83538353 @tagName(backend), @tagName(target.cpu.arch),
83548354 });
83558355 }
8356 const owner_func_ty = Type.fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);
8356 const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);
83578357 if (owner_func_ty.toIntern() != func_ty.toIntern()) {
83588358 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
83598359 func_ty.fmt(pt), owner_func_ty.fmt(pt),
......@@ -8452,7 +8452,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
84528452 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
84538453 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
84548454 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8455 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ .simple = .vector_length }));
8455 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, .u32, .{ .simple = .vector_length }));
84568456 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
84578457 try sema.checkVectorElemType(block, elem_type_src, elem_type);
84588458 const vector_type = try sema.pt.vectorType(.{
......@@ -8470,7 +8470,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
84708470 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
84718471 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
84728472 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8473 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ .simple = .array_length });
8473 const len = try sema.resolveInt(block, len_src, extra.lhs, .usize, .{ .simple = .array_length });
84748474 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);
84758475 try sema.validateArrayElemType(block, elem_type, elem_src);
84768476 const array_ty = try sema.pt.arrayType(.{
......@@ -8490,7 +8490,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
84908490 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
84918491 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
84928492 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8493 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ .simple = .array_length });
8493 const len = try sema.resolveInt(block, len_src, extra.len, .usize, .{ .simple = .array_length });
84948494 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
84958495 try sema.validateArrayElemType(block, elem_type, elem_src);
84968496 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
......@@ -8599,7 +8599,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
85998599 const src = block.nodeOffset(extra.node);
86008600 const operand_src = block.builtinCallArgSrc(extra.node, 0);
86018601 const uncasted_operand = try sema.resolveInst(extra.operand);
8602 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
8602 const operand = try sema.coerce(block, .anyerror, uncasted_operand, operand_src);
86038603 const err_int_ty = try pt.errorIntType();
86048604
86058605 if (try sema.resolveValue(operand)) |val| {
......@@ -9309,7 +9309,7 @@ fn zirFunc(
93099309 const ret_ty: Type = if (extra.data.ret_ty.is_generic)
93109310 .generic_poison
93119311 else switch (extra.data.ret_ty.body_len) {
9312 0 => Type.void,
9312 0 => .void,
93139313 1 => blk: {
93149314 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
93159315 extra_index += 1;
......@@ -9319,7 +9319,7 @@ fn zirFunc(
93199319 const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_ty.body_len);
93209320 extra_index += ret_ty_body.len;
93219321
9322 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ .simple = .function_ret_ty });
9322 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, .type, .{ .simple = .function_ret_ty });
93239323 break :blk ret_ty_val.toType();
93249324 },
93259325 };
......@@ -9649,7 +9649,7 @@ fn funcCommon(
96499649
96509650 var comptime_bits: u32 = 0;
96519651 for (block.params.items(.ty), block.params.items(.is_comptime), 0..) |param_ty_ip, param_is_comptime, i| {
9652 const param_ty = Type.fromInterned(param_ty_ip);
9652 const param_ty: Type = .fromInterned(param_ty_ip);
96539653 const is_noalias = blk: {
96549654 const index = std.math.cast(u5, i) orelse break :blk false;
96559655 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
......@@ -9870,7 +9870,7 @@ fn finishFunc(
98709870 const return_type: Type = if (opt_func_index == .none or ret_poison)
98719871 bare_return_type
98729872 else
9873 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
9873 .fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
98749874
98759875 if (!return_type.isValidReturnType(zcu)) {
98769876 const opaque_str = if (return_type.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
......@@ -10130,14 +10130,14 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1013010130 if (try sema.resolveValue(operand)) |operand_val| ct: {
1013110131 if (!is_vector) {
1013210132 if (operand_val.isUndef(zcu)) {
10133 return Air.internedToRef((try pt.undefValue(Type.usize)).toIntern());
10133 return .undef_usize;
1013410134 }
1013510135 const addr = try operand_val.getUnsignedIntSema(pt) orelse {
1013610136 // Wasn't an integer pointer. This is a runtime operation.
1013710137 break :ct;
1013810138 };
1013910139 return Air.internedToRef((try pt.intValue(
10140 Type.usize,
10140 .usize,
1014110141 addr,
1014210142 )).toIntern());
1014310143 }
......@@ -10145,7 +10145,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1014510145 for (new_elems, 0..) |*new_elem, i| {
1014610146 const ptr_val = try operand_val.elemValue(pt, i);
1014710147 if (ptr_val.isUndef(zcu)) {
10148 new_elem.* = (try pt.undefValue(Type.usize)).toIntern();
10148 new_elem.* = .undef_usize;
1014910149 continue;
1015010150 }
1015110151 const addr = try ptr_val.getUnsignedIntSema(pt) orelse {
......@@ -10153,7 +10153,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1015310153 break :ct;
1015410154 };
1015510155 new_elem.* = (try pt.intValue(
10156 Type.usize,
10156 .usize,
1015710157 addr,
1015810158 )).toIntern();
1015910159 }
......@@ -10170,7 +10170,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1017010170 }
1017110171 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
1017210172 for (new_elems, 0..) |*new_elem, i| {
10173 const idx_ref = try pt.intRef(Type.usize, i);
10173 const idx_ref = try pt.intRef(.usize, i);
1017410174 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
1017510175 new_elem.* = try block.addBitCast(.usize, old_elem);
1017610176 }
......@@ -10646,7 +10646,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1064610646 const vec_len = operand_ty.vectorLen(zcu);
1064710647 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);
1064810648 for (new_elems, 0..) |*new_elem, i| {
10649 const idx_ref = try pt.intRef(Type.usize, i);
10649 const idx_ref = try pt.intRef(.usize, i);
1065010650 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
1065110651 new_elem.* = try block.addTyOp(.fptrunc, dest_scalar_ty, old_elem);
1065210652 }
......@@ -10675,7 +10675,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1067510675 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1067610676 const array = try sema.resolveInst(extra.lhs);
1067710677 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
10678 const elem_index = try sema.coerce(block, Type.usize, uncoerced_elem_index, elem_index_src);
10678 const elem_index = try sema.coerce(block, .usize, uncoerced_elem_index, elem_index_src);
1067910679 return sema.elemVal(block, src, array, elem_index, elem_index_src, true);
1068010680}
1068110681
......@@ -10685,7 +10685,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1068510685
1068610686 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
1068710687 const array = try sema.resolveInst(inst_data.operand);
10688 const elem_index = try sema.pt.intRef(Type.usize, inst_data.idx);
10688 const elem_index = try sema.pt.intRef(.usize, inst_data.idx);
1068910689 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);
1069010690}
1069110691
......@@ -10728,7 +10728,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1072810728 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1072910729 const array_ptr = try sema.resolveInst(extra.lhs);
1073010730 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
10731 const elem_index = try sema.coerce(block, Type.usize, uncoerced_elem_index, elem_index_src);
10731 const elem_index = try sema.coerce(block, .usize, uncoerced_elem_index, elem_index_src);
1073210732 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, true);
1073310733}
1073410734
......@@ -10742,7 +10742,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1074210742 const src = block.nodeOffset(inst_data.src_node);
1074310743 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
1074410744 const array_ptr = try sema.resolveInst(extra.ptr);
10745 const elem_index = try pt.intRef(Type.usize, extra.index);
10745 const elem_index = try pt.intRef(.usize, extra.index);
1074610746 const array_ty = sema.typeOf(array_ptr).childType(zcu);
1074710747 switch (array_ty.zigTypeTag(zcu)) {
1074810748 .array, .vector => {},
......@@ -11104,7 +11104,7 @@ const SwitchProngAnalysis = struct {
1110411104 if (operand_ty.zigTypeTag(zcu) == .@"union") {
1110511105 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
1110611106 const union_obj = zcu.typeToUnion(operand_ty).?;
11107 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
11107 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
1110811108 if (capture_byref) {
1110911109 const ptr_field_ty = try pt.ptrTypeSema(.{
1111011110 .child = field_ty.toIntern(),
......@@ -11154,7 +11154,7 @@ const SwitchProngAnalysis = struct {
1115411154 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1115511155
1115611156 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;
11157 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
11157 const first_field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1115811158
1115911159 const field_indices = try sema.arena.alloc(u32, case_vals.len);
1116011160 for (case_vals, field_indices) |item, *field_idx| {
......@@ -11165,7 +11165,7 @@ const SwitchProngAnalysis = struct {
1116511165 // Fast path: if all the operands are the same type already, we don't need to hit
1116611166 // PTR! This will also allow us to emit simpler code.
1116711167 const same_types = for (field_indices[1..]) |field_idx| {
11168 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11168 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1116911169 if (!field_ty.eql(first_field_ty, zcu)) break false;
1117011170 } else true;
1117111171
......@@ -11173,7 +11173,7 @@ const SwitchProngAnalysis = struct {
1117311173 // We need values to run PTR on, so make a bunch of undef constants.
1117411174 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
1117511175 for (dummy_captures, field_indices) |*dummy, field_idx| {
11176 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11176 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1117711177 dummy.* = try pt.undefRef(field_ty);
1117811178 }
1117911179
......@@ -11208,7 +11208,7 @@ const SwitchProngAnalysis = struct {
1120811208 // We need values to run PTR on, so make a bunch of undef constants.
1120911209 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
1121011210 for (field_indices, dummy_captures) |field_idx, *dummy| {
11211 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11211 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1121211212 const field_ptr_ty = try pt.ptrTypeSema(.{
1121311213 .child = field_ty.toIntern(),
1121411214 .flags = .{
......@@ -11271,7 +11271,7 @@ const SwitchProngAnalysis = struct {
1127111271 // If we can, try to avoid that using in-memory coercions.
1127211272 const first_non_imc = in_mem: {
1127311273 for (field_indices, 0..) |field_idx, i| {
11274 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11274 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1127511275 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {
1127611276 break :in_mem i;
1127711277 }
......@@ -11294,7 +11294,7 @@ const SwitchProngAnalysis = struct {
1129411294 {
1129511295 const next = first_non_imc + 1;
1129611296 for (field_indices[next..], next..) |field_idx, i| {
11297 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11297 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1129811298 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {
1129911299 in_mem_coercible.unset(i);
1130011300 }
......@@ -11341,7 +11341,7 @@ const SwitchProngAnalysis = struct {
1134111341 };
1134211342
1134311343 const field_idx = field_indices[idx];
11344 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11344 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
1134511345 const uncoerced = try coerce_block.addStructFieldVal(operand_val, field_idx, field_ty);
1134611346 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1134711347 _ = try coerce_block.addBr(capture_block_inst, coerced);
......@@ -11365,7 +11365,7 @@ const SwitchProngAnalysis = struct {
1136511365
1136611366 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;
1136711367 const first_imc_field_idx = field_indices[first_imc_item_idx];
11368 const first_imc_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_imc_field_idx]);
11368 const first_imc_field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[first_imc_field_idx]);
1136911369 const uncoerced = try coerce_block.addStructFieldVal(operand_val, first_imc_field_idx, first_imc_field_ty);
1137011370 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
1137111371 _ = try coerce_block.addBr(capture_block_inst, coerced);
......@@ -13165,7 +13165,7 @@ fn analyzeSwitchRuntimeBlock(
1316513165 for (seen_enum_fields, 0..) |seen_field, index| {
1316613166 if (seen_field != null) continue;
1316713167 const union_obj = zcu.typeToUnion(maybe_union_ty).?;
13168 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[index]);
13168 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[index]);
1316913169 if (field_ty.zigTypeTag(zcu) != .noreturn) break true;
1317013170 } else false
1317113171 else
......@@ -13490,7 +13490,7 @@ const RangeSetUnhandledIterator = struct {
1349013490 inline .u64, .i64 => |val_int| {
1349113491 const next_int = @addWithOverflow(val_int, 1);
1349213492 if (next_int[1] == 0)
13493 return (try it.pt.intValue(Type.fromInterned(int.ty), next_int[0])).toIntern();
13493 return (try it.pt.intValue(.fromInterned(int.ty), next_int[0])).toIntern();
1349413494 },
1349513495 .big_int => {},
1349613496 .lazy_align, .lazy_size => unreachable,
......@@ -13506,7 +13506,7 @@ const RangeSetUnhandledIterator = struct {
1350613506 );
1350713507
1350813508 result_bigint.addScalar(val_bigint, 1);
13509 return (try it.pt.intValue_big(Type.fromInterned(int.ty), result_bigint.toConst())).toIntern();
13509 return (try it.pt.intValue_big(.fromInterned(int.ty), result_bigint.toConst())).toIntern();
1351013510 }
1351113511
1351213512 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {
......@@ -13636,7 +13636,7 @@ fn validateErrSetSwitch(
1363613636 .{},
1363713637 );
1363813638 }
13639 return Type.anyerror;
13639 return .anyerror;
1364013640 },
1364113641 else => |err_set_ty_index| else_validation: {
1364213642 const error_names = ip.indexToKey(err_set_ty_index).error_set_type.names;
......@@ -13839,7 +13839,7 @@ fn validateSwitchItemBool(
1383913839 item_ref: Zir.Inst.Ref,
1384013840 item_src: LazySrcLoc,
1384113841) CompileError!Air.Inst.Ref {
13842 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src);
13842 const item = try sema.resolveSwitchItemVal(block, item_ref, .bool, item_src);
1384313843 if (Value.fromInterned(item.val).toBool()) {
1384413844 true_count.* += 1;
1384513845 } else {
......@@ -14224,7 +14224,7 @@ fn zirShl(
1422414224 return lhs;
1422514225 }
1422614226 if (air_tag != .shl_sat and scalar_ty.zigTypeTag(zcu) != .comptime_int) {
14227 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14227 const bit_value = try pt.intValue(.comptime_int, scalar_ty.intInfo(zcu).bits);
1422814228 if (rhs_ty.zigTypeTag(zcu) == .vector) {
1422914229 var i: usize = 0;
1423014230 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
......@@ -14351,8 +14351,7 @@ fn zirShl(
1435114351 try block.addReduce(ov_bit, .Or)
1435214352 else
1435314353 ov_bit;
14354 const zero_ov = Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
14355 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov);
14354 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, .zero_u1);
1435614355
1435714356 try sema.addSafetyCheck(block, src, no_ov, .shl_overflow);
1435814357 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);
......@@ -14406,7 +14405,7 @@ fn zirShr(
1440614405 return lhs;
1440714406 }
1440814407 if (scalar_ty.zigTypeTag(zcu) != .comptime_int) {
14409 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14408 const bit_value = try pt.intValue(.comptime_int, scalar_ty.intInfo(zcu).bits);
1441014409 if (rhs_ty.zigTypeTag(zcu) == .vector) {
1441114410 var i: usize = 0;
1441214411 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
......@@ -14689,7 +14688,7 @@ fn analyzeTupleCat(
1468914688 try sema.tupleFieldValByIndex(block, rhs, i, rhs_ty);
1469014689 }
1469114690
14692 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
14691 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
1469314692}
1469414693
1469514694fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -14716,7 +14715,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1471614715 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1471714716
1471814717 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
14719 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);
14718 if (lhs_is_tuple) break :lhs_info undefined;
1472014719 return sema.fail(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});
1472114720 };
1472214721 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {
......@@ -14892,7 +14891,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1489214891
1489314892 // lhs_dest_slice = dest[0..lhs.len]
1489414893 const slice_ty_ref = Air.internedToRef(slice_ty.toIntern());
14895 const lhs_len_ref = try pt.intRef(Type.usize, lhs_len);
14894 const lhs_len_ref = try pt.intRef(.usize, lhs_len);
1489614895 const lhs_dest_slice = try block.addInst(.{
1489714896 .tag = .slice,
1489814897 .data = .{ .ty_pl = .{
......@@ -14907,7 +14906,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1490714906 _ = try block.addBinOp(.memcpy, lhs_dest_slice, lhs);
1490814907
1490914908 // rhs_dest_slice = dest[lhs.len..][0..rhs.len]
14910 const rhs_len_ref = try pt.intRef(Type.usize, rhs_len);
14909 const rhs_len_ref = try pt.intRef(.usize, rhs_len);
1491114910 const rhs_dest_offset = try block.addInst(.{
1491214911 .tag = .ptr_add,
1491314912 .data = .{ .ty_pl = .{
......@@ -14932,7 +14931,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1493214931 _ = try block.addBinOp(.memcpy, rhs_dest_slice, rhs);
1493314932
1493414933 if (res_sent_val) |sent_val| {
14935 const elem_index = try pt.intRef(Type.usize, result_len);
14934 const elem_index = try pt.intRef(.usize, result_len);
1493614935 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
1493714936 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());
1493814937 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);
......@@ -14943,7 +14942,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1494314942
1494414943 var elem_i: u32 = 0;
1494514944 while (elem_i < lhs_len) : (elem_i += 1) {
14946 const elem_index = try pt.intRef(Type.usize, elem_i);
14945 const elem_index = try pt.intRef(.usize, elem_i);
1494714946 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
1494814947 const operand_src = block.src(.{ .array_cat_lhs = .{
1494914948 .array_cat_offset = inst_data.src_node,
......@@ -14954,8 +14953,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1495414953 }
1495514954 while (elem_i < result_len) : (elem_i += 1) {
1495614955 const rhs_elem_i = elem_i - lhs_len;
14957 const elem_index = try pt.intRef(Type.usize, elem_i);
14958 const rhs_index = try pt.intRef(Type.usize, rhs_elem_i);
14956 const elem_index = try pt.intRef(.usize, elem_i);
14957 const rhs_index = try pt.intRef(.usize, rhs_elem_i);
1495914958 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
1496014959 const operand_src = block.src(.{ .array_cat_rhs = .{
1496114960 .array_cat_offset = inst_data.src_node,
......@@ -14965,7 +14964,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1496514964 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
1496614965 }
1496714966 if (res_sent_val) |sent_val| {
14968 const elem_index = try pt.intRef(Type.usize, result_len);
14967 const elem_index = try pt.intRef(.usize, result_len);
1496914968 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
1497014969 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());
1497114970 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);
......@@ -14978,7 +14977,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1497814977 {
1497914978 var elem_i: u32 = 0;
1498014979 while (elem_i < lhs_len) : (elem_i += 1) {
14981 const index = try pt.intRef(Type.usize, elem_i);
14980 const index = try pt.intRef(.usize, elem_i);
1498214981 const operand_src = block.src(.{ .array_cat_lhs = .{
1498314982 .array_cat_offset = inst_data.src_node,
1498414983 .elem_index = elem_i,
......@@ -14988,7 +14987,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1498814987 }
1498914988 while (elem_i < result_len) : (elem_i += 1) {
1499014989 const rhs_elem_i = elem_i - lhs_len;
14991 const index = try pt.intRef(Type.usize, rhs_elem_i);
14990 const index = try pt.intRef(.usize, rhs_elem_i);
1499214991 const operand_src = block.src(.{ .array_cat_rhs = .{
1499314992 .array_cat_offset = inst_data.src_node,
1499414993 .elem_index = @intCast(rhs_elem_i),
......@@ -15012,8 +15011,8 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1501215011 switch (ptr_info.flags.size) {
1501315012 .slice => {
1501415013 const val = try sema.resolveConstDefinedValue(block, src, operand, .{ .simple = .slice_cat_operand });
15015 return Type.ArrayInfo{
15016 .elem_type = Type.fromInterned(ptr_info.child),
15014 return .{
15015 .elem_type = .fromInterned(ptr_info.child),
1501715016 .sentinel = switch (ptr_info.sentinel) {
1501815017 .none => null,
1501915018 else => Value.fromInterned(ptr_info.sentinel),
......@@ -15113,7 +15112,7 @@ fn analyzeTupleMul(
1511315112 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
1511415113 }
1511515114
15116 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
15115 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
1511715116}
1511815117
1511915118fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -15166,7 +15165,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1516615165
1516715166 if (lhs_ty.isTuple(zcu)) {
1516815167 // In `**` rhs must be comptime-known, but lhs can be runtime-known
15169 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ .simple = .array_mul_factor });
15168 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, .usize, .{ .simple = .array_mul_factor });
1517015169 const factor_casted = try sema.usizeCast(block, rhs_src, factor);
1517115170 return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted);
1517215171 }
......@@ -15188,7 +15187,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1518815187 };
1518915188
1519015189 // In `**` rhs must be comptime-known, but lhs can be runtime-known
15191 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ .simple = .array_mul_factor });
15190 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, .usize, .{ .simple = .array_mul_factor });
1519215191
1519315192 const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch
1519415193 return sema.fail(block, rhs_src, "operation results in overflow", .{});
......@@ -15246,7 +15245,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1524615245 // to get the same elem values.
1524715246 const lhs_vals = try sema.arena.alloc(Air.Inst.Ref, lhs_len);
1524815247 for (lhs_vals, 0..) |*lhs_val, idx| {
15249 const idx_ref = try pt.intRef(Type.usize, idx);
15248 const idx_ref = try pt.intRef(.usize, idx);
1525015249 lhs_val.* = try sema.elemVal(block, lhs_src, lhs, idx_ref, src, false);
1525115250 }
1525215251
......@@ -15267,14 +15266,14 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1526715266 var elem_i: usize = 0;
1526815267 while (elem_i < result_len) {
1526915268 for (lhs_vals) |lhs_val| {
15270 const elem_index = try pt.intRef(Type.usize, elem_i);
15269 const elem_index = try pt.intRef(.usize, elem_i);
1527115270 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
1527215271 try sema.storePtr2(block, src, elem_ptr, src, lhs_val, lhs_src, .store);
1527315272 elem_i += 1;
1527415273 }
1527515274 }
1527615275 if (lhs_info.sentinel) |sent_val| {
15277 const elem_index = try pt.intRef(Type.usize, result_len);
15276 const elem_index = try pt.intRef(.usize, result_len);
1527815277 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
1527915278 const init = Air.internedToRef(sent_val.toIntern());
1528015279 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);
......@@ -16132,14 +16131,13 @@ fn zirOverflowArithmetic(
1613216131 const maybe_rhs_val = try sema.resolveValue(rhs);
1613316132
1613416133 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);
16135 const overflow_ty = Type.fromInterned(ip.indexToKey(tuple_ty.toIntern()).tuple_type.types.get(ip)[1]);
16134 const overflow_ty: Type = .fromInterned(ip.indexToKey(tuple_ty.toIntern()).tuple_type.types.get(ip)[1]);
1613616135
1613716136 var result: struct {
1613816137 inst: Air.Inst.Ref = .none,
1613916138 wrapped: Value = Value.@"unreachable",
1614016139 overflow_bit: Value,
1614116140 } = result: {
16142 const zero_bit = try pt.intValue(Type.u1, 0);
1614316141 switch (zir_tag) {
1614416142 .add_with_overflow => {
1614516143 // If either of the arguments is zero, `false` is returned and the other is stored
......@@ -16147,12 +16145,12 @@ fn zirOverflowArithmetic(
1614716145 // Otherwise, if either of the argument is undefined, undefined is returned.
1614816146 if (maybe_lhs_val) |lhs_val| {
1614916147 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16150 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
16148 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
1615116149 }
1615216150 }
1615316151 if (maybe_rhs_val) |rhs_val| {
1615416152 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
16155 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16153 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1615616154 }
1615716155 }
1615816156 if (maybe_lhs_val) |lhs_val| {
......@@ -16173,7 +16171,7 @@ fn zirOverflowArithmetic(
1617316171 if (rhs_val.isUndef(zcu)) {
1617416172 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1617516173 } else if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
16176 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16174 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1617716175 } else if (maybe_lhs_val) |lhs_val| {
1617816176 if (lhs_val.isUndef(zcu)) {
1617916177 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
......@@ -16192,9 +16190,9 @@ fn zirOverflowArithmetic(
1619216190 if (maybe_lhs_val) |lhs_val| {
1619316191 if (!lhs_val.isUndef(zcu)) {
1619416192 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
16195 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16193 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1619616194 } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
16197 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
16195 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
1619816196 }
1619916197 }
1620016198 }
......@@ -16202,9 +16200,9 @@ fn zirOverflowArithmetic(
1620216200 if (maybe_rhs_val) |rhs_val| {
1620316201 if (!rhs_val.isUndef(zcu)) {
1620416202 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
16205 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
16203 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
1620616204 } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
16207 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16205 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1620816206 }
1620916207 }
1621016208 }
......@@ -16226,12 +16224,12 @@ fn zirOverflowArithmetic(
1622616224 // Oterhwise if either of the arguments is undefined, both results are undefined.
1622716225 if (maybe_lhs_val) |lhs_val| {
1622816226 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16229 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16227 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1623016228 }
1623116229 }
1623216230 if (maybe_rhs_val) |rhs_val| {
1623316231 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
16234 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16232 break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1623516233 }
1623616234 }
1623716235 if (maybe_lhs_val) |lhs_val| {
......@@ -16309,10 +16307,10 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1630916307 const pt = sema.pt;
1631016308 const zcu = pt.zcu;
1631116309 const ip = &zcu.intern_pool;
16312 const ov_ty = if (ty.zigTypeTag(zcu) == .vector) try pt.vectorType(.{
16310 const ov_ty: Type = if (ty.zigTypeTag(zcu) == .vector) try pt.vectorType(.{
1631316311 .len = ty.vectorLen(zcu),
1631416312 .child = .u1_type,
16315 }) else Type.u1;
16313 }) else .u1;
1631616314
1631716315 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };
1631816316 const values = [2]InternPool.Index{ .none, .none };
......@@ -16320,7 +16318,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1632016318 .types = &types,
1632116319 .values = &values,
1632216320 });
16323 return Type.fromInterned(tuple_ty);
16321 return .fromInterned(tuple_ty);
1632416322}
1632516323
1632616324fn analyzeArithmetic(
......@@ -16380,7 +16378,7 @@ fn analyzeArithmetic(
1638016378 const address = std.math.sub(u64, lhs_ptr.byte_offset, rhs_ptr.byte_offset) catch
1638116379 return sema.fail(block, src, "operation results in overflow", .{});
1638216380 const result = address / elem_size;
16383 return try pt.intRef(Type.usize, result);
16381 return try pt.intRef(.usize, result);
1638416382 } else {
1638516383 break :runtime_src lhs_src;
1638616384 }
......@@ -16395,7 +16393,7 @@ fn analyzeArithmetic(
1639516393 const lhs_int = try block.addBitCast(.usize, lhs);
1639616394 const rhs_int = try block.addBitCast(.usize, rhs);
1639716395 const address = try block.addBinOp(.sub_wrap, lhs_int, rhs_int);
16398 return try block.addBinOp(.div_exact, address, try pt.intRef(Type.usize, elem_size));
16396 return try block.addBinOp(.div_exact, address, try pt.intRef(.usize, elem_size));
1639916397 }
1640016398 } else {
1640116399 switch (lhs_ty.ptrSize(zcu)) {
......@@ -16527,8 +16525,7 @@ fn analyzeArithmetic(
1652716525 try block.addReduce(ov_bit, .Or)
1652816526 else
1652916527 ov_bit;
16530 const zero_ov = Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
16531 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov);
16528 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, .zero_u1);
1653216529
1653316530 try sema.addSafetyCheck(block, src, no_ov, .integer_overflow);
1653416531 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);
......@@ -16550,7 +16547,7 @@ fn analyzePtrArithmetic(
1655016547) CompileError!Air.Inst.Ref {
1655116548 // TODO if the operand is comptime-known to be negative, or is a negative int,
1655216549 // coerce to isize instead of usize.
16553 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
16550 const offset = try sema.coerce(block, .usize, uncasted_offset, offset_src);
1655416551 const pt = sema.pt;
1655516552 const zcu = pt.zcu;
1655616553 const opt_ptr_val = try sema.resolveValue(ptr);
......@@ -16736,8 +16733,8 @@ fn zirAsm(
1673616733 const uncasted_arg = try sema.resolveInst(input.data.operand);
1673716734 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
1673816735 switch (uncasted_arg_ty.zigTypeTag(zcu)) {
16739 .comptime_int => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),
16740 .comptime_float => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),
16736 .comptime_int => arg.* = try sema.coerce(block, .usize, uncasted_arg, src),
16737 .comptime_float => arg.* = try sema.coerce(block, .f64, uncasted_arg, src),
1674116738 else => {
1674216739 arg.* = uncasted_arg;
1674316740 },
......@@ -16860,9 +16857,7 @@ fn zirCmpEq(
1686016857 const runtime_src: LazySrcLoc = src: {
1686116858 if (try sema.resolveValue(lhs)) |lval| {
1686216859 if (try sema.resolveValue(rhs)) |rval| {
16863 if (lval.isUndef(zcu) or rval.isUndef(zcu)) {
16864 return pt.undefRef(Type.bool);
16865 }
16860 if (lval.isUndef(zcu) or rval.isUndef(zcu)) return .undef_bool;
1686616861 const lkey = zcu.intern_pool.indexToKey(lval.toIntern());
1686716862 const rkey = zcu.intern_pool.indexToKey(rval.toIntern());
1686816863 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
......@@ -16916,7 +16911,7 @@ fn analyzeCmpUnionTag(
1691616911 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1691716912
1691816913 if (try sema.resolveValue(coerced_tag)) |enum_val| {
16919 if (enum_val.isUndef(zcu)) return pt.undefRef(Type.bool);
16914 if (enum_val.isUndef(zcu)) return .undef_bool;
1692016915 const field_ty = union_ty.unionFieldType(enum_val, zcu).?;
1692116916 if (field_ty.zigTypeTag(zcu) == .noreturn) {
1692216917 return .bool_false;
......@@ -17027,8 +17022,8 @@ fn cmpSelf(
1702717022
1702817023 const maybe_lhs_val = try sema.resolveValue(casted_lhs);
1702917024 const maybe_rhs_val = try sema.resolveValue(casted_rhs);
17030 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);
17031 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);
17025 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
17026 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
1703217027
1703317028 const runtime_src: LazySrcLoc = src: {
1703417029 if (maybe_lhs_val) |lhs_val| {
......@@ -17083,7 +17078,7 @@ fn runtimeBoolCmp(
1708317078) CompileError!Air.Inst.Ref {
1708417079 if ((op == .neq) == rhs) {
1708517080 try sema.requireRuntimeBlock(block, src, runtime_src);
17086 return block.addTyOp(.not, Type.bool, lhs);
17081 return block.addTyOp(.not, .bool, lhs);
1708717082 } else {
1708817083 return lhs;
1708917084 }
......@@ -17107,7 +17102,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1710717102 .comptime_float,
1710817103 .comptime_int,
1710917104 .void,
17110 => return pt.intRef(Type.comptime_int, 0),
17105 => return .zero,
1711117106
1711217107 .bool,
1711317108 .int,
......@@ -17148,7 +17143,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1714817143 .comptime_float,
1714917144 .comptime_int,
1715017145 .void,
17151 => return pt.intRef(Type.comptime_int, 0),
17146 => return .zero,
1715217147
1715317148 .bool,
1715417149 .int,
......@@ -17167,7 +17162,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1716717162 => {},
1716817163 }
1716917164 const bit_size = try operand_ty.bitSizeSema(pt);
17170 return pt.intRef(Type.comptime_int, bit_size);
17165 return pt.intRef(.comptime_int, bit_size);
1717117166}
1717217167
1717317168fn zirThis(
......@@ -17285,7 +17280,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1728517280
1728617281 assert(block.is_typeof);
1728717282 // We need a dummy runtime instruction with the correct type.
17288 return block.addTy(.alloc, Type.fromInterned(capture_ty));
17283 return block.addTy(.alloc, .fromInterned(capture_ty));
1728917284}
1729017285
1729117286fn zirRetAddr(
......@@ -17293,10 +17288,11 @@ fn zirRetAddr(
1729317288 block: *Block,
1729417289 extended: Zir.Inst.Extended.InstData,
1729517290) CompileError!Air.Inst.Ref {
17291 _ = sema;
1729617292 _ = extended;
1729717293 if (block.isComptime()) {
1729817294 // TODO: we could give a meaningful lazy value here. #14938
17299 return sema.pt.intRef(Type.usize, 0);
17295 return .zero_usize;
1730017296 } else {
1730117297 return block.addNoOp(.ret_addr);
1730217298 }
......@@ -17349,7 +17345,7 @@ fn zirBuiltinSrc(
1734917345 } },
1735017346 .byte_offset = 0,
1735117347 } }),
17352 .len = (try pt.intValue(Type.usize, func_name_len)).toIntern(),
17348 .len = (try pt.intValue(.usize, func_name_len)).toIntern(),
1735317349 } });
1735417350 };
1735517351
......@@ -17375,7 +17371,7 @@ fn zirBuiltinSrc(
1737517371 } },
1737617372 .byte_offset = 0,
1737717373 } }),
17378 .len = (try pt.intValue(Type.usize, module_name.len)).toIntern(),
17374 .len = (try pt.intValue(.usize, module_name.len)).toIntern(),
1737917375 } });
1738017376 };
1738117377
......@@ -17401,7 +17397,7 @@ fn zirBuiltinSrc(
1740117397 } },
1740217398 .byte_offset = 0,
1740317399 } }),
17404 .len = (try pt.intValue(Type.usize, file_name.len)).toIntern(),
17400 .len = (try pt.intValue(.usize, file_name.len)).toIntern(),
1740517401 } });
1740617402 };
1740717403
......@@ -17414,9 +17410,9 @@ fn zirBuiltinSrc(
1741417410 // fn_name: [:0]const u8,
1741517411 func_name_val,
1741617412 // line: u32,
17417 (try pt.intValue(Type.u32, extra.line + 1)).toIntern(),
17413 (try pt.intValue(.u32, extra.line + 1)).toIntern(),
1741817414 // column: u32,
17419 (try pt.intValue(Type.u32, extra.column + 1)).toIntern(),
17415 (try pt.intValue(.u32, extra.column + 1)).toIntern(),
1742017416 };
1742117417 return Air.internedToRef((try pt.intern(.{ .aggregate = .{
1742217418 .ty = src_loc_ty.toIntern(),
......@@ -17511,7 +17507,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1751117507 } },
1751217508 .byte_offset = 0,
1751317509 } }),
17514 .len = (try pt.intValue(Type.usize, param_vals.len)).toIntern(),
17510 .len = (try pt.intValue(.usize, param_vals.len)).toIntern(),
1751517511 } });
1751617512 };
1751717513
......@@ -17564,7 +17560,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1756417560 // signedness: Signedness,
1756517561 (try pt.enumValueFieldIndex(signedness_ty, @intFromEnum(info.signedness))).toIntern(),
1756617562 // bits: u16,
17567 (try pt.intValue(Type.u16, info.bits)).toIntern(),
17563 (try pt.intValue(.u16, info.bits)).toIntern(),
1756817564 };
1756917565 return Air.internedToRef((try pt.internUnion(.{
1757017566 .ty = type_info_ty.toIntern(),
......@@ -17580,7 +17576,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1758017576
1758117577 const field_vals = .{
1758217578 // bits: u16,
17583 (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(),
17579 (try pt.intValue(.u16, ty.bitSize(zcu))).toIntern(),
1758417580 };
1758517581 return Air.internedToRef((try pt.internUnion(.{
1758617582 .ty = type_info_ty.toIntern(),
......@@ -17594,7 +17590,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1759417590 .pointer => {
1759517591 const info = ty.ptrInfo(zcu);
1759617592 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|
17597 try pt.intValue(Type.comptime_int, alignment)
17593 try pt.intValue(.comptime_int, alignment)
1759817594 else
1759917595 try Type.fromInterned(info.child).lazyAbiAlignment(pt);
1760017596
......@@ -17638,7 +17634,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1763817634 const info = ty.arrayInfo(zcu);
1763917635 const field_values = .{
1764017636 // len: comptime_int,
17641 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),
17637 (try pt.intValue(.comptime_int, info.len)).toIntern(),
1764217638 // child: type,
1764317639 info.elem_type.toIntern(),
1764417640 // sentinel: ?*const anyopaque,
......@@ -17659,7 +17655,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1765917655 const info = ty.arrayInfo(zcu);
1766017656 const field_values = .{
1766117657 // len: comptime_int,
17662 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),
17658 (try pt.intValue(.comptime_int, info.len)).toIntern(),
1766317659 // child: type,
1766417660 info.elem_type.toIntern(),
1766517661 };
......@@ -17723,7 +17719,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1772317719 } },
1772417720 .byte_offset = 0,
1772517721 } }),
17726 .len = (try pt.intValue(Type.usize, error_name_len)).toIntern(),
17722 .len = (try pt.intValue(.usize, error_name_len)).toIntern(),
1772717723 } });
1772817724 };
1772917725
......@@ -17770,7 +17766,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1777017766 } },
1777117767 .byte_offset = 0,
1777217768 } }),
17773 .len = (try pt.intValue(Type.usize, vals.len)).toIntern(),
17769 .len = (try pt.intValue(.usize, vals.len)).toIntern(),
1777417770 } });
1777517771 } else .none;
1777617772 const errors_val = try pt.intern(.{ .opt = .{
......@@ -17819,7 +17815,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1781917815 .comptime_int_type,
1782017816 )
1782117817 else
17822 (try pt.intValue(Type.comptime_int, tag_index)).toIntern();
17818 (try pt.intValue(.comptime_int, tag_index)).toIntern();
1782317819
1782417820 // TODO: write something like getCoercedInts to avoid needing to dupe
1782517821 const name_val = v: {
......@@ -17844,7 +17840,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1784417840 } },
1784517841 .byte_offset = 0,
1784617842 } }),
17847 .len = (try pt.intValue(Type.usize, tag_name_len)).toIntern(),
17843 .len = (try pt.intValue(.usize, tag_name_len)).toIntern(),
1784817844 } });
1784917845 };
1785017846
......@@ -17887,7 +17883,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1788717883 } },
1788817884 .byte_offset = 0,
1788917885 } }),
17890 .len = (try pt.intValue(Type.usize, enum_field_vals.len)).toIntern(),
17886 .len = (try pt.intValue(.usize, enum_field_vals.len)).toIntern(),
1789117887 } });
1789217888 };
1789317889
......@@ -17949,7 +17945,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1794917945 } },
1795017946 .byte_offset = 0,
1795117947 } }),
17952 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),
17948 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
1795317949 } });
1795417950 };
1795517951
......@@ -17965,7 +17961,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1796517961 // type: type,
1796617962 field_ty,
1796717963 // alignment: comptime_int,
17968 (try pt.intValue(Type.comptime_int, alignment.toByteUnits() orelse 0)).toIntern(),
17964 (try pt.intValue(.comptime_int, alignment.toByteUnits() orelse 0)).toIntern(),
1796917965 };
1797017966 field_val.* = try pt.intern(.{ .aggregate = .{
1797117967 .ty = union_field_ty.toIntern(),
......@@ -18000,7 +17996,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1800017996 } },
1800117997 .byte_offset = 0,
1800217998 } }),
18003 .len = (try pt.intValue(Type.usize, union_field_vals.len)).toIntern(),
17999 .len = (try pt.intValue(.usize, union_field_vals.len)).toIntern(),
1800418000 } });
1800518001 };
1800618002
......@@ -18070,7 +18066,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1807018066 } },
1807118067 .byte_offset = 0,
1807218068 } }),
18073 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),
18069 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
1807418070 } });
1807518071 };
1807618072
......@@ -18089,7 +18085,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1808918085 // is_comptime: bool,
1809018086 Value.makeBool(is_comptime).toIntern(),
1809118087 // alignment: comptime_int,
18092 (try pt.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(zcu).toByteUnits() orelse 0)).toIntern(),
18088 (try pt.intValue(.comptime_int, Type.fromInterned(field_ty).abiAlignment(zcu).toByteUnits() orelse 0)).toIntern(),
1809318089 };
1809418090 struct_field_val.* = try pt.intern(.{ .aggregate = .{
1809518091 .ty = struct_field_ty.toIntern(),
......@@ -18111,7 +18107,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1811118107 else
1811218108 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
1811318109 const field_name_len = field_name.length(ip);
18114 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
18110 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
1811518111 const field_init = struct_type.fieldInit(ip, field_index);
1811618112 const field_is_comptime = struct_type.fieldIsComptime(ip, field_index);
1811718113 const name_val = v: {
......@@ -18134,7 +18130,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1813418130 } },
1813518131 .byte_offset = 0,
1813618132 } }),
18137 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),
18133 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
1813818134 } });
1813918135 };
1814018136
......@@ -18159,7 +18155,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1815918155 // is_comptime: bool,
1816018156 Value.makeBool(field_is_comptime).toIntern(),
1816118157 // alignment: comptime_int,
18162 (try pt.intValue(Type.comptime_int, alignment.toByteUnits() orelse 0)).toIntern(),
18158 (try pt.intValue(.comptime_int, alignment.toByteUnits() orelse 0)).toIntern(),
1816318159 };
1816418160 field_val.* = try pt.intern(.{ .aggregate = .{
1816518161 .ty = struct_field_ty.toIntern(),
......@@ -18195,7 +18191,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1819518191 } },
1819618192 .byte_offset = 0,
1819718193 } }),
18198 .len = (try pt.intValue(Type.usize, struct_field_vals.len)).toIntern(),
18194 .len = (try pt.intValue(.usize, struct_field_vals.len)).toIntern(),
1819918195 } });
1820018196 };
1820118197
......@@ -18304,7 +18300,7 @@ fn typeInfoDecls(
1830418300 } },
1830518301 .byte_offset = 0,
1830618302 } }),
18307 .len = (try pt.intValue(Type.usize, decl_vals.items.len)).toIntern(),
18303 .len = (try pt.intValue(.usize, decl_vals.items.len)).toIntern(),
1830818304 } });
1830918305}
1831018306
......@@ -18354,7 +18350,7 @@ fn typeInfoNamespaceDecls(
1835418350 .byte_offset = 0,
1835518351 },
1835618352 }),
18357 .len = (try pt.intValue(Type.usize, name_len)).toIntern(),
18353 .len = (try pt.intValue(.usize, name_len)).toIntern(),
1835818354 },
1835918355 });
1836018356 };
......@@ -18373,7 +18369,7 @@ fn typeInfoNamespaceDecls(
1837318369 continue;
1837418370 }
1837518371 try sema.ensureNavResolved(block, src, nav, .fully);
18376 const namespace_ty = Type.fromInterned(ip.getNav(nav).status.fully_resolved.val);
18372 const namespace_ty: Type = .fromInterned(ip.getNav(nav).status.fully_resolved.val);
1837718373 try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu).toOptional(), declaration_ty, decl_vals, seen_namespaces);
1837818374 }
1837918375}
......@@ -18424,7 +18420,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1842418420 const pt = sema.pt;
1842518421 const zcu = pt.zcu;
1842618422 switch (operand.zigTypeTag(zcu)) {
18427 .comptime_int => return Type.comptime_int,
18423 .comptime_int => return .comptime_int,
1842818424 .int => {
1842918425 const bits = operand.bitSize(zcu);
1843018426 const count = if (bits == 0)
......@@ -18512,14 +18508,12 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1851218508 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1851318509 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1851418510
18515 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
18511 const operand = try sema.coerce(block, .bool, uncasted_operand, operand_src);
1851618512 if (try sema.resolveValue(operand)) |val| {
18517 return if (val.isUndef(zcu))
18518 pt.undefRef(Type.bool)
18519 else if (val.toBool()) .bool_false else .bool_true;
18513 return if (val.isUndef(zcu)) .undef_bool else if (val.toBool()) .bool_false else .bool_true;
1852018514 }
1852118515 try sema.requireRuntimeBlock(block, src, null);
18522 return block.addTyOp(.not, Type.bool, operand);
18516 return block.addTyOp(.not, .bool, operand);
1852318517}
1852418518
1852518519fn zirBoolBr(
......@@ -18544,7 +18538,7 @@ fn zirBoolBr(
1854418538 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1854518539 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1854618540
18547 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);
18541 const lhs = try sema.coerce(parent_block, .bool, uncoerced_lhs, lhs_src);
1854818542
1854918543 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
1855018544 if (is_bool_or and lhs_val.toBool()) {
......@@ -18559,7 +18553,7 @@ fn zirBoolBr(
1855918553 if (sema.typeOf(rhs_result).isNoReturn(zcu)) {
1856018554 return rhs_result;
1856118555 }
18562 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);
18556 return sema.coerce(parent_block, .bool, rhs_result, rhs_src);
1856318557 }
1856418558
1856518559 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
......@@ -18596,7 +18590,7 @@ fn zirBoolBr(
1859618590 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);
1859718591 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(zcu);
1859818592 const coerced_rhs_result = if (!rhs_noret) rhs: {
18599 const coerced_result = try sema.coerce(rhs_block, Type.bool, rhs_result, rhs_src);
18593 const coerced_result = try sema.coerce(rhs_block, .bool, rhs_result, rhs_src);
1860018594 _ = try rhs_block.addBr(block_inst, coerced_result);
1860118595 break :rhs coerced_result;
1860218596 } else rhs_result;
......@@ -18797,7 +18791,7 @@ fn zirCondbr(
1879718791 const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
1879818792
1879918793 const uncasted_cond = try sema.resolveInst(extra.data.condition);
18800 const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src);
18794 const cond = try sema.coerce(parent_block, .bool, uncasted_cond, cond_src);
1880118795
1880218796 if (try sema.resolveDefinedValue(parent_block, cond_src, cond)) |cond_val| {
1880318797 const body = if (cond_val.toBool()) then_body else else_body;
......@@ -19502,7 +19496,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1950219496 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {
1950319497 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1950419498 extra_i += 1;
19505 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
19499 const coerced = try sema.coerce(block, .u32, try sema.resolveInst(ref), align_src);
1950619500 const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ .simple = .@"align" });
1950719501 // Check if this happens to be the lazy alignment of our element type, in
1950819502 // which case we can make this 0 without resolving it.
......@@ -19526,14 +19520,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1952619520 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
1952719521 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1952819522 extra_i += 1;
19529 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{ .simple = .type });
19523 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, .u16, .{ .simple = .type });
1953019524 break :blk @intCast(bit_offset);
1953119525 } else 0;
1953219526
1953319527 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
1953419528 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1953519529 extra_i += 1;
19536 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{ .simple = .type });
19530 const host_size = try sema.resolveInt(block, hostsize_src, ref, .u16, .{ .simple = .type });
1953719531 break :blk @intCast(host_size);
1953819532 } else 0;
1953919533
......@@ -19767,7 +19761,7 @@ fn unionInit(
1976719761 const zcu = pt.zcu;
1976819762 const ip = &zcu.intern_pool;
1976919763 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
19770 const field_ty = Type.fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
19764 const field_ty: Type = .fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
1977119765 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
1977219766 _ = union_ty_src;
1977319767 return unionInitFromEnumTag(sema, block, init_src, union_ty, field_index, init);
......@@ -19902,7 +19896,7 @@ fn zirStructInit(
1990219896 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
1990319897 const tag_ty = resolved_ty.unionTagTypeHypothetical(zcu);
1990419898 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
19905 const field_ty = Type.fromInterned(zcu.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
19899 const field_ty: Type = .fromInterned(zcu.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
1990619900
1990719901 if (field_ty.zigTypeTag(zcu) == .noreturn) {
1990819902 return sema.failWithOwnedErrorMsg(block, msg: {
......@@ -19990,7 +19984,7 @@ fn finishStructInit(
1999019984 .init_node_offset = init_src.offset.node_offset.x,
1999119985 .elem_index = @intCast(i),
1999219986 } });
19993 const field_ty = Type.fromInterned(tuple.types.get(ip)[i]);
19987 const field_ty: Type = .fromInterned(tuple.types.get(ip)[i]);
1999419988 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
1999519989 continue;
1999619990 }
......@@ -20018,7 +20012,7 @@ fn finishStructInit(
2001820012 .init_node_offset = init_src.offset.node_offset.x,
2001920013 .elem_index = @intCast(i),
2002020014 } });
20021 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
20015 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
2002220016 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
2002320017 continue;
2002420018 }
......@@ -20183,7 +20177,7 @@ fn structInitAnon(
2018320177 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2018420178 errdefer msg.destroy(sema.gpa);
2018520179
20186 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
20180 try sema.addDeclaredHereNote(msg, .fromInterned(field_ty.*));
2018720181 break :msg msg;
2018820182 };
2018920183 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -20317,7 +20311,7 @@ fn structInitAnon(
2031720311 element_refs[i] = try sema.resolveInst(item.data.init);
2031820312 }
2031920313
20320 return block.addAggregateInit(Type.fromInterned(struct_ty), element_refs);
20314 return block.addAggregateInit(.fromInterned(struct_ty), element_refs);
2032120315}
2032220316
2032320317fn zirArrayInit(
......@@ -20441,7 +20435,7 @@ fn zirArrayInit(
2044120435 });
2044220436 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
2044320437
20444 const index = try pt.intRef(Type.usize, i);
20438 const index = try pt.intRef(.usize, i);
2044520439 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);
2044620440 _ = try block.addBinOp(.store, elem_ptr, arg);
2044720441 }
......@@ -20455,7 +20449,7 @@ fn zirArrayInit(
2045520449 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
2045620450
2045720451 for (resolved_args, 0..) |arg, i| {
20458 const index = try pt.intRef(Type.usize, i);
20452 const index = try pt.intRef(.usize, i);
2045920453 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);
2046020454 _ = try block.addBinOp(.store, elem_ptr, arg);
2046120455 }
......@@ -20504,7 +20498,7 @@ fn arrayInitAnon(
2050420498 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2050520499 errdefer msg.destroy(gpa);
2050620500
20507 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
20501 try sema.addDeclaredHereNote(msg, .fromInterned(types[i]));
2050820502 break :msg msg;
2050920503 };
2051020504 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -20561,7 +20555,7 @@ fn arrayInitAnon(
2056120555 element_refs[i] = try sema.resolveInst(operand);
2056220556 }
2056320557
20564 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
20558 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
2056520559}
2056620560
2056720561fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {
......@@ -20632,7 +20626,7 @@ fn fieldType(
2063220626 .optional => {
2063320627 // Struct/array init through optional requires the child type to not be a pointer.
2063420628 // If the child of .optional is a pointer it'll error on the next loop.
20635 cur_ty = Type.fromInterned(ip.indexToKey(cur_ty.toIntern()).opt_type);
20629 cur_ty = .fromInterned(ip.indexToKey(cur_ty.toIntern()).opt_type);
2063620630 continue;
2063720631 },
2063820632 .error_union => {
......@@ -20710,21 +20704,18 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2071020704 const dest_ty: Type = if (is_vector) try pt.vectorType(.{ .child = .u1_type, .len = len }) else .u1;
2071120705 if (try sema.resolveValue(operand)) |val| {
2071220706 if (!is_vector) {
20713 if (val.isUndef(zcu)) return pt.undefRef(Type.u1);
20714 if (val.toBool()) return Air.internedToRef((try pt.intValue(Type.u1, 1)).toIntern());
20715 return Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
20707 return if (val.isUndef(zcu)) .undef_u1 else if (val.toBool()) .one_u1 else .zero_u1;
2071620708 }
2071720709 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
2071820710 const new_elems = try sema.arena.alloc(InternPool.Index, len);
2071920711 for (new_elems, 0..) |*new_elem, i| {
2072020712 const old_elem = try val.elemValue(pt, i);
20721 const new_val = if (old_elem.isUndef(zcu))
20722 try pt.undefValue(Type.u1)
20713 new_elem.* = if (old_elem.isUndef(zcu))
20714 .undef_u1
2072320715 else if (old_elem.toBool())
20724 try pt.intValue(Type.u1, 1)
20716 .one_u1
2072520717 else
20726 try pt.intValue(Type.u1, 0);
20727 new_elem.* = new_val.toIntern();
20718 .zero_u1;
2072820719 }
2072920720 return Air.internedToRef(try pt.intern(.{ .aggregate = .{
2073020721 .ty = dest_ty.toIntern(),
......@@ -20736,7 +20727,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2073620727 }
2073720728 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2073820729 for (new_elems, 0..) |*new_elem, i| {
20739 const idx_ref = try pt.intRef(Type.usize, i);
20730 const idx_ref = try pt.intRef(.usize, i);
2074020731 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
2074120732 new_elem.* = try block.addBitCast(.u1, old_elem);
2074220733 }
......@@ -20747,7 +20738,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2074720738 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2074820739 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2074920740 const uncoerced_operand = try sema.resolveInst(inst_data.operand);
20750 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);
20741 const operand = try sema.coerce(block, .anyerror, uncoerced_operand, operand_src);
2075120742
2075220743 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
2075320744 const err_name = sema.pt.zcu.intern_pool.indexToKey(val.toIntern()).err.name;
......@@ -20993,12 +20984,12 @@ fn zirReify(
2099320984 .float => {
2099420985 const float = try sema.interpretBuiltinType(block, operand_src, .fromInterned(union_val.val), std.builtin.Type.Float);
2099520986
20996 const ty = switch (float.bits) {
20997 16 => Type.f16,
20998 32 => Type.f32,
20999 64 => Type.f64,
21000 80 => Type.f80,
21001 128 => Type.f128,
20987 const ty: Type = switch (float.bits) {
20988 16 => .f16,
20989 32 => .f32,
20990 64 => .f64,
20991 80 => .f80,
20992 128 => .f128,
2100220993 else => return sema.fail(block, src, "{}-bit float unsupported", .{float.bits}),
2100320994 };
2100420995 return Air.internedToRef(ty.toIntern());
......@@ -21038,7 +21029,7 @@ fn zirReify(
2103821029 try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls),
2103921030 ).?);
2104021031
21041 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
21032 if (!try sema.intFitsInType(alignment_val, .u32, null)) {
2104221033 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2104321034 }
2104421035
......@@ -21174,7 +21165,7 @@ fn zirReify(
2117421165 },
2117521166 .error_set => {
2117621167 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse
21177 return Air.internedToRef(Type.anyerror.toIntern());
21168 return .anyerror_type;
2117821169
2117921170 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{ .simple = .error_set_contents });
2118021171
......@@ -21776,7 +21767,7 @@ fn reifyUnion(
2177621767 errdefer if (!has_explicit_tag) ip.remove(pt.tid, enum_tag_ty); // remove generated tag type on error
2177721768
2177821769 for (field_types) |field_ty_ip| {
21779 const field_ty = Type.fromInterned(field_ty_ip);
21770 const field_ty: Type = .fromInterned(field_ty_ip);
2178021771 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
2178121772 return sema.failWithOwnedErrorMsg(block, msg: {
2178221773 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
......@@ -22060,7 +22051,7 @@ fn reifyStruct(
2206022051 }
2206122052
2206222053 if (any_aligned_fields) {
22063 if (!try sema.intFitsInType(field_alignment_val, Type.u32, null)) {
22054 if (!try sema.intFitsInType(field_alignment_val, .u32, null)) {
2206422055 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2206522056 }
2206622057
......@@ -22149,7 +22140,7 @@ fn reifyStruct(
2214922140 if (layout == .@"packed") {
2215022141 var fields_bit_sum: u64 = 0;
2215122142 for (0..struct_type.field_types.len) |field_idx| {
22152 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_idx]);
22143 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_idx]);
2215322144 field_ty.resolveLayout(pt) catch |err| switch (err) {
2215422145 error.AnalysisFail => {
2215522146 const msg = sema.err orelse return err;
......@@ -22325,7 +22316,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2232522316 if (block.wantSafety()) {
2232622317 const len = dest_ty.vectorLen(zcu);
2232722318 for (0..len) |i| {
22328 const idx_ref = try pt.intRef(Type.usize, i);
22319 const idx_ref = try pt.intRef(.usize, i);
2232922320 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);
2233022321 const ok = try block.addBinOp(if (block.float_mode == .optimized) .cmp_eq_optimized else .cmp_eq, elem_ref, Air.internedToRef((try pt.floatValue(operand_scalar_ty, 0.0)).toIntern()));
2233122322 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
......@@ -22358,7 +22349,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2235822349 const len = dest_ty.vectorLen(zcu);
2235922350 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2236022351 for (new_elems, 0..) |*new_elem, i| {
22361 const idx_ref = try pt.intRef(Type.usize, i);
22352 const idx_ref = try pt.intRef(.usize, i);
2236222353 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
2236322354 const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);
2236422355 if (block.wantSafety()) {
......@@ -22408,7 +22399,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2240822399 const len = operand_ty.vectorLen(zcu);
2240922400 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2241022401 for (new_elems, 0..) |*new_elem, i| {
22411 const idx_ref = try pt.intRef(Type.usize, i);
22402 const idx_ref = try pt.intRef(.usize, i);
2241222403 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
2241322404 new_elem.* = try block.addTyOp(.float_from_int, dest_scalar_ty, old_elem);
2241422405 }
......@@ -22431,10 +22422,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2243122422 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);
2243222423
2243322424 const is_vector = dest_ty.zigTypeTag(zcu) == .vector;
22434 const operand_ty = if (is_vector) operand_ty: {
22425 const operand_ty: Type = if (is_vector) operand_ty: {
2243522426 const len = dest_ty.vectorLen(zcu);
2243622427 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });
22437 } else Type.usize;
22428 } else .usize;
2243822429
2243922430 const operand_coerced = try sema.coerce(block, operand_ty, operand_res, operand_src);
2244022431
......@@ -22495,7 +22486,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2249522486 if (ptr_align.compare(.gt, .@"1")) {
2249622487 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
2249722488 const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(
22498 Type.usize,
22489 .usize,
2249922490 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
2250022491 align_bytes_minus_1 & mask
2250122492 else
......@@ -22516,7 +22507,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2251622507 const len = dest_ty.vectorLen(zcu);
2251722508 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .@"fn")) {
2251822509 for (0..len) |i| {
22519 const idx_ref = try pt.intRef(Type.usize, i);
22510 const idx_ref = try pt.intRef(.usize, i);
2252022511 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
2252122512 if (!ptr_ty.isAllowzeroPtr(zcu)) {
2252222513 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);
......@@ -22525,7 +22516,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2252522516 if (ptr_align.compare(.gt, .@"1")) {
2252622517 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
2252722518 const align_mask = Air.internedToRef((try pt.intValue(
22528 Type.usize,
22519 .usize,
2252922520 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
2253022521 align_bytes_minus_1 & mask
2253122522 else
......@@ -22540,7 +22531,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2254022531
2254122532 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2254222533 for (new_elems, 0..) |*new_elem, i| {
22543 const idx_ref = try pt.intRef(Type.usize, i);
22534 const idx_ref = try pt.intRef(.usize, i);
2254422535 const old_elem = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
2254522536 new_elem.* = try block.addBitCast(ptr_ty, old_elem);
2254622537 }
......@@ -22918,12 +22909,12 @@ fn ptrCastFull(
2291822909 }
2291922910
2292022911 check_child: {
22921 const src_child = if (dest_info.flags.size == .slice and src_info.flags.size == .one) blk: {
22912 const src_child: Type = if (dest_info.flags.size == .slice and src_info.flags.size == .one) blk: {
2292222913 // *[n]T -> []T
2292322914 break :blk Type.fromInterned(src_info.child).childType(zcu);
22924 } else Type.fromInterned(src_info.child);
22915 } else .fromInterned(src_info.child);
2292522916
22926 const dest_child = Type.fromInterned(dest_info.child);
22917 const dest_child: Type = .fromInterned(dest_info.child);
2292722918
2292822919 const imc_res = try sema.coerceInMemoryAllowed(
2292922920 block,
......@@ -22956,7 +22947,7 @@ fn ptrCastFull(
2295622947 }
2295722948 if (is_array_ptr_to_slice) {
2295822949 // [*]nT -> []T
22959 const arr_ty = Type.fromInterned(src_info.child);
22950 const arr_ty: Type = .fromInterned(src_info.child);
2296022951 if (arr_ty.sentinel(zcu)) |src_sentinel| {
2296122952 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
2296222953 if (dest_info.sentinel == coerced_sent) break :check_sent;
......@@ -23158,7 +23149,7 @@ fn ptrCastFull(
2315823149 if (dest_info.flags.size == .slice) {
2315923150 // Because the operand is comptime-known and not `null`, the slice length has already been computed:
2316023151 const len: Value = switch (dest_slice_len.?) {
23161 .undef => try pt.undefValue(.usize),
23152 .undef => .undef_usize,
2316223153 .constant => |n| try pt.intValue(.usize, n),
2316323154 .equal_runtime_src_slice => unreachable,
2316423155 .change_runtime_src_slice => unreachable,
......@@ -23267,7 +23258,7 @@ fn ptrCastFull(
2326723258 if (need_align_check) {
2326823259 assert(operand_ptr_int != .none);
2326923260 const align_mask = try pt.intRef(.usize, mask: {
23270 const target_ptr_mask: u64 = Type.fromInterned(dest_info.child).fnPtrMaskOrNull(zcu) orelse ~@as(u64, 0);
23261 const target_ptr_mask = Type.fromInterned(dest_info.child).fnPtrMaskOrNull(zcu) orelse ~@as(u64, 0);
2327123262 break :mask (dest_align.toByteUnits().? - 1) & target_ptr_mask;
2327223263 });
2327323264 const ptr_masked = try block.addBinOp(.bit_and, operand_ptr_int, align_mask);
......@@ -23288,7 +23279,7 @@ fn ptrCastFull(
2328823279 assert(need_operand_ptr);
2328923280
2329023281 const result_len: Air.Inst.Ref = switch (dest_slice_len.?) {
23291 .undef => try pt.undefRef(.usize),
23282 .undef => .undef_usize,
2329223283 .constant => |n| try pt.intRef(.usize, n),
2329323284 .equal_runtime_src_slice => len: {
2329423285 assert(need_operand_len);
......@@ -23658,13 +23649,13 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2365823649
2365923650fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2366023651 const offset = try sema.bitOffsetOf(block, inst);
23661 return sema.pt.intRef(Type.comptime_int, offset);
23652 return sema.pt.intRef(.comptime_int, offset);
2366223653}
2366323654
2366423655fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2366523656 const offset = try sema.bitOffsetOf(block, inst);
2366623657 // TODO reminder to make this a compile error for packed structs
23667 return sema.pt.intRef(Type.comptime_int, offset / 8);
23658 return sema.pt.intRef(.comptime_int, offset / 8);
2366823659}
2366923660
2367023661fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
......@@ -23705,7 +23696,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2370523696 if (i == field_index) {
2370623697 return bit_sum;
2370723698 }
23708 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
23699 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
2370923700 bit_sum += field_ty.bitSize(zcu);
2371023701 } else unreachable;
2371123702 },
......@@ -24620,10 +24611,10 @@ fn analyzeShuffle(
2462024611
2462124612 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
2462224613 for (@intCast(0)..@intCast(min_len)) |i| {
24623 expand_mask_values[i] = (try pt.intValue(Type.comptime_int, i)).toIntern();
24614 expand_mask_values[i] = (try pt.intValue(.comptime_int, i)).toIntern();
2462424615 }
2462524616 for (@intCast(min_len)..@intCast(max_len)) |i| {
24626 expand_mask_values[i] = (try pt.intValue(Type.comptime_int, -1)).toIntern();
24617 expand_mask_values[i] = .negative_one;
2462724618 }
2462824619 const expand_mask = try pt.intern(.{ .aggregate = .{
2462924620 .ty = (try pt.vectorType(.{ .len = @intCast(max_len), .child = .comptime_int_type })).toIntern(),
......@@ -25087,7 +25078,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2508725078 if (parent_ptr_info.flags.size != .one) {
2508825079 return sema.fail(block, inst_src, "expected single pointer type, found '{}'", .{parent_ptr_ty.fmt(pt)});
2508925080 }
25090 const parent_ty = Type.fromInterned(parent_ptr_info.child);
25081 const parent_ty: Type = .fromInterned(parent_ptr_info.child);
2509125082 switch (parent_ty.zigTypeTag(zcu)) {
2509225083 .@"struct", .@"union" => {},
2509325084 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{}'", .{parent_ptr_ty.fmt(pt)}),
......@@ -25741,7 +25732,7 @@ fn zirMemcpy(
2574125732 if (try sema.resolveDefinedValue(block, dest_src, dest_len)) |dest_len_val| {
2574225733 len_val = dest_len_val;
2574325734 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
25744 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
25735 if (!(try sema.valuesEqual(dest_len_val, src_len_val, .usize))) {
2574525736 const msg = msg: {
2574625737 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
2574725738 errdefer msg.destroy(sema.gpa);
......@@ -25952,7 +25943,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2595225943 const dest_elem_ty: Type = dest_elem_ty: {
2595325944 const ptr_info = dest_ptr_ty.ptrInfo(zcu);
2595425945 switch (ptr_info.flags.size) {
25955 .slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),
25946 .slice => break :dest_elem_ty .fromInterned(ptr_info.child),
2595625947 .one => {
2595725948 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) {
2595825949 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu);
......@@ -26118,7 +26109,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2611826109 extra_index += body.len;
2611926110 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;
2612026111
26121 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty });
26112 const val = try sema.resolveGenericBody(block, ret_src, body, inst, .type, .{ .simple = .function_ret_ty });
2612226113 const ty = val.toType();
2612326114 break :blk ty;
2612426115 } else if (extra.data.bits.has_ret_ty_ref) blk: {
......@@ -26129,7 +26120,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2612926120 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);
2613026121 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });
2613126122 break :blk ret_ty_val.toType();
26132 } else Type.void;
26123 } else .void;
2613326124
2613426125 const noalias_bits: u32 = if (extra.data.bits.has_any_noalias) blk: {
2613526126 const x = sema.code.extra[extra_index];
......@@ -26223,7 +26214,7 @@ fn zirWasmMemorySize(
2622326214 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2622426215 }
2622526216
26226 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{ .simple = .wasm_memory_index }));
26217 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, .u32, .{ .simple = .wasm_memory_index }));
2622726218 try sema.requireRuntimeBlock(block, builtin_src, null);
2622826219 return block.addInst(.{
2622926220 .tag = .wasm_memory_size,
......@@ -26248,8 +26239,8 @@ fn zirWasmMemoryGrow(
2624826239 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2624926240 }
2625026241
26251 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ .simple = .wasm_memory_index }));
26252 const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);
26242 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, .u32, .{ .simple = .wasm_memory_index }));
26243 const delta = try sema.coerce(block, .usize, try sema.resolveInst(extra.rhs), delta_src);
2625326244
2625426245 try sema.requireRuntimeBlock(block, builtin_src, null);
2625526246 return block.addInst(.{
......@@ -26484,7 +26475,7 @@ fn zirWorkItem(
2648426475 },
2648526476 }
2648626477
26487 const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{ .simple = .work_group_dim_index }));
26478 const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, .u32, .{ .simple = .work_group_dim_index }));
2648826479 try sema.requireRuntimeBlock(block, builtin_src, null);
2648926480
2649026481 return block.addInst(.{
......@@ -26552,7 +26543,7 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2655226543 const inline_tag_val = try pt.enumValue(
2655326544 callconv_tag_ty,
2655426545 (try pt.intValue(
26555 Type.u8,
26546 .u8,
2655626547 @intFromEnum(std.builtin.CallingConvention.@"inline"),
2655726548 )).toIntern(),
2655826549 );
......@@ -26760,7 +26751,7 @@ fn explainWhyTypeIsComptimeInner(
2676026751
2676126752 if (zcu.typeToStruct(ty)) |struct_type| {
2676226753 for (0..struct_type.field_types.len) |i| {
26763 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26754 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
2676426755 const field_src: LazySrcLoc = .{
2676526756 .base_node_inst = struct_type.zir_index,
2676626757 .offset = .{ .container_field_type = @intCast(i) },
......@@ -26780,7 +26771,7 @@ fn explainWhyTypeIsComptimeInner(
2678026771
2678126772 if (zcu.typeToUnion(ty)) |union_obj| {
2678226773 for (0..union_obj.field_types.len) |i| {
26783 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26774 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[i]);
2678426775 const field_src: LazySrcLoc = .{
2678526776 .base_node_inst = union_obj.zir_index,
2678626777 .offset = .{ .container_field_type = @intCast(i) },
......@@ -27171,7 +27162,7 @@ fn addSafetyCheckUnwrapError(
2717127162
2717227163 defer fail_block.instructions.deinit(gpa);
2717327164
27174 const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand);
27165 const err = try fail_block.addTyOp(unwrap_err_tag, .anyerror, operand);
2717527166 try safetyPanicUnwrapError(sema, &fail_block, src, err);
2717627167
2717727168 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);
......@@ -27344,7 +27335,7 @@ fn fieldVal(
2734427335 switch (inner_ty.zigTypeTag(zcu)) {
2734527336 .array => {
2734627337 if (field_name.eqlSlice("len", ip)) {
27347 return Air.internedToRef((try pt.intValue(Type.usize, inner_ty.arrayLen(zcu))).toIntern());
27338 return Air.internedToRef((try pt.intValue(.usize, inner_ty.arrayLen(zcu))).toIntern());
2734827339 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
2734927340 const ptr_info = object_ty.ptrInfo(zcu);
2735027341 const result_ty = try pt.ptrTypeSema(.{
......@@ -27527,7 +27518,7 @@ fn fieldPtr(
2752727518 switch (inner_ty.zigTypeTag(zcu)) {
2752827519 .array => {
2752927520 if (field_name.eqlSlice("len", ip)) {
27530 const int_val = try pt.intValue(Type.usize, inner_ty.arrayLen(zcu));
27521 const int_val = try pt.intValue(.usize, inner_ty.arrayLen(zcu));
2753127522 return uavRef(sema, int_val.toIntern());
2753227523 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
2753327524 const ptr_info = object_ty.ptrInfo(zcu);
......@@ -27769,12 +27760,12 @@ fn fieldCallBind(
2776927760 if (zcu.typeToStruct(concrete_ty)) |struct_type| {
2777027761 const field_index = struct_type.nameIndex(ip, field_name) orelse
2777127762 break :find_field;
27772 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
27763 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
2777327764
2777427765 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
2777527766 } else if (concrete_ty.isTuple(zcu)) {
2777627767 if (field_name.eqlSlice("len", ip)) {
27777 return .{ .direct = try pt.intRef(Type.usize, concrete_ty.structFieldCount(zcu)) };
27768 return .{ .direct = try pt.intRef(.usize, concrete_ty.structFieldCount(zcu)) };
2777827769 }
2777927770 if (field_name.toUnsigned(ip)) |field_index| {
2778027771 if (field_index >= concrete_ty.structFieldCount(zcu)) break :find_field;
......@@ -27817,7 +27808,7 @@ fn fieldCallBind(
2781727808 if (zcu.typeToFunc(decl_type)) |func_type| f: {
2781827809 if (func_type.param_types.len == 0) break :f;
2781927810
27820 const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]);
27811 const first_param_type: Type = .fromInterned(func_type.param_types.get(ip)[0]);
2782127812 if (first_param_type.isGenericPoison() or
2782227813 (first_param_type.zigTypeTag(zcu) == .pointer and
2782327814 (first_param_type.ptrSize(zcu) == .one or
......@@ -28003,7 +27994,7 @@ fn structFieldPtr(
2800327994
2800427995 if (struct_ty.isTuple(zcu)) {
2800527996 if (field_name.eqlSlice("len", ip)) {
28006 const len_inst = try pt.intRef(Type.usize, struct_ty.structFieldCount(zcu));
27997 const len_inst = try pt.intRef(.usize, struct_ty.structFieldCount(zcu));
2800727998 return sema.analyzeRef(block, src, len_inst);
2800827999 }
2800928000 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
......@@ -28134,7 +28125,7 @@ fn structFieldVal(
2813428125 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
2813528126 }
2813628127
28137 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
28128 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
2813828129 if (try sema.typeHasOnePossibleValue(field_ty)) |field_val|
2813928130 return Air.internedToRef(field_val.toIntern());
2814028131
......@@ -28167,7 +28158,7 @@ fn tupleFieldVal(
2816728158 const pt = sema.pt;
2816828159 const zcu = pt.zcu;
2816928160 if (field_name.eqlSlice("len", &zcu.intern_pool)) {
28170 return pt.intRef(Type.usize, tuple_ty.structFieldCount(zcu));
28161 return pt.intRef(.usize, tuple_ty.structFieldCount(zcu));
2817128162 }
2817228163 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
2817328164 return sema.tupleFieldValByIndex(block, tuple_byval, field_index, tuple_ty);
......@@ -28220,7 +28211,7 @@ fn tupleFieldValByIndex(
2822028211 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {
2822128212 .undef => pt.undefRef(field_ty),
2822228213 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
28223 .bytes => |bytes| try pt.intValue(Type.u8, bytes.at(field_index, &zcu.intern_pool)),
28214 .bytes => |bytes| try pt.intValue(.u8, bytes.at(field_index, &zcu.intern_pool)),
2822428215 .elems => |elems| Value.fromInterned(elems[field_index]),
2822528216 .repeated_elem => |elem| Value.fromInterned(elem),
2822628217 }.toIntern()),
......@@ -28253,7 +28244,7 @@ fn unionFieldPtr(
2825328244 try union_ty.resolveFields(pt);
2825428245 const union_obj = zcu.typeToUnion(union_ty).?;
2825528246 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
28256 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
28247 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
2825728248 const ptr_field_ty = try pt.ptrTypeSema(.{
2825828249 .child = field_ty.toIntern(),
2825928250 .flags = .{
......@@ -28295,8 +28286,8 @@ fn unionFieldPtr(
2829528286 break :ct;
2829628287 }
2829728288 // Store to the union to initialize the tag.
28298 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28299 const payload_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
28289 const field_tag = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28290 const payload_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
2830028291 const new_union_val = try pt.unionValue(union_ty, field_tag, try pt.undefValue(payload_ty));
2830128292 try sema.storePtrVal(block, src, union_ptr_val, new_union_val, union_ty);
2830228293 } else {
......@@ -28306,7 +28297,7 @@ fn unionFieldPtr(
2830628297 return sema.failWithUseOfUndef(block, src);
2830728298 }
2830828299 const un = ip.indexToKey(union_val.toIntern()).un;
28309 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28300 const field_tag = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2831028301 const tag_matches = un.tag == field_tag.toIntern();
2831128302 if (!tag_matches) {
2831228303 const msg = msg: {
......@@ -28332,11 +28323,11 @@ fn unionFieldPtr(
2833228323 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2833328324 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2833428325 {
28335 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28326 const wanted_tag_val = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2833628327 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
2833728328 // TODO would it be better if get_union_tag supported pointers to unions?
2833828329 const union_val = try block.addTyOp(.load, union_ty, union_ptr);
28339 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);
28330 const active_tag = try block.addTyOp(.get_union_tag, .fromInterned(union_obj.enum_tag_ty), union_val);
2834028331 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);
2834128332 }
2834228333 if (field_ty.zigTypeTag(zcu) == .noreturn) {
......@@ -28363,14 +28354,14 @@ fn unionFieldVal(
2836328354 try union_ty.resolveFields(pt);
2836428355 const union_obj = zcu.typeToUnion(union_ty).?;
2836528356 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
28366 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
28357 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
2836728358 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, zcu).?);
2836828359
2836928360 if (try sema.resolveValue(union_byval)) |union_val| {
2837028361 if (union_val.isUndef(zcu)) return pt.undefRef(field_ty);
2837128362
2837228363 const un = ip.indexToKey(union_val.toIntern()).un;
28373 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28364 const field_tag = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2837428365 const tag_matches = un.tag == field_tag.toIntern();
2837528366 switch (union_obj.flagsUnordered(ip).layout) {
2837628367 .auto => {
......@@ -28408,9 +28399,9 @@ fn unionFieldVal(
2840828399 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2840928400 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2841028401 {
28411 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28402 const wanted_tag_val = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2841228403 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
28413 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_byval);
28404 const active_tag = try block.addTyOp(.get_union_tag, .fromInterned(union_obj.enum_tag_ty), union_byval);
2841428405 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);
2841528406 }
2841628407 if (field_ty.zigTypeTag(zcu) == .noreturn) {
......@@ -28540,7 +28531,7 @@ fn elemVal(
2854028531
2854128532 // TODO in case of a vector of pointers, we need to detect whether the element
2854228533 // index is a scalar or vector instead of unconditionally casting to usize.
28543 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
28534 const elem_index = try sema.coerce(block, .usize, elem_index_uncasted, elem_index_src);
2854428535
2854528536 switch (indexable_ty.zigTypeTag(zcu)) {
2854628537 .pointer => switch (indexable_ty.ptrSize(zcu)) {
......@@ -28795,7 +28786,7 @@ fn elemValArray(
2879528786 if (oob_safety and block.wantSafety()) {
2879628787 // Runtime check is only needed if unable to comptime check.
2879728788 if (maybe_index_val == null) {
28798 const len_inst = try pt.intRef(Type.usize, array_len);
28789 const len_inst = try pt.intRef(.usize, array_len);
2879928790 const cmp_op: Air.Inst.Tag = if (array_sent != null) .cmp_lte else .cmp_lt;
2880028791 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
2880128792 }
......@@ -28860,7 +28851,7 @@ fn elemPtrArray(
2886028851
2886128852 // Runtime check is only needed if unable to comptime check.
2886228853 if (oob_safety and block.wantSafety() and offset == null) {
28863 const len_inst = try pt.intRef(Type.usize, array_len);
28854 const len_inst = try pt.intRef(.usize, array_len);
2886428855 const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt;
2886528856 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
2886628857 }
......@@ -28917,9 +28908,9 @@ fn elemValSlice(
2891728908
2891828909 if (oob_safety and block.wantSafety()) {
2891928910 const len_inst = if (maybe_slice_val) |slice_val|
28920 try pt.intRef(Type.usize, try slice_val.sliceLen(pt))
28911 try pt.intRef(.usize, try slice_val.sliceLen(pt))
2892128912 else
28922 try block.addTyOp(.slice_len, Type.usize, slice);
28913 try block.addTyOp(.slice_len, .usize, slice);
2892328914 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
2892428915 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
2892528916 }
......@@ -28976,8 +28967,8 @@ fn elemPtrSlice(
2897628967 const len_inst = len: {
2897728968 if (maybe_undef_slice_val) |slice_val|
2897828969 if (!slice_val.isUndef(zcu))
28979 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));
28980 break :len try block.addTyOp(.slice_len, Type.usize, slice);
28970 break :len try pt.intRef(.usize, try slice_val.sliceLen(pt));
28971 break :len try block.addTyOp(.slice_len, .usize, slice);
2898128972 };
2898228973 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
2898328974 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
......@@ -29142,7 +29133,7 @@ fn coerceExtra(
2914229133 if (!inst_ty.isSinglePointer(zcu)) break :single_item;
2914329134 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
2914429135 const ptr_elem_ty = inst_ty.childType(zcu);
29145 const array_ty = Type.fromInterned(dest_info.child);
29136 const array_ty: Type = .fromInterned(dest_info.child);
2914629137 if (array_ty.zigTypeTag(zcu) != .array) break :single_item;
2914729138 const array_elem_ty = array_ty.childType(zcu);
2914829139 if (array_ty.arrayLen(zcu) != 1) break :single_item;
......@@ -29164,7 +29155,7 @@ fn coerceExtra(
2916429155 const array_elem_type = array_ty.childType(zcu);
2916529156 const dest_is_mut = !dest_info.flags.is_const;
2916629157
29167 const dst_elem_type = Type.fromInterned(dest_info.child);
29158 const dst_elem_type: Type = .fromInterned(dest_info.child);
2916829159 const elem_res = try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src, maybe_inst_val);
2916929160 switch (elem_res) {
2917029161 .ok => {},
......@@ -29225,7 +29216,7 @@ fn coerceExtra(
2922529216 // could be null.
2922629217 const src_elem_ty = inst_ty.childType(zcu);
2922729218 const dest_is_mut = !dest_info.flags.is_const;
29228 const dst_elem_type = Type.fromInterned(dest_info.child);
29219 const dst_elem_type: Type = .fromInterned(dest_info.child);
2922929220 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src, maybe_inst_val)) {
2923029221 .ok => {},
2923129222 else => break :src_c_ptr,
......@@ -29265,16 +29256,16 @@ fn coerceExtra(
2926529256 .byte_offset = 0,
2926629257 } })),
2926729258 .comptime_int => {
29268 const addr = sema.coerceExtra(block, Type.usize, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {
29259 const addr = sema.coerceExtra(block, .usize, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {
2926929260 error.NotCoercible => break :pointer,
2927029261 else => |e| return e,
2927129262 };
2927229263 return try sema.coerceCompatiblePtrs(block, dest_ty, addr, inst_src);
2927329264 },
2927429265 .int => {
29275 const ptr_size_ty = switch (inst_ty.intInfo(zcu).signedness) {
29276 .signed => Type.isize,
29277 .unsigned => Type.usize,
29266 const ptr_size_ty: Type = switch (inst_ty.intInfo(zcu).signedness) {
29267 .signed => .isize,
29268 .unsigned => .usize,
2927829269 };
2927929270 const addr = sema.coerceExtra(block, ptr_size_ty, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {
2928029271 error.NotCoercible => {
......@@ -29291,8 +29282,8 @@ fn coerceExtra(
2929129282 const inst_info = inst_ty.ptrInfo(zcu);
2929229283 switch (try sema.coerceInMemoryAllowed(
2929329284 block,
29294 Type.fromInterned(dest_info.child),
29295 Type.fromInterned(inst_info.child),
29285 .fromInterned(dest_info.child),
29286 .fromInterned(inst_info.child),
2929629287 !dest_info.flags.is_const,
2929729288 target,
2929829289 dest_ty_src,
......@@ -29305,7 +29296,7 @@ fn coerceExtra(
2930529296 if (inst_info.flags.size == .slice) {
2930629297 assert(dest_info.sentinel == .none);
2930729298 if (inst_info.sentinel == .none or
29308 inst_info.sentinel != (try pt.intValue(Type.fromInterned(inst_info.child), 0)).toIntern())
29299 inst_info.sentinel != (try pt.intValue(.fromInterned(inst_info.child), 0)).toIntern())
2930929300 break :p;
2931029301
2931129302 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -29364,8 +29355,8 @@ fn coerceExtra(
2936429355
2936529356 switch (try sema.coerceInMemoryAllowed(
2936629357 block,
29367 Type.fromInterned(dest_info.child),
29368 Type.fromInterned(inst_info.child),
29358 .fromInterned(dest_info.child),
29359 .fromInterned(inst_info.child),
2936929360 !dest_info.flags.is_const,
2937029361 target,
2937129362 dest_ty_src,
......@@ -29378,7 +29369,7 @@ fn coerceExtra(
2937829369
2937929370 if (dest_info.sentinel == .none or inst_info.sentinel == .none or
2938029371 Air.internedToRef(dest_info.sentinel) !=
29381 try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child)))
29372 try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), .fromInterned(dest_info.child)))
2938229373 break :p;
2938329374
2938429375 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -30658,8 +30649,8 @@ fn coerceInMemoryAllowedPtrs(
3065830649 } };
3065930650 }
3066030651
30661 const dest_child = Type.fromInterned(dest_info.child);
30662 const src_child = Type.fromInterned(src_info.child);
30652 const dest_child: Type = .fromInterned(dest_info.child);
30653 const src_child: Type = .fromInterned(src_info.child);
3066330654 const child = try sema.coerceInMemoryAllowed(
3066430655 block,
3066530656 dest_child,
......@@ -30731,7 +30722,7 @@ fn coerceInMemoryAllowedPtrs(
3073130722 .none => Value.@"unreachable",
3073230723 else => Value.fromInterned(dest_info.sentinel),
3073330724 },
30734 .ty = Type.fromInterned(dest_info.child),
30725 .ty = .fromInterned(dest_info.child),
3073530726 } };
3073630727 }
3073730728
......@@ -30794,8 +30785,8 @@ fn coerceVarArgParam(
3079430785 const inst_bits = uncasted_ty.floatBits(target);
3079530786 if (inst_bits >= double_bits) break :float inst;
3079630787 switch (double_bits) {
30797 32 => break :float try sema.coerce(block, Type.f32, inst, inst_src),
30798 64 => break :float try sema.coerce(block, Type.f64, inst, inst_src),
30788 32 => break :float try sema.coerce(block, .f32, inst, inst_src),
30789 64 => break :float try sema.coerce(block, .f64, inst, inst_src),
3079930790 else => unreachable,
3080030791 }
3080130792 },
......@@ -30807,22 +30798,22 @@ fn coerceVarArgParam(
3080730798 .signed => .int,
3080830799 .unsigned => .uint,
3080930800 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30810 .signed => Type.c_int,
30811 .unsigned => Type.c_uint,
30801 .signed => .c_int,
30802 .unsigned => .c_uint,
3081230803 }, inst, inst_src);
3081330804 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
3081430805 .signed => .long,
3081530806 .unsigned => .ulong,
3081630807 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30817 .signed => Type.c_long,
30818 .unsigned => Type.c_ulong,
30808 .signed => .c_long,
30809 .unsigned => .c_ulong,
3081930810 }, inst, inst_src);
3082030811 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
3082130812 .signed => .longlong,
3082230813 .unsigned => .ulonglong,
3082330814 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30824 .signed => Type.c_longlong,
30825 .unsigned => Type.c_ulonglong,
30815 .signed => .c_longlong,
30816 .unsigned => .c_ulonglong,
3082630817 }, inst, inst_src);
3082730818 break :int inst;
3082830819 } else inst,
......@@ -30889,7 +30880,7 @@ fn storePtr2(
3088930880 while (i < field_count) : (i += 1) {
3089030881 const elem_src = operand_src; // TODO better source location
3089130882 const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i);
30892 const elem_index = try pt.intRef(Type.usize, i);
30883 const elem_index = try pt.intRef(.usize, i);
3089330884 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false, true);
3089430885 try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store);
3089530886 }
......@@ -31216,7 +31207,7 @@ fn coerceArrayPtrToSlice(
3121631207 const slice_val = try pt.intern(.{ .slice = .{
3121731208 .ty = dest_ty.toIntern(),
3121831209 .ptr = slice_ptr.toIntern(),
31219 .len = (try pt.intValue(Type.usize, array_ty.arrayLen(zcu))).toIntern(),
31210 .len = (try pt.intValue(.usize, array_ty.arrayLen(zcu))).toIntern(),
3122031211 } });
3122131212 return Air.internedToRef(slice_val);
3122231213 }
......@@ -31358,7 +31349,7 @@ fn coerceEnumToUnion(
3135831349 };
3135931350
3136031351 const union_obj = zcu.typeToUnion(union_ty).?;
31361 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
31352 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
3136231353 try field_ty.resolveFields(pt);
3136331354 if (field_ty.zigTypeTag(zcu) == .noreturn) {
3136431355 const msg = msg: {
......@@ -31448,7 +31439,7 @@ fn coerceEnumToUnion(
3144831439
3144931440 for (0..union_obj.field_types.len) |field_index| {
3145031441 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
31451 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
31442 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
3145231443 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3145331444 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
3145431445 field_name.fmt(ip),
......@@ -31536,7 +31527,7 @@ fn coerceArrayLike(
3153631527 var runtime_src: ?LazySrcLoc = null;
3153731528
3153831529 for (element_vals, element_refs, 0..) |*val, *ref, i| {
31539 const index_ref = Air.internedToRef((try pt.intValue(Type.usize, i)).toIntern());
31530 const index_ref = Air.internedToRef((try pt.intValue(.usize, i)).toIntern());
3154031531 const src = inst_src; // TODO better source location
3154131532 const elem_src = inst_src; // TODO better source location
3154231533 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);
......@@ -31668,7 +31659,7 @@ fn coerceTupleToArrayPtrs(
3166831659 const zcu = pt.zcu;
3166931660 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
3167031661 const ptr_info = ptr_array_ty.ptrInfo(zcu);
31671 const array_ty = Type.fromInterned(ptr_info.child);
31662 const array_ty: Type = .fromInterned(ptr_info.child);
3167231663 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
3167331664 if (ptr_info.flags.alignment != .none) {
3167431665 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});
......@@ -31721,14 +31712,14 @@ fn coerceTupleToTuple(
3172131712 const field_index: u32 = @intCast(field_index_usize);
3172231713
3172331714 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);
31724 const coerced = try sema.coerce(block, Type.fromInterned(field_ty), elem_ref, field_src);
31715 const coerced = try sema.coerce(block, .fromInterned(field_ty), elem_ref, field_src);
3172531716 field_refs[field_index] = coerced;
3172631717 if (default_val != .none) {
3172731718 const init_val = (try sema.resolveValue(coerced)) orelse {
3172831719 return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field });
3172931720 };
3173031721
31731 if (!init_val.eql(Value.fromInterned(default_val), Type.fromInterned(field_ty), pt.zcu)) {
31722 if (!init_val.eql(Value.fromInterned(default_val), .fromInterned(field_ty), pt.zcu)) {
3173231723 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
3173331724 }
3173431725 }
......@@ -31885,7 +31876,7 @@ pub fn ensureNavResolved(sema: *Sema, block: *Block, src: LazySrcLoc, nav_index:
3188531876
3188631877fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
3188731878 const pt = sema.pt;
31888 const ptr_anyopaque_ty = try pt.singleConstPtrType(Type.anyopaque);
31879 const ptr_anyopaque_ty = try pt.singleConstPtrType(.anyopaque);
3188931880 return Value.fromInterned(try pt.intern(.{ .opt = .{
3189031881 .ty = (try pt.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),
3189131882 .val = if (opt_val) |val| (try pt.getCoerced(
......@@ -32140,12 +32131,12 @@ fn analyzeSliceLen(
3214032131 const zcu = pt.zcu;
3214132132 if (try sema.resolveValue(slice_inst)) |slice_val| {
3214232133 if (slice_val.isUndef(zcu)) {
32143 return pt.undefRef(Type.usize);
32134 return .undef_usize;
3214432135 }
32145 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));
32136 return pt.intRef(.usize, try slice_val.sliceLen(pt));
3214632137 }
3214732138 try sema.requireRuntimeBlock(block, src, null);
32148 return block.addTyOp(.slice_len, Type.usize, slice_inst);
32139 return block.addTyOp(.slice_len, .usize, slice_inst);
3214932140}
3215032141
3215132142fn analyzeIsNull(
......@@ -32156,7 +32147,7 @@ fn analyzeIsNull(
3215632147) CompileError!Air.Inst.Ref {
3215732148 const pt = sema.pt;
3215832149 const zcu = pt.zcu;
32159 const result_ty = Type.bool;
32150 const result_ty: Type = .bool;
3216032151 if (try sema.resolveValue(operand)) |opt_val| {
3216132152 if (opt_val.isUndef(zcu)) {
3216232153 return pt.undefRef(result_ty);
......@@ -32224,7 +32215,7 @@ fn analyzeIsNonErrComptimeOnly(
3222432215 else => {},
3222532216 }
3222632217 } else if (operand == .undef) {
32227 return pt.undefRef(Type.bool);
32218 return .undef_bool;
3222832219 } else if (@intFromEnum(operand) < InternPool.static_len) {
3222932220 // None of the ref tags can be errors.
3223032221 return .bool_true;
......@@ -32308,14 +32299,7 @@ fn analyzeIsNonErrComptimeOnly(
3230832299 }
3230932300
3231032301 if (maybe_operand_val) |err_union| {
32311 if (err_union.isUndef(zcu)) {
32312 return pt.undefRef(Type.bool);
32313 }
32314 if (err_union.getErrorName(zcu) == .none) {
32315 return .bool_true;
32316 } else {
32317 return .bool_false;
32318 }
32302 return if (err_union.isUndef(zcu)) .undef_bool else if (err_union.getErrorName(zcu) == .none) .bool_true else .bool_false;
3231932303 }
3232032304 return .none;
3232132305}
......@@ -32412,8 +32396,8 @@ fn analyzeSlice(
3241232396 );
3241332397
3241432398 const bounds_error_message = "slice of single-item pointer must have bounds [0..0], [0..1], or [1..1]";
32415 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
32416 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
32399 if (try sema.compareScalar(start_value, .neq, end_value, .comptime_int)) {
32400 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, .comptime_int)) {
3241732401 const msg = msg: {
3241832402 const msg = try sema.errMsg(start_src, bounds_error_message, .{});
3241932403 errdefer msg.destroy(sema.gpa);
......@@ -32429,7 +32413,7 @@ fn analyzeSlice(
3242932413 break :msg msg;
3243032414 };
3243132415 return sema.failWithOwnedErrorMsg(block, msg);
32432 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
32416 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, .comptime_int)) {
3243332417 const msg = msg: {
3243432418 const msg = try sema.errMsg(end_src, bounds_error_message, .{});
3243532419 errdefer msg.destroy(sema.gpa);
......@@ -32447,7 +32431,7 @@ fn analyzeSlice(
3244732431 return sema.failWithOwnedErrorMsg(block, msg);
3244832432 }
3244932433 } else {
32450 if (try sema.compareScalar(end_value, .gt, Value.one_comptime_int, Type.comptime_int)) {
32434 if (try sema.compareScalar(end_value, .gt, Value.one_comptime_int, .comptime_int)) {
3245132435 return sema.fail(
3245232436 block,
3245332437 end_src,
......@@ -32512,7 +32496,7 @@ fn analyzeSlice(
3251232496 break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(manyptr_ty_key), ptr_or_slice, ptr_src);
3251332497 } else ptr_or_slice;
3251432498
32515 const start = try sema.coerce(block, Type.usize, uncasted_start, start_src);
32499 const start = try sema.coerce(block, .usize, uncasted_start, start_src);
3251632500 const new_ptr = try sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);
3251732501 const new_ptr_ty = sema.typeOf(new_ptr);
3251832502
......@@ -32523,20 +32507,20 @@ fn analyzeSlice(
3252332507 var end_is_len = uncasted_end_opt == .none;
3252432508 const end = e: {
3252532509 if (array_ty.zigTypeTag(zcu) == .array) {
32526 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(zcu));
32510 const len_val = try pt.intValue(.usize, array_ty.arrayLen(zcu));
3252732511
3252832512 if (!end_is_len) {
3252932513 const end = if (by_length) end: {
32530 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32514 const len = try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3253132515 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
32532 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
32533 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32516 break :end try sema.coerce(block, .usize, uncasted_end, end_src);
32517 } else try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3253432518 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3253532519 const len_s_val = try pt.intValue(
32536 Type.usize,
32520 .usize,
3253732521 array_ty.arrayLenIncludingSentinel(zcu),
3253832522 );
32539 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
32523 if (!(try sema.compareAll(end_val, .lte, len_s_val, .usize))) {
3254032524 const sentinel_label: []const u8 = if (array_ty.sentinel(zcu) != null)
3254132525 " +1 (sentinel)"
3254232526 else
......@@ -32557,7 +32541,7 @@ fn analyzeSlice(
3255732541 // end_is_len is only true if we are NOT using the sentinel
3255832542 // length. For sentinel-length, we don't want the type to
3255932543 // contain the sentinel.
32560 if (end_val.eql(len_val, Type.usize, zcu)) {
32544 if (end_val.eql(len_val, .usize, zcu)) {
3256132545 end_is_len = true;
3256232546 }
3256332547 }
......@@ -32568,10 +32552,10 @@ fn analyzeSlice(
3256832552 } else if (slice_ty.isSlice(zcu)) {
3256932553 if (!end_is_len) {
3257032554 const end = if (by_length) end: {
32571 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32555 const len = try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3257232556 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
32573 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
32574 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32557 break :end try sema.coerce(block, .usize, uncasted_end, end_src);
32558 } else try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3257532559 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3257632560 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
3257732561 if (slice_val.isUndef(zcu)) {
......@@ -32580,8 +32564,8 @@ fn analyzeSlice(
3258032564 const has_sentinel = slice_ty.sentinel(zcu) != null;
3258132565 const slice_len = try slice_val.sliceLen(pt);
3258232566 const len_plus_sent = slice_len + @intFromBool(has_sentinel);
32583 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);
32584 if (!(try sema.compareAll(end_val, .lte, slice_len_val_with_sentinel, Type.usize))) {
32567 const slice_len_val_with_sentinel = try pt.intValue(.usize, len_plus_sent);
32568 if (!(try sema.compareAll(end_val, .lte, slice_len_val_with_sentinel, .usize))) {
3258532569 const sentinel_label: []const u8 = if (has_sentinel)
3258632570 " +1 (sentinel)"
3258732571 else
......@@ -32602,8 +32586,8 @@ fn analyzeSlice(
3260232586 // If the slice has a sentinel, we consider end_is_len
3260332587 // is only true if it equals the length WITHOUT the
3260432588 // sentinel, so we don't add a sentinel type.
32605 const slice_len_val = try pt.intValue(Type.usize, slice_len);
32606 if (end_val.eql(slice_len_val, Type.usize, zcu)) {
32589 const slice_len_val = try pt.intValue(.usize, slice_len);
32590 if (end_val.eql(slice_len_val, .usize, zcu)) {
3260732591 end_is_len = true;
3260832592 }
3260932593 }
......@@ -32614,10 +32598,10 @@ fn analyzeSlice(
3261432598 }
3261532599 if (!end_is_len) {
3261632600 if (by_length) {
32617 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32601 const len = try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3261832602 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
32619 break :e try sema.coerce(block, Type.usize, uncasted_end, end_src);
32620 } else break :e try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32603 break :e try sema.coerce(block, .usize, uncasted_end, end_src);
32604 } else break :e try sema.coerce(block, .usize, uncasted_end_opt, end_src);
3262132605 }
3262232606 return sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);
3262332607 };
......@@ -32645,7 +32629,7 @@ fn analyzeSlice(
3264532629 // requirement: start <= end
3264632630 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3264732631 if (try sema.resolveDefinedValue(block, start_src, start)) |start_val| {
32648 if (!by_length and !(try sema.compareAll(start_val, .lte, end_val, Type.usize))) {
32632 if (!by_length and !(try sema.compareAll(start_val, .lte, end_val, .usize))) {
3264932633 return sema.fail(
3265032634 block,
3265132635 start_src,
......@@ -32715,7 +32699,7 @@ fn analyzeSlice(
3271532699 try sema.addSafetyCheckCall(block, src, ok, .@"panic.startGreaterThanEnd", &.{ start, end });
3271632700 }
3271732701 const new_len = if (by_length)
32718 try sema.coerce(block, Type.usize, uncasted_end_opt, end_src)
32702 try sema.coerce(block, .usize, uncasted_end_opt, end_src)
3271932703 else
3272032704 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
3272132705 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
......@@ -32753,9 +32737,9 @@ fn analyzeSlice(
3275332737
3275432738 bounds_check: {
3275532739 const actual_len = if (array_ty.zigTypeTag(zcu) == .array)
32756 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
32740 try pt.intRef(.usize, array_ty.arrayLenIncludingSentinel(zcu))
3275732741 else if (slice_ty.isSlice(zcu)) l: {
32758 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
32742 const slice_len_inst = try block.addTyOp(.slice_len, .usize, ptr_or_slice);
3275932743 break :l if (slice_ty.sentinel(zcu) == null)
3276032744 slice_len_inst
3276132745 else
......@@ -32811,15 +32795,15 @@ fn analyzeSlice(
3281132795
3281232796 // requirement: end <= len
3281332797 const opt_len_inst = if (array_ty.zigTypeTag(zcu) == .array)
32814 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
32798 try pt.intRef(.usize, array_ty.arrayLenIncludingSentinel(zcu))
3281532799 else if (slice_ty.isSlice(zcu)) blk: {
3281632800 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
3281732801 // we don't need to add one for sentinels because the
3281832802 // underlying value data includes the sentinel
32819 break :blk try pt.intRef(Type.usize, try slice_val.sliceLen(pt));
32803 break :blk try pt.intRef(.usize, try slice_val.sliceLen(pt));
3282032804 }
3282132805
32822 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
32806 const slice_len_inst = try block.addTyOp(.slice_len, .usize, ptr_or_slice);
3282332807 if (slice_ty.sentinel(zcu) == null) break :blk slice_len_inst;
3282432808
3282532809 // we have to add one because slice lengths don't include the sentinel
......@@ -32935,8 +32919,8 @@ fn cmpNumeric(
3293532919 }
3293632920
3293732921 // Any other comparison depends on both values, so the result is undef if either is undef.
32938 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);
32939 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);
32922 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
32923 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
3294032924
3294132925 const runtime_src: LazySrcLoc = if (maybe_lhs_val) |lhs_val| rs: {
3294232926 if (maybe_rhs_val) |rhs_val| {
......@@ -33646,7 +33630,7 @@ fn resolvePeerTypes(
3364633630 candidate_srcs: PeerTypeCandidateSrc,
3364733631) !Type {
3364833632 switch (instructions.len) {
33649 0 => return Type.noreturn,
33633 0 => return .noreturn,
3365033634 1 => return sema.typeOf(instructions[0]),
3365133635 else => {},
3365233636 }
......@@ -33780,12 +33764,12 @@ fn resolvePeerTypesInner(
3378033764 .nullable => {
3378133765 for (peer_tys, 0..) |opt_ty, i| {
3378233766 const ty = opt_ty orelse continue;
33783 if (!ty.eql(Type.null, zcu)) return .{ .conflict = .{
33767 if (!ty.eql(.null, zcu)) return .{ .conflict = .{
3378433768 .peer_idx_a = strat_reason,
3378533769 .peer_idx_b = i,
3378633770 } };
3378733771 }
33788 return .{ .success = Type.null };
33772 return .{ .success = .null };
3378933773 },
3379033774
3379133775 .optional => {
......@@ -34006,7 +33990,7 @@ fn resolvePeerTypesInner(
3400633990 };
3400733991
3400833992 // Try peer -> cur, then cur -> peer
34009 ptr_info.child = ((try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) orelse {
33993 ptr_info.child = ((try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), .fromInterned(peer_info.child))) orelse {
3401033994 return .{ .conflict = .{
3401133995 .peer_idx_a = first_idx,
3401233996 .peer_idx_b = i,
......@@ -34153,8 +34137,8 @@ fn resolvePeerTypesInner(
3415334137 };
3415434138
3415534139 // We abstract array handling slightly so that tuple pointers can work like array pointers
34156 const peer_pointee_array = sema.typeIsArrayLike(Type.fromInterned(peer_info.child));
34157 const cur_pointee_array = sema.typeIsArrayLike(Type.fromInterned(ptr_info.child));
34140 const peer_pointee_array = sema.typeIsArrayLike(.fromInterned(peer_info.child));
34141 const cur_pointee_array = sema.typeIsArrayLike(.fromInterned(ptr_info.child));
3415834142
3415934143 // This switch is just responsible for deciding the size and pointee (not including
3416034144 // single-pointer array sentinel).
......@@ -34162,7 +34146,7 @@ fn resolvePeerTypesInner(
3416234146 switch (peer_info.flags.size) {
3416334147 .one => switch (ptr_info.flags.size) {
3416434148 .one => {
34165 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
34149 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), .fromInterned(peer_info.child))) |pointee| {
3416634150 ptr_info.child = pointee.toIntern();
3416734151 break :good;
3416834152 }
......@@ -34204,7 +34188,7 @@ fn resolvePeerTypesInner(
3420434188 .many => {
3420534189 // Only works for *[n]T + [*]T -> [*]T
3420634190 const arr = peer_pointee_array orelse return generic_err;
34207 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
34191 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
3420834192 ptr_info.child = pointee.toIntern();
3420934193 break :good;
3421034194 }
......@@ -34217,7 +34201,7 @@ fn resolvePeerTypesInner(
3421734201 .slice => {
3421834202 // Only works for *[n]T + []T -> []T
3421934203 const arr = peer_pointee_array orelse return generic_err;
34220 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
34204 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
3422134205 ptr_info.child = pointee.toIntern();
3422234206 break :good;
3422334207 }
......@@ -34233,7 +34217,7 @@ fn resolvePeerTypesInner(
3423334217 .one => {
3423434218 // Only works for [*]T + *[n]T -> [*]T
3423534219 const arr = cur_pointee_array orelse return generic_err;
34236 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| {
34220 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, .fromInterned(peer_info.child))) |pointee| {
3423734221 ptr_info.flags.size = .many;
3423834222 ptr_info.child = pointee.toIntern();
3423934223 break :good;
......@@ -34247,7 +34231,7 @@ fn resolvePeerTypesInner(
3424734231 return generic_err;
3424834232 },
3424934233 .many => {
34250 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
34234 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), .fromInterned(peer_info.child))) |pointee| {
3425134235 ptr_info.child = pointee.toIntern();
3425234236 break :good;
3425334237 }
......@@ -34262,7 +34246,7 @@ fn resolvePeerTypesInner(
3426234246 } };
3426334247 }
3426434248 // Okay, then works for [*]T + "[]T" -> [*]T
34265 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
34249 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), .fromInterned(peer_info.child))) |pointee| {
3426634250 ptr_info.flags.size = .many;
3426734251 ptr_info.child = pointee.toIntern();
3426834252 break :good;
......@@ -34275,7 +34259,7 @@ fn resolvePeerTypesInner(
3427534259 .one => {
3427634260 // Only works for []T + *[n]T -> []T
3427734261 const arr = cur_pointee_array orelse return generic_err;
34278 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| {
34262 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, .fromInterned(peer_info.child))) |pointee| {
3427934263 ptr_info.flags.size = .slice;
3428034264 ptr_info.child = pointee.toIntern();
3428134265 break :good;
......@@ -34293,7 +34277,7 @@ fn resolvePeerTypesInner(
3429334277 return generic_err;
3429434278 },
3429534279 .slice => {
34296 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
34280 if (try sema.resolvePairInMemoryCoercible(block, src, .fromInterned(ptr_info.child), .fromInterned(peer_info.child))) |pointee| {
3429734281 ptr_info.child = pointee.toIntern();
3429834282 break :good;
3429934283 }
......@@ -34479,7 +34463,7 @@ fn resolvePeerTypesInner(
3447934463 } },
3448034464 }
3448134465 }
34482 return .{ .success = Type.comptime_int };
34466 return .{ .success = .comptime_int };
3448334467 },
3448434468
3448534469 .comptime_float => {
......@@ -34493,7 +34477,7 @@ fn resolvePeerTypesInner(
3449334477 } },
3449434478 }
3449534479 }
34496 return .{ .success = Type.comptime_float };
34480 return .{ .success = .comptime_float };
3449734481 },
3449834482
3449934483 .fixed_int => {
......@@ -34601,11 +34585,11 @@ fn resolvePeerTypesInner(
3460134585 // Recreate the type so we eliminate any c_longdouble
3460234586 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
3460334587 opt_cur_ty = switch (bits) {
34604 16 => Type.f16,
34605 32 => Type.f32,
34606 64 => Type.f64,
34607 80 => Type.f80,
34608 128 => Type.f128,
34588 16 => .f16,
34589 32 => .f32,
34590 64 => .f64,
34591 80 => .f80,
34592 128 => .f128,
3460934593 else => unreachable,
3461034594 };
3461134595 } else {
......@@ -34716,7 +34700,7 @@ fn resolvePeerTypesInner(
3471634700 break;
3471734701 };
3471834702 const uncoerced_field = Air.internedToRef(uncoerced_field_val.toIntern());
34719 const coerced_inst = sema.coerceExtra(block, Type.fromInterned(field_ty.*), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) {
34703 const coerced_inst = sema.coerceExtra(block, .fromInterned(field_ty.*), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) {
3472034704 // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway
3472134705 error.NotCoercible => {
3472234706 comptime_val = null;
......@@ -34729,7 +34713,7 @@ fn resolvePeerTypesInner(
3472934713 comptime_val = coerced_val;
3473034714 continue;
3473134715 };
34732 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), zcu)) {
34716 if (!coerced_val.eql(existing, .fromInterned(field_ty.*), zcu)) {
3473334717 comptime_val = null;
3473434718 break;
3473534719 }
......@@ -34743,7 +34727,7 @@ fn resolvePeerTypesInner(
3474334727 .values = field_vals,
3474434728 });
3474534729
34746 return .{ .success = Type.fromInterned(final_ty) };
34730 return .{ .success = .fromInterned(final_ty) };
3474734731 },
3474834732
3474934733 .exact => {
......@@ -34813,7 +34797,7 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3481334797 const field_count = ty.structFieldCount(zcu);
3481434798 if (field_count == 0) return .{
3481534799 .len = 0,
34816 .elem_ty = Type.noreturn,
34800 .elem_ty = .noreturn,
3481734801 };
3481834802 if (!ty.isTuple(zcu)) return null;
3481934803 const elem_ty = ty.fieldType(0, zcu);
......@@ -34902,7 +34886,7 @@ pub fn resolveStructAlignment(
3490234886 var alignment: Alignment = .@"1";
3490334887
3490434888 for (0..struct_type.field_types.len) |i| {
34905 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
34889 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3490634890 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt))
3490734891 continue;
3490834892 const field_align = try field_ty.structFieldAlignmentSema(
......@@ -34953,7 +34937,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3495334937 var big_align: Alignment = .@"1";
3495434938
3495534939 for (aligns, sizes, 0..) |*field_align, *field_size, i| {
34956 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
34940 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3495734941 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3495834942 struct_type.offsets.get(ip)[i] = 0;
3495934943 field_size.* = 0;
......@@ -35001,7 +34985,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3500134985 const runtime_order = struct_type.runtime_order.get(ip);
3500234986
3500334987 for (runtime_order, 0..) |*ro, i| {
35004 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
34988 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3500534989 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3500634990 ro.* = .omitted;
3500734991 } else {
......@@ -35095,7 +35079,7 @@ fn backingIntType(
3509535079 const fields_bit_sum = blk: {
3509635080 var accumulator: u64 = 0;
3509735081 for (0..struct_type.field_types.len) |i| {
35098 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35082 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3509935083 accumulator += try field_ty.bitSizeSema(pt);
3510035084 }
3510135085 break :blk accumulator;
......@@ -35234,7 +35218,7 @@ pub fn resolveUnionAlignment(
3523435218
3523535219 var max_align: Alignment = .@"1";
3523635220 for (0..union_type.field_types.len) |field_index| {
35237 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
35221 const field_ty: Type = .fromInterned(union_type.field_types.get(ip)[field_index]);
3523835222 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3523935223
3524035224 const explicit_align = union_type.fieldAlign(ip, field_index);
......@@ -35282,7 +35266,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3528235266 var max_size: u64 = 0;
3528335267 var max_align: Alignment = .@"1";
3528435268 for (0..union_type.field_types.len) |field_index| {
35285 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
35269 const field_ty: Type = .fromInterned(union_type.field_types.get(ip)[field_index]);
3528635270
3528735271 if (try field_ty.comptimeOnlySema(pt) or field_ty.zigTypeTag(pt.zcu) == .noreturn) continue; // TODO: should this affect alignment?
3528835272
......@@ -35307,7 +35291,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3530735291 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
3530835292 try Type.fromInterned(union_type.enum_tag_ty).hasRuntimeBitsSema(pt);
3530935293 const size, const alignment, const padding = if (has_runtime_tag) layout: {
35310 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
35294 const enum_tag_type: Type = .fromInterned(union_type.enum_tag_ty);
3531135295 const tag_align = try enum_tag_type.abiAlignmentSema(pt);
3531235296 const tag_size = try enum_tag_type.abiSizeSema(pt);
3531335297
......@@ -35392,7 +35376,7 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
3539235376 // See also similar code for unions.
3539335377
3539435378 for (0..struct_type.field_types.len) |i| {
35395 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35379 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3539635380 try field_ty.resolveFully(pt);
3539735381 }
3539835382}
......@@ -35421,7 +35405,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3542135405
3542235406 union_obj.setStatus(ip, .fully_resolved_wip);
3542335407 for (0..union_obj.field_types.len) |field_index| {
35424 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
35408 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
3542535409 try field_ty.resolveFully(pt);
3542635410 }
3542735411 union_obj.setStatus(ip, .fully_resolved);
......@@ -35553,7 +35537,7 @@ fn resolveInferredErrorSet(
3555335537 // set. However, in the case of comptime/inline function calls with
3555435538 // inferred error sets, each call gets an adhoc InferredErrorSet object, which
3555535539 // has no corresponding function body.
35556 const ies_func_info = zcu.typeToFunc(Type.fromInterned(func.ty)).?;
35540 const ies_func_info = zcu.typeToFunc(.fromInterned(func.ty)).?;
3555735541 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,
3555835542 // because inline function does not create a new declaration, and the ies has been filled with analyzeCall,
3555935543 // so here we can simply skip this case.
......@@ -36008,7 +35992,7 @@ fn structFieldInits(
3600835992 // In init bodies, the zir index of the struct itself is used
3600935993 // to refer to the current field type.
3601035994
36011 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_i]);
35995 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_i]);
3601235996 const type_ref = Air.internedToRef(field_ty.toIntern());
3601335997 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
3601435998 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
......@@ -36135,7 +36119,7 @@ fn unionFields(
3613536119 }
3613636120
3613736121 if (fields_len > 0) {
36138 const field_count_val = try pt.intValue(Type.comptime_int, fields_len - 1);
36122 const field_count_val = try pt.intValue(.comptime_int, fields_len - 1);
3613936123 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
3614036124 const msg = msg: {
3614136125 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
......@@ -36288,9 +36272,9 @@ fn unionFields(
3628836272 }
3628936273
3629036274 const field_ty: Type = if (!has_type)
36291 Type.void
36275 .void
3629236276 else if (field_type_ref == .none)
36293 Type.noreturn
36277 .noreturn
3629436278 else
3629536279 try sema.resolveType(&block_scope, type_src, field_type_ref);
3629636280
......@@ -36388,11 +36372,11 @@ fn unionFields(
3638836372
3638936373 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
3639036374 if (explicit_tags_seen[field_index]) continue;
36391 try sema.addFieldErrNote(Type.fromInterned(tag_ty), field_index, msg, "field '{}' missing, declared here", .{
36375 try sema.addFieldErrNote(.fromInterned(tag_ty), field_index, msg, "field '{}' missing, declared here", .{
3639236376 field_name.fmt(ip),
3639336377 });
3639436378 }
36395 try sema.addDeclaredHereNote(msg, Type.fromInterned(tag_ty));
36379 try sema.addDeclaredHereNote(msg, .fromInterned(tag_ty));
3639636380 break :msg msg;
3639736381 };
3639836382 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36530,10 +36514,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3653036514 .comptime_int_type,
3653136515 .comptime_float_type,
3653236516 .enum_literal_type,
36517 .ptr_usize_type,
36518 .ptr_const_comptime_int_type,
3653336519 .manyptr_u8_type,
3653436520 .manyptr_const_u8_type,
3653536521 .manyptr_const_u8_sentinel_0_type,
36536 .single_const_pointer_to_comptime_int_type,
3653736522 .slice_const_u8_type,
3653836523 .slice_const_u8_sentinel_0_type,
3653936524 .vector_8_i8_type,
......@@ -36595,11 +36580,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3659536580 .empty_tuple_type => Value.empty_tuple,
3659636581 // values, not types
3659736582 .undef,
36583 .undef_bool,
36584 .undef_usize,
36585 .undef_u1,
3659836586 .zero,
3659936587 .zero_usize,
36588 .zero_u1,
3660036589 .zero_u8,
3660136590 .one,
3660236591 .one_usize,
36592 .one_u1,
3660336593 .one_u8,
3660436594 .four_u8,
3660536595 .negative_one,
......@@ -36705,7 +36695,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3670536695 .storage = .{ .elems = &.{} },
3670636696 } }));
3670736697
36708 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
36698 if (try sema.typeHasOnePossibleValue(.fromInterned(seq_type.child))) |opv| {
3670936699 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
3671036700 .ty = ty.toIntern(),
3671136701 .storage = .{ .repeated_elem = opv.toIntern() },
......@@ -36740,7 +36730,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3674036730 field_val.* = struct_type.field_inits.get(ip)[i];
3674136731 continue;
3674236732 }
36743 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
36733 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]);
3674436734 if (try sema.typeHasOnePossibleValue(field_ty)) |field_opv| {
3674536735 field_val.* = field_opv.toIntern();
3674636736 } else return null;
......@@ -36773,13 +36763,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3677336763 try ty.resolveLayout(pt);
3677436764
3677536765 const union_obj = ip.loadUnionType(ty.toIntern());
36776 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
36766 const tag_val = (try sema.typeHasOnePossibleValue(.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
3677736767 return null;
3677836768 if (union_obj.field_types.len == 0) {
3677936769 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });
3678036770 return Value.fromInterned(only);
3678136771 }
36782 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
36772 const only_field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[0]);
3678336773 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
3678436774 return null;
3678536775 const only = try pt.internUnion(.{
......@@ -36796,7 +36786,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3679636786 .nonexhaustive => {
3679736787 if (enum_type.tag_ty == .comptime_int_type) return null;
3679836788
36799 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {
36789 if (try sema.typeHasOnePossibleValue(.fromInterned(enum_type.tag_ty))) |int_opv| {
3680036790 const only = try pt.intern(.{ .enum_tag = .{
3680136791 .ty = ty.toIntern(),
3680236792 .int = int_opv.toIntern(),
......@@ -36814,7 +36804,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3681436804 1 => try pt.intern(.{ .enum_tag = .{
3681536805 .ty = ty.toIntern(),
3681636806 .int = if (enum_type.values.len == 0)
36817 (try pt.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
36807 (try pt.intValue(.fromInterned(enum_type.tag_ty), 0)).toIntern()
3681836808 else
3681936809 try ip.getCoercedInts(
3682036810 zcu.gpa,
......@@ -37041,7 +37031,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3704137031 if (ptr_type.flags.is_allowzero) return null;
3704237032
3704337033 // optionals of zero sized types behave like bools, not pointers
37044 const payload_ty = Type.fromInterned(opt_child);
37034 const payload_ty: Type = .fromInterned(opt_child);
3704537035 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
3704637036 return null;
3704737037 }
......@@ -37175,7 +37165,7 @@ fn intFromFloatScalar(
3717537165 var big_int = try float128IntPartToBigInt(sema.arena, float);
3717637166 defer big_int.deinit();
3717737167
37178 const cti_result = try pt.intValue_big(Type.comptime_int, big_int.toConst());
37168 const cti_result = try pt.intValue_big(.comptime_int, big_int.toConst());
3717937169
3718037170 if (!(try sema.intFitsInType(cti_result, int_ty, null))) {
3718137171 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{
......@@ -37278,8 +37268,8 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3727837268 assert(enum_type.tag_mode != .nonexhaustive);
3727937269 // The `tagValueIndex` function call below relies on the type being the integer tag type.
3728037270 // `getCoerced` assumes the value will fit the new type.
37281 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
37282 const int_coerced = try pt.getCoerced(int, Type.fromInterned(enum_type.tag_ty));
37271 if (!(try sema.intFitsInType(int, .fromInterned(enum_type.tag_ty), null))) return false;
37272 const int_coerced = try pt.getCoerced(int, .fromInterned(enum_type.tag_ty));
3728337273
3728437274 return enum_type.tagValueIndex(&zcu.intern_pool, int_coerced.toIntern()) != null;
3728537275}
......@@ -37359,7 +37349,7 @@ fn compareVector(
3735937349 const lhs_elem = try lhs.elemValue(pt, i);
3736037350 const rhs_elem = try rhs.elemValue(pt, i);
3736137351 if (lhs_elem.isUndef(zcu) or rhs_elem.isUndef(zcu)) {
37362 scalar.* = try pt.intern(.{ .undef = .bool_type });
37352 scalar.* = .undef_bool;
3736337353 } else {
3736437354 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu));
3736537355 scalar.* = Value.makeBool(res_bool).toIntern();
......@@ -37826,7 +37816,7 @@ pub fn resolveDeclaredEnum(
3782637816 .owner = .wrap(.{ .type = wip_ty.index }),
3782737817 .func_index = .none,
3782837818 .func_is_naked = false,
37829 .fn_ret_ty = Type.void,
37819 .fn_ret_ty = .void,
3783037820 .fn_ret_ty_ies = null,
3783137821 .comptime_err_ret_trace = &comptime_err_ret_trace,
3783237822 };
......@@ -37999,7 +37989,7 @@ fn resolveDeclaredEnumInner(
3799937989 break :overflow false;
3800037990 } else overflow: {
3800137991 assert(wip_ty.nextField(ip, field_name, .none) == null);
38002 last_tag_val = try pt.intValue(Type.comptime_int, field_i);
37992 last_tag_val = try pt.intValue(.comptime_int, field_i);
3800337993 if (!try sema.intFitsInType(last_tag_val.?, int_tag_ty, null)) break :overflow true;
3800437994 last_tag_val = try pt.getCoerced(last_tag_val.?, int_tag_ty);
3800537995 break :overflow false;
src/Sema/arith.zig+6-6
......@@ -168,7 +168,7 @@ fn addWithOverflowScalar(
168168 else => unreachable,
169169 }
170170 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
171 .overflow_bit = try pt.undefValue(.u1),
171 .overflow_bit = .undef_u1,
172172 .wrapped_result = try pt.undefValue(ty),
173173 };
174174 return intAddWithOverflow(sema, lhs, rhs, ty);
......@@ -229,7 +229,7 @@ fn subWithOverflowScalar(
229229 else => unreachable,
230230 }
231231 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
232 .overflow_bit = try pt.undefValue(.u1),
232 .overflow_bit = .undef_u1,
233233 .wrapped_result = try pt.undefValue(ty),
234234 };
235235 return intSubWithOverflow(sema, lhs, rhs, ty);
......@@ -290,7 +290,7 @@ fn mulWithOverflowScalar(
290290 else => unreachable,
291291 }
292292 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
293 .overflow_bit = try pt.undefValue(.u1),
293 .overflow_bit = .undef_u1,
294294 .wrapped_result = try pt.undefValue(ty),
295295 };
296296 return intMulWithOverflow(sema, lhs, rhs, ty);
......@@ -1043,7 +1043,7 @@ fn comptimeIntAdd(sema: *Sema, lhs: Value, rhs: Value) !Value {
10431043fn intAddWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
10441044 switch (ty.toIntern()) {
10451045 .comptime_int_type => return .{
1046 .overflow_bit = try sema.pt.intValue(.u1, 0),
1046 .overflow_bit = .zero_u1,
10471047 .wrapped_result = try comptimeIntAdd(sema, lhs, rhs),
10481048 },
10491049 else => return intAddWithOverflowInner(sema, lhs, rhs, ty),
......@@ -1125,7 +1125,7 @@ fn comptimeIntSub(sema: *Sema, lhs: Value, rhs: Value) !Value {
11251125fn intSubWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
11261126 switch (ty.toIntern()) {
11271127 .comptime_int_type => return .{
1128 .overflow_bit = try sema.pt.intValue(.u1, 0),
1128 .overflow_bit = .zero_u1,
11291129 .wrapped_result = try comptimeIntSub(sema, lhs, rhs),
11301130 },
11311131 else => return intSubWithOverflowInner(sema, lhs, rhs, ty),
......@@ -1211,7 +1211,7 @@ fn comptimeIntMul(sema: *Sema, lhs: Value, rhs: Value) !Value {
12111211fn intMulWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
12121212 switch (ty.toIntern()) {
12131213 .comptime_int_type => return .{
1214 .overflow_bit = try sema.pt.intValue(.u1, 0),
1214 .overflow_bit = .zero_u1,
12151215 .wrapped_result = try comptimeIntMul(sema, lhs, rhs),
12161216 },
12171217 else => return intMulWithOverflowInner(sema, lhs, rhs, ty),
src/Type.zig+7-6
......@@ -2641,10 +2641,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
26412641 if (enum_type.values.len == 0) {
26422642 const only = try pt.intern(.{ .enum_tag = .{
26432643 .ty = ty.toIntern(),
2644 .int = try pt.intern(.{ .int = .{
2645 .ty = enum_type.tag_ty,
2646 .storage = .{ .u64 = 0 },
2647 } }),
2644 .int = (try pt.intValue(.fromInterned(enum_type.tag_ty), 0)).toIntern(),
26482645 } });
26492646 return Value.fromInterned(only);
26502647 } else {
......@@ -3676,10 +3673,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
36763673 .null_type,
36773674 .undefined_type,
36783675 .enum_literal_type,
3676 .ptr_usize_type,
3677 .ptr_const_comptime_int_type,
36793678 .manyptr_u8_type,
36803679 .manyptr_const_u8_type,
36813680 .manyptr_const_u8_sentinel_0_type,
3682 .single_const_pointer_to_comptime_int_type,
36833681 .slice_const_u8_type,
36843682 .slice_const_u8_sentinel_0_type,
36853683 .optional_noreturn_type,
......@@ -3691,9 +3689,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
36913689 .undef => unreachable,
36923690 .zero => unreachable,
36933691 .zero_usize => unreachable,
3692 .zero_u1 => unreachable,
36943693 .zero_u8 => unreachable,
36953694 .one => unreachable,
36963695 .one_usize => unreachable,
3696 .one_u1 => unreachable,
36973697 .one_u8 => unreachable,
36983698 .four_u8 => unreachable,
36993699 .negative_one => unreachable,
......@@ -4100,10 +4100,11 @@ pub const @"c_longlong": Type = .{ .ip_index = .c_longlong_type };
41004100pub const @"c_ulonglong": Type = .{ .ip_index = .c_ulonglong_type };
41014101pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type };
41024102
4103pub const ptr_usize: Type = .{ .ip_index = .ptr_usize_type };
4104pub const ptr_const_comptime_int: Type = .{ .ip_index = .ptr_const_comptime_int_type };
41034105pub const manyptr_u8: Type = .{ .ip_index = .manyptr_u8_type };
41044106pub const manyptr_const_u8: Type = .{ .ip_index = .manyptr_const_u8_type };
41054107pub const manyptr_const_u8_sentinel_0: Type = .{ .ip_index = .manyptr_const_u8_sentinel_0_type };
4106pub const single_const_pointer_to_comptime_int: Type = .{ .ip_index = .single_const_pointer_to_comptime_int_type };
41074108pub const slice_const_u8: Type = .{ .ip_index = .slice_const_u8_type };
41084109pub const slice_const_u8_sentinel_0: Type = .{ .ip_index = .slice_const_u8_sentinel_0_type };
41094110
src/Value.zig+12-6
......@@ -2895,19 +2895,25 @@ pub fn intValueBounds(val: Value, pt: Zcu.PerThread) !?[2]Value {
28952895
28962896pub const BigIntSpace = InternPool.Key.Int.Storage.BigIntSpace;
28972897
2898pub const undef: Value = .{ .ip_index = .undef };
2899pub const undef_bool: Value = .{ .ip_index = .undef_bool };
2900pub const undef_usize: Value = .{ .ip_index = .undef_usize };
2901pub const undef_u1: Value = .{ .ip_index = .undef_u1 };
2902pub const zero_comptime_int: Value = .{ .ip_index = .zero };
28982903pub const zero_usize: Value = .{ .ip_index = .zero_usize };
2904pub const zero_u1: Value = .{ .ip_index = .zero_u1 };
28992905pub const zero_u8: Value = .{ .ip_index = .zero_u8 };
2900pub const zero_comptime_int: Value = .{ .ip_index = .zero };
29012906pub const one_comptime_int: Value = .{ .ip_index = .one };
2907pub const one_usize: Value = .{ .ip_index = .one_usize };
2908pub const one_u1: Value = .{ .ip_index = .one_u1 };
2909pub const one_u8: Value = .{ .ip_index = .one_u8 };
2910pub const four_u8: Value = .{ .ip_index = .four_u8 };
29022911pub const negative_one_comptime_int: Value = .{ .ip_index = .negative_one };
2903pub const undef: Value = .{ .ip_index = .undef };
29042912pub const @"void": Value = .{ .ip_index = .void_value };
2913pub const @"unreachable": Value = .{ .ip_index = .unreachable_value };
29052914pub const @"null": Value = .{ .ip_index = .null_value };
2906pub const @"false": Value = .{ .ip_index = .bool_false };
29072915pub const @"true": Value = .{ .ip_index = .bool_true };
2908pub const @"unreachable": Value = .{ .ip_index = .unreachable_value };
2909
2910pub const generic_poison_type: Value = .{ .ip_index = .generic_poison_type };
2916pub const @"false": Value = .{ .ip_index = .bool_false };
29112917pub const empty_tuple: Value = .{ .ip_index = .empty_tuple };
29122918
29132919pub fn makeBool(x: bool) Value {
src/Zcu/PerThread.zig+2-3
......@@ -1741,8 +1741,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A
17411741 return;
17421742 }
17431743
1744 const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);
1745 try air.legalize(backend, pt);
1744 try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index));
17461745
17471746 var liveness = try Air.Liveness.analyze(gpa, air.*, ip);
17481747 defer liveness.deinit(gpa);
......@@ -3022,7 +3021,7 @@ fn analyzeFnBodyInner(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaE
30223021 // is unused so it just has to be a no-op.
30233022 sema.air_instructions.set(@intFromEnum(ptr_inst), .{
30243023 .tag = .alloc,
3025 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },
3024 .data = .{ .ty = .ptr_const_comptime_int },
30263025 });
30273026 }
30283027
src/arch/x86_64/CodeGen.zig+89-44
......@@ -32,15 +32,65 @@ const FrameIndex = bits.FrameIndex;
3232
3333const InnerError = codegen.CodeGenError || error{OutOfRegisters};
3434
35pub const legalize_features: Air.Legalize.Features = .init(.{
36 .scalarize_ctz = true,
37 .scalarize_popcount = true,
38 .scalarize_byte_swap = true,
39 .scalarize_bit_reverse = true,
40
41 .remove_shift_vector_rhs_splat = false,
42 .reduce_one_elem_to_bitcast = true,
43});
35pub inline fn legalizeFeatures(target: *const std.Target) *const Air.Legalize.Features {
36 @setEvalBranchQuota(1_200);
37 return switch (target.ofmt == .coff) {
38 inline false, true => |use_old| comptime &.init(.{
39 .scalarize_add = use_old,
40 .scalarize_add_sat = use_old,
41 .scalarize_sub = use_old,
42 .scalarize_sub_sat = use_old,
43 .scalarize_mul = use_old,
44 .scalarize_mul_wrap = use_old,
45 .scalarize_mul_sat = true,
46 .scalarize_div_float = use_old,
47 .scalarize_div_float_optimized = use_old,
48 .scalarize_div_trunc = use_old,
49 .scalarize_div_trunc_optimized = use_old,
50 .scalarize_div_floor = use_old,
51 .scalarize_div_floor_optimized = use_old,
52 .scalarize_div_exact = use_old,
53 .scalarize_div_exact_optimized = use_old,
54 .scalarize_max = use_old,
55 .scalarize_min = use_old,
56 .scalarize_shr = true,
57 .scalarize_shr_exact = true,
58 .scalarize_shl = true,
59 .scalarize_shl_exact = true,
60 .scalarize_shl_sat = true,
61 .scalarize_not = use_old,
62 .scalarize_clz = use_old,
63 .scalarize_ctz = true,
64 .scalarize_popcount = true,
65 .scalarize_byte_swap = true,
66 .scalarize_bit_reverse = true,
67 .scalarize_sin = use_old,
68 .scalarize_cos = use_old,
69 .scalarize_tan = use_old,
70 .scalarize_exp = use_old,
71 .scalarize_exp2 = use_old,
72 .scalarize_log = use_old,
73 .scalarize_log2 = use_old,
74 .scalarize_log10 = use_old,
75 .scalarize_abs = use_old,
76 .scalarize_floor = use_old,
77 .scalarize_ceil = use_old,
78 .scalarize_trunc_float = use_old,
79 .scalarize_cmp_vector = true,
80 .scalarize_cmp_vector_optimized = true,
81 .scalarize_fptrunc = use_old,
82 .scalarize_fpext = use_old,
83 .scalarize_intcast = use_old,
84 .scalarize_int_from_float = use_old,
85 .scalarize_int_from_float_optimized = use_old,
86 .scalarize_float_from_int = use_old,
87 .scalarize_mul_add = use_old,
88
89 .remove_shift_vector_rhs_splat = false,
90 .reduce_one_elem_to_bitcast = true,
91 }),
92 };
93}
4494
4595/// Set this to `false` to uncover Sema OPV bugs.
4696/// https://github.com/ziglang/zig/issues/22419
......@@ -5719,7 +5769,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
57195769 },
57205770 .extra_temps = .{
57215771 .{ .type = .i64, .kind = .{ .rc = .general_purpose } },
5722 .{ .type = .i64, .kind = .{ .mut_rc = .{ .ref = .src1, .rc = .general_purpose } } },
5772 .{ .type = .i64, .kind = .{ .rc = .general_purpose } },
57235773 .unused,
57245774 .unused,
57255775 .unused,
......@@ -92473,7 +92523,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9247392523 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
9247492524 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
9247592525 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92476 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },
92526 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
9247792527 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
9247892528 .{ ._, ._r, .sa, .tmp0q, .ui(63), ._, ._ },
9247992529 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
......@@ -92505,7 +92555,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9250592555 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
9250692556 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
9250792557 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92508 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },
92558 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
9250992559 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
9251092560 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
9251192561 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
......@@ -92539,7 +92589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9253992589 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
9254092590 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
9254192591 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92542 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -8), ._, ._ },
92592 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -8), ._, ._ },
9254392593 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
9254492594 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
9254592595 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
......@@ -92600,7 +92650,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9260092650 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
9260192651 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
9260292652 .{ ._, ._, .mov, .tmp2d, .sa(.dst0, .add_bit_size_rem_64), ._, ._ },
92603 .{ ._, ._, .bzhi, .tmp2q, .memad(.src0q, .add_size, -16), .tmp2q, ._ },
92653 .{ ._, ._, .bzhi, .tmp2q, .memad(.src0q, .add_dst0_size, -16), .tmp2q, ._ },
9260492654 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp2q, ._, ._ },
9260592655 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },
9260692656 } },
......@@ -92632,7 +92682,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9263292682 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
9263392683 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
9263492684 .{ ._, ._, .mov, .tmp2d, .sa(.dst0, .add_bit_size_rem_64), ._, ._ },
92635 .{ ._, ._, .bzhi, .tmp2q, .memad(.src0q, .add_size, -8), .tmp2q, ._ },
92685 .{ ._, ._, .bzhi, .tmp2q, .memad(.src0q, .add_dst0_size, -8), .tmp2q, ._ },
9263692686 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp2q, ._, ._ },
9263792687 } },
9263892688 }, .{
......@@ -92663,7 +92713,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9266392713 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
9266492714 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
9266592715 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },
92666 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },
92716 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
9266792717 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
9266892718 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },
9266992719 } },
......@@ -92695,7 +92745,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9269592745 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
9269692746 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
9269792747 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },
92698 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_size, -8), ._, ._ },
92748 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_dst0_size, -8), ._, ._ },
9269992749 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
9270092750 } },
9270192751 }, .{
......@@ -165537,9 +165587,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {
165537165587 .ty = mask_ty.toIntern(),
165538165588 .storage = .{ .elems = &([1]InternPool.Index{
165539165589 (try rhs_ty.childType(zcu).maxIntScalar(pt, .u8)).toIntern(),
165540 } ++ [1]InternPool.Index{
165541 (try pt.intValue(.u8, 0)).toIntern(),
165542 } ** 15) },
165590 } ++ [1]InternPool.Index{.zero_u8} ** 15) },
165543165591 } })));
165544165592 const mask_addr_reg = try self.copyToTmpRegister(.usize, mask_mcv.address());
165545165593 const mask_addr_lock = self.register_manager.lockRegAssumeUnused(mask_addr_reg);
......@@ -178776,10 +178824,10 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
178776178824 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });
178777178825 var mask_elems_buf: [32]InternPool.Index = undefined;
178778178826 const mask_elems = mask_elems_buf[0..vec_len];
178779 for (mask_elems, 0..) |*elem, bit| elem.* = try pt.intern(.{ .int = .{
178780 .ty = mask_elem_ty.toIntern(),
178781 .storage = .{ .u64 = @as(u64, 1) << @intCast(bit) },
178782 } });
178827 for (mask_elems, 0..) |*elem, bit| elem.* = (try pt.intValue(
178828 mask_elem_ty,
178829 @as(u8, 1) << @truncate(bit),
178830 )).toIntern();
178783178831 const mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{
178784178832 .ty = mask_ty.toIntern(),
178785178833 .storage = .{ .elems = mask_elems },
......@@ -179647,16 +179695,13 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
179647179695 var lhs_mask_elems: [16]InternPool.Index = undefined;
179648179696 for (lhs_mask_elems[0..max_abi_size], 0..) |*lhs_mask_elem, byte_index| {
179649179697 const elem_index = byte_index / elem_abi_size;
179650 lhs_mask_elem.* = try pt.intern(.{ .int = .{
179651 .ty = .u8_type,
179652 .storage = .{ .u64 = if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179653 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179654 if (mask_elem < 0) break :elem 0b1_00_00000;
179655 const mask_elem_index: u31 = @intCast(mask_elem);
179656 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179657 break :elem @intCast(mask_elem_index * elem_abi_size + byte_off);
179658 } },
179659 } });
179698 lhs_mask_elem.* = (try pt.intValue(.u8, if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179699 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179700 if (mask_elem < 0) break :elem 0b1_00_00000;
179701 const mask_elem_index: u31 = @intCast(mask_elem);
179702 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179703 break :elem mask_elem_index * elem_abi_size + byte_off;
179704 })).toIntern();
179660179705 }
179661179706 const lhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });
179662179707 const lhs_mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -179681,16 +179726,13 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
179681179726 var rhs_mask_elems: [16]InternPool.Index = undefined;
179682179727 for (rhs_mask_elems[0..max_abi_size], 0..) |*rhs_mask_elem, byte_index| {
179683179728 const elem_index = byte_index / elem_abi_size;
179684 rhs_mask_elem.* = try pt.intern(.{ .int = .{
179685 .ty = .u8_type,
179686 .storage = .{ .u64 = if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179687 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179688 if (mask_elem >= 0) break :elem 0b1_00_00000;
179689 const mask_elem_index: u31 = @intCast(~mask_elem);
179690 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179691 break :elem @intCast(mask_elem_index * elem_abi_size + byte_off);
179692 } },
179693 } });
179729 rhs_mask_elem.* = (try pt.intValue(.u8, if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179730 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179731 if (mask_elem >= 0) break :elem 0b1_00_00000;
179732 const mask_elem_index: u31 = @intCast(~mask_elem);
179733 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179734 break :elem mask_elem_index * elem_abi_size + byte_off;
179735 })).toIntern();
179694179736 }
179695179737 const rhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });
179696179738 const rhs_mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -188160,6 +188202,7 @@ const Select = struct {
188160188202 ptr_bit_size,
188161188203 size,
188162188204 src0_size,
188205 dst0_size,
188163188206 delta_size,
188164188207 delta_elem_size,
188165188208 unaligned_size,
......@@ -188203,6 +188246,7 @@ const Select = struct {
188203188246 const sub_src0_size: Adjust = .{ .sign = .neg, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };
188204188247 const add_src0_size: Adjust = .{ .sign = .pos, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };
188205188248 const add_8_src0_size: Adjust = .{ .sign = .pos, .lhs = .src0_size, .op = .mul, .rhs = .@"8" };
188249 const add_dst0_size: Adjust = .{ .sign = .pos, .lhs = .dst0_size, .op = .mul, .rhs = .@"1" };
188206188250 const add_delta_size_div_8: Adjust = .{ .sign = .pos, .lhs = .delta_size, .op = .div, .rhs = .@"8" };
188207188251 const add_delta_elem_size: Adjust = .{ .sign = .pos, .lhs = .delta_elem_size, .op = .mul, .rhs = .@"1" };
188208188252 const add_delta_elem_size_div_8: Adjust = .{ .sign = .pos, .lhs = .delta_elem_size, .op = .div, .rhs = .@"8" };
......@@ -188998,6 +189042,7 @@ const Select = struct {
188998189042 .ptr_bit_size => s.cg.target.ptrBitWidth(),
188999189043 .size => @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu)),
189000189044 .src0_size => @intCast(Select.Operand.Ref.src0.typeOf(s).abiSize(s.cg.pt.zcu)),
189045 .dst0_size => @intCast(Select.Operand.Ref.dst0.typeOf(s).abiSize(s.cg.pt.zcu)),
189001189046 .delta_size => @intCast(@as(SignedImm, @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu))) -
189002189047 @as(SignedImm, @intCast(op.flags.index.ref.typeOf(s).abiSize(s.cg.pt.zcu)))),
189003189048 .delta_elem_size => @intCast(@as(SignedImm, @intCast(op.flags.base.ref.typeOf(s).elemType2(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))) -
src/codegen.zig+32-7
......@@ -32,8 +32,9 @@ fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Featu
3232 return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
3333}
3434
35pub fn importBackend(comptime backend: std.builtin.CompilerBackend) ?type {
35fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
3636 return switch (backend) {
37 .other, .stage1 => unreachable,
3738 .stage2_aarch64 => @import("arch/aarch64/CodeGen.zig"),
3839 .stage2_arm => @import("arch/arm/CodeGen.zig"),
3940 .stage2_c => @import("codegen/c.zig"),
......@@ -42,11 +43,35 @@ pub fn importBackend(comptime backend: std.builtin.CompilerBackend) ?type {
4243 .stage2_riscv64 => @import("arch/riscv64/CodeGen.zig"),
4344 .stage2_sparc64 => @import("arch/sparc64/CodeGen.zig"),
4445 .stage2_spirv64 => @import("codegen/spirv.zig"),
45 .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"),
46 else => null,
46 .stage2_wasm => @import("arch/wasm/CodeGen.zig"),
47 .stage2_x86, .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"),
48 _ => unreachable,
4749 };
4850}
4951
52pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *const Air.Legalize.Features {
53 const zcu = pt.zcu;
54 const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
55 switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) {
56 else => unreachable,
57 inline .stage2_llvm,
58 .stage2_c,
59 .stage2_wasm,
60 .stage2_arm,
61 .stage2_x86_64,
62 .stage2_aarch64,
63 .stage2_x86,
64 .stage2_riscv64,
65 .stage2_sparc64,
66 .stage2_spirv64,
67 .stage2_powerpc,
68 => |backend| {
69 const Backend = importBackend(backend);
70 return if (@hasDecl(Backend, "legalizeFeatures")) Backend.legalizeFeatures(target) else &.initEmpty();
71 },
72 }
73}
74
5075pub fn generateFunction(
5176 lf: *link.File,
5277 pt: Zcu.PerThread,
......@@ -60,7 +85,7 @@ pub fn generateFunction(
6085 const zcu = pt.zcu;
6186 const func = zcu.funcInfo(func_index);
6287 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
63 switch (target_util.zigBackend(target, false)) {
88 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
6489 else => unreachable,
6590 inline .stage2_aarch64,
6691 .stage2_arm,
......@@ -70,7 +95,7 @@ pub fn generateFunction(
7095 .stage2_x86_64,
7196 => |backend| {
7297 dev.check(devFeatureForBackend(backend));
73 return importBackend(backend).?.generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output);
98 return importBackend(backend).generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output);
7499 },
75100 }
76101}
......@@ -88,14 +113,14 @@ pub fn generateLazyFunction(
88113 zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
89114 else
90115 zcu.getTarget();
91 switch (target_util.zigBackend(target, false)) {
116 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
92117 else => unreachable,
93118 inline .stage2_powerpc,
94119 .stage2_riscv64,
95120 .stage2_x86_64,
96121 => |backend| {
97122 dev.check(devFeatureForBackend(backend));
98 return importBackend(backend).?.generateLazy(lf, pt, src_loc, lazy_sym, code, debug_output);
123 return importBackend(backend).generateLazy(lf, pt, src_loc, lazy_sym, code, debug_output);
99124 },
100125 }
101126}
src/codegen/c.zig+6-6
......@@ -1591,7 +1591,7 @@ pub const DeclGen = struct {
15911591 try writer.writeAll("((");
15921592 try dg.renderCType(writer, ctype);
15931593 return writer.print("){x})", .{
1594 try dg.fmtIntLiteral(try pt.undefValue(.usize), .Other),
1594 try dg.fmtIntLiteral(.undef_usize, .Other),
15951595 });
15961596 },
15971597 .slice => {
......@@ -1605,7 +1605,7 @@ pub const DeclGen = struct {
16051605 const ptr_ty = ty.slicePtrFieldType(zcu);
16061606 try dg.renderType(writer, ptr_ty);
16071607 return writer.print("){x}, {0x}}}", .{
1608 try dg.fmtIntLiteral(try dg.pt.undefValue(.usize), .Other),
1608 try dg.fmtIntLiteral(.undef_usize, .Other),
16091609 });
16101610 },
16111611 },
......@@ -6376,7 +6376,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
63766376 if (operand_child_ctype.info(ctype_pool) == .array) {
63776377 try writer.writeByte('&');
63786378 try f.writeCValueDeref(writer, operand);
6379 try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
6379 try writer.print("[{}]", .{try f.fmtIntLiteral(.zero_usize)});
63806380 } else try f.writeCValue(writer, operand, .Other);
63816381 }
63826382 try a.end(f, writer);
......@@ -6907,7 +6907,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
69076907 try writer.writeAll("for (");
69086908 try f.writeCValue(writer, index, .Other);
69096909 try writer.writeAll(" = ");
6910 try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Other);
6910 try f.object.dg.renderValue(writer, .zero_usize, .Other);
69116911 try writer.writeAll("; ");
69126912 try f.writeCValue(writer, index, .Other);
69136913 try writer.writeAll(" != ");
......@@ -8311,11 +8311,11 @@ const Vectorize = struct {
83118311
83128312 try writer.writeAll("for (");
83138313 try f.writeCValue(writer, local, .Other);
8314 try writer.print(" = {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
8314 try writer.print(" = {d}; ", .{try f.fmtIntLiteral(.zero_usize)});
83158315 try f.writeCValue(writer, local, .Other);
83168316 try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, ty.vectorLen(zcu)))});
83178317 try f.writeCValue(writer, local, .Other);
8318 try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(try pt.intValue(.usize, 1))});
8318 try writer.print(" += {d}) {{\n", .{try f.fmtIntLiteral(.one_usize)});
83198319 f.object.indent_writer.pushIndent();
83208320
83218321 break :index .{ .index = local };
src/codegen/c/Type.zig+15-6
......@@ -1408,6 +1408,15 @@ pub const Pool = struct {
14081408 .bits = pt.zcu.errorSetBits(),
14091409 }, mod, kind),
14101410
1411 .ptr_usize_type,
1412 => return pool.getPointer(allocator, .{
1413 .elem_ctype = .usize,
1414 }),
1415 .ptr_const_comptime_int_type,
1416 => return pool.getPointer(allocator, .{
1417 .elem_ctype = .void,
1418 .@"const" = true,
1419 }),
14111420 .manyptr_u8_type,
14121421 => return pool.getPointer(allocator, .{
14131422 .elem_ctype = .u8,
......@@ -1418,11 +1427,6 @@ pub const Pool = struct {
14181427 .elem_ctype = .u8,
14191428 .@"const" = true,
14201429 }),
1421 .single_const_pointer_to_comptime_int_type,
1422 => return pool.getPointer(allocator, .{
1423 .elem_ctype = .void,
1424 .@"const" = true,
1425 }),
14261430 .slice_const_u8_type,
14271431 .slice_const_u8_sentinel_0_type,
14281432 => {
......@@ -2157,11 +2161,16 @@ pub const Pool = struct {
21572161 },
21582162
21592163 .undef,
2164 .undef_bool,
2165 .undef_usize,
2166 .undef_u1,
21602167 .zero,
21612168 .zero_usize,
2169 .zero_u1,
21622170 .zero_u8,
21632171 .one,
21642172 .one_usize,
2173 .one_u1,
21652174 .one_u8,
21662175 .four_u8,
21672176 .negative_one,
......@@ -2172,7 +2181,7 @@ pub const Pool = struct {
21722181 .bool_false,
21732182 .empty_tuple,
21742183 .none,
2175 => unreachable,
2184 => unreachable, // values, not types
21762185
21772186 _ => |ip_index| switch (ip.indexToKey(ip_index)) {
21782187 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
src/codegen/llvm.zig+7-1
......@@ -3081,10 +3081,11 @@ pub const Object = struct {
30813081 .undefined_type,
30823082 .enum_literal_type,
30833083 => unreachable,
3084 .ptr_usize_type,
3085 .ptr_const_comptime_int_type,
30843086 .manyptr_u8_type,
30853087 .manyptr_const_u8_type,
30863088 .manyptr_const_u8_sentinel_0_type,
3087 .single_const_pointer_to_comptime_int_type,
30883089 => .ptr,
30893090 .slice_const_u8_type,
30903091 .slice_const_u8_sentinel_0_type,
......@@ -3098,11 +3099,16 @@ pub const Object = struct {
30983099 => unreachable,
30993100 // values, not types
31003101 .undef,
3102 .undef_bool,
3103 .undef_usize,
3104 .undef_u1,
31013105 .zero,
31023106 .zero_usize,
3107 .zero_u1,
31033108 .zero_u8,
31043109 .one,
31053110 .one_usize,
3111 .one_u1,
31063112 .one_u8,
31073113 .four_u8,
31083114 .negative_one,
src/mutable_value.zig+2-2
......@@ -260,7 +260,7 @@ pub const MutableValue = union(enum) {
260260 const ptr = try arena.create(MutableValue);
261261 const len = try arena.create(MutableValue);
262262 ptr.* = .{ .interned = try pt.intern(.{ .undef = ip.slicePtrType(ty_ip) }) };
263 len.* = .{ .interned = try pt.intern(.{ .undef = .usize_type }) };
263 len.* = .{ .interned = .undef_usize };
264264 mv.* = .{ .slice = .{
265265 .ty = ty_ip,
266266 .ptr = ptr,
......@@ -464,7 +464,7 @@ pub const MutableValue = union(enum) {
464464 return switch (field_idx) {
465465 Value.slice_ptr_index => .{ .interned = Value.fromInterned(ip_index).slicePtr(pt.zcu).toIntern() },
466466 Value.slice_len_index => .{ .interned = switch (pt.zcu.intern_pool.indexToKey(ip_index)) {
467 .undef => try pt.intern(.{ .undef = .usize_type }),
467 .undef => .undef_usize,
468468 .slice => |s| s.len,
469469 else => unreachable,
470470 } },
test/behavior/abs.zig-2
......@@ -96,7 +96,6 @@ test "@abs big int <= 128 bits" {
9696 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
9797 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
9898 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
99 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
10099
101100 try comptime testAbsSignedBigInt();
102101 try testAbsSignedBigInt();
......@@ -211,7 +210,6 @@ fn testAbsFloats(comptime T: type) !void {
211210test "@abs int vectors" {
212211 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
213212 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
214 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
215213 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
216214 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
217215 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/basic.zig-1
......@@ -837,7 +837,6 @@ test "extern variable with non-pointer opaque type" {
837837 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
838838 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
839839 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
840 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
841840 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
842841
843842 @export(&var_to_export, .{ .name = "opaque_extern_var" });
test/behavior/bitcast.zig-1
......@@ -384,7 +384,6 @@ test "comptime bitcast with fields following f80" {
384384 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
385385 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
386386 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
387 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
388387
389388 const FloatT = extern struct { f: f80, x: u128 align(16) };
390389 const x: FloatT = .{ .f = 0.5, .x = 123 };
test/behavior/bitreverse.zig-4
......@@ -12,7 +12,6 @@ test "@bitReverse" {
1212 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1313 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1414 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
1615 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1716
1817 try comptime testBitReverse();
......@@ -128,7 +127,6 @@ test "bitReverse vectors u8" {
128127 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
129128 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
130129 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
131 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
132130
133131 try comptime vector8();
134132 try vector8();
......@@ -149,7 +147,6 @@ test "bitReverse vectors u16" {
149147 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
150148 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
151149 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
152 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
153150
154151 try comptime vector16();
155152 try vector16();
......@@ -170,7 +167,6 @@ test "bitReverse vectors u24" {
170167 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
171168 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
172169 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
173 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
174170
175171 try comptime vector24();
176172 try vector24();
test/behavior/byteswap.zig-4
......@@ -39,7 +39,6 @@ test "@byteSwap integers" {
3939 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
4040 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
4141 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
42 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
4342
4443 const ByteSwapIntTest = struct {
4544 fn run() !void {
......@@ -100,7 +99,6 @@ test "@byteSwap vectors u8" {
10099 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
101100 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
102101 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
103 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
104102
105103 try comptime vector8();
106104 try vector8();
......@@ -121,7 +119,6 @@ test "@byteSwap vectors u16" {
121119 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
122120 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
123121 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
124 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
125122
126123 try comptime vector16();
127124 try vector16();
......@@ -142,7 +139,6 @@ test "@byteSwap vectors u24" {
142139 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
143140 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
144141 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
145 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
146142
147143 try comptime vector24();
148144 try vector24();
test/behavior/cast.zig-4
......@@ -617,7 +617,6 @@ test "@intCast on vector" {
617617 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
618618 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
619619 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
620 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
621620 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
622621 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
623622 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;
......@@ -2520,7 +2519,6 @@ test "@ptrFromInt on vector" {
25202519 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
25212520 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
25222521 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
2523 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
25242522 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
25252523
25262524 const S = struct {
......@@ -2592,7 +2590,6 @@ test "@intFromFloat on vector" {
25922590 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
25932591 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
25942592 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
2595 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
25962593
25972594 const S = struct {
25982595 fn doTheTest() !void {
......@@ -2693,7 +2690,6 @@ test "@intCast vector of signed integer" {
26932690 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
26942691 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
26952692 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2696 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
26972693 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
26982694 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
26992695 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;
test/behavior/extern.zig-1
......@@ -5,7 +5,6 @@ const expect = std.testing.expect;
55test "anyopaque extern symbol" {
66 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
77 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
98 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
109
1110 const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });
test/behavior/floatop.zig-3
......@@ -135,7 +135,6 @@ test "cmp f32" {
135135 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
136136 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
137137 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
138 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
139138
140139 try testCmp(f32);
141140 try comptime testCmp(f32);
......@@ -144,7 +143,6 @@ test "cmp f32" {
144143test "cmp f64" {
145144 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
146145 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
147 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
148146 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
149147
150148 try testCmp(f64);
......@@ -400,7 +398,6 @@ test "@sqrt f32/f64" {
400398 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
401399 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
402400 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
403 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
404401 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
405402
406403 try testSqrt(f32);
test/behavior/fn.zig-1
......@@ -429,7 +429,6 @@ test "implicit cast function to function ptr" {
429429 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
430430 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
431431 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
432 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
433432
434433 const S1 = struct {
435434 export fn someFunctionThatReturnsAValue() c_int {
test/behavior/math.zig-10
......@@ -85,7 +85,6 @@ test "@clz big ints" {
8585 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
8686 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
8787 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
88 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
8988 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
9089
9190 try testClzBigInts();
......@@ -103,7 +102,6 @@ fn testOneClz(comptime T: type, x: T) u32 {
103102
104103test "@clz vectors" {
105104 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
106 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
107105 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
108106 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
109107 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -173,7 +171,6 @@ fn testOneCtz(comptime T: type, x: T) u32 {
173171}
174172
175173test "@ctz 128-bit integers" {
176 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
177174 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
178175 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
179176 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -198,7 +195,6 @@ test "@ctz vectors" {
198195 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
199196 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
200197 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
201 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
202198
203199 try testCtzVectors();
204200 try comptime testCtzVectors();
......@@ -1694,9 +1690,6 @@ test "vector comparison" {
16941690 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
16951691 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
16961692
1697 if (builtin.zig_backend == .stage2_x86_64 and
1698 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx2)) return error.SkipZigTest;
1699
17001693 const S = struct {
17011694 fn doTheTest() !void {
17021695 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
......@@ -1785,7 +1778,6 @@ test "mod lazy values" {
17851778
17861779test "@clz works on both vector and scalar inputs" {
17871780 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1788 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
17891781 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
17901782 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
17911783 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -1807,7 +1799,6 @@ test "runtime comparison to NaN is comptime-known" {
18071799 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
18081800 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18091801 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1810 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
18111802 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
18121803 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
18131804
......@@ -1838,7 +1829,6 @@ test "runtime int comparison to inf is comptime-known" {
18381829 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
18391830 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18401831 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1841 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
18421832 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
18431833 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
18441834
test/behavior/maximum_minimum.zig-5
......@@ -34,7 +34,6 @@ test "@max on vectors" {
3434 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3535 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
3636 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
37 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
3837
3938 const S = struct {
4039 fn doTheTest() !void {
......@@ -90,7 +89,6 @@ test "@min for vectors" {
9089 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
9190 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
9291 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
93 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
9492
9593 const S = struct {
9694 fn doTheTest() !void {
......@@ -260,7 +258,6 @@ test "@min/@max notices bounds from vector types" {
260258 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
261259 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
262260 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
263 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
264261
265262 var x: @Vector(2, u16) = .{ 30, 67 };
266263 var y: @Vector(2, u32) = .{ 20, 500 };
......@@ -303,7 +300,6 @@ test "@min/@max notices bounds from vector types when element of comptime-known
303300 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
304301 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
305302 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
306 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
307303
308304 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };
309305 _ = &x;
......@@ -375,7 +371,6 @@ test "@min/@max with runtime vectors of signed and unsigned integers of same siz
375371 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
376372 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
377373 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
378 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
379374
380375 const S = struct {
381376 fn min(a: @Vector(2, i32), b: @Vector(2, u32)) @Vector(2, i32) {
test/behavior/popcount.zig-1
......@@ -82,7 +82,6 @@ test "@popCount vectors" {
8282 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
8383 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
8484 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
85 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
8685
8786 try comptime testPopCountVectors();
8887 try testPopCountVectors();
test/behavior/select.zig+1-1
......@@ -70,7 +70,7 @@ fn selectArrays() !void {
7070test "@select compare result" {
7171 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
7272 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
73 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
73 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
7474 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;
7575
7676 const S = struct {
test/behavior/union.zig+1
......@@ -282,6 +282,7 @@ test "cast union to tag type of union" {
282282 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
283283 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
284284 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
285 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
285286
286287 try testCastUnionToTag();
287288 try comptime testCastUnionToTag();
test/behavior/vector.zig+1-7
......@@ -31,7 +31,6 @@ test "vector wrap operators" {
3131 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3232 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
3333 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
34 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
3534
3635 const S = struct {
3736 fn doTheTest() !void {
......@@ -652,7 +651,6 @@ test "vector division operators" {
652651test "vector bitwise not operator" {
653652 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
654653 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
655 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
656654 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
657655 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
658656 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -934,7 +932,6 @@ test "saturating add" {
934932 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
935933 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
936934 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
937 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
938935
939936 const S = struct {
940937 fn doTheTest() !void {
......@@ -969,7 +966,6 @@ test "saturating subtraction" {
969966 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
970967 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
971968 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
972 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
973969
974970 const S = struct {
975971 fn doTheTest() !void {
......@@ -989,7 +985,6 @@ test "saturating subtraction" {
989985
990986test "saturating multiplication" {
991987 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
992 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
993988 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
994989 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
995990 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -1018,12 +1013,12 @@ test "saturating multiplication" {
10181013
10191014test "saturating shift-left" {
10201015 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1021 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
10221016 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
10231017 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
10241018 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10251019 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10261020 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1021 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
10271022
10281023 const S = struct {
10291024 fn doTheTest() !void {
......@@ -1469,7 +1464,6 @@ test "compare vectors with different element types" {
14691464 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
14701465 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
14711466 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1472 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
14731467 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14741468 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
14751469
test/behavior/x86_64/binary.zig+32-12
......@@ -1,5 +1,7 @@
11const AddOneBit = math.AddOneBit;
2const AsSignedness = math.AsSignedness;
23const cast = math.cast;
4const ChangeScalar = math.ChangeScalar;
35const checkExpected = math.checkExpected;
46const Compare = math.Compare;
57const DoubleBits = math.DoubleBits;
......@@ -13,6 +15,7 @@ const math = @import("math.zig");
1315const nan = math.nan;
1416const Scalar = math.Scalar;
1517const sign = math.sign;
18const splat = math.splat;
1619const Sse = math.Sse;
1720const tmin = math.tmin;
1821
......@@ -5141,6 +5144,7 @@ inline fn mulSat(comptime Type: type, lhs: Type, rhs: Type) Type {
51415144test mulSat {
51425145 const test_mul_sat = binary(mulSat, .{});
51435146 try test_mul_sat.testInts();
5147 try test_mul_sat.testIntVectors();
51445148}
51455149
51465150inline fn multiply(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs * rhs) {
......@@ -5265,9 +5269,9 @@ test mulWithOverflow {
52655269}
52665270
52675271inline fn shlWithOverflow(comptime Type: type, lhs: Type, rhs: Type) struct { Type, u1 } {
5268 const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
5272 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
52695273 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5270 return @shlWithOverflow(lhs, if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs);
5274 return @shlWithOverflow(lhs, if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs);
52715275}
52725276test shlWithOverflow {
52735277 const test_shl_with_overflow = binary(shlWithOverflow, .{});
......@@ -5280,7 +5284,9 @@ inline fn equal(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs == rhs) {
52805284test equal {
52815285 const test_equal = binary(equal, .{});
52825286 try test_equal.testInts();
5287 try test_equal.testIntVectors();
52835288 try test_equal.testFloats();
5289 try test_equal.testFloatVectors();
52845290}
52855291
52865292inline fn notEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs != rhs) {
......@@ -5289,7 +5295,9 @@ inline fn notEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs != rhs
52895295test notEqual {
52905296 const test_not_equal = binary(notEqual, .{});
52915297 try test_not_equal.testInts();
5298 try test_not_equal.testIntVectors();
52925299 try test_not_equal.testFloats();
5300 try test_not_equal.testFloatVectors();
52935301}
52945302
52955303inline fn lessThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs < rhs) {
......@@ -5298,7 +5306,9 @@ inline fn lessThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs < rhs)
52985306test lessThan {
52995307 const test_less_than = binary(lessThan, .{});
53005308 try test_less_than.testInts();
5309 try test_less_than.testIntVectors();
53015310 try test_less_than.testFloats();
5311 try test_less_than.testFloatVectors();
53025312}
53035313
53045314inline fn lessThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs <= rhs) {
......@@ -5307,7 +5317,9 @@ inline fn lessThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs
53075317test lessThanOrEqual {
53085318 const test_less_than_or_equal = binary(lessThanOrEqual, .{});
53095319 try test_less_than_or_equal.testInts();
5320 try test_less_than_or_equal.testIntVectors();
53105321 try test_less_than_or_equal.testFloats();
5322 try test_less_than_or_equal.testFloatVectors();
53115323}
53125324
53135325inline fn greaterThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs > rhs) {
......@@ -5316,7 +5328,9 @@ inline fn greaterThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs > r
53165328test greaterThan {
53175329 const test_greater_than = binary(greaterThan, .{});
53185330 try test_greater_than.testInts();
5331 try test_greater_than.testIntVectors();
53195332 try test_greater_than.testFloats();
5333 try test_greater_than.testFloatVectors();
53205334}
53215335
53225336inline fn greaterThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs >= rhs) {
......@@ -5325,7 +5339,9 @@ inline fn greaterThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(
53255339test greaterThanOrEqual {
53265340 const test_greater_than_or_equal = binary(greaterThanOrEqual, .{});
53275341 try test_greater_than_or_equal.testInts();
5342 try test_greater_than_or_equal.testIntVectors();
53285343 try test_greater_than_or_equal.testFloats();
5344 try test_greater_than_or_equal.testFloatVectors();
53295345}
53305346
53315347inline fn bitAnd(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs & rhs) {
......@@ -5347,54 +5363,57 @@ test bitOr {
53475363}
53485364
53495365inline fn shr(comptime Type: type, lhs: Type, rhs: Type) Type {
5350 const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
5366 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
53515367 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5352 return lhs >> if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs;
5368 return lhs >> if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;
53535369}
53545370test shr {
53555371 const test_shr = binary(shr, .{});
53565372 try test_shr.testInts();
5373 try test_shr.testIntVectors();
53575374}
53585375
53595376inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {
5360 const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
5377 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
53615378 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5362 const final_rhs = if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs;
5379 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;
53635380 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);
53645381}
53655382test shrExact {
53665383 const test_shr_exact = binary(shrExact, .{});
53675384 try test_shr_exact.testInts();
5385 try test_shr_exact.testIntVectors();
53685386}
53695387
53705388inline fn shl(comptime Type: type, lhs: Type, rhs: Type) Type {
5371 const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
5389 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
53725390 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5373 return lhs << if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs;
5391 return lhs << if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;
53745392}
53755393test shl {
53765394 const test_shl = binary(shl, .{});
53775395 try test_shl.testInts();
5396 try test_shl.testIntVectors();
53785397}
53795398
53805399inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {
53815400 @setRuntimeSafety(false);
5382 const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
5401 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
53835402 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5384 const final_rhs = if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs;
5403 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;
53855404 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);
53865405}
53875406test shlExactUnsafe {
53885407 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});
53895408 try test_shl_exact_unsafe.testInts();
5409 try test_shl_exact_unsafe.testIntVectors();
53905410}
53915411
53925412inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {
53935413 // workaround https://github.com/ziglang/zig/issues/23034
53945414 if (@inComptime()) {
53955415 // workaround https://github.com/ziglang/zig/issues/23139
5396 //return lhs <<| @min(@abs(rhs), imax(u64));
5397 return lhs <<| @min(@abs(rhs), @as(u64, imax(u64)));
5416 return lhs <<| @min(@abs(rhs), splat(ChangeScalar(Type, u64), imax(u64)));
53985417 }
53995418 // workaround https://github.com/ziglang/zig/issues/23033
54005419 @setRuntimeSafety(false);
......@@ -5403,6 +5422,7 @@ inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {
54035422test shlSat {
54045423 const test_shl_sat = binary(shlSat, .{});
54055424 try test_shl_sat.testInts();
5425 try test_shl_sat.testIntVectors();
54065426}
54075427
54085428inline fn bitXor(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs ^ rhs) {
test/behavior/x86_64/math.zig+26-28
......@@ -8,8 +8,6 @@ pub const fmin = math.floatMin;
88pub const imax = math.maxInt;
99pub const imin = math.minInt;
1010pub const inf = math.inf;
11pub const Log2Int = math.Log2Int;
12pub const Log2IntCeil = math.Log2IntCeil;
1311pub const nan = math.nan;
1412pub const next = math.nextAfter;
1513pub const tmin = math.floatTrueMin;
......@@ -30,38 +28,44 @@ pub fn Scalar(comptime Type: type) type {
3028 .vector => |info| info.child,
3129 };
3230}
31pub fn ChangeScalar(comptime Type: type, comptime NewScalar: type) type {
32 return switch (@typeInfo(Type)) {
33 else => NewScalar,
34 .vector => |vector| @Vector(vector.len, NewScalar),
35 };
36}
37pub fn AsSignedness(comptime Type: type, comptime signedness: std.builtin.Signedness) type {
38 return ChangeScalar(Type, @Type(.{ .int = .{
39 .signedness = signedness,
40 .bits = @typeInfo(Scalar(Type)).int.bits,
41 } }));
42}
3343pub fn AddOneBit(comptime Type: type) type {
34 const ResultScalar = switch (@typeInfo(Scalar(Type))) {
44 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
3545 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = 1 + int.bits } }),
3646 .float => Scalar(Type),
3747 else => @compileError(@typeName(Type)),
38 };
39 return switch (@typeInfo(Type)) {
40 else => ResultScalar,
41 .vector => |vector| @Vector(vector.len, ResultScalar),
42 };
48 });
4349}
4450pub fn DoubleBits(comptime Type: type) type {
45 const ResultScalar = switch (@typeInfo(Scalar(Type))) {
51 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
4652 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = int.bits * 2 } }),
4753 .float => Scalar(Type),
4854 else => @compileError(@typeName(Type)),
49 };
50 return switch (@typeInfo(Type)) {
51 else => ResultScalar,
52 .vector => |vector| @Vector(vector.len, ResultScalar),
53 };
55 });
5456}
5557pub fn RoundBitsUp(comptime Type: type, comptime multiple: u16) type {
56 const ResultScalar = switch (@typeInfo(Scalar(Type))) {
58 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
5759 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = std.mem.alignForward(u16, int.bits, multiple) } }),
5860 .float => Scalar(Type),
5961 else => @compileError(@typeName(Type)),
60 };
61 return switch (@typeInfo(Type)) {
62 else => ResultScalar,
63 .vector => |vector| @Vector(vector.len, ResultScalar),
64 };
62 });
63}
64pub fn Log2Int(comptime Type: type) type {
65 return ChangeScalar(Type, math.Log2Int(Scalar(Type)));
66}
67pub fn Log2IntCeil(comptime Type: type) type {
68 return ChangeScalar(Type, math.Log2IntCeil(Scalar(Type)));
6569}
6670// inline to avoid a runtime `@splat`
6771pub inline fn splat(comptime Type: type, scalar: Scalar(Type)) Type {
......@@ -78,18 +82,12 @@ inline fn select(cond: anytype, lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {
7882 else => @compileError(@typeName(@TypeOf(cond))),
7983 };
8084}
81pub fn sign(rhs: anytype) switch (@typeInfo(@TypeOf(rhs))) {
82 else => bool,
83 .vector => |vector| @Vector(vector.len, bool),
84} {
85pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) {
8586 const ScalarInt = @Type(.{ .int = .{
8687 .signedness = .unsigned,
8788 .bits = @bitSizeOf(Scalar(@TypeOf(rhs))),
8889 } });
89 const VectorInt = switch (@typeInfo(@TypeOf(rhs))) {
90 else => ScalarInt,
91 .vector => |vector| @Vector(vector.len, ScalarInt),
92 };
90 const VectorInt = ChangeScalar(@TypeOf(rhs), ScalarInt);
9391 return @as(VectorInt, @bitCast(rhs)) & splat(VectorInt, @as(ScalarInt, 1) << @bitSizeOf(ScalarInt) - 1) != splat(VectorInt, 0);
9492}
9593fn boolAnd(lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {
test/cases/compile_errors/@import_zon_bad_type.zig+3-3
......@@ -117,9 +117,9 @@ export fn testMutablePointer() void {
117117// tmp.zig:37:38: note: imported here
118118// neg_inf.zon:1:1: error: expected type '?u8'
119119// tmp.zig:57:28: note: imported here
120// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_518'
120// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_522'
121121// tmp.zig:62:39: note: imported here
122// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_520'
122// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_524'
123123// tmp.zig:67:44: note: imported here
124// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_523'
124// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_527'
125125// tmp.zig:72:50: note: imported here
test/cases/compile_errors/anytype_param_requires_comptime.zig+1-1
......@@ -15,6 +15,6 @@ pub export fn entry() void {
1515// error
1616//
1717// :7:25: error: unable to resolve comptime value
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_492.C' must be comptime-known
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_496.C' must be comptime-known
1919// :4:16: note: struct requires comptime because of this field
2020// :4:16: note: types are not available at runtime
test/cases/compile_errors/bogus_method_call_on_slice.zig+1-1
......@@ -16,5 +16,5 @@ pub export fn entry2() void {
1616//
1717// :3:6: error: no field or member function named 'copy' in '[]const u8'
1818// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_496'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_500'
2020// :12:6: note: struct declared here
test/cases/compile_errors/coerce_anon_struct.zig+1-1
......@@ -6,6 +6,6 @@ export fn foo() void {
66
77// error
88//
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_485'
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_489'
1010// :3:16: note: struct declared here
1111// :1:11: note: struct declared here
test/cases/compile_errors/redundant_try.zig+2-2
......@@ -44,9 +44,9 @@ comptime {
4444//
4545// :5:23: error: expected error union type, found 'comptime_int'
4646// :10:23: error: expected error union type, found '@TypeOf(.{})'
47// :15:23: error: expected error union type, found 'tmp.test2__struct_522'
47// :15:23: error: expected error union type, found 'tmp.test2__struct_526'
4848// :15:23: note: struct declared here
49// :20:27: error: expected error union type, found 'tmp.test3__struct_524'
49// :20:27: error: expected error union type, found 'tmp.test3__struct_528'
5050// :20:27: note: struct declared here
5151// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
5252// :31:13: error: expected error union type, found 'u32'
tools/lldb_pretty_printers.py+2-1
......@@ -601,7 +601,8 @@ type_tag_handlers = {
601601 'fn_void_no_args': lambda payload: 'fn() void',
602602 'fn_naked_noreturn_no_args': lambda payload: 'fn() callconv(.naked) noreturn',
603603 'fn_ccc_void_no_args': lambda payload: 'fn() callconv(.c) void',
604 'single_const_pointer_to_comptime_int': lambda payload: '*const comptime_int',
604 'ptr_usize': lambda payload: '*usize',
605 'ptr_const_comptime_int': lambda payload: '*const comptime_int',
605606 'manyptr_u8': lambda payload: '[*]u8',
606607 'manyptr_const_u8': lambda payload: '[*]const u8',
607608 'manyptr_const_u8_sentinel_0': lambda payload: '[*:0]const u8',