authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-25 22:30:08-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-05-25 22:30:08-04:00
log1dd710947696ed11e35e9fc98b7dab4a1188c0d5
tree1c99d13228b908b64689a3c4a2fbe9e3e0145155
parent97816e3cb826b64df578baa72781caba93252fd0
parentf409d925ad4640ea71cc3ef5e83b13ae6e216959
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11716 from Vexu/stage2

Stage2 misc fixes

5 files changed, 316 insertions(+), 211 deletions(-)

src/Sema.zig+224-211
......@@ -584,7 +584,7 @@ fn resolveBody(
584584 sema.comptime_break_inst = break_data.inst;
585585 return error.ComptimeBreak;
586586 }
587 return sema.resolveInst(break_data.operand);
587 return try sema.resolveInst(break_data.operand);
588588}
589589
590590pub fn analyzeBody(
......@@ -1191,7 +1191,7 @@ fn analyzeBodyInner(
11911191 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
11921192 break always_noreturn;
11931193 if (inst == break_data.block_inst) {
1194 break :blk sema.resolveInst(break_data.operand);
1194 break :blk try sema.resolveInst(break_data.operand);
11951195 } else {
11961196 break break_data.inst;
11971197 }
......@@ -1214,7 +1214,7 @@ fn analyzeBodyInner(
12141214 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
12151215 break always_noreturn;
12161216 if (inst == break_data.block_inst) {
1217 break :blk sema.resolveInst(break_data.operand);
1217 break :blk try sema.resolveInst(break_data.operand);
12181218 } else {
12191219 break break_data.inst;
12201220 }
......@@ -1283,7 +1283,7 @@ fn analyzeBodyInner(
12831283
12841284 const break_data = opt_break_data orelse break always_noreturn;
12851285 if (inst == break_data.block_inst) {
1286 break :blk sema.resolveInst(break_data.operand);
1286 break :blk try sema.resolveInst(break_data.operand);
12871287 } else {
12881288 break break_data.inst;
12891289 }
......@@ -1301,7 +1301,7 @@ fn analyzeBodyInner(
13011301 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
13021302 break always_noreturn;
13031303 if (inst == break_data.block_inst) {
1304 break :blk sema.resolveInst(break_data.operand);
1304 break :blk try sema.resolveInst(break_data.operand);
13051305 } else {
13061306 break break_data.inst;
13071307 }
......@@ -1317,7 +1317,7 @@ fn analyzeBodyInner(
13171317 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
13181318 break always_noreturn;
13191319 if (inst == break_data.block_inst) {
1320 break :blk sema.resolveInst(break_data.operand);
1320 break :blk try sema.resolveInst(break_data.operand);
13211321 } else {
13221322 break break_data.inst;
13231323 }
......@@ -1350,7 +1350,7 @@ fn analyzeBodyInner(
13501350 return result;
13511351}
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 {
13541354 var i: usize = @enumToInt(zir_ref);
13551355
13561356 // 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 {
13611361 i -= Zir.Inst.Ref.typed_value_map.len;
13621362
13631363 // 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;
13651367}
13661368
13671369fn resolveConstBool(
......@@ -1370,7 +1372,7 @@ fn resolveConstBool(
13701372 src: LazySrcLoc,
13711373 zir_ref: Zir.Inst.Ref,
13721374) !bool {
1373 const air_inst = sema.resolveInst(zir_ref);
1375 const air_inst = try sema.resolveInst(zir_ref);
13741376 const wanted_type = Type.bool;
13751377 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
13761378 const val = try sema.resolveConstValue(block, src, coerced_inst);
......@@ -1383,7 +1385,7 @@ pub fn resolveConstString(
13831385 src: LazySrcLoc,
13841386 zir_ref: Zir.Inst.Ref,
13851387) ![]u8 {
1386 const air_inst = sema.resolveInst(zir_ref);
1388 const air_inst = try sema.resolveInst(zir_ref);
13871389 const wanted_type = Type.initTag(.const_slice_u8);
13881390 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
13891391 const val = try sema.resolveConstValue(block, src, coerced_inst);
......@@ -1391,7 +1393,7 @@ pub fn resolveConstString(
13911393}
13921394
13931395pub 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);
13951397 const ty = try sema.analyzeAsType(block, src, air_inst);
13961398 if (ty.tag() == .generic_poison) return error.GenericPoison;
13971399 return ty;
......@@ -1513,6 +1515,7 @@ fn resolveDefinedValue(
15131515) CompileError!?Value {
15141516 if (try sema.resolveMaybeUndefVal(block, src, air_ref)) |val| {
15151517 if (val.isUndef()) {
1518 if (block.is_typeof) return null;
15161519 return sema.failWithUseOfUndef(block, src);
15171520 }
15181521 return val;
......@@ -1737,7 +1740,7 @@ fn resolveInt(
17371740 zir_ref: Zir.Inst.Ref,
17381741 dest_ty: Type,
17391742) !u64 {
1740 const air_inst = sema.resolveInst(zir_ref);
1743 const air_inst = try sema.resolveInst(zir_ref);
17411744 const coerced = try sema.coerce(block, dest_ty, air_inst, src);
17421745 const val = try sema.resolveConstValue(block, src, coerced);
17431746 const target = sema.mod.getTarget();
......@@ -1752,7 +1755,7 @@ pub fn resolveInstConst(
17521755 src: LazySrcLoc,
17531756 zir_ref: Zir.Inst.Ref,
17541757) CompileError!TypedValue {
1755 const air_ref = sema.resolveInst(zir_ref);
1758 const air_ref = try sema.resolveInst(zir_ref);
17561759 const val = try sema.resolveConstValue(block, src, air_ref);
17571760 return TypedValue{
17581761 .ty = sema.typeOf(air_ref),
......@@ -1768,7 +1771,7 @@ pub fn resolveInstValue(
17681771 src: LazySrcLoc,
17691772 zir_ref: Zir.Inst.Ref,
17701773) CompileError!TypedValue {
1771 const air_ref = sema.resolveInst(zir_ref);
1774 const air_ref = try sema.resolveInst(zir_ref);
17721775 const val = try sema.resolveValue(block, src, air_ref);
17731776 return TypedValue{
17741777 .ty = sema.typeOf(air_ref),
......@@ -1783,7 +1786,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
17831786 const src: LazySrcLoc = sema.src;
17841787 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
17851788 const pointee_ty = try sema.resolveType(block, src, bin_inst.lhs);
1786 const ptr = sema.resolveInst(bin_inst.rhs);
1789 const ptr = try sema.resolveInst(bin_inst.rhs);
17871790 const target = sema.mod.getTarget();
17881791 const addr_space = target_util.defaultAddressSpace(target, .local);
17891792
......@@ -2531,7 +2534,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
25312534 defer tracy.end();
25322535
25332536 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
2534 const operand = sema.resolveInst(inst_data.operand);
2537 const operand = try sema.resolveInst(inst_data.operand);
25352538 return sema.analyzeRef(block, inst_data.src(), operand);
25362539}
25372540
......@@ -2550,7 +2553,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
25502553 defer tracy.end();
25512554
25522555 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2553 const operand = sema.resolveInst(inst_data.operand);
2556 const operand = try sema.resolveInst(inst_data.operand);
25542557 const src = inst_data.src();
25552558
25562559 return sema.ensureResultUsed(block, operand, src);
......@@ -2574,7 +2577,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
25742577 defer tracy.end();
25752578
25762579 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2577 const operand = sema.resolveInst(inst_data.operand);
2580 const operand = try sema.resolveInst(inst_data.operand);
25782581 const src = inst_data.src();
25792582 const operand_ty = sema.typeOf(operand);
25802583 switch (operand_ty.zigTypeTag()) {
......@@ -2589,7 +2592,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
25892592
25902593 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
25912594 const src = inst_data.src();
2592 const object = sema.resolveInst(inst_data.operand);
2595 const object = try sema.resolveInst(inst_data.operand);
25932596 const object_ty = sema.typeOf(object);
25942597
25952598 const is_pointer_to = object_ty.isSinglePointer();
......@@ -2708,7 +2711,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
27082711
27092712fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
27102713 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2711 const ptr = sema.resolveInst(inst_data.operand);
2714 const ptr = try sema.resolveInst(inst_data.operand);
27122715 const ptr_ty = sema.typeOf(ptr);
27132716 var ptr_info = ptr_ty.ptrInfo().data;
27142717 ptr_info.mutable = false;
......@@ -2824,7 +2827,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
28242827 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
28252828 const src = inst_data.src();
28262829 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
2827 const ptr = sema.resolveInst(inst_data.operand);
2830 const ptr = try sema.resolveInst(inst_data.operand);
28282831 const ptr_inst = Air.refToIndex(ptr).?;
28292832 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
28302833 const value_index = sema.air_instructions.items(.data)[ptr_inst].ty_pl.payload;
......@@ -2986,7 +2989,7 @@ fn zirArrayBasePtr(
29862989 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29872990 const src = inst_data.src();
29882991
2989 const start_ptr = sema.resolveInst(inst_data.operand);
2992 const start_ptr = try sema.resolveInst(inst_data.operand);
29902993 var base_ptr = start_ptr;
29912994 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {
29922995 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
......@@ -3011,7 +3014,7 @@ fn zirFieldBasePtr(
30113014 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
30123015 const src = inst_data.src();
30133016
3014 const start_ptr = sema.resolveInst(inst_data.operand);
3017 const start_ptr = try sema.resolveInst(inst_data.operand);
30153018 var base_ptr = start_ptr;
30163019 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag()) {
30173020 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
......@@ -3075,7 +3078,7 @@ fn zirValidateStructInit(
30753078 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
30763079 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
30773080 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
3078 const object_ptr = sema.resolveInst(field_ptr_extra.lhs);
3081 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
30793082 const agg_ty = sema.typeOf(object_ptr).childType();
30803083 switch (agg_ty.zigTypeTag()) {
30813084 .Struct => return sema.validateStructInit(
......@@ -3251,7 +3254,7 @@ fn validateStructInit(
32513254 var root_msg: ?*Module.ErrorMsg = null;
32523255
32533256 const fields = struct_obj.fields.values();
3254 const struct_ptr = sema.resolveInst(struct_ptr_zir_ref);
3257 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
32553258 const struct_ty = sema.typeOf(struct_ptr).childType();
32563259
32573260 if (is_comptime or block.is_comptime) {
......@@ -3448,7 +3451,7 @@ fn zirValidateArrayInit(
34483451 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
34493452 const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
34503453 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
3451 const array_ptr = sema.resolveInst(elem_ptr_extra.ptr);
3454 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
34523455 const array_ty = sema.typeOf(array_ptr).childType();
34533456 const array_len = array_ty.arrayLen();
34543457
......@@ -3646,7 +3649,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
36463649 // This is an elided instruction, but AstGen was unable to omit it.
36473650 return;
36483651 };
3649 const operand = sema.resolveInst(bin_inst.rhs);
3652 const operand = try sema.resolveInst(bin_inst.rhs);
36503653 const src: LazySrcLoc = sema.src;
36513654 blk: {
36523655 const ptr_inst = Air.refToIndex(ptr) orelse break :blk;
......@@ -3675,8 +3678,8 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
36753678
36763679 const src: LazySrcLoc = sema.src;
36773680 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3678 const ptr = sema.resolveInst(bin_inst.lhs);
3679 const operand = sema.resolveInst(bin_inst.rhs);
3681 const ptr = try sema.resolveInst(bin_inst.lhs);
3682 const operand = try sema.resolveInst(bin_inst.rhs);
36803683 const ptr_inst = Air.refToIndex(ptr).?;
36813684 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
36823685 const air_datas = sema.air_instructions.items(.data);
......@@ -3758,8 +3761,8 @@ fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
37583761 defer tracy.end();
37593762
37603763 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3761 const ptr = sema.resolveInst(bin_inst.lhs);
3762 const value = sema.resolveInst(bin_inst.rhs);
3764 const ptr = try sema.resolveInst(bin_inst.lhs);
3765 const value = try sema.resolveInst(bin_inst.rhs);
37633766 return sema.storePtr(block, sema.src, ptr, value);
37643767}
37653768
......@@ -3772,8 +3775,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
37723775 const inst_data = zir_datas[inst].pl_node;
37733776 const src = inst_data.src();
37743777 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3775 const ptr = sema.resolveInst(extra.lhs);
3776 const operand = sema.resolveInst(extra.rhs);
3778 const ptr = try sema.resolveInst(extra.lhs);
3779 const operand = try sema.resolveInst(extra.rhs);
37773780
37783781 // Check for the possibility of this pattern:
37793782 // %a = ret_ptr
......@@ -3798,7 +3801,7 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
37983801 const callee_src = sema.src;
37993802
38003803 const inst_data = sema.code.instructions.items(.data)[inst].param_type;
3801 const callee = sema.resolveInst(inst_data.callee);
3804 const callee = try sema.resolveInst(inst_data.callee);
38023805 const callee_ty = sema.typeOf(callee);
38033806 var param_index = inst_data.param_index;
38043807
......@@ -3959,7 +3962,7 @@ fn zirCompileLog(
39593962 for (args) |arg_ref, i| {
39603963 if (i != 0) try writer.print(", ", .{});
39613964
3962 const arg = sema.resolveInst(arg_ref);
3965 const arg = try sema.resolveInst(arg_ref);
39633966 const arg_ty = sema.typeOf(arg);
39643967 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {
39653968 try writer.print("@as({}, {})", .{
......@@ -3981,7 +3984,7 @@ fn zirCompileLog(
39813984fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
39823985 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
39833986 const src: LazySrcLoc = inst_data.src();
3984 const msg_inst = sema.resolveInst(inst_data.operand);
3987 const msg_inst = try sema.resolveInst(inst_data.operand);
39853988
39863989 return sema.panicWithMsg(block, src, msg_inst);
39873990}
......@@ -4205,7 +4208,7 @@ fn resolveBlockBody(
42054208 const break_inst = sema.comptime_break_inst;
42064209 const break_data = sema.code.instructions.items(.data)[break_inst].@"break";
42074210 if (break_data.block_inst == body_inst) {
4208 return sema.resolveInst(break_data.operand);
4211 return try sema.resolveInst(break_data.operand);
42094212 } else {
42104213 return error.ComptimeBreak;
42114214 }
......@@ -4535,7 +4538,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
45354538 defer tracy.end();
45364539
45374540 const inst_data = sema.code.instructions.items(.data)[inst].@"break";
4538 const operand = sema.resolveInst(inst_data.operand);
4541 const operand = try sema.resolveInst(inst_data.operand);
45394542 const zir_block = inst_data.block_inst;
45404543
45414544 var block = start_block;
......@@ -4601,7 +4604,7 @@ fn zirDbgVar(
46014604 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return;
46024605
46034606 const str_op = sema.code.instructions.items(.data)[inst].str_op;
4604 const operand = sema.resolveInst(str_op.operand);
4607 const operand = try sema.resolveInst(str_op.operand);
46054608 const name = str_op.getStr(sema.code);
46064609 try sema.addDbgVar(block, operand, air_tag, name);
46074610}
......@@ -4784,7 +4787,7 @@ fn zirCall(
47844787 const modifier = @intToEnum(std.builtin.CallOptions.Modifier, extra.data.flags.packed_modifier);
47854788 const ensure_result_used = extra.data.flags.ensure_result_used;
47864789
4787 var func = sema.resolveInst(extra.data.callee);
4790 var func = try sema.resolveInst(extra.data.callee);
47884791 var resolved_args: []Air.Inst.Ref = undefined;
47894792
47904793 const func_type = sema.typeOf(func);
......@@ -4797,12 +4800,12 @@ fn zirCall(
47974800 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len + 1);
47984801 resolved_args[0] = bound_data.arg0_inst;
47994802 for (args) |zir_arg, i| {
4800 resolved_args[i + 1] = sema.resolveInst(zir_arg);
4803 resolved_args[i + 1] = try sema.resolveInst(zir_arg);
48014804 }
48024805 } else {
48034806 resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len);
48044807 for (args) |zir_arg, i| {
4805 resolved_args[i] = sema.resolveInst(zir_arg);
4808 resolved_args[i] = try sema.resolveInst(zir_arg);
48064809 }
48074810 }
48084811
......@@ -5826,7 +5829,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
58265829 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
58275830 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize);
58285831 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
5829 const uncasted_sentinel = sema.resolveInst(extra.sentinel);
5832 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
58305833 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);
58315834 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel);
58325835 const array_ty = try Type.array(sema.arena, len, sentinel_val, elem_type, sema.mod);
......@@ -5891,7 +5894,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
58915894 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58925895 const src = inst_data.src();
58935896 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5894 const op = sema.resolveInst(inst_data.operand);
5897 const op = try sema.resolveInst(inst_data.operand);
58955898 const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src);
58965899 const result_ty = Type.u16;
58975900
......@@ -5928,7 +5931,7 @@ fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
59285931 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59295932 const src = inst_data.src();
59305933 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5931 const uncasted_operand = sema.resolveInst(inst_data.operand);
5934 const uncasted_operand = try sema.resolveInst(inst_data.operand);
59325935 const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src);
59335936 const target = sema.mod.getTarget();
59345937
......@@ -5966,8 +5969,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
59665969 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
59675970 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
59685971 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
5969 const lhs = sema.resolveInst(extra.lhs);
5970 const rhs = sema.resolveInst(extra.rhs);
5972 const lhs = try sema.resolveInst(extra.lhs);
5973 const rhs = try sema.resolveInst(extra.rhs);
59715974 if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) {
59725975 const msg = msg: {
59735976 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});
......@@ -6026,7 +6029,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
60266029 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
60276030 const src = inst_data.src();
60286031 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6029 const operand = sema.resolveInst(inst_data.operand);
6032 const operand = try sema.resolveInst(inst_data.operand);
60306033 const operand_ty = sema.typeOf(operand);
60316034
60326035 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) {
......@@ -6074,7 +6077,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
60746077 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
60756078 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
60766079 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
6077 const operand = sema.resolveInst(extra.rhs);
6080 const operand = try sema.resolveInst(extra.rhs);
60786081
60796082 if (dest_ty.zigTypeTag() != .Enum) {
60806083 return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty.fmt(sema.mod)});
......@@ -6125,7 +6128,7 @@ fn zirOptionalPayloadPtr(
61256128 defer tracy.end();
61266129
61276130 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6128 const optional_ptr = sema.resolveInst(inst_data.operand);
6131 const optional_ptr = try sema.resolveInst(inst_data.operand);
61296132 const src = inst_data.src();
61306133
61316134 return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false);
......@@ -6210,7 +6213,7 @@ fn zirOptionalPayload(
62106213
62116214 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
62126215 const src = inst_data.src();
6213 const operand = sema.resolveInst(inst_data.operand);
6216 const operand = try sema.resolveInst(inst_data.operand);
62146217 const operand_ty = sema.typeOf(operand);
62156218 const result_ty = switch (operand_ty.zigTypeTag()) {
62166219 .Optional => try operand_ty.optionalChildAlloc(sema.arena),
......@@ -6262,7 +6265,7 @@ fn zirErrUnionPayload(
62626265
62636266 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
62646267 const src = inst_data.src();
6265 const operand = sema.resolveInst(inst_data.operand);
6268 const operand = try sema.resolveInst(inst_data.operand);
62666269 const operand_src = src;
62676270 const operand_ty = sema.typeOf(operand);
62686271 if (operand_ty.zigTypeTag() != .ErrorUnion) {
......@@ -6303,7 +6306,7 @@ fn zirErrUnionPayloadPtr(
63036306 defer tracy.end();
63046307
63056308 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6306 const operand = sema.resolveInst(inst_data.operand);
6309 const operand = try sema.resolveInst(inst_data.operand);
63076310 const src = inst_data.src();
63086311
63096312 return sema.analyzeErrUnionPayloadPtr(block, src, operand, safety_check, false);
......@@ -6389,7 +6392,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
63896392
63906393 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
63916394 const src = inst_data.src();
6392 const operand = sema.resolveInst(inst_data.operand);
6395 const operand = try sema.resolveInst(inst_data.operand);
63936396 const operand_ty = sema.typeOf(operand);
63946397 if (operand_ty.zigTypeTag() != .ErrorUnion) {
63956398 return sema.fail(block, src, "expected error union type, found '{}'", .{
......@@ -6415,7 +6418,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
64156418
64166419 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
64176420 const src = inst_data.src();
6418 const operand = sema.resolveInst(inst_data.operand);
6421 const operand = try sema.resolveInst(inst_data.operand);
64196422 const operand_ty = sema.typeOf(operand);
64206423 assert(operand_ty.zigTypeTag() == .Pointer);
64216424
......@@ -6444,7 +6447,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
64446447
64456448 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
64466449 const src = inst_data.src();
6447 const operand = sema.resolveInst(inst_data.operand);
6450 const operand = try sema.resolveInst(inst_data.operand);
64486451 const operand_ty = sema.typeOf(operand);
64496452 if (operand_ty.zigTypeTag() != .ErrorUnion) {
64506453 return sema.fail(block, src, "expected error union type, found '{}'", .{
......@@ -6940,7 +6943,7 @@ fn analyzeAs(
69406943 zir_operand: Zir.Inst.Ref,
69416944) CompileError!Air.Inst.Ref {
69426945 const dest_ty = try sema.resolveType(block, src, zir_dest_type);
6943 const operand = sema.resolveInst(zir_operand);
6946 const operand = try sema.resolveInst(zir_operand);
69446947 if (dest_ty.tag() == .var_args_param) return operand;
69456948 return sema.coerce(block, dest_ty, operand, src);
69466949}
......@@ -6951,7 +6954,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
69516954
69526955 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
69536956 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6954 const ptr = sema.resolveInst(inst_data.operand);
6957 const ptr = try sema.resolveInst(inst_data.operand);
69556958 const ptr_ty = sema.typeOf(ptr);
69566959 if (!ptr_ty.isPtrAtRuntime()) {
69576960 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)});
......@@ -6972,7 +6975,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
69726975 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
69736976 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
69746977 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
6975 const object = sema.resolveInst(extra.lhs);
6978 const object = try sema.resolveInst(extra.lhs);
69766979 return sema.fieldVal(block, src, object, field_name, field_name_src);
69776980}
69786981
......@@ -6985,7 +6988,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
69856988 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
69866989 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
69876990 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
6988 const object_ptr = sema.resolveInst(extra.lhs);
6991 const object_ptr = try sema.resolveInst(extra.lhs);
69896992 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
69906993}
69916994
......@@ -6998,7 +7001,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
69987001 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
69997002 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
70007003 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
7001 const object_ptr = sema.resolveInst(extra.lhs);
7004 const object_ptr = try sema.resolveInst(extra.lhs);
70027005 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
70037006}
70047007
......@@ -7010,7 +7013,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
70107013 const src = inst_data.src();
70117014 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
70127015 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
7013 const object = sema.resolveInst(extra.lhs);
7016 const object = try sema.resolveInst(extra.lhs);
70147017 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
70157018 return sema.fieldVal(block, src, object, field_name, field_name_src);
70167019}
......@@ -7023,7 +7026,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
70237026 const src = inst_data.src();
70247027 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
70257028 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
7026 const object_ptr = sema.resolveInst(extra.lhs);
7029 const object_ptr = try sema.resolveInst(extra.lhs);
70277030 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
70287031 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
70297032}
......@@ -7035,7 +7038,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Block, extended: Zir.Inst.Extended
70357038 const extra = sema.code.extraData(Zir.Inst.FieldNamedNode, extended.operand).data;
70367039 const src: LazySrcLoc = .{ .node_offset = extra.node };
70377040 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
7038 const object_ptr = sema.resolveInst(extra.lhs);
7041 const object_ptr = try sema.resolveInst(extra.lhs);
70397042 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
70407043 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
70417044}
......@@ -7050,7 +7053,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
70507053 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
70517054
70527055 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
7053 const operand = sema.resolveInst(extra.rhs);
7056 const operand = try sema.resolveInst(extra.rhs);
70547057
70557058 return sema.intCast(block, dest_ty, dest_ty_src, operand, operand_src, true);
70567059}
......@@ -7240,7 +7243,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
72407243 => {},
72417244 }
72427245
7243 const operand = sema.resolveInst(extra.rhs);
7246 const operand = try sema.resolveInst(extra.rhs);
72447247 return sema.bitCast(block, dest_ty, operand, operand_src);
72457248}
72467249
......@@ -7255,7 +7258,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
72557258 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
72567259
72577260 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
7258 const operand = sema.resolveInst(extra.rhs);
7261 const operand = try sema.resolveInst(extra.rhs);
72597262
72607263 const target = sema.mod.getTarget();
72617264 const dest_is_comptime_float = switch (dest_ty.zigTypeTag()) {
......@@ -7300,8 +7303,8 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
73007303 defer tracy.end();
73017304
73027305 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7303 const array = sema.resolveInst(bin_inst.lhs);
7304 const elem_index = sema.resolveInst(bin_inst.rhs);
7306 const array = try sema.resolveInst(bin_inst.lhs);
7307 const elem_index = try sema.resolveInst(bin_inst.rhs);
73057308 return sema.elemVal(block, sema.src, array, elem_index, sema.src);
73067309}
73077310
......@@ -7313,8 +7316,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
73137316 const src = inst_data.src();
73147317 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
73157318 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7316 const array = sema.resolveInst(extra.lhs);
7317 const elem_index = sema.resolveInst(extra.rhs);
7319 const array = try sema.resolveInst(extra.lhs);
7320 const elem_index = try sema.resolveInst(extra.rhs);
73187321 return sema.elemVal(block, src, array, elem_index, elem_index_src);
73197322}
73207323
......@@ -7323,8 +7326,8 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
73237326 defer tracy.end();
73247327
73257328 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7326 const array_ptr = sema.resolveInst(bin_inst.lhs);
7327 const elem_index = sema.resolveInst(bin_inst.rhs);
7329 const array_ptr = try sema.resolveInst(bin_inst.lhs);
7330 const elem_index = try sema.resolveInst(bin_inst.rhs);
73287331 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
73297332}
73307333
......@@ -7336,8 +7339,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
73367339 const src = inst_data.src();
73377340 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
73387341 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7339 const array_ptr = sema.resolveInst(extra.lhs);
7340 const elem_index = sema.resolveInst(extra.rhs);
7342 const array_ptr = try sema.resolveInst(extra.lhs);
7343 const elem_index = try sema.resolveInst(extra.rhs);
73417344 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
73427345}
73437346
......@@ -7348,7 +7351,7 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
73487351 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
73497352 const src = inst_data.src();
73507353 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
7351 const array_ptr = sema.resolveInst(extra.ptr);
7354 const array_ptr = try sema.resolveInst(extra.ptr);
73527355 const elem_index = try sema.addIntUnsigned(Type.usize, extra.index);
73537356 return sema.elemPtr(block, src, array_ptr, elem_index, src);
73547357}
......@@ -7360,8 +7363,8 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
73607363 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
73617364 const src = inst_data.src();
73627365 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
7363 const array_ptr = sema.resolveInst(extra.lhs);
7364 const start = sema.resolveInst(extra.start);
7366 const array_ptr = try sema.resolveInst(extra.lhs);
7367 const start = try sema.resolveInst(extra.start);
73657368
73667369 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);
73677370}
......@@ -7373,9 +7376,9 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
73737376 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
73747377 const src = inst_data.src();
73757378 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
7376 const array_ptr = sema.resolveInst(extra.lhs);
7377 const start = sema.resolveInst(extra.start);
7378 const end = sema.resolveInst(extra.end);
7379 const array_ptr = try sema.resolveInst(extra.lhs);
7380 const start = try sema.resolveInst(extra.start);
7381 const end = try sema.resolveInst(extra.end);
73797382
73807383 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);
73817384}
......@@ -7388,10 +7391,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
73887391 const src = inst_data.src();
73897392 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
73907393 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
7391 const array_ptr = sema.resolveInst(extra.lhs);
7392 const start = sema.resolveInst(extra.start);
7393 const end = sema.resolveInst(extra.end);
7394 const sentinel = sema.resolveInst(extra.sentinel);
7394 const array_ptr = try sema.resolveInst(extra.lhs);
7395 const start = try sema.resolveInst(extra.start);
7396 const end = try sema.resolveInst(extra.end);
7397 const sentinel = try sema.resolveInst(extra.sentinel);
73957398
73967399 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);
73977400}
......@@ -7415,7 +7418,7 @@ fn zirSwitchCapture(
74157418 const operand_is_ref = switch_extra.data.bits.is_ref;
74167419 const cond_inst = Zir.refToIndex(switch_extra.data.operand).?;
74177420 const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node;
7418 const operand_ptr = sema.resolveInst(cond_info.operand);
7421 const operand_ptr = try sema.resolveInst(cond_info.operand);
74197422 const operand_ptr_ty = sema.typeOf(operand_ptr);
74207423 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
74217424
......@@ -7449,7 +7452,7 @@ fn zirSwitchCapture(
74497452 const union_obj = operand_ty.cast(Type.Payload.Union).?.data;
74507453 const enum_ty = union_obj.tag_ty;
74517454
7452 const first_item = sema.resolveInst(items[0]);
7455 const first_item = try sema.resolveInst(items[0]);
74537456 // Previous switch validation ensured this will succeed
74547457 const first_item_val = sema.resolveConstValue(block, .unneeded, first_item) catch unreachable;
74557458
......@@ -7457,7 +7460,7 @@ fn zirSwitchCapture(
74577460 const first_field = union_obj.fields.values()[first_field_index];
74587461
74597462 for (items[1..]) |item| {
7460 const item_ref = sema.resolveInst(item);
7463 const item_ref = try sema.resolveInst(item);
74617464 // Previous switch validation ensured this will succeed
74627465 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
74637466
......@@ -7514,7 +7517,7 @@ fn zirSwitchCapture(
75147517 var names: Module.ErrorSet.NameMap = .{};
75157518 try names.ensureUnusedCapacity(sema.arena, items.len);
75167519 for (items) |item| {
7517 const item_ref = sema.resolveInst(item);
7520 const item_ref = try sema.resolveInst(item);
75187521 // Previous switch validation ensured this will succeed
75197522 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
75207523 names.putAssumeCapacityNoClobber(
......@@ -7528,7 +7531,7 @@ fn zirSwitchCapture(
75287531
75297532 return sema.bitCast(block, else_error_ty, operand, operand_src);
75307533 } else {
7531 const item_ref = sema.resolveInst(items[0]);
7534 const item_ref = try sema.resolveInst(items[0]);
75327535 // Previous switch validation ensured this will succeed
75337536 const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable;
75347537
......@@ -7558,7 +7561,7 @@ fn zirSwitchCond(
75587561 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
75597562 const src = inst_data.src();
75607563 const operand_src = src; // TODO make this point at the switch operand
7561 const operand_ptr = sema.resolveInst(inst_data.operand);
7564 const operand_ptr = try sema.resolveInst(inst_data.operand);
75627565 const operand = if (is_ref)
75637566 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
75647567 else
......@@ -7629,7 +7632,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
76297632 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };
76307633 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
76317634
7632 const operand = sema.resolveInst(extra.data.operand);
7635 const operand = try sema.resolveInst(extra.data.operand);
76337636
76347637 var header_extra_index: usize = extra.end;
76357638
......@@ -8207,7 +8210,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82078210 const body = sema.code.extra[extra_index..][0..body_len];
82088211 extra_index += body_len;
82098212
8210 const item = sema.resolveInst(item_ref);
8213 const item = try sema.resolveInst(item_ref);
82118214 // Validation above ensured these will succeed.
82128215 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;
82138216 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
......@@ -8229,7 +8232,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82298232 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..body_len];
82308233
82318234 for (items) |item_ref| {
8232 const item = sema.resolveInst(item_ref);
8235 const item = try sema.resolveInst(item_ref);
82338236 // Validation above ensured these will succeed.
82348237 const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable;
82358238 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
......@@ -8297,7 +8300,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82978300 case_block.instructions.shrinkRetainingCapacity(0);
82988301 case_block.wip_capture_scope = wip_captures.scope;
82998302
8300 const item = sema.resolveInst(item_ref);
8303 const item = try sema.resolveInst(item_ref);
83018304 // `item` is already guaranteed to be constant known.
83028305
83038306 _ = sema.analyzeBodyInner(&case_block, body) catch |err| switch (err) {
......@@ -8374,14 +8377,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
83748377 cases_extra.appendAssumeCapacity(@intCast(u32, case_block.instructions.items.len));
83758378
83768379 for (items) |item_ref| {
8377 const item = sema.resolveInst(item_ref);
8380 const item = try sema.resolveInst(item_ref);
83788381 cases_extra.appendAssumeCapacity(@enumToInt(item));
83798382 }
83808383
83818384 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
83828385 } else {
83838386 for (items) |item_ref| {
8384 const item = sema.resolveInst(item_ref);
8387 const item = try sema.resolveInst(item_ref);
83858388 const cmp_ok = try case_block.addBinOp(.cmp_eq, operand, item);
83868389 if (any_ok != .none) {
83878390 any_ok = try case_block.addBinOp(.bool_or, any_ok, cmp_ok);
......@@ -8397,8 +8400,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
83978400 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
83988401 extra_index += 1;
83998402
8400 const item_first = sema.resolveInst(first_ref);
8401 const item_last = sema.resolveInst(last_ref);
8403 const item_first = try sema.resolveInst(first_ref);
8404 const item_last = try sema.resolveInst(last_ref);
84028405
84038406 // operand >= first and operand <= last
84048407 const range_first_ok = try case_block.addBinOp(
......@@ -8551,7 +8554,7 @@ fn resolveSwitchItemVal(
85518554 switch_prong_src: Module.SwitchProngSrc,
85528555 range_expand: Module.SwitchProngSrc.RangeExpand,
85538556) CompileError!TypedValue {
8554 const item = sema.resolveInst(item_ref);
8557 const item = try sema.resolveInst(item_ref);
85558558 const item_ty = sema.typeOf(item);
85568559 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
85578560 // Only if we know for sure we need to report a compile error do we resolve the
......@@ -8902,8 +8905,8 @@ fn zirShl(
89028905 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
89038906 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
89048907 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8905 const lhs = sema.resolveInst(extra.lhs);
8906 const rhs = sema.resolveInst(extra.rhs);
8908 const lhs = try sema.resolveInst(extra.lhs);
8909 const rhs = try sema.resolveInst(extra.rhs);
89078910 const lhs_ty = sema.typeOf(lhs);
89088911 const rhs_ty = sema.typeOf(rhs);
89098912 const target = sema.mod.getTarget();
......@@ -9030,8 +9033,8 @@ fn zirShr(
90309033 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
90319034 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
90329035 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9033 const lhs = sema.resolveInst(extra.lhs);
9034 const rhs = sema.resolveInst(extra.rhs);
9036 const lhs = try sema.resolveInst(extra.lhs);
9037 const rhs = try sema.resolveInst(extra.rhs);
90359038 const lhs_ty = sema.typeOf(lhs);
90369039 const rhs_ty = sema.typeOf(rhs);
90379040 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
......@@ -9084,8 +9087,8 @@ fn zirBitwise(
90849087 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
90859088 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
90869089 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9087 const lhs = sema.resolveInst(extra.lhs);
9088 const rhs = sema.resolveInst(extra.rhs);
9090 const lhs = try sema.resolveInst(extra.lhs);
9091 const rhs = try sema.resolveInst(extra.rhs);
90899092 const lhs_ty = sema.typeOf(lhs);
90909093 const rhs_ty = sema.typeOf(rhs);
90919094 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
......@@ -9129,7 +9132,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
91299132 const src = inst_data.src();
91309133 const operand_src = src; // TODO put this on the operand, not the '~'
91319134
9132 const operand = sema.resolveInst(inst_data.operand);
9135 const operand = try sema.resolveInst(inst_data.operand);
91339136 const operand_type = sema.typeOf(operand);
91349137 const scalar_type = operand_type.scalarType();
91359138 const target = sema.mod.getTarget();
......@@ -9244,8 +9247,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
92449247
92459248 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
92469249 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9247 const lhs = sema.resolveInst(extra.lhs);
9248 const rhs = sema.resolveInst(extra.rhs);
9250 const lhs = try sema.resolveInst(extra.lhs);
9251 const rhs = try sema.resolveInst(extra.rhs);
92499252 const lhs_ty = sema.typeOf(lhs);
92509253 const rhs_ty = sema.typeOf(rhs);
92519254
......@@ -9428,7 +9431,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
94289431
94299432 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
94309433 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9431 const lhs = sema.resolveInst(extra.lhs);
9434 const lhs = try sema.resolveInst(extra.lhs);
94329435 const lhs_ty = sema.typeOf(lhs);
94339436 const src: LazySrcLoc = inst_data.src();
94349437 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -9508,7 +9511,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
95089511 const lhs_src = src;
95099512 const rhs_src = src; // TODO better source location
95109513
9511 const rhs = sema.resolveInst(inst_data.operand);
9514 const rhs = try sema.resolveInst(inst_data.operand);
95129515 const rhs_ty = sema.typeOf(rhs);
95139516 const rhs_scalar_ty = rhs_ty.scalarType();
95149517
......@@ -9528,7 +9531,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
95289531 const lhs = if (rhs_ty.zigTypeTag() == .Vector)
95299532 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))
95309533 else
9531 sema.resolveInst(.zero);
9534 try sema.resolveInst(.zero);
95329535
95339536 return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src);
95349537}
......@@ -9539,13 +9542,13 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
95399542 const lhs_src = src;
95409543 const rhs_src = src; // TODO better source location
95419544
9542 const rhs = sema.resolveInst(inst_data.operand);
9545 const rhs = try sema.resolveInst(inst_data.operand);
95439546 const rhs_ty = sema.typeOf(rhs);
95449547
95459548 const lhs = if (rhs_ty.zigTypeTag() == .Vector)
95469549 try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero))
95479550 else
9548 sema.resolveInst(.zero);
9551 try sema.resolveInst(.zero);
95499552
95509553 return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src);
95519554}
......@@ -9564,8 +9567,8 @@ fn zirArithmetic(
95649567 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
95659568 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
95669569 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9567 const lhs = sema.resolveInst(extra.lhs);
9568 const rhs = sema.resolveInst(extra.rhs);
9570 const lhs = try sema.resolveInst(extra.lhs);
9571 const rhs = try sema.resolveInst(extra.rhs);
95699572
95709573 return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src);
95719574}
......@@ -9586,9 +9589,9 @@ fn zirOverflowArithmetic(
95869589 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
95879590 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
95889591
9589 const lhs = sema.resolveInst(extra.lhs);
9590 const rhs = sema.resolveInst(extra.rhs);
9591 const ptr = sema.resolveInst(extra.ptr);
9592 const lhs = try sema.resolveInst(extra.lhs);
9593 const rhs = try sema.resolveInst(extra.rhs);
9594 const ptr = try sema.resolveInst(extra.ptr);
95929595
95939596 const lhs_ty = sema.typeOf(lhs);
95949597 const rhs_ty = sema.typeOf(rhs);
......@@ -10787,7 +10790,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In
1078710790 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1078810791 const src = inst_data.src();
1078910792 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };
10790 const ptr = sema.resolveInst(inst_data.operand);
10793 const ptr = try sema.resolveInst(inst_data.operand);
1079110794 return sema.analyzeLoad(block, src, ptr, ptr_src);
1079210795}
1079310796
......@@ -10879,7 +10882,7 @@ fn zirAsm(
1087910882 const input = sema.code.extraData(Zir.Inst.Asm.Input, extra_i);
1088010883 extra_i = input.end;
1088110884
10882 const uncasted_arg = sema.resolveInst(input.data.operand);
10885 const uncasted_arg = try sema.resolveInst(input.data.operand);
1088310886 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
1088410887 switch (uncasted_arg_ty.zigTypeTag()) {
1088510888 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),
......@@ -10968,8 +10971,8 @@ fn zirCmpEq(
1096810971 const src: LazySrcLoc = inst_data.src();
1096910972 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1097010973 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
10971 const lhs = sema.resolveInst(extra.lhs);
10972 const rhs = sema.resolveInst(extra.rhs);
10974 const lhs = try sema.resolveInst(extra.lhs);
10975 const rhs = try sema.resolveInst(extra.rhs);
1097310976
1097410977 const lhs_ty = sema.typeOf(lhs);
1097510978 const rhs_ty = sema.typeOf(rhs);
......@@ -11080,8 +11083,8 @@ fn zirCmp(
1108011083 const src: LazySrcLoc = inst_data.src();
1108111084 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1108211085 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
11083 const lhs = sema.resolveInst(extra.lhs);
11084 const rhs = sema.resolveInst(extra.rhs);
11086 const lhs = try sema.resolveInst(extra.lhs);
11087 const rhs = try sema.resolveInst(extra.rhs);
1108511088 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
1108611089}
1108711090
......@@ -11275,7 +11278,7 @@ fn zirClosureCapture(
1127511278 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }
1127611279 // ...in which case the closure_capture instruction has access to a runtime
1127711280 // value only. In such case we preserve the type and use a dummy runtime value.
11278 const operand = sema.resolveInst(inst_data.operand);
11281 const operand = try sema.resolveInst(inst_data.operand);
1127911282 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) orelse
1128011283 Value.initTag(.generic_poison);
1128111284
......@@ -12248,7 +12251,7 @@ fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1224812251 _ = block;
1224912252 const zir_datas = sema.code.instructions.items(.data);
1225012253 const inst_data = zir_datas[inst].un_node;
12251 const operand = sema.resolveInst(inst_data.operand);
12254 const operand = try sema.resolveInst(inst_data.operand);
1225212255 const operand_ty = sema.typeOf(operand);
1225312256 return sema.addType(operand_ty);
1225412257}
......@@ -12268,6 +12271,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1226812271 .inlining = block.inlining,
1226912272 .is_comptime = false,
1227012273 .is_typeof = true,
12274 .want_safety = false,
1227112275 };
1227212276 defer child_block.instructions.deinit(sema.gpa);
1227312277
......@@ -12280,7 +12284,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1228012284fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1228112285 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1228212286 const src = inst_data.src();
12283 const operand = sema.resolveInst(inst_data.operand);
12287 const operand = try sema.resolveInst(inst_data.operand);
1228412288 const operand_ty = sema.typeOf(operand);
1228512289 const res_ty = try sema.log2IntType(block, operand_ty, src);
1228612290 return sema.addType(res_ty);
......@@ -12362,8 +12366,7 @@ fn zirTypeofPeer(
1236212366 defer sema.gpa.free(inst_list);
1236312367
1236412368 for (args) |arg_ref, i| {
12365 inst_list[i] = sema.resolveInst(arg_ref);
12366 if (sema.typeOf(inst_list[i]).tag() == .generic_poison) return error.GenericPoison;
12369 inst_list[i] = try sema.resolveInst(arg_ref);
1236712370 }
1236812371
1236912372 const result_type = try sema.resolvePeerTypes(block, src, inst_list, .{ .typeof_builtin_call_node_offset = extra.data.src_node });
......@@ -12377,7 +12380,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1237712380 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1237812381 const src = inst_data.src();
1237912382 const operand_src = src; // TODO put this on the operand, not the `!`
12380 const uncasted_operand = sema.resolveInst(inst_data.operand);
12383 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1238112384
1238212385 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
1238312386 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
......@@ -12403,7 +12406,7 @@ fn zirBoolBr(
1240312406
1240412407 const datas = sema.code.instructions.items(.data);
1240512408 const inst_data = datas[inst].bool_br;
12406 const lhs = sema.resolveInst(inst_data.lhs);
12409 const lhs = try sema.resolveInst(inst_data.lhs);
1240712410 const lhs_src = sema.src;
1240812411 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1240912412 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
......@@ -12488,7 +12491,7 @@ fn zirIsNonNull(
1248812491
1248912492 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1249012493 const src = inst_data.src();
12491 const operand = sema.resolveInst(inst_data.operand);
12494 const operand = try sema.resolveInst(inst_data.operand);
1249212495 return sema.analyzeIsNull(block, src, operand, true);
1249312496}
1249412497
......@@ -12502,7 +12505,7 @@ fn zirIsNonNullPtr(
1250212505
1250312506 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1250412507 const src = inst_data.src();
12505 const ptr = sema.resolveInst(inst_data.operand);
12508 const ptr = try sema.resolveInst(inst_data.operand);
1250612509 if ((try sema.resolveMaybeUndefVal(block, src, ptr)) == null) {
1250712510 return block.addUnOp(.is_non_null_ptr, ptr);
1250812511 }
......@@ -12515,7 +12518,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1251512518 defer tracy.end();
1251612519
1251712520 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12518 const operand = sema.resolveInst(inst_data.operand);
12521 const operand = try sema.resolveInst(inst_data.operand);
1251912522 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
1252012523}
1252112524
......@@ -12525,7 +12528,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1252512528
1252612529 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1252712530 const src = inst_data.src();
12528 const ptr = sema.resolveInst(inst_data.operand);
12531 const ptr = try sema.resolveInst(inst_data.operand);
1252912532 const loaded = try sema.analyzeLoad(block, src, ptr, src);
1253012533 return sema.analyzeIsNonErr(block, src, loaded);
1253112534}
......@@ -12546,7 +12549,7 @@ fn zirCondbr(
1254612549 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
1254712550 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1254812551
12549 const uncasted_cond = sema.resolveInst(extra.data.condition);
12552 const uncasted_cond = try sema.resolveInst(extra.data.condition);
1255012553 const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src);
1255112554
1255212555 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {
......@@ -12654,7 +12657,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1265412657 break :blk labeled_block;
1265512658 };
1265612659
12657 const operand = sema.resolveInst(break_data.operand);
12660 const operand = try sema.resolveInst(break_data.operand);
1265812661 const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand);
1265912662 try labeled_block.label.merges.results.append(sema.gpa, operand);
1266012663 try labeled_block.label.merges.br_list.append(sema.gpa, Air.refToIndex(br_ref).?);
......@@ -12705,7 +12708,7 @@ fn zirRetTok(
1270512708 defer tracy.end();
1270612709
1270712710 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
12708 const operand = sema.resolveInst(inst_data.operand);
12711 const operand = try sema.resolveInst(inst_data.operand);
1270912712 const src = inst_data.src();
1271012713
1271112714 return sema.analyzeRet(block, operand, src);
......@@ -12716,7 +12719,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1271612719 defer tracy.end();
1271712720
1271812721 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12719 const operand = sema.resolveInst(inst_data.operand);
12722 const operand = try sema.resolveInst(inst_data.operand);
1272012723 const src = inst_data.src();
1272112724
1272212725 return sema.analyzeRet(block, operand, src);
......@@ -12728,7 +12731,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1272812731
1272912732 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1273012733 const src = inst_data.src();
12731 const ret_ptr = sema.resolveInst(inst_data.operand);
12734 const ret_ptr = try sema.resolveInst(inst_data.operand);
1273212735
1273312736 if (block.is_comptime or block.inlining != null) {
1273412737 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);
......@@ -12851,7 +12854,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1285112854 const abi_align: u32 = if (inst_data.flags.has_align) blk: {
1285212855 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
1285312856 extra_i += 1;
12854 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);
1285512858 const val = try sema.resolveConstValue(block, src, coerced);
1285612859 // Check if this happens to be the lazy alignment of our element type, in
1285712860 // which case we can make this 0 without resolving it.
......@@ -12978,7 +12981,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1297812981 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
1297912982 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
1298012983 const field_name = try sema.resolveConstString(block, field_src, extra.field_name);
12981 const init = sema.resolveInst(extra.init);
12984 const init = try sema.resolveInst(extra.init);
1298212985 return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src);
1298312986}
1298412987
......@@ -13068,7 +13071,7 @@ fn zirStructInit(
1306813071 return sema.failWithOwnedErrorMsg(block, msg);
1306913072 }
1307013073 found_fields[field_index] = item.data.field_type;
13071 field_inits[field_index] = sema.resolveInst(item.data.init);
13074 field_inits[field_index] = try sema.resolveInst(item.data.init);
1307213075 }
1307313076
1307413077 var root_msg: ?*Module.ErrorMsg = null;
......@@ -13105,7 +13108,7 @@ fn zirStructInit(
1310513108 const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
1310613109 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
1310713110
13108 const init_inst = sema.resolveInst(item.data.init);
13111 const init_inst = try sema.resolveInst(item.data.init);
1310913112 if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {
1311013113 const tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
1311113114 return sema.addConstantMaybeRef(
......@@ -13213,7 +13216,7 @@ fn zirStructInitAnon(
1321313216 extra_index = item.end;
1321413217
1321513218 names[i] = sema.code.nullTerminatedString(item.data.field_name);
13216 const init = sema.resolveInst(item.data.init);
13219 const init = try sema.resolveInst(item.data.init);
1321713220 field_ty.* = sema.typeOf(init);
1321813221 const init_src = src; // TODO better source location
1321913222 if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| {
......@@ -13258,7 +13261,7 @@ fn zirStructInitAnon(
1325813261 .pointee_type = field_ty,
1325913262 });
1326013263 if (values[i].tag() == .unreachable_value) {
13261 const init = sema.resolveInst(item.data.init);
13264 const init = try sema.resolveInst(item.data.init);
1326213265 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);
1326313266 _ = try block.addBinOp(.store, field_ptr, init);
1326413267 }
......@@ -13272,7 +13275,7 @@ fn zirStructInitAnon(
1327213275 for (types) |_, i| {
1327313276 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
1327413277 extra_index = item.end;
13275 element_refs[i] = sema.resolveInst(item.data.init);
13278 element_refs[i] = try sema.resolveInst(item.data.init);
1327613279 }
1327713280
1327813281 return block.addAggregateInit(tuple_ty, element_refs);
......@@ -13296,7 +13299,7 @@ fn zirArrayInit(
1329613299 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len);
1329713300 defer gpa.free(resolved_args);
1329813301
13299 for (args) |arg, i| resolved_args[i] = sema.resolveInst(arg);
13302 for (args) |arg, i| resolved_args[i] = try sema.resolveInst(arg);
1330013303
1330113304 const elem_ty = sema.typeOf(resolved_args[0]);
1330213305 const array_ty = blk: {
......@@ -13380,7 +13383,7 @@ fn zirArrayInitAnon(
1338013383 const opt_runtime_src = rs: {
1338113384 var runtime_src: ?LazySrcLoc = null;
1338213385 for (operands) |operand, i| {
13383 const elem = sema.resolveInst(operand);
13386 const elem = try sema.resolveInst(operand);
1338413387 types[i] = sema.typeOf(elem);
1338513388 const operand_src = src; // TODO better source location
1338613389 if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| {
......@@ -13421,7 +13424,7 @@ fn zirArrayInitAnon(
1342113424 });
1342213425 if (values[i].tag() == .unreachable_value) {
1342313426 const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty);
13424 _ = try block.addBinOp(.store, field_ptr, sema.resolveInst(operand));
13427 _ = try block.addBinOp(.store, field_ptr, try sema.resolveInst(operand));
1342513428 }
1342613429 }
1342713430
......@@ -13430,7 +13433,7 @@ fn zirArrayInitAnon(
1343013433
1343113434 const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
1343213435 for (operands) |operand, i| {
13433 element_refs[i] = sema.resolveInst(operand);
13436 element_refs[i] = try sema.resolveInst(operand);
1343413437 }
1343513438
1343613439 return block.addAggregateInit(tuple_ty, element_refs);
......@@ -13573,7 +13576,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1357313576fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1357413577 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1357513578 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13576 const operand = sema.resolveInst(inst_data.operand);
13579 const operand = try sema.resolveInst(inst_data.operand);
1357713580 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
1357813581 if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1));
1357913582 const bool_ints = [2]Air.Inst.Ref{ .zero, .one };
......@@ -13586,7 +13589,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1358613589 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1358713590 const src = inst_data.src();
1358813591 _ = src;
13589 const operand = sema.resolveInst(inst_data.operand);
13592 const operand = try sema.resolveInst(inst_data.operand);
1359013593 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1359113594
1359213595 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
......@@ -13610,7 +13613,7 @@ fn zirUnaryMath(
1361013613 defer tracy.end();
1361113614
1361213615 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13613 const operand = sema.resolveInst(inst_data.operand);
13616 const operand = try sema.resolveInst(inst_data.operand);
1361413617 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1361513618 const operand_ty = sema.typeOf(operand);
1361613619 const target = sema.mod.getTarget();
......@@ -13670,7 +13673,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1367013673 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1367113674 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1367213675 const src = inst_data.src();
13673 const operand = sema.resolveInst(inst_data.operand);
13676 const operand = try sema.resolveInst(inst_data.operand);
1367413677 const operand_ty = sema.typeOf(operand);
1367513678 const mod = sema.mod;
1367613679
......@@ -13728,7 +13731,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
1372813731 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1372913732 const src = inst_data.src();
1373013733 const type_info_ty = try sema.resolveBuiltinTypeFields(block, src, "Type");
13731 const uncasted_operand = sema.resolveInst(inst_data.operand);
13734 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1373213735 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1373313736 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
1373413737 const val = try sema.resolveConstValue(block, operand_src, type_info);
......@@ -14403,7 +14406,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1440314406 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1440414407 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1440514408 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
14406 const operand = sema.resolveInst(extra.rhs);
14409 const operand = try sema.resolveInst(extra.rhs);
1440714410 const operand_ty = sema.typeOf(operand);
1440814411
1440914412 _ = try sema.checkIntType(block, ty_src, dest_ty);
......@@ -14424,7 +14427,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1442414427 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1442514428 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1442614429 const dest_ty = try sema.resolveType(block, ty_src, extra.lhs);
14427 const operand = sema.resolveInst(extra.rhs);
14430 const operand = try sema.resolveInst(extra.rhs);
1442814431 const operand_ty = sema.typeOf(operand);
1442914432
1443014433 try sema.checkFloatType(block, ty_src, dest_ty);
......@@ -14447,7 +14450,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1444714450 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1444814451
1444914452 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14450 const operand_res = sema.resolveInst(extra.rhs);
14453 const operand_res = try sema.resolveInst(extra.rhs);
1445114454 const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src);
1445214455
1445314456 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -14503,7 +14506,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1450314506 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
1450414507 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1450514508 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14506 const operand = sema.resolveInst(extra.rhs);
14509 const operand = try sema.resolveInst(extra.rhs);
1450714510 const operand_ty = sema.typeOf(operand);
1450814511 try sema.checkErrorSetType(block, dest_ty_src, dest_ty);
1450914512 try sema.checkErrorSetType(block, operand_src, operand_ty);
......@@ -14591,7 +14594,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1459114594 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1459214595 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1459314596 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14594 const operand = sema.resolveInst(extra.rhs);
14597 const operand = try sema.resolveInst(extra.rhs);
1459514598 const operand_ty = sema.typeOf(operand);
1459614599 const target = sema.mod.getTarget();
1459714600
......@@ -14651,7 +14654,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1465114654 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1465214655 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1465314656 const dest_scalar_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14654 const operand = sema.resolveInst(extra.rhs);
14657 const operand = try sema.resolveInst(extra.rhs);
1465514658 const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_scalar_ty);
1465614659 const operand_ty = sema.typeOf(operand);
1465714660 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
......@@ -14734,7 +14737,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1473414737 const align_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1473514738 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1473614739 const dest_align = try sema.resolveAlign(block, align_src, extra.lhs);
14737 const ptr = sema.resolveInst(extra.rhs);
14740 const ptr = try sema.resolveInst(extra.rhs);
1473814741 const ptr_ty = sema.typeOf(ptr);
1473914742
1474014743 // TODO in addition to pointers, this instruction is supposed to work for
......@@ -14768,7 +14771,7 @@ fn zirBitCount(
1476814771) CompileError!Air.Inst.Ref {
1476914772 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1477014773 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14771 const operand = sema.resolveInst(inst_data.operand);
14774 const operand = try sema.resolveInst(inst_data.operand);
1477214775 const operand_ty = sema.typeOf(operand);
1477314776 _ = try checkIntOrVector(sema, block, operand, operand_src);
1477414777 const target = sema.mod.getTarget();
......@@ -14820,7 +14823,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1482014823 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1482114824 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1482214825 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14823 const operand = sema.resolveInst(inst_data.operand);
14826 const operand = try sema.resolveInst(inst_data.operand);
1482414827 const operand_ty = sema.typeOf(operand);
1482514828 const scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1482614829 const target = sema.mod.getTarget();
......@@ -14877,7 +14880,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1487714880fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1487814881 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1487914882 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14880 const operand = sema.resolveInst(inst_data.operand);
14883 const operand = try sema.resolveInst(inst_data.operand);
1488114884 const operand_ty = sema.typeOf(operand);
1488214885 _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1488314886
......@@ -15363,7 +15366,7 @@ fn resolveExportOptions(
1536315366 zir_ref: Zir.Inst.Ref,
1536415367) CompileError!std.builtin.ExportOptions {
1536515368 const export_options_ty = try sema.getBuiltinType(block, src, "ExportOptions");
15366 const air_ref = sema.resolveInst(zir_ref);
15369 const air_ref = try sema.resolveInst(zir_ref);
1536715370 const options = try sema.coerce(block, export_options_ty, air_ref, src);
1536815371
1536915372 const name_operand = try sema.fieldVal(block, src, options, "name", src);
......@@ -15408,7 +15411,7 @@ fn resolveBuiltinEnum(
1540815411 comptime name: []const u8,
1540915412) CompileError!@field(std.builtin, name) {
1541015413 const ty = try sema.getBuiltinType(block, src, name);
15411 const air_ref = sema.resolveInst(zir_ref);
15414 const air_ref = try sema.resolveInst(zir_ref);
1541215415 const coerced = try sema.coerce(block, ty, air_ref, src);
1541315416 const val = try sema.resolveConstValue(block, src, coerced);
1541415417 return val.toEnum(@field(std.builtin, name));
......@@ -15449,7 +15452,7 @@ fn zirCmpxchg(
1544915452 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
1545015453 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = inst_data.src_node };
1545115454 // zig fmt: on
15452 const expected_value = sema.resolveInst(extra.expected_value);
15455 const expected_value = try sema.resolveInst(extra.expected_value);
1545315456 const elem_ty = sema.typeOf(expected_value);
1545415457 if (elem_ty.zigTypeTag() == .Float) {
1545515458 return sema.fail(
......@@ -15459,9 +15462,9 @@ fn zirCmpxchg(
1545915462 .{elem_ty.fmt(sema.mod)},
1546015463 );
1546115464 }
15462 const uncasted_ptr = sema.resolveInst(extra.ptr);
15465 const uncasted_ptr = try sema.resolveInst(extra.ptr);
1546315466 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
15464 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);
1546515468 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order);
1546615469 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order);
1546715470
......@@ -15529,7 +15532,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
1552915532 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1553015533 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
1553115534 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32));
15532 const scalar = sema.resolveInst(extra.rhs);
15535 const scalar = try sema.resolveInst(extra.rhs);
1553315536 const scalar_ty = sema.typeOf(scalar);
1553415537 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
1553515538 const vector_ty = try Type.Tag.vector.create(sema.arena, .{
......@@ -15555,7 +15558,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1555515558 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1555615559 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1555715560 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp");
15558 const operand = sema.resolveInst(extra.rhs);
15561 const operand = try sema.resolveInst(extra.rhs);
1555915562 const operand_ty = sema.typeOf(operand);
1556015563 const target = sema.mod.getTarget();
1556115564
......@@ -15627,9 +15630,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1562715630
1562815631 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
1562915632 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
15630 var a = sema.resolveInst(extra.a);
15631 var b = sema.resolveInst(extra.b);
15632 var mask = sema.resolveInst(extra.mask);
15633 var a = try sema.resolveInst(extra.a);
15634 var b = try sema.resolveInst(extra.b);
15635 var mask = try sema.resolveInst(extra.mask);
1563315636 var mask_ty = sema.typeOf(mask);
1563415637
1563515638 const mask_len = switch (sema.typeOf(mask).zigTypeTag()) {
......@@ -15821,7 +15824,7 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1582115824
1582215825 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
1582315826 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
15824 const pred_uncoerced = sema.resolveInst(extra.pred);
15827 const pred_uncoerced = try sema.resolveInst(extra.pred);
1582515828 const pred_ty = sema.typeOf(pred_uncoerced);
1582615829
1582715830 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison()) {
......@@ -15834,8 +15837,8 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1583415837 const pred = try sema.coerce(block, bool_vec_ty, pred_uncoerced, pred_src);
1583515838
1583615839 const vec_ty = try Type.vector(sema.arena, vec_len, elem_ty);
15837 const a = try sema.coerce(block, vec_ty, sema.resolveInst(extra.a), a_src);
15838 const b = try sema.coerce(block, vec_ty, sema.resolveInst(extra.b), b_src);
15840 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
15841 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
1583915842
1584015843 const maybe_pred = try sema.resolveMaybeUndefVal(block, pred_src, pred);
1584115844 const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a);
......@@ -15907,7 +15910,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1590715910 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
1590815911 // zig fmt: on
1590915912 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
15910 const uncasted_ptr = sema.resolveInst(extra.ptr);
15913 const uncasted_ptr = try sema.resolveInst(extra.ptr);
1591115914 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true);
1591215915 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);
1591315916
......@@ -15954,9 +15957,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1595415957 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
1595515958 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
1595615959 // zig fmt: on
15957 const operand = sema.resolveInst(extra.operand);
15960 const operand = try sema.resolveInst(extra.operand);
1595815961 const elem_ty = sema.typeOf(operand);
15959 const uncasted_ptr = sema.resolveInst(extra.ptr);
15962 const uncasted_ptr = try sema.resolveInst(extra.ptr);
1596015963 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
1596115964 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);
1596215965
......@@ -16037,9 +16040,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1603716040 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
1603816041 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
1603916042 // zig fmt: on
16040 const operand = sema.resolveInst(extra.operand);
16043 const operand = try sema.resolveInst(extra.operand);
1604116044 const elem_ty = sema.typeOf(operand);
16042 const uncasted_ptr = sema.resolveInst(extra.ptr);
16045 const uncasted_ptr = try sema.resolveInst(extra.ptr);
1604316046 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
1604416047 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);
1604516048
......@@ -16070,10 +16073,10 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1607016073 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
1607116074 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
1607216075
16073 const addend = sema.resolveInst(extra.addend);
16076 const addend = try sema.resolveInst(extra.addend);
1607416077 const ty = sema.typeOf(addend);
16075 const mulend1 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend1), mulend1_src);
16076 const mulend2 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend2), mulend2_src);
16078 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
16079 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
1607716080
1607816081 const target = sema.mod.getTarget();
1607916082
......@@ -16137,9 +16140,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1613716140 const call_src = inst_data.src();
1613816141
1613916142 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
16140 var func = sema.resolveInst(extra.callee);
16141 const options = sema.resolveInst(extra.options);
16142 const args = sema.resolveInst(extra.args);
16143 var func = try sema.resolveInst(extra.callee);
16144 const options = try sema.resolveInst(extra.options);
16145 const args = try sema.resolveInst(extra.args);
1614316146
1614416147 const wanted_modifier: std.builtin.CallOptions.Modifier = modifier: {
1614516148 const call_options_ty = try sema.getBuiltinType(block, options_src, "CallOptions");
......@@ -16229,7 +16232,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1622916232
1623016233 const struct_ty = try sema.resolveType(block, ty_src, extra.parent_type);
1623116234 const field_name = try sema.resolveConstString(block, name_src, extra.field_name);
16232 const field_ptr = sema.resolveInst(extra.field_ptr);
16235 const field_ptr = try sema.resolveInst(extra.field_ptr);
1623316236 const field_ptr_ty = sema.typeOf(field_ptr);
1623416237
1623516238 if (struct_ty.zigTypeTag() != .Struct) {
......@@ -16294,8 +16297,8 @@ fn zirMinMax(
1629416297 const src = inst_data.src();
1629516298 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1629616299 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
16297 const lhs = sema.resolveInst(extra.lhs);
16298 const rhs = sema.resolveInst(extra.rhs);
16300 const lhs = try sema.resolveInst(extra.lhs);
16301 const rhs = try sema.resolveInst(extra.rhs);
1629916302 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
1630016303 try sema.checkNumericType(block, rhs_src, sema.typeOf(rhs));
1630116304 return sema.analyzeMinMax(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
......@@ -16362,7 +16365,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1636216365 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1636316366 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1636416367 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16365 const dest_ptr = sema.resolveInst(extra.dest);
16368 const dest_ptr = try sema.resolveInst(extra.dest);
1636616369 const dest_ptr_ty = sema.typeOf(dest_ptr);
1636716370
1636816371 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);
......@@ -16370,7 +16373,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1637016373 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});
1637116374 }
1637216375
16373 const uncasted_src_ptr = sema.resolveInst(extra.source);
16376 const uncasted_src_ptr = try sema.resolveInst(extra.source);
1637416377 const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr);
1637516378 try sema.checkPtrOperand(block, src_src, uncasted_src_ptr_ty);
1637616379 const src_ptr_info = uncasted_src_ptr_ty.ptrInfo().data;
......@@ -16384,7 +16387,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1638416387 .size = .Many,
1638516388 });
1638616389 const src_ptr = try sema.coerce(block, wanted_src_ptr_ty, uncasted_src_ptr, src_src);
16387 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);
1638816391
1638916392 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
1639016393 if (!dest_ptr_val.isComptimeMutablePtr()) break :rs dest_src;
......@@ -16419,15 +16422,15 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1641916422 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1642016423 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1642116424 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
16422 const dest_ptr = sema.resolveInst(extra.dest);
16425 const dest_ptr = try sema.resolveInst(extra.dest);
1642316426 const dest_ptr_ty = sema.typeOf(dest_ptr);
1642416427 try sema.checkPtrOperand(block, dest_src, dest_ptr_ty);
1642516428 if (dest_ptr_ty.isConstPtr()) {
1642616429 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty.fmt(sema.mod)});
1642716430 }
1642816431 const elem_ty = dest_ptr_ty.elemType2();
16429 const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src);
16430 const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);
16432 const value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.byte), value_src);
16433 const len = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.byte_count), len_src);
1643116434
1643216435 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {
1643316436 if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;
......@@ -16521,7 +16524,7 @@ fn zirVarExtended(
1652116524 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
1652216525 const init_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
1652316526 extra_index += 1;
16524 break :blk sema.resolveInst(init_ref);
16527 break :blk try sema.resolveInst(init_ref);
1652516528 } else .none;
1652616529
1652716530 const have_ty = extra.data.var_type != .none;
......@@ -16669,7 +16672,7 @@ fn zirCDefine(
1666916672 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1667016673
1667116674 const name = try sema.resolveConstString(block, name_src, extra.lhs);
16672 const rhs = sema.resolveInst(extra.rhs);
16675 const rhs = try sema.resolveInst(extra.rhs);
1667316676 if (sema.typeOf(rhs).zigTypeTag() != .Void) {
1667416677 const value = try sema.resolveConstString(block, val_src, extra.rhs);
1667516678 try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
......@@ -16718,7 +16721,7 @@ fn zirWasmMemoryGrow(
1671816721 }
1671916722
1672016723 const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32));
16721 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);
1672216725
1672316726 try sema.requireRuntimeBlock(block, builtin_src);
1672416727 return block.addInst(.{
......@@ -16739,9 +16742,9 @@ fn zirPrefetch(
1673916742 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
1674016743 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1674116744 const options_ty = try sema.getBuiltinType(block, opts_src, "PrefetchOptions");
16742 const ptr = sema.resolveInst(extra.lhs);
16745 const ptr = try sema.resolveInst(extra.lhs);
1674316746 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
16744 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);
1674516748 const target = sema.mod.getTarget();
1674616749
1674716750 const rw = try sema.fieldVal(block, opts_src, options, "rw", opts_src);
......@@ -16782,7 +16785,7 @@ fn zirBuiltinExtern(
1678216785 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1678316786
1678416787 var ty = try sema.resolveType(block, ty_src, extra.lhs);
16785 const options_inst = sema.resolveInst(extra.rhs);
16788 const options_inst = try sema.resolveInst(extra.rhs);
1678616789 const mod = sema.mod;
1678716790
1678816791 const options = options: {
......@@ -20197,7 +20200,11 @@ fn beginComptimePtrLoad(
2019720200 var deref = try beginComptimePtrLoad(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty);
2019820201
2019920202 if (field_ptr.container_ty.hasWellDefinedLayout()) {
20200 if (deref.parent) |*parent| {
20203 const struct_ty = field_ptr.container_ty.castTag(.@"struct");
20204 if (struct_ty != null and struct_ty.?.data.layout == .Packed) {
20205 // packed structs are not byte addressable
20206 deref.parent = null;
20207 } else if (deref.parent) |*parent| {
2020120208 // Update the byte offset (in-place)
2020220209 try sema.resolveTypeLayout(block, src, field_ptr.container_ty);
2020320210 const field_offset = field_ptr.container_ty.structFieldOffset(field_index, target);
......@@ -20828,7 +20835,7 @@ fn analyzeDeclVal(
2082820835 const decl_ref = try sema.analyzeDeclRef(decl_index);
2082920836 const result = try sema.analyzeLoad(block, src, decl_ref, src);
2083020837 if (Air.refToIndex(result)) |index| {
20831 if (sema.air_instructions.items(.tag)[index] == .constant) {
20838 if (sema.air_instructions.items(.tag)[index] == .constant and !block.is_typeof) {
2083220839 try sema.decl_val_table.put(sema.gpa, decl_index, result);
2083320840 }
2083420841 }
......@@ -20959,8 +20966,14 @@ fn analyzeLoad(
2095920966 if (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) |elem_val| {
2096020967 return sema.addConstant(elem_ty, elem_val);
2096120968 }
20969 if (block.is_typeof) {
20970 return sema.addConstUndef(elem_ty);
20971 }
2096220972 }
2096320973
20974 const valid_rt = try sema.validateRunTimeType(block, src, elem_ty, false);
20975 if (!valid_rt) return sema.failWithNeededComptime(block, src);
20976
2096420977 try sema.requireRuntimeBlock(block, src);
2096520978 return block.addTyOp(.load, elem_ty, ptr);
2096620979}
......@@ -22845,7 +22858,7 @@ fn semaStructFields(
2284522858 if (has_default) {
2284622859 const default_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
2284722860 extra_index += 1;
22848 const default_inst = sema.resolveInst(default_ref);
22861 const default_inst = try sema.resolveInst(default_ref);
2284922862 // TODO: if we need to report an error here, use a source location
2285022863 // that points to this default value expression rather than the struct.
2285122864 // But only resolve the source location if we need to emit a compile error.
......@@ -23029,7 +23042,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil
2302923042 const tag_ref: Zir.Inst.Ref = if (has_tag) blk: {
2303023043 const tag_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
2303123044 extra_index += 1;
23032 break :blk sema.resolveInst(tag_ref);
23045 break :blk try sema.resolveInst(tag_ref);
2303323046 } else .none;
2303423047
2303523048 if (enum_value_map) |map| {
......@@ -23654,7 +23667,7 @@ fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
2365423667fn addBool(sema: *Sema, ty: Type, boolean: bool) CompileError!Air.Inst.Ref {
2365523668 return switch (ty.zigTypeTag()) {
2365623669 .Vector => sema.addConstant(ty, try Value.Tag.repeated.create(sema.arena, Value.makeBool(boolean))),
23657 .Bool => sema.resolveInst(if (boolean) .bool_true else .bool_false),
23670 .Bool => try sema.resolveInst(if (boolean) .bool_true else .bool_false),
2365823671 else => unreachable,
2365923672 };
2366023673}
src/value.zig+1
......@@ -2645,6 +2645,7 @@ pub const Value = extern union {
26452645 }
26462646 unreachable;
26472647 },
2648 .undef => return Value.undef,
26482649
26492650 else => unreachable,
26502651 }
test/behavior/sizeof_and_typeof.zig+20
......@@ -280,3 +280,23 @@ test "@sizeOf comparison against zero" {
280280 try S.doTheTest(S1, true);
281281 try S.doTheTest(U1, true);
282282}
283
284test "hardcoded address in typeof expression" {
285 const S = struct {
286 fn func() @TypeOf(@intToPtr(*[]u8, 0x10).*[0]) {
287 return 0;
288 }
289 };
290 try expect(S.func() == 0);
291 comptime try expect(S.func() == 0);
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}
test/behavior/struct.zig+21
......@@ -1319,3 +1319,24 @@ test "packed struct aggregate init" {
13191319 const result = @bitCast(u8, S.foo(1, 2));
13201320 try expect(result == 9);
13211321}
1322
1323test "packed struct field access via pointer" {
1324 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1325 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1326 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1327 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1328
1329 const S = struct {
1330 fn doTheTest() !void {
1331 const S = packed struct { a: u30 };
1332 var s1: S = .{ .a = 1 };
1333 var s2 = &s1;
1334 try expect(s2.a == 1);
1335 var s3: S = undefined;
1336 var s4 = &s3;
1337 _ = s4;
1338 }
1339 };
1340 try S.doTheTest();
1341 comptime try S.doTheTest();
1342}
test/cases/compile_errors/dereference_anyopaque.zig created+50
......@@ -0,0 +1,50 @@
1const std = @import("std");
2
3const Error = error{Something};
4
5fn next() Error!void {
6 return;
7}
8
9fn parse(comptime T: type, allocator: std.mem.Allocator) !void {
10 parseFree(T, undefined, allocator);
11 _ = (try next()) != null;
12}
13
14fn parseFree(comptime T: type, value: T, allocator: std.mem.Allocator) void {
15 switch (@typeInfo(T)) {
16 .Struct => |structInfo| {
17 inline for (structInfo.fields) |field| {
18 if (!field.is_comptime)
19 parseFree(field.field_type, undefined, allocator);
20 }
21 },
22 .Pointer => |ptrInfo| {
23 switch (ptrInfo.size) {
24 .One => {
25 parseFree(ptrInfo.child, value.*, allocator);
26 },
27 .Slice => {
28 for (value) |v|
29 parseFree(ptrInfo.child, v, allocator);
30 },
31 else => unreachable,
32 }
33 },
34 else => unreachable,
35 }
36}
37
38pub export fn entry() void {
39 const allocator = std.testing.allocator_instance.allocator();
40 _ = parse(std.StringArrayHashMap(bool), allocator) catch return;
41}
42
43// error
44// backend=llvm
45//
46// :11:22: error: comparison of 'void' with null
47// :25:51: error: unable to resolve comptime value
48// :25:51: error: unable to resolve comptime value
49// :25:51: error: unable to resolve comptime value
50// :25:51: error: unable to resolve comptime value