authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-05-25 23:09:10+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-05-25 23:11:13+03:00
logf409d925ad4640ea71cc3ef5e83b13ae6e216959
tree7f5b992a2d668dc7a448fce2d1f3dc33e3bec270
parenteba66f4a584bbbfed93ac4de890c8a23f245fb1f

Sema: check for generic poison in `resolveInst`


2 files changed, 220 insertions(+), 209 deletions(-)

src/Sema.zig+210-209
...@@ -584,7 +584,7 @@ fn resolveBody(...@@ -584,7 +584,7 @@ fn resolveBody(
584 sema.comptime_break_inst = break_data.inst;584 sema.comptime_break_inst = break_data.inst;
585 return error.ComptimeBreak;585 return error.ComptimeBreak;
586 }586 }
587 return sema.resolveInst(break_data.operand);587 return try sema.resolveInst(break_data.operand);
588}588}
589589
590pub fn analyzeBody(590pub fn analyzeBody(
...@@ -1191,7 +1191,7 @@ fn analyzeBodyInner(...@@ -1191,7 +1191,7 @@ fn analyzeBodyInner(
1191 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse1191 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
1192 break always_noreturn;1192 break always_noreturn;
1193 if (inst == break_data.block_inst) {1193 if (inst == break_data.block_inst) {
1194 break :blk sema.resolveInst(break_data.operand);1194 break :blk try sema.resolveInst(break_data.operand);
1195 } else {1195 } else {
1196 break break_data.inst;1196 break break_data.inst;
1197 }1197 }
...@@ -1214,7 +1214,7 @@ fn analyzeBodyInner(...@@ -1214,7 +1214,7 @@ fn analyzeBodyInner(
1214 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse1214 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
1215 break always_noreturn;1215 break always_noreturn;
1216 if (inst == break_data.block_inst) {1216 if (inst == break_data.block_inst) {
1217 break :blk sema.resolveInst(break_data.operand);1217 break :blk try sema.resolveInst(break_data.operand);
1218 } else {1218 } else {
1219 break break_data.inst;1219 break break_data.inst;
1220 }1220 }
...@@ -1283,7 +1283,7 @@ fn analyzeBodyInner(...@@ -1283,7 +1283,7 @@ fn analyzeBodyInner(
12831283
1284 const break_data = opt_break_data orelse break always_noreturn;1284 const break_data = opt_break_data orelse break always_noreturn;
1285 if (inst == break_data.block_inst) {1285 if (inst == break_data.block_inst) {
1286 break :blk sema.resolveInst(break_data.operand);1286 break :blk try sema.resolveInst(break_data.operand);
1287 } else {1287 } else {
1288 break break_data.inst;1288 break break_data.inst;
1289 }1289 }
...@@ -1301,7 +1301,7 @@ fn analyzeBodyInner(...@@ -1301,7 +1301,7 @@ fn analyzeBodyInner(
1301 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse1301 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
1302 break always_noreturn;1302 break always_noreturn;
1303 if (inst == break_data.block_inst) {1303 if (inst == break_data.block_inst) {
1304 break :blk sema.resolveInst(break_data.operand);1304 break :blk try sema.resolveInst(break_data.operand);
1305 } else {1305 } else {
1306 break break_data.inst;1306 break break_data.inst;
1307 }1307 }
...@@ -1317,7 +1317,7 @@ fn analyzeBodyInner(...@@ -1317,7 +1317,7 @@ fn analyzeBodyInner(
1317 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse1317 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
1318 break always_noreturn;1318 break always_noreturn;
1319 if (inst == break_data.block_inst) {1319 if (inst == break_data.block_inst) {
1320 break :blk sema.resolveInst(break_data.operand);1320 break :blk try sema.resolveInst(break_data.operand);
1321 } else {1321 } else {
1322 break break_data.inst;1322 break break_data.inst;
1323 }1323 }
...@@ -1350,7 +1350,7 @@ fn analyzeBodyInner(...@@ -1350,7 +1350,7 @@ fn analyzeBodyInner(
1350 return result;1350 return result;
1351}1351}
13521352
1353pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref {1353pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
1354 var i: usize = @enumToInt(zir_ref);1354 var i: usize = @enumToInt(zir_ref);
13551355
1356 // First section of indexes correspond to a set number of constant values.1356 // First section of indexes correspond to a set number of constant values.
...@@ -1361,7 +1361,9 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref {...@@ -1361,7 +1361,9 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref {
1361 i -= Zir.Inst.Ref.typed_value_map.len;1361 i -= Zir.Inst.Ref.typed_value_map.len;
13621362
1363 // Finally, the last section of indexes refers to the map of ZIR=>AIR.1363 // Finally, the last section of indexes refers to the map of ZIR=>AIR.
1364 return sema.inst_map.get(@intCast(u32, i)).?;1364 const inst = sema.inst_map.get(@intCast(u32, i)).?;
1365 if (sema.typeOf(inst).tag() == .generic_poison) return error.GenericPoison;
1366 return inst;
1365}1367}
13661368
1367fn resolveConstBool(1369fn resolveConstBool(
...@@ -1370,7 +1372,7 @@ fn resolveConstBool(...@@ -1370,7 +1372,7 @@ fn resolveConstBool(
1370 src: LazySrcLoc,1372 src: LazySrcLoc,
1371 zir_ref: Zir.Inst.Ref,1373 zir_ref: Zir.Inst.Ref,
1372) !bool {1374) !bool {
1373 const air_inst = sema.resolveInst(zir_ref);1375 const air_inst = try sema.resolveInst(zir_ref);
1374 const wanted_type = Type.bool;1376 const wanted_type = Type.bool;
1375 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);1377 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1376 const val = try sema.resolveConstValue(block, src, coerced_inst);1378 const val = try sema.resolveConstValue(block, src, coerced_inst);
...@@ -1383,7 +1385,7 @@ pub fn resolveConstString(...@@ -1383,7 +1385,7 @@ pub fn resolveConstString(
1383 src: LazySrcLoc,1385 src: LazySrcLoc,
1384 zir_ref: Zir.Inst.Ref,1386 zir_ref: Zir.Inst.Ref,
1385) ![]u8 {1387) ![]u8 {
1386 const air_inst = sema.resolveInst(zir_ref);1388 const air_inst = try sema.resolveInst(zir_ref);
1387 const wanted_type = Type.initTag(.const_slice_u8);1389 const wanted_type = Type.initTag(.const_slice_u8);
1388 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);1390 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1389 const val = try sema.resolveConstValue(block, src, coerced_inst);1391 const val = try sema.resolveConstValue(block, src, coerced_inst);
...@@ -1391,7 +1393,7 @@ pub fn resolveConstString(...@@ -1391,7 +1393,7 @@ pub fn resolveConstString(
1391}1393}
13921394
1393pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {1395pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {
1394 const air_inst = sema.resolveInst(zir_ref);1396 const air_inst = try sema.resolveInst(zir_ref);
1395 const ty = try sema.analyzeAsType(block, src, air_inst);1397 const ty = try sema.analyzeAsType(block, src, air_inst);
1396 if (ty.tag() == .generic_poison) return error.GenericPoison;1398 if (ty.tag() == .generic_poison) return error.GenericPoison;
1397 return ty;1399 return ty;
...@@ -1738,7 +1740,7 @@ fn resolveInt(...@@ -1738,7 +1740,7 @@ fn resolveInt(
1738 zir_ref: Zir.Inst.Ref,1740 zir_ref: Zir.Inst.Ref,
1739 dest_ty: Type,1741 dest_ty: Type,
1740) !u64 {1742) !u64 {
1741 const air_inst = sema.resolveInst(zir_ref);1743 const air_inst = try sema.resolveInst(zir_ref);
1742 const coerced = try sema.coerce(block, dest_ty, air_inst, src);1744 const coerced = try sema.coerce(block, dest_ty, air_inst, src);
1743 const val = try sema.resolveConstValue(block, src, coerced);1745 const val = try sema.resolveConstValue(block, src, coerced);
1744 const target = sema.mod.getTarget();1746 const target = sema.mod.getTarget();
...@@ -1753,7 +1755,7 @@ pub fn resolveInstConst(...@@ -1753,7 +1755,7 @@ pub fn resolveInstConst(
1753 src: LazySrcLoc,1755 src: LazySrcLoc,
1754 zir_ref: Zir.Inst.Ref,1756 zir_ref: Zir.Inst.Ref,
1755) CompileError!TypedValue {1757) CompileError!TypedValue {
1756 const air_ref = sema.resolveInst(zir_ref);1758 const air_ref = try sema.resolveInst(zir_ref);
1757 const val = try sema.resolveConstValue(block, src, air_ref);1759 const val = try sema.resolveConstValue(block, src, air_ref);
1758 return TypedValue{1760 return TypedValue{
1759 .ty = sema.typeOf(air_ref),1761 .ty = sema.typeOf(air_ref),
...@@ -1769,7 +1771,7 @@ pub fn resolveInstValue(...@@ -1769,7 +1771,7 @@ pub fn resolveInstValue(
1769 src: LazySrcLoc,1771 src: LazySrcLoc,
1770 zir_ref: Zir.Inst.Ref,1772 zir_ref: Zir.Inst.Ref,
1771) CompileError!TypedValue {1773) CompileError!TypedValue {
1772 const air_ref = sema.resolveInst(zir_ref);1774 const air_ref = try sema.resolveInst(zir_ref);
1773 const val = try sema.resolveValue(block, src, air_ref);1775 const val = try sema.resolveValue(block, src, air_ref);
1774 return TypedValue{1776 return TypedValue{
1775 .ty = sema.typeOf(air_ref),1777 .ty = sema.typeOf(air_ref),
...@@ -1784,7 +1786,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -1784,7 +1786,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1784 const src: LazySrcLoc = sema.src;1786 const src: LazySrcLoc = sema.src;
1785 const bin_inst = sema.code.instructions.items(.data)[inst].bin;1787 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1786 const pointee_ty = try sema.resolveType(block, src, bin_inst.lhs);1788 const pointee_ty = try sema.resolveType(block, src, bin_inst.lhs);
1787 const ptr = sema.resolveInst(bin_inst.rhs);1789 const ptr = try sema.resolveInst(bin_inst.rhs);
1788 const target = sema.mod.getTarget();1790 const target = sema.mod.getTarget();
1789 const addr_space = target_util.defaultAddressSpace(target, .local);1791 const addr_space = target_util.defaultAddressSpace(target, .local);
17901792
...@@ -2532,7 +2534,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -2532,7 +2534,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
2532 defer tracy.end();2534 defer tracy.end();
25332535
2534 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;2536 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
2535 const operand = sema.resolveInst(inst_data.operand);2537 const operand = try sema.resolveInst(inst_data.operand);
2536 return sema.analyzeRef(block, inst_data.src(), operand);2538 return sema.analyzeRef(block, inst_data.src(), operand);
2537}2539}
25382540
...@@ -2551,7 +2553,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -2551,7 +2553,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
2551 defer tracy.end();2553 defer tracy.end();
25522554
2553 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2555 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2554 const operand = sema.resolveInst(inst_data.operand);2556 const operand = try sema.resolveInst(inst_data.operand);
2555 const src = inst_data.src();2557 const src = inst_data.src();
25562558
2557 return sema.ensureResultUsed(block, operand, src);2559 return sema.ensureResultUsed(block, operand, src);
...@@ -2575,7 +2577,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -2575,7 +2577,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
2575 defer tracy.end();2577 defer tracy.end();
25762578
2577 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2579 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2578 const operand = sema.resolveInst(inst_data.operand);2580 const operand = try sema.resolveInst(inst_data.operand);
2579 const src = inst_data.src();2581 const src = inst_data.src();
2580 const operand_ty = sema.typeOf(operand);2582 const operand_ty = sema.typeOf(operand);
2581 switch (operand_ty.zigTypeTag()) {2583 switch (operand_ty.zigTypeTag()) {
...@@ -2590,7 +2592,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -2590,7 +2592,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
25902592
2591 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2593 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2592 const src = inst_data.src();2594 const src = inst_data.src();
2593 const object = sema.resolveInst(inst_data.operand);2595 const object = try sema.resolveInst(inst_data.operand);
2594 const object_ty = sema.typeOf(object);2596 const object_ty = sema.typeOf(object);
25952597
2596 const is_pointer_to = object_ty.isSinglePointer();2598 const is_pointer_to = object_ty.isSinglePointer();
...@@ -2709,7 +2711,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -2709,7 +2711,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
27092711
2710fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2712fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2711 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2713 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2712 const ptr = sema.resolveInst(inst_data.operand);2714 const ptr = try sema.resolveInst(inst_data.operand);
2713 const ptr_ty = sema.typeOf(ptr);2715 const ptr_ty = sema.typeOf(ptr);
2714 var ptr_info = ptr_ty.ptrInfo().data;2716 var ptr_info = ptr_ty.ptrInfo().data;
2715 ptr_info.mutable = false;2717 ptr_info.mutable = false;
...@@ -2825,7 +2827,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -2825,7 +2827,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
2825 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2827 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2826 const src = inst_data.src();2828 const src = inst_data.src();
2827 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };2829 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
2828 const ptr = sema.resolveInst(inst_data.operand);2830 const ptr = try sema.resolveInst(inst_data.operand);
2829 const ptr_inst = Air.refToIndex(ptr).?;2831 const ptr_inst = Air.refToIndex(ptr).?;
2830 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);2832 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
2831 const value_index = sema.air_instructions.items(.data)[ptr_inst].ty_pl.payload;2833 const value_index = sema.air_instructions.items(.data)[ptr_inst].ty_pl.payload;
...@@ -2987,7 +2989,7 @@ fn zirArrayBasePtr(...@@ -2987,7 +2989,7 @@ fn zirArrayBasePtr(
2987 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2989 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2988 const src = inst_data.src();2990 const src = inst_data.src();
29892991
2990 const start_ptr = sema.resolveInst(inst_data.operand);2992 const start_ptr = try sema.resolveInst(inst_data.operand);
2991 var base_ptr = start_ptr;2993 var base_ptr = start_ptr;
2992 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {2994 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {
2993 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),2995 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
...@@ -3012,7 +3014,7 @@ fn zirFieldBasePtr(...@@ -3012,7 +3014,7 @@ fn zirFieldBasePtr(
3012 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3014 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3013 const src = inst_data.src();3015 const src = inst_data.src();
30143016
3015 const start_ptr = sema.resolveInst(inst_data.operand);3017 const start_ptr = try sema.resolveInst(inst_data.operand);
3016 var base_ptr = start_ptr;3018 var base_ptr = start_ptr;
3017 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {3019 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {
3018 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),3020 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
...@@ -3076,7 +3078,7 @@ fn zirValidateStructInit(...@@ -3076,7 +3078,7 @@ fn zirValidateStructInit(
3076 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];3078 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
3077 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;3079 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
3078 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;3080 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
3079 const object_ptr = sema.resolveInst(field_ptr_extra.lhs);3081 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
3080 const agg_ty = sema.typeOf(object_ptr).childType();3082 const agg_ty = sema.typeOf(object_ptr).childType();
3081 switch (agg_ty.zigTypeTag()) {3083 switch (agg_ty.zigTypeTag()) {
3082 .Struct => return sema.validateStructInit(3084 .Struct => return sema.validateStructInit(
...@@ -3252,7 +3254,7 @@ fn validateStructInit(...@@ -3252,7 +3254,7 @@ fn validateStructInit(
3252 var root_msg: ?*Module.ErrorMsg = null;3254 var root_msg: ?*Module.ErrorMsg = null;
32533255
3254 const fields = struct_obj.fields.values();3256 const fields = struct_obj.fields.values();
3255 const struct_ptr = sema.resolveInst(struct_ptr_zir_ref);3257 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
3256 const struct_ty = sema.typeOf(struct_ptr).childType();3258 const struct_ty = sema.typeOf(struct_ptr).childType();
32573259
3258 if (is_comptime or block.is_comptime) {3260 if (is_comptime or block.is_comptime) {
...@@ -3449,7 +3451,7 @@ fn zirValidateArrayInit(...@@ -3449,7 +3451,7 @@ fn zirValidateArrayInit(
3449 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];3451 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
3450 const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;3452 const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
3451 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;3453 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
3452 const array_ptr = sema.resolveInst(elem_ptr_extra.ptr);3454 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
3453 const array_ty = sema.typeOf(array_ptr).childType();3455 const array_ty = sema.typeOf(array_ptr).childType();
3454 const array_len = array_ty.arrayLen();3456 const array_len = array_ty.arrayLen();
34553457
...@@ -3647,7 +3649,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -3647,7 +3649,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
3647 // This is an elided instruction, but AstGen was unable to omit it.3649 // This is an elided instruction, but AstGen was unable to omit it.
3648 return;3650 return;
3649 };3651 };
3650 const operand = sema.resolveInst(bin_inst.rhs);3652 const operand = try sema.resolveInst(bin_inst.rhs);
3651 const src: LazySrcLoc = sema.src;3653 const src: LazySrcLoc = sema.src;
3652 blk: {3654 blk: {
3653 const ptr_inst = Air.refToIndex(ptr) orelse break :blk;3655 const ptr_inst = Air.refToIndex(ptr) orelse break :blk;
...@@ -3676,8 +3678,8 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -3676,8 +3678,8 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
36763678
3677 const src: LazySrcLoc = sema.src;3679 const src: LazySrcLoc = sema.src;
3678 const bin_inst = sema.code.instructions.items(.data)[inst].bin;3680 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3679 const ptr = sema.resolveInst(bin_inst.lhs);3681 const ptr = try sema.resolveInst(bin_inst.lhs);
3680 const operand = sema.resolveInst(bin_inst.rhs);3682 const operand = try sema.resolveInst(bin_inst.rhs);
3681 const ptr_inst = Air.refToIndex(ptr).?;3683 const ptr_inst = Air.refToIndex(ptr).?;
3682 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);3684 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
3683 const air_datas = sema.air_instructions.items(.data);3685 const air_datas = sema.air_instructions.items(.data);
...@@ -3759,8 +3761,8 @@ fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -3759,8 +3761,8 @@ fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
3759 defer tracy.end();3761 defer tracy.end();
37603762
3761 const bin_inst = sema.code.instructions.items(.data)[inst].bin;3763 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3762 const ptr = sema.resolveInst(bin_inst.lhs);3764 const ptr = try sema.resolveInst(bin_inst.lhs);
3763 const value = sema.resolveInst(bin_inst.rhs);3765 const value = try sema.resolveInst(bin_inst.rhs);
3764 return sema.storePtr(block, sema.src, ptr, value);3766 return sema.storePtr(block, sema.src, ptr, value);
3765}3767}
37663768
...@@ -3773,8 +3775,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -3773,8 +3775,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
3773 const inst_data = zir_datas[inst].pl_node;3775 const inst_data = zir_datas[inst].pl_node;
3774 const src = inst_data.src();3776 const src = inst_data.src();
3775 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3777 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3776 const ptr = sema.resolveInst(extra.lhs);3778 const ptr = try sema.resolveInst(extra.lhs);
3777 const operand = sema.resolveInst(extra.rhs);3779 const operand = try sema.resolveInst(extra.rhs);
37783780
3779 // Check for the possibility of this pattern:3781 // Check for the possibility of this pattern:
3780 // %a = ret_ptr3782 // %a = ret_ptr
...@@ -3799,7 +3801,7 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -3799,7 +3801,7 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
3799 const callee_src = sema.src;3801 const callee_src = sema.src;
38003802
3801 const inst_data = sema.code.instructions.items(.data)[inst].param_type;3803 const inst_data = sema.code.instructions.items(.data)[inst].param_type;
3802 const callee = sema.resolveInst(inst_data.callee);3804 const callee = try sema.resolveInst(inst_data.callee);
3803 const callee_ty = sema.typeOf(callee);3805 const callee_ty = sema.typeOf(callee);
3804 var param_index = inst_data.param_index;3806 var param_index = inst_data.param_index;
38053807
...@@ -3960,7 +3962,7 @@ fn zirCompileLog(...@@ -3960,7 +3962,7 @@ fn zirCompileLog(
3960 for (args) |arg_ref, i| {3962 for (args) |arg_ref, i| {
3961 if (i != 0) try writer.print(", ", .{});3963 if (i != 0) try writer.print(", ", .{});
39623964
3963 const arg = sema.resolveInst(arg_ref);3965 const arg = try sema.resolveInst(arg_ref);
3964 const arg_ty = sema.typeOf(arg);3966 const arg_ty = sema.typeOf(arg);
3965 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {3967 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {
3966 try writer.print("@as({}, {})", .{3968 try writer.print("@as({}, {})", .{
...@@ -3982,7 +3984,7 @@ fn zirCompileLog(...@@ -3982,7 +3984,7 @@ fn zirCompileLog(
3982fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {3984fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
3983 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3985 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3984 const src: LazySrcLoc = inst_data.src();3986 const src: LazySrcLoc = inst_data.src();
3985 const msg_inst = sema.resolveInst(inst_data.operand);3987 const msg_inst = try sema.resolveInst(inst_data.operand);
39863988
3987 return sema.panicWithMsg(block, src, msg_inst);3989 return sema.panicWithMsg(block, src, msg_inst);
3988}3990}
...@@ -4206,7 +4208,7 @@ fn resolveBlockBody(...@@ -4206,7 +4208,7 @@ fn resolveBlockBody(
4206 const break_inst = sema.comptime_break_inst;4208 const break_inst = sema.comptime_break_inst;
4207 const break_data = sema.code.instructions.items(.data)[break_inst].@"break";4209 const break_data = sema.code.instructions.items(.data)[break_inst].@"break";
4208 if (break_data.block_inst == body_inst) {4210 if (break_data.block_inst == body_inst) {
4209 return sema.resolveInst(break_data.operand);4211 return try sema.resolveInst(break_data.operand);
4210 } else {4212 } else {
4211 return error.ComptimeBreak;4213 return error.ComptimeBreak;
4212 }4214 }
...@@ -4536,7 +4538,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -4536,7 +4538,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
4536 defer tracy.end();4538 defer tracy.end();
45374539
4538 const inst_data = sema.code.instructions.items(.data)[inst].@"break";4540 const inst_data = sema.code.instructions.items(.data)[inst].@"break";
4539 const operand = sema.resolveInst(inst_data.operand);4541 const operand = try sema.resolveInst(inst_data.operand);
4540 const zir_block = inst_data.block_inst;4542 const zir_block = inst_data.block_inst;
45414543
4542 var block = start_block;4544 var block = start_block;
...@@ -4602,7 +4604,7 @@ fn zirDbgVar(...@@ -4602,7 +4604,7 @@ fn zirDbgVar(
4602 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return;4604 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return;
46034605
4604 const str_op = sema.code.instructions.items(.data)[inst].str_op;4606 const str_op = sema.code.instructions.items(.data)[inst].str_op;
4605 const operand = sema.resolveInst(str_op.operand);4607 const operand = try sema.resolveInst(str_op.operand);
4606 const name = str_op.getStr(sema.code);4608 const name = str_op.getStr(sema.code);
4607 try sema.addDbgVar(block, operand, air_tag, name);4609 try sema.addDbgVar(block, operand, air_tag, name);
4608}4610}
...@@ -4785,7 +4787,7 @@ fn zirCall(...@@ -4785,7 +4787,7 @@ fn zirCall(
4785 const modifier = @intToEnum(std.builtin.CallOptions.Modifier, extra.data.flags.packed_modifier);4787 const modifier = @intToEnum(std.builtin.CallOptions.Modifier, extra.data.flags.packed_modifier);
4786 const ensure_result_used = extra.data.flags.ensure_result_used;4788 const ensure_result_used = extra.data.flags.ensure_result_used;
47874789
4788 var func = sema.resolveInst(extra.data.callee);4790 var func = try sema.resolveInst(extra.data.callee);
4789 var resolved_args: []Air.Inst.Ref = undefined;4791 var resolved_args: []Air.Inst.Ref = undefined;
47904792
4791 const func_type = sema.typeOf(func);4793 const func_type = sema.typeOf(func);
...@@ -4798,12 +4800,12 @@ fn zirCall(...@@ -4798,12 +4800,12 @@ fn zirCall(
4798 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len + 1);4800 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len + 1);
4799 resolved_args[0] = bound_data.arg0_inst;4801 resolved_args[0] = bound_data.arg0_inst;
4800 for (args) |zir_arg, i| {4802 for (args) |zir_arg, i| {
4801 resolved_args[i + 1] = sema.resolveInst(zir_arg);4803 resolved_args[i + 1] = try sema.resolveInst(zir_arg);
4802 }4804 }
4803 } else {4805 } else {
4804 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len);4806 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len);
4805 for (args) |zir_arg, i| {4807 for (args) |zir_arg, i| {
4806 resolved_args[i] = sema.resolveInst(zir_arg);4808 resolved_args[i] = try sema.resolveInst(zir_arg);
4807 }4809 }
4808 }4810 }
48094811
...@@ -5827,7 +5829,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -5827,7 +5829,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
5827 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };5829 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
5828 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize);5830 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize);
5829 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);5831 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
5830 const uncasted_sentinel = sema.resolveInst(extra.sentinel);5832 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
5831 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);5833 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);
5832 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel);5834 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel);
5833 const array_ty = try Type.array(sema.arena, len, sentinel_val, elem_type, sema.mod);5835 const array_ty = try Type.array(sema.arena, len, sentinel_val, elem_type, sema.mod);
...@@ -5892,7 +5894,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -5892,7 +5894,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
5892 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5894 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5893 const src = inst_data.src();5895 const src = inst_data.src();
5894 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5896 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5895 const op = sema.resolveInst(inst_data.operand);5897 const op = try sema.resolveInst(inst_data.operand);
5896 const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src);5898 const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src);
5897 const result_ty = Type.u16;5899 const result_ty = Type.u16;
58985900
...@@ -5929,7 +5931,7 @@ fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -5929,7 +5931,7 @@ fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
5929 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5931 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5930 const src = inst_data.src();5932 const src = inst_data.src();
5931 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5933 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5932 const uncasted_operand = sema.resolveInst(inst_data.operand);5934 const uncasted_operand = try sema.resolveInst(inst_data.operand);
5933 const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src);5935 const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src);
5934 const target = sema.mod.getTarget();5936 const target = sema.mod.getTarget();
59355937
...@@ -5967,8 +5969,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5967,8 +5969,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
5967 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };5969 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
5968 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };5970 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
5969 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };5971 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
5970 const lhs = sema.resolveInst(extra.lhs);5972 const lhs = try sema.resolveInst(extra.lhs);
5971 const rhs = sema.resolveInst(extra.rhs);5973 const rhs = try sema.resolveInst(extra.rhs);
5972 if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) {5974 if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) {
5973 const msg = msg: {5975 const msg = msg: {
5974 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});5976 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});
...@@ -6027,7 +6029,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -6027,7 +6029,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
6027 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6029 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6028 const src = inst_data.src();6030 const src = inst_data.src();
6029 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6031 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6030 const operand = sema.resolveInst(inst_data.operand);6032 const operand = try sema.resolveInst(inst_data.operand);
6031 const operand_ty = sema.typeOf(operand);6033 const operand_ty = sema.typeOf(operand);
60326034
6033 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) {6035 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) {
...@@ -6075,7 +6077,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -6075,7 +6077,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
6075 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6077 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6076 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6078 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6077 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);6079 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
6078 const operand = sema.resolveInst(extra.rhs);6080 const operand = try sema.resolveInst(extra.rhs);
60796081
6080 if (dest_ty.zigTypeTag() != .Enum) {6082 if (dest_ty.zigTypeTag() != .Enum) {
6081 return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty.fmt(sema.mod)});6083 return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty.fmt(sema.mod)});
...@@ -6126,7 +6128,7 @@ fn zirOptionalPayloadPtr(...@@ -6126,7 +6128,7 @@ fn zirOptionalPayloadPtr(
6126 defer tracy.end();6128 defer tracy.end();
61276129
6128 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6130 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6129 const optional_ptr = sema.resolveInst(inst_data.operand);6131 const optional_ptr = try sema.resolveInst(inst_data.operand);
6130 const src = inst_data.src();6132 const src = inst_data.src();
61316133
6132 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);6134 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);
...@@ -6211,7 +6213,7 @@ fn zirOptionalPayload(...@@ -6211,7 +6213,7 @@ fn zirOptionalPayload(
62116213
6212 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6214 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6213 const src = inst_data.src();6215 const src = inst_data.src();
6214 const operand = sema.resolveInst(inst_data.operand);6216 const operand = try sema.resolveInst(inst_data.operand);
6215 const operand_ty = sema.typeOf(operand);6217 const operand_ty = sema.typeOf(operand);
6216 const result_ty = switch (operand_ty.zigTypeTag()) {6218 const result_ty = switch (operand_ty.zigTypeTag()) {
6217 .Optional => try operand_ty.optionalChildAlloc(sema.arena),6219 .Optional => try operand_ty.optionalChildAlloc(sema.arena),
...@@ -6263,7 +6265,7 @@ fn zirErrUnionPayload(...@@ -6263,7 +6265,7 @@ fn zirErrUnionPayload(
62636265
6264 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6266 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6265 const src = inst_data.src();6267 const src = inst_data.src();
6266 const operand = sema.resolveInst(inst_data.operand);6268 const operand = try sema.resolveInst(inst_data.operand);
6267 const operand_src = src;6269 const operand_src = src;
6268 const operand_ty = sema.typeOf(operand);6270 const operand_ty = sema.typeOf(operand);
6269 if (operand_ty.zigTypeTag() != .ErrorUnion) {6271 if (operand_ty.zigTypeTag() != .ErrorUnion) {
...@@ -6304,7 +6306,7 @@ fn zirErrUnionPayloadPtr(...@@ -6304,7 +6306,7 @@ fn zirErrUnionPayloadPtr(
6304 defer tracy.end();6306 defer tracy.end();
63056307
6306 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6308 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6307 const operand = sema.resolveInst(inst_data.operand);6309 const operand = try sema.resolveInst(inst_data.operand);
6308 const src = inst_data.src();6310 const src = inst_data.src();
63096311
6310 return sema.analyzeErrUnionPayloadPtr(block, src, operand, safety_check, false);6312 return sema.analyzeErrUnionPayloadPtr(block, src, operand, safety_check, false);
...@@ -6390,7 +6392,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -6390,7 +6392,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
63906392
6391 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6393 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6392 const src = inst_data.src();6394 const src = inst_data.src();
6393 const operand = sema.resolveInst(inst_data.operand);6395 const operand = try sema.resolveInst(inst_data.operand);
6394 const operand_ty = sema.typeOf(operand);6396 const operand_ty = sema.typeOf(operand);
6395 if (operand_ty.zigTypeTag() != .ErrorUnion) {6397 if (operand_ty.zigTypeTag() != .ErrorUnion) {
6396 return sema.fail(block, src, "expected error union type, found '{}'", .{6398 return sema.fail(block, src, "expected error union type, found '{}'", .{
...@@ -6416,7 +6418,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -6416,7 +6418,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
64166418
6417 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6419 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6418 const src = inst_data.src();6420 const src = inst_data.src();
6419 const operand = sema.resolveInst(inst_data.operand);6421 const operand = try sema.resolveInst(inst_data.operand);
6420 const operand_ty = sema.typeOf(operand);6422 const operand_ty = sema.typeOf(operand);
6421 assert(operand_ty.zigTypeTag() == .Pointer);6423 assert(operand_ty.zigTypeTag() == .Pointer);
64226424
...@@ -6445,7 +6447,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -6445,7 +6447,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
64456447
6446 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;6448 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
6447 const src = inst_data.src();6449 const src = inst_data.src();
6448 const operand = sema.resolveInst(inst_data.operand);6450 const operand = try sema.resolveInst(inst_data.operand);
6449 const operand_ty = sema.typeOf(operand);6451 const operand_ty = sema.typeOf(operand);
6450 if (operand_ty.zigTypeTag() != .ErrorUnion) {6452 if (operand_ty.zigTypeTag() != .ErrorUnion) {
6451 return sema.fail(block, src, "expected error union type, found '{}'", .{6453 return sema.fail(block, src, "expected error union type, found '{}'", .{
...@@ -6941,7 +6943,7 @@ fn analyzeAs(...@@ -6941,7 +6943,7 @@ fn analyzeAs(
6941 zir_operand: Zir.Inst.Ref,6943 zir_operand: Zir.Inst.Ref,
6942) CompileError!Air.Inst.Ref {6944) CompileError!Air.Inst.Ref {
6943 const dest_ty = try sema.resolveType(block, src, zir_dest_type);6945 const dest_ty = try sema.resolveType(block, src, zir_dest_type);
6944 const operand = sema.resolveInst(zir_operand);6946 const operand = try sema.resolveInst(zir_operand);
6945 if (dest_ty.tag() == .var_args_param) return operand;6947 if (dest_ty.tag() == .var_args_param) return operand;
6946 return sema.coerce(block, dest_ty, operand, src);6948 return sema.coerce(block, dest_ty, operand, src);
6947}6949}
...@@ -6952,7 +6954,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -6952,7 +6954,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
69526954
6953 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6955 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6954 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6956 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6955 const ptr = sema.resolveInst(inst_data.operand);6957 const ptr = try sema.resolveInst(inst_data.operand);
6956 const ptr_ty = sema.typeOf(ptr);6958 const ptr_ty = sema.typeOf(ptr);
6957 if (!ptr_ty.isPtrAtRuntime()) {6959 if (!ptr_ty.isPtrAtRuntime()) {
6958 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)});6960 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)});
...@@ -6973,7 +6975,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -6973,7 +6975,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
6973 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };6975 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
6974 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;6976 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
6975 const field_name = sema.code.nullTerminatedString(extra.field_name_start);6977 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
6976 const object = sema.resolveInst(extra.lhs);6978 const object = try sema.resolveInst(extra.lhs);
6977 return sema.fieldVal(block, src, object, field_name, field_name_src);6979 return sema.fieldVal(block, src, object, field_name, field_name_src);
6978}6980}
69796981
...@@ -6986,7 +6988,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -6986,7 +6988,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
6986 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };6988 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
6987 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;6989 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
6988 const field_name = sema.code.nullTerminatedString(extra.field_name_start);6990 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
6989 const object_ptr = sema.resolveInst(extra.lhs);6991 const object_ptr = try sema.resolveInst(extra.lhs);
6990 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);6992 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
6991}6993}
69926994
...@@ -6999,7 +7001,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -6999,7 +7001,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
6999 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };7001 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
7000 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;7002 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
7001 const field_name = sema.code.nullTerminatedString(extra.field_name_start);7003 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
7002 const object_ptr = sema.resolveInst(extra.lhs);7004 const object_ptr = try sema.resolveInst(extra.lhs);
7003 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);7005 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
7004}7006}
70057007
...@@ -7011,7 +7013,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -7011,7 +7013,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
7011 const src = inst_data.src();7013 const src = inst_data.src();
7012 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };7014 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
7013 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;7015 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
7014 const object = sema.resolveInst(extra.lhs);7016 const object = try sema.resolveInst(extra.lhs);
7015 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);7017 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
7016 return sema.fieldVal(block, src, object, field_name, field_name_src);7018 return sema.fieldVal(block, src, object, field_name, field_name_src);
7017}7019}
...@@ -7024,7 +7026,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -7024,7 +7026,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
7024 const src = inst_data.src();7026 const src = inst_data.src();
7025 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };7027 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
7026 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;7028 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
7027 const object_ptr = sema.resolveInst(extra.lhs);7029 const object_ptr = try sema.resolveInst(extra.lhs);
7028 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);7030 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
7029 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);7031 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
7030}7032}
...@@ -7036,7 +7038,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Block, extended: Zir.Inst.Extended...@@ -7036,7 +7038,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Block, extended: Zir.Inst.Extended
7036 const extra = sema.code.extraData(Zir.Inst.FieldNamedNode, extended.operand).data;7038 const extra = sema.code.extraData(Zir.Inst.FieldNamedNode, extended.operand).data;
7037 const src: LazySrcLoc = .{ .node_offset = extra.node };7039 const src: LazySrcLoc = .{ .node_offset = extra.node };
7038 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };7040 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
7039 const object_ptr = sema.resolveInst(extra.lhs);7041 const object_ptr = try sema.resolveInst(extra.lhs);
7040 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);7042 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
7041 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);7043 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
7042}7044}
...@@ -7051,7 +7053,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -7051,7 +7053,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
7051 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;7053 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
70527054
7053 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);7055 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
7054 const operand = sema.resolveInst(extra.rhs);7056 const operand = try sema.resolveInst(extra.rhs);
70557057
7056 return sema.intCast(block, dest_ty, dest_ty_src, operand, operand_src, true);7058 return sema.intCast(block, dest_ty, dest_ty_src, operand, operand_src, true);
7057}7059}
...@@ -7241,7 +7243,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -7241,7 +7243,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
7241 => {},7243 => {},
7242 }7244 }
72437245
7244 const operand = sema.resolveInst(extra.rhs);7246 const operand = try sema.resolveInst(extra.rhs);
7245 return sema.bitCast(block, dest_ty, operand, operand_src);7247 return sema.bitCast(block, dest_ty, operand, operand_src);
7246}7248}
72477249
...@@ -7256,7 +7258,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -7256,7 +7258,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
7256 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;7258 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
72577259
7258 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);7260 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
7259 const operand = sema.resolveInst(extra.rhs);7261 const operand = try sema.resolveInst(extra.rhs);
72607262
7261 const target = sema.mod.getTarget();7263 const target = sema.mod.getTarget();
7262 const dest_is_comptime_float = switch (dest_ty.zigTypeTag()) {7264 const dest_is_comptime_float = switch (dest_ty.zigTypeTag()) {
...@@ -7301,8 +7303,8 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -7301,8 +7303,8 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
7301 defer tracy.end();7303 defer tracy.end();
73027304
7303 const bin_inst = sema.code.instructions.items(.data)[inst].bin;7305 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7304 const array = sema.resolveInst(bin_inst.lhs);7306 const array = try sema.resolveInst(bin_inst.lhs);
7305 const elem_index = sema.resolveInst(bin_inst.rhs);7307 const elem_index = try sema.resolveInst(bin_inst.rhs);
7306 return sema.elemVal(block, sema.src, array, elem_index, sema.src);7308 return sema.elemVal(block, sema.src, array, elem_index, sema.src);
7307}7309}
73087310
...@@ -7314,8 +7316,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7314,8 +7316,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7314 const src = inst_data.src();7316 const src = inst_data.src();
7315 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };7317 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
7316 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;7318 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7317 const array = sema.resolveInst(extra.lhs);7319 const array = try sema.resolveInst(extra.lhs);
7318 const elem_index = sema.resolveInst(extra.rhs);7320 const elem_index = try sema.resolveInst(extra.rhs);
7319 return sema.elemVal(block, src, array, elem_index, elem_index_src);7321 return sema.elemVal(block, src, array, elem_index, elem_index_src);
7320}7322}
73217323
...@@ -7324,8 +7326,8 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -7324,8 +7326,8 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
7324 defer tracy.end();7326 defer tracy.end();
73257327
7326 const bin_inst = sema.code.instructions.items(.data)[inst].bin;7328 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7327 const array_ptr = sema.resolveInst(bin_inst.lhs);7329 const array_ptr = try sema.resolveInst(bin_inst.lhs);
7328 const elem_index = sema.resolveInst(bin_inst.rhs);7330 const elem_index = try sema.resolveInst(bin_inst.rhs);
7329 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);7331 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
7330}7332}
73317333
...@@ -7337,8 +7339,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7337,8 +7339,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7337 const src = inst_data.src();7339 const src = inst_data.src();
7338 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };7340 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
7339 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;7341 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7340 const array_ptr = sema.resolveInst(extra.lhs);7342 const array_ptr = try sema.resolveInst(extra.lhs);
7341 const elem_index = sema.resolveInst(extra.rhs);7343 const elem_index = try sema.resolveInst(extra.rhs);
7342 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);7344 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
7343}7345}
73447346
...@@ -7349,7 +7351,7 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -7349,7 +7351,7 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
7349 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;7351 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
7350 const src = inst_data.src();7352 const src = inst_data.src();
7351 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;7353 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
7352 const array_ptr = sema.resolveInst(extra.ptr);7354 const array_ptr = try sema.resolveInst(extra.ptr);
7353 const elem_index = try sema.addIntUnsigned(Type.usize, extra.index);7355 const elem_index = try sema.addIntUnsigned(Type.usize, extra.index);
7354 return sema.elemPtr(block, src, array_ptr, elem_index, src);7356 return sema.elemPtr(block, src, array_ptr, elem_index, src);
7355}7357}
...@@ -7361,8 +7363,8 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -7361,8 +7363,8 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
7361 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;7363 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
7362 const src = inst_data.src();7364 const src = inst_data.src();
7363 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;7365 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
7364 const array_ptr = sema.resolveInst(extra.lhs);7366 const array_ptr = try sema.resolveInst(extra.lhs);
7365 const start = sema.resolveInst(extra.start);7367 const start = try sema.resolveInst(extra.start);
73667368
7367 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);7369 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);
7368}7370}
...@@ -7374,9 +7376,9 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -7374,9 +7376,9 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
7374 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;7376 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
7375 const src = inst_data.src();7377 const src = inst_data.src();
7376 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;7378 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
7377 const array_ptr = sema.resolveInst(extra.lhs);7379 const array_ptr = try sema.resolveInst(extra.lhs);
7378 const start = sema.resolveInst(extra.start);7380 const start = try sema.resolveInst(extra.start);
7379 const end = sema.resolveInst(extra.end);7381 const end = try sema.resolveInst(extra.end);
73807382
7381 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);7383 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);
7382}7384}
...@@ -7389,10 +7391,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -7389,10 +7391,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
7389 const src = inst_data.src();7391 const src = inst_data.src();
7390 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };7392 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
7391 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;7393 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
7392 const array_ptr = sema.resolveInst(extra.lhs);7394 const array_ptr = try sema.resolveInst(extra.lhs);
7393 const start = sema.resolveInst(extra.start);7395 const start = try sema.resolveInst(extra.start);
7394 const end = sema.resolveInst(extra.end);7396 const end = try sema.resolveInst(extra.end);
7395 const sentinel = sema.resolveInst(extra.sentinel);7397 const sentinel = try sema.resolveInst(extra.sentinel);
73967398
7397 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);7399 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);
7398}7400}
...@@ -7416,7 +7418,7 @@ fn zirSwitchCapture(...@@ -7416,7 +7418,7 @@ fn zirSwitchCapture(
7416 const operand_is_ref = switch_extra.data.bits.is_ref;7418 const operand_is_ref = switch_extra.data.bits.is_ref;
7417 const cond_inst = Zir.refToIndex(switch_extra.data.operand).?;7419 const cond_inst = Zir.refToIndex(switch_extra.data.operand).?;
7418 const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node;7420 const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node;
7419 const operand_ptr = sema.resolveInst(cond_info.operand);7421 const operand_ptr = try sema.resolveInst(cond_info.operand);
7420 const operand_ptr_ty = sema.typeOf(operand_ptr);7422 const operand_ptr_ty = sema.typeOf(operand_ptr);
7421 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;7423 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
74227424
...@@ -7450,7 +7452,7 @@ fn zirSwitchCapture(...@@ -7450,7 +7452,7 @@ fn zirSwitchCapture(
7450 const union_obj = operand_ty.cast(Type.Payload.Union).?.data;7452 const union_obj = operand_ty.cast(Type.Payload.Union).?.data;
7451 const enum_ty = union_obj.tag_ty;7453 const enum_ty = union_obj.tag_ty;
74527454
7453 const first_item = sema.resolveInst(items[0]);7455 const first_item = try sema.resolveInst(items[0]);
7454 // Previous switch validation ensured this will succeed7456 // Previous switch validation ensured this will succeed
7455 const first_item_val = sema.resolveConstValue(block, .unneeded, first_item) catch unreachable;7457 const first_item_val = sema.resolveConstValue(block, .unneeded, first_item) catch unreachable;
74567458
...@@ -7458,7 +7460,7 @@ fn zirSwitchCapture(...@@ -7458,7 +7460,7 @@ fn zirSwitchCapture(
7458 const first_field = union_obj.fields.values()[first_field_index];7460 const first_field = union_obj.fields.values()[first_field_index];
74597461
7460 for (items[1..]) |item| {7462 for (items[1..]) |item| {
7461 const item_ref = sema.resolveInst(item);7463 const item_ref = try sema.resolveInst(item);
7462 // Previous switch validation ensured this will succeed7464 // Previous switch validation ensured this will succeed
7463 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;7465 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
74647466
...@@ -7515,7 +7517,7 @@ fn zirSwitchCapture(...@@ -7515,7 +7517,7 @@ fn zirSwitchCapture(
7515 var names: Module.ErrorSet.NameMap = .{};7517 var names: Module.ErrorSet.NameMap = .{};
7516 try names.ensureUnusedCapacity(sema.arena, items.len);7518 try names.ensureUnusedCapacity(sema.arena, items.len);
7517 for (items) |item| {7519 for (items) |item| {
7518 const item_ref = sema.resolveInst(item);7520 const item_ref = try sema.resolveInst(item);
7519 // Previous switch validation ensured this will succeed7521 // Previous switch validation ensured this will succeed
7520 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;7522 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
7521 names.putAssumeCapacityNoClobber(7523 names.putAssumeCapacityNoClobber(
...@@ -7529,7 +7531,7 @@ fn zirSwitchCapture(...@@ -7529,7 +7531,7 @@ fn zirSwitchCapture(
75297531
7530 return sema.bitCast(block, else_error_ty, operand, operand_src);7532 return sema.bitCast(block, else_error_ty, operand, operand_src);
7531 } else {7533 } else {
7532 const item_ref = sema.resolveInst(items[0]);7534 const item_ref = try sema.resolveInst(items[0]);
7533 // Previous switch validation ensured this will succeed7535 // Previous switch validation ensured this will succeed
7534 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;7536 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
75357537
...@@ -7559,7 +7561,7 @@ fn zirSwitchCond(...@@ -7559,7 +7561,7 @@ fn zirSwitchCond(
7559 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7561 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7560 const src = inst_data.src();7562 const src = inst_data.src();
7561 const operand_src = src; // TODO make this point at the switch operand7563 const operand_src = src; // TODO make this point at the switch operand
7562 const operand_ptr = sema.resolveInst(inst_data.operand);7564 const operand_ptr = try sema.resolveInst(inst_data.operand);
7563 const operand = if (is_ref)7565 const operand = if (is_ref)
7564 try sema.analyzeLoad(block, src, operand_ptr, operand_src)7566 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
7565 else7567 else
...@@ -7630,7 +7632,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7630,7 +7632,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7630 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };7632 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };
7631 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);7633 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
76327634
7633 const operand = sema.resolveInst(extra.data.operand);7635 const operand = try sema.resolveInst(extra.data.operand);
76347636
7635 var header_extra_index: usize = extra.end;7637 var header_extra_index: usize = extra.end;
76367638
...@@ -8208,7 +8210,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8208,7 +8210,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8208 const body = sema.code.extra[extra_index..][0..body_len];8210 const body = sema.code.extra[extra_index..][0..body_len];
8209 extra_index += body_len;8211 extra_index += body_len;
82108212
8211 const item = sema.resolveInst(item_ref);8213 const item = try sema.resolveInst(item_ref);
8212 // Validation above ensured these will succeed.8214 // Validation above ensured these will succeed.
8213 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;8215 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;
8214 if (operand_val.eql(item_val, operand_ty, sema.mod)) {8216 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
...@@ -8230,7 +8232,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8230,7 +8232,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8230 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..body_len];8232 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..body_len];
82318233
8232 for (items) |item_ref| {8234 for (items) |item_ref| {
8233 const item = sema.resolveInst(item_ref);8235 const item = try sema.resolveInst(item_ref);
8234 // Validation above ensured these will succeed.8236 // Validation above ensured these will succeed.
8235 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;8237 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;
8236 if (operand_val.eql(item_val, operand_ty, sema.mod)) {8238 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
...@@ -8298,7 +8300,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8298,7 +8300,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8298 case_block.instructions.shrinkRetainingCapacity(0);8300 case_block.instructions.shrinkRetainingCapacity(0);
8299 case_block.wip_capture_scope = wip_captures.scope;8301 case_block.wip_capture_scope = wip_captures.scope;
83008302
8301 const item = sema.resolveInst(item_ref);8303 const item = try sema.resolveInst(item_ref);
8302 // `item` is already guaranteed to be constant known.8304 // `item` is already guaranteed to be constant known.
83038305
8304 _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) {8306 _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) {
...@@ -8375,14 +8377,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8375,14 +8377,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8375 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));8377 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
83768378
8377 for (items) |item_ref| {8379 for (items) |item_ref| {
8378 const item = sema.resolveInst(item_ref);8380 const item = try sema.resolveInst(item_ref);
8379 cases_extra.appendAssumeCapacity(@enumToInt(item));8381 cases_extra.appendAssumeCapacity(@enumToInt(item));
8380 }8382 }
83818383
8382 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);8384 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
8383 } else {8385 } else {
8384 for (items) |item_ref| {8386 for (items) |item_ref| {
8385 const item = sema.resolveInst(item_ref);8387 const item = try sema.resolveInst(item_ref);
8386 const cmp_ok = try case_block.addBinOp(.cmp_eq, operand, item);8388 const cmp_ok = try case_block.addBinOp(.cmp_eq, operand, item);
8387 if (any_ok != .none) {8389 if (any_ok != .none) {
8388 any_ok = try case_block.addBinOp(.bool_or, any_ok, cmp_ok);8390 any_ok = try case_block.addBinOp(.bool_or, any_ok, cmp_ok);
...@@ -8398,8 +8400,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8398,8 +8400,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8398 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);8400 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
8399 extra_index += 1;8401 extra_index += 1;
84008402
8401 const item_first = sema.resolveInst(first_ref);8403 const item_first = try sema.resolveInst(first_ref);
8402 const item_last = sema.resolveInst(last_ref);8404 const item_last = try sema.resolveInst(last_ref);
84038405
8404 // operand >= first and operand <= last8406 // operand >= first and operand <= last
8405 const range_first_ok = try case_block.addBinOp(8407 const range_first_ok = try case_block.addBinOp(
...@@ -8552,7 +8554,7 @@ fn resolveSwitchItemVal(...@@ -8552,7 +8554,7 @@ fn resolveSwitchItemVal(
8552 switch_prong_src: Module.SwitchProngSrc,8554 switch_prong_src: Module.SwitchProngSrc,
8553 range_expand: Module.SwitchProngSrc.RangeExpand,8555 range_expand: Module.SwitchProngSrc.RangeExpand,
8554) CompileError!TypedValue {8556) CompileError!TypedValue {
8555 const item = sema.resolveInst(item_ref);8557 const item = try sema.resolveInst(item_ref);
8556 const item_ty = sema.typeOf(item);8558 const item_ty = sema.typeOf(item);
8557 // Constructing a LazySrcLoc is costly because we only have the switch AST node.8559 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
8558 // Only if we know for sure we need to report a compile error do we resolve the8560 // Only if we know for sure we need to report a compile error do we resolve the
...@@ -8903,8 +8905,8 @@ fn zirShl(...@@ -8903,8 +8905,8 @@ fn zirShl(
8903 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };8905 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
8904 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };8906 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
8905 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8907 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8906 const lhs = sema.resolveInst(extra.lhs);8908 const lhs = try sema.resolveInst(extra.lhs);
8907 const rhs = sema.resolveInst(extra.rhs);8909 const rhs = try sema.resolveInst(extra.rhs);
8908 const lhs_ty = sema.typeOf(lhs);8910 const lhs_ty = sema.typeOf(lhs);
8909 const rhs_ty = sema.typeOf(rhs);8911 const rhs_ty = sema.typeOf(rhs);
8910 const target = sema.mod.getTarget();8912 const target = sema.mod.getTarget();
...@@ -9031,8 +9033,8 @@ fn zirShr(...@@ -9031,8 +9033,8 @@ fn zirShr(
9031 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };9033 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
9032 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };9034 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
9033 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9035 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9034 const lhs = sema.resolveInst(extra.lhs);9036 const lhs = try sema.resolveInst(extra.lhs);
9035 const rhs = sema.resolveInst(extra.rhs);9037 const rhs = try sema.resolveInst(extra.rhs);
9036 const lhs_ty = sema.typeOf(lhs);9038 const lhs_ty = sema.typeOf(lhs);
9037 const rhs_ty = sema.typeOf(rhs);9039 const rhs_ty = sema.typeOf(rhs);
9038 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);9040 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
...@@ -9085,8 +9087,8 @@ fn zirBitwise(...@@ -9085,8 +9087,8 @@ fn zirBitwise(
9085 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };9087 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
9086 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };9088 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
9087 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9089 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9088 const lhs = sema.resolveInst(extra.lhs);9090 const lhs = try sema.resolveInst(extra.lhs);
9089 const rhs = sema.resolveInst(extra.rhs);9091 const rhs = try sema.resolveInst(extra.rhs);
9090 const lhs_ty = sema.typeOf(lhs);9092 const lhs_ty = sema.typeOf(lhs);
9091 const rhs_ty = sema.typeOf(rhs);9093 const rhs_ty = sema.typeOf(rhs);
9092 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);9094 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
...@@ -9130,7 +9132,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -9130,7 +9132,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
9130 const src = inst_data.src();9132 const src = inst_data.src();
9131 const operand_src = src; // TODO put this on the operand, not the '~'9133 const operand_src = src; // TODO put this on the operand, not the '~'
91329134
9133 const operand = sema.resolveInst(inst_data.operand);9135 const operand = try sema.resolveInst(inst_data.operand);
9134 const operand_type = sema.typeOf(operand);9136 const operand_type = sema.typeOf(operand);
9135 const scalar_type = operand_type.scalarType();9137 const scalar_type = operand_type.scalarType();
9136 const target = sema.mod.getTarget();9138 const target = sema.mod.getTarget();
...@@ -9245,8 +9247,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -9245,8 +9247,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
92459247
9246 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9248 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9247 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9249 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9248 const lhs = sema.resolveInst(extra.lhs);9250 const lhs = try sema.resolveInst(extra.lhs);
9249 const rhs = sema.resolveInst(extra.rhs);9251 const rhs = try sema.resolveInst(extra.rhs);
9250 const lhs_ty = sema.typeOf(lhs);9252 const lhs_ty = sema.typeOf(lhs);
9251 const rhs_ty = sema.typeOf(rhs);9253 const rhs_ty = sema.typeOf(rhs);
92529254
...@@ -9429,7 +9431,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -9429,7 +9431,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
94299431
9430 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9432 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9431 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9433 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9432 const lhs = sema.resolveInst(extra.lhs);9434 const lhs = try sema.resolveInst(extra.lhs);
9433 const lhs_ty = sema.typeOf(lhs);9435 const lhs_ty = sema.typeOf(lhs);
9434 const src: LazySrcLoc = inst_data.src();9436 const src: LazySrcLoc = inst_data.src();
9435 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };9437 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
...@@ -9509,7 +9511,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -9509,7 +9511,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
9509 const lhs_src = src;9511 const lhs_src = src;
9510 const rhs_src = src; // TODO better source location9512 const rhs_src = src; // TODO better source location
95119513
9512 const rhs = sema.resolveInst(inst_data.operand);9514 const rhs = try sema.resolveInst(inst_data.operand);
9513 const rhs_ty = sema.typeOf(rhs);9515 const rhs_ty = sema.typeOf(rhs);
9514 const rhs_scalar_ty = rhs_ty.scalarType();9516 const rhs_scalar_ty = rhs_ty.scalarType();
95159517
...@@ -9529,7 +9531,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -9529,7 +9531,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
9529 const lhs = if (rhs_ty.zigTypeTag() == .Vector)9531 const lhs = if (rhs_ty.zigTypeTag() == .Vector)
9530 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))9532 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))
9531 else9533 else
9532 sema.resolveInst(.zero);9534 try sema.resolveInst(.zero);
95339535
9534 return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src);9536 return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src);
9535}9537}
...@@ -9540,13 +9542,13 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -9540,13 +9542,13 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
9540 const lhs_src = src;9542 const lhs_src = src;
9541 const rhs_src = src; // TODO better source location9543 const rhs_src = src; // TODO better source location
95429544
9543 const rhs = sema.resolveInst(inst_data.operand);9545 const rhs = try sema.resolveInst(inst_data.operand);
9544 const rhs_ty = sema.typeOf(rhs);9546 const rhs_ty = sema.typeOf(rhs);
95459547
9546 const lhs = if (rhs_ty.zigTypeTag() == .Vector)9548 const lhs = if (rhs_ty.zigTypeTag() == .Vector)
9547 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))9549 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))
9548 else9550 else
9549 sema.resolveInst(.zero);9551 try sema.resolveInst(.zero);
95509552
9551 return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src);9553 return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src);
9552}9554}
...@@ -9565,8 +9567,8 @@ fn zirArithmetic(...@@ -9565,8 +9567,8 @@ fn zirArithmetic(
9565 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };9567 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
9566 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };9568 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
9567 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9569 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9568 const lhs = sema.resolveInst(extra.lhs);9570 const lhs = try sema.resolveInst(extra.lhs);
9569 const rhs = sema.resolveInst(extra.rhs);9571 const rhs = try sema.resolveInst(extra.rhs);
95709572
9571 return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src);9573 return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src);
9572}9574}
...@@ -9587,9 +9589,9 @@ fn zirOverflowArithmetic(...@@ -9587,9 +9589,9 @@ fn zirOverflowArithmetic(
9587 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };9589 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
9588 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };9590 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
95899591
9590 const lhs = sema.resolveInst(extra.lhs);9592 const lhs = try sema.resolveInst(extra.lhs);
9591 const rhs = sema.resolveInst(extra.rhs);9593 const rhs = try sema.resolveInst(extra.rhs);
9592 const ptr = sema.resolveInst(extra.ptr);9594 const ptr = try sema.resolveInst(extra.ptr);
95939595
9594 const lhs_ty = sema.typeOf(lhs);9596 const lhs_ty = sema.typeOf(lhs);
9595 const rhs_ty = sema.typeOf(rhs);9597 const rhs_ty = sema.typeOf(rhs);
...@@ -10788,7 +10790,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In...@@ -10788,7 +10790,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In
10788 const inst_data = sema.code.instructions.items(.data)[inst].un_node;10790 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
10789 const src = inst_data.src();10791 const src = inst_data.src();
10790 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };10792 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };
10791 const ptr = sema.resolveInst(inst_data.operand);10793 const ptr = try sema.resolveInst(inst_data.operand);
10792 return sema.analyzeLoad(block, src, ptr, ptr_src);10794 return sema.analyzeLoad(block, src, ptr, ptr_src);
10793}10795}
1079410796
...@@ -10880,7 +10882,7 @@ fn zirAsm(...@@ -10880,7 +10882,7 @@ fn zirAsm(
10880 const input = sema.code.extraData(Zir.Inst.Asm.Input, extra_i);10882 const input = sema.code.extraData(Zir.Inst.Asm.Input, extra_i);
10881 extra_i = input.end;10883 extra_i = input.end;
1088210884
10883 const uncasted_arg = sema.resolveInst(input.data.operand);10885 const uncasted_arg = try sema.resolveInst(input.data.operand);
10884 const uncasted_arg_ty = sema.typeOf(uncasted_arg);10886 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
10885 switch (uncasted_arg_ty.zigTypeTag()) {10887 switch (uncasted_arg_ty.zigTypeTag()) {
10886 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),10888 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),
...@@ -10969,8 +10971,8 @@ fn zirCmpEq(...@@ -10969,8 +10971,8 @@ fn zirCmpEq(
10969 const src: LazySrcLoc = inst_data.src();10971 const src: LazySrcLoc = inst_data.src();
10970 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };10972 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
10971 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };10973 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
10972 const lhs = sema.resolveInst(extra.lhs);10974 const lhs = try sema.resolveInst(extra.lhs);
10973 const rhs = sema.resolveInst(extra.rhs);10975 const rhs = try sema.resolveInst(extra.rhs);
1097410976
10975 const lhs_ty = sema.typeOf(lhs);10977 const lhs_ty = sema.typeOf(lhs);
10976 const rhs_ty = sema.typeOf(rhs);10978 const rhs_ty = sema.typeOf(rhs);
...@@ -11081,8 +11083,8 @@ fn zirCmp(...@@ -11081,8 +11083,8 @@ fn zirCmp(
11081 const src: LazySrcLoc = inst_data.src();11083 const src: LazySrcLoc = inst_data.src();
11082 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };11084 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
11083 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };11085 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
11084 const lhs = sema.resolveInst(extra.lhs);11086 const lhs = try sema.resolveInst(extra.lhs);
11085 const rhs = sema.resolveInst(extra.rhs);11087 const rhs = try sema.resolveInst(extra.rhs);
11086 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);11088 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
11087}11089}
1108811090
...@@ -11276,7 +11278,7 @@ fn zirClosureCapture(...@@ -11276,7 +11278,7 @@ fn zirClosureCapture(
11276 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }11278 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }
11277 // ...in which case the closure_capture instruction has access to a runtime11279 // ...in which case the closure_capture instruction has access to a runtime
11278 // value only. In such case we preserve the type and use a dummy runtime value.11280 // value only. In such case we preserve the type and use a dummy runtime value.
11279 const operand = sema.resolveInst(inst_data.operand);11281 const operand = try sema.resolveInst(inst_data.operand);
11280 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) orelse11282 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) orelse
11281 Value.initTag(.generic_poison);11283 Value.initTag(.generic_poison);
1128211284
...@@ -12249,7 +12251,7 @@ fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12249,7 +12251,7 @@ fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12249 _ = block;12251 _ = block;
12250 const zir_datas = sema.code.instructions.items(.data);12252 const zir_datas = sema.code.instructions.items(.data);
12251 const inst_data = zir_datas[inst].un_node;12253 const inst_data = zir_datas[inst].un_node;
12252 const operand = sema.resolveInst(inst_data.operand);12254 const operand = try sema.resolveInst(inst_data.operand);
12253 const operand_ty = sema.typeOf(operand);12255 const operand_ty = sema.typeOf(operand);
12254 return sema.addType(operand_ty);12256 return sema.addType(operand_ty);
12255}12257}
...@@ -12282,7 +12284,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -12282,7 +12284,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
12282fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {12284fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
12283 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12285 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12284 const src = inst_data.src();12286 const src = inst_data.src();
12285 const operand = sema.resolveInst(inst_data.operand);12287 const operand = try sema.resolveInst(inst_data.operand);
12286 const operand_ty = sema.typeOf(operand);12288 const operand_ty = sema.typeOf(operand);
12287 const res_ty = try sema.log2IntType(block, operand_ty, src);12289 const res_ty = try sema.log2IntType(block, operand_ty, src);
12288 return sema.addType(res_ty);12290 return sema.addType(res_ty);
...@@ -12364,8 +12366,7 @@ fn zirTypeofPeer(...@@ -12364,8 +12366,7 @@ fn zirTypeofPeer(
12364 defer sema.gpa.free(inst_list);12366 defer sema.gpa.free(inst_list);
1236512367
12366 for (args) |arg_ref, i| {12368 for (args) |arg_ref, i| {
12367 inst_list[i] = sema.resolveInst(arg_ref);12369 inst_list[i] = try sema.resolveInst(arg_ref);
12368 if (sema.typeOf(inst_list[i]).tag() == .generic_poison) return error.GenericPoison;
12369 }12370 }
1237012371
12371 const result_type = try sema.resolvePeerTypes(block, src, inst_list, .{ .typeof_builtin_call_node_offset = extra.data.src_node });12372 const result_type = try sema.resolvePeerTypes(block, src, inst_list, .{ .typeof_builtin_call_node_offset = extra.data.src_node });
...@@ -12379,7 +12380,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -12379,7 +12380,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
12379 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12380 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12380 const src = inst_data.src();12381 const src = inst_data.src();
12381 const operand_src = src; // TODO put this on the operand, not the `!`12382 const operand_src = src; // TODO put this on the operand, not the `!`
12382 const uncasted_operand = sema.resolveInst(inst_data.operand);12383 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1238312384
12384 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);12385 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
12385 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {12386 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
...@@ -12405,7 +12406,7 @@ fn zirBoolBr(...@@ -12405,7 +12406,7 @@ fn zirBoolBr(
1240512406
12406 const datas = sema.code.instructions.items(.data);12407 const datas = sema.code.instructions.items(.data);
12407 const inst_data = datas[inst].bool_br;12408 const inst_data = datas[inst].bool_br;
12408 const lhs = sema.resolveInst(inst_data.lhs);12409 const lhs = try sema.resolveInst(inst_data.lhs);
12409 const lhs_src = sema.src;12410 const lhs_src = sema.src;
12410 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);12411 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
12411 const body = sema.code.extra[extra.end..][0..extra.data.body_len];12412 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
...@@ -12490,7 +12491,7 @@ fn zirIsNonNull(...@@ -12490,7 +12491,7 @@ fn zirIsNonNull(
1249012491
12491 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12492 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12492 const src = inst_data.src();12493 const src = inst_data.src();
12493 const operand = sema.resolveInst(inst_data.operand);12494 const operand = try sema.resolveInst(inst_data.operand);
12494 return sema.analyzeIsNull(block, src, operand, true);12495 return sema.analyzeIsNull(block, src, operand, true);
12495}12496}
1249612497
...@@ -12504,7 +12505,7 @@ fn zirIsNonNullPtr(...@@ -12504,7 +12505,7 @@ fn zirIsNonNullPtr(
1250412505
12505 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12506 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12506 const src = inst_data.src();12507 const src = inst_data.src();
12507 const ptr = sema.resolveInst(inst_data.operand);12508 const ptr = try sema.resolveInst(inst_data.operand);
12508 if ((try sema.resolveMaybeUndefVal(block, src, ptr)) == null) {12509 if ((try sema.resolveMaybeUndefVal(block, src, ptr)) == null) {
12509 return block.addUnOp(.is_non_null_ptr, ptr);12510 return block.addUnOp(.is_non_null_ptr, ptr);
12510 }12511 }
...@@ -12517,7 +12518,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12517,7 +12518,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12517 defer tracy.end();12518 defer tracy.end();
1251812519
12519 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12520 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12520 const operand = sema.resolveInst(inst_data.operand);12521 const operand = try sema.resolveInst(inst_data.operand);
12521 return sema.analyzeIsNonErr(block, inst_data.src(), operand);12522 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
12522}12523}
1252312524
...@@ -12527,7 +12528,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -12527,7 +12528,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1252712528
12528 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12529 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12529 const src = inst_data.src();12530 const src = inst_data.src();
12530 const ptr = sema.resolveInst(inst_data.operand);12531 const ptr = try sema.resolveInst(inst_data.operand);
12531 const loaded = try sema.analyzeLoad(block, src, ptr, src);12532 const loaded = try sema.analyzeLoad(block, src, ptr, src);
12532 return sema.analyzeIsNonErr(block, src, loaded);12533 return sema.analyzeIsNonErr(block, src, loaded);
12533}12534}
...@@ -12548,7 +12549,7 @@ fn zirCondbr(...@@ -12548,7 +12549,7 @@ fn zirCondbr(
12548 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];12549 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
12549 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];12550 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1255012551
12551 const uncasted_cond = sema.resolveInst(extra.data.condition);12552 const uncasted_cond = try sema.resolveInst(extra.data.condition);
12552 const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src);12553 const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src);
1255312554
12554 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {12555 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {
...@@ -12656,7 +12657,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi...@@ -12656,7 +12657,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
12656 break :blk labeled_block;12657 break :blk labeled_block;
12657 };12658 };
1265812659
12659 const operand = sema.resolveInst(break_data.operand);12660 const operand = try sema.resolveInst(break_data.operand);
12660 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);12661 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);
12661 try labeled_block.label.merges.results.append(sema.gpa, operand);12662 try labeled_block.label.merges.results.append(sema.gpa, operand);
12662 try labeled_block.label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?);12663 try labeled_block.label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?);
...@@ -12707,7 +12708,7 @@ fn zirRetTok(...@@ -12707,7 +12708,7 @@ fn zirRetTok(
12707 defer tracy.end();12708 defer tracy.end();
1270812709
12709 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;12710 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
12710 const operand = sema.resolveInst(inst_data.operand);12711 const operand = try sema.resolveInst(inst_data.operand);
12711 const src = inst_data.src();12712 const src = inst_data.src();
1271212713
12713 return sema.analyzeRet(block, operand, src);12714 return sema.analyzeRet(block, operand, src);
...@@ -12718,7 +12719,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir...@@ -12718,7 +12719,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
12718 defer tracy.end();12719 defer tracy.end();
1271912720
12720 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12721 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12721 const operand = sema.resolveInst(inst_data.operand);12722 const operand = try sema.resolveInst(inst_data.operand);
12722 const src = inst_data.src();12723 const src = inst_data.src();
1272312724
12724 return sema.analyzeRet(block, operand, src);12725 return sema.analyzeRet(block, operand, src);
...@@ -12730,7 +12731,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir...@@ -12730,7 +12731,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1273012731
12731 const inst_data = sema.code.instructions.items(.data)[inst].un_node;12732 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12732 const src = inst_data.src();12733 const src = inst_data.src();
12733 const ret_ptr = sema.resolveInst(inst_data.operand);12734 const ret_ptr = try sema.resolveInst(inst_data.operand);
1273412735
12735 if (block.is_comptime or block.inlining != null) {12736 if (block.is_comptime or block.inlining != null) {
12736 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);12737 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);
...@@ -12853,7 +12854,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -12853,7 +12854,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
12853 const abi_align: u32 = if (inst_data.flags.has_align) blk: {12854 const abi_align: u32 = if (inst_data.flags.has_align) blk: {
12854 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);12855 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
12855 extra_i += 1;12856 extra_i += 1;
12856 const coerced = try sema.coerce(block, Type.u32, sema.resolveInst(ref), src);12857 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), src);
12857 const val = try sema.resolveConstValue(block, src, coerced);12858 const val = try sema.resolveConstValue(block, src, coerced);
12858 // Check if this happens to be the lazy alignment of our element type, in12859 // Check if this happens to be the lazy alignment of our element type, in
12859 // which case we can make this 0 without resolving it.12860 // which case we can make this 0 without resolving it.
...@@ -12980,7 +12981,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -12980,7 +12981,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
12980 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;12981 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
12981 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);12982 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
12982 const field_name = try sema.resolveConstString(block, field_src, extra.field_name);12983 const field_name = try sema.resolveConstString(block, field_src, extra.field_name);
12983 const init = sema.resolveInst(extra.init);12984 const init = try sema.resolveInst(extra.init);
12984 return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src);12985 return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src);
12985}12986}
1298612987
...@@ -13070,7 +13071,7 @@ fn zirStructInit(...@@ -13070,7 +13071,7 @@ fn zirStructInit(
13070 return sema.failWithOwnedErrorMsg(block, msg);13071 return sema.failWithOwnedErrorMsg(block, msg);
13071 }13072 }
13072 found_fields[field_index] = item.data.field_type;13073 found_fields[field_index] = item.data.field_type;
13073 field_inits[field_index] = sema.resolveInst(item.data.init);13074 field_inits[field_index] = try sema.resolveInst(item.data.init);
13074 }13075 }
1307513076
13076 var root_msg: ?*Module.ErrorMsg = null;13077 var root_msg: ?*Module.ErrorMsg = null;
...@@ -13107,7 +13108,7 @@ fn zirStructInit(...@@ -13107,7 +13108,7 @@ fn zirStructInit(
13107 const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);13108 const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
13108 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);13109 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
1310913110
13110 const init_inst = sema.resolveInst(item.data.init);13111 const init_inst = try sema.resolveInst(item.data.init);
13111 if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {13112 if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {
13112 const tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);13113 const tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
13113 return sema.addConstantMaybeRef(13114 return sema.addConstantMaybeRef(
...@@ -13215,7 +13216,7 @@ fn zirStructInitAnon(...@@ -13215,7 +13216,7 @@ fn zirStructInitAnon(
13215 extra_index = item.end;13216 extra_index = item.end;
1321613217
13217 names[i] = sema.code.nullTerminatedString(item.data.field_name);13218 names[i] = sema.code.nullTerminatedString(item.data.field_name);
13218 const init = sema.resolveInst(item.data.init);13219 const init = try sema.resolveInst(item.data.init);
13219 field_ty.* = sema.typeOf(init);13220 field_ty.* = sema.typeOf(init);
13220 const init_src = src; // TODO better source location13221 const init_src = src; // TODO better source location
13221 if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| {13222 if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| {
...@@ -13260,7 +13261,7 @@ fn zirStructInitAnon(...@@ -13260,7 +13261,7 @@ fn zirStructInitAnon(
13260 .pointee_type = field_ty,13261 .pointee_type = field_ty,
13261 });13262 });
13262 if (values[i].tag() == .unreachable_value) {13263 if (values[i].tag() == .unreachable_value) {
13263 const init = sema.resolveInst(item.data.init);13264 const init = try sema.resolveInst(item.data.init);
13264 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);13265 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);
13265 _ = try block.addBinOp(.store, field_ptr, init);13266 _ = try block.addBinOp(.store, field_ptr, init);
13266 }13267 }
...@@ -13274,7 +13275,7 @@ fn zirStructInitAnon(...@@ -13274,7 +13275,7 @@ fn zirStructInitAnon(
13274 for (types) |_, i| {13275 for (types) |_, i| {
13275 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);13276 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
13276 extra_index = item.end;13277 extra_index = item.end;
13277 element_refs[i] = sema.resolveInst(item.data.init);13278 element_refs[i] = try sema.resolveInst(item.data.init);
13278 }13279 }
1327913280
13280 return block.addAggregateInit(tuple_ty, element_refs);13281 return block.addAggregateInit(tuple_ty, element_refs);
...@@ -13298,7 +13299,7 @@ fn zirArrayInit(...@@ -13298,7 +13299,7 @@ fn zirArrayInit(
13298 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len);13299 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len);
13299 defer gpa.free(resolved_args);13300 defer gpa.free(resolved_args);
1330013301
13301 for (args) |arg, i| resolved_args[i] = sema.resolveInst(arg);13302 for (args) |arg, i| resolved_args[i] = try sema.resolveInst(arg);
1330213303
13303 const elem_ty = sema.typeOf(resolved_args[0]);13304 const elem_ty = sema.typeOf(resolved_args[0]);
13304 const array_ty = blk: {13305 const array_ty = blk: {
...@@ -13382,7 +13383,7 @@ fn zirArrayInitAnon(...@@ -13382,7 +13383,7 @@ fn zirArrayInitAnon(
13382 const opt_runtime_src = rs: {13383 const opt_runtime_src = rs: {
13383 var runtime_src: ?LazySrcLoc = null;13384 var runtime_src: ?LazySrcLoc = null;
13384 for (operands) |operand, i| {13385 for (operands) |operand, i| {
13385 const elem = sema.resolveInst(operand);13386 const elem = try sema.resolveInst(operand);
13386 types[i] = sema.typeOf(elem);13387 types[i] = sema.typeOf(elem);
13387 const operand_src = src; // TODO better source location13388 const operand_src = src; // TODO better source location
13388 if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| {13389 if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| {
...@@ -13423,7 +13424,7 @@ fn zirArrayInitAnon(...@@ -13423,7 +13424,7 @@ fn zirArrayInitAnon(
13423 });13424 });
13424 if (values[i].tag() == .unreachable_value) {13425 if (values[i].tag() == .unreachable_value) {
13425 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);13426 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);
13426 _ = try block.addBinOp(.store, field_ptr, sema.resolveInst(operand));13427 _ = try block.addBinOp(.store, field_ptr, try sema.resolveInst(operand));
13427 }13428 }
13428 }13429 }
1342913430
...@@ -13432,7 +13433,7 @@ fn zirArrayInitAnon(...@@ -13432,7 +13433,7 @@ fn zirArrayInitAnon(
1343213433
13433 const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);13434 const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
13434 for (operands) |operand, i| {13435 for (operands) |operand, i| {
13435 element_refs[i] = sema.resolveInst(operand);13436 element_refs[i] = try sema.resolveInst(operand);
13436 }13437 }
1343713438
13438 return block.addAggregateInit(tuple_ty, element_refs);13439 return block.addAggregateInit(tuple_ty, element_refs);
...@@ -13575,7 +13576,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13575,7 +13576,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13575fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13576fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13576 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13577 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13577 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13578 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13578 const operand = sema.resolveInst(inst_data.operand);13579 const operand = try sema.resolveInst(inst_data.operand);
13579 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {13580 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
13580 if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1));13581 if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1));
13581 const bool_ints = [2]Air.Inst.Ref{ .zero, .one };13582 const bool_ints = [2]Air.Inst.Ref{ .zero, .one };
...@@ -13588,7 +13589,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13588,7 +13589,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13588 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13589 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13589 const src = inst_data.src();13590 const src = inst_data.src();
13590 _ = src;13591 _ = src;
13591 const operand = sema.resolveInst(inst_data.operand);13592 const operand = try sema.resolveInst(inst_data.operand);
13592 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13593 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1359313594
13594 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {13595 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
...@@ -13612,7 +13613,7 @@ fn zirUnaryMath(...@@ -13612,7 +13613,7 @@ fn zirUnaryMath(
13612 defer tracy.end();13613 defer tracy.end();
1361313614
13614 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13615 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13615 const operand = sema.resolveInst(inst_data.operand);13616 const operand = try sema.resolveInst(inst_data.operand);
13616 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13617 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13617 const operand_ty = sema.typeOf(operand);13618 const operand_ty = sema.typeOf(operand);
13618 const target = sema.mod.getTarget();13619 const target = sema.mod.getTarget();
...@@ -13672,7 +13673,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13672,7 +13673,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13672 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13673 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13673 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13674 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13674 const src = inst_data.src();13675 const src = inst_data.src();
13675 const operand = sema.resolveInst(inst_data.operand);13676 const operand = try sema.resolveInst(inst_data.operand);
13676 const operand_ty = sema.typeOf(operand);13677 const operand_ty = sema.typeOf(operand);
13677 const mod = sema.mod;13678 const mod = sema.mod;
1367813679
...@@ -13730,7 +13731,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -13730,7 +13731,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
13730 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13731 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13731 const src = inst_data.src();13732 const src = inst_data.src();
13732 const type_info_ty = try sema.resolveBuiltinTypeFields(block, src, "Type");13733 const type_info_ty = try sema.resolveBuiltinTypeFields(block, src, "Type");
13733 const uncasted_operand = sema.resolveInst(inst_data.operand);13734 const uncasted_operand = try sema.resolveInst(inst_data.operand);
13734 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13735 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13735 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);13736 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
13736 const val = try sema.resolveConstValue(block, operand_src, type_info);13737 const val = try sema.resolveConstValue(block, operand_src, type_info);
...@@ -14405,7 +14406,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -14405,7 +14406,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
14405 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14406 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
14406 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14407 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14407 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);14408 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
14408 const operand = sema.resolveInst(extra.rhs);14409 const operand = try sema.resolveInst(extra.rhs);
14409 const operand_ty = sema.typeOf(operand);14410 const operand_ty = sema.typeOf(operand);
1441014411
14411 _ = try sema.checkIntType(block, ty_src, dest_ty);14412 _ = try sema.checkIntType(block, ty_src, dest_ty);
...@@ -14426,7 +14427,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -14426,7 +14427,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
14426 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14427 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
14427 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14428 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14428 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);14429 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
14429 const operand = sema.resolveInst(extra.rhs);14430 const operand = try sema.resolveInst(extra.rhs);
14430 const operand_ty = sema.typeOf(operand);14431 const operand_ty = sema.typeOf(operand);
1443114432
14432 try sema.checkFloatType(block, ty_src, dest_ty);14433 try sema.checkFloatType(block, ty_src, dest_ty);
...@@ -14449,7 +14450,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14449,7 +14450,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14449 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14450 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1445014451
14451 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14452 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14452 const operand_res = sema.resolveInst(extra.rhs);14453 const operand_res = try sema.resolveInst(extra.rhs);
14453 const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src);14454 const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src);
1445414455
14455 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14456 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -14505,7 +14506,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -14505,7 +14506,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
14505 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };14506 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
14506 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };14507 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
14507 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);14508 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14508 const operand = sema.resolveInst(extra.rhs);14509 const operand = try sema.resolveInst(extra.rhs);
14509 const operand_ty = sema.typeOf(operand);14510 const operand_ty = sema.typeOf(operand);
14510 try sema.checkErrorSetType(block, dest_ty_src, dest_ty);14511 try sema.checkErrorSetType(block, dest_ty_src, dest_ty);
14511 try sema.checkErrorSetType(block, operand_src, operand_ty);14512 try sema.checkErrorSetType(block, operand_src, operand_ty);
...@@ -14593,7 +14594,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -14593,7 +14594,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
14593 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14594 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14594 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14595 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14595 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);14596 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14596 const operand = sema.resolveInst(extra.rhs);14597 const operand = try sema.resolveInst(extra.rhs);
14597 const operand_ty = sema.typeOf(operand);14598 const operand_ty = sema.typeOf(operand);
14598 const target = sema.mod.getTarget();14599 const target = sema.mod.getTarget();
1459914600
...@@ -14653,7 +14654,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14653,7 +14654,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14653 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14654 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14654 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14655 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14655 const dest_scalar_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);14656 const dest_scalar_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14656 const operand = sema.resolveInst(extra.rhs);14657 const operand = try sema.resolveInst(extra.rhs);
14657 const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_scalar_ty);14658 const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_scalar_ty);
14658 const operand_ty = sema.typeOf(operand);14659 const operand_ty = sema.typeOf(operand);
14659 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);14660 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
...@@ -14736,7 +14737,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -14736,7 +14737,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
14736 const align_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14737 const align_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
14737 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14738 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14738 const dest_align = try sema.resolveAlign(block, align_src, extra.lhs);14739 const dest_align = try sema.resolveAlign(block, align_src, extra.lhs);
14739 const ptr = sema.resolveInst(extra.rhs);14740 const ptr = try sema.resolveInst(extra.rhs);
14740 const ptr_ty = sema.typeOf(ptr);14741 const ptr_ty = sema.typeOf(ptr);
1474114742
14742 // TODO in addition to pointers, this instruction is supposed to work for14743 // TODO in addition to pointers, this instruction is supposed to work for
...@@ -14770,7 +14771,7 @@ fn zirBitCount(...@@ -14770,7 +14771,7 @@ fn zirBitCount(
14770) CompileError!Air.Inst.Ref {14771) CompileError!Air.Inst.Ref {
14771 const inst_data = sema.code.instructions.items(.data)[inst].un_node;14772 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14772 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14773 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14773 const operand = sema.resolveInst(inst_data.operand);14774 const operand = try sema.resolveInst(inst_data.operand);
14774 const operand_ty = sema.typeOf(operand);14775 const operand_ty = sema.typeOf(operand);
14775 _ = try checkIntOrVector(sema, block, operand, operand_src);14776 _ = try checkIntOrVector(sema, block, operand, operand_src);
14776 const target = sema.mod.getTarget();14777 const target = sema.mod.getTarget();
...@@ -14822,7 +14823,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14822,7 +14823,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14822 const inst_data = sema.code.instructions.items(.data)[inst].un_node;14823 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14823 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14824 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
14824 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14825 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14825 const operand = sema.resolveInst(inst_data.operand);14826 const operand = try sema.resolveInst(inst_data.operand);
14826 const operand_ty = sema.typeOf(operand);14827 const operand_ty = sema.typeOf(operand);
14827 const scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);14828 const scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
14828 const target = sema.mod.getTarget();14829 const target = sema.mod.getTarget();
...@@ -14879,7 +14880,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14879,7 +14880,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14879fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {14880fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
14880 const inst_data = sema.code.instructions.items(.data)[inst].un_node;14881 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14881 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14882 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14882 const operand = sema.resolveInst(inst_data.operand);14883 const operand = try sema.resolveInst(inst_data.operand);
14883 const operand_ty = sema.typeOf(operand);14884 const operand_ty = sema.typeOf(operand);
14884 _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);14885 _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1488514886
...@@ -15365,7 +15366,7 @@ fn resolveExportOptions(...@@ -15365,7 +15366,7 @@ fn resolveExportOptions(
15365 zir_ref: Zir.Inst.Ref,15366 zir_ref: Zir.Inst.Ref,
15366) CompileError!std.builtin.ExportOptions {15367) CompileError!std.builtin.ExportOptions {
15367 const export_options_ty = try sema.getBuiltinType(block, src, "ExportOptions");15368 const export_options_ty = try sema.getBuiltinType(block, src, "ExportOptions");
15368 const air_ref = sema.resolveInst(zir_ref);15369 const air_ref = try sema.resolveInst(zir_ref);
15369 const options = try sema.coerce(block, export_options_ty, air_ref, src);15370 const options = try sema.coerce(block, export_options_ty, air_ref, src);
1537015371
15371 const name_operand = try sema.fieldVal(block, src, options, "name", src);15372 const name_operand = try sema.fieldVal(block, src, options, "name", src);
...@@ -15410,7 +15411,7 @@ fn resolveBuiltinEnum(...@@ -15410,7 +15411,7 @@ fn resolveBuiltinEnum(
15410 comptime name: []const u8,15411 comptime name: []const u8,
15411) CompileError!@field(std.builtin, name) {15412) CompileError!@field(std.builtin, name) {
15412 const ty = try sema.getBuiltinType(block, src, name);15413 const ty = try sema.getBuiltinType(block, src, name);
15413 const air_ref = sema.resolveInst(zir_ref);15414 const air_ref = try sema.resolveInst(zir_ref);
15414 const coerced = try sema.coerce(block, ty, air_ref, src);15415 const coerced = try sema.coerce(block, ty, air_ref, src);
15415 const val = try sema.resolveConstValue(block, src, coerced);15416 const val = try sema.resolveConstValue(block, src, coerced);
15416 return val.toEnum(@field(std.builtin, name));15417 return val.toEnum(@field(std.builtin, name));
...@@ -15451,7 +15452,7 @@ fn zirCmpxchg(...@@ -15451,7 +15452,7 @@ fn zirCmpxchg(
15451 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };15452 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
15452 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = inst_data.src_node };15453 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = inst_data.src_node };
15453 // zig fmt: on15454 // zig fmt: on
15454 const expected_value = sema.resolveInst(extra.expected_value);15455 const expected_value = try sema.resolveInst(extra.expected_value);
15455 const elem_ty = sema.typeOf(expected_value);15456 const elem_ty = sema.typeOf(expected_value);
15456 if (elem_ty.zigTypeTag() == .Float) {15457 if (elem_ty.zigTypeTag() == .Float) {
15457 return sema.fail(15458 return sema.fail(
...@@ -15461,9 +15462,9 @@ fn zirCmpxchg(...@@ -15461,9 +15462,9 @@ fn zirCmpxchg(
15461 .{elem_ty.fmt(sema.mod)},15462 .{elem_ty.fmt(sema.mod)},
15462 );15463 );
15463 }15464 }
15464 const uncasted_ptr = sema.resolveInst(extra.ptr);15465 const uncasted_ptr = try sema.resolveInst(extra.ptr);
15465 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);15466 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
15466 const new_value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.new_value), new_value_src);15467 const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src);
15467 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order);15468 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order);
15468 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order);15469 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order);
1546915470
...@@ -15531,7 +15532,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -15531,7 +15532,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
15531 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15532 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15532 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15533 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15533 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32));15534 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32));
15534 const scalar = sema.resolveInst(extra.rhs);15535 const scalar = try sema.resolveInst(extra.rhs);
15535 const scalar_ty = sema.typeOf(scalar);15536 const scalar_ty = sema.typeOf(scalar);
15536 try sema.checkVectorElemType(block, scalar_src, scalar_ty);15537 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
15537 const vector_ty = try Type.Tag.vector.create(sema.arena, .{15538 const vector_ty = try Type.Tag.vector.create(sema.arena, .{
...@@ -15557,7 +15558,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15557,7 +15558,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15557 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };15558 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
15558 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };15559 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
15559 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp");15560 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp");
15560 const operand = sema.resolveInst(extra.rhs);15561 const operand = try sema.resolveInst(extra.rhs);
15561 const operand_ty = sema.typeOf(operand);15562 const operand_ty = sema.typeOf(operand);
15562 const target = sema.mod.getTarget();15563 const target = sema.mod.getTarget();
1556315564
...@@ -15629,9 +15630,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -15629,9 +15630,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1562915630
15630 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);15631 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
15631 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);15632 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
15632 var a = sema.resolveInst(extra.a);15633 var a = try sema.resolveInst(extra.a);
15633 var b = sema.resolveInst(extra.b);15634 var b = try sema.resolveInst(extra.b);
15634 var mask = sema.resolveInst(extra.mask);15635 var mask = try sema.resolveInst(extra.mask);
15635 var mask_ty = sema.typeOf(mask);15636 var mask_ty = sema.typeOf(mask);
1563615637
15637 const mask_len = switch (sema.typeOf(mask).zigTypeTag()) {15638 const mask_len = switch (sema.typeOf(mask).zigTypeTag()) {
...@@ -15823,7 +15824,7 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15823,7 +15824,7 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1582315824
15824 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);15825 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
15825 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);15826 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
15826 const pred_uncoerced = sema.resolveInst(extra.pred);15827 const pred_uncoerced = try sema.resolveInst(extra.pred);
15827 const pred_ty = sema.typeOf(pred_uncoerced);15828 const pred_ty = sema.typeOf(pred_uncoerced);
1582815829
15829 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison()) {15830 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison()) {
...@@ -15836,8 +15837,8 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15836,8 +15837,8 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15836 const pred = try sema.coerce(block, bool_vec_ty, pred_uncoerced, pred_src);15837 const pred = try sema.coerce(block, bool_vec_ty, pred_uncoerced, pred_src);
1583715838
15838 const vec_ty = try Type.vector(sema.arena, vec_len, elem_ty);15839 const vec_ty = try Type.vector(sema.arena, vec_len, elem_ty);
15839 const a = try sema.coerce(block, vec_ty, sema.resolveInst(extra.a), a_src);15840 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
15840 const b = try sema.coerce(block, vec_ty, sema.resolveInst(extra.b), b_src);15841 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
1584115842
15842 const maybe_pred = try sema.resolveMaybeUndefVal(block, pred_src, pred);15843 const maybe_pred = try sema.resolveMaybeUndefVal(block, pred_src, pred);
15843 const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a);15844 const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a);
...@@ -15909,7 +15910,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -15909,7 +15910,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
15909 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };15910 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
15910 // zig fmt: on15911 // zig fmt: on
15911 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);15912 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
15912 const uncasted_ptr = sema.resolveInst(extra.ptr);15913 const uncasted_ptr = try sema.resolveInst(extra.ptr);
15913 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true);15914 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true);
15914 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);15915 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);
1591515916
...@@ -15956,9 +15957,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -15956,9 +15957,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
15956 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };15957 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
15957 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };15958 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
15958 // zig fmt: on15959 // zig fmt: on
15959 const operand = sema.resolveInst(extra.operand);15960 const operand = try sema.resolveInst(extra.operand);
15960 const elem_ty = sema.typeOf(operand);15961 const elem_ty = sema.typeOf(operand);
15961 const uncasted_ptr = sema.resolveInst(extra.ptr);15962 const uncasted_ptr = try sema.resolveInst(extra.ptr);
15962 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);15963 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
15963 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);15964 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);
1596415965
...@@ -16039,9 +16040,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -16039,9 +16040,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
16039 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };16040 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16040 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };16041 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
16041 // zig fmt: on16042 // zig fmt: on
16042 const operand = sema.resolveInst(extra.operand);16043 const operand = try sema.resolveInst(extra.operand);
16043 const elem_ty = sema.typeOf(operand);16044 const elem_ty = sema.typeOf(operand);
16044 const uncasted_ptr = sema.resolveInst(extra.ptr);16045 const uncasted_ptr = try sema.resolveInst(extra.ptr);
16045 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);16046 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
16046 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);16047 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);
1604716048
...@@ -16072,10 +16073,10 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -16072,10 +16073,10 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
16072 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };16073 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16073 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };16074 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
1607416075
16075 const addend = sema.resolveInst(extra.addend);16076 const addend = try sema.resolveInst(extra.addend);
16076 const ty = sema.typeOf(addend);16077 const ty = sema.typeOf(addend);
16077 const mulend1 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend1), mulend1_src);16078 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
16078 const mulend2 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend2), mulend2_src);16079 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
1607916080
16080 const target = sema.mod.getTarget();16081 const target = sema.mod.getTarget();
1608116082
...@@ -16139,9 +16140,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -16139,9 +16140,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
16139 const call_src = inst_data.src();16140 const call_src = inst_data.src();
1614016141
16141 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;16142 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
16142 var func = sema.resolveInst(extra.callee);16143 var func = try sema.resolveInst(extra.callee);
16143 const options = sema.resolveInst(extra.options);16144 const options = try sema.resolveInst(extra.options);
16144 const args = sema.resolveInst(extra.args);16145 const args = try sema.resolveInst(extra.args);
1614516146
16146 const wanted_modifier: std.builtin.CallOptions.Modifier = modifier: {16147 const wanted_modifier: std.builtin.CallOptions.Modifier = modifier: {
16147 const call_options_ty = try sema.getBuiltinType(block, options_src, "CallOptions");16148 const call_options_ty = try sema.getBuiltinType(block, options_src, "CallOptions");
...@@ -16231,7 +16232,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -16231,7 +16232,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1623116232
16232 const struct_ty = try sema.resolveType(block, ty_src, extra.parent_type);16233 const struct_ty = try sema.resolveType(block, ty_src, extra.parent_type);
16233 const field_name = try sema.resolveConstString(block, name_src, extra.field_name);16234 const field_name = try sema.resolveConstString(block, name_src, extra.field_name);
16234 const field_ptr = sema.resolveInst(extra.field_ptr);16235 const field_ptr = try sema.resolveInst(extra.field_ptr);
16235 const field_ptr_ty = sema.typeOf(field_ptr);16236 const field_ptr_ty = sema.typeOf(field_ptr);
1623616237
16237 if (struct_ty.zigTypeTag() != .Struct) {16238 if (struct_ty.zigTypeTag() != .Struct) {
...@@ -16296,8 +16297,8 @@ fn zirMinMax(...@@ -16296,8 +16297,8 @@ fn zirMinMax(
16296 const src = inst_data.src();16297 const src = inst_data.src();
16297 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };16298 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
16298 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };16299 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
16299 const lhs = sema.resolveInst(extra.lhs);16300 const lhs = try sema.resolveInst(extra.lhs);
16300 const rhs = sema.resolveInst(extra.rhs);16301 const rhs = try sema.resolveInst(extra.rhs);
16301 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));16302 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
16302 try sema.checkNumericType(block, rhs_src, sema.typeOf(rhs));16303 try sema.checkNumericType(block, rhs_src, sema.typeOf(rhs));
16303 return sema.analyzeMinMax(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);16304 return sema.analyzeMinMax(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
...@@ -16364,7 +16365,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -16364,7 +16365,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
16364 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };16365 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
16365 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };16366 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
16366 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };16367 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16367 const dest_ptr = sema.resolveInst(extra.dest);16368 const dest_ptr = try sema.resolveInst(extra.dest);
16368 const dest_ptr_ty = sema.typeOf(dest_ptr);16369 const dest_ptr_ty = sema.typeOf(dest_ptr);
1636916370
16370 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);16371 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);
...@@ -16372,7 +16373,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -16372,7 +16373,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
16372 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});16373 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});
16373 }16374 }
1637416375
16375 const uncasted_src_ptr = sema.resolveInst(extra.source);16376 const uncasted_src_ptr = try sema.resolveInst(extra.source);
16376 const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr);16377 const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr);
16377 try sema.checkPtrOperand(block, src_src, uncasted_src_ptr_ty);16378 try sema.checkPtrOperand(block, src_src, uncasted_src_ptr_ty);
16378 const src_ptr_info = uncasted_src_ptr_ty.ptrInfo().data;16379 const src_ptr_info = uncasted_src_ptr_ty.ptrInfo().data;
...@@ -16386,7 +16387,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -16386,7 +16387,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
16386 .size = .Many,16387 .size = .Many,
16387 });16388 });
16388 const src_ptr = try sema.coerce(block, wanted_src_ptr_ty, uncasted_src_ptr, src_src);16389 const src_ptr = try sema.coerce(block, wanted_src_ptr_ty, uncasted_src_ptr, src_src);
16389 const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);16390 const len = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.byte_count), len_src);
1639016391
16391 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {16392 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
16392 if (!dest_ptr_val.isComptimeMutablePtr()) break :rs dest_src;16393 if (!dest_ptr_val.isComptimeMutablePtr()) break :rs dest_src;
...@@ -16421,15 +16422,15 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -16421,15 +16422,15 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
16421 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };16422 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
16422 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };16423 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
16423 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };16424 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16424 const dest_ptr = sema.resolveInst(extra.dest);16425 const dest_ptr = try sema.resolveInst(extra.dest);
16425 const dest_ptr_ty = sema.typeOf(dest_ptr);16426 const dest_ptr_ty = sema.typeOf(dest_ptr);
16426 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);16427 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);
16427 if (dest_ptr_ty.isConstPtr()) {16428 if (dest_ptr_ty.isConstPtr()) {
16428 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});16429 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});
16429 }16430 }
16430 const elem_ty = dest_ptr_ty.elemType2();16431 const elem_ty = dest_ptr_ty.elemType2();
16431 const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src);16432 const value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.byte), value_src);
16432 const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);16433 const len = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.byte_count), len_src);
1643316434
16434 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {16435 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {
16435 if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;16436 if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;
...@@ -16523,7 +16524,7 @@ fn zirVarExtended(...@@ -16523,7 +16524,7 @@ fn zirVarExtended(
16523 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {16524 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
16524 const init_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);16525 const init_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
16525 extra_index += 1;16526 extra_index += 1;
16526 break :blk sema.resolveInst(init_ref);16527 break :blk try sema.resolveInst(init_ref);
16527 } else .none;16528 } else .none;
1652816529
16529 const have_ty = extra.data.var_type != .none;16530 const have_ty = extra.data.var_type != .none;
...@@ -16671,7 +16672,7 @@ fn zirCDefine(...@@ -16671,7 +16672,7 @@ fn zirCDefine(
16671 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };16672 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1667216673
16673 const name = try sema.resolveConstString(block, name_src, extra.lhs);16674 const name = try sema.resolveConstString(block, name_src, extra.lhs);
16674 const rhs = sema.resolveInst(extra.rhs);16675 const rhs = try sema.resolveInst(extra.rhs);
16675 if (sema.typeOf(rhs).zigTypeTag() != .Void) {16676 if (sema.typeOf(rhs).zigTypeTag() != .Void) {
16676 const value = try sema.resolveConstString(block, val_src, extra.rhs);16677 const value = try sema.resolveConstString(block, val_src, extra.rhs);
16677 try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });16678 try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
...@@ -16720,7 +16721,7 @@ fn zirWasmMemoryGrow(...@@ -16720,7 +16721,7 @@ fn zirWasmMemoryGrow(
16720 }16721 }
1672116722
16722 const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32));16723 const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32));
16723 const delta = try sema.coerce(block, Type.u32, sema.resolveInst(extra.rhs), delta_src);16724 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
1672416725
16725 try sema.requireRuntimeBlock(block, builtin_src);16726 try sema.requireRuntimeBlock(block, builtin_src);
16726 return block.addInst(.{16727 return block.addInst(.{
...@@ -16741,9 +16742,9 @@ fn zirPrefetch(...@@ -16741,9 +16742,9 @@ fn zirPrefetch(
16741 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };16742 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
16742 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };16743 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
16743 const options_ty = try sema.getBuiltinType(block, opts_src, "PrefetchOptions");16744 const options_ty = try sema.getBuiltinType(block, opts_src, "PrefetchOptions");
16744 const ptr = sema.resolveInst(extra.lhs);16745 const ptr = try sema.resolveInst(extra.lhs);
16745 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));16746 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
16746 const options = try sema.coerce(block, options_ty, sema.resolveInst(extra.rhs), opts_src);16747 const options = try sema.coerce(block, options_ty, try sema.resolveInst(extra.rhs), opts_src);
16747 const target = sema.mod.getTarget();16748 const target = sema.mod.getTarget();
1674816749
16749 const rw = try sema.fieldVal(block, opts_src, options, "rw", opts_src);16750 const rw = try sema.fieldVal(block, opts_src, options, "rw", opts_src);
...@@ -16784,7 +16785,7 @@ fn zirBuiltinExtern(...@@ -16784,7 +16785,7 @@ fn zirBuiltinExtern(
16784 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };16785 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1678516786
16786 var ty = try sema.resolveType(block, ty_src, extra.lhs);16787 var ty = try sema.resolveType(block, ty_src, extra.lhs);
16787 const options_inst = sema.resolveInst(extra.rhs);16788 const options_inst = try sema.resolveInst(extra.rhs);
16788 const mod = sema.mod;16789 const mod = sema.mod;
1678916790
16790 const options = options: {16791 const options = options: {
...@@ -22857,7 +22858,7 @@ fn semaStructFields(...@@ -22857,7 +22858,7 @@ fn semaStructFields(
22857 if (has_default) {22858 if (has_default) {
22858 const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);22859 const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
22859 extra_index += 1;22860 extra_index += 1;
22860 const default_inst = sema.resolveInst(default_ref);22861 const default_inst = try sema.resolveInst(default_ref);
22861 // TODO: if we need to report an error here, use a source location22862 // TODO: if we need to report an error here, use a source location
22862 // that points to this default value expression rather than the struct.22863 // that points to this default value expression rather than the struct.
22863 // But only resolve the source location if we need to emit a compile error.22864 // But only resolve the source location if we need to emit a compile error.
...@@ -23041,7 +23042,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil...@@ -23041,7 +23042,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil
23041 const tag_ref: Zir.Inst.Ref = if (has_tag) blk: {23042 const tag_ref: Zir.Inst.Ref = if (has_tag) blk: {
23042 const tag_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);23043 const tag_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
23043 extra_index += 1;23044 extra_index += 1;
23044 break :blk sema.resolveInst(tag_ref);23045 break :blk try sema.resolveInst(tag_ref);
23045 } else .none;23046 } else .none;
2304623047
23047 if (enum_value_map) |map| {23048 if (enum_value_map) |map| {
...@@ -23666,7 +23667,7 @@ fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {...@@ -23666,7 +23667,7 @@ fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
23666fn addBool(sema: *Sema, ty: Type, boolean: bool) CompileError!Air.Inst.Ref {23667fn addBool(sema: *Sema, ty: Type, boolean: bool) CompileError!Air.Inst.Ref {
23667 return switch (ty.zigTypeTag()) {23668 return switch (ty.zigTypeTag()) {
23668 .Vector => sema.addConstant(ty, try Value.Tag.repeated.create(sema.arena, Value.makeBool(boolean))),23669 .Vector => sema.addConstant(ty, try Value.Tag.repeated.create(sema.arena, Value.makeBool(boolean))),
23669 .Bool => sema.resolveInst(if (boolean) .bool_true else .bool_false),23670 .Bool => try sema.resolveInst(if (boolean) .bool_true else .bool_false),
23670 else => unreachable,23671 else => unreachable,
23671 };23672 };
23672}23673}
test/behavior/sizeof_and_typeof.zig+10
...@@ -290,3 +290,13 @@ test "hardcoded address in typeof expression" {...@@ -290,3 +290,13 @@ test "hardcoded address in typeof expression" {
290 try expect(S.func() == 0);290 try expect(S.func() == 0);
291 comptime try expect(S.func() == 0);291 comptime try expect(S.func() == 0);
292}292}
293
294test "array access of generic param in typeof expression" {
295 const S = struct {
296 fn first(comptime items: anytype) @TypeOf(items[0]) {
297 return items[0];
298 }
299 };
300 try expect(S.first("a") == 'a');
301 comptime try expect(S.first("a") == 'a');
302}