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(...@@ -11194,6 +11194,7 @@ fn rvalueInner(
11194 const as_void = @as(u64, @intFromEnum(Zir.Inst.Ref.void_type)) << 32;11194 const as_void = @as(u64, @intFromEnum(Zir.Inst.Ref.void_type)) << 32;
11195 const as_comptime_int = @as(u64, @intFromEnum(Zir.Inst.Ref.comptime_int_type)) << 32;11195 const as_comptime_int = @as(u64, @intFromEnum(Zir.Inst.Ref.comptime_int_type)) << 32;
11196 const as_usize = @as(u64, @intFromEnum(Zir.Inst.Ref.usize_type)) << 32;11196 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;
11197 const as_u8 = @as(u64, @intFromEnum(Zir.Inst.Ref.u8_type)) << 32;11198 const as_u8 = @as(u64, @intFromEnum(Zir.Inst.Ref.u8_type)) << 32;
11198 switch ((@as(u64, @intFromEnum(ty_inst)) << 32) | @as(u64, @intFromEnum(result))) {11199 switch ((@as(u64, @intFromEnum(ty_inst)) << 32) | @as(u64, @intFromEnum(result))) {
11199 as_ty | @intFromEnum(Zir.Inst.Ref.u1_type),11200 as_ty | @intFromEnum(Zir.Inst.Ref.u1_type),
...@@ -11237,10 +11238,11 @@ fn rvalueInner(...@@ -11237,10 +11238,11 @@ fn rvalueInner(
11237 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),11238 as_ty | @intFromEnum(Zir.Inst.Ref.null_type),
11238 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),11239 as_ty | @intFromEnum(Zir.Inst.Ref.undefined_type),
11239 as_ty | @intFromEnum(Zir.Inst.Ref.enum_literal_type),11240 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),
11240 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),11243 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_u8_type),
11241 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),11244 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_type),
11242 as_ty | @intFromEnum(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),11245 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),
11244 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_type),11246 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_type),
11245 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_sentinel_0_type),11247 as_ty | @intFromEnum(Zir.Inst.Ref.slice_const_u8_sentinel_0_type),
11246 as_ty | @intFromEnum(Zir.Inst.Ref.anyerror_void_error_union_type),11248 as_ty | @intFromEnum(Zir.Inst.Ref.anyerror_void_error_union_type),
...@@ -11249,27 +11251,45 @@ fn rvalueInner(...@@ -11249,27 +11251,45 @@ fn rvalueInner(
11249 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero),11251 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero),
11250 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one),11252 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one),
11251 as_comptime_int | @intFromEnum(Zir.Inst.Ref.negative_one),11253 as_comptime_int | @intFromEnum(Zir.Inst.Ref.negative_one),
11254 as_usize | @intFromEnum(Zir.Inst.Ref.undef_usize),
11252 as_usize | @intFromEnum(Zir.Inst.Ref.zero_usize),11255 as_usize | @intFromEnum(Zir.Inst.Ref.zero_usize),
11253 as_usize | @intFromEnum(Zir.Inst.Ref.one_usize),11256 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),
11254 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_u8),11260 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_u8),
11255 as_u8 | @intFromEnum(Zir.Inst.Ref.one_u8),11261 as_u8 | @intFromEnum(Zir.Inst.Ref.one_u8),
11256 as_u8 | @intFromEnum(Zir.Inst.Ref.four_u8),11262 as_u8 | @intFromEnum(Zir.Inst.Ref.four_u8),
11263 as_bool | @intFromEnum(Zir.Inst.Ref.undef_bool),
11257 as_bool | @intFromEnum(Zir.Inst.Ref.bool_true),11264 as_bool | @intFromEnum(Zir.Inst.Ref.bool_true),
11258 as_bool | @intFromEnum(Zir.Inst.Ref.bool_false),11265 as_bool | @intFromEnum(Zir.Inst.Ref.bool_false),
11259 as_void | @intFromEnum(Zir.Inst.Ref.void_value),11266 as_void | @intFromEnum(Zir.Inst.Ref.void_value),
11260 => return result, // type of result is already correct11267 => 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
11262 as_usize | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_usize,11274 as_usize | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_usize,
11275 as_u1 | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_u1,
11263 as_u8 | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_u8,11276 as_u8 | @intFromEnum(Zir.Inst.Ref.zero) => return .zero_u8,
11264 as_usize | @intFromEnum(Zir.Inst.Ref.one) => return .one_usize,11277 as_usize | @intFromEnum(Zir.Inst.Ref.one) => return .one_usize,
11278 as_u1 | @intFromEnum(Zir.Inst.Ref.one) => return .one_u1,
11265 as_u8 | @intFromEnum(Zir.Inst.Ref.one) => return .one_u8,11279 as_u8 | @intFromEnum(Zir.Inst.Ref.one) => return .one_u8,
11266 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero,11280 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero,
11281 as_u1 | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero_u1,
11267 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero_u8,11282 as_u8 | @intFromEnum(Zir.Inst.Ref.zero_usize) => return .zero_u8,
11268 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one,11283 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one,
11284 as_u1 | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one_u1,
11269 as_u8 | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one_u8,11285 as_u8 | @intFromEnum(Zir.Inst.Ref.one_usize) => return .one_u8,
11286 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_u1) => return .zero,
11270 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero,11287 as_comptime_int | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero,
11288 as_usize | @intFromEnum(Zir.Inst.Ref.zero_u1) => return .zero_usize,
11271 as_usize | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero_usize,11289 as_usize | @intFromEnum(Zir.Inst.Ref.zero_u8) => return .zero_usize,
11290 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_u1) => return .one,
11272 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one,11291 as_comptime_int | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one,
11292 as_usize | @intFromEnum(Zir.Inst.Ref.one_u1) => return .one_usize,
11273 as_usize | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one_usize,11293 as_usize | @intFromEnum(Zir.Inst.Ref.one_u8) => return .one_usize,
1127411294
11275 // Need an explicit type coercion instruction.11295 // Need an explicit type coercion instruction.
lib/std/zig/Zir.zig+8-2
...@@ -2142,7 +2142,7 @@ pub const Inst = struct {...@@ -2142,7 +2142,7 @@ pub const Inst = struct {
2142 ref_start_index = static_len,2142 ref_start_index = static_len,
2143 _,2143 _,
21442144
2145 pub const static_len = 118;2145 pub const static_len = 124;
21462146
2147 pub fn toRef(i: Index) Inst.Ref {2147 pub fn toRef(i: Index) Inst.Ref {
2148 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));2148 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
...@@ -2220,10 +2220,11 @@ pub const Inst = struct {...@@ -2220,10 +2220,11 @@ pub const Inst = struct {
2220 null_type,2220 null_type,
2221 undefined_type,2221 undefined_type,
2222 enum_literal_type,2222 enum_literal_type,
2223 ptr_usize_type,
2224 ptr_const_comptime_int_type,
2223 manyptr_u8_type,2225 manyptr_u8_type,
2224 manyptr_const_u8_type,2226 manyptr_const_u8_type,
2225 manyptr_const_u8_sentinel_0_type,2227 manyptr_const_u8_sentinel_0_type,
2226 single_const_pointer_to_comptime_int_type,
2227 slice_const_u8_type,2228 slice_const_u8_type,
2228 slice_const_u8_sentinel_0_type,2229 slice_const_u8_sentinel_0_type,
2229 vector_8_i8_type,2230 vector_8_i8_type,
...@@ -2279,11 +2280,16 @@ pub const Inst = struct {...@@ -2279,11 +2280,16 @@ pub const Inst = struct {
2279 generic_poison_type,2280 generic_poison_type,
2280 empty_tuple_type,2281 empty_tuple_type,
2281 undef,2282 undef,
2283 undef_bool,
2284 undef_usize,
2285 undef_u1,
2282 zero,2286 zero,
2283 zero_usize,2287 zero_usize,
2288 zero_u1,
2284 zero_u8,2289 zero_u8,
2285 one,2290 one,
2286 one_usize,2291 one_usize,
2292 one_u1,
2287 one_u8,2293 one_u8,
2288 four_u8,2294 four_u8,
2289 negative_one,2295 negative_one,
src/Air.zig+21-15
...@@ -1011,10 +1011,11 @@ pub const Inst = struct {...@@ -1011,10 +1011,11 @@ pub const Inst = struct {
1011 null_type = @intFromEnum(InternPool.Index.null_type),1011 null_type = @intFromEnum(InternPool.Index.null_type),
1012 undefined_type = @intFromEnum(InternPool.Index.undefined_type),1012 undefined_type = @intFromEnum(InternPool.Index.undefined_type),
1013 enum_literal_type = @intFromEnum(InternPool.Index.enum_literal_type),1013 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),
1014 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),1016 manyptr_u8_type = @intFromEnum(InternPool.Index.manyptr_u8_type),
1015 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),1017 manyptr_const_u8_type = @intFromEnum(InternPool.Index.manyptr_const_u8_type),
1016 manyptr_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.manyptr_const_u8_sentinel_0_type),1018 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),
1018 slice_const_u8_type = @intFromEnum(InternPool.Index.slice_const_u8_type),1019 slice_const_u8_type = @intFromEnum(InternPool.Index.slice_const_u8_type),
1019 slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),1020 slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
1020 vector_8_i8_type = @intFromEnum(InternPool.Index.vector_8_i8_type),1021 vector_8_i8_type = @intFromEnum(InternPool.Index.vector_8_i8_type),
...@@ -1070,11 +1071,16 @@ pub const Inst = struct {...@@ -1070,11 +1071,16 @@ pub const Inst = struct {
1070 generic_poison_type = @intFromEnum(InternPool.Index.generic_poison_type),1071 generic_poison_type = @intFromEnum(InternPool.Index.generic_poison_type),
1071 empty_tuple_type = @intFromEnum(InternPool.Index.empty_tuple_type),1072 empty_tuple_type = @intFromEnum(InternPool.Index.empty_tuple_type),
1072 undef = @intFromEnum(InternPool.Index.undef),1073 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),
1073 zero = @intFromEnum(InternPool.Index.zero),1077 zero = @intFromEnum(InternPool.Index.zero),
1074 zero_usize = @intFromEnum(InternPool.Index.zero_usize),1078 zero_usize = @intFromEnum(InternPool.Index.zero_usize),
1079 zero_u1 = @intFromEnum(InternPool.Index.zero_u1),
1075 zero_u8 = @intFromEnum(InternPool.Index.zero_u8),1080 zero_u8 = @intFromEnum(InternPool.Index.zero_u8),
1076 one = @intFromEnum(InternPool.Index.one),1081 one = @intFromEnum(InternPool.Index.one),
1077 one_usize = @intFromEnum(InternPool.Index.one_usize),1082 one_usize = @intFromEnum(InternPool.Index.one_usize),
1083 one_u1 = @intFromEnum(InternPool.Index.one_u1),
1078 one_u8 = @intFromEnum(InternPool.Index.one_u8),1084 one_u8 = @intFromEnum(InternPool.Index.one_u8),
1079 four_u8 = @intFromEnum(InternPool.Index.four_u8),1085 four_u8 = @intFromEnum(InternPool.Index.four_u8),
1080 negative_one = @intFromEnum(InternPool.Index.negative_one),1086 negative_one = @intFromEnum(InternPool.Index.negative_one),
...@@ -1121,7 +1127,7 @@ pub const Inst = struct {...@@ -1121,7 +1127,7 @@ pub const Inst = struct {
1121 }1127 }
11221128
1123 pub fn toType(ref: Ref) Type {1129 pub fn toType(ref: Ref) Type {
1124 return Type.fromInterned(ref.toInterned().?);1130 return .fromInterned(ref.toInterned().?);
1125 }1131 }
1126 };1132 };
11271133
...@@ -1393,7 +1399,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {...@@ -1393,7 +1399,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
13931399
1394pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {1400pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
1395 if (inst.toInterned()) |ip_index| {1401 if (inst.toInterned()) |ip_index| {
1396 return Type.fromInterned(ip.typeOf(ip_index));1402 return .fromInterned(ip.typeOf(ip_index));
1397 } else {1403 } else {
1398 return air.typeOfIndex(inst.toIndex().?, ip);1404 return air.typeOfIndex(inst.toIndex().?, ip);
1399 }1405 }
...@@ -1483,7 +1489,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1483,7 +1489,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1483 .is_non_err_ptr,1489 .is_non_err_ptr,
1484 .is_named_enum_value,1490 .is_named_enum_value,
1485 .error_set_has_value,1491 .error_set_has_value,
1486 => return Type.bool,1492 => return .bool,
14871493
1488 .alloc,1494 .alloc,
1489 .ret_ptr,1495 .ret_ptr,
...@@ -1574,7 +1580,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1574,7 +1580,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1574 .ret_load,1580 .ret_load,
1575 .unreach,1581 .unreach,
1576 .trap,1582 .trap,
1577 => return Type.noreturn,1583 => return .noreturn,
15781584
1579 .breakpoint,1585 .breakpoint,
1580 .dbg_stmt,1586 .dbg_stmt,
...@@ -1597,22 +1603,22 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1597,22 +1603,22 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1597 .set_err_return_trace,1603 .set_err_return_trace,
1598 .vector_store_elem,1604 .vector_store_elem,
1599 .c_va_end,1605 .c_va_end,
1600 => return Type.void,1606 => return .void,
16011607
1602 .slice_len,1608 .slice_len,
1603 .ret_addr,1609 .ret_addr,
1604 .frame_addr,1610 .frame_addr,
1605 .save_err_return_trace_index,1611 .save_err_return_trace_index,
1606 => return Type.usize,1612 => return .usize,
16071613
1608 .wasm_memory_grow => return Type.isize,1614 .wasm_memory_grow => return .isize,
1609 .wasm_memory_size => return Type.usize,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
1613 .call, .call_always_tail, .call_never_tail, .call_never_inline => {1619 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
1614 const callee_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);1620 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()));
1616 },1622 },
16171623
1618 .slice_elem_val, .ptr_elem_val, .array_elem_val => {1624 .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)...@@ -1630,7 +1636,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
16301636
1631 .reduce, .reduce_optimized => {1637 .reduce, .reduce_optimized => {
1632 const operand_ty = air.typeOf(datas[@intFromEnum(inst)].reduce.operand, ip);1638 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);
1634 },1640 },
16351641
1636 .mul_add => return air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip),1642 .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)...@@ -1641,7 +1647,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
16411647
1642 .@"try", .try_cold => {1648 .@"try", .try_cold => {
1643 const err_union_ty = air.typeOf(datas[@intFromEnum(inst)].pl_op.operand, ip);1649 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);
1645 },1651 },
16461652
1647 .tlv_dllimport_ptr => return .fromInterned(datas[@intFromEnum(inst)].ty_nav.ty),1653 .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)...@@ -1649,7 +1655,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1649 .work_item_id,1655 .work_item_id,
1650 .work_group_size,1656 .work_group_size,
1651 .work_group_id,1657 .work_group_id,
1652 => return Type.u32,1658 => return .u32,
16531659
1654 .inferred_alloc => unreachable,1660 .inferred_alloc => unreachable,
1655 .inferred_alloc_comptime => unreachable,1661 .inferred_alloc_comptime => unreachable,
...@@ -1696,7 +1702,7 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {...@@ -1696,7 +1702,7 @@ pub fn internedToRef(ip_index: InternPool.Index) Inst.Ref {
1696/// Returns `null` if runtime-known.1702/// Returns `null` if runtime-known.
1697pub fn value(air: Air, inst: Inst.Ref, pt: Zcu.PerThread) !?Value {1703pub fn value(air: Air, inst: Inst.Ref, pt: Zcu.PerThread) !?Value {
1698 if (inst.toInterned()) |ip_index| {1704 if (inst.toInterned()) |ip_index| {
1699 return Value.fromInterned(ip_index);1705 return .fromInterned(ip_index);
1700 }1706 }
1701 const index = inst.toIndex().?;1707 const index = inst.toIndex().?;
1702 return air.typeOfIndex(index, &pt.zcu.intern_pool).onePossibleValue(pt);1708 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),...@@ -4,6 +4,43 @@ air_extra: std.ArrayListUnmanaged(u32),
4features: *const Features,4features: *const Features,
55
6pub const Feature = enum {6pub 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,
7 scalarize_not,44 scalarize_not,
8 scalarize_clz,45 scalarize_clz,
9 scalarize_ctz,46 scalarize_ctz,
...@@ -26,41 +63,110 @@ pub const Feature = enum {...@@ -26,41 +63,110 @@ pub const Feature = enum {
26 scalarize_trunc_float,63 scalarize_trunc_float,
27 scalarize_neg,64 scalarize_neg,
28 scalarize_neg_optimized,65 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
30 /// Legalize (shift lhs, (splat rhs)) -> (shift lhs, rhs)78 /// Legalize (shift lhs, (splat rhs)) -> (shift lhs, rhs)
31 remove_shift_vector_rhs_splat,79 remove_shift_vector_rhs_splat,
32 /// Legalize reduce of a one element vector to a bitcast80 /// Legalize reduce of a one element vector to a bitcast
33 reduce_one_elem_to_bitcast,81 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 }
34};158};
35159
36pub const Features = std.enums.EnumSet(Feature);160pub const Features = std.enums.EnumSet(Feature);
37161
38pub const Error = std.mem.Allocator.Error;162pub 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 {
41 var l: Legalize = .{165 var l: Legalize = .{
42 .pt = pt,166 .pt = pt,
43 .air_instructions = air.instructions.toMultiArrayList(),167 .air_instructions = air.instructions.toMultiArrayList(),
44 .air_extra = air.extra,168 .air_extra = air.extra,
45 .features = &features: switch (backend) {169 .features = features,
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 },
64 };170 };
65 if (l.features.bits.eql(.initEmpty())) return;171 if (l.features.bits.eql(.initEmpty())) return;
66 defer air.* = l.getTmpAir();172 defer air.* = l.getTmpAir();
...@@ -90,11 +196,93 @@ fn extraData(l: *const Legalize, comptime T: type, index: usize) @TypeOf(Air.ext...@@ -90,11 +196,93 @@ fn extraData(l: *const Legalize, comptime T: type, index: usize) @TypeOf(Air.ext
90fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {196fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
91 const zcu = l.pt.zcu;197 const zcu = l.pt.zcu;
92 const ip = &zcu.intern_pool;198 const ip = &zcu.intern_pool;
93 for (body_start..body_start + body_len) |inst_extra_index| {199 for (0..body_len) |body_index| {
94 const inst: Air.Inst.Index = @enumFromInt(l.air_extra.items[inst_extra_index]);200 const inst: Air.Inst.Index = @enumFromInt(l.air_extra.items[body_start + body_index]);
95 inst: switch (l.air_instructions.items(.tag)[@intFromEnum(inst)]) {201 inst: switch (l.air_instructions.items(.tag)[@intFromEnum(inst)]) {
96 else => {},202 .arg,
97203 => {},
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 },
98 inline .not,286 inline .not,
99 .clz,287 .clz,
100 .ctz,288 .ctz,
...@@ -102,11 +290,38 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {...@@ -102,11 +290,38 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
102 .byte_swap,290 .byte_swap,
103 .bit_reverse,291 .bit_reverse,
104 .abs,292 .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))) {
106 const ty_op = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_op;302 const ty_op = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_op;
107 if (!ty_op.ty.toType().isVector(zcu)) break :done;303 if (ty_op.ty.toType().isVector(zcu)) continue :inst try l.scalarize(inst, .ty_op);
108 continue :inst try l.scalarizeUnary(inst, .ty_op, ty_op.operand);
109 },304 },
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 => {},
110 inline .sqrt,325 inline .sqrt,
111 .sin,326 .sin,
112 .cos,327 .cos,
...@@ -122,84 +337,39 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {...@@ -122,84 +337,39 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
122 .trunc_float,337 .trunc_float,
123 .neg,338 .neg,
124 .neg_optimized,339 .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))) {
126 const un_op = l.air_instructions.items(.data)[@intFromEnum(inst)].un_op;341 const un_op = l.air_instructions.items(.data)[@intFromEnum(inst)].un_op;
127 if (!l.typeOf(un_op).isVector(zcu)) break :done;342 if (l.typeOf(un_op).isVector(zcu)) continue :inst try l.scalarize(inst, .un_op);
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 }
159 },343 },
160344 .cmp_lt,
161 .reduce,345 .cmp_lt_optimized,
162 .reduce_optimized,346 .cmp_lte,
163 => if (l.features.contains(.reduce_one_elem_to_bitcast)) done: {347 .cmp_lte_optimized,
164 const reduce = l.air_instructions.items(.data)[@intFromEnum(inst)].reduce;348 .cmp_eq,
165 const vector_ty = l.typeOf(reduce.operand);349 .cmp_eq_optimized,
166 switch (vector_ty.vectorLen(zcu)) {350 .cmp_gte,
167 0 => unreachable,351 .cmp_gte_optimized,
168 1 => continue :inst l.replaceInst(inst, .bitcast, .{ .ty_op = .{352 .cmp_gt,
169 .ty = Air.internedToRef(vector_ty.scalarType(zcu).toIntern()),353 .cmp_gt_optimized,
170 .operand = reduce.operand,354 .cmp_neq,
171 } }),355 .cmp_neq_optimized,
172 else => break :done,356 => {},
173 }357 inline .cmp_vector,
174 },358 .cmp_vector_optimized,
175359 => |air_tag| if (l.features.contains(comptime .scalarize(air_tag))) {
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 => {
182 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;360 const ty_pl = l.air_instructions.items(.data)[@intFromEnum(inst)].ty_pl;
183 const extra = l.extraData(Air.TryPtr, ty_pl.payload);361 if (ty_pl.ty.toType().isVector(zcu)) continue :inst try l.scalarize(inst, .ty_pl_vector_cmp);
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);
195 },362 },
196 .cond_br => {363 .cond_br,
364 => {
197 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;365 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
198 const extra = l.extraData(Air.CondBr, pl_op.payload);366 const extra = l.extraData(Air.CondBr, pl_op.payload);
199 try l.legalizeBody(extra.end, extra.data.then_body_len);367 try l.legalizeBody(extra.end, extra.data.then_body_len);
200 try l.legalizeBody(extra.end + extra.data.then_body_len, extra.data.else_body_len);368 try l.legalizeBody(extra.end + extra.data.then_body_len, extra.data.else_body_len);
201 },369 },
202 .switch_br, .loop_switch_br => {370 .switch_br,
371 .loop_switch_br,
372 => {
203 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;373 const pl_op = l.air_instructions.items(.data)[@intFromEnum(inst)].pl_op;
204 const extra = l.extraData(Air.SwitchBr, pl_op.payload);374 const extra = l.extraData(Air.SwitchBr, pl_op.payload);
205 const hint_bag_count = std.math.divCeil(usize, extra.data.cases_len + 1, 10) catch unreachable;375 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 {...@@ -212,154 +382,408 @@ fn legalizeBody(l: *Legalize, body_start: usize, body_len: usize) Error!void {
212 }382 }
213 try l.legalizeBody(extra_index, extra.data.else_body_len);383 try l.legalizeBody(extra_index, extra.data.else_body_len);
214 },384 },
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 => {},
215 }522 }
216 }523 }
217}524}
218525
219const UnaryDataTag = enum { un_op, ty_op };526const ScalarizeDataTag = enum { un_op, ty_op, bin_op, ty_pl_vector_cmp, pl_op_bin };
220inline fn scalarizeUnary(l: *Legalize, inst: Air.Inst.Index, data_tag: UnaryDataTag, un_op: Air.Inst.Ref) Error!Air.Inst.Tag {527inline fn scalarize(l: *Legalize, orig_inst: Air.Inst.Index, comptime data_tag: ScalarizeDataTag) Error!Air.Inst.Tag {
221 return l.replaceInst(inst, .block, try l.scalarizeUnaryBlockPayload(inst, data_tag, un_op));528 return l.replaceInst(orig_inst, .block, try l.scalarizeBlockPayload(orig_inst, data_tag));
222}529}
223fn scalarizeUnaryBlockPayload(530fn scalarizeBlockPayload(l: *Legalize, orig_inst: Air.Inst.Index, comptime data_tag: ScalarizeDataTag) Error!Air.Inst.Data {
224 l: *Legalize,
225 inst: Air.Inst.Index,
226 data_tag: UnaryDataTag,
227 un_op: Air.Inst.Ref,
228) Error!Air.Inst.Data {
229 const pt = l.pt;531 const pt = l.pt;
230 const zcu = pt.zcu;532 const zcu = pt.zcu;
231 const gpa = zcu.gpa;533 const gpa = zcu.gpa;
232534
233 const res_ty = l.typeOfIndex(inst);535 const orig = l.air_instructions.get(@intFromEnum(orig_inst));
234 try l.air_instructions.ensureUnusedCapacity(gpa, 15);536 const res_ty = l.typeOfIndex(orig_inst);
235 const res_alloc_inst = l.addInstAssumeCapacity(.{537 const arity = switch (data_tag) {
236 .tag = .alloc,538 .un_op, .ty_op => 1,
237 .data = .{ .ty = try pt.singleMutPtrType(res_ty) },539 .bin_op, .ty_pl_vector_cmp => 2,
238 });540 .pl_op_bin => 3,
239 const index_alloc_inst = l.addInstAssumeCapacity(.{541 };
240 .tag = .alloc,542 const expected_instructions_len = l.air_instructions.len + (6 + arity + 8);
241 .data = .{ .ty = try pt.singleMutPtrType(.usize) },543 try l.air_instructions.ensureTotalCapacity(gpa, expected_instructions_len);
242 });544
243 const index_init_inst = l.addInstAssumeCapacity(.{545 var res_block: Block(4) = .empty;
244 .tag = .store,546 {
245 .data = .{ .bin_op = .{547 const res_alloc_inst = res_block.add(l.addInstAssumeCapacity(.{
246 .lhs = index_alloc_inst.toRef(),548 .tag = .alloc,
247 .rhs = try pt.intRef(.usize, 0),549 .data = .{ .ty = try pt.singleMutPtrType(res_ty) },
248 } },550 }));
249 });551 const index_alloc_inst = res_block.add(l.addInstAssumeCapacity(.{
250 const cur_index_inst = l.addInstAssumeCapacity(.{552 .tag = .alloc,
251 .tag = .load,553 .data = .{ .ty = .ptr_usize },
252 .data = .{ .ty_op = .{554 }));
253 .ty = .usize_type,555 _ = res_block.add(l.addInstAssumeCapacity(.{
254 .operand = index_alloc_inst.toRef(),556 .tag = .store,
255 } },557 .data = .{ .bin_op = .{
256 });558 .lhs = index_alloc_inst.toRef(),
257 const get_elem_inst = l.addInstAssumeCapacity(.{559 .rhs = .zero_usize,
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(),
271 } },560 } },
272 },561 }));
273 });562
274 const set_elem_inst = l.addInstAssumeCapacity(.{563 const loop_inst: Air.Inst.Index = @enumFromInt(l.air_instructions.len + (3 + arity + 7));
275 .tag = .vector_store_elem,564 var loop_block: Block(3 + arity + 2) = .empty;
276 .data = .{ .vector_store_elem = .{565 {
277 .vector_ptr = res_alloc_inst.toRef(),566 const cur_index_inst = loop_block.add(l.addInstAssumeCapacity(.{
278 .payload = try l.addExtra(Air.Bin, .{567 .tag = .load,
279 .lhs = cur_index_inst.toRef(),568 .data = .{ .ty_op = .{
280 .rhs = op_elem_inst.toRef(),569 .ty = .usize_type,
281 }),570 .operand = index_alloc_inst.toRef(),
282 } },571 } },
283 });572 }));
284 const not_done_inst = l.addInstAssumeCapacity(.{573 _ = loop_block.add(l.addInstAssumeCapacity(.{
285 .tag = .cmp_lt,574 .tag = .vector_store_elem,
286 .data = .{ .bin_op = .{575 .data = .{ .vector_store_elem = .{
287 .lhs = cur_index_inst.toRef(),576 .vector_ptr = res_alloc_inst.toRef(),
288 .rhs = try pt.intRef(.usize, res_ty.vectorLen(zcu)),577 .payload = try l.addExtra(Air.Bin, .{
289 } },578 .lhs = cur_index_inst.toRef(),
290 });579 .rhs = loop_block.add(l.addInstAssumeCapacity(res_elem: switch (data_tag) {
291 const next_index_inst = l.addInstAssumeCapacity(.{580 .un_op => .{
292 .tag = .add,581 .tag = orig.tag,
293 .data = .{ .bin_op = .{582 .data = .{ .un_op = loop_block.add(l.addInstAssumeCapacity(.{
294 .lhs = cur_index_inst.toRef(),583 .tag = .array_elem_val,
295 .rhs = try pt.intRef(.usize, 1),584 .data = .{ .bin_op = .{
296 } },585 .lhs = orig.data.un_op,
297 });586 .rhs = cur_index_inst.toRef(),
298 const set_index_inst = l.addInstAssumeCapacity(.{587 } },
299 .tag = .store,588 })).toRef() },
300 .data = .{ .bin_op = .{589 },
301 .lhs = index_alloc_inst.toRef(),590 .ty_op => .{
302 .rhs = next_index_inst.toRef(),591 .tag = orig.tag,
303 } },592 .data = .{ .ty_op = .{
304 });593 .ty = Air.internedToRef(orig.data.ty_op.ty.toType().scalarType(zcu).toIntern()),
305 const loop_inst: Air.Inst.Index = @enumFromInt(l.air_instructions.len + 4);594 .operand = loop_block.add(l.addInstAssumeCapacity(.{
306 const repeat_inst = l.addInstAssumeCapacity(.{595 .tag = .array_elem_val,
307 .tag = .repeat,596 .data = .{ .bin_op = .{
308 .data = .{ .repeat = .{ .loop_inst = loop_inst } },597 .lhs = orig.data.ty_op.operand,
309 });598 .rhs = cur_index_inst.toRef(),
310 const final_res_inst = l.addInstAssumeCapacity(.{599 } },
311 .tag = .load,600 })).toRef(),
312 .data = .{ .ty_op = .{601 } },
313 .ty = Air.internedToRef(res_ty.toIntern()),602 },
314 .operand = res_alloc_inst.toRef(),603 .bin_op => .{
315 } },604 .tag = orig.tag,
316 });605 .data = .{ .bin_op = .{
317 const br_res_inst = l.addInstAssumeCapacity(.{606 .lhs = loop_block.add(l.addInstAssumeCapacity(.{
318 .tag = .br,607 .tag = .array_elem_val,
319 .data = .{ .br = .{608 .data = .{ .bin_op = .{
320 .block_inst = inst,609 .lhs = orig.data.bin_op.lhs,
321 .operand = final_res_inst.toRef(),610 .rhs = cur_index_inst.toRef(),
322 } },611 } },
323 });612 })).toRef(),
324 const done_br_inst = l.addInstAssumeCapacity(.{613 .rhs = loop_block.add(l.addInstAssumeCapacity(.{
325 .tag = .cond_br,614 .tag = .array_elem_val,
326 .data = .{ .pl_op = .{615 .data = .{ .bin_op = .{
327 .operand = not_done_inst.toRef(),616 .lhs = orig.data.bin_op.rhs,
328 .payload = try l.addCondBrBodies(&.{617 .rhs = cur_index_inst.toRef(),
329 next_index_inst,618 } },
330 set_index_inst,619 })).toRef(),
331 repeat_inst,620 } },
332 }, &.{621 },
333 final_res_inst,622 .ty_pl_vector_cmp => {
334 br_res_inst,623 const extra = l.extraData(Air.VectorCmp, orig.data.ty_pl.payload).data;
335 }),624 break :res_elem .{
336 } },625 .tag = switch (orig.tag) {
337 });626 else => unreachable,
338 assert(loop_inst == l.addInstAssumeCapacity(.{627 .cmp_vector => switch (extra.compareOperator()) {
339 .tag = .loop,628 .lt => .cmp_lt,
340 .data = .{ .ty_pl = .{629 .lte => .cmp_lte,
341 .ty = .noreturn_type,630 .eq => .cmp_eq,
342 .payload = try l.addBlockBody(&.{631 .gte => .cmp_gte,
343 cur_index_inst,632 .gt => .cmp_gt,
344 get_elem_inst,633 .neq => .cmp_neq,
345 op_elem_inst,634 },
346 set_elem_inst,635 .cmp_vector_optimized => switch (extra.compareOperator()) {
347 not_done_inst,636 .lt => .cmp_lt_optimized,
348 done_br_inst,637 .lte => .cmp_lte_optimized,
349 }),638 .eq => .cmp_eq_optimized,
350 } },639 .gte => .cmp_gte_optimized,
351 }));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);
352 return .{ .ty_pl = .{758 return .{ .ty_pl = .{
353 .ty = Air.internedToRef(res_ty.toIntern()),759 .ty = Air.internedToRef(res_ty.toIntern()),
354 .payload = try l.addBlockBody(&.{760 .payload = try l.addBlockBody(res_block.body()),
355 res_alloc_inst,
356 index_alloc_inst,
357 index_init_inst,
358 loop_inst,
359 }),
360 } };761 } };
361}762}
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
363fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {787fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {
364 defer l.air_instructions.appendAssumeCapacity(inst);788 defer l.air_instructions.appendAssumeCapacity(inst);
365 return @enumFromInt(l.air_instructions.len);789 return @enumFromInt(l.air_instructions.len);
...@@ -414,7 +838,6 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat...@@ -414,7 +838,6 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat
414838
415const Air = @import("../Air.zig");839const Air = @import("../Air.zig");
416const assert = std.debug.assert;840const assert = std.debug.assert;
417const codegen = @import("../codegen.zig");
418const Legalize = @This();841const Legalize = @This();
419const std = @import("std");842const std = @import("std");
420const Type = @import("../Type.zig");843const Type = @import("../Type.zig");
src/InternPool.zig+60-24
...@@ -4579,10 +4579,11 @@ pub const Index = enum(u32) {...@@ -4579,10 +4579,11 @@ pub const Index = enum(u32) {
4579 undefined_type,4579 undefined_type,
4580 enum_literal_type,4580 enum_literal_type,
45814581
4582 ptr_usize_type,
4583 ptr_const_comptime_int_type,
4582 manyptr_u8_type,4584 manyptr_u8_type,
4583 manyptr_const_u8_type,4585 manyptr_const_u8_type,
4584 manyptr_const_u8_sentinel_0_type,4586 manyptr_const_u8_sentinel_0_type,
4585 single_const_pointer_to_comptime_int_type,
4586 slice_const_u8_type,4587 slice_const_u8_type,
4587 slice_const_u8_sentinel_0_type,4588 slice_const_u8_sentinel_0_type,
45884589
...@@ -4649,19 +4650,29 @@ pub const Index = enum(u32) {...@@ -4649,19 +4650,29 @@ pub const Index = enum(u32) {
46494650
4650 /// `undefined` (untyped)4651 /// `undefined` (untyped)
4651 undef,4652 undef,
4653 /// `@as(bool, undefined)`
4654 undef_bool,
4655 /// `@as(usize, undefined)`
4656 undef_usize,
4657 /// `@as(u1, undefined)`
4658 undef_u1,
4652 /// `0` (comptime_int)4659 /// `0` (comptime_int)
4653 zero,4660 zero,
4654 /// `0` (usize)4661 /// `@as(usize, 0)`
4655 zero_usize,4662 zero_usize,
4656 /// `0` (u8)4663 /// `@as(u1, 0)`
4664 zero_u1,
4665 /// `@as(u8, 0)`
4657 zero_u8,4666 zero_u8,
4658 /// `1` (comptime_int)4667 /// `1` (comptime_int)
4659 one,4668 one,
4660 /// `1` (usize)4669 /// `@as(usize, 1)`
4661 one_usize,4670 one_usize,
4662 /// `1` (u8)4671 /// `@as(u1, 1)`
4672 one_u1,
4673 /// `@as(u8, 1)`
4663 one_u8,4674 one_u8,
4664 /// `4` (u8)4675 /// `@as(u8, 4)`
4665 four_u8,4676 four_u8,
4666 /// `-1` (comptime_int)4677 /// `-1` (comptime_int)
4667 negative_one,4678 negative_one,
...@@ -5074,6 +5085,20 @@ pub const static_keys: [static_len]Key = .{...@@ -5074,6 +5085,20 @@ pub const static_keys: [static_len]Key = .{
5074 .{ .simple_type = .undefined },5085 .{ .simple_type = .undefined },
5075 .{ .simple_type = .enum_literal },5086 .{ .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
5077 // [*]u85102 // [*]u8
5078 .{ .ptr_type = .{5103 .{ .ptr_type = .{
5079 .child = .u8_type,5104 .child = .u8_type,
...@@ -5101,15 +5126,6 @@ pub const static_keys: [static_len]Key = .{...@@ -5101,15 +5126,6 @@ pub const static_keys: [static_len]Key = .{
5101 },5126 },
5102 } },5127 } },
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
5113 // []const u85129 // []const u8
5114 .{ .ptr_type = .{5130 .{ .ptr_type = .{
5115 .child = .u8_type,5131 .child = .u8_type,
...@@ -5245,6 +5261,9 @@ pub const static_keys: [static_len]Key = .{...@@ -5245,6 +5261,9 @@ pub const static_keys: [static_len]Key = .{
5245 } },5261 } },
52465262
5247 .{ .simple_value = .undefined },5263 .{ .simple_value = .undefined },
5264 .{ .undef = .bool_type },
5265 .{ .undef = .usize_type },
5266 .{ .undef = .u1_type },
52485267
5249 .{ .int = .{5268 .{ .int = .{
5250 .ty = .comptime_int_type,5269 .ty = .comptime_int_type,
...@@ -5256,6 +5275,11 @@ pub const static_keys: [static_len]Key = .{...@@ -5256,6 +5275,11 @@ pub const static_keys: [static_len]Key = .{
5256 .storage = .{ .u64 = 0 },5275 .storage = .{ .u64 = 0 },
5257 } },5276 } },
52585277
5278 .{ .int = .{
5279 .ty = .u1_type,
5280 .storage = .{ .u64 = 0 },
5281 } },
5282
5259 .{ .int = .{5283 .{ .int = .{
5260 .ty = .u8_type,5284 .ty = .u8_type,
5261 .storage = .{ .u64 = 0 },5285 .storage = .{ .u64 = 0 },
...@@ -5271,17 +5295,21 @@ pub const static_keys: [static_len]Key = .{...@@ -5271,17 +5295,21 @@ pub const static_keys: [static_len]Key = .{
5271 .storage = .{ .u64 = 1 },5295 .storage = .{ .u64 = 1 },
5272 } },5296 } },
52735297
5274 // one_u85298 .{ .int = .{
5299 .ty = .u1_type,
5300 .storage = .{ .u64 = 1 },
5301 } },
5302
5275 .{ .int = .{5303 .{ .int = .{
5276 .ty = .u8_type,5304 .ty = .u8_type,
5277 .storage = .{ .u64 = 1 },5305 .storage = .{ .u64 = 1 },
5278 } },5306 } },
5279 // four_u85307
5280 .{ .int = .{5308 .{ .int = .{
5281 .ty = .u8_type,5309 .ty = .u8_type,
5282 .storage = .{ .u64 = 4 },5310 .storage = .{ .u64 = 4 },
5283 } },5311 } },
5284 // negative_one5312
5285 .{ .int = .{5313 .{ .int = .{
5286 .ty = .comptime_int_type,5314 .ty = .comptime_int_type,
5287 .storage = .{ .i64 = -1 },5315 .storage = .{ .i64 = -1 },
...@@ -10482,7 +10510,7 @@ pub fn getCoerced(...@@ -10482,7 +10510,7 @@ pub fn getCoerced(
10482 .base_addr = .int,10510 .base_addr = .int,
10483 .byte_offset = 0,10511 .byte_offset = 0,
10484 } }),10512 } }),
10485 .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),10513 .len = .undef_usize,
10486 } }),10514 } }),
10487 };10515 };
10488 },10516 },
...@@ -10601,7 +10629,7 @@ pub fn getCoerced(...@@ -10601,7 +10629,7 @@ pub fn getCoerced(
10601 .base_addr = .int,10629 .base_addr = .int,
10602 .byte_offset = 0,10630 .byte_offset = 0,
10603 } }),10631 } }),
10604 .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),10632 .len = .undef_usize,
10605 } }),10633 } }),
10606 },10634 },
10607 else => |payload| try ip.getCoerced(gpa, tid, payload, new_ty),10635 else => |payload| try ip.getCoerced(gpa, tid, payload, new_ty),
...@@ -11847,10 +11875,11 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -11847,10 +11875,11 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
11847 .null_type,11875 .null_type,
11848 .undefined_type,11876 .undefined_type,
11849 .enum_literal_type,11877 .enum_literal_type,
11878 .ptr_usize_type,
11879 .ptr_const_comptime_int_type,
11850 .manyptr_u8_type,11880 .manyptr_u8_type,
11851 .manyptr_const_u8_type,11881 .manyptr_const_u8_type,
11852 .manyptr_const_u8_sentinel_0_type,11882 .manyptr_const_u8_sentinel_0_type,
11853 .single_const_pointer_to_comptime_int_type,
11854 .slice_const_u8_type,11883 .slice_const_u8_type,
11855 .slice_const_u8_sentinel_0_type,11884 .slice_const_u8_sentinel_0_type,
11856 .vector_8_i8_type,11885 .vector_8_i8_type,
...@@ -11909,12 +11938,13 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {...@@ -11909,12 +11938,13 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
1190911938
11910 .undef => .undefined_type,11939 .undef => .undefined_type,
11911 .zero, .one, .negative_one => .comptime_int_type,11940 .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,
11913 .zero_u8, .one_u8, .four_u8 => .u8_type,11943 .zero_u8, .one_u8, .four_u8 => .u8_type,
11914 .void_value => .void_type,11944 .void_value => .void_type,
11915 .unreachable_value => .noreturn_type,11945 .unreachable_value => .noreturn_type,
11916 .null_value => .null_type,11946 .null_value => .null_type,
11917 .bool_true, .bool_false => .bool_type,11947 .undef_bool, .bool_true, .bool_false => .bool_type,
11918 .empty_tuple => .empty_tuple_type,11948 .empty_tuple => .empty_tuple_type,
1191911949
11920 // This optimization on tags is needed so that indexToKey can call11950 // 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 {...@@ -12186,10 +12216,11 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
12186 .undefined_type => .undefined,12216 .undefined_type => .undefined,
12187 .enum_literal_type => .enum_literal,12217 .enum_literal_type => .enum_literal,
1218812218
12219 .ptr_usize_type,
12220 .ptr_const_comptime_int_type,
12189 .manyptr_u8_type,12221 .manyptr_u8_type,
12190 .manyptr_const_u8_type,12222 .manyptr_const_u8_type,
12191 .manyptr_const_u8_sentinel_0_type,12223 .manyptr_const_u8_sentinel_0_type,
12192 .single_const_pointer_to_comptime_int_type,
12193 .slice_const_u8_type,12224 .slice_const_u8_type,
12194 .slice_const_u8_sentinel_0_type,12225 .slice_const_u8_sentinel_0_type,
12195 => .pointer,12226 => .pointer,
...@@ -12251,11 +12282,16 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {...@@ -12251,11 +12282,16 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
1225112282
12252 // values, not types12283 // values, not types
12253 .undef => unreachable,12284 .undef => unreachable,
12285 .undef_bool => unreachable,
12286 .undef_usize => unreachable,
12287 .undef_u1 => unreachable,
12254 .zero => unreachable,12288 .zero => unreachable,
12255 .zero_usize => unreachable,12289 .zero_usize => unreachable,
12290 .zero_u1 => unreachable,
12256 .zero_u8 => unreachable,12291 .zero_u8 => unreachable,
12257 .one => unreachable,12292 .one => unreachable,
12258 .one_usize => unreachable,12293 .one_usize => unreachable,
12294 .one_u1 => unreachable,
12259 .one_u8 => unreachable,12295 .one_u8 => unreachable,
12260 .four_u8 => unreachable,12296 .four_u8 => unreachable,
12261 .negative_one => unreachable,12297 .negative_one => unreachable,
src/Sema.zig+372-382
...@@ -1881,7 +1881,7 @@ fn analyzeBodyInner(...@@ -1881,7 +1881,7 @@ fn analyzeBodyInner(
1881 extra.data.else_body_len,1881 extra.data.else_body_len,
1882 );1882 );
1883 const uncasted_cond = try sema.resolveInst(extra.data.condition);1883 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);
1885 const cond_val = try sema.resolveConstDefinedValue(1885 const cond_val = try sema.resolveConstDefinedValue(
1886 block,1886 block,
1887 cond_src,1887 cond_src,
...@@ -2012,7 +2012,7 @@ fn resolveConstBool(...@@ -2012,7 +2012,7 @@ fn resolveConstBool(
2012 reason: ComptimeReason,2012 reason: ComptimeReason,
2013) !bool {2013) !bool {
2014 const air_inst = try sema.resolveInst(zir_ref);2014 const air_inst = try sema.resolveInst(zir_ref);
2015 const wanted_type = Type.bool;2015 const wanted_type: Type = .bool;
2016 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);2016 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
2017 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);2017 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
2018 return val.toBool();2018 return val.toBool();
...@@ -2037,7 +2037,7 @@ pub fn toConstString(...@@ -2037,7 +2037,7 @@ pub fn toConstString(
2037 reason: ComptimeReason,2037 reason: ComptimeReason,
2038) ![]u8 {2038) ![]u8 {
2039 const pt = sema.pt;2039 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);
2041 const slice_val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);2041 const slice_val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
2042 const arr_val = try sema.derefSliceAsArray(block, src, slice_val, reason);2042 const arr_val = try sema.derefSliceAsArray(block, src, slice_val, reason);
2043 return arr_val.toAllocatedBytes(arr_val.typeOf(pt.zcu), sema.arena, pt);2043 return arr_val.toAllocatedBytes(arr_val.typeOf(pt.zcu), sema.arena, pt);
...@@ -2051,7 +2051,7 @@ pub fn resolveConstStringIntern(...@@ -2051,7 +2051,7 @@ pub fn resolveConstStringIntern(
2051 reason: ComptimeReason,2051 reason: ComptimeReason,
2052) !InternPool.NullTerminatedString {2052) !InternPool.NullTerminatedString {
2053 const air_inst = try sema.resolveInst(zir_ref);2053 const air_inst = try sema.resolveInst(zir_ref);
2054 const wanted_type = Type.slice_const_u8;2054 const wanted_type: Type = .slice_const_u8;
2055 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);2055 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
2056 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);2056 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
2057 return sema.sliceToIpString(block, src, val, reason);2057 return sema.sliceToIpString(block, src, val, reason);
...@@ -2180,7 +2180,7 @@ fn analyzeAsType(...@@ -2180,7 +2180,7 @@ fn analyzeAsType(
2180 src: LazySrcLoc,2180 src: LazySrcLoc,
2181 air_inst: Air.Inst.Ref,2181 air_inst: Air.Inst.Ref,
2182) !Type {2182) !Type {
2183 const wanted_type = Type.type;2183 const wanted_type: Type = .type;
2184 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);2184 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
2185 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{ .simple = .type });2185 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{ .simple = .type });
2186 return val.toType();2186 return val.toType();
...@@ -2641,7 +2641,7 @@ fn reparentOwnedErrorMsg(...@@ -2641,7 +2641,7 @@ fn reparentOwnedErrorMsg(
2641 msg.msg = msg_str;2641 msg.msg = msg_str;
2642}2642}
26432643
2644const align_ty = Type.u29;2644const align_ty: Type = .u29;
26452645
2646pub fn analyzeAsAlign(2646pub fn analyzeAsAlign(
2647 sema: *Sema,2647 sema: *Sema,
...@@ -2819,7 +2819,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2819,7 +2819,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2819 const pt = sema.pt;2819 const pt = sema.pt;
2820 const zcu = pt.zcu;2820 const zcu = pt.zcu;
2821 const ip = &zcu.intern_pool;2821 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);
2823 const parent_captures: InternPool.CaptureValue.Slice = parent_ty.getCaptures(zcu);2823 const parent_captures: InternPool.CaptureValue.Slice = parent_ty.getCaptures(zcu);
28242824
2825 const captures = try sema.arena.alloc(InternPool.CaptureValue, captures_len);2825 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...@@ -3777,7 +3777,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3777 const alloc = try sema.resolveInst(inst_data.operand);3777 const alloc = try sema.resolveInst(inst_data.operand);
3778 const alloc_ty = sema.typeOf(alloc);3778 const alloc_ty = sema.typeOf(alloc);
3779 const ptr_info = alloc_ty.ptrInfo(zcu);3779 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
3782 // If the alloc was created in a comptime scope, we already created a comptime alloc for it.3782 // If the alloc was created in a comptime scope, we already created a comptime alloc for it.
3783 // However, if the final constructed value does not reference comptime-mutable memory, we wish3783 // 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,...@@ -3848,7 +3848,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
38483848
3849 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);3849 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);
3850 const ptr_info = alloc_ty.ptrInfo(zcu);3850 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
3853 const alloc_inst = alloc.toIndex() orelse return null;3853 const alloc_inst = alloc.toIndex() orelse return null;
3854 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;3854 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,...@@ -4024,9 +4024,9 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4024 // As this is a union field, we must store to the pointer now to set the tag.4024 // As this is a union field, we must store to the pointer now to set the tag.
4025 // If the payload is OPV, there will not be a payload store, so we store that value.4025 // If the payload is OPV, there will not be a payload store, so we store that value.
4026 // Otherwise, there will be a payload store to process later, so undef will suffice.4026 // 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]);
4028 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try pt.undefValue(payload_ty);4028 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);
4030 const store_val = try pt.unionValue(maybe_union_ty, tag_val, payload_val);4030 const store_val = try pt.unionValue(maybe_union_ty, tag_val, payload_val);
4031 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);4031 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
4032 }4032 }
...@@ -4050,7 +4050,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4050,7 +4050,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4050 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;4050 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
4051 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;4051 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
4052 const new_ptr = ptr_mapping.get(air_ptr_inst).?;4052 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())));
4054 },4054 },
4055 else => unreachable,4055 else => unreachable,
4056 }4056 }
...@@ -4284,7 +4284,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4284,7 +4284,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4284 else => unreachable,4284 else => unreachable,
4285 };4285 };
4286 if (zcu.intern_pool.isFuncBody(val)) {4286 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));
4288 if (try ty.fnHasRuntimeBitsSema(pt)) {4288 if (try ty.fnHasRuntimeBitsSema(pt)) {
4289 try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = val }));4289 try sema.addReferenceEntry(block, src, AnalUnit.wrap(.{ .func = val }));
4290 try zcu.ensureFuncBodyAnalysisQueued(val);4290 try zcu.ensureFuncBodyAnalysisQueued(val);
...@@ -4447,14 +4447,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4447,14 +4447,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4447 const range_end = try sema.resolveInst(zir_arg_pair[1]);4447 const range_end = try sema.resolveInst(zir_arg_pair[1]);
4448 break :l try sema.analyzeArithmetic(block, .sub, range_end, range_start, arg_src, arg_src, arg_src, true);4448 break :l try sema.analyzeArithmetic(block, .sub, range_end, range_start, arg_src, arg_src, arg_src, true);
4449 };4449 };
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);
4451 if (len == .none) {4451 if (len == .none) {
4452 len = arg_len;4452 len = arg_len;
4453 len_idx = i;4453 len_idx = i;
4454 }4454 }
4455 if (try sema.resolveDefinedValue(block, src, arg_len)) |arg_val| {4455 if (try sema.resolveDefinedValue(block, src, arg_len)) |arg_val| {
4456 if (len_val) |v| {4456 if (len_val) |v| {
4457 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {4457 if (!(try sema.valuesEqual(arg_val, v, .usize))) {
4458 const msg = msg: {4458 const msg = msg: {
4459 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});4459 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});
4460 errdefer msg.destroy(gpa);4460 errdefer msg.destroy(gpa);
...@@ -5343,7 +5343,7 @@ fn zirValidatePtrArrayInit(...@@ -5343,7 +5343,7 @@ fn zirValidatePtrArrayInit(
5343 // sentinel-terminated array, the sentinel will not have been populated by5343 // sentinel-terminated array, the sentinel will not have been populated by
5344 // any ZIR instructions at comptime; we need to do that here.5344 // any ZIR instructions at comptime; we need to do that here.
5345 if (array_ty.sentinel(zcu)) |sentinel_val| {5345 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);
5347 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);5347 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);
5348 const sentinel = Air.internedToRef(sentinel_val.toIntern());5348 const sentinel = Air.internedToRef(sentinel_val.toIntern());
5349 try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store);5349 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...@@ -5828,7 +5828,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
5828 defer tracy.end();5828 defer tracy.end();
58295829
5830 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].int;5830 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);
5832}5832}
58335833
5834fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5834fn 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....@@ -5846,7 +5846,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
5846 const limbs = try sema.arena.alloc(std.math.big.Limb, int.len);5846 const limbs = try sema.arena.alloc(std.math.big.Limb, int.len);
5847 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);5847 @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, .{
5850 .limbs = limbs,5850 .limbs = limbs,
5851 .positive = true,5851 .positive = true,
5852 })).toIntern());5852 })).toIntern());
...@@ -5856,7 +5856,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -5856,7 +5856,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
5856 _ = block;5856 _ = block;
5857 const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float;5857 const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float;
5858 return Air.internedToRef((try sema.pt.floatValue(5858 return Air.internedToRef((try sema.pt.floatValue(
5859 Type.comptime_float,5859 .comptime_float,
5860 number,5860 number,
5861 )).toIntern());5861 )).toIntern());
5862}5862}
...@@ -5866,7 +5866,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -5866,7 +5866,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
5866 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5866 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5867 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;5867 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
5868 const number = extra.get();5868 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());
5870}5870}
58715871
5872fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5872fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -6641,7 +6641,7 @@ pub fn analyzeExport(...@@ -6641,7 +6641,7 @@ pub fn analyzeExport(
6641 };6641 };
66426642
6643 const exported_nav = ip.getNav(exported_nav_index);6643 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
6646 if (!try sema.validateExternType(export_ty, .other)) {6646 if (!try sema.validateExternType(export_ty, .other)) {
6647 return sema.failWithOwnedErrorMsg(block, msg: {6647 return sema.failWithOwnedErrorMsg(block, msg: {
...@@ -7005,7 +7005,7 @@ fn lookupInNamespace(...@@ -7005,7 +7005,7 @@ fn lookupInNamespace(
70057005
7006 for (usingnamespaces.items) |sub_ns_nav| {7006 for (usingnamespaces.items) |sub_ns_nav| {
7007 try sema.ensureNavResolved(block, src, sub_ns_nav, .fully);7007 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);
7009 const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu));7009 const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu));
7010 try checked_namespaces.put(gpa, sub_ns, {});7010 try checked_namespaces.put(gpa, sub_ns, {});
7011 }7011 }
...@@ -7081,7 +7081,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -7081,7 +7081,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
7081 const gpa = sema.gpa;7081 const gpa = sema.gpa;
70827082
7083 if (block.isComptime() or block.is_typeof) {7083 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);
7085 return Air.internedToRef(index_val.toIntern());7085 return Air.internedToRef(index_val.toIntern());
7086 }7086 }
70877087
...@@ -7326,13 +7326,13 @@ fn checkCallArgumentCount(...@@ -7326,13 +7326,13 @@ fn checkCallArgumentCount(
7326) !Type {7326) !Type {
7327 const pt = sema.pt;7327 const pt = sema.pt;
7328 const zcu = pt.zcu;7328 const zcu = pt.zcu;
7329 const func_ty = func_ty: {7329 const func_ty: Type = func_ty: {
7330 switch (callee_ty.zigTypeTag(zcu)) {7330 switch (callee_ty.zigTypeTag(zcu)) {
7331 .@"fn" => break :func_ty callee_ty,7331 .@"fn" => break :func_ty callee_ty,
7332 .pointer => {7332 .pointer => {
7333 const ptr_info = callee_ty.ptrInfo(zcu);7333 const ptr_info = callee_ty.ptrInfo(zcu);
7334 if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") {7334 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);
7336 }7336 }
7337 },7337 },
7338 .optional => {7338 .optional => {
...@@ -7405,13 +7405,13 @@ fn callBuiltin(...@@ -7405,13 +7405,13 @@ fn callBuiltin(
7405 const pt = sema.pt;7405 const pt = sema.pt;
7406 const zcu = pt.zcu;7406 const zcu = pt.zcu;
7407 const callee_ty = sema.typeOf(builtin_fn);7407 const callee_ty = sema.typeOf(builtin_fn);
7408 const func_ty = func_ty: {7408 const func_ty: Type = func_ty: {
7409 switch (callee_ty.zigTypeTag(zcu)) {7409 switch (callee_ty.zigTypeTag(zcu)) {
7410 .@"fn" => break :func_ty callee_ty,7410 .@"fn" => break :func_ty callee_ty,
7411 .pointer => {7411 .pointer => {
7412 const ptr_info = callee_ty.ptrInfo(zcu);7412 const ptr_info = callee_ty.ptrInfo(zcu);
7413 if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") {7413 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);
7415 }7415 }
7416 },7416 },
7417 else => {},7417 else => {},
...@@ -7568,7 +7568,7 @@ const CallArgsInfo = union(enum) {...@@ -7568,7 +7568,7 @@ const CallArgsInfo = union(enum) {
7568 }7568 }
7569 }7569 }
7570 // Give the arg its result type7570 // 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;
7572 sema.inst_map.putAssumeCapacity(zir_call.call_inst, Air.internedToRef(provide_param_ty.toIntern()));7572 sema.inst_map.putAssumeCapacity(zir_call.call_inst, Air.internedToRef(provide_param_ty.toIntern()));
7573 // Resolve the arg!7573 // Resolve the arg!
7574 const uncoerced_arg = try sema.resolveInlineBody(block, arg_body, zir_call.call_inst);7574 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...@@ -8353,7 +8353,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
8353 @tagName(backend), @tagName(target.cpu.arch),8353 @tagName(backend), @tagName(target.cpu.arch),
8354 });8354 });
8355 }8355 }
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);
8357 if (owner_func_ty.toIntern() != func_ty.toIntern()) {8357 if (owner_func_ty.toIntern() != func_ty.toIntern()) {
8358 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{8358 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
8359 func_ty.fmt(pt), owner_func_ty.fmt(pt),8359 func_ty.fmt(pt), owner_func_ty.fmt(pt),
...@@ -8452,7 +8452,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -8452,7 +8452,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
8452 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);8452 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8453 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);8453 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
8454 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8454 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 }));
8456 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);8456 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
8457 try sema.checkVectorElemType(block, elem_type_src, elem_type);8457 try sema.checkVectorElemType(block, elem_type_src, elem_type);
8458 const vector_type = try sema.pt.vectorType(.{8458 const vector_type = try sema.pt.vectorType(.{
...@@ -8470,7 +8470,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -8470,7 +8470,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8470 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8470 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8471 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });8471 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8472 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });8472 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 });
8474 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);8474 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);
8475 try sema.validateArrayElemType(block, elem_type, elem_src);8475 try sema.validateArrayElemType(block, elem_type, elem_src);
8476 const array_ty = try sema.pt.arrayType(.{8476 const array_ty = try sema.pt.arrayType(.{
...@@ -8490,7 +8490,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -8490,7 +8490,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
8490 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });8490 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8491 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });8491 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
8492 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });8492 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 });
8494 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);8494 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
8495 try sema.validateArrayElemType(block, elem_type, elem_src);8495 try sema.validateArrayElemType(block, elem_type, elem_src);
8496 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);8496 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
...@@ -8599,7 +8599,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8599,7 +8599,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8599 const src = block.nodeOffset(extra.node);8599 const src = block.nodeOffset(extra.node);
8600 const operand_src = block.builtinCallArgSrc(extra.node, 0);8600 const operand_src = block.builtinCallArgSrc(extra.node, 0);
8601 const uncasted_operand = try sema.resolveInst(extra.operand);8601 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);
8603 const err_int_ty = try pt.errorIntType();8603 const err_int_ty = try pt.errorIntType();
86048604
8605 if (try sema.resolveValue(operand)) |val| {8605 if (try sema.resolveValue(operand)) |val| {
...@@ -9309,7 +9309,7 @@ fn zirFunc(...@@ -9309,7 +9309,7 @@ fn zirFunc(
9309 const ret_ty: Type = if (extra.data.ret_ty.is_generic)9309 const ret_ty: Type = if (extra.data.ret_ty.is_generic)
9310 .generic_poison9310 .generic_poison
9311 else switch (extra.data.ret_ty.body_len) {9311 else switch (extra.data.ret_ty.body_len) {
9312 0 => Type.void,9312 0 => .void,
9313 1 => blk: {9313 1 => blk: {
9314 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);9314 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
9315 extra_index += 1;9315 extra_index += 1;
...@@ -9319,7 +9319,7 @@ fn zirFunc(...@@ -9319,7 +9319,7 @@ fn zirFunc(
9319 const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_ty.body_len);9319 const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_ty.body_len);
9320 extra_index += ret_ty_body.len;9320 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 });
9323 break :blk ret_ty_val.toType();9323 break :blk ret_ty_val.toType();
9324 },9324 },
9325 };9325 };
...@@ -9649,7 +9649,7 @@ fn funcCommon(...@@ -9649,7 +9649,7 @@ fn funcCommon(
96499649
9650 var comptime_bits: u32 = 0;9650 var comptime_bits: u32 = 0;
9651 for (block.params.items(.ty), block.params.items(.is_comptime), 0..) |param_ty_ip, param_is_comptime, i| {9651 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);
9653 const is_noalias = blk: {9653 const is_noalias = blk: {
9654 const index = std.math.cast(u5, i) orelse break :blk false;9654 const index = std.math.cast(u5, i) orelse break :blk false;
9655 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;9655 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
...@@ -9870,7 +9870,7 @@ fn finishFunc(...@@ -9870,7 +9870,7 @@ fn finishFunc(
9870 const return_type: Type = if (opt_func_index == .none or ret_poison)9870 const return_type: Type = if (opt_func_index == .none or ret_poison)
9871 bare_return_type9871 bare_return_type
9872 else9872 else
9873 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));9873 .fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
98749874
9875 if (!return_type.isValidReturnType(zcu)) {9875 if (!return_type.isValidReturnType(zcu)) {
9876 const opaque_str = if (return_type.zigTypeTag(zcu) == .@"opaque") "opaque " else "";9876 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!...@@ -10130,14 +10130,14 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10130 if (try sema.resolveValue(operand)) |operand_val| ct: {10130 if (try sema.resolveValue(operand)) |operand_val| ct: {
10131 if (!is_vector) {10131 if (!is_vector) {
10132 if (operand_val.isUndef(zcu)) {10132 if (operand_val.isUndef(zcu)) {
10133 return Air.internedToRef((try pt.undefValue(Type.usize)).toIntern());10133 return .undef_usize;
10134 }10134 }
10135 const addr = try operand_val.getUnsignedIntSema(pt) orelse {10135 const addr = try operand_val.getUnsignedIntSema(pt) orelse {
10136 // Wasn't an integer pointer. This is a runtime operation.10136 // Wasn't an integer pointer. This is a runtime operation.
10137 break :ct;10137 break :ct;
10138 };10138 };
10139 return Air.internedToRef((try pt.intValue(10139 return Air.internedToRef((try pt.intValue(
10140 Type.usize,10140 .usize,
10141 addr,10141 addr,
10142 )).toIntern());10142 )).toIntern());
10143 }10143 }
...@@ -10145,7 +10145,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10145,7 +10145,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10145 for (new_elems, 0..) |*new_elem, i| {10145 for (new_elems, 0..) |*new_elem, i| {
10146 const ptr_val = try operand_val.elemValue(pt, i);10146 const ptr_val = try operand_val.elemValue(pt, i);
10147 if (ptr_val.isUndef(zcu)) {10147 if (ptr_val.isUndef(zcu)) {
10148 new_elem.* = (try pt.undefValue(Type.usize)).toIntern();10148 new_elem.* = .undef_usize;
10149 continue;10149 continue;
10150 }10150 }
10151 const addr = try ptr_val.getUnsignedIntSema(pt) orelse {10151 const addr = try ptr_val.getUnsignedIntSema(pt) orelse {
...@@ -10153,7 +10153,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10153,7 +10153,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10153 break :ct;10153 break :ct;
10154 };10154 };
10155 new_elem.* = (try pt.intValue(10155 new_elem.* = (try pt.intValue(
10156 Type.usize,10156 .usize,
10157 addr,10157 addr,
10158 )).toIntern();10158 )).toIntern();
10159 }10159 }
...@@ -10170,7 +10170,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10170,7 +10170,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10170 }10170 }
10171 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);10171 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
10172 for (new_elems, 0..) |*new_elem, i| {10172 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);
10174 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);10174 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
10175 new_elem.* = try block.addBitCast(.usize, old_elem);10175 new_elem.* = try block.addBitCast(.usize, old_elem);
10176 }10176 }
...@@ -10646,7 +10646,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -10646,7 +10646,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10646 const vec_len = operand_ty.vectorLen(zcu);10646 const vec_len = operand_ty.vectorLen(zcu);
10647 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);10647 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);
10648 for (new_elems, 0..) |*new_elem, i| {10648 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);
10650 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);10650 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
10651 new_elem.* = try block.addTyOp(.fptrunc, dest_scalar_ty, old_elem);10651 new_elem.* = try block.addTyOp(.fptrunc, dest_scalar_ty, old_elem);
10652 }10652 }
...@@ -10675,7 +10675,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10675,7 +10675,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10675 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10675 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10676 const array = try sema.resolveInst(extra.lhs);10676 const array = try sema.resolveInst(extra.lhs);
10677 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10677 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);
10679 return sema.elemVal(block, src, array, elem_index, elem_index_src, true);10679 return sema.elemVal(block, src, array, elem_index, elem_index_src, true);
10680}10680}
1068110681
...@@ -10685,7 +10685,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10685,7 +10685,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1068510685
10686 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;10686 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
10687 const array = try sema.resolveInst(inst_data.operand);10687 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);
10689 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);10689 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);
10690}10690}
1069110691
...@@ -10728,7 +10728,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10728,7 +10728,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10728 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10728 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10729 const array_ptr = try sema.resolveInst(extra.lhs);10729 const array_ptr = try sema.resolveInst(extra.lhs);
10730 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10730 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);
10732 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, true);10732 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, true);
10733}10733}
1073410734
...@@ -10742,7 +10742,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -10742,7 +10742,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
10742 const src = block.nodeOffset(inst_data.src_node);10742 const src = block.nodeOffset(inst_data.src_node);
10743 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;10743 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
10744 const array_ptr = try sema.resolveInst(extra.ptr);10744 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);
10746 const array_ty = sema.typeOf(array_ptr).childType(zcu);10746 const array_ty = sema.typeOf(array_ptr).childType(zcu);
10747 switch (array_ty.zigTypeTag(zcu)) {10747 switch (array_ty.zigTypeTag(zcu)) {
10748 .array, .vector => {},10748 .array, .vector => {},
...@@ -11104,7 +11104,7 @@ const SwitchProngAnalysis = struct {...@@ -11104,7 +11104,7 @@ const SwitchProngAnalysis = struct {
11104 if (operand_ty.zigTypeTag(zcu) == .@"union") {11104 if (operand_ty.zigTypeTag(zcu) == .@"union") {
11105 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);11105 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
11106 const union_obj = zcu.typeToUnion(operand_ty).?;11106 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]);
11108 if (capture_byref) {11108 if (capture_byref) {
11109 const ptr_field_ty = try pt.ptrTypeSema(.{11109 const ptr_field_ty = try pt.ptrTypeSema(.{
11110 .child = field_ty.toIntern(),11110 .child = field_ty.toIntern(),
...@@ -11154,7 +11154,7 @@ const SwitchProngAnalysis = struct {...@@ -11154,7 +11154,7 @@ const SwitchProngAnalysis = struct {
11154 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;11154 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1115511155
11156 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;11156 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
11159 const field_indices = try sema.arena.alloc(u32, case_vals.len);11159 const field_indices = try sema.arena.alloc(u32, case_vals.len);
11160 for (case_vals, field_indices) |item, *field_idx| {11160 for (case_vals, field_indices) |item, *field_idx| {
...@@ -11165,7 +11165,7 @@ const SwitchProngAnalysis = struct {...@@ -11165,7 +11165,7 @@ const SwitchProngAnalysis = struct {
11165 // Fast path: if all the operands are the same type already, we don't need to hit11165 // Fast path: if all the operands are the same type already, we don't need to hit
11166 // PTR! This will also allow us to emit simpler code.11166 // PTR! This will also allow us to emit simpler code.
11167 const same_types = for (field_indices[1..]) |field_idx| {11167 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]);
11169 if (!field_ty.eql(first_field_ty, zcu)) break false;11169 if (!field_ty.eql(first_field_ty, zcu)) break false;
11170 } else true;11170 } else true;
1117111171
...@@ -11173,7 +11173,7 @@ const SwitchProngAnalysis = struct {...@@ -11173,7 +11173,7 @@ const SwitchProngAnalysis = struct {
11173 // We need values to run PTR on, so make a bunch of undef constants.11173 // We need values to run PTR on, so make a bunch of undef constants.
11174 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);11174 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
11175 for (dummy_captures, field_indices) |*dummy, field_idx| {11175 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]);
11177 dummy.* = try pt.undefRef(field_ty);11177 dummy.* = try pt.undefRef(field_ty);
11178 }11178 }
1117911179
...@@ -11208,7 +11208,7 @@ const SwitchProngAnalysis = struct {...@@ -11208,7 +11208,7 @@ const SwitchProngAnalysis = struct {
11208 // We need values to run PTR on, so make a bunch of undef constants.11208 // We need values to run PTR on, so make a bunch of undef constants.
11209 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);11209 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
11210 for (field_indices, dummy_captures) |field_idx, *dummy| {11210 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]);
11212 const field_ptr_ty = try pt.ptrTypeSema(.{11212 const field_ptr_ty = try pt.ptrTypeSema(.{
11213 .child = field_ty.toIntern(),11213 .child = field_ty.toIntern(),
11214 .flags = .{11214 .flags = .{
...@@ -11271,7 +11271,7 @@ const SwitchProngAnalysis = struct {...@@ -11271,7 +11271,7 @@ const SwitchProngAnalysis = struct {
11271 // If we can, try to avoid that using in-memory coercions.11271 // If we can, try to avoid that using in-memory coercions.
11272 const first_non_imc = in_mem: {11272 const first_non_imc = in_mem: {
11273 for (field_indices, 0..) |field_idx, i| {11273 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]);
11275 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {11275 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {
11276 break :in_mem i;11276 break :in_mem i;
11277 }11277 }
...@@ -11294,7 +11294,7 @@ const SwitchProngAnalysis = struct {...@@ -11294,7 +11294,7 @@ const SwitchProngAnalysis = struct {
11294 {11294 {
11295 const next = first_non_imc + 1;11295 const next = first_non_imc + 1;
11296 for (field_indices[next..], next..) |field_idx, i| {11296 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]);
11298 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {11298 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded, null)) {
11299 in_mem_coercible.unset(i);11299 in_mem_coercible.unset(i);
11300 }11300 }
...@@ -11341,7 +11341,7 @@ const SwitchProngAnalysis = struct {...@@ -11341,7 +11341,7 @@ const SwitchProngAnalysis = struct {
11341 };11341 };
1134211342
11343 const field_idx = field_indices[idx];11343 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]);
11345 const uncoerced = try coerce_block.addStructFieldVal(operand_val, field_idx, field_ty);11345 const uncoerced = try coerce_block.addStructFieldVal(operand_val, field_idx, field_ty);
11346 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);11346 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
11347 _ = try coerce_block.addBr(capture_block_inst, coerced);11347 _ = try coerce_block.addBr(capture_block_inst, coerced);
...@@ -11365,7 +11365,7 @@ const SwitchProngAnalysis = struct {...@@ -11365,7 +11365,7 @@ const SwitchProngAnalysis = struct {
1136511365
11366 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;11366 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;
11367 const first_imc_field_idx = field_indices[first_imc_item_idx];11367 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]);
11369 const uncoerced = try coerce_block.addStructFieldVal(operand_val, first_imc_field_idx, first_imc_field_ty);11369 const uncoerced = try coerce_block.addStructFieldVal(operand_val, first_imc_field_idx, first_imc_field_ty);
11370 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);11370 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
11371 _ = try coerce_block.addBr(capture_block_inst, coerced);11371 _ = try coerce_block.addBr(capture_block_inst, coerced);
...@@ -13165,7 +13165,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -13165,7 +13165,7 @@ fn analyzeSwitchRuntimeBlock(
13165 for (seen_enum_fields, 0..) |seen_field, index| {13165 for (seen_enum_fields, 0..) |seen_field, index| {
13166 if (seen_field != null) continue;13166 if (seen_field != null) continue;
13167 const union_obj = zcu.typeToUnion(maybe_union_ty).?;13167 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]);
13169 if (field_ty.zigTypeTag(zcu) != .noreturn) break true;13169 if (field_ty.zigTypeTag(zcu) != .noreturn) break true;
13170 } else false13170 } else false
13171 else13171 else
...@@ -13490,7 +13490,7 @@ const RangeSetUnhandledIterator = struct {...@@ -13490,7 +13490,7 @@ const RangeSetUnhandledIterator = struct {
13490 inline .u64, .i64 => |val_int| {13490 inline .u64, .i64 => |val_int| {
13491 const next_int = @addWithOverflow(val_int, 1);13491 const next_int = @addWithOverflow(val_int, 1);
13492 if (next_int[1] == 0)13492 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();
13494 },13494 },
13495 .big_int => {},13495 .big_int => {},
13496 .lazy_align, .lazy_size => unreachable,13496 .lazy_align, .lazy_size => unreachable,
...@@ -13506,7 +13506,7 @@ const RangeSetUnhandledIterator = struct {...@@ -13506,7 +13506,7 @@ const RangeSetUnhandledIterator = struct {
13506 );13506 );
1350713507
13508 result_bigint.addScalar(val_bigint, 1);13508 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();
13510 }13510 }
1351113511
13512 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {13512 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {
...@@ -13636,7 +13636,7 @@ fn validateErrSetSwitch(...@@ -13636,7 +13636,7 @@ fn validateErrSetSwitch(
13636 .{},13636 .{},
13637 );13637 );
13638 }13638 }
13639 return Type.anyerror;13639 return .anyerror;
13640 },13640 },
13641 else => |err_set_ty_index| else_validation: {13641 else => |err_set_ty_index| else_validation: {
13642 const error_names = ip.indexToKey(err_set_ty_index).error_set_type.names;13642 const error_names = ip.indexToKey(err_set_ty_index).error_set_type.names;
...@@ -13839,7 +13839,7 @@ fn validateSwitchItemBool(...@@ -13839,7 +13839,7 @@ fn validateSwitchItemBool(
13839 item_ref: Zir.Inst.Ref,13839 item_ref: Zir.Inst.Ref,
13840 item_src: LazySrcLoc,13840 item_src: LazySrcLoc,
13841) CompileError!Air.Inst.Ref {13841) 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);
13843 if (Value.fromInterned(item.val).toBool()) {13843 if (Value.fromInterned(item.val).toBool()) {
13844 true_count.* += 1;13844 true_count.* += 1;
13845 } else {13845 } else {
...@@ -14224,7 +14224,7 @@ fn zirShl(...@@ -14224,7 +14224,7 @@ fn zirShl(
14224 return lhs;14224 return lhs;
14225 }14225 }
14226 if (air_tag != .shl_sat and scalar_ty.zigTypeTag(zcu) != .comptime_int) {14226 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);
14228 if (rhs_ty.zigTypeTag(zcu) == .vector) {14228 if (rhs_ty.zigTypeTag(zcu) == .vector) {
14229 var i: usize = 0;14229 var i: usize = 0;
14230 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {14230 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
...@@ -14351,8 +14351,7 @@ fn zirShl(...@@ -14351,8 +14351,7 @@ fn zirShl(
14351 try block.addReduce(ov_bit, .Or)14351 try block.addReduce(ov_bit, .Or)
14352 else14352 else
14353 ov_bit;14353 ov_bit;
14354 const zero_ov = Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());14354 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, .zero_u1);
14355 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov);
1435614355
14357 try sema.addSafetyCheck(block, src, no_ov, .shl_overflow);14356 try sema.addSafetyCheck(block, src, no_ov, .shl_overflow);
14358 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);14357 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);
...@@ -14406,7 +14405,7 @@ fn zirShr(...@@ -14406,7 +14405,7 @@ fn zirShr(
14406 return lhs;14405 return lhs;
14407 }14406 }
14408 if (scalar_ty.zigTypeTag(zcu) != .comptime_int) {14407 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);
14410 if (rhs_ty.zigTypeTag(zcu) == .vector) {14409 if (rhs_ty.zigTypeTag(zcu) == .vector) {
14411 var i: usize = 0;14410 var i: usize = 0;
14412 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {14411 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
...@@ -14689,7 +14688,7 @@ fn analyzeTupleCat(...@@ -14689,7 +14688,7 @@ fn analyzeTupleCat(
14689 try sema.tupleFieldValByIndex(block, rhs, i, rhs_ty);14688 try sema.tupleFieldValByIndex(block, rhs, i, rhs_ty);
14690 }14689 }
1469114690
14692 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);14691 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
14693}14692}
1469414693
14695fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {14694fn 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...@@ -14716,7 +14715,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14716 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });14715 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1471714716
14718 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {14717 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;
14720 return sema.fail(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});14719 return sema.fail(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});
14721 };14720 };
14722 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {14721 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...@@ -14892,7 +14891,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1489214891
14893 // lhs_dest_slice = dest[0..lhs.len]14892 // lhs_dest_slice = dest[0..lhs.len]
14894 const slice_ty_ref = Air.internedToRef(slice_ty.toIntern());14893 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);
14896 const lhs_dest_slice = try block.addInst(.{14895 const lhs_dest_slice = try block.addInst(.{
14897 .tag = .slice,14896 .tag = .slice,
14898 .data = .{ .ty_pl = .{14897 .data = .{ .ty_pl = .{
...@@ -14907,7 +14906,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14907,7 +14906,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14907 _ = try block.addBinOp(.memcpy, lhs_dest_slice, lhs);14906 _ = try block.addBinOp(.memcpy, lhs_dest_slice, lhs);
1490814907
14909 // rhs_dest_slice = dest[lhs.len..][0..rhs.len]14908 // 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);
14911 const rhs_dest_offset = try block.addInst(.{14910 const rhs_dest_offset = try block.addInst(.{
14912 .tag = .ptr_add,14911 .tag = .ptr_add,
14913 .data = .{ .ty_pl = .{14912 .data = .{ .ty_pl = .{
...@@ -14932,7 +14931,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14932,7 +14931,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14932 _ = try block.addBinOp(.memcpy, rhs_dest_slice, rhs);14931 _ = try block.addBinOp(.memcpy, rhs_dest_slice, rhs);
1493314932
14934 if (res_sent_val) |sent_val| {14933 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);
14936 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);14935 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
14937 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());14936 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());
14938 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);14937 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...@@ -14943,7 +14942,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1494314942
14944 var elem_i: u32 = 0;14943 var elem_i: u32 = 0;
14945 while (elem_i < lhs_len) : (elem_i += 1) {14944 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);
14947 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);14946 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
14948 const operand_src = block.src(.{ .array_cat_lhs = .{14947 const operand_src = block.src(.{ .array_cat_lhs = .{
14949 .array_cat_offset = inst_data.src_node,14948 .array_cat_offset = inst_data.src_node,
...@@ -14954,8 +14953,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14954,8 +14953,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14954 }14953 }
14955 while (elem_i < result_len) : (elem_i += 1) {14954 while (elem_i < result_len) : (elem_i += 1) {
14956 const rhs_elem_i = elem_i - lhs_len;14955 const rhs_elem_i = elem_i - lhs_len;
14957 const elem_index = try pt.intRef(Type.usize, elem_i);14956 const elem_index = try pt.intRef(.usize, elem_i);
14958 const rhs_index = try pt.intRef(Type.usize, rhs_elem_i);14957 const rhs_index = try pt.intRef(.usize, rhs_elem_i);
14959 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);14958 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
14960 const operand_src = block.src(.{ .array_cat_rhs = .{14959 const operand_src = block.src(.{ .array_cat_rhs = .{
14961 .array_cat_offset = inst_data.src_node,14960 .array_cat_offset = inst_data.src_node,
...@@ -14965,7 +14964,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14965,7 +14964,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14965 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);14964 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
14966 }14965 }
14967 if (res_sent_val) |sent_val| {14966 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);
14969 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);14968 const elem_ptr = try block.addPtrElemPtr(mutable_alloc, elem_index, elem_ptr_ty);
14970 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());14969 const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern());
14971 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);14970 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...@@ -14978,7 +14977,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14978 {14977 {
14979 var elem_i: u32 = 0;14978 var elem_i: u32 = 0;
14980 while (elem_i < lhs_len) : (elem_i += 1) {14979 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);
14982 const operand_src = block.src(.{ .array_cat_lhs = .{14981 const operand_src = block.src(.{ .array_cat_lhs = .{
14983 .array_cat_offset = inst_data.src_node,14982 .array_cat_offset = inst_data.src_node,
14984 .elem_index = elem_i,14983 .elem_index = elem_i,
...@@ -14988,7 +14987,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14988,7 +14987,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14988 }14987 }
14989 while (elem_i < result_len) : (elem_i += 1) {14988 while (elem_i < result_len) : (elem_i += 1) {
14990 const rhs_elem_i = elem_i - lhs_len;14989 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);
14992 const operand_src = block.src(.{ .array_cat_rhs = .{14991 const operand_src = block.src(.{ .array_cat_rhs = .{
14993 .array_cat_offset = inst_data.src_node,14992 .array_cat_offset = inst_data.src_node,
14994 .elem_index = @intCast(rhs_elem_i),14993 .elem_index = @intCast(rhs_elem_i),
...@@ -15012,8 +15011,8 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins...@@ -15012,8 +15011,8 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
15012 switch (ptr_info.flags.size) {15011 switch (ptr_info.flags.size) {
15013 .slice => {15012 .slice => {
15014 const val = try sema.resolveConstDefinedValue(block, src, operand, .{ .simple = .slice_cat_operand });15013 const val = try sema.resolveConstDefinedValue(block, src, operand, .{ .simple = .slice_cat_operand });
15015 return Type.ArrayInfo{15014 return .{
15016 .elem_type = Type.fromInterned(ptr_info.child),15015 .elem_type = .fromInterned(ptr_info.child),
15017 .sentinel = switch (ptr_info.sentinel) {15016 .sentinel = switch (ptr_info.sentinel) {
15018 .none => null,15017 .none => null,
15019 else => Value.fromInterned(ptr_info.sentinel),15018 else => Value.fromInterned(ptr_info.sentinel),
...@@ -15113,7 +15112,7 @@ fn analyzeTupleMul(...@@ -15113,7 +15112,7 @@ fn analyzeTupleMul(
15113 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);15112 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
15114 }15113 }
1511515114
15116 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);15115 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
15117}15116}
1511815117
15119fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15118fn 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...@@ -15166,7 +15165,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1516615165
15167 if (lhs_ty.isTuple(zcu)) {15166 if (lhs_ty.isTuple(zcu)) {
15168 // In `**` rhs must be comptime-known, but lhs can be runtime-known15167 // 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 });
15170 const factor_casted = try sema.usizeCast(block, rhs_src, factor);15169 const factor_casted = try sema.usizeCast(block, rhs_src, factor);
15171 return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted);15170 return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted);
15172 }15171 }
...@@ -15188,7 +15187,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15188,7 +15187,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15188 };15187 };
1518915188
15190 // In `**` rhs must be comptime-known, but lhs can be runtime-known15189 // 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
15193 const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch15192 const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch
15194 return sema.fail(block, rhs_src, "operation results in overflow", .{});15193 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...@@ -15246,7 +15245,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15246 // to get the same elem values.15245 // to get the same elem values.
15247 const lhs_vals = try sema.arena.alloc(Air.Inst.Ref, lhs_len);15246 const lhs_vals = try sema.arena.alloc(Air.Inst.Ref, lhs_len);
15248 for (lhs_vals, 0..) |*lhs_val, idx| {15247 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);
15250 lhs_val.* = try sema.elemVal(block, lhs_src, lhs, idx_ref, src, false);15249 lhs_val.* = try sema.elemVal(block, lhs_src, lhs, idx_ref, src, false);
15251 }15250 }
1525215251
...@@ -15267,14 +15266,14 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15267,14 +15266,14 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15267 var elem_i: usize = 0;15266 var elem_i: usize = 0;
15268 while (elem_i < result_len) {15267 while (elem_i < result_len) {
15269 for (lhs_vals) |lhs_val| {15268 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);
15271 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);15270 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
15272 try sema.storePtr2(block, src, elem_ptr, src, lhs_val, lhs_src, .store);15271 try sema.storePtr2(block, src, elem_ptr, src, lhs_val, lhs_src, .store);
15273 elem_i += 1;15272 elem_i += 1;
15274 }15273 }
15275 }15274 }
15276 if (lhs_info.sentinel) |sent_val| {15275 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);
15278 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);15277 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
15279 const init = Air.internedToRef(sent_val.toIntern());15278 const init = Air.internedToRef(sent_val.toIntern());
15280 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);15279 try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store);
...@@ -16132,14 +16131,13 @@ fn zirOverflowArithmetic(...@@ -16132,14 +16131,13 @@ fn zirOverflowArithmetic(
16132 const maybe_rhs_val = try sema.resolveValue(rhs);16131 const maybe_rhs_val = try sema.resolveValue(rhs);
1613316132
16134 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);16133 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
16137 var result: struct {16136 var result: struct {
16138 inst: Air.Inst.Ref = .none,16137 inst: Air.Inst.Ref = .none,
16139 wrapped: Value = Value.@"unreachable",16138 wrapped: Value = Value.@"unreachable",
16140 overflow_bit: Value,16139 overflow_bit: Value,
16141 } = result: {16140 } = result: {
16142 const zero_bit = try pt.intValue(Type.u1, 0);
16143 switch (zir_tag) {16141 switch (zir_tag) {
16144 .add_with_overflow => {16142 .add_with_overflow => {
16145 // If either of the arguments is zero, `false` is returned and the other is stored16143 // If either of the arguments is zero, `false` is returned and the other is stored
...@@ -16147,12 +16145,12 @@ fn zirOverflowArithmetic(...@@ -16147,12 +16145,12 @@ fn zirOverflowArithmetic(
16147 // Otherwise, if either of the argument is undefined, undefined is returned.16145 // Otherwise, if either of the argument is undefined, undefined is returned.
16148 if (maybe_lhs_val) |lhs_val| {16146 if (maybe_lhs_val) |lhs_val| {
16149 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {16147 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 };
16151 }16149 }
16152 }16150 }
16153 if (maybe_rhs_val) |rhs_val| {16151 if (maybe_rhs_val) |rhs_val| {
16154 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {16152 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 };
16156 }16154 }
16157 }16155 }
16158 if (maybe_lhs_val) |lhs_val| {16156 if (maybe_lhs_val) |lhs_val| {
...@@ -16173,7 +16171,7 @@ fn zirOverflowArithmetic(...@@ -16173,7 +16171,7 @@ fn zirOverflowArithmetic(
16173 if (rhs_val.isUndef(zcu)) {16171 if (rhs_val.isUndef(zcu)) {
16174 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16172 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16175 } else if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16173 } 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 };
16177 } else if (maybe_lhs_val) |lhs_val| {16175 } else if (maybe_lhs_val) |lhs_val| {
16178 if (lhs_val.isUndef(zcu)) {16176 if (lhs_val.isUndef(zcu)) {
16179 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16177 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
...@@ -16192,9 +16190,9 @@ fn zirOverflowArithmetic(...@@ -16192,9 +16190,9 @@ fn zirOverflowArithmetic(
16192 if (maybe_lhs_val) |lhs_val| {16190 if (maybe_lhs_val) |lhs_val| {
16193 if (!lhs_val.isUndef(zcu)) {16191 if (!lhs_val.isUndef(zcu)) {
16194 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {16192 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 };
16196 } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {16194 } 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 };
16198 }16196 }
16199 }16197 }
16200 }16198 }
...@@ -16202,9 +16200,9 @@ fn zirOverflowArithmetic(...@@ -16202,9 +16200,9 @@ fn zirOverflowArithmetic(
16202 if (maybe_rhs_val) |rhs_val| {16200 if (maybe_rhs_val) |rhs_val| {
16203 if (!rhs_val.isUndef(zcu)) {16201 if (!rhs_val.isUndef(zcu)) {
16204 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16202 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 };
16206 } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {16204 } 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 };
16208 }16206 }
16209 }16207 }
16210 }16208 }
...@@ -16226,12 +16224,12 @@ fn zirOverflowArithmetic(...@@ -16226,12 +16224,12 @@ fn zirOverflowArithmetic(
16226 // Oterhwise if either of the arguments is undefined, both results are undefined.16224 // Oterhwise if either of the arguments is undefined, both results are undefined.
16227 if (maybe_lhs_val) |lhs_val| {16225 if (maybe_lhs_val) |lhs_val| {
16228 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {16226 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 };
16230 }16228 }
16231 }16229 }
16232 if (maybe_rhs_val) |rhs_val| {16230 if (maybe_rhs_val) |rhs_val| {
16233 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {16231 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 };
16235 }16233 }
16236 }16234 }
16237 if (maybe_lhs_val) |lhs_val| {16235 if (maybe_lhs_val) |lhs_val| {
...@@ -16309,10 +16307,10 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {...@@ -16309,10 +16307,10 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
16309 const pt = sema.pt;16307 const pt = sema.pt;
16310 const zcu = pt.zcu;16308 const zcu = pt.zcu;
16311 const ip = &zcu.intern_pool;16309 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(.{
16313 .len = ty.vectorLen(zcu),16311 .len = ty.vectorLen(zcu),
16314 .child = .u1_type,16312 .child = .u1_type,
16315 }) else Type.u1;16313 }) else .u1;
1631616314
16317 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };16315 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };
16318 const values = [2]InternPool.Index{ .none, .none };16316 const values = [2]InternPool.Index{ .none, .none };
...@@ -16320,7 +16318,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {...@@ -16320,7 +16318,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
16320 .types = &types,16318 .types = &types,
16321 .values = &values,16319 .values = &values,
16322 });16320 });
16323 return Type.fromInterned(tuple_ty);16321 return .fromInterned(tuple_ty);
16324}16322}
1632516323
16326fn analyzeArithmetic(16324fn analyzeArithmetic(
...@@ -16380,7 +16378,7 @@ fn analyzeArithmetic(...@@ -16380,7 +16378,7 @@ fn analyzeArithmetic(
16380 const address = std.math.sub(u64, lhs_ptr.byte_offset, rhs_ptr.byte_offset) catch16378 const address = std.math.sub(u64, lhs_ptr.byte_offset, rhs_ptr.byte_offset) catch
16381 return sema.fail(block, src, "operation results in overflow", .{});16379 return sema.fail(block, src, "operation results in overflow", .{});
16382 const result = address / elem_size;16380 const result = address / elem_size;
16383 return try pt.intRef(Type.usize, result);16381 return try pt.intRef(.usize, result);
16384 } else {16382 } else {
16385 break :runtime_src lhs_src;16383 break :runtime_src lhs_src;
16386 }16384 }
...@@ -16395,7 +16393,7 @@ fn analyzeArithmetic(...@@ -16395,7 +16393,7 @@ fn analyzeArithmetic(
16395 const lhs_int = try block.addBitCast(.usize, lhs);16393 const lhs_int = try block.addBitCast(.usize, lhs);
16396 const rhs_int = try block.addBitCast(.usize, rhs);16394 const rhs_int = try block.addBitCast(.usize, rhs);
16397 const address = try block.addBinOp(.sub_wrap, lhs_int, rhs_int);16395 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));
16399 }16397 }
16400 } else {16398 } else {
16401 switch (lhs_ty.ptrSize(zcu)) {16399 switch (lhs_ty.ptrSize(zcu)) {
...@@ -16527,8 +16525,7 @@ fn analyzeArithmetic(...@@ -16527,8 +16525,7 @@ fn analyzeArithmetic(
16527 try block.addReduce(ov_bit, .Or)16525 try block.addReduce(ov_bit, .Or)
16528 else16526 else
16529 ov_bit;16527 ov_bit;
16530 const zero_ov = Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());16528 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, .zero_u1);
16531 const no_ov = try block.addBinOp(.cmp_eq, any_ov_bit, zero_ov);
1653216529
16533 try sema.addSafetyCheck(block, src, no_ov, .integer_overflow);16530 try sema.addSafetyCheck(block, src, no_ov, .integer_overflow);
16534 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);16531 return sema.tupleFieldValByIndex(block, op_ov, 0, op_ov_tuple_ty);
...@@ -16550,7 +16547,7 @@ fn analyzePtrArithmetic(...@@ -16550,7 +16547,7 @@ fn analyzePtrArithmetic(
16550) CompileError!Air.Inst.Ref {16547) CompileError!Air.Inst.Ref {
16551 // TODO if the operand is comptime-known to be negative, or is a negative int,16548 // TODO if the operand is comptime-known to be negative, or is a negative int,
16552 // coerce to isize instead of usize.16549 // 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);
16554 const pt = sema.pt;16551 const pt = sema.pt;
16555 const zcu = pt.zcu;16552 const zcu = pt.zcu;
16556 const opt_ptr_val = try sema.resolveValue(ptr);16553 const opt_ptr_val = try sema.resolveValue(ptr);
...@@ -16736,8 +16733,8 @@ fn zirAsm(...@@ -16736,8 +16733,8 @@ fn zirAsm(
16736 const uncasted_arg = try sema.resolveInst(input.data.operand);16733 const uncasted_arg = try sema.resolveInst(input.data.operand);
16737 const uncasted_arg_ty = sema.typeOf(uncasted_arg);16734 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
16738 switch (uncasted_arg_ty.zigTypeTag(zcu)) {16735 switch (uncasted_arg_ty.zigTypeTag(zcu)) {
16739 .comptime_int => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),16736 .comptime_int => arg.* = try sema.coerce(block, .usize, uncasted_arg, src),
16740 .comptime_float => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),16737 .comptime_float => arg.* = try sema.coerce(block, .f64, uncasted_arg, src),
16741 else => {16738 else => {
16742 arg.* = uncasted_arg;16739 arg.* = uncasted_arg;
16743 },16740 },
...@@ -16860,9 +16857,7 @@ fn zirCmpEq(...@@ -16860,9 +16857,7 @@ fn zirCmpEq(
16860 const runtime_src: LazySrcLoc = src: {16857 const runtime_src: LazySrcLoc = src: {
16861 if (try sema.resolveValue(lhs)) |lval| {16858 if (try sema.resolveValue(lhs)) |lval| {
16862 if (try sema.resolveValue(rhs)) |rval| {16859 if (try sema.resolveValue(rhs)) |rval| {
16863 if (lval.isUndef(zcu) or rval.isUndef(zcu)) {16860 if (lval.isUndef(zcu) or rval.isUndef(zcu)) return .undef_bool;
16864 return pt.undefRef(Type.bool);
16865 }
16866 const lkey = zcu.intern_pool.indexToKey(lval.toIntern());16861 const lkey = zcu.intern_pool.indexToKey(lval.toIntern());
16867 const rkey = zcu.intern_pool.indexToKey(rval.toIntern());16862 const rkey = zcu.intern_pool.indexToKey(rval.toIntern());
16868 return if ((lkey.err.name == rkey.err.name) == (op == .eq))16863 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
...@@ -16916,7 +16911,7 @@ fn analyzeCmpUnionTag(...@@ -16916,7 +16911,7 @@ fn analyzeCmpUnionTag(
16916 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);16911 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1691716912
16918 if (try sema.resolveValue(coerced_tag)) |enum_val| {16913 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;
16920 const field_ty = union_ty.unionFieldType(enum_val, zcu).?;16915 const field_ty = union_ty.unionFieldType(enum_val, zcu).?;
16921 if (field_ty.zigTypeTag(zcu) == .noreturn) {16916 if (field_ty.zigTypeTag(zcu) == .noreturn) {
16922 return .bool_false;16917 return .bool_false;
...@@ -17027,8 +17022,8 @@ fn cmpSelf(...@@ -17027,8 +17022,8 @@ fn cmpSelf(
1702717022
17028 const maybe_lhs_val = try sema.resolveValue(casted_lhs);17023 const maybe_lhs_val = try sema.resolveValue(casted_lhs);
17029 const maybe_rhs_val = try sema.resolveValue(casted_rhs);17024 const maybe_rhs_val = try sema.resolveValue(casted_rhs);
17030 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);17025 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
17031 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);17026 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
1703217027
17033 const runtime_src: LazySrcLoc = src: {17028 const runtime_src: LazySrcLoc = src: {
17034 if (maybe_lhs_val) |lhs_val| {17029 if (maybe_lhs_val) |lhs_val| {
...@@ -17083,7 +17078,7 @@ fn runtimeBoolCmp(...@@ -17083,7 +17078,7 @@ fn runtimeBoolCmp(
17083) CompileError!Air.Inst.Ref {17078) CompileError!Air.Inst.Ref {
17084 if ((op == .neq) == rhs) {17079 if ((op == .neq) == rhs) {
17085 try sema.requireRuntimeBlock(block, src, runtime_src);17080 try sema.requireRuntimeBlock(block, src, runtime_src);
17086 return block.addTyOp(.not, Type.bool, lhs);17081 return block.addTyOp(.not, .bool, lhs);
17087 } else {17082 } else {
17088 return lhs;17083 return lhs;
17089 }17084 }
...@@ -17107,7 +17102,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -17107,7 +17102,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
17107 .comptime_float,17102 .comptime_float,
17108 .comptime_int,17103 .comptime_int,
17109 .void,17104 .void,
17110 => return pt.intRef(Type.comptime_int, 0),17105 => return .zero,
1711117106
17112 .bool,17107 .bool,
17113 .int,17108 .int,
...@@ -17148,7 +17143,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -17148,7 +17143,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
17148 .comptime_float,17143 .comptime_float,
17149 .comptime_int,17144 .comptime_int,
17150 .void,17145 .void,
17151 => return pt.intRef(Type.comptime_int, 0),17146 => return .zero,
1715217147
17153 .bool,17148 .bool,
17154 .int,17149 .int,
...@@ -17167,7 +17162,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -17167,7 +17162,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
17167 => {},17162 => {},
17168 }17163 }
17169 const bit_size = try operand_ty.bitSizeSema(pt);17164 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);
17171}17166}
1717217167
17173fn zirThis(17168fn zirThis(
...@@ -17285,7 +17280,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17285,7 +17280,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1728517280
17286 assert(block.is_typeof);17281 assert(block.is_typeof);
17287 // We need a dummy runtime instruction with the correct type.17282 // 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));
17289}17284}
1729017285
17291fn zirRetAddr(17286fn zirRetAddr(
...@@ -17293,10 +17288,11 @@ fn zirRetAddr(...@@ -17293,10 +17288,11 @@ fn zirRetAddr(
17293 block: *Block,17288 block: *Block,
17294 extended: Zir.Inst.Extended.InstData,17289 extended: Zir.Inst.Extended.InstData,
17295) CompileError!Air.Inst.Ref {17290) CompileError!Air.Inst.Ref {
17291 _ = sema;
17296 _ = extended;17292 _ = extended;
17297 if (block.isComptime()) {17293 if (block.isComptime()) {
17298 // TODO: we could give a meaningful lazy value here. #1493817294 // TODO: we could give a meaningful lazy value here. #14938
17299 return sema.pt.intRef(Type.usize, 0);17295 return .zero_usize;
17300 } else {17296 } else {
17301 return block.addNoOp(.ret_addr);17297 return block.addNoOp(.ret_addr);
17302 }17298 }
...@@ -17349,7 +17345,7 @@ fn zirBuiltinSrc(...@@ -17349,7 +17345,7 @@ fn zirBuiltinSrc(
17349 } },17345 } },
17350 .byte_offset = 0,17346 .byte_offset = 0,
17351 } }),17347 } }),
17352 .len = (try pt.intValue(Type.usize, func_name_len)).toIntern(),17348 .len = (try pt.intValue(.usize, func_name_len)).toIntern(),
17353 } });17349 } });
17354 };17350 };
1735517351
...@@ -17375,7 +17371,7 @@ fn zirBuiltinSrc(...@@ -17375,7 +17371,7 @@ fn zirBuiltinSrc(
17375 } },17371 } },
17376 .byte_offset = 0,17372 .byte_offset = 0,
17377 } }),17373 } }),
17378 .len = (try pt.intValue(Type.usize, module_name.len)).toIntern(),17374 .len = (try pt.intValue(.usize, module_name.len)).toIntern(),
17379 } });17375 } });
17380 };17376 };
1738117377
...@@ -17401,7 +17397,7 @@ fn zirBuiltinSrc(...@@ -17401,7 +17397,7 @@ fn zirBuiltinSrc(
17401 } },17397 } },
17402 .byte_offset = 0,17398 .byte_offset = 0,
17403 } }),17399 } }),
17404 .len = (try pt.intValue(Type.usize, file_name.len)).toIntern(),17400 .len = (try pt.intValue(.usize, file_name.len)).toIntern(),
17405 } });17401 } });
17406 };17402 };
1740717403
...@@ -17414,9 +17410,9 @@ fn zirBuiltinSrc(...@@ -17414,9 +17410,9 @@ fn zirBuiltinSrc(
17414 // fn_name: [:0]const u8,17410 // fn_name: [:0]const u8,
17415 func_name_val,17411 func_name_val,
17416 // line: u32,17412 // line: u32,
17417 (try pt.intValue(Type.u32, extra.line + 1)).toIntern(),17413 (try pt.intValue(.u32, extra.line + 1)).toIntern(),
17418 // column: u32,17414 // column: u32,
17419 (try pt.intValue(Type.u32, extra.column + 1)).toIntern(),17415 (try pt.intValue(.u32, extra.column + 1)).toIntern(),
17420 };17416 };
17421 return Air.internedToRef((try pt.intern(.{ .aggregate = .{17417 return Air.internedToRef((try pt.intern(.{ .aggregate = .{
17422 .ty = src_loc_ty.toIntern(),17418 .ty = src_loc_ty.toIntern(),
...@@ -17511,7 +17507,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17511,7 +17507,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17511 } },17507 } },
17512 .byte_offset = 0,17508 .byte_offset = 0,
17513 } }),17509 } }),
17514 .len = (try pt.intValue(Type.usize, param_vals.len)).toIntern(),17510 .len = (try pt.intValue(.usize, param_vals.len)).toIntern(),
17515 } });17511 } });
17516 };17512 };
1751717513
...@@ -17564,7 +17560,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17564,7 +17560,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17564 // signedness: Signedness,17560 // signedness: Signedness,
17565 (try pt.enumValueFieldIndex(signedness_ty, @intFromEnum(info.signedness))).toIntern(),17561 (try pt.enumValueFieldIndex(signedness_ty, @intFromEnum(info.signedness))).toIntern(),
17566 // bits: u16,17562 // bits: u16,
17567 (try pt.intValue(Type.u16, info.bits)).toIntern(),17563 (try pt.intValue(.u16, info.bits)).toIntern(),
17568 };17564 };
17569 return Air.internedToRef((try pt.internUnion(.{17565 return Air.internedToRef((try pt.internUnion(.{
17570 .ty = type_info_ty.toIntern(),17566 .ty = type_info_ty.toIntern(),
...@@ -17580,7 +17576,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17580,7 +17576,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1758017576
17581 const field_vals = .{17577 const field_vals = .{
17582 // bits: u16,17578 // bits: u16,
17583 (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(),17579 (try pt.intValue(.u16, ty.bitSize(zcu))).toIntern(),
17584 };17580 };
17585 return Air.internedToRef((try pt.internUnion(.{17581 return Air.internedToRef((try pt.internUnion(.{
17586 .ty = type_info_ty.toIntern(),17582 .ty = type_info_ty.toIntern(),
...@@ -17594,7 +17590,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17594,7 +17590,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17594 .pointer => {17590 .pointer => {
17595 const info = ty.ptrInfo(zcu);17591 const info = ty.ptrInfo(zcu);
17596 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|17592 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|
17597 try pt.intValue(Type.comptime_int, alignment)17593 try pt.intValue(.comptime_int, alignment)
17598 else17594 else
17599 try Type.fromInterned(info.child).lazyAbiAlignment(pt);17595 try Type.fromInterned(info.child).lazyAbiAlignment(pt);
1760017596
...@@ -17638,7 +17634,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17638,7 +17634,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17638 const info = ty.arrayInfo(zcu);17634 const info = ty.arrayInfo(zcu);
17639 const field_values = .{17635 const field_values = .{
17640 // len: comptime_int,17636 // len: comptime_int,
17641 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),17637 (try pt.intValue(.comptime_int, info.len)).toIntern(),
17642 // child: type,17638 // child: type,
17643 info.elem_type.toIntern(),17639 info.elem_type.toIntern(),
17644 // sentinel: ?*const anyopaque,17640 // sentinel: ?*const anyopaque,
...@@ -17659,7 +17655,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17659,7 +17655,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17659 const info = ty.arrayInfo(zcu);17655 const info = ty.arrayInfo(zcu);
17660 const field_values = .{17656 const field_values = .{
17661 // len: comptime_int,17657 // len: comptime_int,
17662 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),17658 (try pt.intValue(.comptime_int, info.len)).toIntern(),
17663 // child: type,17659 // child: type,
17664 info.elem_type.toIntern(),17660 info.elem_type.toIntern(),
17665 };17661 };
...@@ -17723,7 +17719,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17723,7 +17719,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17723 } },17719 } },
17724 .byte_offset = 0,17720 .byte_offset = 0,
17725 } }),17721 } }),
17726 .len = (try pt.intValue(Type.usize, error_name_len)).toIntern(),17722 .len = (try pt.intValue(.usize, error_name_len)).toIntern(),
17727 } });17723 } });
17728 };17724 };
1772917725
...@@ -17770,7 +17766,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17770,7 +17766,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17770 } },17766 } },
17771 .byte_offset = 0,17767 .byte_offset = 0,
17772 } }),17768 } }),
17773 .len = (try pt.intValue(Type.usize, vals.len)).toIntern(),17769 .len = (try pt.intValue(.usize, vals.len)).toIntern(),
17774 } });17770 } });
17775 } else .none;17771 } else .none;
17776 const errors_val = try pt.intern(.{ .opt = .{17772 const errors_val = try pt.intern(.{ .opt = .{
...@@ -17819,7 +17815,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17819,7 +17815,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17819 .comptime_int_type,17815 .comptime_int_type,
17820 )17816 )
17821 else17817 else
17822 (try pt.intValue(Type.comptime_int, tag_index)).toIntern();17818 (try pt.intValue(.comptime_int, tag_index)).toIntern();
1782317819
17824 // TODO: write something like getCoercedInts to avoid needing to dupe17820 // TODO: write something like getCoercedInts to avoid needing to dupe
17825 const name_val = v: {17821 const name_val = v: {
...@@ -17844,7 +17840,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17844,7 +17840,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17844 } },17840 } },
17845 .byte_offset = 0,17841 .byte_offset = 0,
17846 } }),17842 } }),
17847 .len = (try pt.intValue(Type.usize, tag_name_len)).toIntern(),17843 .len = (try pt.intValue(.usize, tag_name_len)).toIntern(),
17848 } });17844 } });
17849 };17845 };
1785017846
...@@ -17887,7 +17883,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17887,7 +17883,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17887 } },17883 } },
17888 .byte_offset = 0,17884 .byte_offset = 0,
17889 } }),17885 } }),
17890 .len = (try pt.intValue(Type.usize, enum_field_vals.len)).toIntern(),17886 .len = (try pt.intValue(.usize, enum_field_vals.len)).toIntern(),
17891 } });17887 } });
17892 };17888 };
1789317889
...@@ -17949,7 +17945,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17949,7 +17945,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17949 } },17945 } },
17950 .byte_offset = 0,17946 .byte_offset = 0,
17951 } }),17947 } }),
17952 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),17948 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
17953 } });17949 } });
17954 };17950 };
1795517951
...@@ -17965,7 +17961,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17965,7 +17961,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17965 // type: type,17961 // type: type,
17966 field_ty,17962 field_ty,
17967 // alignment: comptime_int,17963 // 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(),
17969 };17965 };
17970 field_val.* = try pt.intern(.{ .aggregate = .{17966 field_val.* = try pt.intern(.{ .aggregate = .{
17971 .ty = union_field_ty.toIntern(),17967 .ty = union_field_ty.toIntern(),
...@@ -18000,7 +17996,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18000,7 +17996,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18000 } },17996 } },
18001 .byte_offset = 0,17997 .byte_offset = 0,
18002 } }),17998 } }),
18003 .len = (try pt.intValue(Type.usize, union_field_vals.len)).toIntern(),17999 .len = (try pt.intValue(.usize, union_field_vals.len)).toIntern(),
18004 } });18000 } });
18005 };18001 };
1800618002
...@@ -18070,7 +18066,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18070,7 +18066,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18070 } },18066 } },
18071 .byte_offset = 0,18067 .byte_offset = 0,
18072 } }),18068 } }),
18073 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),18069 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
18074 } });18070 } });
18075 };18071 };
1807618072
...@@ -18089,7 +18085,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18089,7 +18085,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18089 // is_comptime: bool,18085 // is_comptime: bool,
18090 Value.makeBool(is_comptime).toIntern(),18086 Value.makeBool(is_comptime).toIntern(),
18091 // alignment: comptime_int,18087 // 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(),
18093 };18089 };
18094 struct_field_val.* = try pt.intern(.{ .aggregate = .{18090 struct_field_val.* = try pt.intern(.{ .aggregate = .{
18095 .ty = struct_field_ty.toIntern(),18091 .ty = struct_field_ty.toIntern(),
...@@ -18111,7 +18107,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18111,7 +18107,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18111 else18107 else
18112 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);18108 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
18113 const field_name_len = field_name.length(ip);18109 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]);
18115 const field_init = struct_type.fieldInit(ip, field_index);18111 const field_init = struct_type.fieldInit(ip, field_index);
18116 const field_is_comptime = struct_type.fieldIsComptime(ip, field_index);18112 const field_is_comptime = struct_type.fieldIsComptime(ip, field_index);
18117 const name_val = v: {18113 const name_val = v: {
...@@ -18134,7 +18130,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18134,7 +18130,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18134 } },18130 } },
18135 .byte_offset = 0,18131 .byte_offset = 0,
18136 } }),18132 } }),
18137 .len = (try pt.intValue(Type.usize, field_name_len)).toIntern(),18133 .len = (try pt.intValue(.usize, field_name_len)).toIntern(),
18138 } });18134 } });
18139 };18135 };
1814018136
...@@ -18159,7 +18155,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18159,7 +18155,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18159 // is_comptime: bool,18155 // is_comptime: bool,
18160 Value.makeBool(field_is_comptime).toIntern(),18156 Value.makeBool(field_is_comptime).toIntern(),
18161 // alignment: comptime_int,18157 // 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(),
18163 };18159 };
18164 field_val.* = try pt.intern(.{ .aggregate = .{18160 field_val.* = try pt.intern(.{ .aggregate = .{
18165 .ty = struct_field_ty.toIntern(),18161 .ty = struct_field_ty.toIntern(),
...@@ -18195,7 +18191,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18195,7 +18191,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18195 } },18191 } },
18196 .byte_offset = 0,18192 .byte_offset = 0,
18197 } }),18193 } }),
18198 .len = (try pt.intValue(Type.usize, struct_field_vals.len)).toIntern(),18194 .len = (try pt.intValue(.usize, struct_field_vals.len)).toIntern(),
18199 } });18195 } });
18200 };18196 };
1820118197
...@@ -18304,7 +18300,7 @@ fn typeInfoDecls(...@@ -18304,7 +18300,7 @@ fn typeInfoDecls(
18304 } },18300 } },
18305 .byte_offset = 0,18301 .byte_offset = 0,
18306 } }),18302 } }),
18307 .len = (try pt.intValue(Type.usize, decl_vals.items.len)).toIntern(),18303 .len = (try pt.intValue(.usize, decl_vals.items.len)).toIntern(),
18308 } });18304 } });
18309}18305}
1831018306
...@@ -18354,7 +18350,7 @@ fn typeInfoNamespaceDecls(...@@ -18354,7 +18350,7 @@ fn typeInfoNamespaceDecls(
18354 .byte_offset = 0,18350 .byte_offset = 0,
18355 },18351 },
18356 }),18352 }),
18357 .len = (try pt.intValue(Type.usize, name_len)).toIntern(),18353 .len = (try pt.intValue(.usize, name_len)).toIntern(),
18358 },18354 },
18359 });18355 });
18360 };18356 };
...@@ -18373,7 +18369,7 @@ fn typeInfoNamespaceDecls(...@@ -18373,7 +18369,7 @@ fn typeInfoNamespaceDecls(
18373 continue;18369 continue;
18374 }18370 }
18375 try sema.ensureNavResolved(block, src, nav, .fully);18371 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);
18377 try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu).toOptional(), declaration_ty, decl_vals, seen_namespaces);18373 try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu).toOptional(), declaration_ty, decl_vals, seen_namespaces);
18378 }18374 }
18379}18375}
...@@ -18424,7 +18420,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi...@@ -18424,7 +18420,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
18424 const pt = sema.pt;18420 const pt = sema.pt;
18425 const zcu = pt.zcu;18421 const zcu = pt.zcu;
18426 switch (operand.zigTypeTag(zcu)) {18422 switch (operand.zigTypeTag(zcu)) {
18427 .comptime_int => return Type.comptime_int,18423 .comptime_int => return .comptime_int,
18428 .int => {18424 .int => {
18429 const bits = operand.bitSize(zcu);18425 const bits = operand.bitSize(zcu);
18430 const count = if (bits == 0)18426 const count = if (bits == 0)
...@@ -18512,14 +18508,12 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18512,14 +18508,12 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18512 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });18508 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
18513 const uncasted_operand = try sema.resolveInst(inst_data.operand);18509 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);
18516 if (try sema.resolveValue(operand)) |val| {18512 if (try sema.resolveValue(operand)) |val| {
18517 return if (val.isUndef(zcu))18513 return if (val.isUndef(zcu)) .undef_bool else if (val.toBool()) .bool_false else .bool_true;
18518 pt.undefRef(Type.bool)
18519 else if (val.toBool()) .bool_false else .bool_true;
18520 }18514 }
18521 try sema.requireRuntimeBlock(block, src, null);18515 try sema.requireRuntimeBlock(block, src, null);
18522 return block.addTyOp(.not, Type.bool, operand);18516 return block.addTyOp(.not, .bool, operand);
18523}18517}
1852418518
18525fn zirBoolBr(18519fn zirBoolBr(
...@@ -18544,7 +18538,7 @@ fn zirBoolBr(...@@ -18544,7 +18538,7 @@ fn zirBoolBr(
18544 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });18538 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
18545 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });18539 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
18549 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {18543 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
18550 if (is_bool_or and lhs_val.toBool()) {18544 if (is_bool_or and lhs_val.toBool()) {
...@@ -18559,7 +18553,7 @@ fn zirBoolBr(...@@ -18559,7 +18553,7 @@ fn zirBoolBr(
18559 if (sema.typeOf(rhs_result).isNoReturn(zcu)) {18553 if (sema.typeOf(rhs_result).isNoReturn(zcu)) {
18560 return rhs_result;18554 return rhs_result;
18561 }18555 }
18562 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);18556 return sema.coerce(parent_block, .bool, rhs_result, rhs_src);
18563 }18557 }
1856418558
18565 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);18559 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
...@@ -18596,7 +18590,7 @@ fn zirBoolBr(...@@ -18596,7 +18590,7 @@ fn zirBoolBr(
18596 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);18590 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);
18597 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(zcu);18591 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(zcu);
18598 const coerced_rhs_result = if (!rhs_noret) rhs: {18592 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);
18600 _ = try rhs_block.addBr(block_inst, coerced_result);18594 _ = try rhs_block.addBr(block_inst, coerced_result);
18601 break :rhs coerced_result;18595 break :rhs coerced_result;
18602 } else rhs_result;18596 } else rhs_result;
...@@ -18797,7 +18791,7 @@ fn zirCondbr(...@@ -18797,7 +18791,7 @@ fn zirCondbr(
18797 const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);18791 const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
1879818792
18799 const uncasted_cond = try sema.resolveInst(extra.data.condition);18793 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
18802 if (try sema.resolveDefinedValue(parent_block, cond_src, cond)) |cond_val| {18796 if (try sema.resolveDefinedValue(parent_block, cond_src, cond)) |cond_val| {
18803 const body = if (cond_val.toBool()) then_body else else_body;18797 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...@@ -19502,7 +19496,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19502 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {19496 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {
19503 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);19497 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
19504 extra_i += 1;19498 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);
19506 const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ .simple = .@"align" });19500 const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ .simple = .@"align" });
19507 // Check if this happens to be the lazy alignment of our element type, in19501 // Check if this happens to be the lazy alignment of our element type, in
19508 // which case we can make this 0 without resolving it.19502 // 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...@@ -19526,14 +19520,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19526 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {19520 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
19527 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);19521 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
19528 extra_i += 1;19522 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 });
19530 break :blk @intCast(bit_offset);19524 break :blk @intCast(bit_offset);
19531 } else 0;19525 } else 0;
1953219526
19533 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {19527 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
19534 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);19528 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
19535 extra_i += 1;19529 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 });
19537 break :blk @intCast(host_size);19531 break :blk @intCast(host_size);
19538 } else 0;19532 } else 0;
1953919533
...@@ -19767,7 +19761,7 @@ fn unionInit(...@@ -19767,7 +19761,7 @@ fn unionInit(
19767 const zcu = pt.zcu;19761 const zcu = pt.zcu;
19768 const ip = &zcu.intern_pool;19762 const ip = &zcu.intern_pool;
19769 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);19763 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]);
19771 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);19765 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
19772 _ = union_ty_src;19766 _ = union_ty_src;
19773 return unionInitFromEnumTag(sema, block, init_src, union_ty, field_index, init);19767 return unionInitFromEnumTag(sema, block, init_src, union_ty, field_index, init);
...@@ -19902,7 +19896,7 @@ fn zirStructInit(...@@ -19902,7 +19896,7 @@ fn zirStructInit(
19902 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);19896 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
19903 const tag_ty = resolved_ty.unionTagTypeHypothetical(zcu);19897 const tag_ty = resolved_ty.unionTagTypeHypothetical(zcu);
19904 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);19898 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
19907 if (field_ty.zigTypeTag(zcu) == .noreturn) {19901 if (field_ty.zigTypeTag(zcu) == .noreturn) {
19908 return sema.failWithOwnedErrorMsg(block, msg: {19902 return sema.failWithOwnedErrorMsg(block, msg: {
...@@ -19990,7 +19984,7 @@ fn finishStructInit(...@@ -19990,7 +19984,7 @@ fn finishStructInit(
19990 .init_node_offset = init_src.offset.node_offset.x,19984 .init_node_offset = init_src.offset.node_offset.x,
19991 .elem_index = @intCast(i),19985 .elem_index = @intCast(i),
19992 } });19986 } });
19993 const field_ty = Type.fromInterned(tuple.types.get(ip)[i]);19987 const field_ty: Type = .fromInterned(tuple.types.get(ip)[i]);
19994 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);19988 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
19995 continue;19989 continue;
19996 }19990 }
...@@ -20018,7 +20012,7 @@ fn finishStructInit(...@@ -20018,7 +20012,7 @@ fn finishStructInit(
20018 .init_node_offset = init_src.offset.node_offset.x,20012 .init_node_offset = init_src.offset.node_offset.x,
20019 .elem_index = @intCast(i),20013 .elem_index = @intCast(i),
20020 } });20014 } });
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]);
20022 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);20016 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
20023 continue;20017 continue;
20024 }20018 }
...@@ -20183,7 +20177,7 @@ fn structInitAnon(...@@ -20183,7 +20177,7 @@ fn structInitAnon(
20183 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});20177 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20184 errdefer msg.destroy(sema.gpa);20178 errdefer msg.destroy(sema.gpa);
2018520179
20186 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));20180 try sema.addDeclaredHereNote(msg, .fromInterned(field_ty.*));
20187 break :msg msg;20181 break :msg msg;
20188 };20182 };
20189 return sema.failWithOwnedErrorMsg(block, msg);20183 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -20317,7 +20311,7 @@ fn structInitAnon(...@@ -20317,7 +20311,7 @@ fn structInitAnon(
20317 element_refs[i] = try sema.resolveInst(item.data.init);20311 element_refs[i] = try sema.resolveInst(item.data.init);
20318 }20312 }
2031920313
20320 return block.addAggregateInit(Type.fromInterned(struct_ty), element_refs);20314 return block.addAggregateInit(.fromInterned(struct_ty), element_refs);
20321}20315}
2032220316
20323fn zirArrayInit(20317fn zirArrayInit(
...@@ -20441,7 +20435,7 @@ fn zirArrayInit(...@@ -20441,7 +20435,7 @@ fn zirArrayInit(
20441 });20435 });
20442 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());20436 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);
20445 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);20439 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);
20446 _ = try block.addBinOp(.store, elem_ptr, arg);20440 _ = try block.addBinOp(.store, elem_ptr, arg);
20447 }20441 }
...@@ -20455,7 +20449,7 @@ fn zirArrayInit(...@@ -20455,7 +20449,7 @@ fn zirArrayInit(
20455 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());20449 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
2045620450
20457 for (resolved_args, 0..) |arg, i| {20451 for (resolved_args, 0..) |arg, i| {
20458 const index = try pt.intRef(Type.usize, i);20452 const index = try pt.intRef(.usize, i);
20459 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);20453 const elem_ptr = try block.addPtrElemPtrTypeRef(base_ptr, index, elem_ptr_ty_ref);
20460 _ = try block.addBinOp(.store, elem_ptr, arg);20454 _ = try block.addBinOp(.store, elem_ptr, arg);
20461 }20455 }
...@@ -20504,7 +20498,7 @@ fn arrayInitAnon(...@@ -20504,7 +20498,7 @@ fn arrayInitAnon(
20504 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});20498 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20505 errdefer msg.destroy(gpa);20499 errdefer msg.destroy(gpa);
2050620500
20507 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));20501 try sema.addDeclaredHereNote(msg, .fromInterned(types[i]));
20508 break :msg msg;20502 break :msg msg;
20509 };20503 };
20510 return sema.failWithOwnedErrorMsg(block, msg);20504 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -20561,7 +20555,7 @@ fn arrayInitAnon(...@@ -20561,7 +20555,7 @@ fn arrayInitAnon(
20561 element_refs[i] = try sema.resolveInst(operand);20555 element_refs[i] = try sema.resolveInst(operand);
20562 }20556 }
2056320557
20564 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);20558 return block.addAggregateInit(.fromInterned(tuple_ty), element_refs);
20565}20559}
2056620560
20567fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {20561fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {
...@@ -20632,7 +20626,7 @@ fn fieldType(...@@ -20632,7 +20626,7 @@ fn fieldType(
20632 .optional => {20626 .optional => {
20633 // Struct/array init through optional requires the child type to not be a pointer.20627 // Struct/array init through optional requires the child type to not be a pointer.
20634 // If the child of .optional is a pointer it'll error on the next loop.20628 // 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);
20636 continue;20630 continue;
20637 },20631 },
20638 .error_union => {20632 .error_union => {
...@@ -20710,21 +20704,18 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -20710,21 +20704,18 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
20710 const dest_ty: Type = if (is_vector) try pt.vectorType(.{ .child = .u1_type, .len = len }) else .u1;20704 const dest_ty: Type = if (is_vector) try pt.vectorType(.{ .child = .u1_type, .len = len }) else .u1;
20711 if (try sema.resolveValue(operand)) |val| {20705 if (try sema.resolveValue(operand)) |val| {
20712 if (!is_vector) {20706 if (!is_vector) {
20713 if (val.isUndef(zcu)) return pt.undefRef(Type.u1);20707 return if (val.isUndef(zcu)) .undef_u1 else if (val.toBool()) .one_u1 else .zero_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());
20716 }20708 }
20717 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);20709 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
20718 const new_elems = try sema.arena.alloc(InternPool.Index, len);20710 const new_elems = try sema.arena.alloc(InternPool.Index, len);
20719 for (new_elems, 0..) |*new_elem, i| {20711 for (new_elems, 0..) |*new_elem, i| {
20720 const old_elem = try val.elemValue(pt, i);20712 const old_elem = try val.elemValue(pt, i);
20721 const new_val = if (old_elem.isUndef(zcu))20713 new_elem.* = if (old_elem.isUndef(zcu))
20722 try pt.undefValue(Type.u1)20714 .undef_u1
20723 else if (old_elem.toBool())20715 else if (old_elem.toBool())
20724 try pt.intValue(Type.u1, 1)20716 .one_u1
20725 else20717 else
20726 try pt.intValue(Type.u1, 0);20718 .zero_u1;
20727 new_elem.* = new_val.toIntern();
20728 }20719 }
20729 return Air.internedToRef(try pt.intern(.{ .aggregate = .{20720 return Air.internedToRef(try pt.intern(.{ .aggregate = .{
20730 .ty = dest_ty.toIntern(),20721 .ty = dest_ty.toIntern(),
...@@ -20736,7 +20727,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -20736,7 +20727,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
20736 }20727 }
20737 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);20728 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
20738 for (new_elems, 0..) |*new_elem, i| {20729 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);
20740 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);20731 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
20741 new_elem.* = try block.addBitCast(.u1, old_elem);20732 new_elem.* = try block.addBitCast(.u1, old_elem);
20742 }20733 }
...@@ -20747,7 +20738,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -20747,7 +20738,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
20747 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;20738 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20748 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);20739 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20749 const uncoerced_operand = try sema.resolveInst(inst_data.operand);20740 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
20752 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {20743 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
20753 const err_name = sema.pt.zcu.intern_pool.indexToKey(val.toIntern()).err.name;20744 const err_name = sema.pt.zcu.intern_pool.indexToKey(val.toIntern()).err.name;
...@@ -20993,12 +20984,12 @@ fn zirReify(...@@ -20993,12 +20984,12 @@ fn zirReify(
20993 .float => {20984 .float => {
20994 const float = try sema.interpretBuiltinType(block, operand_src, .fromInterned(union_val.val), std.builtin.Type.Float);20985 const float = try sema.interpretBuiltinType(block, operand_src, .fromInterned(union_val.val), std.builtin.Type.Float);
2099520986
20996 const ty = switch (float.bits) {20987 const ty: Type = switch (float.bits) {
20997 16 => Type.f16,20988 16 => .f16,
20998 32 => Type.f32,20989 32 => .f32,
20999 64 => Type.f64,20990 64 => .f64,
21000 80 => Type.f80,20991 80 => .f80,
21001 128 => Type.f128,20992 128 => .f128,
21002 else => return sema.fail(block, src, "{}-bit float unsupported", .{float.bits}),20993 else => return sema.fail(block, src, "{}-bit float unsupported", .{float.bits}),
21003 };20994 };
21004 return Air.internedToRef(ty.toIntern());20995 return Air.internedToRef(ty.toIntern());
...@@ -21038,7 +21029,7 @@ fn zirReify(...@@ -21038,7 +21029,7 @@ fn zirReify(
21038 try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls),21029 try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls),
21039 ).?);21030 ).?);
2104021031
21041 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {21032 if (!try sema.intFitsInType(alignment_val, .u32, null)) {
21042 return sema.fail(block, src, "alignment must fit in 'u32'", .{});21033 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
21043 }21034 }
2104421035
...@@ -21174,7 +21165,7 @@ fn zirReify(...@@ -21174,7 +21165,7 @@ fn zirReify(
21174 },21165 },
21175 .error_set => {21166 .error_set => {
21176 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse21167 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse
21177 return Air.internedToRef(Type.anyerror.toIntern());21168 return .anyerror_type;
2117821169
21179 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{ .simple = .error_set_contents });21170 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{ .simple = .error_set_contents });
2118021171
...@@ -21776,7 +21767,7 @@ fn reifyUnion(...@@ -21776,7 +21767,7 @@ fn reifyUnion(
21776 errdefer if (!has_explicit_tag) ip.remove(pt.tid, enum_tag_ty); // remove generated tag type on error21767 errdefer if (!has_explicit_tag) ip.remove(pt.tid, enum_tag_ty); // remove generated tag type on error
2177721768
21778 for (field_types) |field_ty_ip| {21769 for (field_types) |field_ty_ip| {
21779 const field_ty = Type.fromInterned(field_ty_ip);21770 const field_ty: Type = .fromInterned(field_ty_ip);
21780 if (field_ty.zigTypeTag(zcu) == .@"opaque") {21771 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
21781 return sema.failWithOwnedErrorMsg(block, msg: {21772 return sema.failWithOwnedErrorMsg(block, msg: {
21782 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});21773 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(...@@ -22060,7 +22051,7 @@ fn reifyStruct(
22060 }22051 }
2206122052
22062 if (any_aligned_fields) {22053 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)) {
22064 return sema.fail(block, src, "alignment must fit in 'u32'", .{});22055 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
22065 }22056 }
2206622057
...@@ -22149,7 +22140,7 @@ fn reifyStruct(...@@ -22149,7 +22140,7 @@ fn reifyStruct(
22149 if (layout == .@"packed") {22140 if (layout == .@"packed") {
22150 var fields_bit_sum: u64 = 0;22141 var fields_bit_sum: u64 = 0;
22151 for (0..struct_type.field_types.len) |field_idx| {22142 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]);
22153 field_ty.resolveLayout(pt) catch |err| switch (err) {22144 field_ty.resolveLayout(pt) catch |err| switch (err) {
22154 error.AnalysisFail => {22145 error.AnalysisFail => {
22155 const msg = sema.err orelse return err;22146 const msg = sema.err orelse return err;
...@@ -22325,7 +22316,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22325,7 +22316,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22325 if (block.wantSafety()) {22316 if (block.wantSafety()) {
22326 const len = dest_ty.vectorLen(zcu);22317 const len = dest_ty.vectorLen(zcu);
22327 for (0..len) |i| {22318 for (0..len) |i| {
22328 const idx_ref = try pt.intRef(Type.usize, i);22319 const idx_ref = try pt.intRef(.usize, i);
22329 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);22320 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);
22330 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()));22321 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()));
22331 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);22322 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...@@ -22358,7 +22349,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22358 const len = dest_ty.vectorLen(zcu);22349 const len = dest_ty.vectorLen(zcu);
22359 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);22350 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22360 for (new_elems, 0..) |*new_elem, i| {22351 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);
22362 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);22353 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
22363 const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);22354 const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);
22364 if (block.wantSafety()) {22355 if (block.wantSafety()) {
...@@ -22408,7 +22399,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22408,7 +22399,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22408 const len = operand_ty.vectorLen(zcu);22399 const len = operand_ty.vectorLen(zcu);
22409 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);22400 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22410 for (new_elems, 0..) |*new_elem, i| {22401 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);
22412 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);22403 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
22413 new_elem.* = try block.addTyOp(.float_from_int, dest_scalar_ty, old_elem);22404 new_elem.* = try block.addTyOp(.float_from_int, dest_scalar_ty, old_elem);
22414 }22405 }
...@@ -22431,10 +22422,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22431,10 +22422,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22431 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);22422 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);
2243222423
22433 const is_vector = dest_ty.zigTypeTag(zcu) == .vector;22424 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: {
22435 const len = dest_ty.vectorLen(zcu);22426 const len = dest_ty.vectorLen(zcu);
22436 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });22427 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });
22437 } else Type.usize;22428 } else .usize;
2243822429
22439 const operand_coerced = try sema.coerce(block, operand_ty, operand_res, operand_src);22430 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!...@@ -22495,7 +22486,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22495 if (ptr_align.compare(.gt, .@"1")) {22486 if (ptr_align.compare(.gt, .@"1")) {
22496 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;22487 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
22497 const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(22488 const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(
22498 Type.usize,22489 .usize,
22499 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|22490 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
22500 align_bytes_minus_1 & mask22491 align_bytes_minus_1 & mask
22501 else22492 else
...@@ -22516,7 +22507,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22516,7 +22507,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22516 const len = dest_ty.vectorLen(zcu);22507 const len = dest_ty.vectorLen(zcu);
22517 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .@"fn")) {22508 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .@"fn")) {
22518 for (0..len) |i| {22509 for (0..len) |i| {
22519 const idx_ref = try pt.intRef(Type.usize, i);22510 const idx_ref = try pt.intRef(.usize, i);
22520 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);22511 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22521 if (!ptr_ty.isAllowzeroPtr(zcu)) {22512 if (!ptr_ty.isAllowzeroPtr(zcu)) {
22522 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);22513 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!...@@ -22525,7 +22516,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22525 if (ptr_align.compare(.gt, .@"1")) {22516 if (ptr_align.compare(.gt, .@"1")) {
22526 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;22517 const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
22527 const align_mask = Air.internedToRef((try pt.intValue(22518 const align_mask = Air.internedToRef((try pt.intValue(
22528 Type.usize,22519 .usize,
22529 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|22520 if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
22530 align_bytes_minus_1 & mask22521 align_bytes_minus_1 & mask
22531 else22522 else
...@@ -22540,7 +22531,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22540,7 +22531,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2254022531
22541 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);22532 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22542 for (new_elems, 0..) |*new_elem, i| {22533 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);
22544 const old_elem = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);22535 const old_elem = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22545 new_elem.* = try block.addBitCast(ptr_ty, old_elem);22536 new_elem.* = try block.addBitCast(ptr_ty, old_elem);
22546 }22537 }
...@@ -22918,12 +22909,12 @@ fn ptrCastFull(...@@ -22918,12 +22909,12 @@ fn ptrCastFull(
22918 }22909 }
2291922910
22920 check_child: {22911 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: {
22922 // *[n]T -> []T22913 // *[n]T -> []T
22923 break :blk Type.fromInterned(src_info.child).childType(zcu);22914 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
22928 const imc_res = try sema.coerceInMemoryAllowed(22919 const imc_res = try sema.coerceInMemoryAllowed(
22929 block,22920 block,
...@@ -22956,7 +22947,7 @@ fn ptrCastFull(...@@ -22956,7 +22947,7 @@ fn ptrCastFull(
22956 }22947 }
22957 if (is_array_ptr_to_slice) {22948 if (is_array_ptr_to_slice) {
22958 // [*]nT -> []T22949 // [*]nT -> []T
22959 const arr_ty = Type.fromInterned(src_info.child);22950 const arr_ty: Type = .fromInterned(src_info.child);
22960 if (arr_ty.sentinel(zcu)) |src_sentinel| {22951 if (arr_ty.sentinel(zcu)) |src_sentinel| {
22961 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);22952 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
22962 if (dest_info.sentinel == coerced_sent) break :check_sent;22953 if (dest_info.sentinel == coerced_sent) break :check_sent;
...@@ -23158,7 +23149,7 @@ fn ptrCastFull(...@@ -23158,7 +23149,7 @@ fn ptrCastFull(
23158 if (dest_info.flags.size == .slice) {23149 if (dest_info.flags.size == .slice) {
23159 // Because the operand is comptime-known and not `null`, the slice length has already been computed:23150 // Because the operand is comptime-known and not `null`, the slice length has already been computed:
23160 const len: Value = switch (dest_slice_len.?) {23151 const len: Value = switch (dest_slice_len.?) {
23161 .undef => try pt.undefValue(.usize),23152 .undef => .undef_usize,
23162 .constant => |n| try pt.intValue(.usize, n),23153 .constant => |n| try pt.intValue(.usize, n),
23163 .equal_runtime_src_slice => unreachable,23154 .equal_runtime_src_slice => unreachable,
23164 .change_runtime_src_slice => unreachable,23155 .change_runtime_src_slice => unreachable,
...@@ -23267,7 +23258,7 @@ fn ptrCastFull(...@@ -23267,7 +23258,7 @@ fn ptrCastFull(
23267 if (need_align_check) {23258 if (need_align_check) {
23268 assert(operand_ptr_int != .none);23259 assert(operand_ptr_int != .none);
23269 const align_mask = try pt.intRef(.usize, mask: {23260 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);
23271 break :mask (dest_align.toByteUnits().? - 1) & target_ptr_mask;23262 break :mask (dest_align.toByteUnits().? - 1) & target_ptr_mask;
23272 });23263 });
23273 const ptr_masked = try block.addBinOp(.bit_and, operand_ptr_int, align_mask);23264 const ptr_masked = try block.addBinOp(.bit_and, operand_ptr_int, align_mask);
...@@ -23288,7 +23279,7 @@ fn ptrCastFull(...@@ -23288,7 +23279,7 @@ fn ptrCastFull(
23288 assert(need_operand_ptr);23279 assert(need_operand_ptr);
2328923280
23290 const result_len: Air.Inst.Ref = switch (dest_slice_len.?) {23281 const result_len: Air.Inst.Ref = switch (dest_slice_len.?) {
23291 .undef => try pt.undefRef(.usize),23282 .undef => .undef_usize,
23292 .constant => |n| try pt.intRef(.usize, n),23283 .constant => |n| try pt.intRef(.usize, n),
23293 .equal_runtime_src_slice => len: {23284 .equal_runtime_src_slice => len: {
23294 assert(need_operand_len);23285 assert(need_operand_len);
...@@ -23658,13 +23649,13 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -23658,13 +23649,13 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2365823649
23659fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23650fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23660 const offset = try sema.bitOffsetOf(block, inst);23651 const offset = try sema.bitOffsetOf(block, inst);
23661 return sema.pt.intRef(Type.comptime_int, offset);23652 return sema.pt.intRef(.comptime_int, offset);
23662}23653}
2366323654
23664fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23655fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23665 const offset = try sema.bitOffsetOf(block, inst);23656 const offset = try sema.bitOffsetOf(block, inst);
23666 // TODO reminder to make this a compile error for packed structs23657 // 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);
23668}23659}
2366923660
23670fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {23661fn 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...@@ -23705,7 +23696,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
23705 if (i == field_index) {23696 if (i == field_index) {
23706 return bit_sum;23697 return bit_sum;
23707 }23698 }
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]);
23709 bit_sum += field_ty.bitSize(zcu);23700 bit_sum += field_ty.bitSize(zcu);
23710 } else unreachable;23701 } else unreachable;
23711 },23702 },
...@@ -24620,10 +24611,10 @@ fn analyzeShuffle(...@@ -24620,10 +24611,10 @@ fn analyzeShuffle(
2462024611
24621 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);24612 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
24622 for (@intCast(0)..@intCast(min_len)) |i| {24613 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();
24624 }24615 }
24625 for (@intCast(min_len)..@intCast(max_len)) |i| {24616 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;
24627 }24618 }
24628 const expand_mask = try pt.intern(.{ .aggregate = .{24619 const expand_mask = try pt.intern(.{ .aggregate = .{
24629 .ty = (try pt.vectorType(.{ .len = @intCast(max_len), .child = .comptime_int_type })).toIntern(),24620 .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...@@ -25087,7 +25078,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25087 if (parent_ptr_info.flags.size != .one) {25078 if (parent_ptr_info.flags.size != .one) {
25088 return sema.fail(block, inst_src, "expected single pointer type, found '{}'", .{parent_ptr_ty.fmt(pt)});25079 return sema.fail(block, inst_src, "expected single pointer type, found '{}'", .{parent_ptr_ty.fmt(pt)});
25089 }25080 }
25090 const parent_ty = Type.fromInterned(parent_ptr_info.child);25081 const parent_ty: Type = .fromInterned(parent_ptr_info.child);
25091 switch (parent_ty.zigTypeTag(zcu)) {25082 switch (parent_ty.zigTypeTag(zcu)) {
25092 .@"struct", .@"union" => {},25083 .@"struct", .@"union" => {},
25093 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{}'", .{parent_ptr_ty.fmt(pt)}),25084 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(...@@ -25741,7 +25732,7 @@ fn zirMemcpy(
25741 if (try sema.resolveDefinedValue(block, dest_src, dest_len)) |dest_len_val| {25732 if (try sema.resolveDefinedValue(block, dest_src, dest_len)) |dest_len_val| {
25742 len_val = dest_len_val;25733 len_val = dest_len_val;
25743 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {25734 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))) {
25745 const msg = msg: {25736 const msg = msg: {
25746 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});25737 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
25747 errdefer msg.destroy(sema.gpa);25738 errdefer msg.destroy(sema.gpa);
...@@ -25952,7 +25943,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25952,7 +25943,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25952 const dest_elem_ty: Type = dest_elem_ty: {25943 const dest_elem_ty: Type = dest_elem_ty: {
25953 const ptr_info = dest_ptr_ty.ptrInfo(zcu);25944 const ptr_info = dest_ptr_ty.ptrInfo(zcu);
25954 switch (ptr_info.flags.size) {25945 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),
25956 .one => {25947 .one => {
25957 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) {25948 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) {
25958 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu);25949 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...@@ -26118,7 +26109,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26118 extra_index += body.len;26109 extra_index += body.len;
26119 if (extra.data.bits.ret_ty_is_generic) break :blk .generic_poison;26110 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 });
26122 const ty = val.toType();26113 const ty = val.toType();
26123 break :blk ty;26114 break :blk ty;
26124 } else if (extra.data.bits.has_ret_ty_ref) blk: {26115 } 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...@@ -26129,7 +26120,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26129 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);26120 const ret_ty_air_ref = try sema.resolveInst(ret_ty_ref);
26130 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });26121 const ret_ty_val = try sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty });
26131 break :blk ret_ty_val.toType();26122 break :blk ret_ty_val.toType();
26132 } else Type.void;26123 } else .void;
2613326124
26134 const noalias_bits: u32 = if (extra.data.bits.has_any_noalias) blk: {26125 const noalias_bits: u32 = if (extra.data.bits.has_any_noalias) blk: {
26135 const x = sema.code.extra[extra_index];26126 const x = sema.code.extra[extra_index];
...@@ -26223,7 +26214,7 @@ fn zirWasmMemorySize(...@@ -26223,7 +26214,7 @@ fn zirWasmMemorySize(
26223 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26214 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
26224 }26215 }
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 }));
26227 try sema.requireRuntimeBlock(block, builtin_src, null);26218 try sema.requireRuntimeBlock(block, builtin_src, null);
26228 return block.addInst(.{26219 return block.addInst(.{
26229 .tag = .wasm_memory_size,26220 .tag = .wasm_memory_size,
...@@ -26248,8 +26239,8 @@ fn zirWasmMemoryGrow(...@@ -26248,8 +26239,8 @@ fn zirWasmMemoryGrow(
26248 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26239 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
26249 }26240 }
2625026241
26251 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ .simple = .wasm_memory_index }));26242 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, .u32, .{ .simple = .wasm_memory_index }));
26252 const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);26243 const delta = try sema.coerce(block, .usize, try sema.resolveInst(extra.rhs), delta_src);
2625326244
26254 try sema.requireRuntimeBlock(block, builtin_src, null);26245 try sema.requireRuntimeBlock(block, builtin_src, null);
26255 return block.addInst(.{26246 return block.addInst(.{
...@@ -26484,7 +26475,7 @@ fn zirWorkItem(...@@ -26484,7 +26475,7 @@ fn zirWorkItem(
26484 },26475 },
26485 }26476 }
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 }));
26488 try sema.requireRuntimeBlock(block, builtin_src, null);26479 try sema.requireRuntimeBlock(block, builtin_src, null);
2648926480
26490 return block.addInst(.{26481 return block.addInst(.{
...@@ -26552,7 +26543,7 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -26552,7 +26543,7 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
26552 const inline_tag_val = try pt.enumValue(26543 const inline_tag_val = try pt.enumValue(
26553 callconv_tag_ty,26544 callconv_tag_ty,
26554 (try pt.intValue(26545 (try pt.intValue(
26555 Type.u8,26546 .u8,
26556 @intFromEnum(std.builtin.CallingConvention.@"inline"),26547 @intFromEnum(std.builtin.CallingConvention.@"inline"),
26557 )).toIntern(),26548 )).toIntern(),
26558 );26549 );
...@@ -26760,7 +26751,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26760,7 +26751,7 @@ fn explainWhyTypeIsComptimeInner(
2676026751
26761 if (zcu.typeToStruct(ty)) |struct_type| {26752 if (zcu.typeToStruct(ty)) |struct_type| {
26762 for (0..struct_type.field_types.len) |i| {26753 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]);
26764 const field_src: LazySrcLoc = .{26755 const field_src: LazySrcLoc = .{
26765 .base_node_inst = struct_type.zir_index,26756 .base_node_inst = struct_type.zir_index,
26766 .offset = .{ .container_field_type = @intCast(i) },26757 .offset = .{ .container_field_type = @intCast(i) },
...@@ -26780,7 +26771,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26780,7 +26771,7 @@ fn explainWhyTypeIsComptimeInner(
2678026771
26781 if (zcu.typeToUnion(ty)) |union_obj| {26772 if (zcu.typeToUnion(ty)) |union_obj| {
26782 for (0..union_obj.field_types.len) |i| {26773 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]);
26784 const field_src: LazySrcLoc = .{26775 const field_src: LazySrcLoc = .{
26785 .base_node_inst = union_obj.zir_index,26776 .base_node_inst = union_obj.zir_index,
26786 .offset = .{ .container_field_type = @intCast(i) },26777 .offset = .{ .container_field_type = @intCast(i) },
...@@ -27171,7 +27162,7 @@ fn addSafetyCheckUnwrapError(...@@ -27171,7 +27162,7 @@ fn addSafetyCheckUnwrapError(
2717127162
27172 defer fail_block.instructions.deinit(gpa);27163 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);
27175 try safetyPanicUnwrapError(sema, &fail_block, src, err);27166 try safetyPanicUnwrapError(sema, &fail_block, src, err);
2717627167
27177 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);27168 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);
...@@ -27344,7 +27335,7 @@ fn fieldVal(...@@ -27344,7 +27335,7 @@ fn fieldVal(
27344 switch (inner_ty.zigTypeTag(zcu)) {27335 switch (inner_ty.zigTypeTag(zcu)) {
27345 .array => {27336 .array => {
27346 if (field_name.eqlSlice("len", ip)) {27337 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());
27348 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {27339 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27349 const ptr_info = object_ty.ptrInfo(zcu);27340 const ptr_info = object_ty.ptrInfo(zcu);
27350 const result_ty = try pt.ptrTypeSema(.{27341 const result_ty = try pt.ptrTypeSema(.{
...@@ -27527,7 +27518,7 @@ fn fieldPtr(...@@ -27527,7 +27518,7 @@ fn fieldPtr(
27527 switch (inner_ty.zigTypeTag(zcu)) {27518 switch (inner_ty.zigTypeTag(zcu)) {
27528 .array => {27519 .array => {
27529 if (field_name.eqlSlice("len", ip)) {27520 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));
27531 return uavRef(sema, int_val.toIntern());27522 return uavRef(sema, int_val.toIntern());
27532 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {27523 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27533 const ptr_info = object_ty.ptrInfo(zcu);27524 const ptr_info = object_ty.ptrInfo(zcu);
...@@ -27769,12 +27760,12 @@ fn fieldCallBind(...@@ -27769,12 +27760,12 @@ fn fieldCallBind(
27769 if (zcu.typeToStruct(concrete_ty)) |struct_type| {27760 if (zcu.typeToStruct(concrete_ty)) |struct_type| {
27770 const field_index = struct_type.nameIndex(ip, field_name) orelse27761 const field_index = struct_type.nameIndex(ip, field_name) orelse
27771 break :find_field;27762 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
27774 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);27765 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
27775 } else if (concrete_ty.isTuple(zcu)) {27766 } else if (concrete_ty.isTuple(zcu)) {
27776 if (field_name.eqlSlice("len", ip)) {27767 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)) };
27778 }27769 }
27779 if (field_name.toUnsigned(ip)) |field_index| {27770 if (field_name.toUnsigned(ip)) |field_index| {
27780 if (field_index >= concrete_ty.structFieldCount(zcu)) break :find_field;27771 if (field_index >= concrete_ty.structFieldCount(zcu)) break :find_field;
...@@ -27817,7 +27808,7 @@ fn fieldCallBind(...@@ -27817,7 +27808,7 @@ fn fieldCallBind(
27817 if (zcu.typeToFunc(decl_type)) |func_type| f: {27808 if (zcu.typeToFunc(decl_type)) |func_type| f: {
27818 if (func_type.param_types.len == 0) break :f;27809 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]);
27821 if (first_param_type.isGenericPoison() or27812 if (first_param_type.isGenericPoison() or
27822 (first_param_type.zigTypeTag(zcu) == .pointer and27813 (first_param_type.zigTypeTag(zcu) == .pointer and
27823 (first_param_type.ptrSize(zcu) == .one or27814 (first_param_type.ptrSize(zcu) == .one or
...@@ -28003,7 +27994,7 @@ fn structFieldPtr(...@@ -28003,7 +27994,7 @@ fn structFieldPtr(
2800327994
28004 if (struct_ty.isTuple(zcu)) {27995 if (struct_ty.isTuple(zcu)) {
28005 if (field_name.eqlSlice("len", ip)) {27996 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));
28007 return sema.analyzeRef(block, src, len_inst);27998 return sema.analyzeRef(block, src, len_inst);
28008 }27999 }
28009 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);28000 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
...@@ -28134,7 +28125,7 @@ fn structFieldVal(...@@ -28134,7 +28125,7 @@ fn structFieldVal(
28134 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);28125 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
28135 }28126 }
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]);
28138 if (try sema.typeHasOnePossibleValue(field_ty)) |field_val|28129 if (try sema.typeHasOnePossibleValue(field_ty)) |field_val|
28139 return Air.internedToRef(field_val.toIntern());28130 return Air.internedToRef(field_val.toIntern());
2814028131
...@@ -28167,7 +28158,7 @@ fn tupleFieldVal(...@@ -28167,7 +28158,7 @@ fn tupleFieldVal(
28167 const pt = sema.pt;28158 const pt = sema.pt;
28168 const zcu = pt.zcu;28159 const zcu = pt.zcu;
28169 if (field_name.eqlSlice("len", &zcu.intern_pool)) {28160 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));
28171 }28162 }
28172 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);28163 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
28173 return sema.tupleFieldValByIndex(block, tuple_byval, field_index, tuple_ty);28164 return sema.tupleFieldValByIndex(block, tuple_byval, field_index, tuple_ty);
...@@ -28220,7 +28211,7 @@ fn tupleFieldValByIndex(...@@ -28220,7 +28211,7 @@ fn tupleFieldValByIndex(
28220 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {28211 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {
28221 .undef => pt.undefRef(field_ty),28212 .undef => pt.undefRef(field_ty),
28222 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {28213 .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)),
28224 .elems => |elems| Value.fromInterned(elems[field_index]),28215 .elems => |elems| Value.fromInterned(elems[field_index]),
28225 .repeated_elem => |elem| Value.fromInterned(elem),28216 .repeated_elem => |elem| Value.fromInterned(elem),
28226 }.toIntern()),28217 }.toIntern()),
...@@ -28253,7 +28244,7 @@ fn unionFieldPtr(...@@ -28253,7 +28244,7 @@ fn unionFieldPtr(
28253 try union_ty.resolveFields(pt);28244 try union_ty.resolveFields(pt);
28254 const union_obj = zcu.typeToUnion(union_ty).?;28245 const union_obj = zcu.typeToUnion(union_ty).?;
28255 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);28246 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]);
28257 const ptr_field_ty = try pt.ptrTypeSema(.{28248 const ptr_field_ty = try pt.ptrTypeSema(.{
28258 .child = field_ty.toIntern(),28249 .child = field_ty.toIntern(),
28259 .flags = .{28250 .flags = .{
...@@ -28295,8 +28286,8 @@ fn unionFieldPtr(...@@ -28295,8 +28286,8 @@ fn unionFieldPtr(
28295 break :ct;28286 break :ct;
28296 }28287 }
28297 // Store to the union to initialize the tag.28288 // 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);28289 const field_tag = try pt.enumValueFieldIndex(.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28299 const payload_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);28290 const payload_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
28300 const new_union_val = try pt.unionValue(union_ty, field_tag, try pt.undefValue(payload_ty));28291 const new_union_val = try pt.unionValue(union_ty, field_tag, try pt.undefValue(payload_ty));
28301 try sema.storePtrVal(block, src, union_ptr_val, new_union_val, union_ty);28292 try sema.storePtrVal(block, src, union_ptr_val, new_union_val, union_ty);
28302 } else {28293 } else {
...@@ -28306,7 +28297,7 @@ fn unionFieldPtr(...@@ -28306,7 +28297,7 @@ fn unionFieldPtr(
28306 return sema.failWithUseOfUndef(block, src);28297 return sema.failWithUseOfUndef(block, src);
28307 }28298 }
28308 const un = ip.indexToKey(union_val.toIntern()).un;28299 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);
28310 const tag_matches = un.tag == field_tag.toIntern();28301 const tag_matches = un.tag == field_tag.toIntern();
28311 if (!tag_matches) {28302 if (!tag_matches) {
28312 const msg = msg: {28303 const msg = msg: {
...@@ -28332,11 +28323,11 @@ fn unionFieldPtr(...@@ -28332,11 +28323,11 @@ fn unionFieldPtr(
28332 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and28323 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
28333 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)28324 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
28334 {28325 {
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);
28336 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());28327 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
28337 // TODO would it be better if get_union_tag supported pointers to unions?28328 // TODO would it be better if get_union_tag supported pointers to unions?
28338 const union_val = try block.addTyOp(.load, union_ty, union_ptr);28329 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);
28340 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);28331 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);
28341 }28332 }
28342 if (field_ty.zigTypeTag(zcu) == .noreturn) {28333 if (field_ty.zigTypeTag(zcu) == .noreturn) {
...@@ -28363,14 +28354,14 @@ fn unionFieldVal(...@@ -28363,14 +28354,14 @@ fn unionFieldVal(
28363 try union_ty.resolveFields(pt);28354 try union_ty.resolveFields(pt);
28364 const union_obj = zcu.typeToUnion(union_ty).?;28355 const union_obj = zcu.typeToUnion(union_ty).?;
28365 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);28356 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]);
28367 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, zcu).?);28358 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, zcu).?);
2836828359
28369 if (try sema.resolveValue(union_byval)) |union_val| {28360 if (try sema.resolveValue(union_byval)) |union_val| {
28370 if (union_val.isUndef(zcu)) return pt.undefRef(field_ty);28361 if (union_val.isUndef(zcu)) return pt.undefRef(field_ty);
2837128362
28372 const un = ip.indexToKey(union_val.toIntern()).un;28363 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);
28374 const tag_matches = un.tag == field_tag.toIntern();28365 const tag_matches = un.tag == field_tag.toIntern();
28375 switch (union_obj.flagsUnordered(ip).layout) {28366 switch (union_obj.flagsUnordered(ip).layout) {
28376 .auto => {28367 .auto => {
...@@ -28408,9 +28399,9 @@ fn unionFieldVal(...@@ -28408,9 +28399,9 @@ fn unionFieldVal(
28408 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and28399 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
28409 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)28400 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
28410 {28401 {
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);
28412 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());28403 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);
28414 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);28405 try sema.addSafetyCheckInactiveUnionField(block, src, active_tag, wanted_tag);
28415 }28406 }
28416 if (field_ty.zigTypeTag(zcu) == .noreturn) {28407 if (field_ty.zigTypeTag(zcu) == .noreturn) {
...@@ -28540,7 +28531,7 @@ fn elemVal(...@@ -28540,7 +28531,7 @@ fn elemVal(
2854028531
28541 // TODO in case of a vector of pointers, we need to detect whether the element28532 // TODO in case of a vector of pointers, we need to detect whether the element
28542 // index is a scalar or vector instead of unconditionally casting to usize.28533 // 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
28545 switch (indexable_ty.zigTypeTag(zcu)) {28536 switch (indexable_ty.zigTypeTag(zcu)) {
28546 .pointer => switch (indexable_ty.ptrSize(zcu)) {28537 .pointer => switch (indexable_ty.ptrSize(zcu)) {
...@@ -28795,7 +28786,7 @@ fn elemValArray(...@@ -28795,7 +28786,7 @@ fn elemValArray(
28795 if (oob_safety and block.wantSafety()) {28786 if (oob_safety and block.wantSafety()) {
28796 // Runtime check is only needed if unable to comptime check.28787 // Runtime check is only needed if unable to comptime check.
28797 if (maybe_index_val == null) {28788 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);
28799 const cmp_op: Air.Inst.Tag = if (array_sent != null) .cmp_lte else .cmp_lt;28790 const cmp_op: Air.Inst.Tag = if (array_sent != null) .cmp_lte else .cmp_lt;
28800 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);28791 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
28801 }28792 }
...@@ -28860,7 +28851,7 @@ fn elemPtrArray(...@@ -28860,7 +28851,7 @@ fn elemPtrArray(
2886028851
28861 // Runtime check is only needed if unable to comptime check.28852 // Runtime check is only needed if unable to comptime check.
28862 if (oob_safety and block.wantSafety() and offset == null) {28853 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);
28864 const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt;28855 const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt;
28865 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);28856 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
28866 }28857 }
...@@ -28917,9 +28908,9 @@ fn elemValSlice(...@@ -28917,9 +28908,9 @@ fn elemValSlice(
2891728908
28918 if (oob_safety and block.wantSafety()) {28909 if (oob_safety and block.wantSafety()) {
28919 const len_inst = if (maybe_slice_val) |slice_val|28910 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))
28921 else28912 else
28922 try block.addTyOp(.slice_len, Type.usize, slice);28913 try block.addTyOp(.slice_len, .usize, slice);
28923 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;28914 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
28924 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);28915 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
28925 }28916 }
...@@ -28976,8 +28967,8 @@ fn elemPtrSlice(...@@ -28976,8 +28967,8 @@ fn elemPtrSlice(
28976 const len_inst = len: {28967 const len_inst = len: {
28977 if (maybe_undef_slice_val) |slice_val|28968 if (maybe_undef_slice_val) |slice_val|
28978 if (!slice_val.isUndef(zcu))28969 if (!slice_val.isUndef(zcu))
28979 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));28970 break :len try pt.intRef(.usize, try slice_val.sliceLen(pt));
28980 break :len try block.addTyOp(.slice_len, Type.usize, slice);28971 break :len try block.addTyOp(.slice_len, .usize, slice);
28981 };28972 };
28982 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;28973 const cmp_op: Air.Inst.Tag = if (slice_sent) .cmp_lte else .cmp_lt;
28983 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);28974 try sema.addSafetyCheckIndexOob(block, src, elem_index, len_inst, cmp_op);
...@@ -29142,7 +29133,7 @@ fn coerceExtra(...@@ -29142,7 +29133,7 @@ fn coerceExtra(
29142 if (!inst_ty.isSinglePointer(zcu)) break :single_item;29133 if (!inst_ty.isSinglePointer(zcu)) break :single_item;
29143 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;29134 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
29144 const ptr_elem_ty = inst_ty.childType(zcu);29135 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);
29146 if (array_ty.zigTypeTag(zcu) != .array) break :single_item;29137 if (array_ty.zigTypeTag(zcu) != .array) break :single_item;
29147 const array_elem_ty = array_ty.childType(zcu);29138 const array_elem_ty = array_ty.childType(zcu);
29148 if (array_ty.arrayLen(zcu) != 1) break :single_item;29139 if (array_ty.arrayLen(zcu) != 1) break :single_item;
...@@ -29164,7 +29155,7 @@ fn coerceExtra(...@@ -29164,7 +29155,7 @@ fn coerceExtra(
29164 const array_elem_type = array_ty.childType(zcu);29155 const array_elem_type = array_ty.childType(zcu);
29165 const dest_is_mut = !dest_info.flags.is_const;29156 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);
29168 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);29159 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);
29169 switch (elem_res) {29160 switch (elem_res) {
29170 .ok => {},29161 .ok => {},
...@@ -29225,7 +29216,7 @@ fn coerceExtra(...@@ -29225,7 +29216,7 @@ fn coerceExtra(
29225 // could be null.29216 // could be null.
29226 const src_elem_ty = inst_ty.childType(zcu);29217 const src_elem_ty = inst_ty.childType(zcu);
29227 const dest_is_mut = !dest_info.flags.is_const;29218 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);
29229 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src, maybe_inst_val)) {29220 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src, maybe_inst_val)) {
29230 .ok => {},29221 .ok => {},
29231 else => break :src_c_ptr,29222 else => break :src_c_ptr,
...@@ -29265,16 +29256,16 @@ fn coerceExtra(...@@ -29265,16 +29256,16 @@ fn coerceExtra(
29265 .byte_offset = 0,29256 .byte_offset = 0,
29266 } })),29257 } })),
29267 .comptime_int => {29258 .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) {
29269 error.NotCoercible => break :pointer,29260 error.NotCoercible => break :pointer,
29270 else => |e| return e,29261 else => |e| return e,
29271 };29262 };
29272 return try sema.coerceCompatiblePtrs(block, dest_ty, addr, inst_src);29263 return try sema.coerceCompatiblePtrs(block, dest_ty, addr, inst_src);
29273 },29264 },
29274 .int => {29265 .int => {
29275 const ptr_size_ty = switch (inst_ty.intInfo(zcu).signedness) {29266 const ptr_size_ty: Type = switch (inst_ty.intInfo(zcu).signedness) {
29276 .signed => Type.isize,29267 .signed => .isize,
29277 .unsigned => Type.usize,29268 .unsigned => .usize,
29278 };29269 };
29279 const addr = sema.coerceExtra(block, ptr_size_ty, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {29270 const addr = sema.coerceExtra(block, ptr_size_ty, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {
29280 error.NotCoercible => {29271 error.NotCoercible => {
...@@ -29291,8 +29282,8 @@ fn coerceExtra(...@@ -29291,8 +29282,8 @@ fn coerceExtra(
29291 const inst_info = inst_ty.ptrInfo(zcu);29282 const inst_info = inst_ty.ptrInfo(zcu);
29292 switch (try sema.coerceInMemoryAllowed(29283 switch (try sema.coerceInMemoryAllowed(
29293 block,29284 block,
29294 Type.fromInterned(dest_info.child),29285 .fromInterned(dest_info.child),
29295 Type.fromInterned(inst_info.child),29286 .fromInterned(inst_info.child),
29296 !dest_info.flags.is_const,29287 !dest_info.flags.is_const,
29297 target,29288 target,
29298 dest_ty_src,29289 dest_ty_src,
...@@ -29305,7 +29296,7 @@ fn coerceExtra(...@@ -29305,7 +29296,7 @@ fn coerceExtra(
29305 if (inst_info.flags.size == .slice) {29296 if (inst_info.flags.size == .slice) {
29306 assert(dest_info.sentinel == .none);29297 assert(dest_info.sentinel == .none);
29307 if (inst_info.sentinel == .none or29298 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())
29309 break :p;29300 break :p;
2931029301
29311 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);29302 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
...@@ -29364,8 +29355,8 @@ fn coerceExtra(...@@ -29364,8 +29355,8 @@ fn coerceExtra(
2936429355
29365 switch (try sema.coerceInMemoryAllowed(29356 switch (try sema.coerceInMemoryAllowed(
29366 block,29357 block,
29367 Type.fromInterned(dest_info.child),29358 .fromInterned(dest_info.child),
29368 Type.fromInterned(inst_info.child),29359 .fromInterned(inst_info.child),
29369 !dest_info.flags.is_const,29360 !dest_info.flags.is_const,
29370 target,29361 target,
29371 dest_ty_src,29362 dest_ty_src,
...@@ -29378,7 +29369,7 @@ fn coerceExtra(...@@ -29378,7 +29369,7 @@ fn coerceExtra(
2937829369
29379 if (dest_info.sentinel == .none or inst_info.sentinel == .none or29370 if (dest_info.sentinel == .none or inst_info.sentinel == .none or
29380 Air.internedToRef(dest_info.sentinel) !=29371 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)))
29382 break :p;29373 break :p;
2938329374
29384 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);29375 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
...@@ -30658,8 +30649,8 @@ fn coerceInMemoryAllowedPtrs(...@@ -30658,8 +30649,8 @@ fn coerceInMemoryAllowedPtrs(
30658 } };30649 } };
30659 }30650 }
3066030651
30661 const dest_child = Type.fromInterned(dest_info.child);30652 const dest_child: Type = .fromInterned(dest_info.child);
30662 const src_child = Type.fromInterned(src_info.child);30653 const src_child: Type = .fromInterned(src_info.child);
30663 const child = try sema.coerceInMemoryAllowed(30654 const child = try sema.coerceInMemoryAllowed(
30664 block,30655 block,
30665 dest_child,30656 dest_child,
...@@ -30731,7 +30722,7 @@ fn coerceInMemoryAllowedPtrs(...@@ -30731,7 +30722,7 @@ fn coerceInMemoryAllowedPtrs(
30731 .none => Value.@"unreachable",30722 .none => Value.@"unreachable",
30732 else => Value.fromInterned(dest_info.sentinel),30723 else => Value.fromInterned(dest_info.sentinel),
30733 },30724 },
30734 .ty = Type.fromInterned(dest_info.child),30725 .ty = .fromInterned(dest_info.child),
30735 } };30726 } };
30736 }30727 }
3073730728
...@@ -30794,8 +30785,8 @@ fn coerceVarArgParam(...@@ -30794,8 +30785,8 @@ fn coerceVarArgParam(
30794 const inst_bits = uncasted_ty.floatBits(target);30785 const inst_bits = uncasted_ty.floatBits(target);
30795 if (inst_bits >= double_bits) break :float inst;30786 if (inst_bits >= double_bits) break :float inst;
30796 switch (double_bits) {30787 switch (double_bits) {
30797 32 => break :float try sema.coerce(block, Type.f32, inst, inst_src),30788 32 => break :float try sema.coerce(block, .f32, inst, inst_src),
30798 64 => break :float try sema.coerce(block, Type.f64, inst, inst_src),30789 64 => break :float try sema.coerce(block, .f64, inst, inst_src),
30799 else => unreachable,30790 else => unreachable,
30800 }30791 }
30801 },30792 },
...@@ -30807,22 +30798,22 @@ fn coerceVarArgParam(...@@ -30807,22 +30798,22 @@ fn coerceVarArgParam(
30807 .signed => .int,30798 .signed => .int,
30808 .unsigned => .uint,30799 .unsigned => .uint,
30809 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30800 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30810 .signed => Type.c_int,30801 .signed => .c_int,
30811 .unsigned => Type.c_uint,30802 .unsigned => .c_uint,
30812 }, inst, inst_src);30803 }, inst, inst_src);
30813 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {30804 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
30814 .signed => .long,30805 .signed => .long,
30815 .unsigned => .ulong,30806 .unsigned => .ulong,
30816 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30807 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30817 .signed => Type.c_long,30808 .signed => .c_long,
30818 .unsigned => Type.c_ulong,30809 .unsigned => .c_ulong,
30819 }, inst, inst_src);30810 }, inst, inst_src);
30820 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {30811 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
30821 .signed => .longlong,30812 .signed => .longlong,
30822 .unsigned => .ulonglong,30813 .unsigned => .ulonglong,
30823 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {30814 })) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
30824 .signed => Type.c_longlong,30815 .signed => .c_longlong,
30825 .unsigned => Type.c_ulonglong,30816 .unsigned => .c_ulonglong,
30826 }, inst, inst_src);30817 }, inst, inst_src);
30827 break :int inst;30818 break :int inst;
30828 } else inst,30819 } else inst,
...@@ -30889,7 +30880,7 @@ fn storePtr2(...@@ -30889,7 +30880,7 @@ fn storePtr2(
30889 while (i < field_count) : (i += 1) {30880 while (i < field_count) : (i += 1) {
30890 const elem_src = operand_src; // TODO better source location30881 const elem_src = operand_src; // TODO better source location
30891 const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i);30882 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);
30893 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false, true);30884 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false, true);
30894 try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store);30885 try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store);
30895 }30886 }
...@@ -31216,7 +31207,7 @@ fn coerceArrayPtrToSlice(...@@ -31216,7 +31207,7 @@ fn coerceArrayPtrToSlice(
31216 const slice_val = try pt.intern(.{ .slice = .{31207 const slice_val = try pt.intern(.{ .slice = .{
31217 .ty = dest_ty.toIntern(),31208 .ty = dest_ty.toIntern(),
31218 .ptr = slice_ptr.toIntern(),31209 .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(),
31220 } });31211 } });
31221 return Air.internedToRef(slice_val);31212 return Air.internedToRef(slice_val);
31222 }31213 }
...@@ -31358,7 +31349,7 @@ fn coerceEnumToUnion(...@@ -31358,7 +31349,7 @@ fn coerceEnumToUnion(
31358 };31349 };
3135931350
31360 const union_obj = zcu.typeToUnion(union_ty).?;31351 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]);
31362 try field_ty.resolveFields(pt);31353 try field_ty.resolveFields(pt);
31363 if (field_ty.zigTypeTag(zcu) == .noreturn) {31354 if (field_ty.zigTypeTag(zcu) == .noreturn) {
31364 const msg = msg: {31355 const msg = msg: {
...@@ -31448,7 +31439,7 @@ fn coerceEnumToUnion(...@@ -31448,7 +31439,7 @@ fn coerceEnumToUnion(
3144831439
31449 for (0..union_obj.field_types.len) |field_index| {31440 for (0..union_obj.field_types.len) |field_index| {
31450 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31441 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]);
31452 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;31443 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
31453 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{31444 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
31454 field_name.fmt(ip),31445 field_name.fmt(ip),
...@@ -31536,7 +31527,7 @@ fn coerceArrayLike(...@@ -31536,7 +31527,7 @@ fn coerceArrayLike(
31536 var runtime_src: ?LazySrcLoc = null;31527 var runtime_src: ?LazySrcLoc = null;
3153731528
31538 for (element_vals, element_refs, 0..) |*val, *ref, i| {31529 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());
31540 const src = inst_src; // TODO better source location31531 const src = inst_src; // TODO better source location
31541 const elem_src = inst_src; // TODO better source location31532 const elem_src = inst_src; // TODO better source location
31542 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);31533 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);
...@@ -31668,7 +31659,7 @@ fn coerceTupleToArrayPtrs(...@@ -31668,7 +31659,7 @@ fn coerceTupleToArrayPtrs(
31668 const zcu = pt.zcu;31659 const zcu = pt.zcu;
31669 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);31660 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31670 const ptr_info = ptr_array_ty.ptrInfo(zcu);31661 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);
31672 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);31663 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
31673 if (ptr_info.flags.alignment != .none) {31664 if (ptr_info.flags.alignment != .none) {
31674 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});31665 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});
...@@ -31721,14 +31712,14 @@ fn coerceTupleToTuple(...@@ -31721,14 +31712,14 @@ fn coerceTupleToTuple(
31721 const field_index: u32 = @intCast(field_index_usize);31712 const field_index: u32 = @intCast(field_index_usize);
3172231713
31723 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);31714 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);
31725 field_refs[field_index] = coerced;31716 field_refs[field_index] = coerced;
31726 if (default_val != .none) {31717 if (default_val != .none) {
31727 const init_val = (try sema.resolveValue(coerced)) orelse {31718 const init_val = (try sema.resolveValue(coerced)) orelse {
31728 return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field });31719 return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field });
31729 };31720 };
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)) {
31732 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);31723 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
31733 }31724 }
31734 }31725 }
...@@ -31885,7 +31876,7 @@ pub fn ensureNavResolved(sema: *Sema, block: *Block, src: LazySrcLoc, nav_index:...@@ -31885,7 +31876,7 @@ pub fn ensureNavResolved(sema: *Sema, block: *Block, src: LazySrcLoc, nav_index:
3188531876
31886fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {31877fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
31887 const pt = sema.pt;31878 const pt = sema.pt;
31888 const ptr_anyopaque_ty = try pt.singleConstPtrType(Type.anyopaque);31879 const ptr_anyopaque_ty = try pt.singleConstPtrType(.anyopaque);
31889 return Value.fromInterned(try pt.intern(.{ .opt = .{31880 return Value.fromInterned(try pt.intern(.{ .opt = .{
31890 .ty = (try pt.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),31881 .ty = (try pt.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),
31891 .val = if (opt_val) |val| (try pt.getCoerced(31882 .val = if (opt_val) |val| (try pt.getCoerced(
...@@ -32140,12 +32131,12 @@ fn analyzeSliceLen(...@@ -32140,12 +32131,12 @@ fn analyzeSliceLen(
32140 const zcu = pt.zcu;32131 const zcu = pt.zcu;
32141 if (try sema.resolveValue(slice_inst)) |slice_val| {32132 if (try sema.resolveValue(slice_inst)) |slice_val| {
32142 if (slice_val.isUndef(zcu)) {32133 if (slice_val.isUndef(zcu)) {
32143 return pt.undefRef(Type.usize);32134 return .undef_usize;
32144 }32135 }
32145 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));32136 return pt.intRef(.usize, try slice_val.sliceLen(pt));
32146 }32137 }
32147 try sema.requireRuntimeBlock(block, src, null);32138 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);
32149}32140}
3215032141
32151fn analyzeIsNull(32142fn analyzeIsNull(
...@@ -32156,7 +32147,7 @@ fn analyzeIsNull(...@@ -32156,7 +32147,7 @@ fn analyzeIsNull(
32156) CompileError!Air.Inst.Ref {32147) CompileError!Air.Inst.Ref {
32157 const pt = sema.pt;32148 const pt = sema.pt;
32158 const zcu = pt.zcu;32149 const zcu = pt.zcu;
32159 const result_ty = Type.bool;32150 const result_ty: Type = .bool;
32160 if (try sema.resolveValue(operand)) |opt_val| {32151 if (try sema.resolveValue(operand)) |opt_val| {
32161 if (opt_val.isUndef(zcu)) {32152 if (opt_val.isUndef(zcu)) {
32162 return pt.undefRef(result_ty);32153 return pt.undefRef(result_ty);
...@@ -32224,7 +32215,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32224,7 +32215,7 @@ fn analyzeIsNonErrComptimeOnly(
32224 else => {},32215 else => {},
32225 }32216 }
32226 } else if (operand == .undef) {32217 } else if (operand == .undef) {
32227 return pt.undefRef(Type.bool);32218 return .undef_bool;
32228 } else if (@intFromEnum(operand) < InternPool.static_len) {32219 } else if (@intFromEnum(operand) < InternPool.static_len) {
32229 // None of the ref tags can be errors.32220 // None of the ref tags can be errors.
32230 return .bool_true;32221 return .bool_true;
...@@ -32308,14 +32299,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32308,14 +32299,7 @@ fn analyzeIsNonErrComptimeOnly(
32308 }32299 }
3230932300
32310 if (maybe_operand_val) |err_union| {32301 if (maybe_operand_val) |err_union| {
32311 if (err_union.isUndef(zcu)) {32302 return if (err_union.isUndef(zcu)) .undef_bool else if (err_union.getErrorName(zcu) == .none) .bool_true else .bool_false;
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 }
32319 }32303 }
32320 return .none;32304 return .none;
32321}32305}
...@@ -32412,8 +32396,8 @@ fn analyzeSlice(...@@ -32412,8 +32396,8 @@ fn analyzeSlice(
32412 );32396 );
3241332397
32414 const bounds_error_message = "slice of single-item pointer must have bounds [0..0], [0..1], or [1..1]";32398 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)) {32399 if (try sema.compareScalar(start_value, .neq, end_value, .comptime_int)) {
32416 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {32400 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, .comptime_int)) {
32417 const msg = msg: {32401 const msg = msg: {
32418 const msg = try sema.errMsg(start_src, bounds_error_message, .{});32402 const msg = try sema.errMsg(start_src, bounds_error_message, .{});
32419 errdefer msg.destroy(sema.gpa);32403 errdefer msg.destroy(sema.gpa);
...@@ -32429,7 +32413,7 @@ fn analyzeSlice(...@@ -32429,7 +32413,7 @@ fn analyzeSlice(
32429 break :msg msg;32413 break :msg msg;
32430 };32414 };
32431 return sema.failWithOwnedErrorMsg(block, msg);32415 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)) {
32433 const msg = msg: {32417 const msg = msg: {
32434 const msg = try sema.errMsg(end_src, bounds_error_message, .{});32418 const msg = try sema.errMsg(end_src, bounds_error_message, .{});
32435 errdefer msg.destroy(sema.gpa);32419 errdefer msg.destroy(sema.gpa);
...@@ -32447,7 +32431,7 @@ fn analyzeSlice(...@@ -32447,7 +32431,7 @@ fn analyzeSlice(
32447 return sema.failWithOwnedErrorMsg(block, msg);32431 return sema.failWithOwnedErrorMsg(block, msg);
32448 }32432 }
32449 } else {32433 } 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)) {
32451 return sema.fail(32435 return sema.fail(
32452 block,32436 block,
32453 end_src,32437 end_src,
...@@ -32512,7 +32496,7 @@ fn analyzeSlice(...@@ -32512,7 +32496,7 @@ fn analyzeSlice(
32512 break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(manyptr_ty_key), ptr_or_slice, ptr_src);32496 break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(manyptr_ty_key), ptr_or_slice, ptr_src);
32513 } else ptr_or_slice;32497 } 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);
32516 const new_ptr = try sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);32500 const new_ptr = try sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);
32517 const new_ptr_ty = sema.typeOf(new_ptr);32501 const new_ptr_ty = sema.typeOf(new_ptr);
3251832502
...@@ -32523,20 +32507,20 @@ fn analyzeSlice(...@@ -32523,20 +32507,20 @@ fn analyzeSlice(
32523 var end_is_len = uncasted_end_opt == .none;32507 var end_is_len = uncasted_end_opt == .none;
32524 const end = e: {32508 const end = e: {
32525 if (array_ty.zigTypeTag(zcu) == .array) {32509 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
32528 if (!end_is_len) {32512 if (!end_is_len) {
32529 const end = if (by_length) end: {32513 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);
32531 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);32515 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);32516 break :end try sema.coerce(block, .usize, uncasted_end, end_src);
32533 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);32517 } else try sema.coerce(block, .usize, uncasted_end_opt, end_src);
32534 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {32518 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32535 const len_s_val = try pt.intValue(32519 const len_s_val = try pt.intValue(
32536 Type.usize,32520 .usize,
32537 array_ty.arrayLenIncludingSentinel(zcu),32521 array_ty.arrayLenIncludingSentinel(zcu),
32538 );32522 );
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))) {
32540 const sentinel_label: []const u8 = if (array_ty.sentinel(zcu) != null)32524 const sentinel_label: []const u8 = if (array_ty.sentinel(zcu) != null)
32541 " +1 (sentinel)"32525 " +1 (sentinel)"
32542 else32526 else
...@@ -32557,7 +32541,7 @@ fn analyzeSlice(...@@ -32557,7 +32541,7 @@ fn analyzeSlice(
32557 // end_is_len is only true if we are NOT using the sentinel32541 // end_is_len is only true if we are NOT using the sentinel
32558 // length. For sentinel-length, we don't want the type to32542 // length. For sentinel-length, we don't want the type to
32559 // contain the sentinel.32543 // contain the sentinel.
32560 if (end_val.eql(len_val, Type.usize, zcu)) {32544 if (end_val.eql(len_val, .usize, zcu)) {
32561 end_is_len = true;32545 end_is_len = true;
32562 }32546 }
32563 }32547 }
...@@ -32568,10 +32552,10 @@ fn analyzeSlice(...@@ -32568,10 +32552,10 @@ fn analyzeSlice(
32568 } else if (slice_ty.isSlice(zcu)) {32552 } else if (slice_ty.isSlice(zcu)) {
32569 if (!end_is_len) {32553 if (!end_is_len) {
32570 const end = if (by_length) end: {32554 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);
32572 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);32556 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);32557 break :end try sema.coerce(block, .usize, uncasted_end, end_src);
32574 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);32558 } else try sema.coerce(block, .usize, uncasted_end_opt, end_src);
32575 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {32559 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32576 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {32560 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
32577 if (slice_val.isUndef(zcu)) {32561 if (slice_val.isUndef(zcu)) {
...@@ -32580,8 +32564,8 @@ fn analyzeSlice(...@@ -32580,8 +32564,8 @@ fn analyzeSlice(
32580 const has_sentinel = slice_ty.sentinel(zcu) != null;32564 const has_sentinel = slice_ty.sentinel(zcu) != null;
32581 const slice_len = try slice_val.sliceLen(pt);32565 const slice_len = try slice_val.sliceLen(pt);
32582 const len_plus_sent = slice_len + @intFromBool(has_sentinel);32566 const len_plus_sent = slice_len + @intFromBool(has_sentinel);
32583 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);32567 const slice_len_val_with_sentinel = try pt.intValue(.usize, len_plus_sent);
32584 if (!(try sema.compareAll(end_val, .lte, slice_len_val_with_sentinel, Type.usize))) {32568 if (!(try sema.compareAll(end_val, .lte, slice_len_val_with_sentinel, .usize))) {
32585 const sentinel_label: []const u8 = if (has_sentinel)32569 const sentinel_label: []const u8 = if (has_sentinel)
32586 " +1 (sentinel)"32570 " +1 (sentinel)"
32587 else32571 else
...@@ -32602,8 +32586,8 @@ fn analyzeSlice(...@@ -32602,8 +32586,8 @@ fn analyzeSlice(
32602 // If the slice has a sentinel, we consider end_is_len32586 // If the slice has a sentinel, we consider end_is_len
32603 // is only true if it equals the length WITHOUT the32587 // is only true if it equals the length WITHOUT the
32604 // sentinel, so we don't add a sentinel type.32588 // sentinel, so we don't add a sentinel type.
32605 const slice_len_val = try pt.intValue(Type.usize, slice_len);32589 const slice_len_val = try pt.intValue(.usize, slice_len);
32606 if (end_val.eql(slice_len_val, Type.usize, zcu)) {32590 if (end_val.eql(slice_len_val, .usize, zcu)) {
32607 end_is_len = true;32591 end_is_len = true;
32608 }32592 }
32609 }32593 }
...@@ -32614,10 +32598,10 @@ fn analyzeSlice(...@@ -32614,10 +32598,10 @@ fn analyzeSlice(
32614 }32598 }
32615 if (!end_is_len) {32599 if (!end_is_len) {
32616 if (by_length) {32600 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);
32618 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);32602 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);32603 break :e try sema.coerce(block, .usize, uncasted_end, end_src);
32620 } else break :e try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);32604 } else break :e try sema.coerce(block, .usize, uncasted_end_opt, end_src);
32621 }32605 }
32622 return sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);32606 return sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);
32623 };32607 };
...@@ -32645,7 +32629,7 @@ fn analyzeSlice(...@@ -32645,7 +32629,7 @@ fn analyzeSlice(
32645 // requirement: start <= end32629 // requirement: start <= end
32646 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {32630 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32647 if (try sema.resolveDefinedValue(block, start_src, start)) |start_val| {32631 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))) {
32649 return sema.fail(32633 return sema.fail(
32650 block,32634 block,
32651 start_src,32635 start_src,
...@@ -32715,7 +32699,7 @@ fn analyzeSlice(...@@ -32715,7 +32699,7 @@ fn analyzeSlice(
32715 try sema.addSafetyCheckCall(block, src, ok, .@"panic.startGreaterThanEnd", &.{ start, end });32699 try sema.addSafetyCheckCall(block, src, ok, .@"panic.startGreaterThanEnd", &.{ start, end });
32716 }32700 }
32717 const new_len = if (by_length)32701 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)
32719 else32703 else
32720 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);32704 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
32721 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);32705 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
...@@ -32753,9 +32737,9 @@ fn analyzeSlice(...@@ -32753,9 +32737,9 @@ fn analyzeSlice(
3275332737
32754 bounds_check: {32738 bounds_check: {
32755 const actual_len = if (array_ty.zigTypeTag(zcu) == .array)32739 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))
32757 else if (slice_ty.isSlice(zcu)) l: {32741 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);
32759 break :l if (slice_ty.sentinel(zcu) == null)32743 break :l if (slice_ty.sentinel(zcu) == null)
32760 slice_len_inst32744 slice_len_inst
32761 else32745 else
...@@ -32811,15 +32795,15 @@ fn analyzeSlice(...@@ -32811,15 +32795,15 @@ fn analyzeSlice(
3281132795
32812 // requirement: end <= len32796 // requirement: end <= len
32813 const opt_len_inst = if (array_ty.zigTypeTag(zcu) == .array)32797 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))
32815 else if (slice_ty.isSlice(zcu)) blk: {32799 else if (slice_ty.isSlice(zcu)) blk: {
32816 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {32800 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
32817 // we don't need to add one for sentinels because the32801 // we don't need to add one for sentinels because the
32818 // underlying value data includes the sentinel32802 // 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));
32820 }32804 }
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);
32823 if (slice_ty.sentinel(zcu) == null) break :blk slice_len_inst;32807 if (slice_ty.sentinel(zcu) == null) break :blk slice_len_inst;
3282432808
32825 // we have to add one because slice lengths don't include the sentinel32809 // we have to add one because slice lengths don't include the sentinel
...@@ -32935,8 +32919,8 @@ fn cmpNumeric(...@@ -32935,8 +32919,8 @@ fn cmpNumeric(
32935 }32919 }
3293632920
32937 // Any other comparison depends on both values, so the result is undef if either is undef.32921 // 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);32922 if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
32939 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(Type.bool);32923 if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return .undef_bool;
3294032924
32941 const runtime_src: LazySrcLoc = if (maybe_lhs_val) |lhs_val| rs: {32925 const runtime_src: LazySrcLoc = if (maybe_lhs_val) |lhs_val| rs: {
32942 if (maybe_rhs_val) |rhs_val| {32926 if (maybe_rhs_val) |rhs_val| {
...@@ -33646,7 +33630,7 @@ fn resolvePeerTypes(...@@ -33646,7 +33630,7 @@ fn resolvePeerTypes(
33646 candidate_srcs: PeerTypeCandidateSrc,33630 candidate_srcs: PeerTypeCandidateSrc,
33647) !Type {33631) !Type {
33648 switch (instructions.len) {33632 switch (instructions.len) {
33649 0 => return Type.noreturn,33633 0 => return .noreturn,
33650 1 => return sema.typeOf(instructions[0]),33634 1 => return sema.typeOf(instructions[0]),
33651 else => {},33635 else => {},
33652 }33636 }
...@@ -33780,12 +33764,12 @@ fn resolvePeerTypesInner(...@@ -33780,12 +33764,12 @@ fn resolvePeerTypesInner(
33780 .nullable => {33764 .nullable => {
33781 for (peer_tys, 0..) |opt_ty, i| {33765 for (peer_tys, 0..) |opt_ty, i| {
33782 const ty = opt_ty orelse continue;33766 const ty = opt_ty orelse continue;
33783 if (!ty.eql(Type.null, zcu)) return .{ .conflict = .{33767 if (!ty.eql(.null, zcu)) return .{ .conflict = .{
33784 .peer_idx_a = strat_reason,33768 .peer_idx_a = strat_reason,
33785 .peer_idx_b = i,33769 .peer_idx_b = i,
33786 } };33770 } };
33787 }33771 }
33788 return .{ .success = Type.null };33772 return .{ .success = .null };
33789 },33773 },
3379033774
33791 .optional => {33775 .optional => {
...@@ -34006,7 +33990,7 @@ fn resolvePeerTypesInner(...@@ -34006,7 +33990,7 @@ fn resolvePeerTypesInner(
34006 };33990 };
3400733991
34008 // Try peer -> cur, then cur -> peer33992 // 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 {
34010 return .{ .conflict = .{33994 return .{ .conflict = .{
34011 .peer_idx_a = first_idx,33995 .peer_idx_a = first_idx,
34012 .peer_idx_b = i,33996 .peer_idx_b = i,
...@@ -34153,8 +34137,8 @@ fn resolvePeerTypesInner(...@@ -34153,8 +34137,8 @@ fn resolvePeerTypesInner(
34153 };34137 };
3415434138
34155 // We abstract array handling slightly so that tuple pointers can work like array pointers34139 // 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));34140 const peer_pointee_array = sema.typeIsArrayLike(.fromInterned(peer_info.child));
34157 const cur_pointee_array = sema.typeIsArrayLike(Type.fromInterned(ptr_info.child));34141 const cur_pointee_array = sema.typeIsArrayLike(.fromInterned(ptr_info.child));
3415834142
34159 // This switch is just responsible for deciding the size and pointee (not including34143 // This switch is just responsible for deciding the size and pointee (not including
34160 // single-pointer array sentinel).34144 // single-pointer array sentinel).
...@@ -34162,7 +34146,7 @@ fn resolvePeerTypesInner(...@@ -34162,7 +34146,7 @@ fn resolvePeerTypesInner(
34162 switch (peer_info.flags.size) {34146 switch (peer_info.flags.size) {
34163 .one => switch (ptr_info.flags.size) {34147 .one => switch (ptr_info.flags.size) {
34164 .one => {34148 .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| {
34166 ptr_info.child = pointee.toIntern();34150 ptr_info.child = pointee.toIntern();
34167 break :good;34151 break :good;
34168 }34152 }
...@@ -34204,7 +34188,7 @@ fn resolvePeerTypesInner(...@@ -34204,7 +34188,7 @@ fn resolvePeerTypesInner(
34204 .many => {34188 .many => {
34205 // Only works for *[n]T + [*]T -> [*]T34189 // Only works for *[n]T + [*]T -> [*]T
34206 const arr = peer_pointee_array orelse return generic_err;34190 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| {
34208 ptr_info.child = pointee.toIntern();34192 ptr_info.child = pointee.toIntern();
34209 break :good;34193 break :good;
34210 }34194 }
...@@ -34217,7 +34201,7 @@ fn resolvePeerTypesInner(...@@ -34217,7 +34201,7 @@ fn resolvePeerTypesInner(
34217 .slice => {34201 .slice => {
34218 // Only works for *[n]T + []T -> []T34202 // Only works for *[n]T + []T -> []T
34219 const arr = peer_pointee_array orelse return generic_err;34203 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| {
34221 ptr_info.child = pointee.toIntern();34205 ptr_info.child = pointee.toIntern();
34222 break :good;34206 break :good;
34223 }34207 }
...@@ -34233,7 +34217,7 @@ fn resolvePeerTypesInner(...@@ -34233,7 +34217,7 @@ fn resolvePeerTypesInner(
34233 .one => {34217 .one => {
34234 // Only works for [*]T + *[n]T -> [*]T34218 // Only works for [*]T + *[n]T -> [*]T
34235 const arr = cur_pointee_array orelse return generic_err;34219 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| {
34237 ptr_info.flags.size = .many;34221 ptr_info.flags.size = .many;
34238 ptr_info.child = pointee.toIntern();34222 ptr_info.child = pointee.toIntern();
34239 break :good;34223 break :good;
...@@ -34247,7 +34231,7 @@ fn resolvePeerTypesInner(...@@ -34247,7 +34231,7 @@ fn resolvePeerTypesInner(
34247 return generic_err;34231 return generic_err;
34248 },34232 },
34249 .many => {34233 .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| {
34251 ptr_info.child = pointee.toIntern();34235 ptr_info.child = pointee.toIntern();
34252 break :good;34236 break :good;
34253 }34237 }
...@@ -34262,7 +34246,7 @@ fn resolvePeerTypesInner(...@@ -34262,7 +34246,7 @@ fn resolvePeerTypesInner(
34262 } };34246 } };
34263 }34247 }
34264 // Okay, then works for [*]T + "[]T" -> [*]T34248 // 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| {
34266 ptr_info.flags.size = .many;34250 ptr_info.flags.size = .many;
34267 ptr_info.child = pointee.toIntern();34251 ptr_info.child = pointee.toIntern();
34268 break :good;34252 break :good;
...@@ -34275,7 +34259,7 @@ fn resolvePeerTypesInner(...@@ -34275,7 +34259,7 @@ fn resolvePeerTypesInner(
34275 .one => {34259 .one => {
34276 // Only works for []T + *[n]T -> []T34260 // Only works for []T + *[n]T -> []T
34277 const arr = cur_pointee_array orelse return generic_err;34261 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| {
34279 ptr_info.flags.size = .slice;34263 ptr_info.flags.size = .slice;
34280 ptr_info.child = pointee.toIntern();34264 ptr_info.child = pointee.toIntern();
34281 break :good;34265 break :good;
...@@ -34293,7 +34277,7 @@ fn resolvePeerTypesInner(...@@ -34293,7 +34277,7 @@ fn resolvePeerTypesInner(
34293 return generic_err;34277 return generic_err;
34294 },34278 },
34295 .slice => {34279 .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| {
34297 ptr_info.child = pointee.toIntern();34281 ptr_info.child = pointee.toIntern();
34298 break :good;34282 break :good;
34299 }34283 }
...@@ -34479,7 +34463,7 @@ fn resolvePeerTypesInner(...@@ -34479,7 +34463,7 @@ fn resolvePeerTypesInner(
34479 } },34463 } },
34480 }34464 }
34481 }34465 }
34482 return .{ .success = Type.comptime_int };34466 return .{ .success = .comptime_int };
34483 },34467 },
3448434468
34485 .comptime_float => {34469 .comptime_float => {
...@@ -34493,7 +34477,7 @@ fn resolvePeerTypesInner(...@@ -34493,7 +34477,7 @@ fn resolvePeerTypesInner(
34493 } },34477 } },
34494 }34478 }
34495 }34479 }
34496 return .{ .success = Type.comptime_float };34480 return .{ .success = .comptime_float };
34497 },34481 },
3449834482
34499 .fixed_int => {34483 .fixed_int => {
...@@ -34601,11 +34585,11 @@ fn resolvePeerTypesInner(...@@ -34601,11 +34585,11 @@ fn resolvePeerTypesInner(
34601 // Recreate the type so we eliminate any c_longdouble34585 // Recreate the type so we eliminate any c_longdouble
34602 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));34586 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
34603 opt_cur_ty = switch (bits) {34587 opt_cur_ty = switch (bits) {
34604 16 => Type.f16,34588 16 => .f16,
34605 32 => Type.f32,34589 32 => .f32,
34606 64 => Type.f64,34590 64 => .f64,
34607 80 => Type.f80,34591 80 => .f80,
34608 128 => Type.f128,34592 128 => .f128,
34609 else => unreachable,34593 else => unreachable,
34610 };34594 };
34611 } else {34595 } else {
...@@ -34716,7 +34700,7 @@ fn resolvePeerTypesInner(...@@ -34716,7 +34700,7 @@ fn resolvePeerTypesInner(
34716 break;34700 break;
34717 };34701 };
34718 const uncoerced_field = Air.internedToRef(uncoerced_field_val.toIntern());34702 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) {
34720 // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway34704 // 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
34721 error.NotCoercible => {34705 error.NotCoercible => {
34722 comptime_val = null;34706 comptime_val = null;
...@@ -34729,7 +34713,7 @@ fn resolvePeerTypesInner(...@@ -34729,7 +34713,7 @@ fn resolvePeerTypesInner(
34729 comptime_val = coerced_val;34713 comptime_val = coerced_val;
34730 continue;34714 continue;
34731 };34715 };
34732 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), zcu)) {34716 if (!coerced_val.eql(existing, .fromInterned(field_ty.*), zcu)) {
34733 comptime_val = null;34717 comptime_val = null;
34734 break;34718 break;
34735 }34719 }
...@@ -34743,7 +34727,7 @@ fn resolvePeerTypesInner(...@@ -34743,7 +34727,7 @@ fn resolvePeerTypesInner(
34743 .values = field_vals,34727 .values = field_vals,
34744 });34728 });
3474534729
34746 return .{ .success = Type.fromInterned(final_ty) };34730 return .{ .success = .fromInterned(final_ty) };
34747 },34731 },
3474834732
34749 .exact => {34733 .exact => {
...@@ -34813,7 +34797,7 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {...@@ -34813,7 +34797,7 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
34813 const field_count = ty.structFieldCount(zcu);34797 const field_count = ty.structFieldCount(zcu);
34814 if (field_count == 0) return .{34798 if (field_count == 0) return .{
34815 .len = 0,34799 .len = 0,
34816 .elem_ty = Type.noreturn,34800 .elem_ty = .noreturn,
34817 };34801 };
34818 if (!ty.isTuple(zcu)) return null;34802 if (!ty.isTuple(zcu)) return null;
34819 const elem_ty = ty.fieldType(0, zcu);34803 const elem_ty = ty.fieldType(0, zcu);
...@@ -34902,7 +34886,7 @@ pub fn resolveStructAlignment(...@@ -34902,7 +34886,7 @@ pub fn resolveStructAlignment(
34902 var alignment: Alignment = .@"1";34886 var alignment: Alignment = .@"1";
3490334887
34904 for (0..struct_type.field_types.len) |i| {34888 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]);
34906 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt))34890 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt))
34907 continue;34891 continue;
34908 const field_align = try field_ty.structFieldAlignmentSema(34892 const field_align = try field_ty.structFieldAlignmentSema(
...@@ -34953,7 +34937,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -34953,7 +34937,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
34953 var big_align: Alignment = .@"1";34937 var big_align: Alignment = .@"1";
3495434938
34955 for (aligns, sizes, 0..) |*field_align, *field_size, i| {34939 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]);
34957 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {34941 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
34958 struct_type.offsets.get(ip)[i] = 0;34942 struct_type.offsets.get(ip)[i] = 0;
34959 field_size.* = 0;34943 field_size.* = 0;
...@@ -35001,7 +34985,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35001,7 +34985,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35001 const runtime_order = struct_type.runtime_order.get(ip);34985 const runtime_order = struct_type.runtime_order.get(ip);
3500234986
35003 for (runtime_order, 0..) |*ro, i| {34987 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]);
35005 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {34989 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
35006 ro.* = .omitted;34990 ro.* = .omitted;
35007 } else {34991 } else {
...@@ -35095,7 +35079,7 @@ fn backingIntType(...@@ -35095,7 +35079,7 @@ fn backingIntType(
35095 const fields_bit_sum = blk: {35079 const fields_bit_sum = blk: {
35096 var accumulator: u64 = 0;35080 var accumulator: u64 = 0;
35097 for (0..struct_type.field_types.len) |i| {35081 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]);
35099 accumulator += try field_ty.bitSizeSema(pt);35083 accumulator += try field_ty.bitSizeSema(pt);
35100 }35084 }
35101 break :blk accumulator;35085 break :blk accumulator;
...@@ -35234,7 +35218,7 @@ pub fn resolveUnionAlignment(...@@ -35234,7 +35218,7 @@ pub fn resolveUnionAlignment(
3523435218
35235 var max_align: Alignment = .@"1";35219 var max_align: Alignment = .@"1";
35236 for (0..union_type.field_types.len) |field_index| {35220 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]);
35238 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;35222 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3523935223
35240 const explicit_align = union_type.fieldAlign(ip, field_index);35224 const explicit_align = union_type.fieldAlign(ip, field_index);
...@@ -35282,7 +35266,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35282,7 +35266,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35282 var max_size: u64 = 0;35266 var max_size: u64 = 0;
35283 var max_align: Alignment = .@"1";35267 var max_align: Alignment = .@"1";
35284 for (0..union_type.field_types.len) |field_index| {35268 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
35287 if (try field_ty.comptimeOnlySema(pt) or field_ty.zigTypeTag(pt.zcu) == .noreturn) continue; // TODO: should this affect alignment?35271 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 {...@@ -35307,7 +35291,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35307 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and35291 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35308 try Type.fromInterned(union_type.enum_tag_ty).hasRuntimeBitsSema(pt);35292 try Type.fromInterned(union_type.enum_tag_ty).hasRuntimeBitsSema(pt);
35309 const size, const alignment, const padding = if (has_runtime_tag) layout: {35293 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);
35311 const tag_align = try enum_tag_type.abiAlignmentSema(pt);35295 const tag_align = try enum_tag_type.abiAlignmentSema(pt);
35312 const tag_size = try enum_tag_type.abiSizeSema(pt);35296 const tag_size = try enum_tag_type.abiSizeSema(pt);
3531335297
...@@ -35392,7 +35376,7 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35392,7 +35376,7 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
35392 // See also similar code for unions.35376 // See also similar code for unions.
3539335377
35394 for (0..struct_type.field_types.len) |i| {35378 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]);
35396 try field_ty.resolveFully(pt);35380 try field_ty.resolveFully(pt);
35397 }35381 }
35398}35382}
...@@ -35421,7 +35405,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35421,7 +35405,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3542135405
35422 union_obj.setStatus(ip, .fully_resolved_wip);35406 union_obj.setStatus(ip, .fully_resolved_wip);
35423 for (0..union_obj.field_types.len) |field_index| {35407 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]);
35425 try field_ty.resolveFully(pt);35409 try field_ty.resolveFully(pt);
35426 }35410 }
35427 union_obj.setStatus(ip, .fully_resolved);35411 union_obj.setStatus(ip, .fully_resolved);
...@@ -35553,7 +35537,7 @@ fn resolveInferredErrorSet(...@@ -35553,7 +35537,7 @@ fn resolveInferredErrorSet(
35553 // set. However, in the case of comptime/inline function calls with35537 // set. However, in the case of comptime/inline function calls with
35554 // inferred error sets, each call gets an adhoc InferredErrorSet object, which35538 // inferred error sets, each call gets an adhoc InferredErrorSet object, which
35555 // has no corresponding function body.35539 // 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)).?;
35557 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,35541 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,
35558 // because inline function does not create a new declaration, and the ies has been filled with analyzeCall,35542 // because inline function does not create a new declaration, and the ies has been filled with analyzeCall,
35559 // so here we can simply skip this case.35543 // so here we can simply skip this case.
...@@ -36008,7 +35992,7 @@ fn structFieldInits(...@@ -36008,7 +35992,7 @@ fn structFieldInits(
36008 // In init bodies, the zir index of the struct itself is used35992 // In init bodies, the zir index of the struct itself is used
36009 // to refer to the current field type.35993 // 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]);
36012 const type_ref = Air.internedToRef(field_ty.toIntern());35996 const type_ref = Air.internedToRef(field_ty.toIntern());
36013 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});35997 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
36014 sema.inst_map.putAssumeCapacity(zir_index, type_ref);35998 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
...@@ -36135,7 +36119,7 @@ fn unionFields(...@@ -36135,7 +36119,7 @@ fn unionFields(
36135 }36119 }
3613636120
36137 if (fields_len > 0) {36121 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);
36139 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {36123 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
36140 const msg = msg: {36124 const msg = msg: {
36141 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});36125 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
...@@ -36288,9 +36272,9 @@ fn unionFields(...@@ -36288,9 +36272,9 @@ fn unionFields(
36288 }36272 }
3628936273
36290 const field_ty: Type = if (!has_type)36274 const field_ty: Type = if (!has_type)
36291 Type.void36275 .void
36292 else if (field_type_ref == .none)36276 else if (field_type_ref == .none)
36293 Type.noreturn36277 .noreturn
36294 else36278 else
36295 try sema.resolveType(&block_scope, type_src, field_type_ref);36279 try sema.resolveType(&block_scope, type_src, field_type_ref);
3629636280
...@@ -36388,11 +36372,11 @@ fn unionFields(...@@ -36388,11 +36372,11 @@ fn unionFields(
3638836372
36389 for (tag_info.names.get(ip), 0..) |field_name, field_index| {36373 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
36390 if (explicit_tags_seen[field_index]) continue;36374 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", .{
36392 field_name.fmt(ip),36376 field_name.fmt(ip),
36393 });36377 });
36394 }36378 }
36395 try sema.addDeclaredHereNote(msg, Type.fromInterned(tag_ty));36379 try sema.addDeclaredHereNote(msg, .fromInterned(tag_ty));
36396 break :msg msg;36380 break :msg msg;
36397 };36381 };
36398 return sema.failWithOwnedErrorMsg(&block_scope, msg);36382 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36530,10 +36514,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36530,10 +36514,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36530 .comptime_int_type,36514 .comptime_int_type,
36531 .comptime_float_type,36515 .comptime_float_type,
36532 .enum_literal_type,36516 .enum_literal_type,
36517 .ptr_usize_type,
36518 .ptr_const_comptime_int_type,
36533 .manyptr_u8_type,36519 .manyptr_u8_type,
36534 .manyptr_const_u8_type,36520 .manyptr_const_u8_type,
36535 .manyptr_const_u8_sentinel_0_type,36521 .manyptr_const_u8_sentinel_0_type,
36536 .single_const_pointer_to_comptime_int_type,
36537 .slice_const_u8_type,36522 .slice_const_u8_type,
36538 .slice_const_u8_sentinel_0_type,36523 .slice_const_u8_sentinel_0_type,
36539 .vector_8_i8_type,36524 .vector_8_i8_type,
...@@ -36595,11 +36580,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36595,11 +36580,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36595 .empty_tuple_type => Value.empty_tuple,36580 .empty_tuple_type => Value.empty_tuple,
36596 // values, not types36581 // values, not types
36597 .undef,36582 .undef,
36583 .undef_bool,
36584 .undef_usize,
36585 .undef_u1,
36598 .zero,36586 .zero,
36599 .zero_usize,36587 .zero_usize,
36588 .zero_u1,
36600 .zero_u8,36589 .zero_u8,
36601 .one,36590 .one,
36602 .one_usize,36591 .one_usize,
36592 .one_u1,
36603 .one_u8,36593 .one_u8,
36604 .four_u8,36594 .four_u8,
36605 .negative_one,36595 .negative_one,
...@@ -36705,7 +36695,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36705,7 +36695,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36705 .storage = .{ .elems = &.{} },36695 .storage = .{ .elems = &.{} },
36706 } }));36696 } }));
3670736697
36708 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {36698 if (try sema.typeHasOnePossibleValue(.fromInterned(seq_type.child))) |opv| {
36709 return Value.fromInterned(try pt.intern(.{ .aggregate = .{36699 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
36710 .ty = ty.toIntern(),36700 .ty = ty.toIntern(),
36711 .storage = .{ .repeated_elem = opv.toIntern() },36701 .storage = .{ .repeated_elem = opv.toIntern() },
...@@ -36740,7 +36730,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36740,7 +36730,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36740 field_val.* = struct_type.field_inits.get(ip)[i];36730 field_val.* = struct_type.field_inits.get(ip)[i];
36741 continue;36731 continue;
36742 }36732 }
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]);
36744 if (try sema.typeHasOnePossibleValue(field_ty)) |field_opv| {36734 if (try sema.typeHasOnePossibleValue(field_ty)) |field_opv| {
36745 field_val.* = field_opv.toIntern();36735 field_val.* = field_opv.toIntern();
36746 } else return null;36736 } else return null;
...@@ -36773,13 +36763,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36773,13 +36763,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36773 try ty.resolveLayout(pt);36763 try ty.resolveLayout(pt);
3677436764
36775 const union_obj = ip.loadUnionType(ty.toIntern());36765 const union_obj = ip.loadUnionType(ty.toIntern());
36776 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse36766 const tag_val = (try sema.typeHasOnePossibleValue(.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
36777 return null;36767 return null;
36778 if (union_obj.field_types.len == 0) {36768 if (union_obj.field_types.len == 0) {
36779 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });36769 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });
36780 return Value.fromInterned(only);36770 return Value.fromInterned(only);
36781 }36771 }
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]);
36783 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse36773 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
36784 return null;36774 return null;
36785 const only = try pt.internUnion(.{36775 const only = try pt.internUnion(.{
...@@ -36796,7 +36786,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36796,7 +36786,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36796 .nonexhaustive => {36786 .nonexhaustive => {
36797 if (enum_type.tag_ty == .comptime_int_type) return null;36787 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| {
36800 const only = try pt.intern(.{ .enum_tag = .{36790 const only = try pt.intern(.{ .enum_tag = .{
36801 .ty = ty.toIntern(),36791 .ty = ty.toIntern(),
36802 .int = int_opv.toIntern(),36792 .int = int_opv.toIntern(),
...@@ -36814,7 +36804,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36814,7 +36804,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36814 1 => try pt.intern(.{ .enum_tag = .{36804 1 => try pt.intern(.{ .enum_tag = .{
36815 .ty = ty.toIntern(),36805 .ty = ty.toIntern(),
36816 .int = if (enum_type.values.len == 0)36806 .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()
36818 else36808 else
36819 try ip.getCoercedInts(36809 try ip.getCoercedInts(
36820 zcu.gpa,36810 zcu.gpa,
...@@ -37041,7 +37031,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {...@@ -37041,7 +37031,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
37041 if (ptr_type.flags.is_allowzero) return null;37031 if (ptr_type.flags.is_allowzero) return null;
3704237032
37043 // optionals of zero sized types behave like bools, not pointers37033 // 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);
37045 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {37035 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
37046 return null;37036 return null;
37047 }37037 }
...@@ -37175,7 +37165,7 @@ fn intFromFloatScalar(...@@ -37175,7 +37165,7 @@ fn intFromFloatScalar(
37175 var big_int = try float128IntPartToBigInt(sema.arena, float);37165 var big_int = try float128IntPartToBigInt(sema.arena, float);
37176 defer big_int.deinit();37166 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
37180 if (!(try sema.intFitsInType(cti_result, int_ty, null))) {37170 if (!(try sema.intFitsInType(cti_result, int_ty, null))) {
37181 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{37171 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 {...@@ -37278,8 +37268,8 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
37278 assert(enum_type.tag_mode != .nonexhaustive);37268 assert(enum_type.tag_mode != .nonexhaustive);
37279 // The `tagValueIndex` function call below relies on the type being the integer tag type.37269 // The `tagValueIndex` function call below relies on the type being the integer tag type.
37280 // `getCoerced` assumes the value will fit the new type.37270 // `getCoerced` assumes the value will fit the new type.
37281 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;37271 if (!(try sema.intFitsInType(int, .fromInterned(enum_type.tag_ty), null))) return false;
37282 const int_coerced = try pt.getCoerced(int, Type.fromInterned(enum_type.tag_ty));37272 const int_coerced = try pt.getCoerced(int, .fromInterned(enum_type.tag_ty));
3728337273
37284 return enum_type.tagValueIndex(&zcu.intern_pool, int_coerced.toIntern()) != null;37274 return enum_type.tagValueIndex(&zcu.intern_pool, int_coerced.toIntern()) != null;
37285}37275}
...@@ -37359,7 +37349,7 @@ fn compareVector(...@@ -37359,7 +37349,7 @@ fn compareVector(
37359 const lhs_elem = try lhs.elemValue(pt, i);37349 const lhs_elem = try lhs.elemValue(pt, i);
37360 const rhs_elem = try rhs.elemValue(pt, i);37350 const rhs_elem = try rhs.elemValue(pt, i);
37361 if (lhs_elem.isUndef(zcu) or rhs_elem.isUndef(zcu)) {37351 if (lhs_elem.isUndef(zcu) or rhs_elem.isUndef(zcu)) {
37362 scalar.* = try pt.intern(.{ .undef = .bool_type });37352 scalar.* = .undef_bool;
37363 } else {37353 } else {
37364 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu));37354 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu));
37365 scalar.* = Value.makeBool(res_bool).toIntern();37355 scalar.* = Value.makeBool(res_bool).toIntern();
...@@ -37826,7 +37816,7 @@ pub fn resolveDeclaredEnum(...@@ -37826,7 +37816,7 @@ pub fn resolveDeclaredEnum(
37826 .owner = .wrap(.{ .type = wip_ty.index }),37816 .owner = .wrap(.{ .type = wip_ty.index }),
37827 .func_index = .none,37817 .func_index = .none,
37828 .func_is_naked = false,37818 .func_is_naked = false,
37829 .fn_ret_ty = Type.void,37819 .fn_ret_ty = .void,
37830 .fn_ret_ty_ies = null,37820 .fn_ret_ty_ies = null,
37831 .comptime_err_ret_trace = &comptime_err_ret_trace,37821 .comptime_err_ret_trace = &comptime_err_ret_trace,
37832 };37822 };
...@@ -37999,7 +37989,7 @@ fn resolveDeclaredEnumInner(...@@ -37999,7 +37989,7 @@ fn resolveDeclaredEnumInner(
37999 break :overflow false;37989 break :overflow false;
38000 } else overflow: {37990 } else overflow: {
38001 assert(wip_ty.nextField(ip, field_name, .none) == null);37991 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);
38003 if (!try sema.intFitsInType(last_tag_val.?, int_tag_ty, null)) break :overflow true;37993 if (!try sema.intFitsInType(last_tag_val.?, int_tag_ty, null)) break :overflow true;
38004 last_tag_val = try pt.getCoerced(last_tag_val.?, int_tag_ty);37994 last_tag_val = try pt.getCoerced(last_tag_val.?, int_tag_ty);
38005 break :overflow false;37995 break :overflow false;
src/Sema/arith.zig+6-6
...@@ -168,7 +168,7 @@ fn addWithOverflowScalar(...@@ -168,7 +168,7 @@ fn addWithOverflowScalar(
168 else => unreachable,168 else => unreachable,
169 }169 }
170 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{170 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
171 .overflow_bit = try pt.undefValue(.u1),171 .overflow_bit = .undef_u1,
172 .wrapped_result = try pt.undefValue(ty),172 .wrapped_result = try pt.undefValue(ty),
173 };173 };
174 return intAddWithOverflow(sema, lhs, rhs, ty);174 return intAddWithOverflow(sema, lhs, rhs, ty);
...@@ -229,7 +229,7 @@ fn subWithOverflowScalar(...@@ -229,7 +229,7 @@ fn subWithOverflowScalar(
229 else => unreachable,229 else => unreachable,
230 }230 }
231 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{231 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
232 .overflow_bit = try pt.undefValue(.u1),232 .overflow_bit = .undef_u1,
233 .wrapped_result = try pt.undefValue(ty),233 .wrapped_result = try pt.undefValue(ty),
234 };234 };
235 return intSubWithOverflow(sema, lhs, rhs, ty);235 return intSubWithOverflow(sema, lhs, rhs, ty);
...@@ -290,7 +290,7 @@ fn mulWithOverflowScalar(...@@ -290,7 +290,7 @@ fn mulWithOverflowScalar(
290 else => unreachable,290 else => unreachable,
291 }291 }
292 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{292 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return .{
293 .overflow_bit = try pt.undefValue(.u1),293 .overflow_bit = .undef_u1,
294 .wrapped_result = try pt.undefValue(ty),294 .wrapped_result = try pt.undefValue(ty),
295 };295 };
296 return intMulWithOverflow(sema, lhs, rhs, ty);296 return intMulWithOverflow(sema, lhs, rhs, ty);
...@@ -1043,7 +1043,7 @@ fn comptimeIntAdd(sema: *Sema, lhs: Value, rhs: Value) !Value {...@@ -1043,7 +1043,7 @@ fn comptimeIntAdd(sema: *Sema, lhs: Value, rhs: Value) !Value {
1043fn intAddWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {1043fn intAddWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
1044 switch (ty.toIntern()) {1044 switch (ty.toIntern()) {
1045 .comptime_int_type => return .{1045 .comptime_int_type => return .{
1046 .overflow_bit = try sema.pt.intValue(.u1, 0),1046 .overflow_bit = .zero_u1,
1047 .wrapped_result = try comptimeIntAdd(sema, lhs, rhs),1047 .wrapped_result = try comptimeIntAdd(sema, lhs, rhs),
1048 },1048 },
1049 else => return intAddWithOverflowInner(sema, lhs, rhs, ty),1049 else => return intAddWithOverflowInner(sema, lhs, rhs, ty),
...@@ -1125,7 +1125,7 @@ fn comptimeIntSub(sema: *Sema, lhs: Value, rhs: Value) !Value {...@@ -1125,7 +1125,7 @@ fn comptimeIntSub(sema: *Sema, lhs: Value, rhs: Value) !Value {
1125fn intSubWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {1125fn intSubWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
1126 switch (ty.toIntern()) {1126 switch (ty.toIntern()) {
1127 .comptime_int_type => return .{1127 .comptime_int_type => return .{
1128 .overflow_bit = try sema.pt.intValue(.u1, 0),1128 .overflow_bit = .zero_u1,
1129 .wrapped_result = try comptimeIntSub(sema, lhs, rhs),1129 .wrapped_result = try comptimeIntSub(sema, lhs, rhs),
1130 },1130 },
1131 else => return intSubWithOverflowInner(sema, lhs, rhs, ty),1131 else => return intSubWithOverflowInner(sema, lhs, rhs, ty),
...@@ -1211,7 +1211,7 @@ fn comptimeIntMul(sema: *Sema, lhs: Value, rhs: Value) !Value {...@@ -1211,7 +1211,7 @@ fn comptimeIntMul(sema: *Sema, lhs: Value, rhs: Value) !Value {
1211fn intMulWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {1211fn intMulWithOverflow(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value.OverflowArithmeticResult {
1212 switch (ty.toIntern()) {1212 switch (ty.toIntern()) {
1213 .comptime_int_type => return .{1213 .comptime_int_type => return .{
1214 .overflow_bit = try sema.pt.intValue(.u1, 0),1214 .overflow_bit = .zero_u1,
1215 .wrapped_result = try comptimeIntMul(sema, lhs, rhs),1215 .wrapped_result = try comptimeIntMul(sema, lhs, rhs),
1216 },1216 },
1217 else => return intMulWithOverflowInner(sema, lhs, rhs, ty),1217 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 {...@@ -2641,10 +2641,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2641 if (enum_type.values.len == 0) {2641 if (enum_type.values.len == 0) {
2642 const only = try pt.intern(.{ .enum_tag = .{2642 const only = try pt.intern(.{ .enum_tag = .{
2643 .ty = ty.toIntern(),2643 .ty = ty.toIntern(),
2644 .int = try pt.intern(.{ .int = .{2644 .int = (try pt.intValue(.fromInterned(enum_type.tag_ty), 0)).toIntern(),
2645 .ty = enum_type.tag_ty,
2646 .storage = .{ .u64 = 0 },
2647 } }),
2648 } });2645 } });
2649 return Value.fromInterned(only);2646 return Value.fromInterned(only);
2650 } else {2647 } else {
...@@ -3676,10 +3673,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {...@@ -3676,10 +3673,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
3676 .null_type,3673 .null_type,
3677 .undefined_type,3674 .undefined_type,
3678 .enum_literal_type,3675 .enum_literal_type,
3676 .ptr_usize_type,
3677 .ptr_const_comptime_int_type,
3679 .manyptr_u8_type,3678 .manyptr_u8_type,
3680 .manyptr_const_u8_type,3679 .manyptr_const_u8_type,
3681 .manyptr_const_u8_sentinel_0_type,3680 .manyptr_const_u8_sentinel_0_type,
3682 .single_const_pointer_to_comptime_int_type,
3683 .slice_const_u8_type,3681 .slice_const_u8_type,
3684 .slice_const_u8_sentinel_0_type,3682 .slice_const_u8_sentinel_0_type,
3685 .optional_noreturn_type,3683 .optional_noreturn_type,
...@@ -3691,9 +3689,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {...@@ -3691,9 +3689,11 @@ pub fn resolveFields(ty: Type, pt: Zcu.PerThread) SemaError!void {
3691 .undef => unreachable,3689 .undef => unreachable,
3692 .zero => unreachable,3690 .zero => unreachable,
3693 .zero_usize => unreachable,3691 .zero_usize => unreachable,
3692 .zero_u1 => unreachable,
3694 .zero_u8 => unreachable,3693 .zero_u8 => unreachable,
3695 .one => unreachable,3694 .one => unreachable,
3696 .one_usize => unreachable,3695 .one_usize => unreachable,
3696 .one_u1 => unreachable,
3697 .one_u8 => unreachable,3697 .one_u8 => unreachable,
3698 .four_u8 => unreachable,3698 .four_u8 => unreachable,
3699 .negative_one => unreachable,3699 .negative_one => unreachable,
...@@ -4100,10 +4100,11 @@ pub const @"c_longlong": Type = .{ .ip_index = .c_longlong_type };...@@ -4100,10 +4100,11 @@ pub const @"c_longlong": Type = .{ .ip_index = .c_longlong_type };
4100pub const @"c_ulonglong": Type = .{ .ip_index = .c_ulonglong_type };4100pub const @"c_ulonglong": Type = .{ .ip_index = .c_ulonglong_type };
4101pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type };4101pub 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 };
4103pub const manyptr_u8: Type = .{ .ip_index = .manyptr_u8_type };4105pub const manyptr_u8: Type = .{ .ip_index = .manyptr_u8_type };
4104pub const manyptr_const_u8: Type = .{ .ip_index = .manyptr_const_u8_type };4106pub const manyptr_const_u8: Type = .{ .ip_index = .manyptr_const_u8_type };
4105pub const manyptr_const_u8_sentinel_0: Type = .{ .ip_index = .manyptr_const_u8_sentinel_0_type };4107pub 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 };
4107pub const slice_const_u8: Type = .{ .ip_index = .slice_const_u8_type };4108pub const slice_const_u8: Type = .{ .ip_index = .slice_const_u8_type };
4108pub const slice_const_u8_sentinel_0: Type = .{ .ip_index = .slice_const_u8_sentinel_0_type };4109pub 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 {...@@ -2895,19 +2895,25 @@ pub fn intValueBounds(val: Value, pt: Zcu.PerThread) !?[2]Value {
28952895
2896pub const BigIntSpace = InternPool.Key.Int.Storage.BigIntSpace;2896pub 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 };
2898pub const zero_usize: Value = .{ .ip_index = .zero_usize };2903pub const zero_usize: Value = .{ .ip_index = .zero_usize };
2904pub const zero_u1: Value = .{ .ip_index = .zero_u1 };
2899pub const zero_u8: Value = .{ .ip_index = .zero_u8 };2905pub const zero_u8: Value = .{ .ip_index = .zero_u8 };
2900pub const zero_comptime_int: Value = .{ .ip_index = .zero };
2901pub const one_comptime_int: Value = .{ .ip_index = .one };2906pub 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 };
2902pub const negative_one_comptime_int: Value = .{ .ip_index = .negative_one };2911pub const negative_one_comptime_int: Value = .{ .ip_index = .negative_one };
2903pub const undef: Value = .{ .ip_index = .undef };
2904pub const @"void": Value = .{ .ip_index = .void_value };2912pub const @"void": Value = .{ .ip_index = .void_value };
2913pub const @"unreachable": Value = .{ .ip_index = .unreachable_value };
2905pub const @"null": Value = .{ .ip_index = .null_value };2914pub const @"null": Value = .{ .ip_index = .null_value };
2906pub const @"false": Value = .{ .ip_index = .bool_false };
2907pub const @"true": Value = .{ .ip_index = .bool_true };2915pub const @"true": Value = .{ .ip_index = .bool_true };
2908pub const @"unreachable": Value = .{ .ip_index = .unreachable_value };2916pub const @"false": Value = .{ .ip_index = .bool_false };
2909
2910pub const generic_poison_type: Value = .{ .ip_index = .generic_poison_type };
2911pub const empty_tuple: Value = .{ .ip_index = .empty_tuple };2917pub const empty_tuple: Value = .{ .ip_index = .empty_tuple };
29122918
2913pub fn makeBool(x: bool) Value {2919pub 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...@@ -1741,8 +1741,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A
1741 return;1741 return;
1742 }1742 }
17431743
1744 const backend = target_util.zigBackend(zcu.root_mod.resolved_target.result, zcu.comp.config.use_llvm);1744 try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index));
1745 try air.legalize(backend, pt);
17461745
1747 var liveness = try Air.Liveness.analyze(gpa, air.*, ip);1746 var liveness = try Air.Liveness.analyze(gpa, air.*, ip);
1748 defer liveness.deinit(gpa);1747 defer liveness.deinit(gpa);
...@@ -3022,7 +3021,7 @@ fn analyzeFnBodyInner(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaE...@@ -3022,7 +3021,7 @@ fn analyzeFnBodyInner(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaE
3022 // is unused so it just has to be a no-op.3021 // is unused so it just has to be a no-op.
3023 sema.air_instructions.set(@intFromEnum(ptr_inst), .{3022 sema.air_instructions.set(@intFromEnum(ptr_inst), .{
3024 .tag = .alloc,3023 .tag = .alloc,
3025 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },3024 .data = .{ .ty = .ptr_const_comptime_int },
3026 });3025 });
3027 }3026 }
30283027
src/arch/x86_64/CodeGen.zig+89-44
...@@ -32,15 +32,65 @@ const FrameIndex = bits.FrameIndex;...@@ -32,15 +32,65 @@ const FrameIndex = bits.FrameIndex;
3232
33const InnerError = codegen.CodeGenError || error{OutOfRegisters};33const InnerError = codegen.CodeGenError || error{OutOfRegisters};
3434
35pub const legalize_features: Air.Legalize.Features = .init(.{35pub inline fn legalizeFeatures(target: *const std.Target) *const Air.Legalize.Features {
36 .scalarize_ctz = true,36 @setEvalBranchQuota(1_200);
37 .scalarize_popcount = true,37 return switch (target.ofmt == .coff) {
38 .scalarize_byte_swap = true,38 inline false, true => |use_old| comptime &.init(.{
39 .scalarize_bit_reverse = true,39 .scalarize_add = use_old,
4040 .scalarize_add_sat = use_old,
41 .remove_shift_vector_rhs_splat = false,41 .scalarize_sub = use_old,
42 .reduce_one_elem_to_bitcast = true,42 .scalarize_sub_sat = use_old,
43});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
45/// Set this to `false` to uncover Sema OPV bugs.95/// Set this to `false` to uncover Sema OPV bugs.
46/// https://github.com/ziglang/zig/issues/2241996/// https://github.com/ziglang/zig/issues/22419
...@@ -5719,7 +5769,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -5719,7 +5769,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5719 },5769 },
5720 .extra_temps = .{5770 .extra_temps = .{
5721 .{ .type = .i64, .kind = .{ .rc = .general_purpose } },5771 .{ .type = .i64, .kind = .{ .rc = .general_purpose } },
5722 .{ .type = .i64, .kind = .{ .mut_rc = .{ .ref = .src1, .rc = .general_purpose } } },5772 .{ .type = .i64, .kind = .{ .rc = .general_purpose } },
5723 .unused,5773 .unused,
5724 .unused,5774 .unused,
5725 .unused,5775 .unused,
...@@ -92473,7 +92523,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92473,7 +92523,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92473 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },92523 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
92474 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },92524 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
92475 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92525 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92476 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },92526 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
92477 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },92527 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
92478 .{ ._, ._r, .sa, .tmp0q, .ui(63), ._, ._ },92528 .{ ._, ._r, .sa, .tmp0q, .ui(63), ._, ._ },
92479 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },92529 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
...@@ -92505,7 +92555,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92505,7 +92555,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92505 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },92555 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
92506 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },92556 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
92507 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92557 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92508 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },92558 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
92509 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },92559 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
92510 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },92560 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
92511 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },92561 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
...@@ -92539,7 +92589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92539,7 +92589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92539 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },92589 .{ ._, ._, .lea, .tmp1p, .mem(.dst0), ._, ._ },
92540 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },92590 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
92541 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92591 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92542 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_size, -8), ._, ._ },92592 .{ ._, ._, .mov, .tmp0q, .memad(.src0q, .add_dst0_size, -8), ._, ._ },
92543 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },92593 .{ ._, ._l, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
92544 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },92594 .{ ._, ._r, .sa, .tmp0q, .uia(64, .dst0, .sub_bit_size_rem_64), ._, ._ },
92545 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },92595 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
...@@ -92600,7 +92650,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92600,7 +92650,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92600 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },92650 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
92601 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92651 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92602 .{ ._, ._, .mov, .tmp2d, .sa(.dst0, .add_bit_size_rem_64), ._, ._ },92652 .{ ._, ._, .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, ._ },
92604 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp2q, ._, ._ },92654 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp2q, ._, ._ },
92605 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },92655 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },
92606 } },92656 } },
...@@ -92632,7 +92682,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92632,7 +92682,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92632 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },92682 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
92633 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92683 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92634 .{ ._, ._, .mov, .tmp2d, .sa(.dst0, .add_bit_size_rem_64), ._, ._ },92684 .{ ._, ._, .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, ._ },
92636 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp2q, ._, ._ },92686 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp2q, ._, ._ },
92637 } },92687 } },
92638 }, .{92688 }, .{
...@@ -92663,7 +92713,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92663,7 +92713,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92663 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },92713 .{ ._, ._, .mov, .tmp2d, .sia(-2, .dst0, .add_size_div_8), ._, ._ },
92664 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92714 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92665 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },92715 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },
92666 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_size, -16), ._, ._ },92716 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_dst0_size, -16), ._, ._ },
92667 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },92717 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -16), .tmp0q, ._, ._ },
92668 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },92718 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .si(0), ._, ._ },
92669 } },92719 } },
...@@ -92695,7 +92745,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -92695,7 +92745,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
92695 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },92745 .{ ._, ._, .mov, .tmp2d, .sia(-1, .dst0, .add_size_div_8), ._, ._ },
92696 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },92746 .{ ._, .@"rep _sq", .mov, ._, ._, ._, ._ },
92697 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },92747 .{ ._, ._, .mov, .tmp0q, .ua(.dst0, .add_umax), ._, ._ },
92698 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_size, -8), ._, ._ },92748 .{ ._, ._, .@"and", .tmp0q, .memad(.src0q, .add_dst0_size, -8), ._, ._ },
92699 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },92749 .{ ._, ._, .mov, .memad(.dst0q, .add_size, -8), .tmp0q, ._, ._ },
92700 } },92750 } },
92701 }, .{92751 }, .{
...@@ -165537,9 +165587,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -165537,9 +165587,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {
165537 .ty = mask_ty.toIntern(),165587 .ty = mask_ty.toIntern(),
165538 .storage = .{ .elems = &([1]InternPool.Index{165588 .storage = .{ .elems = &([1]InternPool.Index{
165539 (try rhs_ty.childType(zcu).maxIntScalar(pt, .u8)).toIntern(),165589 (try rhs_ty.childType(zcu).maxIntScalar(pt, .u8)).toIntern(),
165540 } ++ [1]InternPool.Index{165590 } ++ [1]InternPool.Index{.zero_u8} ** 15) },
165541 (try pt.intValue(.u8, 0)).toIntern(),
165542 } ** 15) },
165543 } })));165591 } })));
165544 const mask_addr_reg = try self.copyToTmpRegister(.usize, mask_mcv.address());165592 const mask_addr_reg = try self.copyToTmpRegister(.usize, mask_mcv.address());
165545 const mask_addr_lock = self.register_manager.lockRegAssumeUnused(mask_addr_reg);165593 const mask_addr_lock = self.register_manager.lockRegAssumeUnused(mask_addr_reg);
...@@ -178776,10 +178824,10 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -178776,10 +178824,10 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
178776 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });178824 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });
178777 var mask_elems_buf: [32]InternPool.Index = undefined;178825 var mask_elems_buf: [32]InternPool.Index = undefined;
178778 const mask_elems = mask_elems_buf[0..vec_len];178826 const mask_elems = mask_elems_buf[0..vec_len];
178779 for (mask_elems, 0..) |*elem, bit| elem.* = try pt.intern(.{ .int = .{178827 for (mask_elems, 0..) |*elem, bit| elem.* = (try pt.intValue(
178780 .ty = mask_elem_ty.toIntern(),178828 mask_elem_ty,
178781 .storage = .{ .u64 = @as(u64, 1) << @intCast(bit) },178829 @as(u8, 1) << @truncate(bit),
178782 } });178830 )).toIntern();
178783 const mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{178831 const mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{
178784 .ty = mask_ty.toIntern(),178832 .ty = mask_ty.toIntern(),
178785 .storage = .{ .elems = mask_elems },178833 .storage = .{ .elems = mask_elems },
...@@ -179647,16 +179695,13 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -179647,16 +179695,13 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
179647 var lhs_mask_elems: [16]InternPool.Index = undefined;179695 var lhs_mask_elems: [16]InternPool.Index = undefined;
179648 for (lhs_mask_elems[0..max_abi_size], 0..) |*lhs_mask_elem, byte_index| {179696 for (lhs_mask_elems[0..max_abi_size], 0..) |*lhs_mask_elem, byte_index| {
179649 const elem_index = byte_index / elem_abi_size;179697 const elem_index = byte_index / elem_abi_size;
179650 lhs_mask_elem.* = try pt.intern(.{ .int = .{179698 lhs_mask_elem.* = (try pt.intValue(.u8, if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179651 .ty = .u8_type,179699 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179652 .storage = .{ .u64 = if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {179700 if (mask_elem < 0) break :elem 0b1_00_00000;
179653 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;179701 const mask_elem_index: u31 = @intCast(mask_elem);
179654 if (mask_elem < 0) break :elem 0b1_00_00000;179702 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179655 const mask_elem_index: u31 = @intCast(mask_elem);179703 break :elem mask_elem_index * elem_abi_size + byte_off;
179656 const byte_off: u32 = @intCast(byte_index % elem_abi_size);179704 })).toIntern();
179657 break :elem @intCast(mask_elem_index * elem_abi_size + byte_off);
179658 } },
179659 } });
179660 }179705 }
179661 const lhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });179706 const lhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });
179662 const lhs_mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{179707 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 {...@@ -179681,16 +179726,13 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
179681 var rhs_mask_elems: [16]InternPool.Index = undefined;179726 var rhs_mask_elems: [16]InternPool.Index = undefined;
179682 for (rhs_mask_elems[0..max_abi_size], 0..) |*rhs_mask_elem, byte_index| {179727 for (rhs_mask_elems[0..max_abi_size], 0..) |*rhs_mask_elem, byte_index| {
179683 const elem_index = byte_index / elem_abi_size;179728 const elem_index = byte_index / elem_abi_size;
179684 rhs_mask_elem.* = try pt.intern(.{ .int = .{179729 rhs_mask_elem.* = (try pt.intValue(.u8, if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {
179685 .ty = .u8_type,179730 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;
179686 .storage = .{ .u64 = if (elem_index >= mask_elems.len) 0b1_00_00000 else elem: {179731 if (mask_elem >= 0) break :elem 0b1_00_00000;
179687 const mask_elem = mask_elems[elem_index] orelse break :elem 0b1_00_00000;179732 const mask_elem_index: u31 = @intCast(~mask_elem);
179688 if (mask_elem >= 0) break :elem 0b1_00_00000;179733 const byte_off: u32 = @intCast(byte_index % elem_abi_size);
179689 const mask_elem_index: u31 = @intCast(~mask_elem);179734 break :elem mask_elem_index * elem_abi_size + byte_off;
179690 const byte_off: u32 = @intCast(byte_index % elem_abi_size);179735 })).toIntern();
179691 break :elem @intCast(mask_elem_index * elem_abi_size + byte_off);
179692 } },
179693 } });
179694 }179736 }
179695 const rhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });179737 const rhs_mask_ty = try pt.vectorType(.{ .len = max_abi_size, .child = .u8_type });
179696 const rhs_mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{179738 const rhs_mask_mcv = try self.genTypedValue(.fromInterned(try pt.intern(.{ .aggregate = .{
...@@ -188160,6 +188202,7 @@ const Select = struct {...@@ -188160,6 +188202,7 @@ const Select = struct {
188160 ptr_bit_size,188202 ptr_bit_size,
188161 size,188203 size,
188162 src0_size,188204 src0_size,
188205 dst0_size,
188163 delta_size,188206 delta_size,
188164 delta_elem_size,188207 delta_elem_size,
188165 unaligned_size,188208 unaligned_size,
...@@ -188203,6 +188246,7 @@ const Select = struct {...@@ -188203,6 +188246,7 @@ const Select = struct {
188203 const sub_src0_size: Adjust = .{ .sign = .neg, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };188246 const sub_src0_size: Adjust = .{ .sign = .neg, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };
188204 const add_src0_size: Adjust = .{ .sign = .pos, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };188247 const add_src0_size: Adjust = .{ .sign = .pos, .lhs = .src0_size, .op = .mul, .rhs = .@"1" };
188205 const add_8_src0_size: Adjust = .{ .sign = .pos, .lhs = .src0_size, .op = .mul, .rhs = .@"8" };188248 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" };
188206 const add_delta_size_div_8: Adjust = .{ .sign = .pos, .lhs = .delta_size, .op = .div, .rhs = .@"8" };188250 const add_delta_size_div_8: Adjust = .{ .sign = .pos, .lhs = .delta_size, .op = .div, .rhs = .@"8" };
188207 const add_delta_elem_size: Adjust = .{ .sign = .pos, .lhs = .delta_elem_size, .op = .mul, .rhs = .@"1" };188251 const add_delta_elem_size: Adjust = .{ .sign = .pos, .lhs = .delta_elem_size, .op = .mul, .rhs = .@"1" };
188208 const add_delta_elem_size_div_8: Adjust = .{ .sign = .pos, .lhs = .delta_elem_size, .op = .div, .rhs = .@"8" };188252 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 {...@@ -188998,6 +189042,7 @@ const Select = struct {
188998 .ptr_bit_size => s.cg.target.ptrBitWidth(),189042 .ptr_bit_size => s.cg.target.ptrBitWidth(),
188999 .size => @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu)),189043 .size => @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu)),
189000 .src0_size => @intCast(Select.Operand.Ref.src0.typeOf(s).abiSize(s.cg.pt.zcu)),189044 .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)),
189001 .delta_size => @intCast(@as(SignedImm, @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu))) -189046 .delta_size => @intCast(@as(SignedImm, @intCast(op.flags.base.ref.typeOf(s).abiSize(s.cg.pt.zcu))) -
189002 @as(SignedImm, @intCast(op.flags.index.ref.typeOf(s).abiSize(s.cg.pt.zcu)))),189047 @as(SignedImm, @intCast(op.flags.index.ref.typeOf(s).abiSize(s.cg.pt.zcu)))),
189003 .delta_elem_size => @intCast(@as(SignedImm, @intCast(op.flags.base.ref.typeOf(s).elemType2(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))) -189048 .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...@@ -32,8 +32,9 @@ fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Featu
32 return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");32 return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
33}33}
3434
35pub fn importBackend(comptime backend: std.builtin.CompilerBackend) ?type {35fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
36 return switch (backend) {36 return switch (backend) {
37 .other, .stage1 => unreachable,
37 .stage2_aarch64 => @import("arch/aarch64/CodeGen.zig"),38 .stage2_aarch64 => @import("arch/aarch64/CodeGen.zig"),
38 .stage2_arm => @import("arch/arm/CodeGen.zig"),39 .stage2_arm => @import("arch/arm/CodeGen.zig"),
39 .stage2_c => @import("codegen/c.zig"),40 .stage2_c => @import("codegen/c.zig"),
...@@ -42,11 +43,35 @@ pub fn importBackend(comptime backend: std.builtin.CompilerBackend) ?type {...@@ -42,11 +43,35 @@ pub fn importBackend(comptime backend: std.builtin.CompilerBackend) ?type {
42 .stage2_riscv64 => @import("arch/riscv64/CodeGen.zig"),43 .stage2_riscv64 => @import("arch/riscv64/CodeGen.zig"),
43 .stage2_sparc64 => @import("arch/sparc64/CodeGen.zig"),44 .stage2_sparc64 => @import("arch/sparc64/CodeGen.zig"),
44 .stage2_spirv64 => @import("codegen/spirv.zig"),45 .stage2_spirv64 => @import("codegen/spirv.zig"),
45 .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"),46 .stage2_wasm => @import("arch/wasm/CodeGen.zig"),
46 else => null,47 .stage2_x86, .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"),
48 _ => unreachable,
47 };49 };
48}50}
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
50pub fn generateFunction(75pub fn generateFunction(
51 lf: *link.File,76 lf: *link.File,
52 pt: Zcu.PerThread,77 pt: Zcu.PerThread,
...@@ -60,7 +85,7 @@ pub fn generateFunction(...@@ -60,7 +85,7 @@ pub fn generateFunction(
60 const zcu = pt.zcu;85 const zcu = pt.zcu;
61 const func = zcu.funcInfo(func_index);86 const func = zcu.funcInfo(func_index);
62 const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;87 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)) {
64 else => unreachable,89 else => unreachable,
65 inline .stage2_aarch64,90 inline .stage2_aarch64,
66 .stage2_arm,91 .stage2_arm,
...@@ -70,7 +95,7 @@ pub fn generateFunction(...@@ -70,7 +95,7 @@ pub fn generateFunction(
70 .stage2_x86_64,95 .stage2_x86_64,
71 => |backend| {96 => |backend| {
72 dev.check(devFeatureForBackend(backend));97 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);
74 },99 },
75 }100 }
76}101}
...@@ -88,14 +113,14 @@ pub fn generateLazyFunction(...@@ -88,14 +113,14 @@ pub fn generateLazyFunction(
88 zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result113 zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
89 else114 else
90 zcu.getTarget();115 zcu.getTarget();
91 switch (target_util.zigBackend(target, false)) {116 switch (target_util.zigBackend(target, zcu.comp.config.use_llvm)) {
92 else => unreachable,117 else => unreachable,
93 inline .stage2_powerpc,118 inline .stage2_powerpc,
94 .stage2_riscv64,119 .stage2_riscv64,
95 .stage2_x86_64,120 .stage2_x86_64,
96 => |backend| {121 => |backend| {
97 dev.check(devFeatureForBackend(backend));122 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);
99 },124 },
100 }125 }
101}126}
src/codegen/c.zig+6-6
...@@ -1591,7 +1591,7 @@ pub const DeclGen = struct {...@@ -1591,7 +1591,7 @@ pub const DeclGen = struct {
1591 try writer.writeAll("((");1591 try writer.writeAll("((");
1592 try dg.renderCType(writer, ctype);1592 try dg.renderCType(writer, ctype);
1593 return writer.print("){x})", .{1593 return writer.print("){x})", .{
1594 try dg.fmtIntLiteral(try pt.undefValue(.usize), .Other),1594 try dg.fmtIntLiteral(.undef_usize, .Other),
1595 });1595 });
1596 },1596 },
1597 .slice => {1597 .slice => {
...@@ -1605,7 +1605,7 @@ pub const DeclGen = struct {...@@ -1605,7 +1605,7 @@ pub const DeclGen = struct {
1605 const ptr_ty = ty.slicePtrFieldType(zcu);1605 const ptr_ty = ty.slicePtrFieldType(zcu);
1606 try dg.renderType(writer, ptr_ty);1606 try dg.renderType(writer, ptr_ty);
1607 return writer.print("){x}, {0x}}}", .{1607 return writer.print("){x}, {0x}}}", .{
1608 try dg.fmtIntLiteral(try dg.pt.undefValue(.usize), .Other),1608 try dg.fmtIntLiteral(.undef_usize, .Other),
1609 });1609 });
1610 },1610 },
1611 },1611 },
...@@ -6376,7 +6376,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6376,7 +6376,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
6376 if (operand_child_ctype.info(ctype_pool) == .array) {6376 if (operand_child_ctype.info(ctype_pool) == .array) {
6377 try writer.writeByte('&');6377 try writer.writeByte('&');
6378 try f.writeCValueDeref(writer, operand);6378 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)});
6380 } else try f.writeCValue(writer, operand, .Other);6380 } else try f.writeCValue(writer, operand, .Other);
6381 }6381 }
6382 try a.end(f, writer);6382 try a.end(f, writer);
...@@ -6907,7 +6907,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6907,7 +6907,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6907 try writer.writeAll("for (");6907 try writer.writeAll("for (");
6908 try f.writeCValue(writer, index, .Other);6908 try f.writeCValue(writer, index, .Other);
6909 try writer.writeAll(" = ");6909 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);
6911 try writer.writeAll("; ");6911 try writer.writeAll("; ");
6912 try f.writeCValue(writer, index, .Other);6912 try f.writeCValue(writer, index, .Other);
6913 try writer.writeAll(" != ");6913 try writer.writeAll(" != ");
...@@ -8311,11 +8311,11 @@ const Vectorize = struct {...@@ -8311,11 +8311,11 @@ const Vectorize = struct {
83118311
8312 try writer.writeAll("for (");8312 try writer.writeAll("for (");
8313 try f.writeCValue(writer, local, .Other);8313 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)});
8315 try f.writeCValue(writer, local, .Other);8315 try f.writeCValue(writer, local, .Other);
8316 try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, ty.vectorLen(zcu)))});8316 try writer.print(" < {d}; ", .{try f.fmtIntLiteral(try pt.intValue(.usize, ty.vectorLen(zcu)))});
8317 try f.writeCValue(writer, local, .Other);8317 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)});
8319 f.object.indent_writer.pushIndent();8319 f.object.indent_writer.pushIndent();
83208320
8321 break :index .{ .index = local };8321 break :index .{ .index = local };
src/codegen/c/Type.zig+15-6
...@@ -1408,6 +1408,15 @@ pub const Pool = struct {...@@ -1408,6 +1408,15 @@ pub const Pool = struct {
1408 .bits = pt.zcu.errorSetBits(),1408 .bits = pt.zcu.errorSetBits(),
1409 }, mod, kind),1409 }, 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 }),
1411 .manyptr_u8_type,1420 .manyptr_u8_type,
1412 => return pool.getPointer(allocator, .{1421 => return pool.getPointer(allocator, .{
1413 .elem_ctype = .u8,1422 .elem_ctype = .u8,
...@@ -1418,11 +1427,6 @@ pub const Pool = struct {...@@ -1418,11 +1427,6 @@ pub const Pool = struct {
1418 .elem_ctype = .u8,1427 .elem_ctype = .u8,
1419 .@"const" = true,1428 .@"const" = true,
1420 }),1429 }),
1421 .single_const_pointer_to_comptime_int_type,
1422 => return pool.getPointer(allocator, .{
1423 .elem_ctype = .void,
1424 .@"const" = true,
1425 }),
1426 .slice_const_u8_type,1430 .slice_const_u8_type,
1427 .slice_const_u8_sentinel_0_type,1431 .slice_const_u8_sentinel_0_type,
1428 => {1432 => {
...@@ -2157,11 +2161,16 @@ pub const Pool = struct {...@@ -2157,11 +2161,16 @@ pub const Pool = struct {
2157 },2161 },
21582162
2159 .undef,2163 .undef,
2164 .undef_bool,
2165 .undef_usize,
2166 .undef_u1,
2160 .zero,2167 .zero,
2161 .zero_usize,2168 .zero_usize,
2169 .zero_u1,
2162 .zero_u8,2170 .zero_u8,
2163 .one,2171 .one,
2164 .one_usize,2172 .one_usize,
2173 .one_u1,
2165 .one_u8,2174 .one_u8,
2166 .four_u8,2175 .four_u8,
2167 .negative_one,2176 .negative_one,
...@@ -2172,7 +2181,7 @@ pub const Pool = struct {...@@ -2172,7 +2181,7 @@ pub const Pool = struct {
2172 .bool_false,2181 .bool_false,
2173 .empty_tuple,2182 .empty_tuple,
2174 .none,2183 .none,
2175 => unreachable,2184 => unreachable, // values, not types
21762185
2177 _ => |ip_index| switch (ip.indexToKey(ip_index)) {2186 _ => |ip_index| switch (ip.indexToKey(ip_index)) {
2178 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),2187 .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 {...@@ -3081,10 +3081,11 @@ pub const Object = struct {
3081 .undefined_type,3081 .undefined_type,
3082 .enum_literal_type,3082 .enum_literal_type,
3083 => unreachable,3083 => unreachable,
3084 .ptr_usize_type,
3085 .ptr_const_comptime_int_type,
3084 .manyptr_u8_type,3086 .manyptr_u8_type,
3085 .manyptr_const_u8_type,3087 .manyptr_const_u8_type,
3086 .manyptr_const_u8_sentinel_0_type,3088 .manyptr_const_u8_sentinel_0_type,
3087 .single_const_pointer_to_comptime_int_type,
3088 => .ptr,3089 => .ptr,
3089 .slice_const_u8_type,3090 .slice_const_u8_type,
3090 .slice_const_u8_sentinel_0_type,3091 .slice_const_u8_sentinel_0_type,
...@@ -3098,11 +3099,16 @@ pub const Object = struct {...@@ -3098,11 +3099,16 @@ pub const Object = struct {
3098 => unreachable,3099 => unreachable,
3099 // values, not types3100 // values, not types
3100 .undef,3101 .undef,
3102 .undef_bool,
3103 .undef_usize,
3104 .undef_u1,
3101 .zero,3105 .zero,
3102 .zero_usize,3106 .zero_usize,
3107 .zero_u1,
3103 .zero_u8,3108 .zero_u8,
3104 .one,3109 .one,
3105 .one_usize,3110 .one_usize,
3111 .one_u1,
3106 .one_u8,3112 .one_u8,
3107 .four_u8,3113 .four_u8,
3108 .negative_one,3114 .negative_one,
src/mutable_value.zig+2-2
...@@ -260,7 +260,7 @@ pub const MutableValue = union(enum) {...@@ -260,7 +260,7 @@ pub const MutableValue = union(enum) {
260 const ptr = try arena.create(MutableValue);260 const ptr = try arena.create(MutableValue);
261 const len = try arena.create(MutableValue);261 const len = try arena.create(MutableValue);
262 ptr.* = .{ .interned = try pt.intern(.{ .undef = ip.slicePtrType(ty_ip) }) };262 ptr.* = .{ .interned = try pt.intern(.{ .undef = ip.slicePtrType(ty_ip) }) };
263 len.* = .{ .interned = try pt.intern(.{ .undef = .usize_type }) };263 len.* = .{ .interned = .undef_usize };
264 mv.* = .{ .slice = .{264 mv.* = .{ .slice = .{
265 .ty = ty_ip,265 .ty = ty_ip,
266 .ptr = ptr,266 .ptr = ptr,
...@@ -464,7 +464,7 @@ pub const MutableValue = union(enum) {...@@ -464,7 +464,7 @@ pub const MutableValue = union(enum) {
464 return switch (field_idx) {464 return switch (field_idx) {
465 Value.slice_ptr_index => .{ .interned = Value.fromInterned(ip_index).slicePtr(pt.zcu).toIntern() },465 Value.slice_ptr_index => .{ .interned = Value.fromInterned(ip_index).slicePtr(pt.zcu).toIntern() },
466 Value.slice_len_index => .{ .interned = switch (pt.zcu.intern_pool.indexToKey(ip_index)) {466 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,
468 .slice => |s| s.len,468 .slice => |s| s.len,
469 else => unreachable,469 else => unreachable,
470 } },470 } },
test/behavior/abs.zig-2
...@@ -96,7 +96,6 @@ test "@abs big int <= 128 bits" {...@@ -96,7 +96,6 @@ test "@abs big int <= 128 bits" {
96 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO96 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
97 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO97 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
98 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO98 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
101 try comptime testAbsSignedBigInt();100 try comptime testAbsSignedBigInt();
102 try testAbsSignedBigInt();101 try testAbsSignedBigInt();
...@@ -211,7 +210,6 @@ fn testAbsFloats(comptime T: type) !void {...@@ -211,7 +210,6 @@ fn testAbsFloats(comptime T: type) !void {
211test "@abs int vectors" {210test "@abs int vectors" {
212 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO211 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
213 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO212 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;
215 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO213 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
216 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO214 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
217 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO215 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" {...@@ -837,7 +837,6 @@ test "extern variable with non-pointer opaque type" {
837 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO837 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
838 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO838 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
839 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO839 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;
841 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO840 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
842841
843 @export(&var_to_export, .{ .name = "opaque_extern_var" });842 @export(&var_to_export, .{ .name = "opaque_extern_var" });
test/behavior/bitcast.zig-1
...@@ -384,7 +384,6 @@ test "comptime bitcast with fields following f80" {...@@ -384,7 +384,6 @@ test "comptime bitcast with fields following f80" {
384 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;384 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
385 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;385 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
386 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO386 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
389 const FloatT = extern struct { f: f80, x: u128 align(16) };388 const FloatT = extern struct { f: f80, x: u128 align(16) };
390 const x: FloatT = .{ .f = 0.5, .x = 123 };389 const x: FloatT = .{ .f = 0.5, .x = 123 };
test/behavior/bitreverse.zig-4
...@@ -12,7 +12,6 @@ test "@bitReverse" {...@@ -12,7 +12,6 @@ test "@bitReverse" {
12 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;12 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;14 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;
16 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;15 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1716
18 try comptime testBitReverse();17 try comptime testBitReverse();
...@@ -128,7 +127,6 @@ test "bitReverse vectors u8" {...@@ -128,7 +127,6 @@ test "bitReverse vectors u8" {
128 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO127 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
129 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;128 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
130 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;129 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
133 try comptime vector8();131 try comptime vector8();
134 try vector8();132 try vector8();
...@@ -149,7 +147,6 @@ test "bitReverse vectors u16" {...@@ -149,7 +147,6 @@ test "bitReverse vectors u16" {
149 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO147 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
150 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;148 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
151 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;149 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
154 try comptime vector16();151 try comptime vector16();
155 try vector16();152 try vector16();
...@@ -170,7 +167,6 @@ test "bitReverse vectors u24" {...@@ -170,7 +167,6 @@ test "bitReverse vectors u24" {
170 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO167 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
171 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;168 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
172 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;169 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
175 try comptime vector24();171 try comptime vector24();
176 try vector24();172 try vector24();
test/behavior/byteswap.zig-4
...@@ -39,7 +39,6 @@ test "@byteSwap integers" {...@@ -39,7 +39,6 @@ test "@byteSwap integers" {
39 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;39 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
40 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;40 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
41 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;41 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
44 const ByteSwapIntTest = struct {43 const ByteSwapIntTest = struct {
45 fn run() !void {44 fn run() !void {
...@@ -100,7 +99,6 @@ test "@byteSwap vectors u8" {...@@ -100,7 +99,6 @@ test "@byteSwap vectors u8" {
100 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO99 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
101 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;100 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
102 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;101 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
105 try comptime vector8();103 try comptime vector8();
106 try vector8();104 try vector8();
...@@ -121,7 +119,6 @@ test "@byteSwap vectors u16" {...@@ -121,7 +119,6 @@ test "@byteSwap vectors u16" {
121 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO119 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
122 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;120 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
123 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;121 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
126 try comptime vector16();123 try comptime vector16();
127 try vector16();124 try vector16();
...@@ -142,7 +139,6 @@ test "@byteSwap vectors u24" {...@@ -142,7 +139,6 @@ test "@byteSwap vectors u24" {
142 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO139 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
143 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;140 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
144 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;141 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
147 try comptime vector24();143 try comptime vector24();
148 try vector24();144 try vector24();
test/behavior/cast.zig-4
...@@ -617,7 +617,6 @@ test "@intCast on vector" {...@@ -617,7 +617,6 @@ test "@intCast on vector" {
617 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO617 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
618 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO618 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
619 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO619 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
620 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
621 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;620 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
622 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;621 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
623 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;622 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;
...@@ -2520,7 +2519,6 @@ test "@ptrFromInt on vector" {...@@ -2520,7 +2519,6 @@ test "@ptrFromInt on vector" {
2520 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO2519 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2521 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO2520 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2522 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;2521 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;
2524 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;2522 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
25252523
2526 const S = struct {2524 const S = struct {
...@@ -2592,7 +2590,6 @@ test "@intFromFloat on vector" {...@@ -2592,7 +2590,6 @@ test "@intFromFloat on vector" {
2592 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO2590 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2593 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO2591 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2594 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;2592 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
2597 const S = struct {2594 const S = struct {
2598 fn doTheTest() !void {2595 fn doTheTest() !void {
...@@ -2693,7 +2690,6 @@ test "@intCast vector of signed integer" {...@@ -2693,7 +2690,6 @@ test "@intCast vector of signed integer" {
2693 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO2690 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2694 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO2691 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
2695 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO2692 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2696 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
2697 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;2693 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
2698 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;2694 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
2699 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;2695 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;...@@ -5,7 +5,6 @@ const expect = std.testing.expect;
5test "anyopaque extern symbol" {5test "anyopaque extern symbol" {
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;7 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;
9 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;8 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
109
11 const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });10 const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });
test/behavior/floatop.zig-3
...@@ -135,7 +135,6 @@ test "cmp f32" {...@@ -135,7 +135,6 @@ test "cmp f32" {
135 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;135 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
136 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO136 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
137 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234137 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
140 try testCmp(f32);139 try testCmp(f32);
141 try comptime testCmp(f32);140 try comptime testCmp(f32);
...@@ -144,7 +143,6 @@ test "cmp f32" {...@@ -144,7 +143,6 @@ test "cmp f32" {
144test "cmp f64" {143test "cmp f64" {
145 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;144 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
146 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO145 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;
148 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234146 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
149147
150 try testCmp(f64);148 try testCmp(f64);
...@@ -400,7 +398,6 @@ test "@sqrt f32/f64" {...@@ -400,7 +398,6 @@ test "@sqrt f32/f64" {
400 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO398 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
401 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO399 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
402 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO400 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;
404 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;401 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
405402
406 try testSqrt(f32);403 try testSqrt(f32);
test/behavior/fn.zig-1
...@@ -429,7 +429,6 @@ test "implicit cast function to function ptr" {...@@ -429,7 +429,6 @@ test "implicit cast function to function ptr" {
429 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO429 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
430 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO430 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
431 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;431 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
434 const S1 = struct {433 const S1 = struct {
435 export fn someFunctionThatReturnsAValue() c_int {434 export fn someFunctionThatReturnsAValue() c_int {
test/behavior/math.zig-10
...@@ -85,7 +85,6 @@ test "@clz big ints" {...@@ -85,7 +85,6 @@ test "@clz big ints" {
85 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO85 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
86 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO86 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
87 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;87 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;
89 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;88 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
9089
91 try testClzBigInts();90 try testClzBigInts();
...@@ -103,7 +102,6 @@ fn testOneClz(comptime T: type, x: T) u32 {...@@ -103,7 +102,6 @@ fn testOneClz(comptime T: type, x: T) u32 {
103102
104test "@clz vectors" {103test "@clz vectors" {
105 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO104 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;
107 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO105 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
108 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO106 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
109 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO107 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -173,7 +171,6 @@ fn testOneCtz(comptime T: type, x: T) u32 {...@@ -173,7 +171,6 @@ fn testOneCtz(comptime T: type, x: T) u32 {
173}171}
174172
175test "@ctz 128-bit integers" {173test "@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;
177 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO174 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
178 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO175 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
179 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO176 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -198,7 +195,6 @@ test "@ctz vectors" {...@@ -198,7 +195,6 @@ test "@ctz vectors" {
198 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO195 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
199 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;196 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
200 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;197 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
203 try testCtzVectors();199 try testCtzVectors();
204 try comptime testCtzVectors();200 try comptime testCtzVectors();
...@@ -1694,9 +1690,6 @@ test "vector comparison" {...@@ -1694,9 +1690,6 @@ test "vector comparison" {
1694 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1690 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1695 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1691 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
1700 const S = struct {1693 const S = struct {
1701 fn doTheTest() !void {1694 fn doTheTest() !void {
1702 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };1695 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
...@@ -1785,7 +1778,6 @@ test "mod lazy values" {...@@ -1785,7 +1778,6 @@ test "mod lazy values" {
17851778
1786test "@clz works on both vector and scalar inputs" {1779test "@clz works on both vector and scalar inputs" {
1787 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO1780 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;
1789 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1781 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1790 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1782 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1791 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1783 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -1807,7 +1799,6 @@ test "runtime comparison to NaN is comptime-known" {...@@ -1807,7 +1799,6 @@ test "runtime comparison to NaN is comptime-known" {
1807 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1799 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1808 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1800 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1809 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1801 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;
1811 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1802 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1812 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/212341803 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" {...@@ -1838,7 +1829,6 @@ test "runtime int comparison to inf is comptime-known" {
1838 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1829 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1839 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1830 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1840 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1831 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;
1842 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1832 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1843 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/212341833 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" {...@@ -34,7 +34,6 @@ test "@max on vectors" {
34 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO34 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
35 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;35 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
36 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;36 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
39 const S = struct {38 const S = struct {
40 fn doTheTest() !void {39 fn doTheTest() !void {
...@@ -90,7 +89,6 @@ test "@min for vectors" {...@@ -90,7 +89,6 @@ test "@min for vectors" {
90 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO89 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
91 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;90 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
92 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;91 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
95 const S = struct {93 const S = struct {
96 fn doTheTest() !void {94 fn doTheTest() !void {
...@@ -260,7 +258,6 @@ test "@min/@max notices bounds from vector types" {...@@ -260,7 +258,6 @@ test "@min/@max notices bounds from vector types" {
260 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO258 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
261 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO259 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
262 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;260 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
265 var x: @Vector(2, u16) = .{ 30, 67 };262 var x: @Vector(2, u16) = .{ 30, 67 };
266 var y: @Vector(2, u32) = .{ 20, 500 };263 var y: @Vector(2, u32) = .{ 20, 500 };
...@@ -303,7 +300,6 @@ test "@min/@max notices bounds from vector types when element of comptime-known...@@ -303,7 +300,6 @@ test "@min/@max notices bounds from vector types when element of comptime-known
303 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO300 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
304 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO301 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
305 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;302 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
308 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };304 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };
309 _ = &x;305 _ = &x;
...@@ -375,7 +371,6 @@ test "@min/@max with runtime vectors of signed and unsigned integers of same siz...@@ -375,7 +371,6 @@ test "@min/@max with runtime vectors of signed and unsigned integers of same siz
375 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO371 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
376 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO372 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
377 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;373 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
380 const S = struct {375 const S = struct {
381 fn min(a: @Vector(2, i32), b: @Vector(2, u32)) @Vector(2, i32) {376 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" {...@@ -82,7 +82,6 @@ test "@popCount vectors" {
82 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO82 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
83 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;83 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
84 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;84 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
87 try comptime testPopCountVectors();86 try comptime testPopCountVectors();
88 try testPopCountVectors();87 try testPopCountVectors();
test/behavior/select.zig+1-1
...@@ -70,7 +70,7 @@ fn selectArrays() !void {...@@ -70,7 +70,7 @@ fn selectArrays() !void {
70test "@select compare result" {70test "@select compare result" {
71 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;71 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
72 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;72 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;
74 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;74 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;
7575
76 const S = struct {76 const S = struct {
test/behavior/union.zig+1
...@@ -282,6 +282,7 @@ test "cast union to tag type of union" {...@@ -282,6 +282,7 @@ test "cast union to tag type of union" {
282 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;282 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
283 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;283 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
284 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO284 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
286 try testCastUnionToTag();287 try testCastUnionToTag();
287 try comptime testCastUnionToTag();288 try comptime testCastUnionToTag();
test/behavior/vector.zig+1-7
...@@ -31,7 +31,6 @@ test "vector wrap operators" {...@@ -31,7 +31,6 @@ test "vector wrap operators" {
31 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO31 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
32 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;32 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;33 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
36 const S = struct {35 const S = struct {
37 fn doTheTest() !void {36 fn doTheTest() !void {
...@@ -652,7 +651,6 @@ test "vector division operators" {...@@ -652,7 +651,6 @@ test "vector division operators" {
652test "vector bitwise not operator" {651test "vector bitwise not operator" {
653 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO652 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
654 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;653 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;
656 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO654 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
657 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO655 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
658 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO656 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -934,7 +932,6 @@ test "saturating add" {...@@ -934,7 +932,6 @@ test "saturating add" {
934 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO932 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
935 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;933 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
936 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;934 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
939 const S = struct {936 const S = struct {
940 fn doTheTest() !void {937 fn doTheTest() !void {
...@@ -969,7 +966,6 @@ test "saturating subtraction" {...@@ -969,7 +966,6 @@ test "saturating subtraction" {
969 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO966 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
970 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;967 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
971 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;968 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
974 const S = struct {970 const S = struct {
975 fn doTheTest() !void {971 fn doTheTest() !void {
...@@ -989,7 +985,6 @@ test "saturating subtraction" {...@@ -989,7 +985,6 @@ test "saturating subtraction" {
989985
990test "saturating multiplication" {986test "saturating multiplication" {
991 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO987 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
992 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
993 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO988 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
994 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO989 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
995 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO990 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -1018,12 +1013,12 @@ test "saturating multiplication" {...@@ -1018,12 +1013,12 @@ test "saturating multiplication" {
10181013
1019test "saturating shift-left" {1014test "saturating shift-left" {
1020 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO1015 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1021 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1022 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1016 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1023 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1017 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1024 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1018 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1025 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1019 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1026 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1020 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
1028 const S = struct {1023 const S = struct {
1029 fn doTheTest() !void {1024 fn doTheTest() !void {
...@@ -1469,7 +1464,6 @@ test "compare vectors with different element types" {...@@ -1469,7 +1464,6 @@ test "compare vectors with different element types" {
1469 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1464 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1470 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1465 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1471 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO1466 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1472 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1473 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1467 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1474 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1468 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
14751469
test/behavior/x86_64/binary.zig+32-12
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const AddOneBit = math.AddOneBit;1const AddOneBit = math.AddOneBit;
2const AsSignedness = math.AsSignedness;
2const cast = math.cast;3const cast = math.cast;
4const ChangeScalar = math.ChangeScalar;
3const checkExpected = math.checkExpected;5const checkExpected = math.checkExpected;
4const Compare = math.Compare;6const Compare = math.Compare;
5const DoubleBits = math.DoubleBits;7const DoubleBits = math.DoubleBits;
...@@ -13,6 +15,7 @@ const math = @import("math.zig");...@@ -13,6 +15,7 @@ const math = @import("math.zig");
13const nan = math.nan;15const nan = math.nan;
14const Scalar = math.Scalar;16const Scalar = math.Scalar;
15const sign = math.sign;17const sign = math.sign;
18const splat = math.splat;
16const Sse = math.Sse;19const Sse = math.Sse;
17const tmin = math.tmin;20const tmin = math.tmin;
1821
...@@ -5141,6 +5144,7 @@ inline fn mulSat(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5141,6 +5144,7 @@ inline fn mulSat(comptime Type: type, lhs: Type, rhs: Type) Type {
5141test mulSat {5144test mulSat {
5142 const test_mul_sat = binary(mulSat, .{});5145 const test_mul_sat = binary(mulSat, .{});
5143 try test_mul_sat.testInts();5146 try test_mul_sat.testInts();
5147 try test_mul_sat.testIntVectors();
5144}5148}
51455149
5146inline fn multiply(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs * rhs) {5150inline fn multiply(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs * rhs) {
...@@ -5265,9 +5269,9 @@ test mulWithOverflow {...@@ -5265,9 +5269,9 @@ test mulWithOverflow {
5265}5269}
52665270
5267inline fn shlWithOverflow(comptime Type: type, lhs: Type, rhs: Type) struct { Type, u1 } {5271inline 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);
5269 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5273 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);
5271}5275}
5272test shlWithOverflow {5276test shlWithOverflow {
5273 const test_shl_with_overflow = binary(shlWithOverflow, .{});5277 const test_shl_with_overflow = binary(shlWithOverflow, .{});
...@@ -5280,7 +5284,9 @@ inline fn equal(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs == rhs) {...@@ -5280,7 +5284,9 @@ inline fn equal(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs == rhs) {
5280test equal {5284test equal {
5281 const test_equal = binary(equal, .{});5285 const test_equal = binary(equal, .{});
5282 try test_equal.testInts();5286 try test_equal.testInts();
5287 try test_equal.testIntVectors();
5283 try test_equal.testFloats();5288 try test_equal.testFloats();
5289 try test_equal.testFloatVectors();
5284}5290}
52855291
5286inline fn notEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs != rhs) {5292inline 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...@@ -5289,7 +5295,9 @@ inline fn notEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs != rhs
5289test notEqual {5295test notEqual {
5290 const test_not_equal = binary(notEqual, .{});5296 const test_not_equal = binary(notEqual, .{});
5291 try test_not_equal.testInts();5297 try test_not_equal.testInts();
5298 try test_not_equal.testIntVectors();
5292 try test_not_equal.testFloats();5299 try test_not_equal.testFloats();
5300 try test_not_equal.testFloatVectors();
5293}5301}
52945302
5295inline fn lessThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs < rhs) {5303inline 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)...@@ -5298,7 +5306,9 @@ inline fn lessThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs < rhs)
5298test lessThan {5306test lessThan {
5299 const test_less_than = binary(lessThan, .{});5307 const test_less_than = binary(lessThan, .{});
5300 try test_less_than.testInts();5308 try test_less_than.testInts();
5309 try test_less_than.testIntVectors();
5301 try test_less_than.testFloats();5310 try test_less_than.testFloats();
5311 try test_less_than.testFloatVectors();
5302}5312}
53035313
5304inline fn lessThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs <= rhs) {5314inline 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...@@ -5307,7 +5317,9 @@ inline fn lessThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs
5307test lessThanOrEqual {5317test lessThanOrEqual {
5308 const test_less_than_or_equal = binary(lessThanOrEqual, .{});5318 const test_less_than_or_equal = binary(lessThanOrEqual, .{});
5309 try test_less_than_or_equal.testInts();5319 try test_less_than_or_equal.testInts();
5320 try test_less_than_or_equal.testIntVectors();
5310 try test_less_than_or_equal.testFloats();5321 try test_less_than_or_equal.testFloats();
5322 try test_less_than_or_equal.testFloatVectors();
5311}5323}
53125324
5313inline fn greaterThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs > rhs) {5325inline 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...@@ -5316,7 +5328,9 @@ inline fn greaterThan(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs > r
5316test greaterThan {5328test greaterThan {
5317 const test_greater_than = binary(greaterThan, .{});5329 const test_greater_than = binary(greaterThan, .{});
5318 try test_greater_than.testInts();5330 try test_greater_than.testInts();
5331 try test_greater_than.testIntVectors();
5319 try test_greater_than.testFloats();5332 try test_greater_than.testFloats();
5333 try test_greater_than.testFloatVectors();
5320}5334}
53215335
5322inline fn greaterThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs >= rhs) {5336inline 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(...@@ -5325,7 +5339,9 @@ inline fn greaterThanOrEqual(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(
5325test greaterThanOrEqual {5339test greaterThanOrEqual {
5326 const test_greater_than_or_equal = binary(greaterThanOrEqual, .{});5340 const test_greater_than_or_equal = binary(greaterThanOrEqual, .{});
5327 try test_greater_than_or_equal.testInts();5341 try test_greater_than_or_equal.testInts();
5342 try test_greater_than_or_equal.testIntVectors();
5328 try test_greater_than_or_equal.testFloats();5343 try test_greater_than_or_equal.testFloats();
5344 try test_greater_than_or_equal.testFloatVectors();
5329}5345}
53305346
5331inline fn bitAnd(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs & rhs) {5347inline fn bitAnd(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs & rhs) {
...@@ -5347,54 +5363,57 @@ test bitOr {...@@ -5347,54 +5363,57 @@ test bitOr {
5347}5363}
53485364
5349inline fn shr(comptime Type: type, lhs: Type, rhs: Type) Type {5365inline 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);
5351 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5367 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;
5353}5369}
5354test shr {5370test shr {
5355 const test_shr = binary(shr, .{});5371 const test_shr = binary(shr, .{});
5356 try test_shr.testInts();5372 try test_shr.testInts();
5373 try test_shr.testIntVectors();
5357}5374}
53585375
5359inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {5376inline 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);
5361 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5378 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;
5363 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);5380 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);
5364}5381}
5365test shrExact {5382test shrExact {
5366 const test_shr_exact = binary(shrExact, .{});5383 const test_shr_exact = binary(shrExact, .{});
5367 try test_shr_exact.testInts();5384 try test_shr_exact.testInts();
5385 try test_shr_exact.testIntVectors();
5368}5386}
53695387
5370inline fn shl(comptime Type: type, lhs: Type, rhs: Type) Type {5388inline 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);
5372 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5390 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;
5374}5392}
5375test shl {5393test shl {
5376 const test_shl = binary(shl, .{});5394 const test_shl = binary(shl, .{});
5377 try test_shl.testInts();5395 try test_shl.testInts();
5396 try test_shl.testIntVectors();
5378}5397}
53795398
5380inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {5399inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {
5381 @setRuntimeSafety(false);5400 @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);
5383 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5402 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;
5385 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);5404 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);
5386}5405}
5387test shlExactUnsafe {5406test shlExactUnsafe {
5388 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});5407 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});
5389 try test_shl_exact_unsafe.testInts();5408 try test_shl_exact_unsafe.testInts();
5409 try test_shl_exact_unsafe.testIntVectors();
5390}5410}
53915411
5392inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {5412inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {
5393 // workaround https://github.com/ziglang/zig/issues/230345413 // workaround https://github.com/ziglang/zig/issues/23034
5394 if (@inComptime()) {5414 if (@inComptime()) {
5395 // workaround https://github.com/ziglang/zig/issues/231395415 // workaround https://github.com/ziglang/zig/issues/23139
5396 //return lhs <<| @min(@abs(rhs), imax(u64));5416 return lhs <<| @min(@abs(rhs), splat(ChangeScalar(Type, u64), imax(u64)));
5397 return lhs <<| @min(@abs(rhs), @as(u64, imax(u64)));
5398 }5417 }
5399 // workaround https://github.com/ziglang/zig/issues/230335418 // workaround https://github.com/ziglang/zig/issues/23033
5400 @setRuntimeSafety(false);5419 @setRuntimeSafety(false);
...@@ -5403,6 +5422,7 @@ inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5403,6 +5422,7 @@ inline fn shlSat(comptime Type: type, lhs: Type, rhs: Type) Type {
5403test shlSat {5422test shlSat {
5404 const test_shl_sat = binary(shlSat, .{});5423 const test_shl_sat = binary(shlSat, .{});
5405 try test_shl_sat.testInts();5424 try test_shl_sat.testInts();
5425 try test_shl_sat.testIntVectors();
5406}5426}
54075427
5408inline fn bitXor(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs ^ rhs) {5428inline 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;...@@ -8,8 +8,6 @@ pub const fmin = math.floatMin;
8pub const imax = math.maxInt;8pub const imax = math.maxInt;
9pub const imin = math.minInt;9pub const imin = math.minInt;
10pub const inf = math.inf;10pub const inf = math.inf;
11pub const Log2Int = math.Log2Int;
12pub const Log2IntCeil = math.Log2IntCeil;
13pub const nan = math.nan;11pub const nan = math.nan;
14pub const next = math.nextAfter;12pub const next = math.nextAfter;
15pub const tmin = math.floatTrueMin;13pub const tmin = math.floatTrueMin;
...@@ -30,38 +28,44 @@ pub fn Scalar(comptime Type: type) type {...@@ -30,38 +28,44 @@ pub fn Scalar(comptime Type: type) type {
30 .vector => |info| info.child,28 .vector => |info| info.child,
31 };29 };
32}30}
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}
33pub fn AddOneBit(comptime Type: type) type {43pub fn AddOneBit(comptime Type: type) type {
34 const ResultScalar = switch (@typeInfo(Scalar(Type))) {44 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
35 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = 1 + int.bits } }),45 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = 1 + int.bits } }),
36 .float => Scalar(Type),46 .float => Scalar(Type),
37 else => @compileError(@typeName(Type)),47 else => @compileError(@typeName(Type)),
38 };48 });
39 return switch (@typeInfo(Type)) {
40 else => ResultScalar,
41 .vector => |vector| @Vector(vector.len, ResultScalar),
42 };
43}49}
44pub fn DoubleBits(comptime Type: type) type {50pub fn DoubleBits(comptime Type: type) type {
45 const ResultScalar = switch (@typeInfo(Scalar(Type))) {51 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
46 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = int.bits * 2 } }),52 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = int.bits * 2 } }),
47 .float => Scalar(Type),53 .float => Scalar(Type),
48 else => @compileError(@typeName(Type)),54 else => @compileError(@typeName(Type)),
49 };55 });
50 return switch (@typeInfo(Type)) {
51 else => ResultScalar,
52 .vector => |vector| @Vector(vector.len, ResultScalar),
53 };
54}56}
55pub fn RoundBitsUp(comptime Type: type, comptime multiple: u16) type {57pub fn RoundBitsUp(comptime Type: type, comptime multiple: u16) type {
56 const ResultScalar = switch (@typeInfo(Scalar(Type))) {58 return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) {
57 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = std.mem.alignForward(u16, int.bits, multiple) } }),59 .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = std.mem.alignForward(u16, int.bits, multiple) } }),
58 .float => Scalar(Type),60 .float => Scalar(Type),
59 else => @compileError(@typeName(Type)),61 else => @compileError(@typeName(Type)),
60 };62 });
61 return switch (@typeInfo(Type)) {63}
62 else => ResultScalar,64pub fn Log2Int(comptime Type: type) type {
63 .vector => |vector| @Vector(vector.len, ResultScalar),65 return ChangeScalar(Type, math.Log2Int(Scalar(Type)));
64 };66}
67pub fn Log2IntCeil(comptime Type: type) type {
68 return ChangeScalar(Type, math.Log2IntCeil(Scalar(Type)));
65}69}
66// inline to avoid a runtime `@splat`70// inline to avoid a runtime `@splat`
67pub inline fn splat(comptime Type: type, scalar: Scalar(Type)) Type {71pub 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) {...@@ -78,18 +82,12 @@ inline fn select(cond: anytype, lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {
78 else => @compileError(@typeName(@TypeOf(cond))),82 else => @compileError(@typeName(@TypeOf(cond))),
79 };83 };
80}84}
81pub fn sign(rhs: anytype) switch (@typeInfo(@TypeOf(rhs))) {85pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) {
82 else => bool,
83 .vector => |vector| @Vector(vector.len, bool),
84} {
85 const ScalarInt = @Type(.{ .int = .{86 const ScalarInt = @Type(.{ .int = .{
86 .signedness = .unsigned,87 .signedness = .unsigned,
87 .bits = @bitSizeOf(Scalar(@TypeOf(rhs))),88 .bits = @bitSizeOf(Scalar(@TypeOf(rhs))),
88 } });89 } });
89 const VectorInt = switch (@typeInfo(@TypeOf(rhs))) {90 const VectorInt = ChangeScalar(@TypeOf(rhs), ScalarInt);
90 else => ScalarInt,
91 .vector => |vector| @Vector(vector.len, ScalarInt),
92 };
93 return @as(VectorInt, @bitCast(rhs)) & splat(VectorInt, @as(ScalarInt, 1) << @bitSizeOf(ScalarInt) - 1) != splat(VectorInt, 0);91 return @as(VectorInt, @bitCast(rhs)) & splat(VectorInt, @as(ScalarInt, 1) << @bitSizeOf(ScalarInt) - 1) != splat(VectorInt, 0);
94}92}
95fn boolAnd(lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {93fn 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 {...@@ -117,9 +117,9 @@ export fn testMutablePointer() void {
117// tmp.zig:37:38: note: imported here117// tmp.zig:37:38: note: imported here
118// neg_inf.zon:1:1: error: expected type '?u8'118// neg_inf.zon:1:1: error: expected type '?u8'
119// tmp.zig:57:28: note: imported here119// 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'
121// tmp.zig:62:39: note: imported here121// 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'
123// tmp.zig:67:44: note: imported here123// 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'
125// tmp.zig:72:50: note: imported here125// 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 {...@@ -15,6 +15,6 @@ pub export fn entry() void {
15// error15// error
16//16//
17// :7:25: error: unable to resolve comptime value17// :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-known18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_496.C' must be comptime-known
19// :4:16: note: struct requires comptime because of this field19// :4:16: note: struct requires comptime because of this field
20// :4:16: note: types are not available at runtime20// :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 {...@@ -16,5 +16,5 @@ pub export fn entry2() void {
16//16//
17// :3:6: error: no field or member function named 'copy' in '[]const u8'17// :3:6: error: no field or member function named 'copy' in '[]const u8'
18// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'18// :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'
20// :12:6: note: struct declared here20// :12:6: note: struct declared here
test/cases/compile_errors/coerce_anon_struct.zig+1-1
...@@ -6,6 +6,6 @@ export fn foo() void {...@@ -6,6 +6,6 @@ export fn foo() void {
66
7// error7// error
8//8//
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'
10// :3:16: note: struct declared here10// :3:16: note: struct declared here
11// :1:11: note: struct declared here11// :1:11: note: struct declared here
test/cases/compile_errors/redundant_try.zig+2-2
...@@ -44,9 +44,9 @@ comptime {...@@ -44,9 +44,9 @@ comptime {
44//44//
45// :5:23: error: expected error union type, found 'comptime_int'45// :5:23: error: expected error union type, found 'comptime_int'
46// :10:23: error: expected error union type, found '@TypeOf(.{})'46// :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'
48// :15:23: note: struct declared here48// :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'
50// :20:27: note: struct declared here50// :20:27: note: struct declared here
51// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'51// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
52// :31:13: error: expected error union type, found 'u32'52// :31:13: error: expected error union type, found 'u32'
tools/lldb_pretty_printers.py+2-1
...@@ -601,7 +601,8 @@ type_tag_handlers = {...@@ -601,7 +601,8 @@ type_tag_handlers = {
601 'fn_void_no_args': lambda payload: 'fn() void',601 'fn_void_no_args': lambda payload: 'fn() void',
602 'fn_naked_noreturn_no_args': lambda payload: 'fn() callconv(.naked) noreturn',602 'fn_naked_noreturn_no_args': lambda payload: 'fn() callconv(.naked) noreturn',
603 'fn_ccc_void_no_args': lambda payload: 'fn() callconv(.c) void',603 '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',
605 'manyptr_u8': lambda payload: '[*]u8',606 'manyptr_u8': lambda payload: '[*]u8',
606 'manyptr_const_u8': lambda payload: '[*]const u8',607 'manyptr_const_u8': lambda payload: '[*]const u8',
607 'manyptr_const_u8_sentinel_0': lambda payload: '[*:0]const u8',608 'manyptr_const_u8_sentinel_0': lambda payload: '[*:0]const u8',