authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-02 19:46:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-03 03:14:54-04:00
logaf20fdbce71d6799ab8fdca4374ade80755b04a3
treee1d2c8779dde26ea40a01a658c04c8a8249e487d
parentbb98620c10992884d58ae97a3a30dd9e26735fea

stage1: eliminate the IrInst base struct

This commit intentions to have no functional changes. The only purpose is to delete the struct IrInst, which is the common base struct that both IrInstSrc (ZIR) and IrInstGen (AIR) instructions embed. This untangles stage1 ZIR and AIR memory layout, paving the way for a following commit to reduce memory usage.

6 files changed, 2011 insertions(+), 1945 deletions(-)

src/stage1/all_types.hpp+13-20
......@@ -31,7 +31,6 @@ struct BuiltinFnEntry;
3131struct TypeStructField;
3232struct CodeGen;
3333struct ZigValue;
34struct IrInst;
3534struct IrInstSrc;
3635struct IrInstGen;
3736struct IrInstGenCast;
......@@ -313,7 +312,7 @@ struct ConstErrValue {
313312struct ConstBoundFnValue {
314313 ZigFn *fn;
315314 IrInstGen *first_arg;
316 IrInst *first_arg_src;
315 AstNode *first_arg_src;
317316};
318317
319318struct ConstArgTuple {
......@@ -394,7 +393,7 @@ struct LazyValueTypeInfoDecls {
394393 IrAnalyze *ira;
395394
396395 ScopeDecls *decls_scope;
397 IrInst *source_instr;
396 AstNode *source_node;
398397};
399398
400399struct LazyValueAlignOf {
......@@ -2444,7 +2443,7 @@ struct Stage1ZirBasicBlock {
24442443 IrBasicBlockGen *child;
24452444 Scope *scope;
24462445 const char *name_hint;
2447 IrInst *suspend_instruction_ref;
2446 IrInstSrc *suspend_instruction_ref;
24482447
24492448 uint32_t ref_count;
24502449 uint32_t index; // index into the basic block list
......@@ -2463,11 +2462,11 @@ struct IrBasicBlockGen {
24632462 // The instruction that referenced this basic block and caused us to
24642463 // analyze the basic block. If the same instruction wants us to emit
24652464 // the same basic block, then we re-generate it instead of saving it.
2466 IrInst *ref_instruction;
2465 IrInstSrc *ref_instruction;
24672466 // When this is non-null, a branch to this basic block is only allowed
24682467 // if the branch is comptime. The instruction points to the reason
24692468 // the basic block must be comptime.
2470 IrInst *must_be_comptime_source_instr;
2469 AstNode *must_be_comptime_source_node;
24712470
24722471 uint32_t debug_id;
24732472 bool already_appended;
......@@ -2714,24 +2713,13 @@ enum IrInstGenId {
27142713 IrInstGenIdExtern,
27152714};
27162715
2717// Common fields between IrInstSrc and IrInstGen.
2718struct IrInst {
2719 // if ref_count is zero and the instruction has no side effects,
2720 // the instruction can be omitted in codegen
2716struct IrInstSrc {
27212717 uint32_t ref_count;
27222718 uint32_t debug_id;
27232719
27242720 Scope *scope;
27252721 AstNode *source_node;
27262722
2727 // for debugging purposes, these are useful to call to inspect the instruction
2728 void dump();
2729 void src();
2730};
2731
2732struct IrInstSrc {
2733 IrInst base;
2734
27352723 IrInstSrcId id;
27362724
27372725 // When analyzing IR, instructions that point to this instruction in the "old ir"
......@@ -2746,9 +2734,14 @@ struct IrInstSrc {
27462734};
27472735
27482736struct IrInstGen {
2749 IrInst base;
2750
27512737 IrInstGenId id;
2738 // if ref_count is zero and the instruction has no side effects,
2739 // the instruction can be omitted in codegen
2740 uint32_t ref_count;
2741 uint32_t debug_id;
2742
2743 Scope *scope;
2744 AstNode *source_node;
27522745
27532746 LLVMValueRef llvm_value;
27542747 ZigValue *value;
src/stage1/analyze.cpp+18-18
......@@ -5076,7 +5076,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
50765076 // TODO function pointer call here, could be anything
50775077 continue;
50785078 }
5079 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.base.source_node, must_not_be_async,
5079 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,
50805080 call->modifier))
50815081 {
50825082 case ErrorSemanticAnalyzeFail:
......@@ -5096,7 +5096,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
50965096 for (size_t i = 0; i < fn->await_list.length; i += 1) {
50975097 IrInstGenAwait *await = fn->await_list.at(i);
50985098 if (await->is_nosuspend) continue;
5099 switch (analyze_callee_async(g, fn, await->target_fn, await->base.base.source_node, must_not_be_async,
5099 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,
51005100 CallModifierNone))
51015101 {
51025102 case ErrorSemanticAnalyzeFail:
......@@ -6736,11 +6736,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
67366736 if (fn->analyzed_executable.need_err_code_spill) {
67376737 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
67386738 alloca_gen->base.id = IrInstGenIdAlloca;
6739 alloca_gen->base.base.source_node = fn->proto_node;
6740 alloca_gen->base.base.scope = fn->child_scope;
6739 alloca_gen->base.source_node = fn->proto_node;
6740 alloca_gen->base.scope = fn->child_scope;
67416741 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
67426742 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6743 alloca_gen->base.base.ref_count = 1;
6743 alloca_gen->base.ref_count = 1;
67446744 alloca_gen->name_hint = "";
67456745 fn->alloca_gen_list.append(alloca_gen);
67466746 fn->err_code_spill = &alloca_gen->base;
......@@ -6762,7 +6762,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
67626762 if (call->fn_ref->value->type->data.fn.fn_type_id.cc != CallingConventionAsync) {
67636763 continue;
67646764 }
6765 add_node_error(g, call->base.base.source_node,
6765 add_node_error(g, call->base.source_node,
67666766 buf_sprintf("function is not comptime-known; @asyncCall required"));
67676767 return ErrorSemanticAnalyzeFail;
67686768 }
......@@ -6772,14 +6772,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
67726772 if (callee->anal_state == FnAnalStateProbing) {
67736773 ErrorMsg *msg = add_node_error(g, fn->proto_node,
67746774 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
6775 g->trace_err = add_error_note(g, msg, call->base.base.source_node,
6775 g->trace_err = add_error_note(g, msg, call->base.source_node,
67766776 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
67776777 return ErrorSemanticAnalyzeFail;
67786778 }
67796779
67806780 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
67816781 frame_type->data.frame.resolve_loop_type = callee_frame_type;
6782 frame_type->data.frame.resolve_loop_src_node = call->base.base.source_node;
6782 frame_type->data.frame.resolve_loop_src_node = call->base.source_node;
67836783
67846784 analyze_fn_body(g, callee);
67856785 if (callee->anal_state == FnAnalStateInvalid) {
......@@ -6795,7 +6795,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
67956795 if (!fn_is_async(callee))
67966796 continue;
67976797
6798 mark_suspension_point(call->base.base.scope);
6798 mark_suspension_point(call->base.scope);
67996799
68006800 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
68016801 return err;
......@@ -6840,17 +6840,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
68406840 }
68416841 // This await is a suspend point, but it might not need a spill.
68426842 // We do need to mark the ExprScope as having a suspend point in it.
6843 mark_suspension_point(await->base.base.scope);
6843 mark_suspension_point(await->base.scope);
68446844
68456845 if (await->result_loc != nullptr) {
68466846 // If there's a result location, that is the spill
68476847 continue;
68486848 }
6849 if (await->base.base.ref_count == 0)
6849 if (await->base.ref_count == 0)
68506850 continue;
68516851 if (!type_has_bits(g, await->base.value->type))
68526852 continue;
6853 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
6853 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
68546854 await->base.value->type, "");
68556855 }
68566856 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
......@@ -6858,7 +6858,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
68586858 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
68596859 IrInstGen *instruction = block->instruction_list.at(instr_i);
68606860 if (instruction->id == IrInstGenIdSuspendFinish) {
6861 mark_suspension_point(instruction->base.scope);
6861 mark_suspension_point(instruction->scope);
68626862 }
68636863 }
68646864 }
......@@ -6885,14 +6885,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
68856885 }
68866886 if (instruction->value->special != ConstValSpecialRuntime)
68876887 continue;
6888 if (instruction->base.ref_count == 0)
6888 if (instruction->ref_count == 0)
68896889 continue;
68906890 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
68916891 return ErrorSemanticAnalyzeFail;
68926892 if (!type_has_bits(g, instruction->value->type))
68936893 continue;
6894 if (scope_needs_spill(instruction->base.scope)) {
6895 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
6894 if (scope_needs_spill(instruction->scope)) {
6895 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
68966896 fn, instruction->value->type, "");
68976897 }
68986898 }
......@@ -6950,7 +6950,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
69506950 ZigType *child_type = resolve_type_isf(ptr_type->data.pointer.child_type);
69516951 if (!type_has_bits(g, child_type))
69526952 continue;
6953 if (instruction->base.base.ref_count == 0)
6953 if (instruction->base.ref_count == 0)
69546954 continue;
69556955 if (instruction->base.value->special != ConstValSpecialRuntime) {
69566956 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -6961,7 +6961,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
69616961 }
69626962
69636963 frame_type->data.frame.resolve_loop_type = child_type;
6964 frame_type->data.frame.resolve_loop_src_node = instruction->base.base.source_node;
6964 frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node;
69656965 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
69666966 return err;
69676967 }
src/stage1/astgen.cpp+37-28
......@@ -39,7 +39,7 @@ static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf
3939static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
4040 ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime);
4141
42static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) {
42static void ir_assert_impl(bool ok, IrInstSrc *source_instruction, char const *file, unsigned int line) {
4343 if (ok) return;
4444 src_assert_impl(ok, source_instruction->source_node, file, line);
4545}
......@@ -386,7 +386,7 @@ static void ir_ref_bb(Stage1ZirBasicBlock *bb) {
386386
387387static void ir_ref_instruction(IrInstSrc *instruction, Stage1ZirBasicBlock *cur_bb) {
388388 assert(instruction->id != IrInstSrcIdInvalid);
389 instruction->base.ref_count += 1;
389 instruction->ref_count += 1;
390390 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
391391 && instruction->id != IrInstSrcIdConst)
392392 {
......@@ -939,9 +939,9 @@ template<typename T>
939939static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
940940 T *special_instruction = heap::c_allocator.create<T>();
941941 special_instruction->base.id = ir_inst_id(special_instruction);
942 special_instruction->base.base.scope = scope;
943 special_instruction->base.base.source_node = source_node;
944 special_instruction->base.base.debug_id = irb_next_debug_id(ag);
942 special_instruction->base.scope = scope;
943 special_instruction->base.source_node = source_node;
944 special_instruction->base.debug_id = irb_next_debug_id(ag);
945945 special_instruction->base.owner_bb = ag->current_basic_block;
946946 return special_instruction;
947947}
......@@ -1325,9 +1325,9 @@ static IrInstSrc *ir_build_ptr_type_simple(Stage1AstGen *ag, Scope *scope, AstNo
13251325{
13261326 IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>();
13271327 inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple;
1328 inst->base.base.scope = scope;
1329 inst->base.base.source_node = source_node;
1330 inst->base.base.debug_id = irb_next_debug_id(ag);
1328 inst->base.scope = scope;
1329 inst->base.source_node = source_node;
1330 inst->base.debug_id = irb_next_debug_id(ag);
13311331 inst->base.owner_bb = ag->current_basic_block;
13321332 ir_instruction_append(ag->current_basic_block, &inst->base);
13331333
......@@ -2391,9 +2391,9 @@ static IrInstSrc *ir_build_check_switch_prongs(Stage1AstGen *ag, Scope *scope, A
23912391 IrInstSrcCheckSwitchProngs *instruction = heap::c_allocator.create<IrInstSrcCheckSwitchProngs>();
23922392 instruction->base.id = have_underscore_prong ?
23932393 IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo;
2394 instruction->base.base.scope = scope;
2395 instruction->base.base.source_node = source_node;
2396 instruction->base.base.debug_id = irb_next_debug_id(ag);
2394 instruction->base.scope = scope;
2395 instruction->base.source_node = source_node;
2396 instruction->base.debug_id = irb_next_debug_id(ag);
23972397 instruction->base.owner_bb = ag->current_basic_block;
23982398 ir_instruction_append(ag->current_basic_block, &instruction->base);
23992399
......@@ -2582,9 +2582,9 @@ static IrInstSrc *ir_build_arg_type(Stage1AstGen *ag, Scope *scope, AstNode *sou
25822582 IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>();
25832583 instruction->base.id = allow_var ?
25842584 IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse;
2585 instruction->base.base.scope = scope;
2586 instruction->base.base.source_node = source_node;
2587 instruction->base.base.debug_id = irb_next_debug_id(ag);
2585 instruction->base.scope = scope;
2586 instruction->base.source_node = source_node;
2587 instruction->base.debug_id = irb_next_debug_id(ag);
25882588 instruction->base.owner_bb = ag->current_basic_block;
25892589 ir_instruction_append(ag->current_basic_block, &instruction->base);
25902590
......@@ -3157,7 +3157,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
31573157 variable_entry->const_value = codegen->pass1_arena->create<ZigValue>();
31583158
31593159 if (is_comptime != nullptr) {
3160 is_comptime->base.ref_count += 1;
3160 is_comptime->ref_count += 1;
31613161 }
31623162
31633163 if (name) {
......@@ -3405,7 +3405,7 @@ static IrInstSrc *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b
34053405 ir_build_end_expr(ag, parent_scope, block_node, result, &result_loc_ret->base);
34063406 if (!astgen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr))
34073407 return ag->codegen->invalid_inst_src;
3408 return ir_build_return_src(ag, child_scope, result->base.source_node, result);
3408 return ir_build_return_src(ag, child_scope, result->source_node, result);
34093409}
34103410
34113411static IrInstSrc *astgen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) {
......@@ -3565,9 +3565,9 @@ static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, IrInstSrc *c
35653565 peer_parent->parent = parent;
35663566
35673567 IrInstSrc *popped_inst = ag->current_basic_block->instruction_list.pop();
3568 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);
3568 ir_assert(popped_inst == cond_br_inst, cond_br_inst);
35693569
3570 ir_build_reset_result(ag, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
3570 ir_build_reset_result(ag, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base);
35713571 ag->current_basic_block->instruction_list.append(popped_inst);
35723572
35733573 return peer_parent;
......@@ -5436,7 +5436,7 @@ static IrInstSrc *astgen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *n
54365436
54375437static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
54385438 if (inst == ag->codegen->invalid_inst_src) return inst;
5439 ir_build_end_expr(ag, scope, inst->base.source_node, inst, result_loc);
5439 ir_build_end_expr(ag, scope, inst->source_node, inst, result_loc);
54405440 return inst;
54415441}
54425442
......@@ -5447,7 +5447,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,
54475447 // [STMT_EXPR_TEST_THING] <--- (search this token)
54485448 if (value == ag->codegen->invalid_inst_src ||
54495449 instr_is_unreachable(value) ||
5450 value->base.source_node->type == NodeTypeDefer ||
5450 value->source_node->type == NodeTypeDefer ||
54515451 value->id == IrInstSrcIdDeclVar)
54525452 {
54535453 return value;
......@@ -5457,7 +5457,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,
54575457 if (lval == LValPtr) {
54585458 // We needed a pointer to a value, but we got a value. So we create
54595459 // an instruction which just makes a pointer of it.
5460 return ir_build_ref_src(ag, scope, value->base.source_node, value);
5460 return ir_build_ref_src(ag, scope, value->source_node, value);
54615461 } else if (result_loc != nullptr) {
54625462 return ir_expr_wrap(ag, scope, value, result_loc);
54635463 } else {
......@@ -5690,11 +5690,11 @@ static IrInstSrc *astgen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast
56905690
56915691 result_loc_cast = ir_build_cast_result_loc(ag, container_type, parent_result_loc);
56925692 child_result_loc = &result_loc_cast->base;
5693 init_array_type_source_node = container_type->base.source_node;
5693 init_array_type_source_node = container_type->source_node;
56945694 } else {
56955695 child_result_loc = parent_result_loc;
56965696 if (parent_result_loc->source_instruction != nullptr) {
5697 init_array_type_source_node = parent_result_loc->source_instruction->base.source_node;
5697 init_array_type_source_node = parent_result_loc->source_instruction->source_node;
56985698 } else {
56995699 init_array_type_source_node = node;
57005700 }
......@@ -5784,7 +5784,7 @@ static ResultLocVar *ir_build_var_result_loc(Stage1AstGen *ag, IrInstSrc *alloca
57845784 result_loc_var->base.allow_write_through_const = true;
57855785 result_loc_var->var = var;
57865786
5787 ir_build_reset_result(ag, alloca->base.scope, alloca->base.source_node, &result_loc_var->base);
5787 ir_build_reset_result(ag, alloca->scope, alloca->source_node, &result_loc_var->base);
57885788
57895789 return result_loc_var;
57905790}
......@@ -5799,7 +5799,7 @@ static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest
57995799 ir_ref_instruction(dest_type, ag->current_basic_block);
58005800 result_loc_cast->parent = parent_result_loc;
58015801
5802 ir_build_reset_result(ag, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base);
5802 ir_build_reset_result(ag, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
58035803
58045804 return result_loc_cast;
58055805}
......@@ -5897,7 +5897,7 @@ static IrInstSrc *astgen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node)
58975897 return ag->codegen->invalid_inst_src;
58985898
58995899 if (result_loc_cast != nullptr) {
5900 IrInstSrc *implicit_cast = ir_build_implicit_cast(ag, scope, init_value->base.source_node,
5900 IrInstSrc *implicit_cast = ir_build_implicit_cast(ag, scope, init_value->source_node,
59015901 init_value, result_loc_cast);
59025902 ir_build_end_expr(ag, scope, node, implicit_cast, &result_loc_var->base);
59035903 }
......@@ -8066,13 +8066,13 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *sta
80668066 }
80678067
80688068 if (!instr_is_unreachable(result)) {
8069 ir_build_add_implicit_return_type(ag, scope, result->base.source_node, result, nullptr);
8069 ir_build_add_implicit_return_type(ag, scope, result->source_node, result, nullptr);
80708070 // no need for save_err_ret_addr because this cannot return error
80718071 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
80728072 result_loc_ret->base.id = ResultLocIdReturn;
80738073 ir_build_reset_result(ag, scope, node, &result_loc_ret->base);
80748074 ir_build_end_expr(ag, scope, node, result, &result_loc_ret->base);
8075 ir_build_return_src(ag, scope, result->base.source_node, result);
8075 ir_build_return_src(ag, scope, result->source_node, result);
80768076 }
80778077
80788078 return true;
......@@ -8113,3 +8113,12 @@ void ir_add_call_stack_errors_gen(CodeGen *codegen, Stage1Air *exec, ErrorMsg *e
81138113 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
81148114}
81158115
8116void IrInstSrc::src() {
8117 IrInstSrc *inst = this;
8118 if (inst->source_node != nullptr) {
8119 inst->source_node->src();
8120 } else {
8121 fprintf(stderr, "(null source node)\n");
8122 }
8123}
8124
src/stage1/codegen.cpp+26-26
......@@ -908,14 +908,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
908908
909909static void ir_assert_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line) {
910910 if (ok) return;
911 src_assert_impl(ok, source_instruction->base.source_node, file, line);
911 src_assert_impl(ok, source_instruction->source_node, file, line);
912912}
913913
914914#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
915915
916916static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
917917 // TODO memoize
918 Scope *scope = instruction->base.scope;
918 Scope *scope = instruction->scope;
919919 while (scope) {
920920 if (scope->id == ScopeIdBlock) {
921921 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -951,7 +951,7 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
951951}
952952
953953static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
954 return ir_want_runtime_safety_scope(g, instruction->base.scope);
954 return ir_want_runtime_safety_scope(g, instruction->scope);
955955}
956956
957957static Buf *panic_msg_buf(PanicMsgId msg_id) {
......@@ -1078,7 +1078,7 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
10781078}
10791079
10801080static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1081 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);
1081 return gen_assertion_scope(g, msg_id, source_instruction->scope);
10821082}
10831083
10841084static LLVMValueRef gen_wasm_memory_size(CodeGen *g) {
......@@ -1923,7 +1923,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
19231923 return false;
19241924 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
19251925 ty = arg->value->type;
1926 source_node = arg->base.source_node;
1926 source_node = arg->source_node;
19271927 val = ir_llvm_value(g, arg);
19281928 break;
19291929 }
......@@ -2451,7 +2451,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl
24512451
24522452 LLVMValueRef return_err_fn = get_return_err_fn(g);
24532453 bool is_llvm_alloca;
2454 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.base.scope,
2454 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope,
24552455 &is_llvm_alloca);
24562456 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
24572457 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -2622,7 +2622,7 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
26222622 frame_index_trace_arg(g, ret_type) + 1, "");
26232623 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
26242624 bool is_llvm_alloca;
2625 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
2625 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
26262626 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
26272627 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
26282628 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -3900,7 +3900,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, Stage1Air *executable, IrIns
39003900 codegen_report_errors_and_exit(g);
39013901 if (!ptr_type_has_bits)
39023902 return nullptr;
3903 if (instruction->ptr->base.ref_count == 0) {
3903 if (instruction->ptr->ref_count == 0) {
39043904 // In this case, this StorePtr instruction should be elided. Something happened like this:
39053905 // var t = true;
39063906 // const x = if (t) Num.Two else unreachable;
......@@ -4365,7 +4365,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
43654365 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
43664366 frame_index_trace_arg(g, src_return_type) + 1, "");
43674367 bool is_llvm_alloca;
4368 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope,
4368 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope,
43694369 &is_llvm_alloca);
43704370 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
43714371 }
......@@ -4424,7 +4424,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
44244424 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
44254425
44264426 bool is_llvm_alloca;
4427 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
4427 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
44284428 }
44294429 }
44304430 } else {
......@@ -4433,7 +4433,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
44334433 }
44344434 if (prefix_arg_err_ret_stack) {
44354435 bool is_llvm_alloca;
4436 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
4436 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
44374437 }
44384438 }
44394439 FnWalk fn_walk = {};
......@@ -4567,7 +4567,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
45674567
45684568 LLVMPositionBuilderAtEnd(g->builder, call_bb);
45694569 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4570 render_async_var_decls(g, instruction->base.base.scope);
4570 render_async_var_decls(g, instruction->base.scope);
45714571
45724572 if (!type_has_bits(g, src_return_type))
45734573 return nullptr;
......@@ -4795,7 +4795,7 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
47954795}
47964796
47974797static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, IrInstGenAsm *instruction) {
4798 AstNode *asm_node = instruction->base.base.source_node;
4798 AstNode *asm_node = instruction->base.source_node;
47994799 assert(asm_node->type == NodeTypeAsmExpr);
48004800 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
48014801
......@@ -5463,7 +5463,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, Stage1Air *executab
54635463 IrInstGenErrorReturnTrace *instruction)
54645464{
54655465 bool is_llvm_alloca;
5466 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
5466 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
54675467 if (cur_err_ret_trace_val == nullptr) {
54685468 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
54695469 }
......@@ -5692,7 +5692,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, Stage1Air *executable, IrInstGe
56925692 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
56935693 LLVMValueRef fill_char;
56945694 if (val_is_undef) {
5695 if (ir_want_runtime_safety_scope(g, instruction->base.base.scope)) {
5695 if (ir_want_runtime_safety_scope(g, instruction->base.scope)) {
56965696 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
56975697 } else {
56985698 return nullptr;
......@@ -6179,7 +6179,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, Stage1Air *executab
61796179 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
61806180
61816181 LLVMPositionBuilderAtEnd(g->builder, err_block);
6182 gen_safety_crash_for_err(g, err_val, instruction->base.base.scope);
6182 gen_safety_crash_for_err(g, err_val, instruction->base.scope);
61836183
61846184 LLVMPositionBuilderAtEnd(g->builder, ok_block);
61856185 }
......@@ -6306,7 +6306,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, Stage1Air *executable, IrIns
63066306
63076307static LLVMValueRef ir_render_panic(CodeGen *g, Stage1Air *executable, IrInstGenPanic *instruction) {
63086308 bool is_llvm_alloca;
6309 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
6309 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
63106310 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
63116311 return nullptr;
63126312}
......@@ -6619,7 +6619,7 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, Stage1Air *executable,
66196619 if (ir_want_runtime_safety(g, &instruction->base)) {
66206620 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
66216621 }
6622 render_async_var_decls(g, instruction->base.base.scope);
6622 render_async_var_decls(g, instruction->base.scope);
66236623 return nullptr;
66246624}
66256625
......@@ -6649,7 +6649,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
66496649 frame_index_trace_arg(g, result_type), "");
66506650 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
66516651 bool is_llvm_alloca;
6652 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->base.scope, &is_llvm_alloca);
6652 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca);
66536653 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
66546654 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
66556655 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -6701,7 +6701,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, Stage1Air *executable, IrInstGen
67016701 // supply the error return trace pointer
67026702 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
67036703 bool is_llvm_alloca;
6704 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
6704 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
67056705 assert(my_err_ret_trace_val != nullptr);
67066706 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
67076707 frame_index_trace_arg(g, result_type) + 1, "");
......@@ -6810,8 +6810,8 @@ static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, Stage1Air *executa
68106810}
68116811
68126812static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6813 AstNode *source_node = instruction->base.source_node;
6814 Scope *scope = instruction->base.scope;
6813 AstNode *source_node = instruction->source_node;
6814 Scope *scope = instruction->scope;
68156815
68166816 assert(source_node);
68176817 assert(scope);
......@@ -7020,9 +7020,9 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
70207020 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
70217021 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
70227022 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
7023 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
7023 if (instruction->ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
70247024 continue;
7025 if (get_scope_typeof(instruction->base.scope) != nullptr)
7025 if (get_scope_typeof(instruction->scope) != nullptr)
70267026 continue;
70277027
70287028 if (!g->strip_debug_symbols) {
......@@ -8270,7 +8270,7 @@ static void do_code_gen(CodeGen *g) {
82708270 zig_unreachable();
82718271 if (!type_has_bits(g, child_type))
82728272 continue;
8273 if (instruction->base.base.ref_count == 0)
8273 if (instruction->base.ref_count == 0)
82748274 continue;
82758275 if (instruction->base.value->special != ConstValSpecialRuntime) {
82768276 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -8448,7 +8448,7 @@ static void do_code_gen(CodeGen *g) {
84488448
84498449 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
84508450 }
8451 render_async_var_decls(g, entry_block->instruction_list.at(0)->base.scope);
8451 render_async_var_decls(g, entry_block->instruction_list.at(0)->scope);
84528452 } else {
84538453 // create debug variable declarations for parameters
84548454 // rely on the first variables in the variable_list being parameters.
src/stage1/ir.cpp+1893-1841
......@@ -50,6 +50,7 @@ struct IrAnalyze {
5050 size_t *backward_branch_count;
5151 size_t *backward_branch_quota;
5252 ZigFn *fn;
53 IrInstSrc *suspend_source_instr;
5354
5455 // For the purpose of using in a debugger
5556 void dump();
......@@ -216,15 +217,14 @@ struct DbgIrBreakPoint {
216217};
217218
218219static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
219static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
220static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node,
220221 IrInstGen *value, ZigType *expected_type);
221static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,
222static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr,
222223 ResultLoc *result_loc);
223224static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
224 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
225 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src,
225226 ZigType *container_type, bool initializing);
226static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line);
227static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
227static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var);
228228static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
229229static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
230230static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const);
......@@ -233,53 +233,51 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
233233static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
234234static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
235235 ZigValue *out_val, ZigValue *ptr_val);
236static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
237 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on,
238 bool keep_bigger_alignment);
236static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
237 IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src,
238 bool safety_check_on, bool keep_bigger_alignment);
239239static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
240240static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
241static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
241static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
242242 ZigType *ptr_type);
243static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
243static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
244244 ZigType *dest_type);
245static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
245static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
246246 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
247static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
247static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
248248 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
249static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
249static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
250250 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
251static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
251static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
252252 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
253static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
253static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
254254 IrInstGen *base_ptr, bool initializing);
255static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
255static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
256256 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
257257static void ir_reset_result(ResultLoc *result_loc);
258static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
258static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
259259 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
260260static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
261 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
262static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
263static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
264static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty);
265static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
261 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type);
262static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value);
263static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode *source_node);
264static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty);
265static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node,
266266 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
267267 IrInstGen *result_loc);
268static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
268static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
269269 IrInstGen *struct_operand, TypeStructField *field);
270270static bool value_cmp_numeric_val_any(ZigValue *left, Cmp predicate, ZigValue *right);
271271static bool value_cmp_numeric_val_all(ZigValue *left, Cmp predicate, ZigValue *right);
272272static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field);
273273static void value_to_bigfloat(BigFloat *out, ZigValue *val);
274274
275static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) {
275static void ir_assert_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) {
276276 if (ok) return;
277277 src_assert_impl(ok, source_instruction->source_node, file, line);
278278}
279279
280
281280#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
282#define ir_assert_gen(OK, SOURCE_INSTRUCTION) ir_assert_gen_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
283281
284282void destroy_instruction_gen(IrInstGen *inst) {
285283 switch (inst->id) {
......@@ -498,7 +496,7 @@ static void ira_deref(IrAnalyze *ira) {
498496 // destroy dangling IrInstGenConst
499497 for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) {
500498 auto constant = ira->new_irb.constants.items[i];
501 if (constant->base.base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base))
499 if (constant->base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base))
502500 destroy_instruction_gen(&constant->base);
503501 }
504502 ira->new_irb.constants.deinit(&heap::c_allocator);
......@@ -692,7 +690,7 @@ static bool instr_is_comptime(IrInstGen *instruction) {
692690
693691static void ir_ref_inst_gen(IrInstGen *instruction) {
694692 assert(instruction->id != IrInstGenIdInvalid);
695 instruction->base.ref_count += 1;
693 instruction->ref_count += 1;
696694}
697695
698696static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
......@@ -1108,9 +1106,9 @@ template<typename T>
11081106static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
11091107 T *special_instruction = heap::c_allocator.create<T>();
11101108 special_instruction->base.id = ir_inst_id(special_instruction);
1111 special_instruction->base.base.scope = scope;
1112 special_instruction->base.base.source_node = source_node;
1113 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1109 special_instruction->base.scope = scope;
1110 special_instruction->base.source_node = source_node;
1111 special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec);
11141112 special_instruction->base.owner_bb = irb->current_basic_block;
11151113 special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>();
11161114 return special_instruction;
......@@ -1120,9 +1118,9 @@ template<typename T>
11201118static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
11211119 T *special_instruction = heap::c_allocator.create<T>();
11221120 special_instruction->base.id = ir_inst_id(special_instruction);
1123 special_instruction->base.base.scope = scope;
1124 special_instruction->base.base.source_node = source_node;
1125 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1121 special_instruction->base.scope = scope;
1122 special_instruction->base.source_node = source_node;
1123 special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec);
11261124 special_instruction->base.owner_bb = irb->current_basic_block;
11271125 return special_instruction;
11281126}
......@@ -1155,20 +1153,20 @@ IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigF
11551153{
11561154 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
11571155 alloca_gen->base.id = IrInstGenIdAlloca;
1158 alloca_gen->base.base.source_node = source_node;
1159 alloca_gen->base.base.scope = scope;
1156 alloca_gen->base.source_node = source_node;
1157 alloca_gen->base.scope = scope;
11601158 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
11611159 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
1162 alloca_gen->base.base.ref_count = 1;
1160 alloca_gen->base.ref_count = 1;
11631161 alloca_gen->name_hint = name_hint;
11641162 fn->alloca_gen_list.append(alloca_gen);
11651163 return &alloca_gen->base;
11661164}
11671165
1168static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type,
1169 IrInstGen *value, CastOp cast_op)
1166static IrInstGen *ir_build_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1167 ZigType *dest_type, IrInstGen *value, CastOp cast_op)
11701168{
1171 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1169 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, scope, source_node);
11721170 inst->base.value->type = dest_type;
11731171 inst->value = value;
11741172 inst->cast_op = cast_op;
......@@ -1178,10 +1176,10 @@ static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *de
11781176 return &inst->base;
11791177}
11801178
1181static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,
1179static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *condition,
11821180 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
11831181{
1184 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1182 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, scope, source_node);
11851183 inst->condition = condition;
11861184 inst->then_block = then_block;
11871185 inst->else_block = else_block;
......@@ -1191,9 +1189,8 @@ static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrI
11911189 return &inst->base;
11921190}
11931191
1194static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) {
1195 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb,
1196 source_inst->scope, source_inst->source_node);
1192static IrInstGen *ir_build_return_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand) {
1193 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, scope, source_node);
11971194 inst->operand = operand;
11981195
11991196 if (operand != nullptr) ir_ref_inst_gen(operand);
......@@ -1201,11 +1198,11 @@ static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrIns
12011198 return &inst->base;
12021199}
12031200
1204static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,
1201static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *res_type,
12051202 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
12061203{
12071204 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
1208 source_instr->scope, source_instr->source_node);
1205 scope, source_node);
12091206 inst->base.value->type = res_type;
12101207 inst->op_id = op_id;
12111208 inst->op1 = op1;
......@@ -1219,8 +1216,8 @@ static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigT
12191216}
12201217
12211218
1222static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
1223 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1219static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) {
1220 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, scope, source_node);
12241221 instruction->var = var;
12251222
12261223 var->ref_count += 1;
......@@ -1249,10 +1246,10 @@ static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *s
12491246 return &instruction->base;
12501247}
12511248
1252static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1249static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12531250 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
12541251{
1255 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1252 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, scope, source_node);
12561253 inst->base.value->type = ptr_type;
12571254 inst->struct_ptr = struct_ptr;
12581255 inst->field = field;
......@@ -1262,11 +1259,11 @@ static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr
12621259 return &inst->base;
12631260}
12641261
1265static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1262static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12661263 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
12671264{
12681265 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
1269 source_instr->scope, source_instr->source_node);
1266 scope, source_node);
12701267 inst->base.value->type = ptr_type;
12711268 inst->initializing = initializing;
12721269 inst->safety_check_on = safety_check_on;
......@@ -1278,13 +1275,13 @@ static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
12781275 return &inst->base;
12791276}
12801277
1281static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,
1278static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12821279 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
12831280 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
12841281 IrInstGen *result_loc, ZigType *return_type)
12851282{
12861283 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
1287 source_instruction->scope, source_instruction->source_node);
1284 scope, source_node);
12881285 call_instruction->base.value->type = return_type;
12891286 call_instruction->fn_entry = fn_entry;
12901287 call_instruction->fn_ref = fn_ref;
......@@ -1304,14 +1301,14 @@ static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instructi
13041301 return call_instruction;
13051302}
13061303
1307static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,
1304static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, size_t incoming_count,
13081305 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)
13091306{
13101307 assert(incoming_count != 0);
13111308 assert(incoming_count != SIZE_MAX);
13121309
13131310 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,
1314 source_instr->scope, source_instr->source_node);
1311 scope, source_node);
13151312 phi_instruction->base.value->type = result_type;
13161313 phi_instruction->incoming_count = incoming_count;
13171314 phi_instruction->incoming_blocks = incoming_blocks;
......@@ -1324,16 +1321,16 @@ static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t
13241321 return &phi_instruction->base;
13251322}
13261323
1327static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {
1328 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1324static IrInstGen *ir_build_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrBasicBlockGen *dest_block) {
1325 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, scope, source_node);
13291326 inst->dest_block = dest_block;
13301327
13311328 return &inst->base;
13321329}
13331330
1334static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type, bool wrapping) {
1331static IrInstGen *ir_build_negation(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, ZigType *expr_type, bool wrapping) {
13351332 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
1336 source_instr->scope, source_instr->source_node);
1333 scope, source_node);
13371334 instruction->base.value->type = expr_type;
13381335 instruction->operand = operand;
13391336 instruction->wrapping = wrapping;
......@@ -1343,11 +1340,11 @@ static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInst
13431340 return &instruction->base;
13441341}
13451342
1346static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
1343static IrInstGen *ir_build_binary_not(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
13471344 ZigType *expr_type)
13481345{
13491346 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,
1350 source_instr->scope, source_instr->source_node);
1347 scope, source_node);
13511348 instruction->base.value->type = expr_type;
13521349 instruction->operand = operand;
13531350
......@@ -1356,14 +1353,14 @@ static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrIn
13561353 return &instruction->base;
13571354}
13581355
1359static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) {
1360 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1356static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1357 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, scope, source_node);
13611358 return &inst->base;
13621359}
13631360
1364static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {
1361static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr, IrInstGen *value) {
13651362 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,
1366 source_instr->scope, source_instr->source_node);
1363 scope, source_node);
13671364 instruction->ptr = ptr;
13681365 instruction->value = value;
13691366
......@@ -1373,11 +1370,11 @@ static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, I
13731370 return &instruction->base;
13741371}
13751372
1376static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
1373static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node,
13771374 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)
13781375{
13791376 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
1380 &ira->new_irb, src_inst->scope, src_inst->source_node);
1377 &ira->new_irb, scope, source_node);
13811378 inst->vector_ptr = vector_ptr;
13821379 inst->index = index;
13831380 inst->value = value;
......@@ -1389,11 +1386,11 @@ static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
13891386 return &inst->base;
13901387}
13911388
1392static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,
1389static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
13931390 ZigVar *var, IrInstGen *var_ptr)
13941391{
13951392 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
1396 source_instruction->scope, source_instruction->source_node);
1393 scope, source_node);
13971394 inst->base.value->special = ConstValSpecialStatic;
13981395 inst->base.value->type = ira->codegen->builtin_types.entry_void;
13991396 inst->var = var;
......@@ -1404,11 +1401,11 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi
14041401 return &inst->base;
14051402}
14061403
1407static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf *name,
1404static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, Buf *name,
14081405 GlobalLinkageId linkage, bool is_thread_local, ZigType *expr_type)
14091406{
14101407 IrInstGenExtern *instruction = ir_build_inst_gen<IrInstGenExtern>(&ira->new_irb,
1411 source_instr->scope, source_instr->source_node);
1408 scope, source_node);
14121409 instruction->base.value->type = expr_type;
14131410 instruction->name = name;
14141411 instruction->linkage = linkage;
......@@ -1417,11 +1414,11 @@ static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf
14171414 return &instruction->base;
14181415}
14191416
1420static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,
1417static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
14211418 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)
14221419{
14231420 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(
1424 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1421 &ira->new_irb, scope, source_node);
14251422 instruction->base.value->type = ty;
14261423 instruction->ptr = ptr;
14271424 instruction->result_loc = result_loc;
......@@ -1432,12 +1429,12 @@ static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instructi
14321429 return &instruction->base;
14331430}
14341431
1435static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
1432static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
14361433 Buf *asm_template, AsmToken *token_list, size_t token_list_len,
14371434 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
14381435 bool has_side_effects, ZigType *return_type)
14391436{
1440 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1437 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, scope, source_node);
14411438 instruction->base.value->type = return_type;
14421439 instruction->asm_template = asm_template;
14431440 instruction->token_list = token_list;
......@@ -1448,13 +1445,13 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
14481445 instruction->return_count = return_count;
14491446 instruction->has_side_effects = has_side_effects;
14501447
1451 assert(source_instr->source_node->type == NodeTypeAsmExpr);
1452 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {
1448 assert(source_node->type == NodeTypeAsmExpr);
1449 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
14531450 IrInstGen *output_type = output_types[i];
14541451 if (output_type) ir_ref_inst_gen(output_type);
14551452 }
14561453
1457 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {
1454 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
14581455 IrInstGen *input_value = input_list[i];
14591456 ir_ref_inst_gen(input_value);
14601457 }
......@@ -1462,9 +1459,9 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
14621459 return &instruction->base;
14631460}
14641461
1465static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
1462static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
14661463 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,
1467 source_instr->scope, source_instr->source_node);
1464 scope, source_node);
14681465 inst->base.value->type = ira->codegen->builtin_types.entry_bool;
14691466 inst->value = value;
14701467
......@@ -1473,11 +1470,11 @@ static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_inst
14731470 return &inst->base;
14741471}
14751472
1476static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
1473static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
14771474 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
14781475{
14791476 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,
1480 source_instr->scope, source_instr->source_node);
1477 scope, source_node);
14811478 inst->base.value->type = result_type;
14821479 inst->base_ptr = base_ptr;
14831480 inst->safety_check_on = safety_check_on;
......@@ -1488,11 +1485,11 @@ static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *sourc
14881485 return &inst->base;
14891486}
14901487
1491static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty,
1488static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_ty,
14921489 IrInstGen *operand, IrInstGen *result_loc)
14931490{
14941491 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(
1495 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1492 &ira->new_irb, scope, source_node);
14961493 instruction->base.value->type = result_ty;
14971494 instruction->operand = operand;
14981495 instruction->result_loc = result_loc;
......@@ -1503,11 +1500,11 @@ static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruct
15031500 return &instruction->base;
15041501}
15051502
1506static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,
1503static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
15071504 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
15081505{
15091506 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
1510 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1507 &ira->new_irb, scope, source_node);
15111508 instruction->base.value->type = result_type;
15121509 instruction->operand = operand;
15131510 instruction->result_loc = result_loc;
......@@ -1518,11 +1515,11 @@ static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instr
15181515 return &instruction->base;
15191516}
15201517
1521static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,
1518static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
15221519 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
15231520{
15241521 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
1525 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1522 &ira->new_irb, scope, source_node);
15261523 instruction->base.value->type = result_type;
15271524 instruction->operand = operand;
15281525 instruction->result_loc = result_loc;
......@@ -1533,9 +1530,9 @@ static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruct
15331530 return &instruction->base;
15341531}
15351532
1536static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
1533static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) {
15371534 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,
1538 source_instr->scope, source_instr->source_node);
1535 scope, source_node);
15391536 instruction->base.value->type = result_type;
15401537 instruction->op = op;
15411538
......@@ -1544,9 +1541,9 @@ static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType
15441541 return &instruction->base;
15451542}
15461543
1547static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
1544static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) {
15481545 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,
1549 source_instr->scope, source_instr->source_node);
1546 scope, source_node);
15501547 instruction->base.value->type = result_type;
15511548 instruction->op = op;
15521549
......@@ -1555,11 +1552,11 @@ static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType
15551552 return &instruction->base;
15561553}
15571554
1558static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,
1555static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
15591556 IrInstGen *op)
15601557{
15611558 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,
1562 source_instr->scope, source_instr->source_node);
1559 scope, source_node);
15631560 instruction->base.value->type = result_type;
15641561 instruction->op = op;
15651562
......@@ -1568,11 +1565,11 @@ static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, Z
15681565 return &instruction->base;
15691566}
15701567
1571static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,
1568static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *op_type,
15721569 IrInstGen *op)
15731570{
15741571 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,
1575 source_instr->scope, source_instr->source_node);
1572 scope, source_node);
15761573 instruction->base.value->type = op_type;
15771574 instruction->op = op;
15781575
......@@ -1581,11 +1578,11 @@ static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigTy
15811578 return &instruction->base;
15821579}
15831580
1584static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,
1581static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *int_type,
15851582 IrInstGen *op)
15861583{
15871584 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
1588 source_instr->scope, source_instr->source_node);
1585 scope, source_node);
15891586 instruction->base.value->type = int_type;
15901587 instruction->op = op;
15911588
......@@ -1594,11 +1591,11 @@ static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr,
15941591 return &instruction->base;
15951592}
15961593
1597static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,
1594static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
15981595 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
15991596{
16001597 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,
1601 source_instr->scope, source_instr->source_node);
1598 scope, source_node);
16021599 instruction->target_value = target_value;
16031600 instruction->else_block = else_block;
16041601 instruction->case_count = case_count;
......@@ -1613,11 +1610,11 @@ static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_
16131610 return instruction;
16141611}
16151612
1616static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
1613static IrInstGen *ir_build_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
16171614 ZigType *tag_type)
16181615{
16191616 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
1620 source_instr->scope, source_instr->source_node);
1617 scope, source_node);
16211618 instruction->value = value;
16221619 instruction->base.value->type = tag_type;
16231620
......@@ -1626,11 +1623,11 @@ static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrIns
16261623 return &instruction->base;
16271624}
16281625
1629static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
1626static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
16301627 IrInstGen *operand, IrInstGen *result_loc)
16311628{
16321629 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
1633 source_instruction->scope, source_instruction->source_node);
1630 scope, source_node);
16341631 instruction->base.value->type = result_type;
16351632 instruction->operand = operand;
16361633 instruction->result_loc = result_loc;
......@@ -1641,11 +1638,11 @@ static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, Z
16411638 return &instruction->base;
16421639}
16431640
1644static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
1641static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
16451642 ZigType *str_type)
16461643{
16471644 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,
1648 source_instr->scope, source_instr->source_node);
1645 scope, source_node);
16491646 instruction->base.value->type = str_type;
16501647 instruction->value = value;
16511648
......@@ -1654,12 +1651,12 @@ static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
16541651 return &instruction->base;
16551652}
16561653
1657static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
1654static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
16581655 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
16591656 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
16601657{
16611658 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
1662 source_instruction->scope, source_instruction->source_node);
1659 scope, source_node);
16631660 instruction->base.value->type = result_type;
16641661 instruction->ptr = ptr;
16651662 instruction->cmp_value = cmp_value;
......@@ -1677,17 +1674,17 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio
16771674 return &instruction->base;
16781675}
16791676
1680static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) {
1677static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, AtomicOrder order) {
16811678 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,
1682 source_instr->scope, source_instr->source_node);
1679 scope, source_node);
16831680 instruction->order = order;
16841681
16851682 return &instruction->base;
16861683}
16871684
1688static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, IrInst *source_instruction, ReduceOp op, IrInstGen *value, ZigType *result_type) {
1685static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, IrInstGen *value, ZigType *result_type) {
16891686 IrInstGenReduce *instruction = ir_build_inst_gen<IrInstGenReduce>(&ira->new_irb,
1690 source_instruction->scope, source_instruction->source_node);
1687 scope, source_node);
16911688 instruction->base.value->type = result_type;
16921689 instruction->op = op;
16931690 instruction->value = value;
......@@ -1713,23 +1710,23 @@ static void ir_set_cursor_at_end_and_append_block_gen(IrBuilderGen *irb, IrBasic
17131710 ir_set_cursor_at_end_gen(irb, basic_block);
17141711}
17151712
1716static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) {
1713static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
17171714 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,
1718 source_instr->scope, source_instr->source_node);
1715 scope, source_node);
17191716 return &inst->base;
17201717}
17211718
1722static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) {
1719static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
17231720 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,
1724 source_instr->scope, source_instr->source_node);
1721 scope, source_node);
17251722 return &inst->base;
17261723}
17271724
1728static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,
1725static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_type,
17291726 IrInstGen *target)
17301727{
17311728 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,
1732 source_instr->scope, source_instr->source_node);
1729 scope, source_node);
17331730 instruction->base.value->type = dest_type;
17341731 instruction->target = target;
17351732
......@@ -1754,11 +1751,11 @@ static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstN
17541751 return &inst->base;
17551752}
17561753
1757static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
1754static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
17581755 IrInstGen *scalar)
17591756{
17601757 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(
1761 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1758 &ira->new_irb, scope, source_node);
17621759 instruction->base.value->type = result_type;
17631760 instruction->scalar = scalar;
17641761
......@@ -1767,9 +1764,9 @@ static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction,
17671764 return &instruction->base;
17681765}
17691766
1770static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
1767static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
17711768 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,
1772 source_instr->scope, source_instr->source_node);
1769 scope, source_node);
17731770 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
17741771 instruction->value = value;
17751772
......@@ -1778,11 +1775,11 @@ static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, Ir
17781775 return &instruction->base;
17791776}
17801777
1781static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
1778static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
17821779 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)
17831780{
17841781 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,
1785 source_instr->scope, source_instr->source_node);
1782 scope, source_node);
17861783 instruction->dest_ptr = dest_ptr;
17871784 instruction->byte = byte;
17881785 instruction->count = count;
......@@ -1794,11 +1791,11 @@ static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
17941791 return &instruction->base;
17951792}
17961793
1797static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
1794static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
17981795 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)
17991796{
18001797 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,
1801 source_instr->scope, source_instr->source_node);
1798 scope, source_node);
18021799 instruction->dest_ptr = dest_ptr;
18031800 instruction->src_ptr = src_ptr;
18041801 instruction->count = count;
......@@ -1810,12 +1807,12 @@ static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
18101807 return &instruction->base;
18111808}
18121809
1813static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,
1810static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *slice_type,
18141811 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc,
18151812 ZigValue *sentinel)
18161813{
18171814 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
1818 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1815 &ira->new_irb, scope, source_node);
18191816 instruction->base.value->type = slice_type;
18201817 instruction->ptr = ptr;
18211818 instruction->start = start;
......@@ -1832,33 +1829,33 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
18321829 return &instruction->base;
18331830}
18341831
1835static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {
1832static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
18361833 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
1837 source_instr->scope, source_instr->source_node);
1834 scope, source_node);
18381835 return &instruction->base;
18391836}
18401837
1841static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {
1842 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1838static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1839 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, scope, source_node);
18431840 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
18441841 return &inst->base;
18451842}
18461843
1847static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) {
1848 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1844static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1845 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, scope, source_node);
18491846 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
18501847 return &inst->base;
18511848}
18521849
1853static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) {
1854 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1850static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
1851 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, scope, source_node);
18551852 inst->base.value->type = ty;
18561853 return &inst->base;
18571854}
18581855
1859static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn)
1856static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *fn)
18601857{
1861 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1858 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, scope, source_node);
18621859 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
18631860 inst->fn = fn;
18641861
......@@ -1867,12 +1864,12 @@ static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr,
18671864 return &inst->base;
18681865}
18691866
1870static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
1867static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
18711868 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,
18721869 ZigType *result_ptr_type)
18731870{
18741871 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,
1875 source_instr->scope, source_instr->source_node);
1872 scope, source_node);
18761873 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
18771874 instruction->op = op;
18781875 instruction->op1 = op1;
......@@ -1887,11 +1884,11 @@ static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
18871884 return &instruction->base;
18881885}
18891886
1890static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
1887static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
18911888 BuiltinFnId fn_id, ZigType *operand_type)
18921889{
18931890 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,
1894 source_instr->scope, source_instr->source_node);
1891 scope, source_node);
18951892 instruction->base.value->type = operand_type;
18961893 instruction->operand = operand;
18971894 instruction->fn_id = fn_id;
......@@ -1901,11 +1898,11 @@ static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, Ir
19011898 return &instruction->base;
19021899}
19031900
1904static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
1901static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2,
19051902 IrInstGen *op3, ZigType *expr_type)
19061903{
19071904 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,
1908 source_instr->scope, source_instr->source_node);
1905 scope, source_node);
19091906 instruction->base.value->type = expr_type;
19101907 instruction->op1 = op1;
19111908 instruction->op2 = op2;
......@@ -1918,9 +1915,9 @@ static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrI
19181915 return &instruction->base;
19191916}
19201917
1921static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {
1918static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *err_union) {
19221919 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
1923 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1920 &ira->new_irb, scope, source_node);
19241921 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
19251922 instruction->err_union = err_union;
19261923
......@@ -1955,11 +1952,11 @@ static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope,
19551952 return &inst->base;
19561953}
19571954
1958static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
1955static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
19591956 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
19601957{
19611958 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
1962 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1959 &ira->new_irb, scope, source_node);
19631960 instruction->base.value->type = ptr_type;
19641961 instruction->ptr = ptr;
19651962 instruction->safety_check_on = safety_check_on;
......@@ -1969,11 +1966,11 @@ static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instructi
19691966 return &instruction->base;
19701967}
19711968
1972static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
1969static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
19731970 IrInstGen *operand, ZigType *ty)
19741971{
19751972 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
1976 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
1973 &ira->new_irb, scope, source_node);
19771974 instruction->base.value->type = ty;
19781975 instruction->operand = operand;
19791976
......@@ -2006,8 +2003,8 @@ static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode
20062003 return &instruction->base;
20072004}
20082005
2009static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
2010 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2006static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) {
2007 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, scope, source_node);
20112008 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
20122009 inst->target = target;
20132010
......@@ -2052,9 +2049,9 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode
20522049 return &instruction->base;
20532050}
20542051
2055static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) {
2052static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *msg) {
20562053 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,
2057 source_instr->scope, source_instr->source_node);
2054 scope, source_node);
20582055 instruction->msg = msg;
20592056
20602057 ir_ref_inst_gen(msg);
......@@ -2062,11 +2059,11 @@ static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrIns
20622059 return &instruction->base;
20632060}
20642061
2065static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,
2062static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
20662063 ZigType *result_type)
20672064{
20682065 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,
2069 source_instr->scope, source_instr->source_node);
2066 scope, source_node);
20702067 instruction->base.value->type = result_type;
20712068 instruction->target = target;
20722069
......@@ -2075,11 +2072,11 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
20752072 return &instruction->base;
20762073}
20772074
2078static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
2075static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
20792076 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)
20802077{
20812078 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,
2082 source_instr->scope, source_instr->source_node);
2079 scope, source_node);
20832080 inst->base.value->type = result_type;
20842081 inst->field_ptr = field_ptr;
20852082 inst->field = field;
......@@ -2111,10 +2108,10 @@ static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope,
21112108 return &inst->base;
21122109}
21132110
2114static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
2111static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21152112 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)
21162113{
2117 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2114 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, scope, source_node);
21182115 instruction->base.value->type = operand_type;
21192116 instruction->ptr = ptr;
21202117 instruction->op = op;
......@@ -2127,11 +2124,11 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
21272124 return &instruction->base;
21282125}
21292126
2130static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
2127static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21312128 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)
21322129{
21332130 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,
2134 source_instr->scope, source_instr->source_node);
2131 scope, source_node);
21352132 instruction->base.value->type = operand_type;
21362133 instruction->ptr = ptr;
21372134 instruction->ordering = ordering;
......@@ -2141,11 +2138,11 @@ static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
21412138 return &instruction->base;
21422139}
21432140
2144static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,
2141static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21452142 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)
21462143{
21472144 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,
2148 source_instr->scope, source_instr->source_node);
2145 scope, source_node);
21492146 instruction->ptr = ptr;
21502147 instruction->value = value;
21512148 instruction->ordering = ordering;
......@@ -2157,11 +2154,11 @@ static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr
21572154}
21582155
21592156
2160static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,
2157static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21612158 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
21622159{
21632160 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
2164 source_instruction->scope, source_instruction->source_node);
2161 scope, source_node);
21652162 instruction->base.value->type = result_type;
21662163 instruction->vector = vector;
21672164 instruction->result_loc = result_loc;
......@@ -2172,11 +2169,11 @@ static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instru
21722169 return &instruction->base;
21732170}
21742171
2175static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,
2172static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21762173 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
21772174{
21782175 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
2179 source_instruction->scope, source_instruction->source_node);
2176 scope, source_node);
21802177 instruction->base.value->type = result_type;
21812178 instruction->operand = operand;
21822179 instruction->result_loc = result_loc;
......@@ -2187,11 +2184,11 @@ static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_
21872184 return &instruction->base;
21882185}
21892186
2190static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,
2187static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21912188 IrInstGen *array, ZigType *result_type)
21922189{
21932190 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
2194 source_instruction->scope, source_instruction->source_node);
2191 scope, source_node);
21952192 instruction->base.value->type = result_type;
21962193 instruction->array = array;
21972194
......@@ -2200,11 +2197,11 @@ static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instru
22002197 return &instruction->base;
22012198}
22022199
2203static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,
2200static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22042201 IrInstGen *target)
22052202{
22062203 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
2207 source_instruction->scope, source_instruction->source_node);
2204 scope, source_node);
22082205 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
22092206 instruction->target = target;
22102207
......@@ -2213,11 +2210,11 @@ static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instructio
22132210 return &instruction->base;
22142211}
22152212
2216static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,
2213static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22172214 IrInstGen *target)
22182215{
22192216 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
2220 source_instruction->scope, source_instruction->source_node);
2217 scope, source_node);
22212218 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
22222219 instruction->target = target;
22232220
......@@ -2226,20 +2223,20 @@ static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instru
22262223 return &instruction->base;
22272224}
22282225
2229static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,
2226static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22302227 uint32_t align, const char *name_hint)
22312228{
22322229 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
2233 source_instruction->scope, source_instruction->source_node);
2230 scope, source_node);
22342231 instruction->align = align;
22352232 instruction->name_hint = name_hint;
22362233
22372234 return instruction;
22382235}
22392236
2240static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) {
2237static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSuspendBegin *begin) {
22412238 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,
2242 source_instr->scope, source_instr->source_node);
2239 scope, source_node);
22432240 inst->begin = begin;
22442241
22452242 ir_ref_inst_gen(&begin->base);
......@@ -2247,11 +2244,11 @@ static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_ins
22472244 return &inst->base;
22482245}
22492246
2250static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
2247static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22512248 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc, bool is_nosuspend)
22522249{
22532250 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
2254 source_instruction->scope, source_instruction->source_node);
2251 scope, source_node);
22552252 instruction->base.value->type = result_type;
22562253 instruction->frame = frame;
22572254 instruction->result_loc = result_loc;
......@@ -2263,9 +2260,9 @@ static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruc
22632260 return instruction;
22642261}
22652262
2266static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {
2263static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *frame) {
22672264 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,
2268 source_instr->scope, source_instr->source_node);
2265 scope, source_node);
22692266 instruction->frame = frame;
22702267
22712268 ir_ref_inst_gen(frame);
......@@ -2273,11 +2270,11 @@ static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrIn
22732270 return &instruction->base;
22742271}
22752272
2276static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2273static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
22772274 SpillId spill_id)
22782275{
22792276 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,
2280 source_instr->scope, source_instr->source_node);
2277 scope, source_node);
22812278 instruction->operand = operand;
22822279 instruction->spill_id = spill_id;
22832280
......@@ -2286,11 +2283,11 @@ static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr,
22862283 return &instruction->base;
22872284}
22882285
2289static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,
2286static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSpillBegin *begin,
22902287 ZigType *result_type)
22912288{
22922289 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,
2293 source_instr->scope, source_instr->source_node);
2290 scope, source_node);
22942291 instruction->base.value->type = result_type;
22952292 instruction->begin = begin;
22962293
......@@ -2299,11 +2296,11 @@ static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, I
22992296 return &instruction->base;
23002297}
23012298
2302static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction,
2299static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node,
23032300 IrInstGen *vector, IrInstGen *index)
23042301{
23052302 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
2306 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2303 &ira->new_irb, scope, source_node);
23072304 instruction->base.value->type = vector->value->type->data.vector.elem_type;
23082305 instruction->vector = vector;
23092306 instruction->index = index;
......@@ -2314,9 +2311,9 @@ static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_in
23142311 return &instruction->base;
23152312}
23162313
2317static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index) {
2314static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index) {
23182315 IrInstGenWasmMemorySize *instruction = ir_build_inst_gen<IrInstGenWasmMemorySize>(&ira->new_irb,
2319 source_instr->scope, source_instr->source_node);
2316 scope, source_node);
23202317 instruction->base.value->type = ira->codegen->builtin_types.entry_u32;
23212318 instruction->index = index;
23222319
......@@ -2325,9 +2322,9 @@ static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_i
23252322 return &instruction->base;
23262323}
23272324
2328static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index, IrInstGen *delta) {
2325static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index, IrInstGen *delta) {
23292326 IrInstGenWasmMemoryGrow *instruction = ir_build_inst_gen<IrInstGenWasmMemoryGrow>(&ira->new_irb,
2330 source_instr->scope, source_instr->source_node);
2327 scope, source_node);
23312328 instruction->base.value->type = ira->codegen->builtin_types.entry_i32;
23322329 instruction->index = index;
23332330 instruction->delta = delta;
......@@ -2551,15 +2548,10 @@ static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode
25512548 return add_node_error(codegen, source_node, msg);
25522549}
25532550
2554static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) {
2551static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstGen *source_instruction, Buf *msg) {
25552552 return ir_add_error_node(ira, source_instruction->source_node, msg);
25562553}
25572554
2558static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) {
2559 if (ok) return;
2560 src_assert_impl(ok, source_instruction->base.source_node, file, line);
2561}
2562
25632555// This function takes a comptime ptr and makes the child const value conform to the type
25642556// described by the pointer.
25652557static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
......@@ -2622,11 +2614,11 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
26222614 break;
26232615 }
26242616 }
2625 if (get_scope_typeof(instruction->base.scope) != nullptr) {
2617 if (get_scope_typeof(instruction->scope) != nullptr) {
26262618 // doesn't count, it's inside a @TypeOf()
26272619 continue;
26282620 }
2629 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,
2621 exec_add_error_node_gen(codegen, exec, instruction->source_node,
26302622 buf_sprintf("unable to evaluate constant expression"));
26312623 return ErrorSemanticAnalyzeFail;
26322624 }
......@@ -2634,9 +2626,9 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
26342626 zig_unreachable();
26352627}
26362628
2637static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {
2629static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstSrc* source_instruction) {
26382630 if (ir_should_inline(ira->zir, source_instruction->scope)) {
2639 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));
2631 ir_add_error_node(ira, source_instruction->source_node, buf_sprintf("unable to evaluate constant expression"));
26402632 return false;
26412633 }
26422634 return true;
......@@ -3518,7 +3510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
35183510 }
35193511 Buf *val_buf = buf_alloc();
35203512 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3521 ir_add_error_node(ira, instruction->base.source_node,
3513 ir_add_error_node(ira, instruction->source_node,
35223514 buf_sprintf("type %s cannot represent integer value %s",
35233515 buf_ptr(&other_type->name),
35243516 buf_ptr(val_buf)));
......@@ -3613,7 +3605,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
36133605 }
36143606 Buf *val_buf = buf_alloc();
36153607 float_append_buf(val_buf, const_val);
3616 ir_add_error_node(ira, instruction->base.source_node,
3608 ir_add_error_node(ira, instruction->source_node,
36173609 buf_sprintf("cast of value %s to type '%s' loses information",
36183610 buf_ptr(val_buf),
36193611 buf_ptr(&other_type->name)));
......@@ -3622,7 +3614,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
36223614 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
36233615 Buf *val_buf = buf_alloc();
36243616 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3625 ir_add_error_node(ira, instruction->base.source_node,
3617 ir_add_error_node(ira, instruction->source_node,
36263618 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
36273619 buf_ptr(val_buf),
36283620 buf_ptr(&other_type->name)));
......@@ -3643,7 +3635,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
36433635 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
36443636 Buf *val_buf = buf_alloc();
36453637 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3646 ir_add_error_node(ira, instruction->base.source_node,
3638 ir_add_error_node(ira, instruction->source_node,
36473639 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
36483640 buf_ptr(val_buf),
36493641 buf_ptr(&child_type->name)));
......@@ -3666,7 +3658,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
36663658 Buf *val_buf = buf_alloc();
36673659 float_append_buf(val_buf, const_val);
36683660
3669 ir_add_error_node(ira, instruction->base.source_node,
3661 ir_add_error_node(ira, instruction->source_node,
36703662 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
36713663 buf_ptr(val_buf),
36723664 buf_ptr(&other_type->name)));
......@@ -3696,7 +3688,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
36963688 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
36973689 }
36983690
3699 ir_add_error_node(ira, instruction->base.source_node,
3691 ir_add_error_node(ira, instruction->source_node,
37003692 buf_sprintf("%s value %s cannot be coerced to type '%s'",
37013693 num_lit_str,
37023694 buf_ptr(val_buf),
......@@ -4210,7 +4202,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
42104202 size_t errors_count = 0;
42114203 ZigType *err_set_type = nullptr;
42124204 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
4213 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) {
4205 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
42144206 return ira->codegen->builtin_types.entry_invalid;
42154207 }
42164208 if (type_is_global_error_set(prev_inst->value->type)) {
......@@ -4254,14 +4246,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
42544246 }
42554247
42564248 if (prev_type->id == ZigTypeIdErrorSet) {
4257 ir_assert_gen(err_set_type != nullptr, prev_inst);
4249 ir_assert(err_set_type != nullptr, prev_inst);
42584250 if (cur_type->id == ZigTypeIdErrorSet) {
42594251 if (type_is_global_error_set(err_set_type)) {
42604252 continue;
42614253 }
42624254 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
42634255 cur_type->data.error_set.infer_fn == ira->fn;
4264 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
4256 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
42654257 return ira->codegen->builtin_types.entry_invalid;
42664258 }
42674259 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -4329,7 +4321,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
43294321 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
43304322 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
43314323 cur_err_set_type->data.error_set.infer_fn == ira->fn;
4332 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
4324 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
43334325 return ira->codegen->builtin_types.entry_invalid;
43344326 }
43354327 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
......@@ -4384,7 +4376,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
43844376 if (cur_type->id == ZigTypeIdErrorSet) {
43854377 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
43864378 cur_type->data.error_set.infer_fn == ira->fn;
4387 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
4379 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
43884380 return ira->codegen->builtin_types.entry_invalid;
43894381 }
43904382 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -4407,7 +4399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
44074399 err_set_type = cur_type;
44084400 }
44094401
4410 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) {
4402 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) {
44114403 return ira->codegen->builtin_types.entry_invalid;
44124404 }
44134405
......@@ -4470,11 +4462,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
44704462 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
44714463 cur_err_set_type->data.error_set.infer_fn == ira->fn;
44724464
4473 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) {
4465 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
44744466 return ira->codegen->builtin_types.entry_invalid;
44754467 }
44764468
4477 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
4469 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
44784470 return ira->codegen->builtin_types.entry_invalid;
44794471 }
44804472
......@@ -4653,7 +4645,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
46534645 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
46544646 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
46554647 cur_err_set_type->data.error_set.infer_fn == ira->fn;
4656 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
4648 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
46574649 return ira->codegen->builtin_types.entry_invalid;
46584650 }
46594651 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||
......@@ -4890,9 +4882,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
48904882 ErrorMsg *msg = ir_add_error_node(ira, source_node,
48914883 buf_sprintf("incompatible types: '%s' and '%s'",
48924884 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
4893 add_error_note(ira->codegen, msg, prev_inst->base.source_node,
4885 add_error_note(ira->codegen, msg, prev_inst->source_node,
48944886 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));
4895 add_error_note(ira->codegen, msg, cur_inst->base.source_node,
4887 add_error_note(ira->codegen, msg, cur_inst->source_node,
48964888 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
48974889
48984890 return ira->codegen->builtin_types.entry_invalid;
......@@ -4984,7 +4976,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
49844976 }
49854977}
49864978
4987static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
4979static bool eval_const_expr_implicit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
49884980 CastOp cast_op,
49894981 ZigValue *other_val, ZigType *other_type,
49904982 ZigValue *const_val, ZigType *new_type)
......@@ -5069,7 +5061,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
50695061 Buf *int_buf = buf_alloc();
50705062 bigint_append_buf(int_buf, &const_val->data.x_bigint, 10);
50715063
5072 ir_add_error(ira, source_instr,
5064 ir_add_error_node(ira, source_node,
50735065 buf_sprintf("integer value '%s' cannot be stored in type '%s'",
50745066 buf_ptr(int_buf), buf_ptr(&new_type->name)));
50755067 return false;
......@@ -5086,9 +5078,9 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
50865078 return true;
50875079}
50885080
5089static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
5081static IrInstGen *ir_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
50905082 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5091 inst->scope, inst->source_node);
5083 scope, source_node);
50925084 IrInstGen *new_instruction = &const_instruction->base;
50935085 new_instruction->value->type = ty;
50945086 new_instruction->value->special = ConstValSpecialStatic;
......@@ -5096,45 +5088,46 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
50965088 return new_instruction;
50975089}
50985090
5099static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
5091static IrInstGen *ir_const_noval(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
51005092 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
5101 old_instruction->scope, old_instruction->source_node);
5093 scope, source_node);
51025094 ira->new_irb.constants.append(&heap::c_allocator, const_instruction);
51035095 return &const_instruction->base;
51045096}
51055097
51065098// This function initializes the new IrInstGen with the provided ZigValue,
51075099// rather than creating a new one.
5108static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {
5109 IrInstGen *result = ir_const_noval(ira, old_instruction);
5100static IrInstGen *ir_const_move(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) {
5101 IrInstGen *result = ir_const_noval(ira, scope, source_node);
51105102 result->value = val;
51115103 return result;
51125104}
51135105
5114static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
5106static IrInstGen *ir_resolve_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
51155107 ZigType *wanted_type, CastOp cast_op)
51165108{
51175109 if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) {
5118 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5110 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
51195111 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
51205112 if (val == nullptr)
51215113 return ira->codegen->invalid_inst_gen;
51225114
5123 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, val, val->type,
5115 if (!eval_const_expr_implicit_cast(ira, scope, source_node, cast_op, val, val->type,
51245116 result->value, wanted_type))
51255117 {
51265118 return ira->codegen->invalid_inst_gen;
51275119 }
51285120 return result;
51295121 } else {
5130 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);
5122 return ir_build_cast(ira, scope, source_node,
5123 wanted_type, value, cast_op);
51315124 }
51325125}
51335126
5134static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,
5135 IrInstGen *value, ZigType *wanted_type)
5127static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
5128 Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type)
51365129{
5137 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);
5130 src_assert(value->value->type->id == ZigTypeIdPointer, source_node);
51385131
51395132 Error err;
51405133
......@@ -5151,13 +5144,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
51515144 if (val == nullptr)
51525145 return ira->codegen->invalid_inst_gen;
51535146 if (val->special == ConstValSpecialUndef)
5154 return ir_const_undef(ira, source_instr, wanted_type);
5147 return ir_const_undef(ira, scope, source_node, wanted_type);
51555148
5156 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
5149 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node);
51575150 if (pointee == nullptr)
51585151 return ira->codegen->invalid_inst_gen;
51595152 if (pointee->special != ConstValSpecialRuntime) {
5160 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5153 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
51615154 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
51625155 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
51635156 result->value->data.x_ptr.data.base_array.array_val = pointee;
......@@ -5166,10 +5159,11 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
51665159 }
51675160 }
51685161
5169 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
5162 return ir_build_cast(ira, scope, source_node,
5163 wanted_type, value, CastOpBitCast);
51705164}
51715165
5172static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,
5166static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node,
51735167 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
51745168{
51755169 Error err;
......@@ -5189,7 +5183,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
51895183 // undef_array->special = ConstValSpecialUndef;
51905184 // undef_array->type = array_type;
51915185
5192 // IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5186 // IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
51935187 // init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);
51945188 // result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;
51955189 // result->value->type = wanted_type;
......@@ -5210,13 +5204,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
52105204 ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, undef_allowed);
52115205 if (array_ptr_val == nullptr)
52125206 return ira->codegen->invalid_inst_gen;
5213 ir_assert(is_slice(wanted_type), source_instr);
5207 src_assert(is_slice(wanted_type), source_node);
52145208 if (array_ptr_val->special == ConstValSpecialUndef) {
52155209 ZigValue *undef_array = ira->codegen->pass1_arena->create<ZigValue>();
52165210 undef_array->special = ConstValSpecialUndef;
52175211 undef_array->type = array_type;
52185212
5219 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5213 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
52205214 init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);
52215215 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;
52225216 result->value->type = wanted_type;
......@@ -5227,7 +5221,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
52275221 if (array_ptr_val->data.x_ptr.special == ConstPtrSpecialSubArray) {
52285222 ZigValue *array_val = array_ptr_val->data.x_ptr.data.base_array.array_val;
52295223 if (array_val->special != ConstValSpecialRuntime) {
5230 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5224 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
52315225 init_const_slice(ira->codegen, result->value, array_val,
52325226 array_ptr_val->data.x_ptr.data.base_array.elem_index,
52335227 array_type->data.array.len, wanted_const, nullptr);
......@@ -5236,13 +5230,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
52365230 return result;
52375231 }
52385232 } else if (array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
5239 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node);
5233 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_node);
52405234 if (pointee == nullptr)
52415235 return ira->codegen->invalid_inst_gen;
52425236 if (pointee->special != ConstValSpecialRuntime) {
52435237 assert(array_ptr_val->type->id == ZigTypeIdPointer);
52445238
5245 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5239 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
52465240 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, wanted_const, nullptr);
52475241 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
52485242 result->value->type = wanted_type;
......@@ -5252,16 +5246,17 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
52525246 }
52535247
52545248 if (result_loc == nullptr) result_loc = no_result_loc();
5255 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
5249 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr,
5250 result_loc, wanted_type, nullptr, true, true);
52565251 if (type_is_invalid(result_loc_inst->value->type) ||
52575252 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
52585253 {
52595254 return result_loc_inst;
52605255 }
5261 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
5256 return ir_build_ptr_of_array_to_slice(ira, scope, source_node, wanted_type, array_ptr, result_loc_inst);
52625257}
52635258
5264static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) {
5259static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) {
52655260 assert(old_bb);
52665261
52675262 if (old_bb->child) {
......@@ -5276,13 +5271,13 @@ static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_b
52765271 return new_bb;
52775272}
52785273
5279static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) {
5274static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) {
52805275 assert(ref_old_instruction != nullptr);
52815276 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
5282 if (new_bb->must_be_comptime_source_instr) {
5283 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
5277 if (new_bb->must_be_comptime_source_node != nullptr) {
5278 ErrorMsg *msg = ir_add_error_node(ira, ref_old_instruction->source_node,
52845279 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
5285 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
5280 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_node,
52865281 buf_sprintf("compile-time variable assigned here"));
52875282 return nullptr;
52885283 }
......@@ -5290,14 +5285,16 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBloc
52905285}
52915286
52925287static void ir_start_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, Stage1ZirBasicBlock *const_predecessor_bb) {
5293 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);
5288 src_assert(!old_bb->suspended,
5289 (old_bb->instruction_list.length != 0) ?
5290 old_bb->instruction_list.at(0)->source_node : nullptr);
52945291 ira->instruction_index = 0;
52955292 ira->zir_current_basic_block = old_bb;
52965293 ira->const_predecessor_bb = const_predecessor_bb;
52975294 ira->old_bb_index = old_bb->index;
52985295}
52995296
5300static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1ZirBasicBlock *next_bb,
5297static IrInstGen *ira_suspend(IrAnalyze *ira, IrInstSrc *old_instruction, Stage1ZirBasicBlock *next_bb,
53015298 IrSuspendPosition *suspend_pos)
53025299{
53035300 if (ira->codegen->verbose_ir) {
......@@ -5306,7 +5303,7 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1Zir
53065303 ira->zir_current_basic_block->debug_id,
53075304 ira->zir->basic_block_list.at(ira->old_bb_index)->name_hint,
53085305 ira->zir->basic_block_list.at(ira->old_bb_index)->debug_id,
5309 ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id,
5306 ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
53105307 ira->old_bb_index, ira->instruction_index);
53115308 }
53125309 suspend_pos->basic_block_index = ira->old_bb_index;
......@@ -5342,7 +5339,7 @@ static IrInstGen *ira_resume(IrAnalyze *ira) {
53425339 if (ira->codegen->verbose_ir) {
53435340 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->zir_current_basic_block->name_hint,
53445341 ira->zir_current_basic_block->debug_id,
5345 ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id);
5342 ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
53465343 }
53475344 ira->const_predecessor_bb = nullptr;
53485345 ira->new_irb.current_basic_block = ira->zir_current_basic_block->child;
......@@ -5418,7 +5415,7 @@ static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
54185415 return ira->codegen->unreach_instruction;
54195416}
54205417
5421static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
5418static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {
54225419 size_t *bbc = ira->backward_branch_count;
54235420 size_t *quota = ira->backward_branch_quota;
54245421
......@@ -5430,16 +5427,16 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction)
54305427
54315428 *bbc += 1;
54325429 if (*bbc > *quota) {
5433 ir_add_error(ira, source_instruction,
5430 ir_add_error_node(ira, source_node,
54345431 buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));
54355432 return false;
54365433 }
54375434 return true;
54385435}
54395436
5440static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, Stage1ZirBasicBlock *old_bb) {
5437static IrInstGen *ir_inline_bb(IrAnalyze *ira, AstNode* source_node, Stage1ZirBasicBlock *old_bb) {
54415438 if (old_bb->debug_id <= ira->zir_current_basic_block->debug_id) {
5442 if (!ir_emit_backward_branch(ira, source_instruction))
5439 if (!ir_emit_backward_branch(ira, source_node))
54435440 return ir_unreach_error(ira);
54445441 }
54455442
......@@ -5454,8 +5451,8 @@ static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
54545451 return instruction;
54555452}
54565453
5457static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {
5458 IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry);
5454static IrInstGen *ir_const_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
5455 IrInstGen *result = ir_const(ira, scope, source_node, fn_entry->type_entry);
54595456 result->value->special = ConstValSpecialStatic;
54605457 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;
54615458 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
......@@ -5463,62 +5460,62 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en
54635460 return result;
54645461}
54655462
5466static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg,
5467 IrInst *first_arg_src)
5463static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5464 ZigFn *fn_entry, IrInstGen *first_arg, AstNode *first_arg_src)
54685465{
54695466 // This is unfortunately required to avoid improperly freeing first_arg_src
54705467 ira_ref(ira);
54715468
5472 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));
5469 IrInstGen *result = ir_const(ira, scope, source_node, get_bound_fn_type(ira->codegen, fn_entry));
54735470 result->value->data.x_bound_fn.fn = fn_entry;
54745471 result->value->data.x_bound_fn.first_arg = first_arg;
54755472 result->value->data.x_bound_fn.first_arg_src = first_arg_src;
54765473 return result;
54775474}
54785475
5479static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
5480 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
5476static IrInstGen *ir_const_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
5477 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_type);
54815478 result->value->data.x_type = ty;
54825479 return result;
54835480}
54845481
5485static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {
5486 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
5482static IrInstGen *ir_const_bool(IrAnalyze *ira, Scope *scope, AstNode *source_node, bool value) {
5483 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
54875484 result->value->data.x_bool = value;
54885485 return result;
54895486}
54905487
5491static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
5492 IrInstGen *result = ir_const(ira, source_instruction, ty);
5488static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
5489 IrInstGen *result = ir_const(ira, scope, source_node, ty);
54935490 result->value->special = ConstValSpecialUndef;
54945491 return result;
54955492}
54965493
5497static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {
5498 IrInstGen *result = ir_const_noval(ira, source_instruction);
5494static IrInstGen *ir_const_unreachable(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
5495 IrInstGen *result = ir_const_noval(ira, scope, source_node);
54995496 result->value = ira->codegen->intern.for_unreachable();
55005497 return result;
55015498}
55025499
5503static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {
5504 IrInstGen *result = ir_const_noval(ira, source_instruction);
5500static IrInstGen *ir_const_void(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
5501 IrInstGen *result = ir_const_noval(ira, scope, source_node);
55055502 result->value = ira->codegen->intern.for_void();
55065503 return result;
55075504}
55085505
5509static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {
5510 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
5506static IrInstGen *ir_const_unsigned(IrAnalyze *ira, Scope *scope, AstNode *source_node, uint64_t value) {
5507 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_num_lit_int);
55115508 bigint_init_unsigned(&result->value->data.x_bigint, value);
55125509 return result;
55135510}
55145511
5515static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
5512static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
55165513 ZigValue *pointee, ZigType *pointee_type,
55175514 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
55185515{
55195516 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
55205517 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
5521 IrInstGen *const_instr = ir_const(ira, instruction, ptr_type);
5518 IrInstGen *const_instr = ir_const(ira, scope, source_node, ptr_type);
55225519 ZigValue *const_val = const_instr->value;
55235520 const_val->data.x_ptr.special = ConstPtrSpecialRef;
55245521 const_val->data.x_ptr.mut = ptr_mut;
......@@ -5562,7 +5559,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *so
55625559
55635560static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {
55645561 Error err;
5565 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node,
5562 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
55665563 value->value, undef_allowed)))
55675564 {
55685565 return nullptr;
......@@ -5641,7 +5638,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
56415638 return nullptr;
56425639
56435640 if (err_value->value->type->id != ZigTypeIdErrorSet) {
5644 ir_add_error_node(ira, err_value->base.source_node,
5641 ir_add_error_node(ira, err_value->source_node,
56455642 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
56465643 return nullptr;
56475644 }
......@@ -5670,13 +5667,13 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
56705667 return nullptr;
56715668
56725669 if (type_value->value->type->id != ZigTypeIdMetaType) {
5673 ir_add_error_node(ira, type_value->base.source_node,
5670 ir_add_error_node(ira, type_value->source_node,
56745671 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
56755672 return nullptr;
56765673 }
56775674
56785675 Error err;
5679 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
5676 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,
56805677 type_value->value, LazyOkNoUndef)))
56815678 {
56825679 return nullptr;
......@@ -5690,7 +5687,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
56905687 if (val == nullptr)
56915688 return ira->codegen->builtin_types.entry_invalid;
56925689
5693 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val);
5690 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val);
56945691}
56955692
56965693static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
......@@ -5712,7 +5709,7 @@ static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type
57125709 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
57135710 if (type_is_invalid(elem_type))
57145711 return ira->codegen->builtin_types.entry_invalid;
5715 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type)))
5712 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->source_node, elem_type)))
57165713 return ira->codegen->builtin_types.entry_invalid;
57175714 return elem_type;
57185715}
......@@ -5723,12 +5720,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
57235720 return ira->codegen->builtin_types.entry_invalid;
57245721
57255722 if (ty->id != ZigTypeIdInt) {
5726 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
5723 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
57275724 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
57285725 if (ty->id == ZigTypeIdVector &&
57295726 ty->data.vector.elem_type->id == ZigTypeIdInt)
57305727 {
5731 add_error_note(ira->codegen, msg, type_value->base.source_node,
5728 add_error_note(ira->codegen, msg, type_value->source_node,
57325729 buf_sprintf("represent vectors with their element types, i.e. '%s'",
57335730 buf_ptr(&ty->data.vector.elem_type->name)));
57345731 }
......@@ -5738,14 +5735,14 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
57385735 return ty;
57395736}
57405737
5741static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) {
5738static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, AstNode *op_source, IrInstGen *type_value) {
57425739 if (type_is_invalid(type_value->value->type))
57435740 return ira->codegen->builtin_types.entry_invalid;
57445741
57455742 if (type_value->value->type->id != ZigTypeIdMetaType) {
5746 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
5743 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
57475744 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
5748 add_error_note(ira->codegen, msg, op_source->source_node,
5745 add_error_note(ira->codegen, msg, op_source,
57495746 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
57505747 return ira->codegen->builtin_types.entry_invalid;
57515748 }
......@@ -5757,9 +5754,9 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrI
57575754 assert(const_val->data.x_type != nullptr);
57585755 ZigType *result_type = const_val->data.x_type;
57595756 if (result_type->id != ZigTypeIdErrorSet) {
5760 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
5757 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
57615758 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
5762 add_error_note(ira->codegen, msg, op_source->source_node,
5759 add_error_note(ira->codegen, msg, op_source,
57635760 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
57645761 return ira->codegen->builtin_types.entry_invalid;
57655762 }
......@@ -5771,7 +5768,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
57715768 return nullptr;
57725769
57735770 if (fn_value->value->type->id != ZigTypeIdFn) {
5774 ir_add_error_node(ira, fn_value->base.source_node,
5771 ir_add_error_node(ira, fn_value->source_node,
57755772 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
57765773 return nullptr;
57775774 }
......@@ -5787,7 +5784,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
57875784 return const_val->data.x_ptr.data.fn.fn_entry;
57885785}
57895786
5790static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
5787static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node,
57915788 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
57925789{
57935790 assert(wanted_type->id == ZigTypeIdOptional);
......@@ -5803,7 +5800,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
58035800 return ira->codegen->invalid_inst_gen;
58045801
58055802 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5806 source_instr->scope, source_instr->source_node);
5803 scope, source_node);
58075804 const_instruction->base.value->special = ConstValSpecialStatic;
58085805 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
58095806 copy_const_val(ira->codegen, const_instruction->base.value, val);
......@@ -5819,19 +5816,19 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
58195816 }
58205817 IrInstGen *result_loc_inst = nullptr;
58215818 if (result_loc != nullptr) {
5822 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
5819 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
58235820 if (type_is_invalid(result_loc_inst->value->type) ||
58245821 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
58255822 {
58265823 return result_loc_inst;
58275824 }
58285825 }
5829 IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
5826 IrInstGen *result = ir_build_optional_wrap(ira, scope, source_node, wanted_type, value, result_loc_inst);
58305827 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
58315828 return result;
58325829}
58335830
5834static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,
5831static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
58355832 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
58365833{
58375834 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5853,7 +5850,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
58535850 err_set_val->data.x_err_set = nullptr;
58545851
58555852 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5856 source_instr->scope, source_instr->source_node);
5853 scope, source_node);
58575854 const_instruction->base.value->type = wanted_type;
58585855 const_instruction->base.value->special = ConstValSpecialStatic;
58595856 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
......@@ -5864,7 +5861,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
58645861 IrInstGen *result_loc_inst;
58655862 if (handle_is_ptr(ira->codegen, wanted_type)) {
58665863 if (result_loc == nullptr) result_loc = no_result_loc();
5867 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
5864 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
58685865 if (type_is_invalid(result_loc_inst->value->type) ||
58695866 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
58705867 return result_loc_inst;
......@@ -5873,12 +5870,12 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
58735870 result_loc_inst = nullptr;
58745871 }
58755872
5876 IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
5873 IrInstGen *result = ir_build_err_wrap_payload(ira, scope, source_node, wanted_type, value, result_loc_inst);
58775874 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
58785875 return result;
58795876}
58805877
5881static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
5878static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
58825879 ZigType *wanted_type)
58835880{
58845881 assert(value->value->type->id == ZigTypeIdErrorSet);
......@@ -5889,7 +5886,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
58895886 if (!val)
58905887 return ira->codegen->invalid_inst_gen;
58915888
5892 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
5889 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) {
58935890 return ira->codegen->invalid_inst_gen;
58945891 }
58955892 if (!type_is_global_error_set(wanted_type)) {
......@@ -5901,7 +5898,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
59015898 }
59025899 }
59035900 if (!subset) {
5904 ir_add_error(ira, source_instr,
5901 ir_add_error_node(ira, source_node,
59055902 buf_sprintf("error.%s not a member of error set '%s'",
59065903 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));
59075904 return ira->codegen->invalid_inst_gen;
......@@ -5909,17 +5906,17 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
59095906 }
59105907
59115908 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5912 source_instr->scope, source_instr->source_node);
5909 scope, source_node);
59135910 const_instruction->base.value->type = wanted_type;
59145911 const_instruction->base.value->special = ConstValSpecialStatic;
59155912 const_instruction->base.value->data.x_err_set = val->data.x_err_set;
59165913 return &const_instruction->base;
59175914 }
59185915
5919 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);
5916 return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpErrSet);
59205917}
59215918
5922static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
5919static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node,
59235920 IrInstGen *frame_ptr, ZigType *wanted_type)
59245921{
59255922 if (instr_is_comptime(frame_ptr)) {
......@@ -5927,27 +5924,27 @@ static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* sourc
59275924 if (ptr_val == nullptr)
59285925 return ira->codegen->invalid_inst_gen;
59295926
5930 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);
5927 src_assert(ptr_val->type->id == ZigTypeIdPointer, source_node );
59315928 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
59325929 zig_panic("TODO comptime frame pointer");
59335930 }
59345931 }
59355932
5936 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);
5933 return ir_build_cast(ira, scope, source_node, wanted_type, frame_ptr, CastOpBitCast);
59375934}
59385935
5939static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
5936static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node,
59405937 IrInstGen *value, ZigType *wanted_type)
59415938{
59425939 if (instr_is_comptime(value)) {
59435940 zig_panic("TODO comptime anyframe->T to anyframe");
59445941 }
59455942
5946 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
5943 return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpBitCast);
59475944}
59485945
59495946
5950static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
5947static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
59515948 ZigType *wanted_type, ResultLoc *result_loc)
59525949{
59535950 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5965,7 +5962,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
59655962 err_set_val->data.x_err_set = val->data.x_err_set;
59665963
59675964 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5968 source_instr->scope, source_instr->source_node);
5965 scope, source_node);
59695966 const_instruction->base.value->type = wanted_type;
59705967 const_instruction->base.value->special = ConstValSpecialStatic;
59715968 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
......@@ -5976,7 +5973,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
59765973 IrInstGen *result_loc_inst;
59775974 if (handle_is_ptr(ira->codegen, wanted_type)) {
59785975 if (result_loc == nullptr) result_loc = no_result_loc();
5979 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
5976 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
59805977 if (type_is_invalid(result_loc_inst->value->type) ||
59815978 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
59825979 {
......@@ -5987,19 +5984,19 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
59875984 }
59885985
59895986
5990 IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
5987 IrInstGen *result = ir_build_err_wrap_code(ira, scope, source_node, wanted_type, value, result_loc_inst);
59915988 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
59925989 return result;
59935990}
59945991
5995static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) {
5992static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type) {
59965993 assert(wanted_type->id == ZigTypeIdOptional);
59975994 assert(instr_is_comptime(value));
59985995
59995996 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
60005997 assert(val != nullptr);
60015998
6002 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
5999 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
60036000 result->value->special = ConstValSpecialStatic;
60046001
60056002 if (get_src_ptr_type(wanted_type) != nullptr) {
......@@ -6012,7 +6009,7 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr,
60126009 return result;
60136010}
60146011
6015static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,
6012static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, Scope *scope, AstNode *source_node,
60166013 IrInstGen *value, ZigType *wanted_type)
60176014{
60186015 assert(wanted_type->id == ZigTypeIdPointer);
......@@ -6022,13 +6019,13 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in
60226019 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
60236020 assert(val != nullptr);
60246021
6025 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6022 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
60266023 result->value->data.x_ptr.special = ConstPtrSpecialNull;
60276024 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
60286025 return result;
60296026}
60306027
6031static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
6028static IrInstGen *ir_get_ref2(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
60326029 ZigType *elem_type, bool is_const, bool is_volatile)
60336030{
60346031 Error err;
......@@ -6040,7 +6037,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
60406037 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
60416038 if (!val)
60426039 return ira->codegen->invalid_inst_gen;
6043 return ir_get_const_ptr(ira, source_instruction, val, elem_type,
6040 return ir_get_const_ptr(ira, scope, source_node, val, elem_type,
60446041 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
60456042 }
60466043
......@@ -6052,20 +6049,20 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
60526049
60536050 IrInstGen *result_loc;
60546051 if (type_has_bits(ira->codegen, ptr_type) && !handle_is_ptr(ira->codegen, elem_type)) {
6055 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);
6052 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), elem_type, nullptr, true, true);
60566053 } else {
60576054 result_loc = nullptr;
60586055 }
60596056
6060 IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
6057 IrInstGen *new_instruction = ir_build_ref_gen(ira, scope, source_node, ptr_type, value, result_loc);
60616058 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
60626059 return new_instruction;
60636060}
60646061
6065static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
6062static IrInstGen *ir_get_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
60666063 bool is_const, bool is_volatile)
60676064{
6068 return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile);
6065 return ir_get_ref2(ira, scope, source_node, value, value->value->type, is_const, is_volatile);
60696066}
60706067
60716068static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {
......@@ -6099,13 +6096,13 @@ static bool can_fold_enum_type(ZigType *ty) {
60996096 (tag_int_type->id == ZigTypeIdInt && tag_int_type->data.integral.bit_count == 0);
61006097}
61016098
6102static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
6099static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) {
61036100 Error err;
61046101
61056102 IrInstGen *enum_target;
61066103 ZigType *enum_type;
61076104 if (target->value->type->id == ZigTypeIdUnion) {
6108 enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type);
6105 enum_type = ir_resolve_union_tag_type(ira, target->source_node, target->value->type);
61096106 if (type_is_invalid(enum_type))
61106107 return ira->codegen->invalid_inst_gen;
61116108 enum_target = ir_implicit_cast(ira, target, enum_type);
......@@ -6115,7 +6112,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
61156112 enum_target = target;
61166113 enum_type = target->value->type;
61176114 } else {
6118 ir_add_error_node(ira, target->base.source_node,
6115 ir_add_error_node(ira, target->source_node,
61196116 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
61206117 return ira->codegen->invalid_inst_gen;
61216118 }
......@@ -6128,7 +6125,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
61286125
61296126 // If there is only one possible tag, then we know at comptime what it is.
61306127 if (can_fold_enum_type(enum_type)) {
6131 IrInstGen *result = ir_const(ira, source_instr, tag_type);
6128 IrInstGen *result = ir_const(ira, scope, source_node, tag_type);
61326129 init_const_bigint(result->value, tag_type,
61336130 &enum_type->data.enumeration.fields[0].value);
61346131 return result;
......@@ -6138,15 +6135,15 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
61386135 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
61396136 if (!val)
61406137 return ira->codegen->invalid_inst_gen;
6141 IrInstGen *result = ir_const(ira, source_instr, tag_type);
6138 IrInstGen *result = ir_const(ira, scope, source_node, tag_type);
61426139 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
61436140 return result;
61446141 }
61456142
6146 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);
6143 return ir_build_widen_or_shorten(ira, scope, source_node, enum_target, tag_type);
61476144}
61486145
6149static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
6146static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node,
61506147 IrInstGen *target, ZigType *wanted_type)
61516148{
61526149 assert(target->value->type->id == ZigTypeIdUnion);
......@@ -6157,7 +6154,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
61576154 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
61586155 if (!val)
61596156 return ira->codegen->invalid_inst_gen;
6160 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6157 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
61616158 result->value->special = ConstValSpecialStatic;
61626159 result->value->type = wanted_type;
61636160 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
......@@ -6166,7 +6163,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
61666163
61676164 // If there is only 1 possible tag, then we know at comptime what it is.
61686165 if (can_fold_enum_type(wanted_type)) {
6169 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6166 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
61706167 result->value->special = ConstValSpecialStatic;
61716168 result->value->type = wanted_type;
61726169 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
......@@ -6174,18 +6171,18 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
61746171 return result;
61756172 }
61766173
6177 return ir_build_union_tag(ira, source_instr, target, wanted_type);
6174 return ir_build_union_tag(ira, scope, source_node, target, wanted_type);
61786175}
61796176
6180static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,
6177static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, Scope *scope, AstNode *source_node,
61816178 IrInstGen *target, ZigType *wanted_type)
61826179{
6183 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6180 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
61846181 result->value->special = ConstValSpecialUndef;
61856182 return result;
61866183}
61876184
6188static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6185static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node,
61896186 IrInstGen *uncasted_target, ZigType *wanted_type)
61906187{
61916188 Error err;
......@@ -6207,7 +6204,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62076204 Buf *int_buf = buf_alloc();
62086205 bigint_append_buf(int_buf, &target->value->data.x_enum_tag, 10);
62096206
6210 ir_add_error(ira, &target->base,
6207 ir_add_error(ira, target,
62116208 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));
62126209 return ira->codegen->invalid_inst_gen;
62136210 }
......@@ -6223,7 +6220,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62236220 case OnePossibleValueNo: {
62246221 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
62256222 union_field->enum_field->decl_index);
6226 ErrorMsg *msg = ir_add_error(ira, source_instr,
6223 ErrorMsg *msg = ir_add_error_node(ira, source_node,
62276224 buf_sprintf("cast to union '%s' must initialize '%s' field '%s'",
62286225 buf_ptr(&wanted_type->name),
62296226 buf_ptr(&field_type->name),
......@@ -6236,7 +6233,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62366233 break;
62376234 }
62386235
6239 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6236 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
62406237 result->value->special = ConstValSpecialStatic;
62416238 result->value->type = wanted_type;
62426239 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
......@@ -6247,7 +6244,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62476244 }
62486245
62496246 if (target->value->type->data.enumeration.non_exhaustive) {
6250 ir_add_error(ira, source_instr,
6247 ir_add_error_node(ira, source_node,
62516248 buf_sprintf("runtime cast to union '%s' from non-exhustive enum",
62526249 buf_ptr(&wanted_type->name)));
62536250 return ira->codegen->invalid_inst_gen;
......@@ -6256,10 +6253,10 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62566253 // if the union has all fields 0 bits, we can do it
62576254 // and in fact it's a noop cast because the union value is just the enum value
62586255 if (wanted_type->data.unionation.gen_field_count == 0) {
6259 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);
6256 return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpNoop);
62606257 }
62616258
6262 ErrorMsg *msg = ir_add_error(ira, source_instr,
6259 ErrorMsg *msg = ir_add_error_node(ira, source_node,
62636260 buf_sprintf("runtime cast to union '%s' which has non-void fields",
62646261 buf_ptr(&wanted_type->name)));
62656262 for (uint32_t i = 0; i < wanted_type->data.unionation.src_field_count; i += 1) {
......@@ -6283,7 +6280,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62836280
62846281static bool value_numeric_fits_in_type(ZigValue *value, ZigType *type_entry);
62856282
6286static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,
6283static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node,
62876284 IrInstGen *target, ZigType *wanted_type)
62886285{
62896286 ZigType *wanted_scalar_type = (target->value->type->id == ZigTypeIdVector) ?
......@@ -6298,19 +6295,19 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
62986295
62996296 if (wanted_scalar_type->id == ZigTypeIdInt) {
63006297 if (!wanted_scalar_type->data.integral.is_signed && value_cmp_numeric_val_any(val, CmpLT, nullptr)) {
6301 ir_add_error(ira, source_instr,
6298 ir_add_error_node(ira, source_node,
63026299 buf_sprintf("attempt to cast negative value to unsigned integer"));
63036300 return ira->codegen->invalid_inst_gen;
63046301 }
63056302 if (!value_numeric_fits_in_type(val, wanted_scalar_type)) {
6306 ir_add_error(ira, source_instr,
6303 ir_add_error_node(ira, source_node,
63076304 buf_sprintf("cast from '%s' to '%s' truncates bits",
63086305 buf_ptr(&target->value->type->name), buf_ptr(&wanted_scalar_type->name)));
63096306 return ira->codegen->invalid_inst_gen;
63106307 }
63116308 }
63126309
6313 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6310 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
63146311 result->value->type = wanted_type;
63156312
63166313 if (wanted_type->id == ZigTypeIdVector) {
......@@ -6346,16 +6343,16 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
63466343 if (!type_has_bits(ira->codegen, wanted_type)) {
63476344 assert(wanted_type->id == ZigTypeIdInt);
63486345 assert(type_has_bits(ira->codegen, target->value->type));
6349 ir_build_assert_zero(ira, source_instr, target);
6350 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
6346 ir_build_assert_zero(ira, scope, source_node, target);
6347 IrInstGen *result = ir_const_unsigned(ira, scope, source_node, 0);
63516348 result->value->type = wanted_type;
63526349 return result;
63536350 }
63546351
6355 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
6352 return ir_build_widen_or_shorten(ira, scope, source_node, target, wanted_type);
63566353}
63576354
6358static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
6355static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, Scope *scope, AstNode *source_node,
63596356 IrInstGen *target, ZigType *wanted_type)
63606357{
63616358 Error err;
......@@ -6367,7 +6364,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
63676364 return ira->codegen->invalid_inst_gen;
63686365
63696366 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
6370 ir_add_error(ira, source_instr,
6367 ir_add_error_node(ira, source_node,
63716368 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
63726369 buf_ptr(&actual_type->name),
63736370 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
......@@ -6385,7 +6382,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
63856382 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
63866383 Buf *val_buf = buf_alloc();
63876384 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6388 ErrorMsg *msg = ir_add_error(ira, source_instr,
6385 ErrorMsg *msg = ir_add_error_node(ira, source_node,
63896386 buf_sprintf("enum '%s' has no tag matching integer value %s",
63906387 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
63916388 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
......@@ -6393,22 +6390,22 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
63936390 return ira->codegen->invalid_inst_gen;
63946391 }
63956392
6396 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6393 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
63976394 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
63986395 return result;
63996396 }
64006397
6401 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);
6398 return ir_build_int_to_enum_gen(ira, scope, source_node, wanted_type, target);
64026399}
64036400
6404static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,
6401static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node,
64056402 IrInstGen *target, ZigType *wanted_type)
64066403{
64076404 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
64086405 if (!val)
64096406 return ira->codegen->invalid_inst_gen;
64106407
6411 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6408 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
64126409 if (wanted_type->id == ZigTypeIdComptimeFloat) {
64136410 float_init_float(result->value, val);
64146411 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
......@@ -6419,7 +6416,7 @@ static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_in
64196416 return result;
64206417}
64216418
6422static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
6419static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
64236420 ZigType *wanted_type)
64246421{
64256422 assert(target->value->type->id == ZigTypeIdInt);
......@@ -6431,9 +6428,9 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
64316428 if (!val)
64326429 return ira->codegen->invalid_inst_gen;
64336430
6434 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6431 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
64356432
6436 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
6433 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) {
64376434 return ira->codegen->invalid_inst_gen;
64386435 }
64396436
......@@ -6444,7 +6441,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
64446441 if (bigint_cmp_zero(&val->data.x_bigint) == CmpEQ || bigint_cmp(&val->data.x_bigint, &err_count) != CmpLT) {
64456442 Buf *val_buf = buf_alloc();
64466443 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6447 ir_add_error(ira, source_instr,
6444 ir_add_error_node(ira, source_node,
64486445 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));
64496446 return ira->codegen->invalid_inst_gen;
64506447 }
......@@ -6468,7 +6465,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
64686465 if (err == nullptr) {
64696466 Buf *val_buf = buf_alloc();
64706467 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6471 ir_add_error(ira, source_instr,
6468 ir_add_error_node(ira, source_node,
64726469 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));
64736470 return ira->codegen->invalid_inst_gen;
64746471 }
......@@ -6478,10 +6475,10 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
64786475 }
64796476 }
64806477
6481 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
6478 return ir_build_int_to_err_gen(ira, scope, source_node, target, wanted_type);
64826479}
64836480
6484static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
6481static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
64856482 ZigType *wanted_type)
64866483{
64876484 assert(wanted_type->id == ZigTypeIdInt);
......@@ -6493,7 +6490,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
64936490 if (!val)
64946491 return ira->codegen->invalid_inst_gen;
64956492
6496 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6493 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
64976494
64986495 ErrorTableEntry *err;
64996496 if (err_type->id == ZigTypeIdErrorUnion) {
......@@ -6510,7 +6507,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
65106507 if (!bigint_fits_in_bits(&result->value->data.x_bigint,
65116508 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))
65126509 {
6513 ir_add_error_node(ira, source_instr->source_node,
6510 ir_add_error_node(ira, source_node,
65146511 buf_sprintf("error code '%s' does not fit in '%s'",
65156512 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
65166513 return ira->codegen->invalid_inst_gen;
......@@ -6528,15 +6525,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
65286525 zig_unreachable();
65296526 }
65306527 if (!type_is_global_error_set(err_set_type)) {
6531 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {
6528 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_node)) {
65326529 return ira->codegen->invalid_inst_gen;
65336530 }
65346531 if (err_set_type->data.error_set.err_count == 0) {
6535 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6532 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
65366533 bigint_init_unsigned(&result->value->data.x_bigint, 0);
65376534 return result;
65386535 } else if (err_set_type->data.error_set.err_count == 1) {
6539 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
6536 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
65406537 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
65416538 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
65426539 return result;
......@@ -6546,15 +6543,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
65466543 BigInt bn;
65476544 bigint_init_unsigned(&bn, ira->codegen->errors_by_index.length);
65486545 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
6549 ir_add_error_node(ira, source_instr->source_node,
6546 ir_add_error_node(ira, source_node,
65506547 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
65516548 return ira->codegen->invalid_inst_gen;
65526549 }
65536550
6554 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
6551 return ir_build_err_to_int_gen(ira, scope, source_node, target, wanted_type);
65556552}
65566553
6557static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
6554static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
65586555 ZigType *wanted_type)
65596556{
65606557 assert(wanted_type->id == ZigTypeIdPointer);
......@@ -6573,7 +6570,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
65736570 return ira->codegen->invalid_inst_gen;
65746571
65756572 assert(val->type->id == ZigTypeIdPointer);
6576 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
6573 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node);
65776574 if (pointee == nullptr)
65786575 return ira->codegen->invalid_inst_gen;
65796576 if (pointee->special != ConstValSpecialRuntime) {
......@@ -6586,7 +6583,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
65866583 array_val->parent.data.p_scalar.scalar_val = pointee;
65876584
65886585 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
6589 source_instr->scope, source_instr->source_node);
6586 scope, source_node);
65906587 const_instruction->base.value->type = wanted_type;
65916588 const_instruction->base.value->special = ConstValSpecialStatic;
65926589 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef;
......@@ -6597,7 +6594,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
65976594 }
65986595
65996596 // pointer to array and pointer to single item are represented the same way at runtime
6600 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);
6597 return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpBitCast);
66016598}
66026599
66036600static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,
......@@ -6794,25 +6791,25 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
67946791 }
67956792}
67966793
6797static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,
6794static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
67986795 IrInstGen *array, ZigType *vector_type)
67996796{
68006797 if (instr_is_comptime(array)) {
68016798 // arrays and vectors have the same ZigValue representation
6802 IrInstGen *result = ir_const(ira, source_instr, vector_type);
6799 IrInstGen *result = ir_const(ira, scope, source_node, vector_type);
68036800 copy_const_val(ira->codegen, result->value, array->value);
68046801 result->value->type = vector_type;
68056802 return result;
68066803 }
6807 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
6804 return ir_build_array_to_vector(ira, scope, source_node, array, vector_type);
68086805}
68096806
6810static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,
6807static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
68116808 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
68126809{
68136810 if (instr_is_comptime(vector)) {
68146811 // arrays and vectors have the same ZigValue representation
6815 IrInstGen *result = ir_const(ira, source_instr, array_type);
6812 IrInstGen *result = ir_const(ira, scope, source_node, array_type);
68166813 copy_const_val(ira->codegen, result->value, vector->value);
68176814 result->value->type = array_type;
68186815 return result;
......@@ -6820,14 +6817,14 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst
68206817 if (result_loc == nullptr) {
68216818 result_loc = no_result_loc();
68226819 }
6823 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true);
6820 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, array_type, nullptr, true, true);
68246821 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
68256822 return result_loc_inst;
68266823 }
6827 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
6824 return ir_build_vector_to_array(ira, scope, source_node, array_type, vector, result_loc_inst);
68286825}
68296826
6830static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
6827static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
68316828 IrInstGen *integer, ZigType *dest_type)
68326829{
68336830 IrInstGen *unsigned_integer;
......@@ -6839,7 +6836,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
68396836 if (integer->value->type->data.integral.bit_count >
68406837 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)
68416838 {
6842 ir_add_error(ira, source_instr,
6839 ir_add_error_node(ira, source_node,
68436840 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
68446841 buf_ptr(&integer->value->type->name),
68456842 buf_ptr(&dest_type->name)));
......@@ -6849,7 +6846,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
68496846 if (integer->value->type->data.integral.is_signed) {
68506847 ZigType *unsigned_int_type = get_int_type(ira->codegen, false,
68516848 integer->value->type->data.integral.bit_count);
6852 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
6849 unsigned_integer = ir_analyze_bit_cast(ira, scope, source_node, integer, unsigned_int_type);
68536850 if (type_is_invalid(unsigned_integer->value->type))
68546851 return ira->codegen->invalid_inst_gen;
68556852 } else {
......@@ -6857,7 +6854,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
68576854 }
68586855 }
68596856
6860 return ir_analyze_int_to_ptr(ira, source_instr, unsigned_integer, dest_type);
6857 return ir_analyze_int_to_ptr(ira, scope, source_node, unsigned_integer, dest_type);
68616858}
68626859
68636860static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
......@@ -6871,7 +6868,7 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
68716868 return false;
68726869}
68736870
6874static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
6871static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
68756872 ZigType *enum_type)
68766873{
68776874 assert(enum_type->id == ZigTypeIdEnum);
......@@ -6882,19 +6879,19 @@ static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr,
68826879
68836880 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
68846881 if (field == nullptr) {
6885 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",
6882 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("enum '%s' has no field named '%s'",
68866883 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
68876884 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
68886885 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
68896886 return ira->codegen->invalid_inst_gen;
68906887 }
6891 IrInstGen *result = ir_const(ira, source_instr, enum_type);
6888 IrInstGen *result = ir_const(ira, scope, source_node, enum_type);
68926889 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
68936890
68946891 return result;
68956892}
68966893
6897static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,
6894static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
68986895 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)
68996896{
69006897 Error err;
......@@ -6906,7 +6903,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69066903 size_t instr_field_count = actual_type->data.structure.src_field_count;
69076904 assert(array_len == instr_field_count);
69086905
6909 bool need_comptime = ir_should_inline(ira->zir, source_instr->scope)
6906 bool need_comptime = ir_should_inline(ira->zir, scope)
69106907 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;
69116908 bool is_comptime = true;
69126909
......@@ -6915,16 +6912,16 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69156912 // Determine if the struct_operand will be comptime.
69166913 ZigValue *elem_values = heap::c_allocator.allocate<ZigValue>(array_len);
69176914 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(array_len);
6918 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);
6915 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
69196916
69206917 for (size_t i = 0; i < array_len; i += 1) {
69216918 TypeStructField *src_field = actual_type->data.structure.fields[i];
69226919
6923 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr,
6920 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr,
69246921 actual_type, false);
69256922 if (type_is_invalid(field_ptr->value->type))
69266923 return ira->codegen->invalid_inst_gen;
6927 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);
6924 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
69286925 if (type_is_invalid(field_value->value->type))
69296926 return ira->codegen->invalid_inst_gen;
69306927 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, elem_type);
......@@ -6950,13 +6947,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69506947 }
69516948
69526949 if (is_comptime) {
6953 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);
6950 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
69546951 const_result->value->data.x_array.special = ConstArraySpecialNone;
69556952 const_result->value->data.x_array.data.s_none.elements = elem_values;
69566953 return const_result;
69576954 }
69586955
6959 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),
6956 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
69606957 wanted_type, nullptr, true, true);
69616958 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
69626959 return ira->codegen->invalid_inst_gen;
......@@ -6964,12 +6961,12 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69646961
69656962 ZigType *elem_type_ptr = get_pointer_to_type(ira->codegen, elem_type, false);
69666963 for (size_t i = 0; i < array_len; i += 1) {
6967 IrInstGen *index_val = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
6964 IrInstGen *index_val = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_usize);
69686965 bigint_init_unsigned(&index_val->value->data.x_bigint, i);
69696966
6970 IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, source_instr->scope, source_instr->source_node,
6967 IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, scope, source_node,
69716968 result_loc_inst, index_val, false, elem_type_ptr);
6972 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, elem_ptr, casted_fields[i], true);
6969 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, elem_ptr, casted_fields[i], true);
69736970 if (type_is_invalid(store_ptr_inst->value->type))
69746971 return ira->codegen->invalid_inst_gen;
69756972 }
......@@ -6980,13 +6977,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69806977 return result_loc_inst;
69816978}
69826979
6983static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,
6980static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, Scope *scope, AstNode *source_node,
69846981 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)
69856982{
69866983 Error err;
69876984
69886985 if (wanted_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
6989 ir_add_error(ira, source_instr, buf_sprintf("type coercion of anon struct literal to inferred struct"));
6986 ir_add_error_node(ira, source_node, buf_sprintf("type coercion of anon struct literal to inferred struct"));
69906987 return ira->codegen->invalid_inst_gen;
69916988 }
69926989
......@@ -6996,7 +6993,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
69966993 size_t actual_field_count = wanted_type->data.structure.src_field_count;
69976994 size_t instr_field_count = actual_type->data.structure.src_field_count;
69986995
6999 bool need_comptime = ir_should_inline(ira->zir, source_instr->scope)
6996 bool need_comptime = ir_should_inline(ira->zir, scope)
70006997 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;
70016998 bool is_comptime = true;
70026999
......@@ -7005,13 +7002,13 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
70057002 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
70067003 ZigValue **field_values = heap::c_allocator.allocate<ZigValue *>(actual_field_count);
70077004 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(actual_field_count);
7008 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);
7005 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
70097006
70107007 for (size_t i = 0; i < instr_field_count; i += 1) {
70117008 TypeStructField *src_field = actual_type->data.structure.fields[i];
70127009 TypeStructField *dst_field = find_struct_type_field(wanted_type, src_field->name);
70137010 if (dst_field == nullptr) {
7014 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("no field named '%s' in struct '%s'",
7011 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("no field named '%s' in struct '%s'",
70157012 buf_ptr(src_field->name), buf_ptr(&wanted_type->name)));
70167013 if (wanted_type->data.structure.decl_node) {
70177014 add_error_note(ira->codegen, msg, wanted_type->data.structure.decl_node,
......@@ -7022,20 +7019,20 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
70227019 return ira->codegen->invalid_inst_gen;
70237020 }
70247021
7025 ir_assert(src_field->decl_node != nullptr, source_instr);
7022 src_assert(src_field->decl_node != nullptr, source_node);
70267023 AstNode *existing_assign_node = field_assign_nodes[dst_field->src_index];
70277024 if (existing_assign_node != nullptr) {
7028 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("duplicate field"));
7025 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("duplicate field"));
70297026 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
70307027 return ira->codegen->invalid_inst_gen;
70317028 }
70327029 field_assign_nodes[dst_field->src_index] = src_field->decl_node;
70337030
7034 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr,
7031 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr,
70357032 actual_type, false);
70367033 if (type_is_invalid(field_ptr->value->type))
70377034 return ira->codegen->invalid_inst_gen;
7038 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);
7035 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
70397036 if (type_is_invalid(field_value->value->type))
70407037 return ira->codegen->invalid_inst_gen;
70417038 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, dst_field->type_entry);
......@@ -7067,7 +7064,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
70677064 TypeStructField *field = wanted_type->data.structure.fields[i];
70687065 memoize_field_init_val(ira->codegen, wanted_type, field);
70697066 if (field->init_val == nullptr) {
7070 ir_add_error(ira, source_instr,
7067 ir_add_error_node(ira, source_node,
70717068 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));
70727069 any_missing = true;
70737070 continue;
......@@ -7080,19 +7077,19 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
70807077 init_val_copy->parent.data.p_struct.struct_val = const_result->value;
70817078 init_val_copy->parent.data.p_struct.field_index = i;
70827079 field_values[i] = init_val_copy;
7083 casted_fields[i] = ir_const_move(ira, source_instr, init_val_copy);
7080 casted_fields[i] = ir_const_move(ira, scope, source_node, init_val_copy);
70847081 }
70857082 if (any_missing)
70867083 return ira->codegen->invalid_inst_gen;
70877084
70887085 if (is_comptime) {
70897086 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
7090 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);
7087 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
70917088 const_result->value->data.x_struct.fields = field_values;
70927089 return const_result;
70937090 }
70947091
7095 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),
7092 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
70967093 wanted_type, nullptr, true, true);
70977094 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
70987095 return ira->codegen->invalid_inst_gen;
......@@ -7100,10 +7097,10 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
71007097
71017098 for (size_t i = 0; i < actual_field_count; i += 1) {
71027099 TypeStructField *field = wanted_type->data.structure.fields[i];
7103 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc_inst, wanted_type, true);
7100 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc_inst, wanted_type, true);
71047101 if (type_is_invalid(field_ptr->value->type))
71057102 return ira->codegen->invalid_inst_gen;
7106 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, field_ptr, casted_fields[i], true);
7103 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, field_ptr, casted_fields[i], true);
71077104 if (type_is_invalid(store_ptr_inst->value->type))
71087105 return ira->codegen->invalid_inst_gen;
71097106 }
......@@ -7115,7 +7112,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
71157112 return result_loc_inst;
71167113}
71177114
7118static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,
7115static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node,
71197116 IrInstGen *struct_ptr, ZigType *struct_type, ZigType *union_type)
71207117{
71217118 Error err;
......@@ -7141,11 +7138,11 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
71417138 if (payload_type == nullptr)
71427139 return ira->codegen->invalid_inst_gen;
71437140
7144 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, only_field, struct_ptr,
7141 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, only_field, struct_ptr,
71457142 struct_type, false);
71467143 if (type_is_invalid(field_ptr->value->type))
71477144 return ira->codegen->invalid_inst_gen;
7148 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);
7145 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
71497146 if (type_is_invalid(field_value->value->type))
71507147 return ira->codegen->invalid_inst_gen;
71517148
......@@ -7158,7 +7155,7 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
71587155 if (val == nullptr)
71597156 return ira->codegen->invalid_inst_gen;
71607157
7161 IrInstGen *result = ir_const(ira, source_instr, union_type);
7158 IrInstGen *result = ir_const(ira, scope, source_node, union_type);
71627159 bigint_init_bigint(&result->value->data.x_union.tag, &union_field->enum_field->value);
71637160 result->value->data.x_union.payload = val;
71647161
......@@ -7168,18 +7165,18 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
71687165 return result;
71697166 }
71707167
7171 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),
7168 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
71727169 union_type, nullptr, true, true);
71737170 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
71747171 return ira->codegen->invalid_inst_gen;
71757172 }
71767173
7177 IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name, source_instr,
7178 result_loc_inst, source_instr, union_type, true);
7174 IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name,
7175 scope, source_node, result_loc_inst, source_node, union_type, true);
71797176 if (type_is_invalid(payload_ptr->value->type))
71807177 return ira->codegen->invalid_inst_gen;
71817178
7182 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, payload_ptr, casted_value, false);
7179 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, payload_ptr, casted_value, false);
71837180 if (type_is_invalid(store_ptr_inst->value->type))
71847181 return ira->codegen->invalid_inst_gen;
71857182
......@@ -7190,13 +7187,13 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
71907187// otherwise return ErrorNone. Does not emit any instructions.
71917188// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
71927189// pointer types' alignments if both of the pointer types are ABI aligned.
7193static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type,
7190static Error ir_cast_ptr_align(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_ptr_type,
71947191 ZigType *src_ptr_type, AstNode *src_source_node)
71957192{
71967193 Error err;
71977194
7198 ir_assert(dest_ptr_type->id == ZigTypeIdPointer, source_instr);
7199 ir_assert(src_ptr_type->id == ZigTypeIdPointer, source_instr);
7195 src_assert(dest_ptr_type->id == ZigTypeIdPointer, source_node);
7196 src_assert(src_ptr_type->id == ZigTypeIdPointer, source_node);
72007197
72017198 if (dest_ptr_type->data.pointer.explicit_alignment == 0 &&
72027199 src_ptr_type->data.pointer.explicit_alignment == 0)
......@@ -7213,10 +7210,10 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de
72137210 uint32_t wanted_align = get_ptr_align(ira->codegen, dest_ptr_type);
72147211 uint32_t actual_align = get_ptr_align(ira->codegen, src_ptr_type);
72157212 if (wanted_align > actual_align) {
7216 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
7213 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment"));
72177214 add_error_note(ira->codegen, msg, src_source_node,
72187215 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_ptr_type->name), actual_align));
7219 add_error_note(ira->codegen, msg, source_instr->source_node,
7216 add_error_note(ira->codegen, msg, source_node,
72207217 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_ptr_type->name), wanted_align));
72217218 return ErrorSemanticAnalyzeFail;
72227219 }
......@@ -7224,34 +7221,33 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de
72247221 return ErrorNone;
72257222}
72267223
7227static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
7224static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
72287225 IrInstGen *struct_operand, TypeStructField *field)
72297226{
7230 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
7227 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, struct_operand, true, false);
72317228 if (type_is_invalid(struct_ptr->value->type))
72327229 return ira->codegen->invalid_inst_gen;
7233 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
7230 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, struct_ptr,
72347231 struct_operand->value->type, false);
72357232 if (type_is_invalid(field_ptr->value->type))
72367233 return ira->codegen->invalid_inst_gen;
7237 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
7234 return ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
72387235}
72397236
7240static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,
7237static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
72417238 IrInstGen *optional_operand, bool safety_check_on)
72427239{
7243 IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
7244 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
7240 IrInstGen *opt_ptr = ir_get_ref(ira, scope, source_node, optional_operand, true, false);
7241 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, scope, source_node, opt_ptr,
72457242 safety_check_on, false);
7246 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);
7243 return ir_get_deref(ira, scope, source_node, payload_ptr, nullptr);
72477244}
72487245
7249static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7246static IrInstGen *ir_analyze_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
72507247 ZigType *wanted_type, IrInstGen *value)
72517248{
72527249 Error err;
72537250 ZigType *actual_type = value->value->type;
7254 AstNode *source_node = source_instr->source_node;
72557251
72567252 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
72577253 return ira->codegen->invalid_inst_gen;
......@@ -7268,21 +7264,21 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
72687264 if (const_cast_result.id == ConstCastResultIdInvalid)
72697265 return ira->codegen->invalid_inst_gen;
72707266 if (const_cast_result.id == ConstCastResultIdOk) {
7271 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
7267 return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop);
72727268 }
72737269
72747270 if (const_cast_result.id == ConstCastResultIdFnCC) {
7275 ir_assert(value->value->type->id == ZigTypeIdFn, source_instr);
7271 src_assert(value->value->type->id == ZigTypeIdFn, source_node);
72767272 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.
72777273 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&
72787274 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)
72797275 {
7280 ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
7276 src_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
72817277 ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry;
72827278 if (fn->inferred_async_node == nullptr) {
7283 fn->inferred_async_node = source_instr->source_node;
7279 fn->inferred_async_node = source_node;
72847280 }
7285 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
7281 return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop);
72867282 }
72877283 }
72887284
......@@ -7293,12 +7289,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
72937289 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
72947290 false).id == ConstCastResultIdOk)
72957291 {
7296 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
7292 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
72977293 } else if (actual_type->id == ZigTypeIdComptimeInt ||
72987294 actual_type->id == ZigTypeIdComptimeFloat)
72997295 {
73007296 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
7301 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
7297 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
73027298 } else {
73037299 return ira->codegen->invalid_inst_gen;
73047300 }
......@@ -7318,11 +7314,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
73187314 actual_type->data.pointer.child_type->data.array.child_type, source_node,
73197315 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
73207316 {
7321 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
7317 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value,
73227318 wanted_child_type);
73237319 if (type_is_invalid(cast1->value->type))
73247320 return ira->codegen->invalid_inst_gen;
7325 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
7321 return ir_analyze_optional_wrap(ira, scope, source_node, cast1, wanted_type, nullptr);
73267322 }
73277323 }
73287324 }
......@@ -7332,12 +7328,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
73327328 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
73337329 source_node, false).id == ConstCastResultIdOk)
73347330 {
7335 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
7331 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
73367332 } else if (actual_type->id == ZigTypeIdComptimeInt ||
73377333 actual_type->id == ZigTypeIdComptimeFloat)
73387334 {
73397335 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
7340 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
7336 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
73417337 } else {
73427338 return ira->codegen->invalid_inst_gen;
73437339 }
......@@ -7355,11 +7351,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
73557351 actual_type->id == ZigTypeIdComptimeInt ||
73567352 actual_type->id == ZigTypeIdComptimeFloat)
73577353 {
7358 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
7354 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.error_union.payload_type, value);
73597355 if (type_is_invalid(cast1->value->type))
73607356 return ira->codegen->invalid_inst_gen;
73617357
7362 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
7358 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
73637359 if (type_is_invalid(cast2->value->type))
73647360 return ira->codegen->invalid_inst_gen;
73657361
......@@ -7376,13 +7372,13 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
73767372 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
73777373 {
73787374 if (value->value->special == ConstValSpecialUndef) {
7379 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
7375 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
73807376 result->value->special = ConstValSpecialUndef;
73817377 return result;
73827378 }
73837379 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
73847380 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
7385 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
7381 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
73867382 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
73877383 copy_const_val(ira->codegen, result->value, value->value);
73887384 result->value->type = wanted_type;
......@@ -7391,7 +7387,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
73917387 }
73927388 return result;
73937389 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
7394 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
7390 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
73957391 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
73967392 BigFloat bf;
73977393 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
......@@ -7413,7 +7409,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
74137409 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
74147410 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
74157411 {
7416 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7412 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
74177413 }
74187414
74197415 // small enough unsigned ints can get casted to large enough signed ints
......@@ -7421,7 +7417,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
74217417 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
74227418 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
74237419 {
7424 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7420 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
74257421 }
74267422
74277423 // float widening conversion
......@@ -7429,7 +7425,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
74297425 actual_type->id == ZigTypeIdFloat &&
74307426 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
74317427 {
7432 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7428 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
74337429 }
74347430
74357431 // *[N]T to ?[]T
......@@ -7439,11 +7435,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
74397435 actual_type->data.pointer.ptr_len == PtrLenSingle &&
74407436 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
74417437 {
7442 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
7438 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.maybe.child_type, value);
74437439 if (type_is_invalid(cast1->value->type))
74447440 return ira->codegen->invalid_inst_gen;
74457441
7446 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
7442 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
74477443 if (type_is_invalid(cast2->value->type))
74487444 return ira->codegen->invalid_inst_gen;
74497445
......@@ -7474,7 +7470,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
74747470 actual_type->data.pointer.child_type->data.array.child_type, source_node,
74757471 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
74767472 {
7477 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type);
7473 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value, wanted_type);
74787474 }
74797475 }
74807476 }
......@@ -7525,17 +7521,17 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
75257521 }
75267522 if (ok_align) {
75277523 if (wanted_type->id == ZigTypeIdErrorUnion) {
7528 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
7524 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, slice_type, value);
75297525 if (type_is_invalid(cast1->value->type))
75307526 return ira->codegen->invalid_inst_gen;
75317527
7532 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
7528 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
75337529 if (type_is_invalid(cast2->value->type))
75347530 return ira->codegen->invalid_inst_gen;
75357531
75367532 return cast2;
75377533 } else {
7538 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, nullptr);
7534 return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, value, slice_type, nullptr);
75397535 }
75407536 }
75417537 }
......@@ -7554,7 +7550,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
75547550 scalar_wanted_type->data.integral.is_signed == scalar_actual_type->data.integral.is_signed &&
75557551 scalar_wanted_type->data.integral.bit_count >= scalar_actual_type->data.integral.bit_count)
75567552 {
7557 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7553 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
75587554 }
75597555
75607556 // small enough unsigned ints can get casted to large enough signed ints
......@@ -7562,7 +7558,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
75627558 scalar_actual_type->id == ZigTypeIdInt && !scalar_actual_type->data.integral.is_signed &&
75637559 scalar_wanted_type->data.integral.bit_count > scalar_actual_type->data.integral.bit_count)
75647560 {
7565 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7561 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
75667562 }
75677563
75687564 // float widening conversion
......@@ -7570,7 +7566,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
75707566 scalar_actual_type->id == ZigTypeIdFloat &&
75717567 scalar_wanted_type->data.floating.bit_count >= scalar_actual_type->data.floating.bit_count)
75727568 {
7573 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
7569 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
75747570 }
75757571 }
75767572
......@@ -7605,10 +7601,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
76057601 }
76067602 }
76077603 if (ok) {
7608 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
7604 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, scope, source_node, value, anyframe_type);
76097605 if (anyframe_type == wanted_type)
76107606 return cast1;
7611 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
7607 return ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
76127608 }
76137609 }
76147610 }
......@@ -7617,28 +7613,28 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
76177613 if (actual_type->id == ZigTypeIdAnyFrame && actual_type->data.any_frame.result_type != nullptr &&
76187614 wanted_type->id == ZigTypeIdAnyFrame && wanted_type->data.any_frame.result_type == nullptr)
76197615 {
7620 return ir_analyze_anyframe_to_anyframe(ira, source_instr, value, wanted_type);
7616 return ir_analyze_anyframe_to_anyframe(ira, scope, source_node, value, wanted_type);
76217617 }
76227618
76237619 // cast from null literal to maybe type
76247620 if (wanted_type->id == ZigTypeIdOptional &&
76257621 actual_type->id == ZigTypeIdNull)
76267622 {
7627 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
7623 return ir_analyze_null_to_maybe(ira, scope, source_node, value, wanted_type);
76287624 }
76297625
76307626 // cast from null literal to C pointer
76317627 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&
76327628 actual_type->id == ZigTypeIdNull)
76337629 {
7634 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
7630 return ir_analyze_null_to_c_pointer(ira, scope, source_node, value, wanted_type);
76357631 }
76367632
76377633 // cast from E to E!T
76387634 if (wanted_type->id == ZigTypeIdErrorUnion &&
76397635 actual_type->id == ZigTypeIdErrorSet)
76407636 {
7641 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, nullptr);
7637 return ir_analyze_err_wrap_code(ira, scope, source_node, value, wanted_type, nullptr);
76427638 }
76437639
76447640 // cast from typed number to integer or float literal.
......@@ -7647,35 +7643,35 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
76477643 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
76487644 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
76497645 {
7650 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
7646 return ir_analyze_number_to_literal(ira, scope, source_node, value, wanted_type);
76517647 }
76527648
76537649 // cast from enum literal to enum with matching field name
76547650 if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum)
76557651 {
7656 return ir_analyze_enum_literal(ira, source_instr, value, wanted_type);
7652 return ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type);
76577653 }
76587654
76597655 // cast from enum literal to optional enum
76607656 if (actual_type->id == ZigTypeIdEnumLiteral &&
76617657 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
76627658 {
7663 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
7659 IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.maybe.child_type);
76647660 if (type_is_invalid(result->value->type))
76657661 return result;
76667662
7667 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
7663 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
76687664 }
76697665
76707666 // cast from enum literal to error union when payload is an enum
76717667 if (actual_type->id == ZigTypeIdEnumLiteral &&
76727668 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
76737669 {
7674 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
7670 IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.error_union.payload_type);
76757671 if (type_is_invalid(result->value->type))
76767672 return result;
76777673
7678 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
7674 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
76797675 }
76807676
76817677 // cast from union to the enum type of the union
......@@ -7684,7 +7680,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
76847680 return ira->codegen->invalid_inst_gen;
76857681
76867682 if (actual_type->data.unionation.tag_type == wanted_type) {
7687 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);
7683 return ir_analyze_union_to_tag(ira, scope, source_node, value, wanted_type);
76887684 }
76897685 }
76907686
......@@ -7693,7 +7689,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
76937689 if (is_tagged_union(wanted_type) && (actual_type->id == ZigTypeIdEnum ||
76947690 actual_type->id == ZigTypeIdEnumLiteral))
76957691 {
7696 return ir_analyze_enum_to_union(ira, source_instr, value, wanted_type);
7692 return ir_analyze_enum_to_union(ira, scope, source_node, value, wanted_type);
76977693 }
76987694
76997695 // cast from *T to *[1]T
......@@ -7709,10 +7705,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77097705 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
77107706 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
77117707 {
7712 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))
7708 if ((err = ir_cast_ptr_align(ira, scope, source_node, wanted_type, actual_type, value->source_node)))
77137709 return ira->codegen->invalid_inst_gen;
77147710
7715 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
7711 return ir_analyze_ptr_to_array(ira, scope, source_node, value, wanted_type);
77167712 }
77177713 }
77187714
......@@ -7733,8 +7729,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77337729 slice_ptr_type->data.pointer.sentinel))))
77347730 {
77357731 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
7736 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
7737 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);
7732 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, scope, source_node, value, ptr_field);
7733 return ir_implicit_cast2(ira, scope, source_node, slice_ptr, wanted_type);
77387734 }
77397735 }
77407736
......@@ -7754,8 +7750,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77547750 dest_ptr_type = wanted_type->data.maybe.child_type;
77557751 }
77567752 if (dest_ptr_type != nullptr) {
7757 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true,
7758 false);
7753 return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node,
7754 wanted_type, source_node, true, false);
77597755 }
77607756 }
77617757
......@@ -7768,7 +7764,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77687764 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
77697765 return ira->codegen->invalid_inst_gen;
77707766 if (!has_bits) {
7771 return ir_get_ref(ira, source_instr, value, false, false);
7767 return ir_get_ref(ira, scope, source_node, value, false, false);
77727768 }
77737769 }
77747770
......@@ -7778,7 +7774,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77787774 types_match_const_cast_only(ira, wanted_type->data.array.child_type,
77797775 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
77807776 {
7781 return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, nullptr);
7777 return ir_analyze_vector_to_array(ira, scope, source_node, value, wanted_type, nullptr);
77827778 }
77837779
77847780 // cast from [N]T to @Vector(N, T)
......@@ -7787,7 +7783,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77877783 types_match_const_cast_only(ira, actual_type->data.array.child_type,
77887784 wanted_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
77897785 {
7790 return ir_analyze_array_to_vector(ira, source_instr, value, wanted_type);
7786 return ir_analyze_array_to_vector(ira, scope, source_node, value, wanted_type);
77917787 }
77927788
77937789 // casting between C pointers and normal pointers
......@@ -7797,14 +7793,15 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
77977793 actual_type->data.pointer.child_type, source_node,
77987794 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
77997795 {
7800 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true, false);
7796 return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node,
7797 wanted_type, source_node, true, false);
78017798 }
78027799
78037800 // cast from integer to C pointer
78047801 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&
78057802 (actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt))
78067803 {
7807 return ir_analyze_int_to_c_ptr(ira, source_instr, value, wanted_type);
7804 return ir_analyze_int_to_c_ptr(ira, scope, source_node, value, wanted_type);
78087805 }
78097806
78107807 // cast from inferred struct type to array, union, or struct
......@@ -7816,34 +7813,34 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
78167813 if (wanted_type->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&
78177814 wanted_type->data.array.len == field_count)
78187815 {
7819 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);
7816 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
78207817 if (type_is_invalid(struct_ptr->value->type))
78217818 return ira->codegen->invalid_inst_gen;
78227819
7823 IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, source_instr, struct_ptr, actual_type, wanted_type);
7820 IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
78247821 if (ptr->value->type->id != ZigTypeIdPointer)
78257822 return ptr;
7826 return ir_get_deref(ira, source_instr, ptr, nullptr);
7823 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
78277824 } else if (wanted_type->id == ZigTypeIdStruct && !is_slice(wanted_type) &&
78287825 (!is_array_init || field_count == 0))
78297826 {
7830 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);
7827 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
78317828 if (type_is_invalid(struct_ptr->value->type))
78327829 return ira->codegen->invalid_inst_gen;
78337830
7834 IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, source_instr, struct_ptr, actual_type, wanted_type);
7831 IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
78357832 if (ptr->value->type->id != ZigTypeIdPointer)
78367833 return ptr;
7837 return ir_get_deref(ira, source_instr, ptr, nullptr);
7834 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
78387835 } else if (wanted_type->id == ZigTypeIdUnion && !is_array_init && field_count == 1) {
7839 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);
7836 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
78407837 if (type_is_invalid(struct_ptr->value->type))
78417838 return ira->codegen->invalid_inst_gen;
78427839
7843 IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, source_instr, struct_ptr, actual_type, wanted_type);
7840 IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
78447841 if (ptr->value->type->id != ZigTypeIdPointer)
78457842 return ptr;
7846 return ir_get_deref(ira, source_instr, ptr, nullptr);
7843 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
78477844 }
78487845 }
78497846
......@@ -7862,22 +7859,22 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
78627859 if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&
78637860 wanted_child->data.array.len == field_count && (const_ok || field_count == 0))
78647861 {
7865 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, wanted_child);
7862 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, wanted_child);
78667863 if (res->value->type->id == ZigTypeIdPointer)
78677864 return res;
7868 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7865 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
78697866 } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) &&
78707867 (!is_array_init || field_count == 0) && const_ok)
78717868 {
7872 IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, source_instr, value, anon_type, wanted_child);
7869 IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, scope, source_node, value, anon_type, wanted_child);
78737870 if (res->value->type->id == ZigTypeIdPointer)
78747871 return res;
7875 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7872 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
78767873 } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1 && const_ok) {
7877 IrInstGen *res = ir_analyze_struct_literal_to_union(ira, source_instr, value, anon_type, wanted_child);
7874 IrInstGen *res = ir_analyze_struct_literal_to_union(ira, scope, source_node, value, anon_type, wanted_child);
78787875 if (res->value->type->id == ZigTypeIdPointer)
78797876 return res;
7880 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7877 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
78817878 }
78827879 } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) {
78837880 ZigType *slice_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
......@@ -7886,49 +7883,49 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
78867883 {
78877884 ZigType *slice_child_type = slice_type->data.pointer.child_type;
78887885 ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr);
7889 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, slice_array_type);
7886 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, slice_array_type);
78907887 if (type_is_invalid(res->value->type))
78917888 return ira->codegen->invalid_inst_gen;
78927889 if (res->value->type->id != ZigTypeIdPointer)
7893 res = ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7890 res = ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
78947891
7895 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, res, wanted_type, nullptr);
7892 return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, res, wanted_type, nullptr);
78967893 }
78977894 }
78987895 }
78997896
79007897 // cast from undefined to anything
79017898 if (actual_type->id == ZigTypeIdUndefined) {
7902 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
7899 return ir_analyze_undefined_to_anything(ira, scope, source_node, value, wanted_type);
79037900 }
79047901
79057902 // T to ?U, where T implicitly casts to U
79067903 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
7907 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
7904 IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.maybe.child_type);
79087905 if (type_is_invalid(cast1->value->type))
79097906 return ira->codegen->invalid_inst_gen;
7910 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
7907 return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type);
79117908 }
79127909
79137910 // T to E!U, where T implicitly casts to U
79147911 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
79157912 actual_type->id != ZigTypeIdErrorSet)
79167913 {
7917 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
7914 IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.error_union.payload_type);
79187915 if (type_is_invalid(cast1->value->type))
79197916 return ira->codegen->invalid_inst_gen;
7920 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
7917 return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type);
79217918 }
79227919
7923 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
7920 ErrorMsg *parent_msg = ir_add_error_node(ira, source_node,
79247921 buf_sprintf("expected type '%s', found '%s'",
79257922 buf_ptr(&wanted_type->name),
79267923 buf_ptr(&actual_type->name)));
7927 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
7924 report_recursive_error(ira, source_node, &const_cast_result, parent_msg);
79287925 return ira->codegen->invalid_inst_gen;
79297926}
79307927
7931static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
7928static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node,
79327929 IrInstGen *value, ZigType *expected_type)
79337930{
79347931 assert(value);
......@@ -7942,20 +7939,20 @@ static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
79427939 if (value->value->type->id == ZigTypeIdUnreachable)
79437940 return value;
79447941
7945 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
7942 return ir_analyze_cast(ira, scope, source_node, expected_type, value);
79467943}
79477944
79487945static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
7949 return ir_implicit_cast2(ira, &value->base, value, expected_type);
7946 return ir_implicit_cast2(ira, value->scope, value->source_node, value, expected_type);
79507947}
79517948
79527949static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
7953 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);
7950 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
79547951 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
79557952 if (elem_type != g->builtin_types.entry_anytype)
79567953 return elem_type;
79577954
7958 if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value))
7955 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))
79597956 return g->builtin_types.entry_invalid;
79607957
79617958 assert(value_is_comptime(ptr->value));
......@@ -7963,7 +7960,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
79637960 return pointee->type;
79647961}
79657962
7966static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr,
7963static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr,
79677964 ResultLoc *result_loc)
79687965{
79697966 Error err;
......@@ -7972,7 +7969,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
79727969 return ira->codegen->invalid_inst_gen;
79737970
79747971 if (ptr_type->id != ZigTypeIdPointer) {
7975 ir_add_error_node(ira, source_instruction->source_node,
7972 ir_add_error_node(ira, source_node,
79767973 buf_sprintf("attempt to dereference non-pointer type '%s'",
79777974 buf_ptr(&ptr_type->name)));
79787975 return ira->codegen->invalid_inst_gen;
......@@ -7986,7 +7983,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
79867983 case OnePossibleValueInvalid:
79877984 return ira->codegen->invalid_inst_gen;
79887985 case OnePossibleValueYes:
7989 return ir_const_move(ira, source_instruction,
7986 return ir_const_move(ira, scope, source_node,
79907987 get_the_one_possible_value(ira->codegen, child_type));
79917988 case OnePossibleValueNo:
79927989 break;
......@@ -7995,11 +7992,11 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
79957992 if (ptr->value->special == ConstValSpecialUndef) {
79967993 // If we are in a TypeOf call, we return an undefined value instead of erroring
79977994 // since we know the type.
7998 if (get_scope_typeof(source_instruction->scope)) {
7999 return ir_const_undef(ira, source_instruction, child_type);
7995 if (get_scope_typeof(scope)) {
7996 return ir_const_undef(ira, scope, source_node, child_type);
80007997 }
80017998
8002 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));
7999 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
80038000 return ira->codegen->invalid_inst_gen;
80048001 }
80058002 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
......@@ -8008,9 +8005,9 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
80088005 child_type = pointee->type;
80098006 }
80108007 if (pointee->special != ConstValSpecialRuntime) {
8011 IrInstGen *result = ir_const(ira, source_instruction, child_type);
8008 IrInstGen *result = ir_const(ira, scope, source_node, child_type);
80128009
8013 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
8010 if ((err = ir_read_const_ptr(ira, ira->codegen, source_node, result->value,
80148011 ptr->value)))
80158012 {
80168013 return ira->codegen->invalid_inst_gen;
......@@ -8038,12 +8035,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
80388035 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
80398036 if (ptr->id == IrInstGenIdElemPtr) {
80408037 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
8041 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,
8042 elem_ptr->array_ptr, nullptr);
8038 IrInstGen *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr->scope,
8039 elem_ptr->array_ptr->source_node, elem_ptr->array_ptr, nullptr);
80438040 IrInstGen *elem_index = elem_ptr->elem_index;
8044 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);
8041 return ir_build_vector_extract_elem(ira, scope, source_node, vector_loaded, elem_index);
80458042 }
8046 ir_add_error(ira, &ptr->base,
8043 ir_add_error(ira, ptr,
80478044 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));
80488045 return ira->codegen->invalid_inst_gen;
80498046 }
......@@ -8051,7 +8048,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
80518048 IrInstGen *result_loc_inst;
80528049 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(ira->codegen, child_type)) {
80538050 if (result_loc == nullptr) result_loc = no_result_loc();
8054 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);
8051 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, child_type, nullptr, true, true);
80558052 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
80568053 return result_loc_inst;
80578054 }
......@@ -8059,7 +8056,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
80598056 result_loc_inst = nullptr;
80608057 }
80618058
8062 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
8059 return ir_build_load_ptr_gen(ira, scope, source_node, ptr, child_type, result_loc_inst);
80638060}
80648061
80658062static bool ir_resolve_const_align(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
......@@ -8110,7 +8107,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_typ
81108107 if (type_is_invalid(casted_value->value->type))
81118108 return false;
81128109
8113 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node,
8110 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
81148111 casted_value->value, out);
81158112}
81168113
......@@ -8279,7 +8276,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
82798276 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
82808277 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
82818278 if (char_val->special == ConstValSpecialUndef) {
8282 ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value"));
8279 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
82838280 return nullptr;
82848281 }
82858282 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
......@@ -8301,13 +8298,13 @@ static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira
83018298 ira->src_implicit_return_type_list.append(value);
83028299 }
83038300
8304 return ir_const_void(ira, &instruction->base.base);
8301 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
83058302}
83068303
83078304static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
83088305 if (instruction->operand == nullptr) {
83098306 // result location mechanism took care of it.
8310 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
8307 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr);
83118308 return ir_finish_anal(ira, result);
83128309 }
83138310
......@@ -8330,7 +8327,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
83308327 handle_is_ptr(ira->codegen, ira->explicit_return_type))
83318328 {
83328329 // result location mechanism took care of it.
8333 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
8330 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr);
83348331 return ir_finish_anal(ira, result);
83358332 }
83368333
......@@ -8338,16 +8335,17 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
83388335 casted_operand->value->type->id == ZigTypeIdPointer &&
83398336 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
83408337 {
8341 ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable"));
8338 ir_add_error_node(ira, instruction->operand->source_node,
8339 buf_sprintf("function returns address of local variable"));
83428340 return ir_unreach_error(ira);
83438341 }
83448342
8345 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);
8343 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, casted_operand);
83468344 return ir_finish_anal(ira, result);
83478345}
83488346
83498347static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
8350 return ir_const_move(ira, &instruction->base.base, instruction->value);
8348 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, instruction->value);
83518349}
83528350
83538351static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
......@@ -8388,11 +8386,13 @@ static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_
83888386 } else {
83898387 zig_unreachable();
83908388 }
8391 return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool);
8389 return ir_const_bool(ira, bin_op_instruction->base.scope,
8390 bin_op_instruction->base.source_node, result_bool);
83928391 }
83938392
8394 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,
8395 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
8393 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope,
8394 bin_op_instruction->base.source_node, bool_type, bin_op_instruction->op_id,
8395 casted_op1, casted_op2, bin_op_instruction->safety_check_on);
83968396}
83978397
83988398static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
......@@ -8444,12 +8444,12 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
84448444}
84458445
84468446static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
8447 ZigValue *op1_val, ZigValue *op2_val, IrInst *source_instr, IrBinOp op_id,
8447 ZigValue *op1_val, ZigValue *op2_val, Scope *scope, AstNode *source_node, IrBinOp op_id,
84488448 bool one_possible_value)
84498449{
84508450 if (op1_val->special == ConstValSpecialUndef ||
84518451 op2_val->special == ConstValSpecialUndef)
8452 return ir_const_undef(ira, source_instr, resolved_type);
8452 return ir_const_undef(ira, scope, source_node, resolved_type);
84538453 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
84548454 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
84558455 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
......@@ -8469,7 +8469,7 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
84698469 cmp_result = CmpEQ;
84708470 }
84718471 bool answer = resolve_cmp_op_id(op_id, cmp_result);
8472 return ir_const_bool(ira, source_instr, answer);
8472 return ir_const_bool(ira, scope, source_node, answer);
84738473 }
84748474 } else {
84758475 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);
......@@ -8481,12 +8481,12 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
84818481 } else {
84828482 zig_unreachable();
84838483 }
8484 return ir_const_bool(ira, source_instr, answer);
8484 return ir_const_bool(ira, scope, source_node, answer);
84858485 }
84868486 zig_unreachable();
84878487}
84888488
8489static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
8489static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2,
84908490 ZigType *resolved_type, IrBinOp op_id)
84918491{
84928492 assert(op1->value->type == resolved_type && op2->value->type == resolved_type);
......@@ -8510,8 +8510,8 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc
85108510 if (op2_val == nullptr)
85118511 return ira->codegen->invalid_inst_gen;
85128512 if (resolved_type->id != ZigTypeIdVector)
8513 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, source_instr, op_id, one_possible_value);
8514 IrInstGen *result = ir_const(ira, source_instr,
8513 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, scope, source_node, op_id, one_possible_value);
8514 IrInstGen *result = ir_const(ira, scope, source_node,
85158515 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
85168516 result->value->data.x_array.data.s_none.elements =
85178517 ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len);
......@@ -8521,7 +8521,7 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc
85218521 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
85228522 &op1_val->data.x_array.data.s_none.elements[i],
85238523 &op2_val->data.x_array.data.s_none.elements[i],
8524 source_instr, op_id, one_possible_value);
8524 scope, source_node, op_id, one_possible_value);
85258525 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value);
85268526 }
85278527 return result;
......@@ -8608,7 +8608,7 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val
86088608 zig_unreachable();
86098609}
86108610
8611static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
8611static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node,
86128612 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
86138613{
86148614 Error err;
......@@ -8616,12 +8616,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
86168616 // Before resolving the values, we special case comparisons against zero. These can often
86178617 // be done without resolving lazy values, preventing potential dependency loops.
86188618 Cmp op1_cmp_zero;
8619 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) {
8619 if ((err = lazy_cmp_zero(ira->codegen, source_node, op1_val, &op1_cmp_zero))) {
86208620 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
86218621 return ira->codegen->trace_err;
86228622 }
86238623 Cmp op2_cmp_zero;
8624 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) {
8624 if ((err = lazy_cmp_zero(ira->codegen, source_node, op2_val, &op2_cmp_zero))) {
86258625 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
86268626 return ira->codegen->trace_err;
86278627 }
......@@ -8658,12 +8658,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
86588658 }
86598659never_mind_just_calculate_it_normally:
86608660
8661 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node,
8661 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node,
86628662 op1_val, UndefOk)))
86638663 {
86648664 return ira->codegen->trace_err;
86658665 }
8666 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node,
8666 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node,
86678667 op2_val, UndefOk)))
86688668 {
86698669 return ira->codegen->trace_err;
......@@ -8686,12 +8686,12 @@ never_mind_just_calculate_it_normally:
86868686 return nullptr;
86878687 }
86888688 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
8689 IrInstGen *tmp = ir_const_noval(ira, source_instr);
8689 IrInstGen *tmp = ir_const_noval(ira, scope, source_node);
86908690 tmp->value = op1_val;
86918691 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);
86928692 op1_val = casted->value;
86938693 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {
8694 IrInstGen *tmp = ir_const_noval(ira, source_instr);
8694 IrInstGen *tmp = ir_const_noval(ira, scope, source_node);
86958695 tmp->value = op2_val;
86968696 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);
86978697 op2_val = casted->value;
......@@ -8746,7 +8746,7 @@ never_mind_just_calculate_it_normally:
87468746 return nullptr;
87478747}
87488748
8749static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,
8749static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, Scope *scope, AstNode *source_node,
87508750 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
87518751{
87528752 Error err;
......@@ -8757,7 +8757,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
87578757 ZigType *op2_scalar_type = op2->value->type;
87588758 if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) {
87598759 if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) {
8760 ir_add_error(ira, source_instr,
8760 ir_add_error_node(ira, source_node,
87618761 buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64,
87628762 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
87638763 return ira->codegen->invalid_inst_gen;
......@@ -8766,7 +8766,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
87668766 op1_scalar_type = op1->value->type->data.vector.elem_type;
87678767 op2_scalar_type = op2->value->type->data.vector.elem_type;
87688768 } else if (op1->value->type->id == ZigTypeIdVector || op2->value->type->id == ZigTypeIdVector) {
8769 ir_add_error(ira, source_instr,
8769 ir_add_error_node(ira, source_node,
87708770 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
87718771 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
87728772 return ira->codegen->invalid_inst_gen;
......@@ -8796,14 +8796,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
87968796 }
87978797 Cmp op1_cmp_zero;
87988798 bool have_op1_cmp_zero = false;
8799 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) {
8799 if ((err = lazy_cmp_zero(ira->codegen, source_node, op1->value, &op1_cmp_zero))) {
88008800 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
88018801 } else {
88028802 have_op1_cmp_zero = true;
88038803 }
88048804 Cmp op2_cmp_zero;
88058805 bool have_op2_cmp_zero = false;
8806 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) {
8806 if ((err = lazy_cmp_zero(ira->codegen, source_node, op2->value, &op2_cmp_zero))) {
88078807 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
88088808 } else {
88098809 have_op2_cmp_zero = true;
......@@ -8811,7 +8811,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88118811 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
88128812 (have_op1_cmp_zero && have_op2_cmp_zero))
88138813 {
8814 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);
8814 IrInstGen *result_instruction = ir_const(ira, scope, source_node, result_type);
88158815 ZigValue *out_val = result_instruction->value;
88168816 if (result_type->id == ZigTypeIdVector) {
88178817 size_t len = result_type->data.vector.len;
......@@ -8824,10 +8824,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88248824 ZigValue *scalar_op2_val = &op2->value->data.x_array.data.s_none.elements[i];
88258825 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
88268826 assert(scalar_out_val->type == scalar_result_type);
8827 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr,
8827 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node,
88288828 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);
88298829 if (msg != nullptr) {
8830 add_error_note(ira->codegen, msg, source_instr->source_node,
8830 add_error_note(ira->codegen, msg, source_node,
88318831 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
88328832 return ira->codegen->invalid_inst_gen;
88338833 }
......@@ -8835,7 +8835,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88358835 out_val->type = result_type;
88368836 out_val->special = ConstValSpecialStatic;
88378837 } else {
8838 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,
8838 if (ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1->value, op_id,
88398839 op2->value, out_val) != nullptr)
88408840 {
88418841 return ira->codegen->invalid_inst_gen;
......@@ -8853,9 +8853,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88538853 // 0 > unsigned_x // false
88548854 switch (op_id) {
88558855 case IrBinOpCmpLessOrEq:
8856 return ir_const_bool(ira, source_instr, true);
8856 return ir_const_bool(ira, scope, source_node, true);
88578857 case IrBinOpCmpGreaterThan:
8858 return ir_const_bool(ira, source_instr, false);
8858 return ir_const_bool(ira, scope, source_node, false);
88598859 default:
88608860 break;
88618861 }
......@@ -8870,11 +8870,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88708870 case IrBinOpCmpNotEq:
88718871 case IrBinOpCmpLessOrEq:
88728872 case IrBinOpCmpLessThan:
8873 return ir_const_bool(ira, source_instr, true);
8873 return ir_const_bool(ira, scope, source_node, true);
88748874 case IrBinOpCmpEq:
88758875 case IrBinOpCmpGreaterOrEq:
88768876 case IrBinOpCmpGreaterThan:
8877 return ir_const_bool(ira, source_instr, false);
8877 return ir_const_bool(ira, scope, source_node, false);
88788878 default:
88798879 break;
88808880 }
......@@ -8886,9 +8886,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
88868886 // unsigned_x >= 0 // true
88878887 switch (op_id) {
88888888 case IrBinOpCmpLessThan:
8889 return ir_const_bool(ira, source_instr, false);
8889 return ir_const_bool(ira, scope, source_node, false);
88908890 case IrBinOpCmpGreaterOrEq:
8891 return ir_const_bool(ira, source_instr, true);
8891 return ir_const_bool(ira, scope, source_node, true);
88928892 default:
88938893 break;
88948894 }
......@@ -8903,11 +8903,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
89038903 case IrBinOpCmpNotEq:
89048904 case IrBinOpCmpGreaterOrEq:
89058905 case IrBinOpCmpGreaterThan:
8906 return ir_const_bool(ira, source_instr, true);
8906 return ir_const_bool(ira, scope, source_node, true);
89078907 case IrBinOpCmpEq:
89088908 case IrBinOpCmpLessThan:
89098909 case IrBinOpCmpLessOrEq:
8910 return ir_const_bool(ira, source_instr, false);
8910 return ir_const_bool(ira, scope, source_node, false);
89118911 default:
89128912 break;
89138913 }
......@@ -8936,7 +8936,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
89368936 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
89378937 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))
89388938 return ira->codegen->invalid_inst_gen;
8939 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
8939 return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true);
89408940 }
89418941
89428942 // For mixed unsigned integer sizes, implicit cast both operands to the larger integer.
......@@ -8967,7 +8967,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
89678967 if (op1_val == nullptr)
89688968 return ira->codegen->invalid_inst_gen;
89698969 if (op1_val->special == ConstValSpecialUndef)
8970 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
8970 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
89718971 bool is_unsigned;
89728972 if (op1_is_float) {
89738973 BigInt bigint = {};
......@@ -8975,7 +8975,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
89758975 Cmp zcmp = float_cmp_zero(op1_val);
89768976 if (float_has_fraction(op1_val)) {
89778977 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {
8978 return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq);
8978 return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq);
89798979 }
89808980 if (zcmp == CmpLT) {
89818981 bigint_decr(&bigint);
......@@ -8993,10 +8993,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
89938993 op1_bits += 1;
89948994 }
89958995 } else if (op1_is_float) {
8996 ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);
8996 src_assert(op1_scalar_type->id == ZigTypeIdFloat, source_node);
89978997 dest_float_type = op1_scalar_type;
89988998 } else {
8999 ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);
8999 src_assert(op1_scalar_type->id == ZigTypeIdInt, source_node);
90009000 op1_bits = op1_scalar_type->data.integral.bit_count;
90019001 if (!op1_scalar_type->data.integral.is_signed && dest_int_is_signed) {
90029002 op1_bits += 1;
......@@ -9008,7 +9008,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
90089008 if (op2_val == nullptr)
90099009 return ira->codegen->invalid_inst_gen;
90109010 if (op2_val->special == ConstValSpecialUndef)
9011 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
9011 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
90129012 bool is_unsigned;
90139013 if (op2_is_float) {
90149014 BigInt bigint = {};
......@@ -9016,7 +9016,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
90169016 Cmp zcmp = float_cmp_zero(op2_val);
90179017 if (float_has_fraction(op2_val)) {
90189018 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {
9019 return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq);
9019 return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq);
90209020 }
90219021 if (zcmp == CmpLT) {
90229022 bigint_decr(&bigint);
......@@ -9034,10 +9034,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
90349034 op2_bits += 1;
90359035 }
90369036 } else if (op2_is_float) {
9037 ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);
9037 src_assert(op2_scalar_type->id == ZigTypeIdFloat, source_node);
90389038 dest_float_type = op2_scalar_type;
90399039 } else {
9040 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);
9040 src_assert(op2_scalar_type->id == ZigTypeIdInt, source_node);
90419041 op2_bits = op2_scalar_type->data.integral.bit_count;
90429042 if (!op2_scalar_type->data.integral.is_signed && dest_int_is_signed) {
90439043 op2_bits += 1;
......@@ -9055,7 +9055,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
90559055 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
90569056 if (type_is_invalid(casted_op2->value->type))
90579057 return ira->codegen->invalid_inst_gen;
9058 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
9058 return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true);
90599059}
90609060
90619061static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {
......@@ -9106,7 +9106,7 @@ static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {
91069106 zig_unreachable();
91079107}
91089108
9109static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type,
9109static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type,
91109110 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)
91119111{
91129112 assert(optional->value->type->id == ZigTypeIdOptional);
......@@ -9126,22 +9126,22 @@ static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira
91269126 }
91279127
91289128 if (!optional_value_is_null(optional_val)) {
9129 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false);
9129 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false);
91309130 if (type_is_invalid(optional_unwrapped->value->type)) {
91319131 return ira->codegen->invalid_inst_gen;
91329132 }
91339133
9134 IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, source_instr, optional_unwrapped, non_optional, child_type, op_id);
9134 IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, scope, source_node, optional_unwrapped, non_optional, child_type, op_id);
91359135 assert(ret != nullptr);
91369136 return ret;
91379137 }
9138 return ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq));
9138 return ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq));
91399139 } else {
91409140 return nullptr;
91419141 }
91429142}
91439143
9144static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type,
9144static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type,
91459145 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)
91469146{
91479147 assert(optional->value->type->id == ZigTypeIdOptional);
......@@ -9152,26 +9152,26 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *
91529152 ZigType *result_type = ira->codegen->builtin_types.entry_bool;
91539153 ir_append_basic_block_gen(&ira->new_irb, ira->new_irb.current_basic_block);
91549154
9155 IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNull");
9156 IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNotNull");
9157 IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalEnd");
9155 IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNull");
9156 IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNotNull");
9157 IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalEnd");
91589158
9159 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, source_instr, optional);
9160 ir_build_cond_br_gen(ira, source_instr, is_non_null, non_null_block, null_block);
9159 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, scope, source_node, optional);
9160 ir_build_cond_br_gen(ira, scope, source_node, is_non_null, non_null_block, null_block);
91619161
91629162 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, non_null_block);
9163 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false);
9163 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false);
91649164 if (type_is_invalid(optional_unwrapped->value->type)) {
91659165 return ira->codegen->invalid_inst_gen;
91669166 }
9167 IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, source_instr, result_type, op_id,
9167 IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id,
91689168 optional_unwrapped, non_optional, false); // safety check unnecessary for comparison operators
9169 ir_build_br_gen(ira, source_instr, end_block);
9169 ir_build_br_gen(ira, scope, source_node, end_block);
91709170
91719171
91729172 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, null_block);
9173 IrInstGen *null_result = ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq));
9174 ir_build_br_gen(ira, source_instr, end_block);
9173 IrInstGen *null_result = ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq));
9174 ir_build_br_gen(ira, scope, source_node, end_block);
91759175
91769176 ir_set_cursor_at_end_gen(&ira->new_irb, end_block);
91779177 int incoming_count = 2;
......@@ -9182,10 +9182,10 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *
91829182 incoming_values[0] = null_result;
91839183 incoming_values[1] = non_null_cmp_result;
91849184
9185 return ir_build_phi_gen(ira, source_instr, incoming_count, incoming_blocks, incoming_values, result_type);
9185 return ir_build_phi_gen(ira, scope, source_node, incoming_count, incoming_blocks, incoming_values, result_type);
91869186}
91879187
9188static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr,
9188static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node,
91899189 IrInstGen *op1, IrInstGen *op2, IrInstGen *optional, IrBinOp op_id)
91909190{
91919191 assert(op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
......@@ -9204,22 +9204,22 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s
92049204 ZigType *child_type = optional->value->type->data.maybe.child_type;
92059205 bool child_type_matches = (child_type == non_optional->value->type);
92069206 if (!child_type_matches || !type_is_self_comparable(child_type, true)) {
9207 ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node, buf_sprintf("cannot compare types '%s' and '%s'",
9207 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cannot compare types '%s' and '%s'",
92089208 buf_ptr(&op1->value->type->name),
92099209 buf_ptr(&op2->value->type->name)));
92109210
92119211 if (!child_type_matches) {
92129212 if (non_optional->value->type->id == ZigTypeIdOptional) {
9213 add_error_note(ira->codegen, msg, source_instr->source_node, buf_sprintf(
9213 add_error_note(ira->codegen, msg, source_node, buf_sprintf(
92149214 "optional to optional comparison is only supported for optional pointer types"));
92159215 } else {
9216 add_error_note(ira->codegen, msg, source_instr->source_node,
9216 add_error_note(ira->codegen, msg, source_node,
92179217 buf_sprintf("optional child type '%s' must be the same as non-optional type '%s'",
92189218 buf_ptr(&child_type->name),
92199219 buf_ptr(&non_optional->value->type->name)));
92209220 }
92219221 } else {
9222 add_error_note(ira->codegen, msg, source_instr->source_node,
9222 add_error_note(ira->codegen, msg, source_node,
92239223 buf_sprintf("operator not supported for type '%s'",
92249224 buf_ptr(&child_type->name)));
92259225 }
......@@ -9227,17 +9227,17 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s
92279227 }
92289228
92299229 if (child_type->id == ZigTypeIdVector) {
9230 ir_add_error_node(ira, source_instr->source_node, buf_sprintf("TODO add comparison of optional vector"));
9230 ir_add_error_node(ira, source_node, buf_sprintf("TODO add comparison of optional vector"));
92319231 return ira->codegen->invalid_inst_gen;
92329232 }
92339233
9234 if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, source_instr, child_type,
9234 if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, scope, source_node, child_type,
92359235 optional, non_optional, op_id))
92369236 {
92379237 return const_result;
92389238 }
92399239
9240 return ir_evaluate_cmp_optional_non_optional(ira, source_instr, child_type, optional, non_optional, op_id);
9240 return ir_evaluate_cmp_optional_non_optional(ira, scope, source_node, child_type, optional, non_optional, op_id);
92419241}
92429242
92439243static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
......@@ -9249,12 +9249,13 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
92499249 if (type_is_invalid(op2->value->type))
92509250 return ira->codegen->invalid_inst_gen;
92519251
9252 AstNode *source_node = bin_op_instruction->base.base.source_node;
9252 AstNode *source_node = bin_op_instruction->base.source_node;
92539253
92549254 IrBinOp op_id = bin_op_instruction->op_id;
92559255 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
92569256 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
9257 return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq));
9257 return ir_const_bool(ira, bin_op_instruction->base.scope,
9258 bin_op_instruction->base.source_node, (op_id == IrBinOpCmpEq));
92589259 } else if (is_equality_cmp &&
92599260 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
92609261 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
......@@ -9273,13 +9274,16 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
92739274 return ira->codegen->invalid_inst_gen;
92749275 bool is_null = optional_value_is_null(maybe_val);
92759276 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
9276 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
9277 return ir_const_bool(ira, bin_op_instruction->base.scope,
9278 bin_op_instruction->base.source_node, bool_result);
92779279 }
92789280
9279 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);
9281 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope,
9282 bin_op_instruction->base.source_node, maybe_op);
92809283
92819284 if (op_id == IrBinOpCmpEq) {
9282 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
9285 return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope,
9286 bin_op_instruction->base.source_node, is_non_null);
92839287 } else {
92849288 return is_non_null;
92859289 }
......@@ -9302,28 +9306,28 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
93029306 if (!c_ptr_val)
93039307 return ira->codegen->invalid_inst_gen;
93049308 if (c_ptr_val->special == ConstValSpecialUndef)
9305 return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool);
9309 return ir_const_undef(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool);
93069310 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
93079311 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
93089312 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
93099313 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
9310 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
9314 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result);
93119315 }
9312 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);
9316 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, c_ptr_op);
93139317
93149318 if (op_id == IrBinOpCmpEq) {
9315 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
9319 return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, is_non_null);
93169320 } else {
93179321 return is_non_null;
93189322 }
93199323 } else if (is_equality_cmp &&
93209324 (op1->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op1->value->type) == nullptr))
93219325 {
9322 return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op1, op_id);
9326 return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op1, op_id);
93239327 } else if(is_equality_cmp &&
93249328 (op2->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op2->value->type) == nullptr))
93259329 {
9326 return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op2, op_id);
9330 return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op2, op_id);
93279331 } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) {
93289332 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
93299333 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
......@@ -9369,10 +9373,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
93699373 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
93709374 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
93719375
9372 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
9376 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result);
93739377 }
93749378
9375 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
9379 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool,
93769380 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
93779381 }
93789382
......@@ -9404,7 +9408,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94049408 } else {
94059409 zig_unreachable();
94069410 }
9407 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
9411 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
94089412 }
94099413
94109414 if (!type_is_global_error_set(intersect_type)) {
......@@ -9424,7 +9428,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94249428 } else {
94259429 zig_unreachable();
94269430 }
9427 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
9431 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
94289432 }
94299433 }
94309434
......@@ -9446,10 +9450,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94469450 zig_unreachable();
94479451 }
94489452
9449 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
9453 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
94509454 }
94519455
9452 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
9456 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool,
94539457 op_id, op1, op2, bin_op_instruction->safety_check_on);
94549458 }
94559459
......@@ -9457,7 +9461,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94579461 // This operation allows any combination of integer and float types, regardless of the
94589462 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
94599463 // numeric types.
9460 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id);
9464 return ir_analyze_bin_op_cmp_numeric(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op_id);
94619465 }
94629466
94639467 IrInstGen *instructions[] = {op1, op2};
......@@ -9481,7 +9485,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94819485 if (type_is_invalid(casted_op2->value->type))
94829486 return ira->codegen->invalid_inst_gen;
94839487
9484 IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, &bin_op_instruction->base.base, casted_op1,
9488 IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, casted_op1,
94859489 casted_op2, resolved_type, op_id);
94869490 if (resolve_const_result != nullptr) {
94879491 return resolve_const_result;
......@@ -9490,11 +9494,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
94909494 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
94919495 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :
94929496 ira->codegen->builtin_types.entry_bool;
9493 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type,
9497 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, res_type,
94949498 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
94959499}
94969500
9497static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
9501static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry,
94989502 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
94999503{
95009504 bool is_int;
......@@ -9517,10 +9521,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
95179521 if ((op_id == IrBinOpDivUnspecified || op_id == IrBinOpRemRem || op_id == IrBinOpRemMod ||
95189522 op_id == IrBinOpDivTrunc || op_id == IrBinOpDivFloor) && op2_zcmp == CmpEQ)
95199523 {
9520 return ir_add_error(ira, source_instr, buf_sprintf("division by zero"));
9524 return ir_add_error_node(ira, source_node, buf_sprintf("division by zero"));
95219525 }
95229526 if ((op_id == IrBinOpRemRem || op_id == IrBinOpRemMod) && op2_zcmp == CmpLT) {
9523 return ir_add_error(ira, source_instr, buf_sprintf("negative denominator"));
9527 return ir_add_error_node(ira, source_node, buf_sprintf("negative denominator"));
95249528 }
95259529
95269530 switch (op_id) {
......@@ -9565,7 +9569,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
95659569 BigInt orig_bigint;
95669570 bigint_shl(&orig_bigint, &out_val->data.x_bigint, &op2_val->data.x_bigint);
95679571 if (bigint_cmp(&op1_val->data.x_bigint, &orig_bigint) != CmpEQ) {
9568 return ir_add_error(ira, source_instr, buf_sprintf("exact shift shifted out 1 bits"));
9572 return ir_add_error_node(ira, source_node, buf_sprintf("exact shift shifted out 1 bits"));
95699573 }
95709574 break;
95719575 }
......@@ -9633,14 +9637,14 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
96339637 BigInt remainder;
96349638 bigint_rem(&remainder, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
96359639 if (bigint_cmp_zero(&remainder) != CmpEQ) {
9636 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));
9640 return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder"));
96379641 }
96389642 } else {
96399643 float_div_trunc(out_val, op1_val, op2_val);
96409644 ZigValue remainder = {};
96419645 float_rem(&remainder, op1_val, op2_val);
96429646 if (float_cmp_zero(&remainder) != CmpEQ) {
9643 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));
9647 return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder"));
96449648 }
96459649 }
96469650 break;
......@@ -9664,7 +9668,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
96649668 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
96659669 type_entry->data.integral.is_signed))
96669670 {
9667 return ir_add_error(ira, source_instr, buf_sprintf("operation caused overflow"));
9671 return ir_add_error_node(ira, source_node, buf_sprintf("operation caused overflow"));
96689672 }
96699673 }
96709674
......@@ -9674,10 +9678,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
96749678}
96759679
96769680// This works on operands that have already been checked to be comptime known.
9677static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
9681static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, Scope *scope, AstNode *source_node,
96789682 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
96799683{
9680 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);
9684 IrInstGen *result_instruction = ir_const(ira, scope, source_node, type_entry);
96819685 ZigValue *out_val = result_instruction->value;
96829686 if (type_entry->id == ZigTypeIdVector) {
96839687 expand_undef_array(ira->codegen, op1_val);
......@@ -9692,10 +9696,10 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
96929696 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
96939697 assert(scalar_op1_val->type == scalar_type);
96949698 assert(scalar_out_val->type == scalar_type);
9695 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,
9699 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
96969700 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);
96979701 if (msg != nullptr) {
9698 add_error_note(ira->codegen, msg, source_instr->source_node,
9702 add_error_note(ira->codegen, msg, source_node,
96999703 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
97009704 return ira->codegen->invalid_inst_gen;
97019705 }
......@@ -9703,7 +9707,7 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
97039707 out_val->type = type_entry;
97049708 out_val->special = ConstValSpecialStatic;
97059709 } else {
9706 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
9710 if (ir_eval_math_op_scalar(ira, scope, source_node, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
97079711 return ira->codegen->invalid_inst_gen;
97089712 }
97099713 }
......@@ -9723,14 +9727,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
97239727 ZigType *op2_type = op2->value->type;
97249728
97259729 if (op1_type->id == ZigTypeIdVector && op2_type->id != ZigTypeIdVector) {
9726 ir_add_error(ira, &bin_op_instruction->op1->base,
9730 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
97279731 buf_sprintf("bit shifting operation expected vector type, found '%s'",
97289732 buf_ptr(&op2_type->name)));
97299733 return ira->codegen->invalid_inst_gen;
97309734 }
97319735
97329736 if (op1_type->id != ZigTypeIdVector && op2_type->id == ZigTypeIdVector) {
9733 ir_add_error(ira, &bin_op_instruction->op1->base,
9737 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
97349738 buf_sprintf("bit shifting operation expected vector type, found '%s'",
97359739 buf_ptr(&op1_type->name)));
97369740 return ira->codegen->invalid_inst_gen;
......@@ -9742,14 +9746,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
97429746 op2_type->data.vector.elem_type : op2_type;
97439747
97449748 if (op1_scalar_type->id != ZigTypeIdInt && op1_scalar_type->id != ZigTypeIdComptimeInt) {
9745 ir_add_error(ira, &bin_op_instruction->op1->base,
9749 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
97469750 buf_sprintf("bit shifting operation expected integer type, found '%s'",
97479751 buf_ptr(&op1_scalar_type->name)));
97489752 return ira->codegen->invalid_inst_gen;
97499753 }
97509754
97519755 if (op2_scalar_type->id != ZigTypeIdInt && op2_scalar_type->id != ZigTypeIdComptimeInt) {
9752 ir_add_error(ira, &bin_op_instruction->op2->base,
9756 ir_add_error_node(ira, bin_op_instruction->op2->source_node,
97539757 buf_sprintf("shift amount has to be an integer type, but found '%s'",
97549758 buf_ptr(&op2_scalar_type->name)));
97559759 return ira->codegen->invalid_inst_gen;
......@@ -9766,7 +9770,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
97669770 }
97679771
97689772 if (!instr_is_comptime(op2)) {
9769 ir_add_error(ira, &bin_op_instruction->base.base,
9773 ir_add_error_node(ira, bin_op_instruction->base.source_node,
97709774 buf_sprintf("LHS of shift must be a fixed-width integer type, or RHS must be compile-time known"));
97719775 return ira->codegen->invalid_inst_gen;
97729776 }
......@@ -9778,7 +9782,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
97789782 if (op2_val->data.x_bigint.is_negative) {
97799783 Buf *val_buf = buf_alloc();
97809784 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
9781 ir_add_error(ira, &casted_op2->base,
9785 ir_add_error(ira, casted_op2,
97829786 buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
97839787 return ira->codegen->invalid_inst_gen;
97849788 }
......@@ -9806,10 +9810,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
98069810 init_const_usize(ira->codegen, &bit_count_value, bit_count);
98079811
98089812 if (!value_cmp_numeric_val_all(op2_val, CmpLT, &bit_count_value)) {
9809 ErrorMsg* msg = ir_add_error(ira,
9810 &bin_op_instruction->base.base,
9813 ErrorMsg* msg = ir_add_error_node(ira,
9814 bin_op_instruction->base.source_node,
98119815 buf_sprintf("RHS of shift is too large for LHS type"));
9812 add_error_note(ira->codegen, msg, op1->base.source_node,
9816 add_error_note(ira->codegen, msg, op1->source_node,
98139817 buf_sprintf("type %s has only %u bits",
98149818 buf_ptr(&op1->value->type->name), bit_count));
98159819
......@@ -9825,7 +9829,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
98259829 return ira->codegen->invalid_inst_gen;
98269830
98279831 if (value_cmp_numeric_val_all(op2_val, CmpEQ, nullptr))
9828 return ir_analyze_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1);
9832 return ir_analyze_cast(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type, op1);
98299833 }
98309834
98319835 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
......@@ -9837,10 +9841,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
98379841 if (op2_val == nullptr)
98389842 return ira->codegen->invalid_inst_gen;
98399843
9840 return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1_type, op1_val, op_id, op2_val);
9844 return ir_analyze_math_op(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1_type, op1_val, op_id, op2_val);
98419845 }
98429846
9843 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,
9847 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type,
98449848 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
98459849}
98469850
......@@ -10006,14 +10010,14 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1000610010 if (op1_val == nullptr)
1000710011 return ira->codegen->invalid_inst_gen;
1000810012 if (op1_val->special == ConstValSpecialUndef)
10009 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
10013 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type);
1001010014 }
1001110015 if (instr_is_comptime(casted_op2)) {
1001210016 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
1001310017 if (op2_val == nullptr)
1001410018 return ira->codegen->invalid_inst_gen;
1001510019 if (op2_val->special == ConstValSpecialUndef)
10016 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
10020 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type);
1001710021 }
1001810022
1001910023 ZigType *elem_type = op1->value->type->data.pointer.child_type;
......@@ -10069,18 +10073,18 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1006910073 } else {
1007010074 zig_unreachable();
1007110075 }
10072 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
10076 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
1007310077 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1007410078 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
1007510079 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
1007610080 return result;
1007710081 }
1007810082
10079 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);
10083 return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, result_type, op_id, op1, casted_op2, true);
1008010084 }
1008110085
1008210086 IrInstGen *instructions[] = {op1, op2};
10083 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);
10087 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);
1008410088 if (type_is_invalid(resolved_type))
1008510089 return ira->codegen->invalid_inst_gen;
1008610090
......@@ -10091,7 +10095,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1009110095 bool is_float = scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat;
1009210096
1009310097 if (!is_int && !(is_float && ok_float_op(op_id))) {
10094 AstNode *source_node = instruction->base.base.source_node;
10098 AstNode *source_node = instruction->base.source_node;
1009510099 ir_add_error_node(ira, source_node,
1009610100 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
1009710101 buf_ptr(&op1->value->type->name),
......@@ -10144,17 +10148,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1014410148 // division function ambiguity problem.
1014510149 ok = true;
1014610150 } else {
10147 IrInstGen *trunc_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,
10151 IrInstGen *trunc_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
1014810152 op1_val, IrBinOpDivTrunc, op2_val);
1014910153 if (type_is_invalid(trunc_val->value->type))
1015010154 return ira->codegen->invalid_inst_gen;
1015110155
10152 IrInstGen *floor_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,
10156 IrInstGen *floor_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
1015310157 op1_val, IrBinOpDivFloor, op2_val);
1015410158 if (type_is_invalid(floor_val->value->type))
1015510159 return ira->codegen->invalid_inst_gen;
1015610160
10157 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base,
10161 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node,
1015810162 trunc_val, floor_val, IrBinOpCmpEq);
1015910163 if (type_is_invalid(cmp_val->value->type))
1016010164 return ira->codegen->invalid_inst_gen;
......@@ -10165,7 +10169,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1016510169 }
1016610170
1016710171 if (!ok) {
10168 ir_add_error(ira, &instruction->base.base,
10172 ir_add_error_node(ira, instruction->base.source_node,
1016910173 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
1017010174 buf_ptr(&op1->value->type->name),
1017110175 buf_ptr(&op2->value->type->name)));
......@@ -10183,17 +10187,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1018310187 // division function ambiguity problem.
1018410188 ok = true;
1018510189 } else {
10186 IrInstGen *rem_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,
10190 IrInstGen *rem_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
1018710191 op1_val, IrBinOpRemRem, op2_val);
1018810192 if (type_is_invalid(rem_val->value->type))
1018910193 return ira->codegen->invalid_inst_gen;
1019010194
10191 IrInstGen *mod_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,
10195 IrInstGen *mod_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
1019210196 op1_val, IrBinOpRemMod, op2_val);
1019310197 if (type_is_invalid(mod_val->value->type))
1019410198 return ira->codegen->invalid_inst_gen;
1019510199
10196 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base,
10200 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node,
1019710201 rem_val, mod_val, IrBinOpCmpEq);
1019810202 if (type_is_invalid(cmp_val->value->type))
1019910203 return ira->codegen->invalid_inst_gen;
......@@ -10204,7 +10208,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1020410208 }
1020510209
1020610210 if (!ok) {
10207 ir_add_error(ira, &instruction->base.base,
10211 ir_add_error_node(ira, instruction->base.source_node,
1020810212 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
1020910213 buf_ptr(&op1->value->type->name),
1021010214 buf_ptr(&op2->value->type->name)));
......@@ -10213,7 +10217,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1021310217 }
1021410218 }
1021510219
10216 return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val);
10220 return ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, op1_val, op_id, op2_val);
1021710221 }
1021810222
1021910223 const bool is_signed_div =
......@@ -10225,7 +10229,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1022510229 op_id = IrBinOpDivTrunc;
1022610230
1022710231 if (is_signed_div) {
10228 ir_add_error(ira, &instruction->base.base,
10232 ir_add_error_node(ira, instruction->base.source_node,
1022910233 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
1023010234 buf_ptr(&op1->value->type->name),
1023110235 buf_ptr(&op2->value->type->name)));
......@@ -10235,7 +10239,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1023510239 op_id = IrBinOpRemRem;
1023610240
1023710241 if (is_signed_div) {
10238 ir_add_error(ira, &instruction->base.base,
10242 ir_add_error_node(ira, instruction->base.source_node,
1023910243 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
1024010244 buf_ptr(&op1->value->type->name),
1024110245 buf_ptr(&op2->value->type->name)));
......@@ -10243,11 +10247,11 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
1024310247 }
1024410248 }
1024510249
10246 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,
10250 return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
1024710251 op_id, casted_op1, casted_op2, instruction->safety_check_on);
1024810252}
1024910253
10250static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
10254static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1025110255 IrInstGen *op1, IrInstGen *op2)
1025210256{
1025310257 Error err;
......@@ -10259,9 +10263,9 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
1025910263
1026010264 Buf *bare_name = buf_alloc();
1026110265 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
10262 source_instr->scope, source_instr->source_node, bare_name);
10263 ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope,
10264 ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
10266 scope, source_node, bare_name);
10267 ZigType *new_type = get_partial_container_type(ira->codegen, scope,
10268 ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
1026510269 new_type->data.structure.special = StructSpecialInferredTuple;
1026610270 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
1026710271 uint32_t new_field_count = op1_field_count + op2_field_count;
......@@ -10270,7 +10274,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
1027010274 new_type->data.structure.fields = realloc_type_struct_fields(new_type->data.structure.fields,
1027110275 0, new_field_count);
1027210276
10273 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
10277 IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
1027410278 new_type, nullptr, false, true);
1027510279
1027610280 for (uint32_t i = 0; i < new_field_count; i += 1) {
......@@ -10304,18 +10308,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
1030410308 src_field = op2_type->data.structure.fields[i - op1_field_count];
1030510309 src_struct_op = op2;
1030610310 }
10307 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
10311 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, scope, source_node,
1030810312 src_struct_op, src_field);
1030910313 if (type_is_invalid(field_value->value->type))
1031010314 return ira->codegen->invalid_inst_gen;
10311 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
10315 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, dst_field,
1031210316 new_struct_ptr, new_type, true);
1031310317 if (type_is_invalid(dest_ptr->value->type))
1031410318 return ira->codegen->invalid_inst_gen;
1031510319 if (instr_is_comptime(field_value)) {
1031610320 const_ptrs.append(dest_ptr);
1031710321 }
10318 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
10322 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, dest_ptr, field_value,
1031910323 true);
1032010324 if (type_is_invalid(store_ptr_inst->value->type))
1032110325 return ira->codegen->invalid_inst_gen;
......@@ -10329,17 +10333,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
1032910333 // This field will be generated comptime; no need to do this.
1033010334 continue;
1033110335 }
10332 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
10336 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
10337 elem_result_loc->source_node, elem_result_loc, nullptr);
1033310338 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {
1033410339 elem_result_loc->value->special = ConstValSpecialRuntime;
1033510340 }
10336 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, true);
10341 ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node, elem_result_loc, deref, true);
1033710342 }
1033810343 }
1033910344
1034010345 const_ptrs.deinit();
1034110346
10342 return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
10347 return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr);
1034310348}
1034410349
1034510350static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
......@@ -10354,7 +10359,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1035410359 return ira->codegen->invalid_inst_gen;
1035510360
1035610361 if (is_tuple(op1_type) && is_tuple(op2_type)) {
10357 return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2);
10362 return ir_analyze_tuple_cat(ira, instruction->base.scope, instruction->base.source_node, op1, op2);
1035810363 }
1035910364
1036010365 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
......@@ -10402,14 +10407,14 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1040210407 {
1040310408 ZigType *array_type = op1_type->data.pointer.child_type;
1040410409 child_type = array_type->data.array.child_type;
10405 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node);
10410 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);
1040610411 if (op1_array_val == nullptr)
1040710412 return ira->codegen->invalid_inst_gen;
1040810413 op1_array_index = 0;
1040910414 op1_array_end = array_type->data.array.len;
1041010415 sentinel1 = array_type->data.array.sentinel;
1041110416 } else {
10412 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
10417 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
1041310418 return ira->codegen->invalid_inst_gen;
1041410419 }
1041510420
......@@ -10450,7 +10455,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1045010455 {
1045110456 ZigType *array_type = op2_type->data.pointer.child_type;
1045210457 op2_type_valid = array_type->data.array.child_type == child_type;
10453 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node);
10458 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);
1045410459 if (op2_array_val == nullptr)
1045510460 return ira->codegen->invalid_inst_gen;
1045610461 op2_array_index = 0;
......@@ -10458,12 +10463,12 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1045810463
1045910464 sentinel2 = array_type->data.array.sentinel;
1046010465 } else {
10461 ir_add_error(ira, &op2->base,
10466 ir_add_error(ira, op2,
1046210467 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
1046310468 return ira->codegen->invalid_inst_gen;
1046410469 }
1046510470 if (!op2_type_valid) {
10466 ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'",
10471 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
1046710472 buf_ptr(&child_type->name),
1046810473 buf_ptr(&op2->value->type->name)));
1046910474 return ira->codegen->invalid_inst_gen;
......@@ -10483,7 +10488,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1048310488 }
1048410489
1048510490 // The type of result is populated in the following if blocks
10486 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
10491 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1048710492 ZigValue *out_val = result->value;
1048810493
1048910494 ZigValue *out_array_val;
......@@ -10571,7 +10576,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1057110576 return result;
1057210577}
1057310578
10574static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
10579static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1057510580 IrInstGen *op1, IrInstGen *op2)
1057610581{
1057710582 Error err;
......@@ -10584,22 +10589,22 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1058410589
1058510590 uint64_t new_field_count;
1058610591 if (mul_u64_overflow(op1_field_count, mult_amt, &new_field_count)) {
10587 ir_add_error(ira, source_instr, buf_sprintf("operation results in overflow"));
10592 ir_add_error_node(ira, source_node, buf_sprintf("operation results in overflow"));
1058810593 return ira->codegen->invalid_inst_gen;
1058910594 }
1059010595
1059110596 Buf *bare_name = buf_alloc();
1059210597 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
10593 source_instr->scope, source_instr->source_node, bare_name);
10594 ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope,
10595 ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
10598 scope, source_node, bare_name);
10599 ZigType *new_type = get_partial_container_type(ira->codegen, scope,
10600 ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
1059610601 new_type->data.structure.special = StructSpecialInferredTuple;
1059710602 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
1059810603 new_type->data.structure.src_field_count = new_field_count;
1059910604 new_type->data.structure.fields = realloc_type_struct_fields(
1060010605 new_type->data.structure.fields, 0, new_field_count);
1060110606
10602 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
10607 IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
1060310608 new_type, nullptr, false, true);
1060410609
1060510610 for (uint64_t i = 0; i < new_field_count; i += 1) {
......@@ -10624,12 +10629,12 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1062410629 TypeStructField *dst_field = new_type->data.structure.fields[i];
1062510630
1062610631 IrInstGen *field_value = ir_analyze_struct_value_field_value(
10627 ira, source_instr, op1, src_field);
10632 ira, scope, source_node, op1, src_field);
1062810633 if (type_is_invalid(field_value->value->type))
1062910634 return ira->codegen->invalid_inst_gen;
1063010635
1063110636 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(
10632 ira, source_instr, dst_field, new_struct_ptr, new_type, true);
10637 ira, scope, source_node, dst_field, new_struct_ptr, new_type, true);
1063310638 if (type_is_invalid(dest_ptr->value->type))
1063410639 return ira->codegen->invalid_inst_gen;
1063510640
......@@ -10638,7 +10643,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1063810643 }
1063910644
1064010645 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(
10641 ira, source_instr, dest_ptr, field_value, true);
10646 ira, scope, source_node, dest_ptr, field_value, true);
1064210647 if (type_is_invalid(store_ptr_inst->value->type))
1064310648 return ira->codegen->invalid_inst_gen;
1064410649 }
......@@ -10652,12 +10657,13 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1065210657 // This field will be generated comptime; no need to do this.
1065310658 continue;
1065410659 }
10655 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
10660 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
10661 elem_result_loc->source_node, elem_result_loc, nullptr);
1065610662 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {
1065710663 elem_result_loc->value->special = ConstValSpecialRuntime;
1065810664 }
10659 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(
10660 ira, &elem_result_loc->base, elem_result_loc, deref, true);
10665 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, elem_result_loc->scope,
10666 elem_result_loc->source_node, elem_result_loc, deref, true);
1066110667 if (type_is_invalid(store_ptr_inst->value->type))
1066210668 return ira->codegen->invalid_inst_gen;
1066310669 }
......@@ -10665,7 +10671,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1066510671
1066610672 const_ptrs.deinit();
1066710673
10668 return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
10674 return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr);
1066910675}
1067010676
1067110677static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
......@@ -10690,7 +10696,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1069010696 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
1069110697 {
1069210698 array_type = op1->value->type->data.pointer.child_type;
10693 IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr);
10699 IrInstGen *array_inst = ir_get_deref(ira, op1->scope, op1->source_node, op1, nullptr);
1069410700 if (type_is_invalid(array_inst->value->type))
1069510701 return ira->codegen->invalid_inst_gen;
1069610702 array_val = ir_resolve_const(ira, array_inst, UndefOk);
......@@ -10698,9 +10704,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1069810704 return ira->codegen->invalid_inst_gen;
1069910705 want_ptr_to_array = true;
1070010706 } else if (is_tuple(op1->value->type)) {
10701 return ir_analyze_tuple_mult(ira, &instruction->base.base, op1, op2);
10707 return ir_analyze_tuple_mult(ira, instruction->base.scope, instruction->base.source_node, op1, op2);
1070210708 } else {
10703 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
10709 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
1070410710 return ira->codegen->invalid_inst_gen;
1070510711 }
1070610712
......@@ -10712,7 +10718,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1071210718 uint64_t new_array_len;
1071310719
1071410720 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {
10715 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));
10721 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("operation results in overflow"));
1071610722 return ira->codegen->invalid_inst_gen;
1071710723 }
1071810724
......@@ -10722,9 +10728,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1072210728
1072310729 IrInstGen *array_result;
1072410730 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
10725 array_result = ir_const_undef(ira, &instruction->base.base, result_array_type);
10731 array_result = ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, result_array_type);
1072610732 } else {
10727 array_result = ir_const(ira, &instruction->base.base, result_array_type);
10733 array_result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_array_type);
1072810734 ZigValue *out_val = array_result->value;
1072910735
1073010736 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
......@@ -10765,7 +10771,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1076510771 }
1076610772skip_computation:
1076710773 if (want_ptr_to_array) {
10768 return ir_get_ref(ira, &instruction->base.base, array_result, true, false);
10774 return ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, array_result, true, false);
1076910775 } else {
1077010776 return array_result;
1077110777 }
......@@ -10774,26 +10780,26 @@ skip_computation:
1077410780static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1077510781 IrInstSrcMergeErrSets *instruction)
1077610782{
10777 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child);
10783 ZigType *op1_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op1->child);
1077810784 if (type_is_invalid(op1_type))
1077910785 return ira->codegen->invalid_inst_gen;
1078010786
10781 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child);
10787 ZigType *op2_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op2->child);
1078210788 if (type_is_invalid(op2_type))
1078310789 return ira->codegen->invalid_inst_gen;
1078410790
10785 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {
10791 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {
1078610792 return ira->codegen->invalid_inst_gen;
1078710793 }
1078810794
10789 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {
10795 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {
1079010796 return ira->codegen->invalid_inst_gen;
1079110797 }
1079210798
1079310799 if (type_is_global_error_set(op1_type) ||
1079410800 type_is_global_error_set(op2_type))
1079510801 {
10796 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set);
10802 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_global_error_set);
1079710803 }
1079810804
1079910805 size_t errors_count = ira->codegen->errors_by_index.length;
......@@ -10806,7 +10812,7 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1080610812 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
1080710813 heap::c_allocator.deallocate(errors, errors_count);
1080810814
10809 return ir_const_type(ira, &instruction->base.base, result_type);
10815 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type);
1081010816}
1081110817
1081210818
......@@ -10871,7 +10877,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1087110877 }
1087210878 }
1087310879
10874 AstNode *source_node = decl_var_instruction->base.base.source_node;
10880 AstNode *source_node = decl_var_instruction->base.source_node;
1087510881
1087610882 bool is_comptime_var = ir_get_var_is_comptime(var);
1087710883
......@@ -10881,13 +10887,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1088110887 // if this is null, a compiler error happened and did not initialize the variable.
1088210888 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
1088310889 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
10884 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base);
10890 src_assert(var_ptr != nullptr || ira->codegen->errors.length != 0,
10891 decl_var_instruction->base.source_node);
1088510892 var->var_type = ira->codegen->builtin_types.entry_invalid;
1088610893 return ira->codegen->invalid_inst_gen;
1088710894 }
1088810895
1088910896 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
10890 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base);
10897 src_assert(var_ptr->value->type->id == ZigTypeIdPointer, decl_var_instruction->base.source_node);
1089110898
1089210899 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
1089310900 if (type_is_invalid(result_type)) {
......@@ -10902,7 +10909,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1090210909 if (ptr_val == nullptr)
1090310910 return ira->codegen->invalid_inst_gen;
1090410911
10905 init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.base.source_node);
10912 init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.source_node);
1090610913 if (init_val == nullptr)
1090710914 return ira->codegen->invalid_inst_gen;
1090810915
......@@ -10935,7 +10942,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1093510942 case ReqCompTimeNo:
1093610943 if (init_val != nullptr && value_is_comptime(init_val)) {
1093710944 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
10938 decl_var_instruction->base.base.source_node, init_val, UndefOk)))
10945 decl_var_instruction->base.source_node, init_val, UndefOk)))
1093910946 {
1094010947 result_type = ira->codegen->builtin_types.entry_invalid;
1094110948 } else if (init_val->type->id == ZigTypeIdFn &&
......@@ -10968,13 +10975,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1096810975 assert(var->var_type);
1096910976
1097010977 if (type_is_invalid(result_type)) {
10971 return ir_const_void(ira, &decl_var_instruction->base.base);
10978 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
1097210979 }
1097310980
1097410981 if (decl_var_instruction->align_value == nullptr) {
1097510982 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
1097610983 var->var_type = ira->codegen->builtin_types.entry_invalid;
10977 return ir_const_void(ira, &decl_var_instruction->base.base);
10984 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
1097810985 }
1097910986 var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);
1098010987 } else {
......@@ -10993,7 +11000,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1099311000 // we need a runtime ptr but we have a comptime val.
1099411001 // since it's a comptime val there are no instructions for it.
1099511002 // we memcpy the init value here
10996 IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr);
11003 IrInstGen *deref = ir_get_deref(ira, var_ptr->scope, var_ptr->source_node, var_ptr, nullptr);
1099711004 if (type_is_invalid(deref->value->type)) {
1099811005 var->var_type = ira->codegen->builtin_types.entry_invalid;
1099911006 return ira->codegen->invalid_inst_gen;
......@@ -11003,13 +11010,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1100311010 // instruction.
1100411011 assert(deref->value->special != ConstValSpecialRuntime);
1100511012 var_ptr->value->special = ConstValSpecialRuntime;
11006 ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false);
11013 ir_analyze_store_ptr(ira, var_ptr->scope, var_ptr->source_node, var_ptr, deref, false);
1100711014 }
1100811015 if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) {
11009 return ir_const_void(ira, &decl_var_instruction->base.base);
11016 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
1101011017 }
1101111018 } else if (is_comptime_var) {
11012 ir_add_error(ira, &decl_var_instruction->base.base,
11019 ir_add_error_node(ira, decl_var_instruction->base.source_node,
1101311020 buf_sprintf("cannot store runtime value in compile time variable"));
1101411021 var->var_type = ira->codegen->builtin_types.entry_invalid;
1101511022 return ira->codegen->invalid_inst_gen;
......@@ -11019,7 +11026,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1101911026 if (fn_entry)
1102011027 fn_entry->variable_list.append(var);
1102111028
11022 return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr);
11029 return ir_build_var_decl_gen(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node, var, var_ptr);
1102311030}
1102411031
1102511032static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
......@@ -11035,32 +11042,32 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1103511042 assert(options_type->id == ZigTypeIdStruct);
1103611043
1103711044 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
11038 ir_assert(name_field != nullptr, &instruction->base.base);
11039 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
11045 src_assert(name_field != nullptr, instruction->base.source_node);
11046 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field);
1104011047 if (type_is_invalid(name_inst->value->type))
1104111048 return ira->codegen->invalid_inst_gen;
1104211049
1104311050 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
11044 ir_assert(linkage_field != nullptr, &instruction->base.base);
11045 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
11051 src_assert(linkage_field != nullptr, instruction->base.source_node);
11052 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field);
1104611053 if (type_is_invalid(linkage_inst->value->type))
1104711054 return ira->codegen->invalid_inst_gen;
1104811055
1104911056 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
11050 ir_assert(section_field != nullptr, &instruction->base.base);
11051 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);
11057 src_assert(section_field != nullptr, instruction->base.source_node);
11058 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, section_field);
1105211059 if (type_is_invalid(section_inst->value->type))
1105311060 return ira->codegen->invalid_inst_gen;
1105411061
1105511062 // The `section` field is optional, we have to unwrap it first
11056 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst);
11063 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, section_inst);
1105711064 bool is_non_null;
1105811065 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
1105911066 return ira->codegen->invalid_inst_gen;
1106011067
1106111068 IrInstGen *section_str_inst = nullptr;
1106211069 if (is_non_null) {
11063 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false);
11070 section_str_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, section_inst, false);
1106411071 if (type_is_invalid(section_str_inst->value->type))
1106511072 return ira->codegen->invalid_inst_gen;
1106611073 }
......@@ -11071,7 +11078,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1107111078 return ira->codegen->invalid_inst_gen;
1107211079
1107311080 if (buf_len(symbol_name) < 1) {
11074 ir_add_error(ira, &name_inst->base,
11081 ir_add_error(ira, name_inst,
1107511082 buf_sprintf("exported symbol name cannot be empty"));
1107611083 return ira->codegen->invalid_inst_gen;
1107711084 }
......@@ -11090,12 +11097,12 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1109011097 // in another file.
1109111098 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
1109211099 tld_fn->base.id = TldIdFn;
11093 tld_fn->base.source_node = instruction->base.base.source_node;
11100 tld_fn->base.source_node = instruction->base.source_node;
1109411101
1109511102 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
1109611103 if (entry) {
1109711104 AstNode *other_export_node = entry->value->source_node;
11098 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
11105 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
1109911106 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
1110011107 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here"));
1110111108 return ira->codegen->invalid_inst_gen;
......@@ -11114,17 +11121,17 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1111411121 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
1111511122 switch (cc) {
1111611123 case CallingConventionUnspecified: {
11117 ErrorMsg *msg = ir_add_error(ira, &target->base,
11124 ErrorMsg *msg = ir_add_error(ira, target,
1111811125 buf_sprintf("exported function must specify calling convention"));
1111911126 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1112011127 } break;
1112111128 case CallingConventionAsync: {
11122 ErrorMsg *msg = ir_add_error(ira, &target->base,
11129 ErrorMsg *msg = ir_add_error(ira, target,
1112311130 buf_sprintf("exported function cannot be async"));
1112411131 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1112511132 } break;
1112611133 case CallingConventionInline: {
11127 ErrorMsg *msg = ir_add_error(ira, &target->base,
11134 ErrorMsg *msg = ir_add_error(ira, target,
1112811135 buf_sprintf("exported function cannot be inline"));
1112911136 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1113011137 } break;
......@@ -11147,10 +11154,10 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1114711154 } break;
1114811155 case ZigTypeIdStruct:
1114911156 if (is_slice(target->value->type)) {
11150 ir_add_error(ira, &target->base,
11157 ir_add_error(ira, target,
1115111158 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
1115211159 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
11153 ErrorMsg *msg = ir_add_error(ira, &target->base,
11160 ErrorMsg *msg = ir_add_error(ira, target,
1115411161 buf_sprintf("exported struct value must be declared extern"));
1115511162 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
1115611163 } else {
......@@ -11159,7 +11166,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1115911166 break;
1116011167 case ZigTypeIdUnion:
1116111168 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
11162 ErrorMsg *msg = ir_add_error(ira, &target->base,
11169 ErrorMsg *msg = ir_add_error(ira, target,
1116311170 buf_sprintf("exported union value must be declared extern"));
1116411171 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
1116511172 } else {
......@@ -11168,7 +11175,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1116811175 break;
1116911176 case ZigTypeIdEnum:
1117011177 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
11171 ErrorMsg *msg = ir_add_error(ira, &target->base,
11178 ErrorMsg *msg = ir_add_error(ira, target,
1117211179 buf_sprintf("exported enum value must be declared extern"));
1117311180 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
1117411181 } else {
......@@ -11181,7 +11188,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1118111188 return ira->codegen->invalid_inst_gen;
1118211189
1118311190 if (!ok_type) {
11184 ir_add_error(ira, &target->base,
11191 ir_add_error(ira, target,
1118511192 buf_sprintf("array element type '%s' not extern-compatible",
1118611193 buf_ptr(&target->value->type->data.array.child_type->name)));
1118711194 } else {
......@@ -11196,31 +11203,31 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1119611203 zig_unreachable();
1119711204 case ZigTypeIdStruct:
1119811205 if (is_slice(type_value)) {
11199 ir_add_error(ira, &target->base,
11206 ir_add_error(ira, target,
1120011207 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
1120111208 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {
11202 ErrorMsg *msg = ir_add_error(ira, &target->base,
11209 ErrorMsg *msg = ir_add_error(ira, target,
1120311210 buf_sprintf("exported struct must be declared extern"));
1120411211 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
1120511212 }
1120611213 break;
1120711214 case ZigTypeIdUnion:
1120811215 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
11209 ErrorMsg *msg = ir_add_error(ira, &target->base,
11216 ErrorMsg *msg = ir_add_error(ira, target,
1121011217 buf_sprintf("exported union must be declared extern"));
1121111218 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
1121211219 }
1121311220 break;
1121411221 case ZigTypeIdEnum:
1121511222 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
11216 ErrorMsg *msg = ir_add_error(ira, &target->base,
11223 ErrorMsg *msg = ir_add_error(ira, target,
1121711224 buf_sprintf("exported enum must be declared extern"));
1121811225 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
1121911226 }
1122011227 break;
1122111228 case ZigTypeIdFn: {
1122211229 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
11223 ir_add_error(ira, &target->base,
11230 ir_add_error(ira, target,
1122411231 buf_sprintf("exported function type must specify calling convention"));
1122511232 }
1122611233 } break;
......@@ -11246,7 +11253,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1124611253 case ZigTypeIdOpaque:
1124711254 case ZigTypeIdFnFrame:
1124811255 case ZigTypeIdAnyFrame:
11249 ir_add_error(ira, &target->base,
11256 ir_add_error(ira, target,
1125011257 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
1125111258 break;
1125211259 }
......@@ -11272,7 +11279,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1127211279 case ZigTypeIdEnumLiteral:
1127311280 case ZigTypeIdFnFrame:
1127411281 case ZigTypeIdAnyFrame:
11275 ir_add_error(ira, &target->base,
11282 ir_add_error(ira, target,
1127611283 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
1127711284 break;
1127811285 }
......@@ -11288,7 +11295,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1128811295 }
1128911296 }
1129011297
11291 return ir_const_void(ira, &instruction->base.base);
11298 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1129211299}
1129311300
1129411301static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node);
......@@ -11306,38 +11313,38 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1130611313 assert(options_type->id == ZigTypeIdStruct);
1130711314
1130811315 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
11309 ir_assert(name_field != nullptr, &instruction->base.base);
11310 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
11316 src_assert(name_field != nullptr, instruction->base.source_node);
11317 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field);
1131111318 if (type_is_invalid(name_inst->value->type))
1131211319 return ira->codegen->invalid_inst_gen;
1131311320
1131411321 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
11315 ir_assert(linkage_field != nullptr, &instruction->base.base);
11316 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
11322 src_assert(linkage_field != nullptr, instruction->base.source_node);
11323 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field);
1131711324 if (type_is_invalid(linkage_inst->value->type))
1131811325 return ira->codegen->invalid_inst_gen;
1131911326
1132011327 TypeStructField *is_thread_local_field = find_struct_type_field(options_type, buf_create_from_str("is_thread_local"));
11321 ir_assert(is_thread_local_field != nullptr, &instruction->base.base);
11322 IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, is_thread_local_field);
11328 src_assert(is_thread_local_field != nullptr, instruction->base.source_node);
11329 IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, is_thread_local_field);
1132311330 if (type_is_invalid(is_thread_local_inst->value->type))
1132411331 return ira->codegen->invalid_inst_gen;
1132511332
1132611333 TypeStructField *library_name_field = find_struct_type_field(options_type, buf_create_from_str("library_name"));
11327 ir_assert(library_name_field != nullptr, &instruction->base.base);
11328 IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, library_name_field);
11334 src_assert(library_name_field != nullptr, instruction->base.source_node);
11335 IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, library_name_field);
1132911336 if (type_is_invalid(library_name_inst->value->type))
1133011337 return ira->codegen->invalid_inst_gen;
1133111338
1133211339 // The `library_name` field is optional, we have to unwrap it first
11333 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, library_name_inst);
11340 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, library_name_inst);
1133411341 bool is_non_null;
1133511342 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
1133611343 return ira->codegen->invalid_inst_gen;
1133711344
1133811345 IrInstGen *library_name_val_inst = nullptr;
1133911346 if (is_non_null) {
11340 library_name_val_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, library_name_inst, false);
11347 library_name_val_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, library_name_inst, false);
1134111348 if (type_is_invalid(library_name_val_inst->value->type))
1134211349 return ira->codegen->invalid_inst_gen;
1134311350 }
......@@ -11348,7 +11355,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1134811355 return ira->codegen->invalid_inst_gen;
1134911356
1135011357 if (get_src_ptr_type(value_type) == nullptr) {
11351 ir_add_error(ira, &name_inst->base,
11358 ir_add_error(ira, name_inst,
1135211359 buf_sprintf("expected (optional) pointer type or function"));
1135311360 return ira->codegen->invalid_inst_gen;
1135411361 }
......@@ -11358,7 +11365,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1135811365 return ira->codegen->invalid_inst_gen;
1135911366
1136011367 if (buf_len(symbol_name) == 0) {
11361 ir_add_error(ira, &name_inst->base,
11368 ir_add_error(ira, name_inst,
1136211369 buf_sprintf("extern symbol name cannot be empty"));
1136311370 return ira->codegen->invalid_inst_gen;
1136411371 }
......@@ -11370,12 +11377,12 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1137011377 return ira->codegen->invalid_inst_gen;
1137111378
1137211379 if (buf_len(library_name) == 0) {
11373 ir_add_error(ira, &library_name_inst->base,
11380 ir_add_error(ira, library_name_inst,
1137411381 buf_sprintf("library name name cannot be empty"));
1137511382 return ira->codegen->invalid_inst_gen;
1137611383 }
1137711384
11378 add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.base.source_node);
11385 add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.source_node);
1137911386
1138011387 buf_destroy(library_name);
1138111388 }
......@@ -11396,18 +11403,18 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
1139611403 // XXX: Find a better way to do this (in stage2).
1139711404 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
1139811405 tld_fn->base.id = TldIdFn;
11399 tld_fn->base.source_node = instruction->base.base.source_node;
11406 tld_fn->base.source_node = instruction->base.source_node;
1140011407
1140111408 auto entry = ira->codegen->external_symbol_names.put_unique(symbol_name, &tld_fn->base);
1140211409 if (entry) {
1140311410 AstNode *other_extern_node = entry->value->source_node;
11404 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
11411 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
1140511412 buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name)));
1140611413 add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here"));
1140711414 return ira->codegen->invalid_inst_gen;
1140811415 }
1140911416
11410 return ir_build_extern_gen(ira, &instruction->base.base, symbol_name, global_linkage_id,
11417 return ir_build_extern_gen(ira, instruction->base.scope, instruction->base.source_node, symbol_name, global_linkage_id,
1141111418 is_thread_local, expr_type);
1141211419}
1141311420
......@@ -11423,24 +11430,24 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1142311430 if (instruction->optional == IrInstErrorReturnTraceNull) {
1142411431 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
1142511432 if (!ira_has_err_ret_trace(ira)) {
11426 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
11433 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, optional_type);
1142711434 ZigValue *out_val = result->value;
1142811435 assert(get_src_ptr_type(optional_type) != nullptr);
1142911436 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1143011437 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
1143111438 return result;
1143211439 }
11433 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
11434 instruction->base.base.source_node, instruction->optional, optional_type);
11440 return ir_build_error_return_trace_gen(ira, instruction->base.scope,
11441 instruction->base.source_node, instruction->optional, optional_type);
1143511442 } else {
1143611443 assert(ira->codegen->have_err_ret_tracing);
11437 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
11438 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);
11444 return ir_build_error_return_trace_gen(ira, instruction->base.scope,
11445 instruction->base.source_node, instruction->optional, ptr_to_stack_trace_type);
1143911446 }
1144011447}
1144111448
1144211449static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
11443 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
11450 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
1144411451 result->value->special = ConstValSpecialLazy;
1144511452
1144611453 LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>();
......@@ -11459,7 +11466,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr
1145911466 return result;
1146011467}
1146111468
11462static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type,
11469static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *var_type,
1146311470 uint32_t align, const char *name_hint, bool force_comptime)
1146411471{
1146511472 Error err;
......@@ -11468,7 +11475,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
1146811475 pointee->special = ConstValSpecialUndef;
1146911476 pointee->llvm_align = align;
1147011477
11471 IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
11478 IrInstGenAlloca *result = ir_build_alloca_gen(ira, scope, source_node, align, name_hint);
1147211479 result->base.value->special = ConstValSpecialStatic;
1147311480 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
1147411481 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
......@@ -11481,7 +11488,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
1148111488 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
1148211489 return ira->codegen->invalid_inst_gen;
1148311490 if (!var_type_has_bits) {
11484 ir_add_error(ira, source_inst,
11491 ir_add_error_node(ira, source_node,
1148511492 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
1148611493 name_hint, buf_ptr(&var_type->name)));
1148711494 return ira->codegen->invalid_inst_gen;
......@@ -11502,9 +11509,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
1150211509 return &result->base;
1150311510}
1150411511
11505static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr,
11506 ResultLoc *result_loc)
11507{
11512static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_loc) {
1150811513 switch (result_loc->id) {
1150911514 case ResultLocIdInvalid:
1151011515 case ResultLocIdPeerParent:
......@@ -11584,12 +11589,13 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
1158411589 zig_unreachable();
1158511590}
1158611591
11587static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr,
11592static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
1158811593 ResultLoc *result_loc, ZigType *value_type)
1158911594{
1159011595 if (type_is_invalid(value_type))
1159111596 return ira->codegen->invalid_inst_gen;
11592 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
11597 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr->scope,
11598 suspend_source_instr->source_node, 0, "");
1159311599 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
1159411600 PtrLenSingle, 0, 0, 0, false);
1159511601 set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base);
......@@ -11618,7 +11624,7 @@ static bool result_loc_is_discard(ResultLoc *result_loc_pass1) {
1161811624}
1161911625
1162011626// when calling this function, at the callsite must check for result type noreturn and propagate it up
11621static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
11627static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
1162211628 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
1162311629 bool allow_discard)
1162411630{
......@@ -11662,7 +11668,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1166211668 var = new_var;
1166311669 }
1166411670 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {
11665 ir_add_error(ira, &result_loc->source_instruction->base,
11671 ir_add_error_node(ira, result_loc->source_instruction->source_node,
1166611672 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));
1166711673 return ira->codegen->invalid_inst_gen;
1166811674 }
......@@ -11674,14 +11680,16 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1167411680 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {
1167511681 return ira->codegen->invalid_inst_gen;
1167611682 }
11677 IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type,
11683 IrInstGen *alloca_gen = ir_analyze_alloca(ira,
11684 result_loc->source_instruction->scope,
11685 result_loc->source_instruction->source_node, value_type,
1167811686 align, alloca_src->name_hint, force_comptime);
1167911687 if (force_runtime) {
1168011688 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
1168111689 alloca_gen->value->special = ConstValSpecialRuntime;
1168211690 }
1168311691 if (alloca_src->base.child != nullptr && !result_loc->written) {
11684 alloca_src->base.child->base.ref_count = 0;
11692 alloca_src->base.child->ref_count = 0;
1168511693 }
1168611694 alloca_src->base.child = alloca_gen;
1168711695 var->ptr_instruction = alloca_gen;
......@@ -11786,7 +11794,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1178611794
1178711795 IrInstGen *casted_value;
1178811796 if (value != nullptr) {
11789 casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type);
11797 casted_value = ir_implicit_cast2(ira, suspend_source_instr->scope,
11798 suspend_source_instr->source_node, value, dest_type);
1179011799 if (type_is_invalid(casted_value->value->type))
1179111800 return ira->codegen->invalid_inst_gen;
1179211801 dest_type = casted_value->value->type;
......@@ -11835,7 +11844,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1183511844
1183611845 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
1183711846 parent_result_loc->value->type, ptr_type,
11838 result_cast->base.source_instruction->base.source_node, false);
11847 result_cast->base.source_instruction->source_node, false);
1183911848 if (const_cast_result.id == ConstCastResultIdInvalid)
1184011849 return ira->codegen->invalid_inst_gen;
1184111850 if (const_cast_result.id != ConstCastResultIdOk) {
......@@ -11849,8 +11858,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1184911858 }
1185011859
1185111860 result_loc->written = true;
11852 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
11853 &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false, false);
11861 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope,
11862 suspend_source_instr->source_node, parent_result_loc,
11863 parent_result_loc->source_node, ptr_type,
11864 result_cast->base.source_instruction->source_node, false, false);
1185411865 return result_loc->resolved_loc;
1185511866 }
1185611867 case ResultLocIdBitCast: {
......@@ -11863,13 +11874,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1186311874 if ((err = get_codegen_ptr_type(ira->codegen, dest_type, &dest_cg_ptr_type)))
1186411875 return ira->codegen->invalid_inst_gen;
1186511876 if (dest_cg_ptr_type != nullptr) {
11866 ir_add_error(ira, &result_loc->source_instruction->base,
11877 ir_add_error_node(ira, result_loc->source_instruction->source_node,
1186711878 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
1186811879 return ira->codegen->invalid_inst_gen;
1186911880 }
1187011881
1187111882 if (!type_can_bit_cast(dest_type)) {
11872 ir_add_error(ira, &result_loc->source_instruction->base,
11883 ir_add_error_node(ira, result_loc->source_instruction->source_node,
1187311884 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
1187411885 return ira->codegen->invalid_inst_gen;
1187511886 }
......@@ -11878,20 +11889,21 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1187811889 if ((err = get_codegen_ptr_type(ira->codegen, value_type, &value_cg_ptr_type)))
1187911890 return ira->codegen->invalid_inst_gen;
1188011891 if (value_cg_ptr_type != nullptr) {
11881 ir_add_error(ira, suspend_source_instr,
11892 ir_add_error_node(ira, suspend_source_instr->source_node,
1188211893 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
1188311894 return ira->codegen->invalid_inst_gen;
1188411895 }
1188511896
1188611897 if (!type_can_bit_cast(value_type)) {
11887 ir_add_error(ira, suspend_source_instr,
11898 ir_add_error_node(ira, suspend_source_instr->source_node,
1188811899 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
1188911900 return ira->codegen->invalid_inst_gen;
1189011901 }
1189111902
1189211903 IrInstGen *bitcasted_value;
1189311904 if (value != nullptr) {
11894 bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type);
11905 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction->scope,
11906 result_loc->source_instruction->source_node, value, dest_type);
1189511907 dest_type = bitcasted_value->value->type;
1189611908 } else {
1189711909 bitcasted_value = nullptr;
......@@ -11943,15 +11955,17 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1194311955 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1194411956
1194511957 result_loc->written = true;
11946 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
11947 &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false, false);
11958 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope,
11959 suspend_source_instr->source_node, parent_result_loc,
11960 parent_result_loc->source_node, ptr_type,
11961 result_bit_cast->base.source_instruction->source_node, false, false);
1194811962 return result_loc->resolved_loc;
1194911963 }
1195011964 }
1195111965 zig_unreachable();
1195211966}
1195311967
11954static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
11968static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
1195511969 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
1195611970 bool allow_discard)
1195711971{
......@@ -11994,7 +12008,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1199412008 field->type_entry = value_type;
1199512009 field->type_val = create_const_type(ira->codegen, field->type_entry);
1199612010 field->src_index = old_field_count;
11997 field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node;
12011 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
1199812012 if (value && instr_is_comptime(value)) {
1199912013 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
1200012014 if (!val)
......@@ -12007,7 +12021,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1200712021
1200812022 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
1200912023 if (instr_is_comptime(result_loc)) {
12010 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
12024 casted_ptr = ir_const(ira, suspend_source_instr->scope,
12025 suspend_source_instr->source_node, struct_ptr_type);
1201112026 copy_const_val(ira->codegen, casted_ptr->value, result_loc->value);
1201212027 casted_ptr->value->type = struct_ptr_type;
1201312028 } else {
......@@ -12034,7 +12049,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1203412049 }
1203512050 }
1203612051
12037 result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr, field, casted_ptr,
12052 result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr->scope,
12053 suspend_source_instr->source_node, field, casted_ptr,
1203812054 isf->inferred_struct_type, true);
1203912055 if (type_is_invalid(result_loc->value->type)) {
1204012056 return result_loc;
......@@ -12046,7 +12062,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1204612062 return result_loc;
1204712063 }
1204812064
12049 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
12065 src_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr->source_node);
1205012066 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
1205112067 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
1205212068 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
......@@ -12054,21 +12070,25 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1205412070 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);
1205512071 if (!same_comptime_repr) {
1205612072 result_loc_pass1->written = was_written;
12057 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
12073 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope,
12074 suspend_source_instr->source_node, result_loc, false, true);
1205812075 }
1205912076 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&
1206012077 value_type->id != ZigTypeIdUndefined)
1206112078 {
1206212079 if (value_type->id == ZigTypeIdErrorSet) {
12063 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
12080 return ir_analyze_unwrap_err_code(ira, suspend_source_instr->scope,
12081 suspend_source_instr->source_node, result_loc, true);
1206412082 } else {
12065 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
12083 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira,
12084 suspend_source_instr->scope, suspend_source_instr->source_node,
1206612085 result_loc, false, true);
1206712086 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
1206812087 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
1206912088 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
1207012089 {
12071 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true);
12090 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope,
12091 suspend_source_instr->source_node, unwrapped_err_ptr, false, true);
1207212092 } else {
1207312093 return unwrapped_err_ptr;
1207412094 }
......@@ -12095,17 +12115,17 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
1209512115 if (implicit_elem_type == ira->codegen->builtin_types.entry_anytype) {
1209612116 Buf *bare_name = buf_alloc();
1209712117 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
12098 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
12118 instruction->base.scope, instruction->base.source_node, bare_name);
1209912119
1210012120 StructSpecial struct_special = StructSpecialInferredStruct;
12101 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&
12102 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
12121 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&
12122 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
1210312123 {
1210412124 struct_special = StructSpecialInferredTuple;
1210512125 }
1210612126
1210712127 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
12108 instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node,
12128 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
1210912129 buf_ptr(name), bare_name, ContainerLayoutAuto);
1211012130 inferred_struct_type->data.structure.special = struct_special;
1211112131 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
......@@ -12116,7 +12136,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
1211612136 if (type_is_invalid(implicit_elem_type))
1211712137 return ira->codegen->invalid_inst_gen;
1211812138 }
12119 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
12139 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
1212012140 implicit_elem_type, nullptr, false, true);
1212112141 if (result_loc != nullptr)
1212212142 return result_loc;
......@@ -12125,7 +12145,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
1212512145 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
1212612146 instruction->result_loc->id == ResultLocIdReturn)
1212712147 {
12128 result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(),
12148 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
1212912149 implicit_elem_type, nullptr, false, true);
1213012150 if (result_loc != nullptr &&
1213112151 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
......@@ -12136,9 +12156,9 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
1213612156 return result_loc;
1213712157 }
1213812158
12139 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);
12159 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, implicit_elem_type);
1214012160 result->value->special = ConstValSpecialUndef;
12141 IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false);
12161 IrInstGen *ptr = ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, result, false, false);
1214212162 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
1214312163 return ptr;
1214412164}
......@@ -12180,14 +12200,14 @@ static void ir_reset_result(ResultLoc *result_loc) {
1218012200
1218112201static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
1218212202 ir_reset_result(instruction->result_loc);
12183 return ir_const_void(ira, &instruction->base.base);
12203 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1218412204}
1218512205
12186static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,
12206static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1218712207 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
1218812208 IrInstGen *ret_ptr_uncasted)
1218912209{
12190 ir_assert(is_async_call_builtin, source_instr);
12210 src_assert(is_async_call_builtin, source_node);
1219112211 if (type_is_invalid(ret_ptr_uncasted->value->type))
1219212212 return ira->codegen->invalid_inst_gen;
1219312213 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
......@@ -12197,47 +12217,47 @@ static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr
1219712217 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
1219812218}
1219912219
12200static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,
12220static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry,
1220112221 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
1220212222 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
1220312223 ResultLoc *call_result_loc)
1220412224{
1220512225 if (fn_entry == nullptr) {
1220612226 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {
12207 ir_add_error(ira, &fn_ref->base,
12227 ir_add_error(ira, fn_ref,
1220812228 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));
1220912229 return ira->codegen->invalid_inst_gen;
1221012230 }
1221112231 if (casted_new_stack == nullptr) {
12212 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));
12232 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));
1221312233 return ira->codegen->invalid_inst_gen;
1221412234 }
1221512235 }
1221612236 if (casted_new_stack != nullptr) {
1221712237 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
12218 IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
12238 IrInstGen *ret_ptr = get_async_call_result_loc(ira, scope, source_node, fn_ret_type, is_async_call_builtin,
1221912239 casted_args, arg_count, ret_ptr_uncasted);
1222012240 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
1222112241 return ira->codegen->invalid_inst_gen;
1222212242
1222312243 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1222412244
12225 IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
12245 IrInstGenCall *call_gen = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref,
1222612246 arg_count, casted_args, CallModifierAsync, casted_new_stack,
1222712247 is_async_call_builtin, ret_ptr, anyframe_type);
1222812248 return &call_gen->base;
1222912249 } else {
1223012250 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
12231 IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
12251 IrInstGen *result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
1223212252 frame_type, nullptr, true, false);
1223312253 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1223412254 return result_loc;
1223512255 }
12236 result_loc = ir_implicit_cast2(ira, source_instr, result_loc,
12256 result_loc = ir_implicit_cast2(ira, scope, source_node, result_loc,
1223712257 get_pointer_to_type(ira->codegen, frame_type, false));
1223812258 if (type_is_invalid(result_loc->value->type))
1223912259 return ira->codegen->invalid_inst_gen;
12240 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,
12260 return &ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref, arg_count,
1224112261 casted_args, CallModifierAsync, casted_new_stack,
1224212262 is_async_call_builtin, result_loc, frame_type)->base;
1224312263 }
......@@ -12276,7 +12296,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1227612296}
1227712297
1227812298static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
12279 IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i,
12299 IrInstGen *arg, AstNode *arg_src, Scope **child_scope, size_t *next_proto_i,
1228012300 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
1228112301 ZigFn *impl_fn)
1228212302{
......@@ -12298,7 +12318,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1229812318 if (type_is_invalid(param_type))
1229912319 return false;
1230012320
12301 casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type);
12321 casted_arg = ir_implicit_cast2(ira, arg->scope, arg_src, arg, param_type);
1230212322 if (type_is_invalid(casted_arg->value->type))
1230312323 return false;
1230412324
......@@ -12326,7 +12346,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1232612346 ZigValue *arg_val;
1232712347
1232812348 if (comptime_arg && !instr_is_comptime(casted_arg)) {
12329 ir_add_error(ira, &casted_arg->base,
12349 ir_add_error(ira, casted_arg,
1233012350 buf_sprintf("runtime value cannot be passed to comptime arg"));
1233112351 return false;
1233212352 }
......@@ -12355,7 +12375,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1235512375 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
1235612376 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
1235712377 {
12358 ir_add_error(ira, &casted_arg->base,
12378 ir_add_error(ira, casted_arg,
1235912379 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
1236012380 return false;
1236112381 }
......@@ -12372,7 +12392,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1237212392 return true;
1237312393}
1237412394
12375static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
12395static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) {
1237612396 while (var->next_var != nullptr) {
1237712397 var = var->next_var;
1237812398 }
......@@ -12391,7 +12411,7 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v
1239112411 bool comptime_var_mem = ir_get_var_is_comptime(var);
1239212412 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
1239312413
12394 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);
12414 IrInstGen *result = ir_build_var_ptr_gen(ira, scope, source_node, var);
1239512415 result->value->type = var_ptr_type;
1239612416
1239712417 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {
......@@ -12427,20 +12447,20 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v
1242712447}
1242812448
1242912449// This function is called when a comptime value becomes accessible at runtime.
12430static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) {
12431 ir_assert(value_is_comptime(val), source_instr);
12450static void mark_comptime_value_escape(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) {
12451 src_assert(value_is_comptime(val), source_node);
1243212452 if (val->special == ConstValSpecialUndef)
1243312453 return;
1243412454
1243512455 if (val->type->id == ZigTypeIdFn && val->type->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
12436 ir_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
12456 src_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
1243712457 if (val->data.x_ptr.data.fn.fn_entry->non_async_node == nullptr) {
12438 val->data.x_ptr.data.fn.fn_entry->non_async_node = source_instr->source_node;
12458 val->data.x_ptr.data.fn.fn_entry->non_async_node = source_node;
1243912459 }
1244012460 }
1244112461}
1244212462
12443static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12463static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1244412464 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
1244512465{
1244612466 assert(ptr->value->type->id == ZigTypeIdPointer);
......@@ -12449,14 +12469,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1244912469 if (uncasted_value->value->type->id == ZigTypeIdErrorUnion ||
1245012470 uncasted_value->value->type->id == ZigTypeIdErrorSet)
1245112471 {
12452 ir_add_error(ira, source_instr, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`"));
12472 ir_add_error_node(ira, source_node, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`"));
1245312473 return ira->codegen->invalid_inst_gen;
1245412474 }
12455 return ir_const_void(ira, source_instr);
12475 return ir_const_void(ira, scope, source_node);
1245612476 }
1245712477
1245812478 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
12459 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
12479 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
1246012480 return ira->codegen->invalid_inst_gen;
1246112481 }
1246212482
......@@ -12469,14 +12489,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1246912489 case OnePossibleValueInvalid:
1247012490 return ira->codegen->invalid_inst_gen;
1247112491 case OnePossibleValueYes:
12472 return ir_const_void(ira, source_instr);
12492 return ir_const_void(ira, scope, source_node);
1247312493 case OnePossibleValueNo:
1247412494 break;
1247512495 }
1247612496
1247712497 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1247812498 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
12479 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
12499 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
1248012500 return ira->codegen->invalid_inst_gen;
1248112501 }
1248212502 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
......@@ -12484,24 +12504,24 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1248412504 ptr->value->data.x_ptr.mut == ConstPtrMutInfer)
1248512505 {
1248612506 if (instr_is_comptime(value)) {
12487 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
12507 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_node);
1248812508 if (dest_val == nullptr)
1248912509 return ira->codegen->invalid_inst_gen;
1249012510 if (dest_val->special != ConstValSpecialRuntime) {
1249112511 copy_const_val(ira->codegen, dest_val, value->value);
1249212512
1249312513 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
12494 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
12514 ira->new_irb.current_basic_block->must_be_comptime_source_node == nullptr)
1249512515 {
12496 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;
12516 ira->new_irb.current_basic_block->must_be_comptime_source_node = source_node;
1249712517 }
12498 return ir_const_void(ira, source_instr);
12518 return ir_const_void(ira, scope, source_node);
1249912519 }
1250012520 }
1250112521 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
1250212522 ptr->value->special = ConstValSpecialRuntime;
1250312523 } else {
12504 ir_add_error(ira, source_instr,
12524 ir_add_error_node(ira, source_node,
1250512525 buf_sprintf("cannot store runtime value in compile time variable"));
1250612526 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
1250712527 dest_val->type = ira->codegen->builtin_types.entry_invalid;
......@@ -12525,11 +12545,11 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1252512545 case OnePossibleValueInvalid:
1252612546 return ira->codegen->invalid_inst_gen;
1252712547 case OnePossibleValueNo:
12528 ir_add_error(ira, source_instr,
12548 ir_add_error_node(ira, source_node,
1252912549 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));
1253012550 return ira->codegen->invalid_inst_gen;
1253112551 case OnePossibleValueYes:
12532 return ir_const_void(ira, source_instr);
12552 return ir_const_void(ira, scope, source_node);
1253312553 }
1253412554 zig_unreachable();
1253512555 case ReqCompTimeNo:
......@@ -12537,7 +12557,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1253712557 }
1253812558
1253912559 if (instr_is_comptime(value)) {
12540 mark_comptime_value_escape(ira, source_instr, value->value);
12560 mark_comptime_value_escape(ira, scope, source_node, value->value);
1254112561 }
1254212562
1254312563 // If this is a store to a pointer with a runtime-known vector index,
......@@ -12549,20 +12569,20 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1254912569 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
1255012570 if (ptr->id == IrInstGenIdElemPtr) {
1255112571 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
12552 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
12572 return ir_build_vector_store_elem(ira, scope, source_node, elem_ptr->array_ptr,
1255312573 elem_ptr->elem_index, value);
1255412574 }
12555 ir_add_error(ira, &ptr->base,
12575 ir_add_error(ira, ptr,
1255612576 buf_sprintf("unable to determine vector element index of type '%s'",
1255712577 buf_ptr(&ptr->value->type->name)));
1255812578 return ira->codegen->invalid_inst_gen;
1255912579 }
1256012580
12561 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);
12581 return ir_build_store_ptr_gen(ira, scope, source_node, ptr, value);
1256212582}
1256312583
12564static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
12565 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry)
12584static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12585 IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry)
1256612586{
1256712587 if (new_stack == nullptr)
1256812588 return nullptr;
......@@ -12570,7 +12590,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
1257012590 if (!is_async_call_builtin &&
1257112591 arch_stack_pointer_register_name(ira->codegen->zig_target->arch) == nullptr)
1257212592 {
12573 ir_add_error(ira, source_instr,
12593 ir_add_error_node(ira, source_node,
1257412594 buf_sprintf("target arch '%s' does not support calling with a new stack",
1257512595 target_arch_name(ira->codegen->zig_target->arch)));
1257612596 }
......@@ -12591,14 +12611,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
1259112611 false, false, PtrLenUnknown, required_align, 0, 0, false);
1259212612 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
1259312613 ira->codegen->need_frame_size_prefix_data = true;
12594 return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice);
12614 return ir_implicit_cast2(ira, new_stack->scope, new_stack_src, new_stack, u8_slice);
1259512615 }
1259612616}
1259712617
12598static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12618static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1259912619 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
12600 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier,
12601 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin,
12620 IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier,
12621 IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin,
1260212622 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
1260312623{
1260412624 Error err;
......@@ -12615,12 +12635,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1261512635 }
1261612636 size_t src_param_count = fn_type_id->param_count - var_args_1_or_0;
1261712637 size_t call_param_count = args_len + first_arg_1_or_0;
12618 AstNode *source_node = source_instr->source_node;
1261912638
1262012639 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1262112640
1262212641 if (fn_type_id->cc == CallingConventionNaked) {
12623 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention"));
12642 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));
1262412643 if (fn_proto_node) {
1262512644 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
1262612645 }
......@@ -12652,25 +12671,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1265212671 if (modifier == CallModifierCompileTime) {
1265312672 // If we are evaluating an extern function in a TypeOf call, we can return an undefined value
1265412673 // of its return type.
12655 if (fn_entry != nullptr && get_scope_typeof(source_instr->scope) != nullptr &&
12674 if (fn_entry != nullptr && get_scope_typeof(scope) != nullptr &&
1265612675 fn_proto_node->data.fn_proto.is_extern) {
1265712676
1265812677 assert(fn_entry->body_node == nullptr);
1265912678 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
12660 ZigType *return_type = ir_analyze_type_expr(ira, source_instr->scope, return_type_node);
12679 ZigType *return_type = ir_analyze_type_expr(ira, scope, return_type_node);
1266112680 if (type_is_invalid(return_type))
1266212681 return ira->codegen->invalid_inst_gen;
1266312682
12664 return ir_const_undef(ira, source_instr, return_type);
12683 return ir_const_undef(ira, scope, source_node, return_type);
1266512684 }
1266612685
1266712686 // No special handling is needed for compile time evaluation of generic functions.
1266812687 if (!fn_entry || fn_entry->body_node == nullptr) {
12669 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));
12688 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));
1267012689 return ira->codegen->invalid_inst_gen;
1267112690 }
1267212691
12673 if (!ir_emit_backward_branch(ira, source_instr))
12692 if (!ir_emit_backward_branch(ira, source_node))
1267412693 return ira->codegen->invalid_inst_gen;
1267512694
1267612695 // Fork a scope of the function with known values for the parameters.
......@@ -12692,7 +12711,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1269212711 if (!first_arg_known_bare) {
1269312712 first_arg = first_arg_ptr;
1269412713 } else {
12695 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
12714 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node, first_arg_ptr, nullptr);
1269612715 if (type_is_invalid(first_arg->value->type))
1269712716 return ira->codegen->invalid_inst_gen;
1269812717 }
......@@ -12710,7 +12729,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1271012729
1271112730 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
1271212731 if (return_type_node == nullptr) {
12713 ir_add_error(ira, &fn_ref->base,
12732 ir_add_error(ira, fn_ref,
1271412733 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
1271512734 return ira->codegen->invalid_inst_gen;
1271612735 }
......@@ -12744,7 +12763,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1274412763
1274512764 if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr,
1274612765 ira->backward_branch_count, ira->backward_branch_quota,
12747 fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node,
12766 fn_entry, nullptr, source_node, nullptr, ira->new_irb.exec, return_type_node,
1274812767 UndefOk)))
1274912768 {
1275012769 return ira->codegen->invalid_inst_gen;
......@@ -12777,13 +12796,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1277712796 }
1277812797 }
1277912798
12780 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);
12799 IrInstGen *new_instruction = ir_const_move(ira, scope, source_node, result);
1278112800 return ir_finish_anal(ira, new_instruction);
1278212801 }
1278312802
1278412803 if (fn_type->data.fn.is_generic) {
1278512804 if (!fn_entry) {
12786 ir_add_error(ira, &fn_ref->base,
12805 ir_add_error(ira, fn_ref,
1278712806 buf_sprintf("calling a generic function requires compile-time known function value"));
1278812807 return ira->codegen->invalid_inst_gen;
1278912808 }
......@@ -12827,7 +12846,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1282712846 if (!first_arg_known_bare) {
1282812847 first_arg = first_arg_ptr;
1282912848 } else {
12830 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
12849 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node,
12850 first_arg_ptr, nullptr);
1283112851 if (type_is_invalid(first_arg->value->type))
1283212852 return ira->codegen->invalid_inst_gen;
1283312853 }
......@@ -12847,7 +12867,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1284712867 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
1284812868 assert(param_decl_node->type == NodeTypeParamDecl);
1284912869
12850 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope,
12870 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, arg->source_node,
12871 &impl_fn->child_scope,
1285112872 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
1285212873 {
1285312874 return ira->codegen->invalid_inst_gen;
......@@ -12882,7 +12903,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1288212903 return ira->codegen->invalid_inst_gen;
1288312904
1288412905 if(!is_valid_return_type(specified_return_type)){
12885 ErrorMsg *msg = ir_add_error(ira, source_instr,
12906 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1288612907 buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));
1288712908 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
1288812909
......@@ -12905,7 +12926,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1290512926 switch (type_requires_comptime(ira->codegen, specified_return_type)) {
1290612927 case ReqCompTimeYes:
1290712928 // Throw out our work and call the function as if it were comptime.
12908 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,
12929 return ir_analyze_fn_call(ira, scope, source_node, fn_entry, fn_type, fn_ref, first_arg_ptr,
1290912930 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
1291012931 args_ptr, args_len, ret_ptr, call_result_loc);
1291112932 case ReqCompTimeInvalid:
......@@ -12924,7 +12945,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1292412945 if (type_is_invalid(impl_fn->type_entry))
1292512946 return ira->codegen->invalid_inst_gen;
1292612947
12927 impl_fn->analyzed_executable.source_node = source_instr->source_node;
12948 impl_fn->analyzed_executable.source_node = source_node;
1292812949 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
1292912950 impl_fn->branch_quota = *ira->backward_branch_quota;
1293012951
......@@ -12937,14 +12958,14 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1293712958 parent_fn_entry->calls_or_awaits_errorable_fn = true;
1293812959 }
1293912960
12940 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
12961 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack,
1294112962 new_stack_src, is_async_call_builtin, impl_fn);
1294212963 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
1294312964 return ira->codegen->invalid_inst_gen;
1294412965
1294512966 size_t impl_param_count = impl_fn_type_id->param_count;
1294612967 if (modifier == CallModifierAsync) {
12947 IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
12968 IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, impl_fn, impl_fn->type_entry,
1294812969 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
1294912970 call_result_loc);
1295012971 return ir_finish_anal(ira, result);
......@@ -12952,20 +12973,20 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1295212973
1295312974 IrInstGen *result_loc;
1295412975 if (handle_is_ptr(ira->codegen, impl_fn_type_id->return_type)) {
12955 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
12976 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
1295612977 impl_fn_type_id->return_type, nullptr, true, false);
1295712978 if (result_loc != nullptr) {
1295812979 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1295912980 return result_loc;
1296012981 }
1296112982 if (result_loc->value->type->data.pointer.is_const) {
12962 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
12983 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
1296312984 return ira->codegen->invalid_inst_gen;
1296412985 }
1296512986
12966 IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type);
12987 IrInstGen *dummy_value = ir_const(ira, scope, source_node, impl_fn_type_id->return_type);
1296712988 dummy_value->value->special = ConstValSpecialRuntime;
12968 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
12989 IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node,
1296912990 dummy_value, result_loc->value->type->data.pointer.child_type);
1297012991 if (type_is_invalid(dummy_result->value->type))
1297112992 return ira->codegen->invalid_inst_gen;
......@@ -12979,7 +13000,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1297913000 }
1298013001 }
1298113002 } else if (is_async_call_builtin) {
12982 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,
13003 result_loc = get_async_call_result_loc(ira, scope, source_node, impl_fn_type_id->return_type,
1298313004 is_async_call_builtin, args_ptr, args_len, ret_ptr);
1298413005 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
1298513006 return ira->codegen->invalid_inst_gen;
......@@ -12991,15 +13012,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1299113012 parent_fn_entry->inferred_async_node == nullptr &&
1299213013 modifier != CallModifierNoSuspend)
1299313014 {
12994 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
13015 parent_fn_entry->inferred_async_node = fn_ref->source_node;
1299513016 parent_fn_entry->inferred_async_fn = impl_fn;
1299613017 }
1299713018
12998 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr,
13019 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node,
1299913020 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
1300013021 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);
1300113022
13002 if (get_scope_typeof(source_instr->scope) == nullptr) {
13023 if (get_scope_typeof(scope) == nullptr) {
1300313024 parent_fn_entry->call_list.append(new_call_instruction);
1300413025 }
1300513026
......@@ -13027,12 +13048,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1302713048 if (param_type->id == ZigTypeIdPointer) {
1302813049 first_arg = first_arg_ptr;
1302913050 } else {
13030 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
13051 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node,
13052 first_arg_ptr, nullptr);
1303113053 if (type_is_invalid(first_arg->value->type))
1303213054 return ira->codegen->invalid_inst_gen;
1303313055 }
1303413056
13035 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type);
13057 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg->scope, first_arg_ptr_src, first_arg, param_type);
1303613058 if (type_is_invalid(casted_arg->value->type))
1303713059 return ira->codegen->invalid_inst_gen;
1303813060
......@@ -13067,18 +13089,18 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1306713089 return ira->codegen->invalid_inst_gen;
1306813090
1306913091 if (fn_entry != nullptr && fn_type_id->cc == CallingConventionInline && modifier == CallModifierNeverInline) {
13070 ir_add_error(ira, source_instr,
13092 ir_add_error_node(ira, source_node,
1307113093 buf_sprintf("no-inline call of inline function"));
1307213094 return ira->codegen->invalid_inst_gen;
1307313095 }
1307413096
13075 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src,
13097 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack, new_stack_src,
1307613098 is_async_call_builtin, fn_entry);
1307713099 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
1307813100 return ira->codegen->invalid_inst_gen;
1307913101
1308013102 if (modifier == CallModifierAsync) {
13081 IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
13103 IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, fn_entry, fn_type, fn_ref,
1308213104 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
1308313105 return ir_finish_anal(ira, result);
1308413106 }
......@@ -13087,28 +13109,28 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1308713109 parent_fn_entry->inferred_async_node == nullptr &&
1308813110 modifier != CallModifierNoSuspend)
1308913111 {
13090 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
13112 parent_fn_entry->inferred_async_node = fn_ref->source_node;
1309113113 parent_fn_entry->inferred_async_fn = fn_entry;
1309213114 }
1309313115
1309413116 IrInstGen *result_loc;
1309513117 if (handle_is_ptr(ira->codegen, return_type)) {
13096 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
13118 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
1309713119 return_type, nullptr, true, false);
1309813120 if (result_loc != nullptr) {
1309913121 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1310013122 return result_loc;
1310113123 }
1310213124 if (result_loc->value->type->data.pointer.is_const) {
13103 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
13125 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
1310413126 return ira->codegen->invalid_inst_gen;
1310513127 }
1310613128
1310713129 ZigType *expected_return_type = result_loc->value->type->data.pointer.child_type;
1310813130
13109 IrInstGen *dummy_value = ir_const(ira, source_instr, return_type);
13131 IrInstGen *dummy_value = ir_const(ira, scope, source_node, return_type);
1311013132 dummy_value->value->special = ConstValSpecialRuntime;
13111 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
13133 IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node,
1311213134 dummy_value, expected_return_type);
1311313135 if (type_is_invalid(dummy_result->value->type)) {
1311413136 if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) &&
......@@ -13118,7 +13140,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1311813140 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
1311913141 ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error"));
1312013142 } else {
13121 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node,
13143 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->source_node,
1312213144 buf_sprintf("cannot store an error in type '%s'", buf_ptr(&expected_return_type->name)));
1312313145 }
1312413146 }
......@@ -13133,7 +13155,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1313313155 }
1313413156 }
1313513157 } else if (is_async_call_builtin) {
13136 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,
13158 result_loc = get_async_call_result_loc(ira, scope, source_node, return_type, is_async_call_builtin,
1313713159 args_ptr, args_len, ret_ptr);
1313813160 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
1313913161 return ira->codegen->invalid_inst_gen;
......@@ -13141,10 +13163,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1314113163 result_loc = nullptr;
1314213164 }
1314313165
13144 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
13166 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref,
1314513167 call_param_count, casted_args, modifier, casted_new_stack,
1314613168 is_async_call_builtin, result_loc, return_type);
13147 if (get_scope_typeof(source_instr->scope) == nullptr) {
13169 if (get_scope_typeof(scope) == nullptr) {
1314813170 parent_fn_entry->call_list.append(new_call_instruction);
1314913171 }
1315013172 return ir_finish_anal(ira, &new_call_instruction->base);
......@@ -13152,15 +13174,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1315213174
1315313175static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
1315413176 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
13155 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier)
13177 IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier)
1315613178{
1315713179 IrInstGen *new_stack = nullptr;
13158 IrInst *new_stack_src = nullptr;
13180 AstNode *new_stack_src = nullptr;
1315913181 if (call_instruction->new_stack) {
1316013182 new_stack = call_instruction->new_stack->child;
1316113183 if (type_is_invalid(new_stack->value->type))
1316213184 return ira->codegen->invalid_inst_gen;
13163 new_stack_src = &call_instruction->new_stack->base;
13185 new_stack_src = call_instruction->new_stack->source_node;
1316413186 }
1316513187 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);
1316613188 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
......@@ -13174,7 +13196,8 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1317413196 if (type_is_invalid(ret_ptr->value->type))
1317513197 return ira->codegen->invalid_inst_gen;
1317613198 }
13177 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,
13199 IrInstGen *result = ir_analyze_fn_call(ira, call_instruction->base.scope,
13200 call_instruction->base.source_node, fn_entry, fn_type, fn_ref,
1317813201 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
1317913202 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
1318013203 call_instruction->result_loc);
......@@ -13182,7 +13205,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1318213205 return result;
1318313206}
1318413207
13185static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
13208static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1318613209 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
1318713210 ResultLoc *result_loc)
1318813211{
......@@ -13195,19 +13218,19 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1319513218 return ira->codegen->invalid_inst_gen;
1319613219
1319713220 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
13198 ir_assert(modifier_field != nullptr, source_instr);
13199 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
13221 src_assert(modifier_field != nullptr, source_node);
13222 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, scope, source_node, options, modifier_field);
1320013223 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
1320113224 if (modifier_val == nullptr)
1320213225 return ira->codegen->invalid_inst_gen;
1320313226 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);
1320413227
13205 if (ir_should_inline(ira->zir, source_instr->scope)) {
13228 if (ir_should_inline(ira->zir, scope)) {
1320613229 switch (modifier) {
1320713230 case CallModifierBuiltin:
1320813231 zig_unreachable();
1320913232 case CallModifierAsync:
13210 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));
13233 ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @call with async modifier"));
1321113234 return ira->codegen->invalid_inst_gen;
1321213235 case CallModifierCompileTime:
1321313236 case CallModifierNone:
......@@ -13217,18 +13240,18 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1321713240 modifier = CallModifierCompileTime;
1321813241 break;
1321913242 case CallModifierNeverInline:
13220 ir_add_error(ira, source_instr,
13243 ir_add_error_node(ira, source_node,
1322113244 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
1322213245 return ira->codegen->invalid_inst_gen;
1322313246 case CallModifierNeverTail:
13224 ir_add_error(ira, source_instr,
13247 ir_add_error_node(ira, source_node,
1322513248 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
1322613249 return ira->codegen->invalid_inst_gen;
1322713250 }
1322813251 }
1322913252
1323013253 IrInstGen *first_arg_ptr = nullptr;
13231 IrInst *first_arg_ptr_src = nullptr;
13254 AstNode *first_arg_ptr_src = nullptr;
1323213255 ZigFn *fn = nullptr;
1323313256 if (instr_is_comptime(fn_ref)) {
1323413257 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
......@@ -13249,7 +13272,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1324913272 case CallModifierAlwaysInline:
1325013273 case CallModifierAsync:
1325113274 if (fn == nullptr) {
13252 ir_add_error(ira, &modifier_inst->base,
13275 ir_add_error(ira, modifier_inst,
1325313276 buf_sprintf("the specified modifier requires a comptime-known function"));
1325413277 return ira->codegen->invalid_inst_gen;
1325513278 }
......@@ -13261,43 +13284,43 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1326113284 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;
1326213285
1326313286 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
13264 ir_assert(stack_field != nullptr, source_instr);
13265 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
13287 src_assert(stack_field != nullptr, source_node);
13288 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, scope, source_node, options, stack_field);
1326613289 if (type_is_invalid(opt_stack->value->type))
1326713290 return ira->codegen->invalid_inst_gen;
1326813291
13269 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
13292 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, scope, source_node, opt_stack);
1327013293 bool stack_is_non_null;
1327113294 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))
1327213295 return ira->codegen->invalid_inst_gen;
1327313296
1327413297 IrInstGen *stack = nullptr;
13275 IrInst *stack_src = nullptr;
13298 AstNode *stack_src = nullptr;
1327613299 if (stack_is_non_null) {
13277 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
13300 stack = ir_analyze_optional_value_payload_value(ira, scope, source_node, opt_stack, false);
1327813301 if (type_is_invalid(stack->value->type))
1327913302 return ira->codegen->invalid_inst_gen;
13280 stack_src = &stack->base;
13303 stack_src = stack->source_node;
1328113304 }
1328213305
13283 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
13306 return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
1328413307 modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc);
1328513308}
1328613309
13287static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_instr, CallModifier modifier,
13310static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node, CallModifier modifier,
1328813311 IrInstSrc *pass1_fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstGen **args_ptr, size_t args_len, ResultLoc *result_loc)
1328913312{
1329013313 IrInstGen *fn_ref = pass1_fn_ref->child;
1329113314 if (type_is_invalid(fn_ref->value->type))
1329213315 return ira->codegen->invalid_inst_gen;
1329313316
13294 if (ir_should_inline(ira->zir, source_instr->scope)) {
13295 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @asyncCall"));
13317 if (ir_should_inline(ira->zir, scope)) {
13318 ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @asyncCall"));
1329613319 return ira->codegen->invalid_inst_gen;
1329713320 }
1329813321
1329913322 IrInstGen *first_arg_ptr = nullptr;
13300 IrInst *first_arg_ptr_src = nullptr;
13323 AstNode *first_arg_ptr_src = nullptr;
1330113324 ZigFn *fn = nullptr;
1330213325 if (instr_is_comptime(fn_ref)) {
1330313326 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
......@@ -13320,22 +13343,23 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins
1332013343 }
1332113344
1332213345 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;
13323 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack->child,
13324 &new_stack->base, true, fn);
13346 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node,
13347 new_stack->child, new_stack->source_node, true, fn);
1332513348 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
1332613349 return ira->codegen->invalid_inst_gen;
1332713350
13328 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
13329 modifier, casted_new_stack, &new_stack->base, true, args_ptr, args_len, ret_ptr_uncasted, result_loc);
13351 return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr,
13352 first_arg_ptr_src, modifier, casted_new_stack, new_stack->source_node, true, args_ptr,
13353 args_len, ret_ptr_uncasted, result_loc);
1333013354}
1333113355
13332static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) {
13356static bool ir_extract_tuple_call_args(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) {
1333313357 ZigType *args_type = args->value->type;
1333413358 if (type_is_invalid(args_type))
1333513359 return false;
1333613360
1333713361 if (args_type->id != ZigTypeIdStruct) {
13338 ir_add_error(ira, &args->base,
13362 ir_add_error(ira, args,
1333913363 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));
1334013364 return false;
1334113365 }
......@@ -13345,12 +13369,12 @@ static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrI
1334513369 *args_ptr = heap::c_allocator.allocate<IrInstGen *>(*args_len);
1334613370 for (size_t i = 0; i < *args_len; i += 1) {
1334713371 TypeStructField *arg_field = args_type->data.structure.fields[i];
13348 (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, source_instr, args, arg_field);
13372 (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, scope, source_node, args, arg_field);
1334913373 if (type_is_invalid((*args_ptr)[i]->value->type))
1335013374 return false;
1335113375 }
1335213376 } else {
13353 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));
13377 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));
1335413378 return false;
1335513379 }
1335613380 return true;
......@@ -13360,11 +13384,11 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1336013384 IrInstGen *args = instruction->args->child;
1336113385 IrInstGen **args_ptr = nullptr;
1336213386 size_t args_len = 0;
13363 if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) {
13387 if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) {
1336413388 return ira->codegen->invalid_inst_gen;
1336513389 }
1336613390
13367 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
13391 IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options,
1336813392 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
1336913393 heap::c_allocator.deallocate(args_ptr, args_len);
1337013394 return result;
......@@ -13374,11 +13398,11 @@ static IrInstGen *ir_analyze_instruction_async_call_extra(IrAnalyze *ira, IrInst
1337413398 IrInstGen *args = instruction->args->child;
1337513399 IrInstGen **args_ptr = nullptr;
1337613400 size_t args_len = 0;
13377 if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) {
13401 if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) {
1337813402 return ira->codegen->invalid_inst_gen;
1337913403 }
1338013404
13381 IrInstGen *result = ir_analyze_async_call_extra(ira, &instruction->base.base, instruction->modifier,
13405 IrInstGen *result = ir_analyze_async_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->modifier,
1338213406 instruction->fn_ref, instruction->ret_ptr, instruction->new_stack, args_ptr, args_len, instruction->result_loc);
1338313407 heap::c_allocator.deallocate(args_ptr, args_len);
1338413408 return result;
......@@ -13392,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall
1339213416 return ira->codegen->invalid_inst_gen;
1339313417 }
1339413418
13395 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
13419 IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options,
1339613420 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
1339713421 heap::c_allocator.deallocate(args_ptr, instruction->args_len);
1339813422 return result;
......@@ -13404,7 +13428,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
1340413428 return ira->codegen->invalid_inst_gen;
1340513429
1340613430 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||
13407 ir_should_inline(ira->zir, call_instruction->base.base.scope);
13431 ir_should_inline(ira->zir, call_instruction->base.scope);
1340813432 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1340913433
1341013434 if (is_comptime || instr_is_comptime(fn_ref)) {
......@@ -13412,9 +13436,9 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
1341213436 ZigType *ty = ir_resolve_type(ira, fn_ref);
1341313437 if (ty == nullptr)
1341413438 return ira->codegen->invalid_inst_gen;
13415 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,
13439 ErrorMsg *msg = ir_add_error(ira, fn_ref,
1341613440 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
13417 add_error_note(ira->codegen, msg, call_instruction->base.base.source_node,
13441 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
1341813442 buf_sprintf("use @as builtin for type coercion"));
1341913443 return ira->codegen->invalid_inst_gen;
1342013444 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
......@@ -13427,12 +13451,12 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
1342713451 assert(fn_ref->value->special == ConstValSpecialStatic);
1342813452 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
1342913453 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
13430 IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
13454 AstNode *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
1343113455 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1343213456 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1343313457 fn_ref, first_arg_ptr, first_arg_ptr_src, modifier);
1343413458 } else {
13435 ir_add_error(ira, &fn_ref->base,
13459 ir_add_error(ira, fn_ref,
1343613460 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
1343713461 return ira->codegen->invalid_inst_gen;
1343813462 }
......@@ -13442,7 +13466,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
1344213466 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
1344313467 fn_ref, nullptr, nullptr, modifier);
1344413468 } else {
13445 ir_add_error(ira, &fn_ref->base,
13469 ir_add_error(ira, fn_ref,
1344613470 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
1344713471 return ira->codegen->invalid_inst_gen;
1344813472 }
......@@ -13561,7 +13585,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1356113585}
1356213586
1356313587static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
13564 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
13588 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
1356513589 result->value->special = ConstValSpecialLazy;
1356613590
1356713591 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();
......@@ -13576,7 +13600,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru
1357613600 return result;
1357713601}
1357813602
13579static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type,
13603static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *scalar_type,
1358013604 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
1358113605{
1358213606 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
......@@ -13586,7 +13610,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z
1358613610
1358713611 if (!ok_type) {
1358813612 const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'";
13589 return ir_add_error(ira, source_instr, buf_sprintf(fmt, buf_ptr(&scalar_type->name)));
13613 return ir_add_error_node(ira, source_node, buf_sprintf(fmt, buf_ptr(&scalar_type->name)));
1359013614 }
1359113615
1359213616 if (is_float) {
......@@ -13606,7 +13630,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z
1360613630 }
1360713631
1360813632 if (!bigint_fits_in_bits(&scalar_out_val->data.x_bigint, scalar_type->data.integral.bit_count, true)) {
13609 return ir_add_error(ira, source_instr, buf_sprintf("negation caused overflow"));
13633 return ir_add_error_node(ira, source_node, buf_sprintf("negation caused overflow"));
1361013634 }
1361113635 return nullptr;
1361213636}
......@@ -13632,7 +13656,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
1363213656 break;
1363313657 ZIG_FALLTHROUGH;
1363413658 default:
13635 ir_add_error(ira, &instruction->base.base,
13659 ir_add_error_node(ira, instruction->base.source_node,
1363613660 buf_sprintf("negation of type '%s'", buf_ptr(&scalar_type->name)));
1363713661 return ira->codegen->invalid_inst_gen;
1363813662 }
......@@ -13642,7 +13666,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
1364213666 if (!operand_val)
1364313667 return ira->codegen->invalid_inst_gen;
1364413668
13645 IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type);
13669 IrInstGen *result_instruction = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
1364613670 ZigValue *out_val = result_instruction->value;
1364713671 if (expr_type->id == ZigTypeIdVector) {
1364813672 expand_undef_array(ira->codegen, operand_val);
......@@ -13654,10 +13678,10 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
1365413678 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
1365513679 assert(scalar_operand_val->type == scalar_type);
1365613680 assert(scalar_out_val->type == scalar_type);
13657 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type,
13681 ErrorMsg *msg = ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type,
1365813682 scalar_operand_val, scalar_out_val, is_wrap_op);
1365913683 if (msg != nullptr) {
13660 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
13684 add_error_note(ira->codegen, msg, instruction->base.source_node,
1366113685 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
1366213686 return ira->codegen->invalid_inst_gen;
1366313687 }
......@@ -13665,7 +13689,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
1366513689 out_val->type = expr_type;
1366613690 out_val->special = ConstValSpecialStatic;
1366713691 } else {
13668 if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val,
13692 if (ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type, operand_val, out_val,
1366913693 is_wrap_op) != nullptr)
1367013694 {
1367113695 return ira->codegen->invalid_inst_gen;
......@@ -13674,7 +13698,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
1367413698 return result_instruction;
1367513699 }
1367613700
13677 return ir_build_negation(ira, &instruction->base.base, value, expr_type, is_wrap_op);
13701 return ir_build_negation(ira, instruction->base.scope, instruction->base.source_node, value, expr_type, is_wrap_op);
1367813702}
1367913703
1368013704static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
......@@ -13687,7 +13711,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
1368713711 expr_type->data.vector.elem_type : expr_type;
1368813712
1368913713 if (scalar_type->id != ZigTypeIdInt) {
13690 ir_add_error(ira, &instruction->base.base,
13714 ir_add_error_node(ira, instruction->base.source_node,
1369113715 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));
1369213716 return ira->codegen->invalid_inst_gen;
1369313717 }
......@@ -13697,7 +13721,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
1369713721 if (expr_val == nullptr)
1369813722 return ira->codegen->invalid_inst_gen;
1369913723
13700 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
13724 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
1370113725
1370213726 if (expr_type->id == ZigTypeIdVector) {
1370313727 expand_undef_array(ira->codegen, expr_val);
......@@ -13721,7 +13745,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
1372113745 return result;
1372213746 }
1372313747
13724 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);
13748 return ir_build_binary_not(ira, instruction->base.scope, instruction->base.source_node, value, expr_type);
1372513749}
1372613750
1372713751static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
......@@ -13740,19 +13764,20 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in
1374013764 return ira->codegen->invalid_inst_gen;
1374113765 ZigType *ptr_type = ptr->value->type;
1374213766 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
13743 ir_add_error_node(ira, instruction->base.base.source_node,
13767 ir_add_error_node(ira, instruction->base.source_node,
1374413768 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
1374513769 buf_ptr(&ptr_type->name)));
1374613770 return ira->codegen->invalid_inst_gen;
1374713771 }
1374813772
13749 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);
13773 IrInstGen *result = ir_get_deref(ira, instruction->base.scope,
13774 instruction->base.source_node, ptr, instruction->result_loc);
1375013775 if (type_is_invalid(result->value->type))
1375113776 return ira->codegen->invalid_inst_gen;
1375213777
1375313778 // If the result needs to be an lvalue, type check it
1375413779 if (instruction->lval != LValNone && result->value->type->id != ZigTypeIdPointer) {
13755 ir_add_error(ira, &instruction->base.base,
13780 ir_add_error_node(ira, instruction->base.source_node,
1375613781 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
1375713782 return ira->codegen->invalid_inst_gen;
1375813783 }
......@@ -13786,15 +13811,15 @@ static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_inst
1378613811 return ir_unreach_error(ira);
1378713812
1378813813 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
13789 return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block);
13814 return ir_inline_bb(ira, br_instruction->base.source_node, old_dest_block);
1379013815
13791 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base);
13816 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
1379213817 if (new_bb == nullptr)
1379313818 return ir_unreach_error(ira);
1379413819
1379513820 ir_push_resume_block(ira, old_dest_block);
1379613821
13797 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);
13822 IrInstGen *result = ir_build_br_gen(ira, br_instruction->base.scope, br_instruction->base.source_node, new_bb);
1379813823 return ir_finish_anal(ira, result);
1379913824}
1380013825
......@@ -13821,44 +13846,48 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr
1382113846 cond_br_instruction->then_block : cond_br_instruction->else_block;
1382213847
1382313848 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
13824 return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block);
13849 return ir_inline_bb(ira, cond_br_instruction->base.source_node, old_dest_block);
1382513850
13826 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base);
13851 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
1382713852 if (new_dest_block == nullptr)
1382813853 return ir_unreach_error(ira);
1382913854
1383013855 ir_push_resume_block(ira, old_dest_block);
1383113856
13832 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);
13857 IrInstGen *result = ir_build_br_gen(ira, cond_br_instruction->base.scope,
13858 cond_br_instruction->base.source_node, new_dest_block);
1383313859 return ir_finish_anal(ira, result);
1383413860 }
1383513861
1383613862 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
13837 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base);
13863 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
1383813864 if (new_then_block == nullptr)
1383913865 return ir_unreach_error(ira);
1384013866
13841 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base);
13867 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
1384213868 if (new_else_block == nullptr)
1384313869 return ir_unreach_error(ira);
1384413870
1384513871 ir_push_resume_block(ira, cond_br_instruction->else_block);
1384613872 ir_push_resume_block(ira, cond_br_instruction->then_block);
1384713873
13848 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,
13849 casted_condition, new_then_block, new_else_block);
13874 IrInstGen *result = ir_build_cond_br_gen(ira, cond_br_instruction->base.scope,
13875 cond_br_instruction->base.source_node, casted_condition, new_then_block,
13876 new_else_block);
1385013877 return ir_finish_anal(ira, result);
1385113878}
1385213879
1385313880static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
1385413881 IrInstSrcUnreachable *unreachable_instruction)
1385513882{
13856 if (ir_should_inline(ira->zir, unreachable_instruction->base.base.scope)) {
13857 ir_add_error(ira, &unreachable_instruction->base.base, buf_sprintf("reached unreachable code"));
13883 if (ir_should_inline(ira->zir, unreachable_instruction->base.scope)) {
13884 ir_add_error_node(ira, unreachable_instruction->base.source_node,
13885 buf_sprintf("reached unreachable code"));
1385813886 return ir_unreach_error(ira);
1385913887 }
1386013888
13861 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);
13889 IrInstGen *result = ir_build_unreachable_gen(ira, unreachable_instruction->base.scope,
13890 unreachable_instruction->base.source_node);
1386213891 return ir_finish_anal(ira, result);
1386313892}
1386413893
......@@ -13876,7 +13905,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1387613905 return ira->codegen->invalid_inst_gen;
1387713906
1387813907 if (value->value->special != ConstValSpecialRuntime) {
13879 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
13908 IrInstGen *result = ir_const(ira, phi_instruction->base.scope,
13909 phi_instruction->base.source_node, nullptr);
1388013910 copy_const_val(ira->codegen, result->value, value->value);
1388113911 return result;
1388213912 } else {
......@@ -13899,9 +13929,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1389913929 if (gen_instruction == nullptr) {
1390013930 // unreachable instructions will cause implicit_elem_type to be null
1390113931 if (this_peer->base.implicit_elem_type == nullptr) {
13902 instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base);
13932 instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction->scope, this_peer->base.source_instruction->source_node);
1390313933 } else {
13904 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,
13934 instructions[i] = ir_const(ira, this_peer->base.source_instruction->scope,
13935 this_peer->base.source_instruction->source_node,
1390513936 this_peer->base.implicit_elem_type);
1390613937 instructions[i]->value->special = ConstValSpecialRuntime;
1390713938 }
......@@ -13910,18 +13941,19 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1391013941 }
1391113942
1391213943 }
13913 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent);
13944 ZigType *expected_type = ir_result_loc_expected_type(ira, peer_parent->parent);
1391413945 peer_parent->resolved_type = ir_resolve_peer_types(ira,
13915 peer_parent->base.source_instruction->base.source_node, expected_type, instructions,
13946 peer_parent->base.source_instruction->source_node, expected_type, instructions,
1391613947 peer_parent->peers.length);
1391713948 if (type_is_invalid(peer_parent->resolved_type))
1391813949 return ira->codegen->invalid_inst_gen;
1391913950
1392013951 // the logic below assumes there are no instructions in the new current basic block yet
13921 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);
13952 src_assert(ira->new_irb.current_basic_block->instruction_list.length == 0,
13953 phi_instruction->base.source_node);
1392213954
1392313955 // In case resolving the parent activates a suspend, do it now
13924 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,
13956 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
1392513957 peer_parent->resolved_type, nullptr, false, true);
1392613958 if (parent_result_loc != nullptr &&
1392713959 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))
......@@ -13937,7 +13969,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1393713969 if (instrs_to_move.length != 0) {
1393813970 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
1393913971 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
13940 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);
13972 src_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable,
13973 phi_instruction->base.source_node);
1394113974 while (instrs_to_move.length != 0) {
1394213975 predecessor->instruction_list.append(instrs_to_move.pop());
1394313976 }
......@@ -13947,7 +13980,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1394713980 }
1394813981
1394913982 IrSuspendPosition suspend_pos;
13950 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);
13983 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);
1395113984 ir_push_resume(ira, suspend_pos);
1395213985
1395313986 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
......@@ -13988,7 +14021,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1398814021 }
1398914022
1399014023 if (new_incoming_blocks.length == 0) {
13991 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);
14024 IrInstGen *result = ir_build_unreachable_gen(ira, phi_instruction->base.scope,
14025 phi_instruction->base.source_node);
1399214026 return ir_finish_anal(ira, result);
1399314027 }
1399414028
......@@ -14011,7 +14045,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1401114045 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
1401214046 } else if (peer_parent->parent->resolved_loc) {
1401314047 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
14014 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base);
14048 src_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer,
14049 phi_instruction->base.source_node);
1401514050 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
1401614051 }
1401714052
......@@ -14021,7 +14056,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1402114056 }
1402214057
1402314058 if (resolved_type == nullptr) {
14024 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr,
14059 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
1402514060 new_incoming_values.items, new_incoming_values.length);
1402614061 if (type_is_invalid(resolved_type))
1402714062 return ira->codegen->invalid_inst_gen;
......@@ -14031,7 +14066,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1403114066 case OnePossibleValueInvalid:
1403214067 return ira->codegen->invalid_inst_gen;
1403314068 case OnePossibleValueYes:
14034 return ir_const_move(ira, &phi_instruction->base.base,
14069 return ir_const_move(ira, phi_instruction->base.scope, phi_instruction->base.source_node,
1403514070 get_the_one_possible_value(ira->codegen, resolved_type));
1403614071 case OnePossibleValueNo:
1403714072 break;
......@@ -14041,7 +14076,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1404114076 case ReqCompTimeInvalid:
1404214077 return ira->codegen->invalid_inst_gen;
1404314078 case ReqCompTimeYes:
14044 ir_add_error(ira, &phi_instruction->base.base,
14079 ir_add_error_node(ira, phi_instruction->base.source_node,
1404514080 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));
1404614081 return ira->codegen->invalid_inst_gen;
1404714082 case ReqCompTimeNo:
......@@ -14057,7 +14092,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1405714092 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
1405814093 IrInstGen *new_value = new_incoming_values.at(i);
1405914094 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
14060 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);
14095 src_assert(predecessor->instruction_list.length != 0, phi_instruction->base.source_node);
1406114096 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
1406214097 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
1406314098 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
......@@ -14075,8 +14110,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1407514110 }
1407614111 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);
1407714112
14078 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,
14079 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);
14113 IrInstGen *result = ir_build_phi_gen(ira, phi_instruction->base.scope,
14114 phi_instruction->base.source_node, new_incoming_blocks.length,
14115 new_incoming_blocks.items, new_incoming_values.items, resolved_type);
1408014116
1408114117 if (all_stack_ptrs) {
1408214118 assert(result->value->special == ConstValSpecialRuntime);
......@@ -14088,9 +14124,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1408814124
1408914125static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
1409014126 ZigVar *var = instruction->var;
14091 IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var);
14127 IrInstGen *result = ir_get_var_ptr(ira, instruction->base.scope, instruction->base.source_node, var);
1409214128 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
14093 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
14129 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
1409414130 buf_sprintf("'%s' not accessible from inner function", var->name));
1409514131 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
1409614132 buf_sprintf("crossed function definition here"));
......@@ -14244,8 +14280,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1424414280 array_type->data.pointer.ptr_len == PtrLenSingle &&
1424514281 array_type->data.pointer.child_type->id == ZigTypeIdArray)
1424614282 {
14247 IrInstGen *ptr_value = ir_get_deref(ira, &elem_ptr_instruction->base.base,
14248 array_ptr, nullptr);
14283 IrInstGen *ptr_value = ir_get_deref(ira, elem_ptr_instruction->base.scope,
14284 elem_ptr_instruction->base.source_node, array_ptr, nullptr);
1424914285 if (type_is_invalid(ptr_value->value->type))
1425014286 return ira->codegen->invalid_inst_gen;
1425114287
......@@ -14257,7 +14293,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1425714293
1425814294 if (array_type->id == ZigTypeIdArray) {
1425914295 if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){
14260 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("accessing a zero length array is not allowed"));
14296 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14297 buf_sprintf("accessing a zero length array is not allowed"));
1426114298 return ira->codegen->invalid_inst_gen;
1426214299 }
1426314300
......@@ -14282,7 +14319,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1428214319 }
1428314320 } else if (array_type->id == ZigTypeIdPointer) {
1428414321 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
14285 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14322 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1428614323 buf_sprintf("index of single-item pointer"));
1428714324 return ira->codegen->invalid_inst_gen;
1428814325 }
......@@ -14301,27 +14338,27 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1430114338 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
1430214339 if (type_is_invalid(casted_elem_index->value->type))
1430314340 return ira->codegen->invalid_inst_gen;
14304 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);
14341 src_assert(instr_is_comptime(casted_elem_index), elem_ptr_instruction->base.source_node);
1430514342 Buf *field_name = buf_alloc();
1430614343 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
14307 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base,
14344 return ir_analyze_inferred_field_ptr(ira, field_name, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
1430814345 array_ptr, array_type);
1430914346 } else if (is_tuple(array_type)) {
1431014347 uint64_t elem_index_scalar;
1431114348 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
1431214349 return ira->codegen->invalid_inst_gen;
1431314350 if (elem_index_scalar >= array_type->data.structure.src_field_count) {
14314 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf(
14351 ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf(
1431514352 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
1431614353 elem_index_scalar, buf_ptr(&array_type->name),
1431714354 array_type->data.structure.src_field_count));
1431814355 return ira->codegen->invalid_inst_gen;
1431914356 }
1432014357 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];
14321 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr,
14358 return ir_analyze_struct_field_ptr(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, field, array_ptr,
1432214359 array_type, false);
1432314360 } else {
14324 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14361 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1432514362 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
1432614363 return ira->codegen->invalid_inst_gen;
1432714364 }
......@@ -14342,7 +14379,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1434214379 uint64_t array_len = array_type->data.array.len +
1434314380 (array_type->data.array.sentinel != nullptr);
1434414381 if (index >= array_len) {
14345 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14382 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1434614383 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
1434714384 index, array_len));
1434814385 return ira->codegen->invalid_inst_gen;
......@@ -14351,7 +14388,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1435114388 } else if (array_type->id == ZigTypeIdVector) {
1435214389 uint64_t vector_len = array_type->data.vector.len;
1435314390 if (index >= vector_len) {
14354 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14391 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1435514392 buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64,
1435614393 index, vector_len));
1435714394 return ira->codegen->invalid_inst_gen;
......@@ -14385,13 +14422,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1438514422 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))
1438614423 {
1438714424 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14388 elem_ptr_instruction->base.base.source_node, orig_array_ptr_val, UndefBad)))
14425 elem_ptr_instruction->base.source_node, orig_array_ptr_val, UndefBad)))
1438914426 {
1439014427 return ira->codegen->invalid_inst_gen;
1439114428 }
1439214429
1439314430 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
14394 elem_ptr_instruction->base.base.source_node);
14431 elem_ptr_instruction->base.source_node);
1439514432 if (array_ptr_val == nullptr)
1439614433 return ira->codegen->invalid_inst_gen;
1439714434
......@@ -14411,7 +14448,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1441114448 elem_val->parent.data.p_array.elem_index = i;
1441214449 }
1441314450 } else if (is_slice(array_type)) {
14414 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base);
14451 src_assert(array_ptr->value->type->id == ZigTypeIdPointer, elem_ptr_instruction->base.source_node);
1441514452 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1441614453
1441714454 if (type_is_invalid(actual_array_type))
......@@ -14454,12 +14491,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1445414491 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
1445514492 {
1445614493 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14457 elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk)))
14494 elem_ptr_instruction->base.source_node, array_ptr_val, UndefOk)))
1445814495 {
1445914496 return ira->codegen->invalid_inst_gen;
1446014497 }
1446114498 if (array_type->id == ZigTypeIdPointer) {
14462 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
14499 IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type);
1446314500 ZigValue *out_val = result->value;
1446414501 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
1446514502 size_t new_index;
......@@ -14529,7 +14566,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1452914566 zig_panic("TODO elem ptr on a null pointer");
1453014567 }
1453114568 if (new_index >= mem_size) {
14532 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14569 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1453314570 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
1453414571 return ira->codegen->invalid_inst_gen;
1453514572 }
......@@ -14538,21 +14575,22 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1453814575 expand_undef_struct(ira->codegen, array_ptr_val);
1453914576
1454014577 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
14541 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);
14578 src_assert(ptr_field != nullptr, elem_ptr_instruction->base.source_node);
1454214579 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
14543 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
14544 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,
14580 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14581 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
1454514582 return_type);
1454614583 }
1454714584 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
14548 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
14585 IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope,
14586 elem_ptr_instruction->base.source_node, return_type);
1454914587 ZigValue *out_val = result->value;
1455014588 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
1455114589 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
1455214590 uint64_t full_slice_len = slice_len +
1455314591 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
1455414592 if (index >= full_slice_len) {
14555 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
14593 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1455614594 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
1455714595 index, slice_len));
1455814596 return ira->codegen->invalid_inst_gen;
......@@ -14575,7 +14613,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1457514613 ConstArraySpecialBuf)
1457614614 {
1457714615 if (new_index >= ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len) {
14578 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("out of bounds slice"));
14616 ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf("out of bounds slice"));
1457914617 return ira->codegen->invalid_inst_gen;
1458014618 }
1458114619 }
......@@ -14606,12 +14644,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1460614644
1460714645 IrInstGen *result;
1460814646 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14609 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
14610 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,
14647 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14648 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
1461114649 false, return_type);
1461214650 result->value->special = ConstValSpecialStatic;
1461314651 } else {
14614 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
14652 result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type);
1461514653 }
1461614654 ZigValue *out_val = result->value;
1461714655 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
......@@ -14637,7 +14675,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1463714675 // runtime known element index
1463814676 switch (type_requires_comptime(ira->codegen, return_type)) {
1463914677 case ReqCompTimeYes:
14640 ir_add_error(ira, &elem_index->base,
14678 ir_add_error(ira, elem_index,
1464114679 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
1464214680 buf_ptr(&return_type->data.pointer.child_type->name)));
1464314681 return ira->codegen->invalid_inst_gen;
......@@ -14667,13 +14705,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1466714705 }
1466814706 }
1466914707
14670 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
14671 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
14708 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14709 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
1467214710}
1467314711
1467414712static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14675 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
14676 IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type)
14713 ZigType *bare_struct_type, Buf *field_name, Scope *scope, AstNode *source_node,
14714 IrInstGen *container_ptr, AstNode *container_ptr_src, ZigType *container_type)
1467714715{
1467814716 if (!is_slice(bare_struct_type)) {
1467914717 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
......@@ -14681,16 +14719,16 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1468114719 auto tld = find_container_decl(ira->codegen, container_scope, field_name);
1468214720 if (tld) {
1468314721 if (tld->id == TldIdFn) {
14684 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
14722 resolve_top_level_decl(ira->codegen, tld, source_node, false);
1468514723 if (tld->resolution == TldResolutionInvalid)
1468614724 return ira->codegen->invalid_inst_gen;
1468714725 if (tld->resolution == TldResolutionResolving)
14688 return ir_error_dependency_loop(ira, source_instr);
14726 return ir_error_dependency_loop(ira, source_node);
1468914727
1469014728 if (tld->visib_mod == VisibModPrivate &&
14691 tld->import != get_scope_import(source_instr->scope))
14729 tld->import != get_scope_import(scope))
1469214730 {
14693 ErrorMsg *msg = ir_add_error(ira, source_instr,
14731 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1469414732 buf_sprintf("'%s' is private", buf_ptr(field_name)));
1469514733 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
1469614734 return ira->codegen->invalid_inst_gen;
......@@ -14703,15 +14741,15 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1470314741 if (type_is_invalid(fn_entry->type_entry))
1470414742 return ira->codegen->invalid_inst_gen;
1470514743
14706 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr,
14744 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn_entry, container_ptr,
1470714745 container_ptr_src);
14708 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
14746 return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false);
1470914747 } else if (tld->id == TldIdVar) {
14710 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
14748 resolve_top_level_decl(ira->codegen, tld, source_node, false);
1471114749 if (tld->resolution == TldResolutionInvalid)
1471214750 return ira->codegen->invalid_inst_gen;
1471314751 if (tld->resolution == TldResolutionResolving)
14714 return ir_error_dependency_loop(ira, source_instr);
14752 return ir_error_dependency_loop(ira, source_node);
1471514753
1471614754 TldVar *tld_var = (TldVar *)tld;
1471714755 ZigVar *var = tld_var->var;
......@@ -14721,11 +14759,11 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1472114759 return ira->codegen->invalid_inst_gen;
1472214760
1472314761 if (var->const_value->type->id == ZigTypeIdFn) {
14724 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
14762 src_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
1472514763 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
14726 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr,
14764 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn, container_ptr,
1472714765 container_ptr_src);
14728 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
14766 return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false);
1472914767 }
1473014768 }
1473114769 }
......@@ -14744,7 +14782,7 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
1474414782 } else {
1474514783 prefix_name = "";
1474614784 }
14747 ir_add_error_node(ira, source_instr->source_node,
14785 ir_add_error_node(ira, source_node,
1474814786 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));
1474914787 return ira->codegen->invalid_inst_gen;
1475014788}
......@@ -14762,7 +14800,7 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
1476214800 field->type_entry, nullptr, UndefOk);
1476314801}
1476414802
14765static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
14803static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1476614804 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
1476714805{
1476814806 Error err;
......@@ -14770,21 +14808,21 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1477014808 if (field_type == nullptr)
1477114809 return ira->codegen->invalid_inst_gen;
1477214810 if (field->is_comptime) {
14773 IrInstGen *elem = ir_const(ira, source_instr, field_type);
14811 IrInstGen *elem = ir_const(ira, scope, source_node, field_type);
1477414812 memoize_field_init_val(ira->codegen, struct_type, field);
1477514813 if(field->init_val != nullptr && type_is_invalid(field->init_val->type)){
1477614814 return ira->codegen->invalid_inst_gen;
1477714815 }
1477814816 copy_const_val(ira->codegen, elem->value, field->init_val);
14779 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);
14817 return ir_get_ref2(ira, scope, source_node, elem, field_type, true, false);
1478014818 }
1478114819 switch (type_has_one_possible_value(ira->codegen, field_type)) {
1478214820 case OnePossibleValueInvalid:
1478314821 return ira->codegen->invalid_inst_gen;
1478414822 case OnePossibleValueYes: {
14785 IrInstGen *elem = ir_const_move(ira, source_instr,
14823 IrInstGen *elem = ir_const_move(ira, scope, source_node,
1478614824 get_the_one_possible_value(ira->codegen, field_type));
14787 return ir_get_ref(ira, source_instr, elem,
14825 return ir_get_ref(ira, scope, source_node, elem,
1478814826 struct_ptr->value->type->data.pointer.is_const,
1478914827 struct_ptr->value->type->data.pointer.is_volatile);
1479014828 }
......@@ -14819,7 +14857,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1481914857 return ira->codegen->invalid_inst_gen;
1482014858
1482114859 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14822 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
14860 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
1482314861 if (struct_val == nullptr)
1482414862 return ira->codegen->invalid_inst_gen;
1482514863 if (type_is_invalid(struct_val->type))
......@@ -14827,7 +14865,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1482714865
1482814866 // This to allow lazy values to be resolved.
1482914867 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14830 source_instr->source_node, struct_val, UndefOk)))
14868 source_node, struct_val, UndefOk)))
1483114869 {
1483214870 return ira->codegen->invalid_inst_gen;
1483314871 }
......@@ -14846,10 +14884,10 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1484614884 }
1484714885 IrInstGen *result;
1484814886 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14849 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
14887 result = ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type);
1485014888 result->value->special = ConstValSpecialStatic;
1485114889 } else {
14852 result = ir_const(ira, source_instr, ptr_type);
14890 result = ir_const(ira, scope, source_node, ptr_type);
1485314891 }
1485414892 ZigValue *const_val = result->value;
1485514893 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
......@@ -14859,11 +14897,11 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1485914897 return result;
1486014898 }
1486114899 }
14862 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
14900 return ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type);
1486314901}
1486414902
1486514903static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
14866 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)
14904 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type)
1486714905{
1486814906 // The type of the field is not available until a store using this pointer happens.
1486914907 // So, here we create a special pointer type which has the inferred struct type and
......@@ -14872,7 +14910,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
1487214910 // struct.
1487314911
1487414912 ZigType *container_ptr_type = container_ptr->value->type;
14875 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
14913 src_assert(container_ptr_type->id == ZigTypeIdPointer, source_node);
1487614914
1487714915 InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>();
1487814916 inferred_struct_field->inferred_struct_type = container_type;
......@@ -14890,20 +14928,20 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
1489014928
1489114929 IrInstGen *result;
1489214930 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14893 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);
14931 result = ir_build_cast(ira, scope, source_node, container_ptr_type, container_ptr, CastOpNoop);
1489414932 } else {
14895 result = ir_const(ira, source_instr, field_ptr_type);
14933 result = ir_const(ira, scope, source_node, field_ptr_type);
1489614934 }
1489714935 copy_const_val(ira->codegen, result->value, ptr_val);
1489814936 result->value->type = field_ptr_type;
1489914937 return result;
1490014938 }
1490114939
14902 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);
14940 return ir_build_cast(ira, scope, source_node, field_ptr_type, container_ptr, CastOpNoop);
1490314941}
1490414942
1490514943static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
14906 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
14944 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src,
1490714945 ZigType *container_type, bool initializing)
1490814946{
1490914947 Error err;
......@@ -14913,13 +14951,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1491314951 if (initializing && bare_type->id == ZigTypeIdStruct &&
1491414952 bare_type->data.structure.resolve_status == ResolveStatusBeingInferred)
1491514953 {
14916 return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type);
14954 return ir_analyze_inferred_field_ptr(ira, field_name, scope, source_node, container_ptr, bare_type);
1491714955 }
1491814956
1491914957 // Tracks wether we should return an undefined value of the correct type.
1492014958 // We do this if the container pointer is undefined and we are in a TypeOf call.
1492114959 bool return_undef = container_ptr->value->special == ConstValSpecialUndef && \
14922 get_scope_typeof(source_instr->scope) != nullptr;
14960 get_scope_typeof(scope) != nullptr;
1492314961
1492414962 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
1492514963 return ira->codegen->invalid_inst_gen;
......@@ -14931,19 +14969,19 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1493114969 if (return_undef) {
1493214970 ZigType *field_ptr_type = get_pointer_to_type(ira->codegen, resolve_struct_field_type(ira->codegen, field),
1493314971 container_ptr->value->type->data.pointer.is_const);
14934 return ir_const_undef(ira, source_instr, field_ptr_type);
14972 return ir_const_undef(ira, scope, source_node, field_ptr_type);
1493514973 }
1493614974
14937 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);
14975 return ir_analyze_struct_field_ptr(ira, scope, source_node, field, container_ptr, bare_type, initializing);
1493814976 } else {
1493914977 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14940 source_instr, container_ptr, container_ptr_src, container_type);
14978 scope, source_node, container_ptr, container_ptr_src, container_type);
1494114979 }
1494214980 }
1494314981
1494414982 if (bare_type->id == ZigTypeIdEnum || bare_type->id == ZigTypeIdOpaque) {
1494514983 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14946 source_instr, container_ptr, container_ptr_src, container_type);
14984 scope, source_node, container_ptr, container_ptr_src, container_type);
1494714985 }
1494814986
1494914987 if (bare_type->id == ZigTypeIdUnion) {
......@@ -14953,7 +14991,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1495314991 TypeUnionField *field = find_union_type_field(bare_type, field_name);
1495414992 if (field == nullptr) {
1495514993 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14956 source_instr, container_ptr, container_ptr_src, container_type);
14994 scope, source_node, container_ptr, container_ptr_src, container_type);
1495714995 }
1495814996
1495914997 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
......@@ -14969,7 +15007,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1496915007
1497015008 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
1497115009 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14972 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
15010 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
1497315011 if (union_val == nullptr)
1497415012 return ira->codegen->invalid_inst_gen;
1497515013 if (type_is_invalid(union_val->type))
......@@ -14980,7 +15018,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1498015018 // its payload slot is UB.
1498115019 const UndefAllowed allow_undef = initializing ? UndefOk : UndefBad;
1498215020 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14983 source_instr->source_node, union_val, allow_undef)))
15021 source_node, union_val, allow_undef)))
1498415022 {
1498515023 return ira->codegen->invalid_inst_gen;
1498615024 }
......@@ -15001,7 +15039,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1500115039 zig_unreachable();
1500215040
1500315041 if (field != actual_field) {
15004 ir_add_error_node(ira, source_instr->source_node,
15042 ir_add_error_node(ira, source_node,
1500515043 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
1500615044 buf_ptr(actual_field->name)));
1500715045 return ira->codegen->invalid_inst_gen;
......@@ -15013,11 +15051,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1501315051
1501415052 IrInstGen *result;
1501515053 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
15016 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,
15054 result = ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true,
1501715055 initializing, ptr_type);
1501815056 result->value->special = ConstValSpecialStatic;
1501915057 } else {
15020 result = ir_const(ira, source_instr, ptr_type);
15058 result = ir_const(ira, scope, source_node, ptr_type);
1502115059 }
1502215060 ZigValue *const_val = result->value;
1502315061 const_val->data.x_ptr.special = ConstPtrSpecialRef;
......@@ -15027,7 +15065,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1502715065 }
1502815066 }
1502915067
15030 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);
15068 return ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true, initializing, ptr_type);
1503115069 }
1503215070
1503315071 zig_unreachable();
......@@ -15042,18 +15080,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
1504215080 }
1504315081}
1504415082
15045static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
15046 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
15083static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode* source_node) {
15084 ir_add_error_node(ira, source_node, buf_sprintf("dependency loop detected"));
1504715085 return ira->codegen->invalid_inst_gen;
1504815086}
1504915087
15050static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) {
15051 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
15088static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, Tld *tld) {
15089 resolve_top_level_decl(ira->codegen, tld, source_node, true);
1505215090 if (tld->resolution == TldResolutionInvalid) {
1505315091 return ira->codegen->invalid_inst_gen;
1505415092 }
1505515093 if (tld->resolution == TldResolutionResolving)
15056 return ir_error_dependency_loop(ira, source_instruction);
15094 return ir_error_dependency_loop(ira, source_node);
1505715095
1505815096 switch (tld->id) {
1505915097 case TldIdContainer:
......@@ -15067,10 +15105,10 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
1506715105
1506815106 if (tld_var->extern_lib_name != nullptr) {
1506915107 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
15070 source_instruction->source_node);
15108 source_node);
1507115109 }
1507215110
15073 return ir_get_var_ptr(ira, source_instruction, var);
15111 return ir_get_var_ptr(ira, scope, source_node, var);
1507415112 }
1507515113 case TldIdFn: {
1507615114 TldFn *tld_fn = (TldFn *)tld;
......@@ -15081,11 +15119,11 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
1508115119 return ira->codegen->invalid_inst_gen;
1508215120
1508315121 if (tld_fn->extern_lib_name != nullptr) {
15084 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
15122 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_node);
1508515123 }
1508615124
15087 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);
15088 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
15125 IrInstGen *fn_inst = ir_const_fn(ira, scope, source_node, fn_entry);
15126 return ir_get_ref(ira, scope, source_node, fn_inst, true, false);
1508915127 }
1509015128 }
1509115129 zig_unreachable();
......@@ -15119,27 +15157,30 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1511915157 }
1512015158
1512115159
15122 AstNode *source_node = field_ptr_instruction->base.base.source_node;
15160 AstNode *source_node = field_ptr_instruction->base.source_node;
1512315161
1512415162 if (type_is_invalid(container_type)) {
1512515163 return ira->codegen->invalid_inst_gen;
1512615164 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
15127 IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base,
15165 IrInstGen *len_inst = ir_const_unsigned(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
1512815166 container_type->data.structure.src_field_count);
15129 return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false);
15167 return ir_get_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_inst, true, false);
1513015168 } else if (is_slice(container_type) || is_container_ref(container_type)) {
1513115169 assert(container_ptr->value->type->id == ZigTypeIdPointer);
1513215170 if (container_type->id == ZigTypeIdPointer) {
1513315171 ZigType *bare_type = container_ref_type(container_type);
15134 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);
15135 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
15136 container_child, &field_ptr_instruction->container_ptr->base, bare_type,
15172 IrInstGen *container_child = ir_get_deref(ira, field_ptr_instruction->base.scope,
15173 field_ptr_instruction->base.source_node, container_ptr, nullptr);
15174 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name,
15175 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15176 container_child, field_ptr_instruction->container_ptr->source_node, bare_type,
1513715177 field_ptr_instruction->initializing);
1513815178 return result;
1513915179 } else {
15140 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
15141 container_ptr, &field_ptr_instruction->container_ptr->base, container_type,
15142 field_ptr_instruction->initializing);
15180 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name,
15181 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15182 container_ptr, field_ptr_instruction->container_ptr->source_node,
15183 container_type, field_ptr_instruction->initializing);
1514315184 return result;
1514415185 }
1514515186 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
......@@ -15154,7 +15195,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1515415195 ZigType *usize = ira->codegen->builtin_types.entry_usize;
1515515196 bool ptr_is_const = true;
1515615197 bool ptr_is_volatile = false;
15157 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val,
15198 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_val,
1515815199 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
1515915200 } else {
1516015201 ir_add_error_node(ira, source_node,
......@@ -15172,7 +15213,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1517215213 if (child_val == nullptr)
1517315214 return ira->codegen->invalid_inst_gen;
1517415215 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
15175 field_ptr_instruction->base.base.source_node, child_val, UndefBad)))
15216 field_ptr_instruction->base.source_node, child_val, UndefBad)))
1517615217 {
1517715218 return ira->codegen->invalid_inst_gen;
1517815219 }
......@@ -15189,7 +15230,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1518915230 if (field) {
1519015231 bool ptr_is_const = true;
1519115232 bool ptr_is_volatile = false;
15192 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
15233 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
1519315234 create_const_enum(ira->codegen, child_type, &field->value), child_type,
1519415235 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
1519515236 }
......@@ -15198,14 +15239,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1519815239 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
1519915240 if (tld) {
1520015241 if (tld->visib_mod == VisibModPrivate &&
15201 tld->import != get_scope_import(field_ptr_instruction->base.base.scope))
15242 tld->import != get_scope_import(field_ptr_instruction->base.scope))
1520215243 {
15203 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,
15204 buf_sprintf("'%s' is private", buf_ptr(field_name)));
15244 ErrorMsg *msg = ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15245 buf_sprintf("'%s' is private", buf_ptr(field_name)));
1520515246 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
1520615247 return ira->codegen->invalid_inst_gen;
1520715248 }
15208 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld);
15249 return ir_analyze_decl_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, tld);
1520915250 }
1521015251 if (child_type->id == ZigTypeIdUnion &&
1521115252 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
......@@ -15218,14 +15259,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1521815259 ZigType *enum_type = child_type->data.unionation.tag_type;
1521915260 bool ptr_is_const = true;
1522015261 bool ptr_is_volatile = false;
15221 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
15262 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
1522215263 create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type,
1522315264 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
1522415265 }
1522515266 }
1522615267 const char *container_name = (child_type == ira->codegen->root_import) ?
1522715268 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
15228 ir_add_error(ira, &field_ptr_instruction->base.base,
15269 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1522915270 buf_sprintf("%s has no member called '%s'",
1523015271 container_name, buf_ptr(field_name)));
1523115272 return ira->codegen->invalid_inst_gen;
......@@ -15238,7 +15279,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1523815279 err_entry = existing_entry->value;
1523915280 } else {
1524015281 err_entry = heap::c_allocator.create<ErrorTableEntry>();
15241 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
15282 err_entry->decl_node = field_ptr_instruction->base.source_node;
1524215283 buf_init_from_buf(&err_entry->name, field_name);
1524315284 size_t error_value_count = ira->codegen->errors_by_index.length;
1524415285 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));
......@@ -15248,17 +15289,17 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1524815289 }
1524915290 if (err_entry->set_with_only_this_in_it == nullptr) {
1525015291 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,
15251 field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node,
15292 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
1525215293 err_entry);
1525315294 }
1525415295 err_set_type = err_entry->set_with_only_this_in_it;
1525515296 } else {
15256 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {
15297 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {
1525715298 return ira->codegen->invalid_inst_gen;
1525815299 }
1525915300 err_entry = find_err_table_entry(child_type, field_name);
1526015301 if (err_entry == nullptr) {
15261 ir_add_error(ira, &field_ptr_instruction->base.base,
15302 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1526215303 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));
1526315304 return ira->codegen->invalid_inst_gen;
1526415305 }
......@@ -15271,19 +15312,20 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1527115312
1527215313 bool ptr_is_const = true;
1527315314 bool ptr_is_volatile = false;
15274 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val,
15315 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope,
15316 field_ptr_instruction->base.source_node, const_val,
1527515317 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
1527615318 } else {
15277 ir_add_error(ira, &field_ptr_instruction->base.base,
15319 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1527815320 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
1527915321 return ira->codegen->invalid_inst_gen;
1528015322 }
1528115323 } else if (field_ptr_instruction->initializing) {
15282 ir_add_error(ira, &field_ptr_instruction->base.base,
15324 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1528315325 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
1528415326 return ira->codegen->invalid_inst_gen;
1528515327 } else {
15286 ir_add_error_node(ira, field_ptr_instruction->base.base.source_node,
15328 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1528715329 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
1528815330 return ira->codegen->invalid_inst_gen;
1528915331 }
......@@ -15298,14 +15340,14 @@ static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStor
1529815340 if (type_is_invalid(value->value->type))
1529915341 return ira->codegen->invalid_inst_gen;
1530015342
15301 return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const);
15343 return ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, ptr, value, instruction->allow_write_through_const);
1530215344}
1530315345
1530415346static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
1530515347 IrInstGen *ptr = instruction->ptr->child;
1530615348 if (type_is_invalid(ptr->value->type))
1530715349 return ira->codegen->invalid_inst_gen;
15308 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);
15350 return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ptr, nullptr);
1530915351}
1531015352
1531115353static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
......@@ -15325,7 +15367,7 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf
1532515367 args[i] = value;
1532615368 }
1532715369
15328 type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.base.source_node,
15370 type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.source_node,
1532915371 nullptr, args, value_count);
1533015372
1533115373 heap::c_allocator.deallocate(args, value_count);
......@@ -15334,13 +15376,13 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf
1533415376 if (type_is_invalid(type_entry))
1533515377 return ira->codegen->invalid_inst_gen;
1533615378
15337 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);
15379 return ir_const_type(ira, typeof_instruction->base.scope, typeof_instruction->base.source_node, type_entry);
1533815380}
1533915381
1534015382static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
1534115383 if (ira->new_irb.exec->is_inline) {
1534215384 // ignore setCold when running functions at compile time
15343 return ir_const_void(ira, &instruction->base.base);
15385 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1534415386 }
1534515387
1534615388 IrInstGen *is_cold_value = instruction->is_cold->child;
......@@ -15348,22 +15390,22 @@ static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCo
1534815390 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
1534915391 return ira->codegen->invalid_inst_gen;
1535015392
15351 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);
15393 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
1535215394 if (fn_entry == nullptr) {
15353 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));
15395 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setCold outside function"));
1535415396 return ira->codegen->invalid_inst_gen;
1535515397 }
1535615398
1535715399 if (fn_entry->set_cold_node != nullptr) {
15358 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function"));
15400 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cold set twice in same function"));
1535915401 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));
1536015402 return ira->codegen->invalid_inst_gen;
1536115403 }
1536215404
15363 fn_entry->set_cold_node = instruction->base.base.source_node;
15405 fn_entry->set_cold_node = instruction->base.source_node;
1536415406 fn_entry->is_cold = want_cold;
1536515407
15366 return ir_const_void(ira, &instruction->base.base);
15408 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1536715409}
1536815410
1536915411static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
......@@ -15371,13 +15413,14 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1537115413{
1537215414 if (ira->new_irb.exec->is_inline) {
1537315415 // ignore setRuntimeSafety when running functions at compile time
15374 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
15416 return ir_const_void(ira, set_runtime_safety_instruction->base.scope,
15417 set_runtime_safety_instruction->base.source_node);
1537515418 }
1537615419
1537715420 bool *safety_off_ptr;
1537815421 AstNode **safety_set_node_ptr;
1537915422
15380 Scope *scope = set_runtime_safety_instruction->base.base.scope;
15423 Scope *scope = set_runtime_safety_instruction->base.scope;
1538115424 while (scope != nullptr) {
1538215425 if (scope->id == ScopeIdBlock) {
1538315426 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -15408,7 +15451,7 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1540815451 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
1540915452 return ira->codegen->invalid_inst_gen;
1541015453
15411 AstNode *source_node = set_runtime_safety_instruction->base.base.source_node;
15454 AstNode *source_node = set_runtime_safety_instruction->base.source_node;
1541215455 if (*safety_set_node_ptr) {
1541315456 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1541415457 buf_sprintf("runtime safety set twice for same scope"));
......@@ -15418,7 +15461,8 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
1541815461 *safety_set_node_ptr = source_node;
1541915462 *safety_off_ptr = !want_runtime_safety;
1542015463
15421 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
15464 return ir_const_void(ira, set_runtime_safety_instruction->base.scope,
15465 set_runtime_safety_instruction->base.source_node);
1542215466}
1542315467
1542415468static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
......@@ -15426,13 +15470,13 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1542615470{
1542715471 if (ira->new_irb.exec->is_inline) {
1542815472 // ignore setFloatMode when running functions at compile time
15429 return ir_const_void(ira, &instruction->base.base);
15473 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1543015474 }
1543115475
1543215476 bool *fast_math_on_ptr;
1543315477 AstNode **fast_math_set_node_ptr;
1543415478
15435 Scope *scope = instruction->base.base.scope;
15479 Scope *scope = instruction->base.scope;
1543615480 while (scope != nullptr) {
1543715481 if (scope->id == ScopeIdBlock) {
1543815482 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -15463,7 +15507,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1546315507 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
1546415508 return ira->codegen->invalid_inst_gen;
1546515509
15466 AstNode *source_node = instruction->base.base.source_node;
15510 AstNode *source_node = instruction->base.source_node;
1546715511 if (*fast_math_set_node_ptr) {
1546815512 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1546915513 buf_sprintf("float mode set twice for same scope"));
......@@ -15473,7 +15517,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
1547315517 *fast_math_set_node_ptr = source_node;
1547415518 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
1547515519
15476 return ir_const_void(ira, &instruction->base.base);
15520 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1547715521}
1547815522
1547915523static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
......@@ -15485,11 +15529,12 @@ static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSr
1548515529 }
1548615530
1548715531 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);
15488 return ir_const_type(ira, &instruction->base.base, any_frame_type);
15532 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, any_frame_type);
1548915533}
1549015534
1549115535static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
15492 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
15536 IrInstGen *result = ir_const(ira, slice_type_instruction->base.scope,
15537 slice_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type);
1549315538 result->value->special = ConstValSpecialLazy;
1549415539
1549515540 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();
......@@ -15542,10 +15587,10 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
1554215587static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
1554315588 Error err;
1554415589
15545 assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr);
15590 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
1554615591
15547 AstNode *node = asm_instruction->base.base.source_node;
15548 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;
15592 AstNode *node = asm_instruction->base.source_node;
15593 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
1554915594
1555015595 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
1555115596 if (template_buf == nullptr)
......@@ -15555,10 +15600,10 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
1555515600 buf_append_char(&ira->codegen->global_asm, '\n');
1555615601 buf_append_buf(&ira->codegen->global_asm, template_buf);
1555715602
15558 return ir_const_void(ira, &asm_instruction->base.base);
15603 return ir_const_void(ira, asm_instruction->base.scope, asm_instruction->base.source_node);
1555915604 }
1556015605
15561 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))
15606 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))
1556215607 return ira->codegen->invalid_inst_gen;
1556315608
1556415609 ZigList<AsmToken> tok_list = {};
......@@ -15606,7 +15651,7 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
1560615651 if (instr_is_comptime(input_value) &&
1560715652 (input_value->value->type->id == ZigTypeIdComptimeInt ||
1560815653 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
15609 ir_add_error(ira, &input_value->base,
15654 ir_add_error(ira, input_value,
1561015655 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
1561115656 return ira->codegen->invalid_inst_gen;
1561215657 }
......@@ -15614,14 +15659,15 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
1561415659 input_list[i] = input_value;
1561515660 }
1561615661
15617 return ir_build_asm_gen(ira, &asm_instruction->base.base,
15662 return ir_build_asm_gen(ira, asm_instruction->base.scope, asm_instruction->base.source_node,
1561815663 template_buf, tok_list.items, tok_list.length,
1561915664 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
1562015665 asm_instruction->has_side_effects, return_type);
1562115666}
1562215667
1562315668static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
15624 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
15669 IrInstGen *result = ir_const(ira, array_type_instruction->base.scope,
15670 array_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type);
1562515671 result->value->special = ConstValSpecialLazy;
1562615672
1562715673 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();
......@@ -15646,7 +15692,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr
1564615692}
1564715693
1564815694static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
15649 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
15695 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
1565015696 result->value->special = ConstValSpecialLazy;
1565115697
1565215698 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();
......@@ -15662,7 +15708,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf
1566215708 return result;
1566315709}
1566415710
15665static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) {
15711static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
1566615712 ZigType *type_entry = value->value->type;
1566715713
1566815714 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
......@@ -15671,30 +15717,30 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst,
1567115717 if (c_ptr_val == nullptr)
1567215718 return ira->codegen->invalid_inst_gen;
1567315719 if (c_ptr_val->special == ConstValSpecialUndef)
15674 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
15720 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
1567515721 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
1567615722 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
1567715723 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
15678 return ir_const_bool(ira, source_inst, !is_null);
15724 return ir_const_bool(ira, scope, source_node, !is_null);
1567915725 }
1568015726
15681 return ir_build_test_non_null_gen(ira, source_inst, value);
15727 return ir_build_test_non_null_gen(ira, scope, source_node, value);
1568215728 } else if (type_entry->id == ZigTypeIdOptional) {
1568315729 if (instr_is_comptime(value)) {
1568415730 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
1568515731 if (maybe_val == nullptr)
1568615732 return ira->codegen->invalid_inst_gen;
1568715733 if (maybe_val->special == ConstValSpecialUndef)
15688 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
15734 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
1568915735
15690 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));
15736 return ir_const_bool(ira, scope, source_node, !optional_value_is_null(maybe_val));
1569115737 }
1569215738
15693 return ir_build_test_non_null_gen(ira, source_inst, value);
15739 return ir_build_test_non_null_gen(ira, scope, source_node, value);
1569415740 } else if (type_entry->id == ZigTypeIdNull) {
15695 return ir_const_bool(ira, source_inst, false);
15741 return ir_const_bool(ira, scope, source_node, false);
1569615742 } else {
15697 return ir_const_bool(ira, source_inst, true);
15743 return ir_const_bool(ira, scope, source_node, true);
1569815744 }
1569915745}
1570015746
......@@ -15703,10 +15749,10 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc
1570315749 if (type_is_invalid(value->value->type))
1570415750 return ira->codegen->invalid_inst_gen;
1570515751
15706 return ir_analyze_test_non_null(ira, &instruction->base.base, value);
15752 return ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, value);
1570715753}
1570815754
15709static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
15755static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1571015756 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
1571115757{
1571215758 Error err;
......@@ -15721,14 +15767,14 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
1572115767 if (!val)
1572215768 return ira->codegen->invalid_inst_gen;
1572315769 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15724 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
15770 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_node);
1572515771 if (c_ptr_val == nullptr)
1572615772 return ira->codegen->invalid_inst_gen;
1572715773 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
1572815774 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
1572915775 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
1573015776 if (is_null) {
15731 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
15777 ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null"));
1573215778 return ira->codegen->invalid_inst_gen;
1573315779 }
1573415780 return base_ptr;
......@@ -15736,13 +15782,13 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
1573615782 }
1573715783 if (!safety_check_on)
1573815784 return base_ptr;
15739 IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
15740 ir_build_assert_non_null(ira, source_instr, c_ptr_val);
15785 IrInstGen *c_ptr_val = ir_get_deref(ira, scope, source_node, base_ptr, nullptr);
15786 ir_build_assert_non_null(ira, scope, source_node, c_ptr_val);
1574115787 return base_ptr;
1574215788 }
1574315789
1574415790 if (type_entry->id != ZigTypeIdOptional) {
15745 ir_add_error(ira, &base_ptr->base,
15791 ir_add_error(ira, base_ptr,
1574615792 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
1574715793 return ira->codegen->invalid_inst_gen;
1574815794 }
......@@ -15759,7 +15805,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
1575915805 if (ptr_val == nullptr)
1576015806 return ira->codegen->invalid_inst_gen;
1576115807 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15762 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
15808 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
1576315809 if (optional_val == nullptr)
1576415810 return ira->codegen->invalid_inst_gen;
1576515811
......@@ -15787,21 +15833,21 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
1578715833 }
1578815834 } else {
1578915835 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
15790 source_instr->source_node, optional_val, UndefBad)))
15836 source_node, optional_val, UndefBad)))
1579115837 return ira->codegen->invalid_inst_gen;
1579215838 if (optional_value_is_null(optional_val)) {
15793 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
15839 ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null"));
1579415840 return ira->codegen->invalid_inst_gen;
1579515841 }
1579615842 }
1579715843
1579815844 IrInstGen *result;
1579915845 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
15800 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,
15846 result = ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, false,
1580115847 initializing, result_type);
1580215848 result->value->special = ConstValSpecialStatic;
1580315849 } else {
15804 result = ir_const(ira, source_instr, result_type);
15850 result = ir_const(ira, scope, source_node, result_type);
1580515851 }
1580615852 ZigValue *result_val = result->value;
1580715853 result_val->data.x_ptr.special = ConstPtrSpecialRef;
......@@ -15826,7 +15872,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
1582615872 }
1582715873 }
1582815874
15829 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,
15875 return ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, safety_check_on,
1583015876 initializing, result_type);
1583115877}
1583215878
......@@ -15837,7 +15883,7 @@ static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
1583715883 if (type_is_invalid(base_ptr->value->type))
1583815884 return ira->codegen->invalid_inst_gen;
1583915885
15840 return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr,
15886 return ir_analyze_unwrap_optional_payload(ira, instruction->base.scope, instruction->base.source_node, base_ptr,
1584115887 instruction->safety_check_on, false);
1584215888}
1584315889
......@@ -15851,20 +15897,20 @@ static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instr
1585115897 return ira->codegen->invalid_inst_gen;
1585215898
1585315899 if (int_type->data.integral.bit_count == 0)
15854 return ir_const_unsigned(ira, &instruction->base.base, 0);
15900 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1585515901
1585615902 if (instr_is_comptime(op)) {
1585715903 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
1585815904 if (val == nullptr)
1585915905 return ira->codegen->invalid_inst_gen;
1586015906 if (val->special == ConstValSpecialUndef)
15861 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
15907 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
1586215908 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
15863 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
15909 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize);
1586415910 }
1586515911
1586615912 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15867 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);
15913 return ir_build_ctz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
1586815914}
1586915915
1587015916static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
......@@ -15877,20 +15923,20 @@ static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instr
1587715923 return ira->codegen->invalid_inst_gen;
1587815924
1587915925 if (int_type->data.integral.bit_count == 0)
15880 return ir_const_unsigned(ira, &instruction->base.base, 0);
15926 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1588115927
1588215928 if (instr_is_comptime(op)) {
1588315929 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
1588415930 if (val == nullptr)
1588515931 return ira->codegen->invalid_inst_gen;
1588615932 if (val->special == ConstValSpecialUndef)
15887 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
15933 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
1588815934 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
15889 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
15935 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize);
1589015936 }
1589115937
1589215938 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15893 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);
15939 return ir_build_clz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
1589415940}
1589515941
1589615942static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
......@@ -15903,38 +15949,38 @@ static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopC
1590315949 return ira->codegen->invalid_inst_gen;
1590415950
1590515951 if (int_type->data.integral.bit_count == 0)
15906 return ir_const_unsigned(ira, &instruction->base.base, 0);
15952 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1590715953
1590815954 if (instr_is_comptime(op)) {
1590915955 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
1591015956 if (val == nullptr)
1591115957 return ira->codegen->invalid_inst_gen;
1591215958 if (val->special == ConstValSpecialUndef)
15913 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
15959 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
1591415960
1591515961 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
1591615962 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);
15917 return ir_const_unsigned(ira, &instruction->base.base, result);
15963 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result);
1591815964 }
1591915965 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);
15920 return ir_const_unsigned(ira, &instruction->base.base, result);
15966 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result);
1592115967 }
1592215968
1592315969 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15924 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);
15970 return ir_build_pop_count_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
1592515971}
1592615972
15927static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value) {
15973static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
1592815974 if (type_is_invalid(value->value->type))
1592915975 return ira->codegen->invalid_inst_gen;
1593015976
1593115977 if (value->value->type->id != ZigTypeIdUnion) {
15932 ir_add_error(ira, &value->base,
15978 ir_add_error(ira, value,
1593315979 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
1593415980 return ira->codegen->invalid_inst_gen;
1593515981 }
1593615982 if (!value->value->type->data.unionation.have_explicit_tag_type) {
15937 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
15983 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union has no associated enum"));
1593815984 if (value->value->type->data.unionation.decl_node != nullptr) {
1593915985 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
1594015986 buf_sprintf("declared here"));
......@@ -15951,14 +15997,14 @@ static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrI
1595115997 return ira->codegen->invalid_inst_gen;
1595215998
1595315999 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
15954 source_instr->scope, source_instr->source_node);
16000 scope, source_node);
1595516001 const_instruction->base.value->type = tag_type;
1595616002 const_instruction->base.value->special = ConstValSpecialStatic;
1595716003 bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag);
1595816004 return &const_instruction->base;
1595916005 }
1596016006
15961 return ir_build_union_tag(ira, source_instr, value, tag_type);
16007 return ir_build_union_tag(ira, scope, source_node, value, tag_type);
1596216008}
1596316009
1596416010static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
......@@ -16008,10 +16054,11 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1600816054 }
1600916055
1601016056 if (is_comptime || old_dest_block->ref_count == 1) {
16011 return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block);
16057 return ir_inline_bb(ira, switch_br_instruction->base.source_node, old_dest_block);
1601216058 } else {
16013 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);
16014 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);
16059 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);
16060 IrInstGen *result = ir_build_br_gen(ira, switch_br_instruction->base.scope,
16061 switch_br_instruction->base.source_node, new_dest_block);
1601516062 return ir_finish_anal(ira, result);
1601616063 }
1601716064 }
......@@ -16020,7 +16067,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1602016067 for (size_t i = 0; i < case_count; i += 1) {
1602116068 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
1602216069 IrInstGenSwitchBrCase *new_case = &cases[i];
16023 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);
16070 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);
1602416071 new_case->value = ira->codegen->invalid_inst_gen;
1602516072
1602616073 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
......@@ -16048,12 +16095,12 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1604816095 IrInstGenSwitchBrCase *new_case = &cases[i];
1604916096 if (type_is_invalid(new_case->value->value->type))
1605016097 return ir_unreach_error(ira);
16051 new_case->block->ref_instruction = &switch_br_instruction->base.base;
16098 new_case->block->ref_instruction = &switch_br_instruction->base;
1605216099 }
1605316100
16054 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);
16055 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,
16056 target_value, new_else_block, case_count, cases);
16101 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);
16102 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, switch_br_instruction->base.scope,
16103 switch_br_instruction->base.source_node, target_value, new_else_block, case_count, cases);
1605716104 return ir_finish_anal(ira, &switch_br->base);
1605816105}
1605916106
......@@ -16069,13 +16116,14 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1606916116 assert(instr_is_comptime(target_value_ptr));
1607016117 ZigType *ptr_type = target_value_ptr->value->data.x_type;
1607116118 assert(ptr_type->id == ZigTypeIdPointer);
16072 return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type);
16119 return ir_const_type(ira, switch_target_instruction->base.scope,
16120 switch_target_instruction->base.source_node, ptr_type->data.pointer.child_type);
1607316121 }
1607416122
1607516123 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
1607616124 ZigValue *pointee_val = nullptr;
1607716125 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16078 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node);
16126 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
1607916127 if (pointee_val == nullptr)
1608016128 return ira->codegen->invalid_inst_gen;
1608116129
......@@ -16100,13 +16148,15 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1610016148 case ZigTypeIdFn:
1610116149 case ZigTypeIdErrorSet: {
1610216150 if (pointee_val) {
16103 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
16151 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope,
16152 switch_target_instruction->base.source_node, nullptr);
1610416153 copy_const_val(ira->codegen, result->value, pointee_val);
1610516154 result->value->type = target_type;
1610616155 return result;
1610716156 }
1610816157
16109 IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
16158 IrInstGen *result = ir_get_deref(ira, switch_target_instruction->base.scope,
16159 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
1611016160 result->value->type = target_type;
1611116161 return result;
1611216162 }
......@@ -16115,7 +16165,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1611516165 if (!decl_node->data.container_decl.auto_enum &&
1611616166 decl_node->data.container_decl.init_arg_expr == nullptr)
1611716167 {
16118 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,
16168 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,
1611916169 buf_sprintf("switch on union which has no attached enum"));
1612016170 add_error_note(ira->codegen, msg, decl_node,
1612116171 buf_sprintf("consider 'union(enum)' here"));
......@@ -16125,22 +16175,23 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1612516175 assert(tag_type != nullptr);
1612616176 assert(tag_type->id == ZigTypeIdEnum);
1612716177 if (pointee_val) {
16128 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
16178 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type);
1612916179 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
1613016180 return result;
1613116181 }
1613216182
1613316183 if (can_fold_enum_type(tag_type)) {
16134 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
16184 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type);
1613516185 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
1613616186 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
1613716187 return result;
1613816188 }
1613916189
16140 IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
16190 IrInstGen *union_value = ir_get_deref(ira, switch_target_instruction->base.scope,
16191 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
1614116192 union_value->value->type = target_type;
1614216193
16143 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);
16194 return ir_build_union_tag(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, union_value, tag_type);
1614416195 }
1614516196 case ZigTypeIdEnum: {
1614616197 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
......@@ -16148,18 +16199,19 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1614816199
1614916200 if (can_fold_enum_type(target_type)) {
1615016201 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
16151 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
16202 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type);
1615216203 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
1615316204 return result;
1615416205 }
1615516206
1615616207 if (pointee_val) {
16157 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
16208 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type);
1615816209 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
1615916210 return result;
1616016211 }
1616116212
16162 IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
16213 IrInstGen *enum_value = ir_get_deref(ira, switch_target_instruction->base.scope,
16214 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
1616316215 enum_value->value->type = target_type;
1616416216 return enum_value;
1616516217 }
......@@ -16175,7 +16227,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1617516227 case ZigTypeIdVector:
1617616228 case ZigTypeIdFnFrame:
1617716229 case ZigTypeIdAnyFrame:
16178 ir_add_error(ira, &switch_target_instruction->base.base,
16230 ir_add_error_node(ira, switch_target_instruction->base.source_node,
1617916231 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
1618016232 return ira->codegen->invalid_inst_gen;
1618116233 }
......@@ -16228,12 +16280,12 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
1622816280 ZigType *payload_type = payload_field->type_entry;
1622916281 if (first_field->type_entry != payload_type) {
1623016282 if (invalid_payload_msg == nullptr) {
16231 invalid_payload_msg = ir_add_error(ira, &instruction->base.base,
16283 invalid_payload_msg = ir_add_error_node(ira, instruction->base.source_node,
1623216284 buf_sprintf("capture group with incompatible types"));
16233 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node,
16285 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node,
1623416286 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
1623516287 }
16236 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node,
16288 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node,
1623716289 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
1623816290 }
1623916291 }
......@@ -16247,11 +16299,11 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
1624716299 if (!target_value_ptr)
1624816300 return ira->codegen->invalid_inst_gen;
1624916301
16250 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node);
16302 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
1625116303 if (pointee_val == nullptr)
1625216304 return ira->codegen->invalid_inst_gen;
1625316305
16254 IrInstGen *result = ir_const(ira, &instruction->base.base,
16306 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node,
1625516307 get_pointer_to_type(ira->codegen, first_field->type_entry,
1625616308 target_val_ptr->type->data.pointer.is_const));
1625716309 ZigValue *out_val = result->value;
......@@ -16263,7 +16315,7 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
1626316315
1626416316 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
1626516317 target_value_ptr->value->type->data.pointer.is_const);
16266 return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field,
16318 return ir_build_union_field_ptr(ira, instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field,
1626716319 false, false, result_type);
1626816320 } else if (target_type->id == ZigTypeIdErrorSet) {
1626916321 // construct an error set from the prong values
......@@ -16293,12 +16345,13 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
1629316345 ref_type->data.pointer.explicit_alignment,
1629416346 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
1629516347 ref_type->data.pointer.allow_zero);
16296 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,
16297 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false);
16348 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node,
16349 target_value_ptr, instruction->target_value_ptr->source_node,
16350 new_target_value_ptr_type, instruction->base.source_node, false, false);
1629816351 } else if (instruction->prongs_len > 1) {
1629916352 return target_value_ptr;
1630016353 } else {
16301 ir_add_error(ira, &instruction->base.base,
16354 ir_add_error_node(ira, instruction->base.source_node,
1630216355 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
1630316356 return ira->codegen->invalid_inst_gen;
1630416357 }
......@@ -16316,7 +16369,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
1631616369 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
1631716370 if (target_type->id == ZigTypeIdErrorSet) {
1631816371 // make a new set that has the other cases removed
16319 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {
16372 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {
1632016373 return ira->codegen->invalid_inst_gen;
1632116374 }
1632216375 if (type_is_global_error_set(target_type)) {
......@@ -16378,8 +16431,9 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
1637816431 ref_type->data.pointer.explicit_alignment,
1637916432 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
1638016433 ref_type->data.pointer.allow_zero);
16381 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,
16382 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false);
16434 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node,
16435 target_value_ptr, instruction->target_value_ptr->source_node,
16436 new_target_value_ptr_type, instruction->base.source_node, false, false);
1638316437 }
1638416438
1638516439 return target_value_ptr;
......@@ -16393,7 +16447,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport
1639316447 if (!import_target_str)
1639416448 return ira->codegen->invalid_inst_gen;
1639516449
16396 AstNode *source_node = import_instruction->base.base.source_node;
16450 AstNode *source_node = import_instruction->base.source_node;
1639716451 ZigType *import = source_node->owner;
1639816452
1639916453 ZigType *target_import;
......@@ -16418,7 +16472,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport
1641816472 }
1641916473 }
1642016474
16421 return ir_const_type(ira, &import_instruction->base.base, target_import);
16475 return ir_const_type(ira, import_instruction->base.scope, import_instruction->base.source_node, target_import);
1642216476}
1642316477
1642416478static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
......@@ -16434,10 +16488,10 @@ static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_i
1643416488 is_const = true;
1643516489 }
1643616490
16437 return ir_get_ref(ira, &ref_instruction->base.base, value, is_const, is_volatile);
16491 return ir_get_ref(ira, ref_instruction->base.scope, ref_instruction->base.source_node, value, is_const, is_volatile);
1643816492}
1643916493
16440static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
16494static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1644116495 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
1644216496 IrInstGen *result_loc)
1644316497{
......@@ -16468,26 +16522,26 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi
1646816522 }
1646916523 }
1647016524
16471 bool is_comptime = ir_should_inline(ira->zir, source_instruction->scope)
16525 bool is_comptime = ir_should_inline(ira->zir, scope)
1647216526 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
1647316527
16474 IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
16528 IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr);
1647516529 if (is_comptime && !instr_is_comptime(result)) {
16476 ir_add_error(ira, &field_result_loc->base,
16530 ir_add_error(ira, field_result_loc,
1647716531 buf_sprintf("unable to evaluate constant expression"));
1647816532 return ira->codegen->invalid_inst_gen;
1647916533 }
1648016534 return result;
1648116535}
1648216536
16483static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,
16537static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1648416538 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
1648516539 IrInstGen *result_loc)
1648616540{
1648716541 Error err;
1648816542 if (container_type->id == ZigTypeIdUnion) {
1648916543 if (instr_field_count != 1) {
16490 ir_add_error(ira, source_instr,
16544 ir_add_error_node(ira, source_node,
1649116545 buf_sprintf("union initialization expects exactly one field"));
1649216546 return ira->codegen->invalid_inst_gen;
1649316547 }
......@@ -16496,11 +16550,11 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1649616550 if (type_is_invalid(field_result_loc->value->type))
1649716551 return ira->codegen->invalid_inst_gen;
1649816552
16499 return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name,
16553 return ir_analyze_union_init(ira, scope, source_node, field->source_node, container_type, field->name,
1650016554 field_result_loc, result_loc);
1650116555 }
1650216556 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
16503 ir_add_error(ira, source_instr,
16557 ir_add_error_node(ira, source_node,
1650416558 buf_sprintf("type '%s' does not support struct initialization syntax",
1650516559 buf_ptr(&container_type->name)));
1650616560 return ira->codegen->invalid_inst_gen;
......@@ -16521,7 +16575,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1652116575 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
1652216576 ZigList<IrInstGen *> const_ptrs = {};
1652316577
16524 bool is_comptime = ir_should_inline(ira->zir, source_instr->scope)
16578 bool is_comptime = ir_should_inline(ira->zir, scope)
1652516579 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
1652616580
1652716581
......@@ -16580,7 +16634,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1658016634 TypeStructField *field = container_type->data.structure.fields[i];
1658116635 memoize_field_init_val(ira->codegen, container_type, field);
1658216636 if (field->init_val == nullptr) {
16583 ir_add_error(ira, source_instr,
16637 ir_add_error_node(ira, source_node,
1658416638 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));
1658516639 any_missing = true;
1658616640 continue;
......@@ -16588,12 +16642,12 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1658816642 if (type_is_invalid(field->init_val->type))
1658916643 return ira->codegen->invalid_inst_gen;
1659016644
16591 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
16645 IrInstGen *runtime_inst = ir_const(ira, scope, source_node, field->init_val->type);
1659216646 copy_const_val(ira->codegen, runtime_inst->value, field->init_val);
1659316647
16594 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
16648 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc,
1659516649 container_type, true);
16596 ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false);
16650 ir_analyze_store_ptr(ira, scope, source_node, field_ptr, runtime_inst, false);
1659716651 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
1659816652 const_ptrs.append(field_ptr);
1659916653 } else {
......@@ -16609,18 +16663,20 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1660916663 result_loc->value->special = ConstValSpecialRuntime;
1661016664 for (size_t i = 0; i < const_ptrs.length; i += 1) {
1661116665 IrInstGen *field_result_loc = const_ptrs.at(i);
16612 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);
16666 IrInstGen *deref = ir_get_deref(ira, field_result_loc->scope,
16667 field_result_loc->source_node, field_result_loc, nullptr);
1661316668 field_result_loc->value->special = ConstValSpecialRuntime;
16614 ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false);
16669 ir_analyze_store_ptr(ira, field_result_loc->scope, field_result_loc->source_node,
16670 field_result_loc, deref, false);
1661516671 }
1661616672 }
1661716673 }
1661816674
1661916675 const_ptrs.deinit();
16620 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
16676 IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr);
1662116677
1662216678 if (is_comptime && !instr_is_comptime(result)) {
16623 ir_add_error_node(ira, first_non_const_instruction->base.source_node,
16679 ir_add_error_node(ira, first_non_const_instruction->source_node,
1662416680 buf_sprintf("unable to evaluate constant expression"));
1662516681 return ira->codegen->invalid_inst_gen;
1662616682 }
......@@ -16631,14 +16687,14 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
1663116687static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1663216688 IrInstSrcContainerInitList *instruction)
1663316689{
16634 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
16690 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
1663516691 IrInstGen *result_loc = instruction->result_loc->child;
1663616692 if (type_is_invalid(result_loc->value->type))
1663716693 return result_loc;
1663816694
16639 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
16695 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
1664016696 if (result_loc->value->type->data.pointer.is_const) {
16641 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
16697 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
1664216698 return ira->codegen->invalid_inst_gen;
1664316699 }
1664416700
......@@ -16654,19 +16710,19 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1665416710
1665516711 if (container_type->id == ZigTypeIdVoid) {
1665616712 if (elem_count != 0) {
16657 ir_add_error_node(ira, instruction->base.base.source_node,
16713 ir_add_error_node(ira, instruction->base.source_node,
1665816714 buf_sprintf("void expression expects no arguments"));
1665916715 return ira->codegen->invalid_inst_gen;
1666016716 }
16661 return ir_const_void(ira, &instruction->base.base);
16717 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1666216718 }
1666316719
1666416720 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
16665 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
16721 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
1666616722 IrInstGen *result_loc = instruction->result_loc->child;
1666716723 if (type_is_invalid(result_loc->value->type))
1666816724 return result_loc;
16669 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc);
16725 return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type, 0, nullptr, result_loc);
1667016726 }
1667116727
1667216728 if (container_type->id == ZigTypeIdArray) {
......@@ -16674,7 +16730,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1667416730 if (container_type->data.array.len != elem_count) {
1667516731 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);
1667616732
16677 ir_add_error(ira, &instruction->base.base,
16733 ir_add_error_node(ira, instruction->base.source_node,
1667816734 buf_sprintf("expected %s literal, found %s literal",
1667916735 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
1668016736 return ira->codegen->invalid_inst_gen;
......@@ -16687,7 +16743,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1668716743 } else if (container_type->id == ZigTypeIdVector || is_tuple(container_type)) {
1668816744 // OK
1668916745 } else {
16690 ir_add_error(ira, &instruction->base.base,
16746 ir_add_error_node(ira, instruction->base.source_node,
1669116747 buf_sprintf("type '%s' does not support array initialization",
1669216748 buf_ptr(&container_type->name)));
1669316749 return ira->codegen->invalid_inst_gen;
......@@ -16697,7 +16753,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1669716753 case OnePossibleValueInvalid:
1669816754 return ira->codegen->invalid_inst_gen;
1669916755 case OnePossibleValueYes:
16700 return ir_const_move(ira, &instruction->base.base,
16756 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node,
1670116757 get_the_one_possible_value(ira->codegen, container_type));
1670216758 case OnePossibleValueNo:
1670316759 break;
......@@ -16708,7 +16764,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1670816764 case ReqCompTimeInvalid:
1670916765 return ira->codegen->invalid_inst_gen;
1671016766 case ReqCompTimeNo:
16711 is_comptime = ir_should_inline(ira->zir, instruction->base.base.scope);
16767 is_comptime = ir_should_inline(ira->zir, instruction->base.scope);
1671216768 break;
1671316769 case ReqCompTimeYes:
1671416770 is_comptime = true;
......@@ -16752,32 +16808,35 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1675216808 // This field will be generated comptime; no need to do this.
1675316809 continue;
1675416810 }
16755 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
16811 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
16812 elem_result_loc->source_node, elem_result_loc, nullptr);
1675616813 elem_result_loc->value->special = ConstValSpecialRuntime;
16757 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
16814 ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node,
16815 elem_result_loc, deref, false);
1675816816 }
1675916817 }
1676016818 }
1676116819
1676216820 const_ptrs.deinit();
1676316821
16764 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr);
16822 IrInstGen *result = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
16823 result_loc, nullptr);
1676516824 // If the result is a tuple, we are allowed to return a struct that uses ConstValSpecialRuntime fields at comptime.
1676616825 if (instr_is_comptime(result) || is_tuple(container_type))
1676716826 return result;
1676816827
1676916828 if (is_comptime) {
16770 ir_add_error(ira, &first_non_const_instruction->base,
16829 ir_add_error(ira, first_non_const_instruction,
1677116830 buf_sprintf("unable to evaluate constant expression"));
1677216831 return ira->codegen->invalid_inst_gen;
1677316832 }
1677416833
1677516834 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
1677616835 if (is_slice(result_elem_type)) {
16777 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
16836 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
1677816837 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
1677916838 buf_ptr(&result_elem_type->name)));
16780 add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node,
16839 add_error_note(ira->codegen, msg, first_non_const_instruction->source_node,
1678116840 buf_sprintf("this value is not comptime-known"));
1678216841 return ira->codegen->invalid_inst_gen;
1678316842 }
......@@ -16787,20 +16846,20 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1678716846static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
1678816847 IrInstSrcContainerInitFields *instruction)
1678916848{
16790 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
16849 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
1679116850 IrInstGen *result_loc = instruction->result_loc->child;
1679216851 if (type_is_invalid(result_loc->value->type))
1679316852 return result_loc;
1679416853
16795 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
16854 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
1679616855 if (result_loc->value->type->data.pointer.is_const) {
16797 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
16856 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
1679816857 return ira->codegen->invalid_inst_gen;
1679916858 }
1680016859
1680116860 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
1680216861
16803 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,
16862 return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type,
1680416863 instruction->field_count, instruction->fields, result_loc);
1680516864}
1680616865
......@@ -16810,7 +16869,7 @@ static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCo
1681016869 if (!msg_buf)
1681116870 return ira->codegen->invalid_inst_gen;
1681216871
16813 ir_add_error(ira, &instruction->base.base, msg_buf);
16872 ir_add_error_node(ira, instruction->base.source_node, msg_buf);
1681416873
1681516874 return ira->codegen->invalid_inst_gen;
1681616875}
......@@ -16825,7 +16884,7 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo
1682516884 buf_resize(&buf, 0);
1682616885 if (msg->value->special == ConstValSpecialLazy) {
1682716886 // Resolve any lazy value that's passed, we need its value
16828 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))
16887 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))
1682916888 return ira->codegen->invalid_inst_gen;
1683016889 }
1683116890 render_const_value(ira->codegen, &buf, msg->value);
......@@ -16834,15 +16893,15 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo
1683416893 }
1683516894 fprintf(stderr, "\n");
1683616895
16837 auto *expr = &instruction->base.base.source_node->data.fn_call_expr;
16896 auto *expr = &instruction->base.source_node->data.fn_call_expr;
1683816897 if (!expr->seen) {
1683916898 // Here we bypass higher level functions such as ir_add_error because we do not want
1684016899 // invalidate_exec to be called.
16841 add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement"));
16900 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
1684216901 }
1684316902 expr->seen = true;
1684416903
16845 return ir_const_void(ira, &instruction->base.base);
16904 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1684616905}
1684716906
1684816907static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
......@@ -16864,7 +16923,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
1686416923 ira->codegen, &err->name,
1686516924 ira->codegen->intern.for_zero_byte());
1686616925 }
16867 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
16926 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1686816927 result->value = err->cached_error_name_val;
1686916928 return result;
1687016929 }
......@@ -16875,7 +16934,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
1687516934 true, false, PtrLenUnknown, 0, 0, 0, false,
1687616935 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());
1687716936 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
16878 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);
16937 return ir_build_err_name_gen(ira, instruction->base.scope, instruction->base.source_node, value, str_type);
1687916938}
1688016939
1688116940static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {
......@@ -16887,7 +16946,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
1688716946 ZigType *target_type = target->value->type;
1688816947
1688916948 if (target_type->id == ZigTypeIdEnumLiteral) {
16890 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
16949 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1689116950 Buf *field_name = target->value->data.x_enum_literal;
1689216951 result->value = create_sentineled_str_lit(
1689316952 ira->codegen, field_name,
......@@ -16896,21 +16955,21 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
1689616955 }
1689716956
1689816957 if (target_type->id == ZigTypeIdUnion) {
16899 target = ir_analyze_union_tag(ira, &instruction->base.base, target);
16958 target = ir_analyze_union_tag(ira, instruction->base.scope, instruction->base.source_node, target);
1690016959 if (type_is_invalid(target->value->type))
1690116960 return ira->codegen->invalid_inst_gen;
1690216961 target_type = target->value->type;
1690316962 }
1690416963
1690516964 if (target_type->id != ZigTypeIdEnum) {
16906 ir_add_error(ira, &target->base,
16965 ir_add_error(ira, target,
1690716966 buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target_type->name)));
1690816967 return ira->codegen->invalid_inst_gen;
1690916968 }
1691016969
1691116970 if (can_fold_enum_type(target_type)) {
1691216971 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
16913 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
16972 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1691416973 result->value = create_sentineled_str_lit(
1691516974 ira->codegen, only_field->name,
1691616975 ira->codegen->intern.for_zero_byte());
......@@ -16925,11 +16984,11 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
1692516984 Buf *int_buf = buf_alloc();
1692616985 bigint_append_buf(int_buf, &target->value->data.x_bigint, 10);
1692716986
16928 ir_add_error(ira, &target->base,
16987 ir_add_error(ira, target,
1692916988 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));
1693016989 return ira->codegen->invalid_inst_gen;
1693116990 }
16932 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
16991 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1693316992 result->value = create_sentineled_str_lit(
1693416993 ira->codegen, field->name,
1693516994 ira->codegen->intern.for_zero_byte());
......@@ -16941,7 +17000,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
1694117000 true, false, PtrLenUnknown, 0, 0, 0, false,
1694217001 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());
1694317002 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
16944 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);
17003 return ir_build_tag_name_gen(ira, instruction->base.scope, instruction->base.source_node, target, result_type);
1694517004}
1694617005
1694717006static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
......@@ -16963,7 +17022,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1696317022 return ira->codegen->invalid_inst_gen;
1696417023
1696517024 if (container_type->id != ZigTypeIdStruct) {
16966 ir_add_error(ira, &type_value->base,
17025 ir_add_error(ira, type_value,
1696717026 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
1696817027 return ira->codegen->invalid_inst_gen;
1696917028 }
......@@ -16973,14 +17032,14 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1697317032
1697417033 TypeStructField *field = find_struct_type_field(container_type, field_name);
1697517034 if (field == nullptr) {
16976 ir_add_error(ira, &field_name_value->base,
17035 ir_add_error(ira, field_name_value,
1697717036 buf_sprintf("struct '%s' has no field '%s'",
1697817037 buf_ptr(&container_type->name), buf_ptr(field_name)));
1697917038 return ira->codegen->invalid_inst_gen;
1698017039 }
1698117040
1698217041 if (field_ptr->value->type->id != ZigTypeIdPointer) {
16983 ir_add_error(ira, &field_ptr->base,
17042 ir_add_error(ira, field_ptr,
1698417043 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
1698517044 return ira->codegen->invalid_inst_gen;
1698617045 }
......@@ -17010,20 +17069,20 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1701017069 return ira->codegen->invalid_inst_gen;
1701117070
1701217071 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {
17013 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));
17072 ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct"));
1701417073 return ira->codegen->invalid_inst_gen;
1701517074 }
1701617075
1701717076 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
1701817077 if (ptr_field_index != field->src_index) {
17019 ir_add_error(ira, &instruction->base.base,
17078 ir_add_error_node(ira, instruction->base.source_node,
1702017079 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
1702117080 buf_ptr(field->name), field->src_index,
1702217081 ptr_field_index, buf_ptr(&container_type->name)));
1702317082 return ira->codegen->invalid_inst_gen;
1702417083 }
1702517084
17026 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
17085 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
1702717086 ZigValue *out_val = result->value;
1702817087 out_val->data.x_ptr.special = ConstPtrSpecialRef;
1702917088 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
......@@ -17031,7 +17090,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1703117090 return result;
1703217091 }
1703317092
17034 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
17093 return ir_build_field_parent_ptr_gen(ira, instruction->base.scope, instruction->base.source_node, casted_field_ptr, field, result_type);
1703517094}
1703617095
1703717096static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
......@@ -17052,21 +17111,21 @@ static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
1705217111 return nullptr;
1705317112
1705417113 if (container_type->id != ZigTypeIdStruct) {
17055 ir_add_error(ira, &type_value->base,
17114 ir_add_error(ira, type_value,
1705617115 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
1705717116 return nullptr;
1705817117 }
1705917118
1706017119 TypeStructField *field = find_struct_type_field(container_type, field_name);
1706117120 if (field == nullptr) {
17062 ir_add_error(ira, &field_name_value->base,
17121 ir_add_error(ira, field_name_value,
1706317122 buf_sprintf("struct '%s' has no field '%s'",
1706417123 buf_ptr(&container_type->name), buf_ptr(field_name)));
1706517124 return nullptr;
1706617125 }
1706717126
1706817127 if (!type_has_bits(ira->codegen, field->type_entry)) {
17069 ir_add_error(ira, &field_name_value->base,
17128 ir_add_error(ira, field_name_value,
1707017129 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
1707117130 buf_ptr(field_name), buf_ptr(&container_type->name)));
1707217131 return nullptr;
......@@ -17088,7 +17147,7 @@ static IrInstGen *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstSrcOffs
1708817147 return ira->codegen->invalid_inst_gen;
1708917148
1709017149 size_t byte_offset = host_int_byte_offset + (field->bit_offset_in_host / 8);
17091 return ir_const_unsigned(ira, &instruction->base.base, byte_offset);
17150 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, byte_offset);
1709217151}
1709317152
1709417153static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
......@@ -17102,7 +17161,7 @@ static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrc
1710217161 return ira->codegen->invalid_inst_gen;
1710317162
1710417163 size_t bit_offset = host_int_byte_offset * 8 + field->bit_offset_in_host;
17105 return ir_const_unsigned(ira, &instruction->base.base, bit_offset);
17164 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, bit_offset);
1710617165}
1710717166
1710817167static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
......@@ -17150,7 +17209,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
1715017209 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
1715117210}
1715217211
17153static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
17212static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigValue *out_val,
1715417213 ScopeDecls *decls_scope, bool resolve_types)
1715517214{
1715617215 Error err;
......@@ -17174,7 +17233,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
1717417233 out_val->data.x_lazy = &lazy_type_info_decls->base;
1717517234 lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;
1717617235
17177 lazy_type_info_decls->source_instr = source_instr;
17236 lazy_type_info_decls->source_node = source_node;
1717817237 lazy_type_info_decls->decls_scope = decls_scope;
1717917238
1718017239 return ErrorNone;
......@@ -17202,7 +17261,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
1720217261 }
1720317262
1720417263 if (curr_entry->value->resolution == TldResolutionResolving) {
17205 ir_error_dependency_loop(ira, source_instr);
17264 ir_error_dependency_loop(ira, source_node);
1720617265 return ErrorSemanticAnalyzeFail;
1720717266 }
1720817267
......@@ -17435,7 +17494,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
1743517494 zig_unreachable();
1743617495}
1743717496
17438static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr, ZigType *ptr_type_entry) {
17497static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) {
1743917498 ZigType *attrs_type;
1744017499 BuiltinPtrSize size_enum_index;
1744117500 if (is_slice(ptr_type_entry)) {
......@@ -17489,7 +17548,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr,
1748917548 fields[3]->special = ConstValSpecialLazy;
1749017549 fields[3]->data.x_lazy = &lazy_align_of->base;
1749117550 lazy_align_of->base.id = LazyValueIdAlignOf;
17492 lazy_align_of->target_type = ir_const_type(ira, source_instr, attrs_type->data.pointer.child_type);
17551 lazy_align_of->target_type = ir_const_type(ira, scope, source_node, attrs_type->data.pointer.child_type);
1749317552 }
1749417553 // child: type
1749517554 ensure_field_index(result->type, "child", 4);
......@@ -17532,7 +17591,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
1753217591 enum_field_val->data.x_struct.fields = inner_fields;
1753317592}
1753417593
17535static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
17594static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry,
1753617595 ZigValue **out)
1753717596{
1753817597 Error err;
......@@ -17601,7 +17660,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1760117660 }
1760217661 case ZigTypeIdPointer:
1760317662 {
17604 result = create_ptr_like_type_info(ira, source_instr, type_entry);
17663 result = create_ptr_like_type_info(ira, scope, source_node, type_entry);
1760517664 if (result == nullptr)
1760617665 return ErrorSemanticAnalyzeFail;
1760717666 break;
......@@ -17739,7 +17798,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1773917798 }
1774017799 // decls: []TypeInfo.Declaration
1774117800 ensure_field_index(result->type, "decls", 3);
17742 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
17801 if ((err = ir_make_type_info_decls(ira, source_node, fields[3],
1774317802 type_entry->data.enumeration.decls_scope, false)))
1774417803 {
1774517804 return err;
......@@ -17759,7 +17818,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1775917818 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
1776017819
1776117820 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
17762 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) {
17821 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
1776317822 return ErrorSemanticAnalyzeFail;
1776417823 }
1776517824 if (type_is_global_error_set(type_entry)) {
......@@ -17905,7 +17964,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1790517964 }
1790617965 // decls: []TypeInfo.Declaration
1790717966 ensure_field_index(result->type, "decls", 3);
17908 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
17967 if ((err = ir_make_type_info_decls(ira, source_node, fields[3],
1790917968 type_entry->data.unionation.decls_scope, false)))
1791017969 {
1791117970 return err;
......@@ -17916,7 +17975,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1791617975 case ZigTypeIdStruct:
1791717976 {
1791817977 if (type_entry->data.structure.special == StructSpecialSlice) {
17919 result = create_ptr_like_type_info(ira, source_instr, type_entry);
17978 result = create_ptr_like_type_info(ira, scope, source_node, type_entry);
1792017979 if (result == nullptr)
1792117980 return ErrorSemanticAnalyzeFail;
1792217981 break;
......@@ -17997,7 +18056,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1799718056 }
1799818057 // decls: []TypeInfo.Declaration
1799918058 ensure_field_index(result->type, "decls", 2);
18000 if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
18059 if ((err = ir_make_type_info_decls(ira, source_node, fields[2],
1800118060 type_entry->data.structure.decls_scope, false)))
1800218061 {
1800318062 return err;
......@@ -18112,7 +18171,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1811218171 {
1811318172 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
1811418173 assert(fn_type->id == ZigTypeIdFn);
18115 if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result)))
18174 if ((err = ir_make_type_info_value(ira, scope, source_node, fn_type, &result)))
1811618175 return err;
1811718176
1811818177 break;
......@@ -18128,7 +18187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1812818187
1812918188 // decls: []TypeInfo.Declaration
1813018189 ensure_field_index(result->type, "decls", 0);
18131 if ((err = ir_make_type_info_decls(ira, source_instr, fields[0],
18190 if ((err = ir_make_type_info_decls(ira, source_node, fields[0],
1813218191 type_entry->data.opaque.decls_scope, false)))
1813318192 {
1813418193 return err;
......@@ -18167,10 +18226,10 @@ static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcType
1816718226 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1816818227
1816918228 ZigValue *payload;
18170 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))
18229 if ((err = ir_make_type_info_value(ira, instruction->base.scope, instruction->base.source_node, type_entry, &payload)))
1817118230 return ira->codegen->invalid_inst_gen;
1817218231
18173 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
18232 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
1817418233 ZigValue *out_val = result->value;
1817518234 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
1817618235 out_val->data.x_union.payload = payload;
......@@ -18194,14 +18253,14 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
1819418253 return val;
1819518254}
1819618255
18197static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value,
18256static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value,
1819818257 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
1819918258{
18200 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
18259 ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index);
1820118260 if (field_val == nullptr)
1820218261 return ErrorSemanticAnalyzeFail;
1820318262
18204 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);
18263 IrInstGen *field_inst = ir_const_move(ira, scope, source_node, field_val);
1820518264 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
1820618265 get_optional_type(ira->codegen, elem_type));
1820718266 if (type_is_invalid(casted_field_inst->value->type))
......@@ -18295,7 +18354,7 @@ static Error get_const_field_buf(IrAnalyze *ira, AstNode *source_node, ZigValue
1829518354 return ErrorNone;
1829618355}
1829718356
18298static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) {
18357static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigTypeId tagTypeId, ZigValue *payload) {
1829918358 Error err;
1830018359 switch (tagTypeId) {
1830118360 case ZigTypeIdInvalid:
......@@ -18319,7 +18378,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1831918378 case ZigTypeIdEnumLiteral:
1832018379 return ira->codegen->builtin_types.entry_enum_literal;
1832118380 default:
18322 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, payload, UndefBad)))
18381 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, payload, UndefBad)))
1832318382 return ira->codegen->invalid_inst_gen->value->type;
1832418383 }
1832518384 switch (tagTypeId) {
......@@ -18337,10 +18396,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1833718396 case ZigTypeIdInt: {
1833818397 assert(payload->special == ConstValSpecialStatic);
1833918398 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
18340 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
18399 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 1);
1834118400 if (bi == nullptr)
1834218401 return ira->codegen->invalid_inst_gen->value->type;
18343 ZigValue *value = get_const_field(ira, source_instr->source_node, payload, "signedness", 0);
18402 ZigValue *value = get_const_field(ira, source_node, payload, "signedness", 0);
1834418403 if (value == nullptr)
1834518404 return ira->codegen->invalid_inst_gen->value->type;
1834618405 assert(value->type == get_builtin_type(ira->codegen, "Signedness"));
......@@ -18351,7 +18410,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1835118410 {
1835218411 assert(payload->special == ConstValSpecialStatic);
1835318412 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
18354 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0);
18413 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 0);
1835518414 if (bi == nullptr)
1835618415 return ira->codegen->invalid_inst_gen->value->type;
1835718416 uint32_t bits = bigint_as_u32(bi);
......@@ -18361,7 +18420,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1836118420 case 64: return ira->codegen->builtin_types.entry_f64;
1836218421 case 128: return ira->codegen->builtin_types.entry_f128;
1836318422 }
18364 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));
18423 ir_add_error_node(ira, source_node, buf_sprintf("%d-bit float unsupported", bits));
1836518424 return ira->codegen->invalid_inst_gen->value->type;
1836618425 }
1836718426 case ZigTypeIdPointer:
......@@ -18369,45 +18428,45 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1836918428 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
1837018429 assert(payload->special == ConstValSpecialStatic);
1837118430 assert(payload->type == type_info_pointer_type);
18372 ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0);
18431 ZigValue *size_value = get_const_field(ira, source_node, payload, "size", 0);
1837318432 if (size_value == nullptr)
1837418433 return ira->codegen->invalid_inst_gen->value->type;
1837518434
1837618435 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
1837718436 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
1837818437 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
18379 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4);
18438 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 4);
1838018439 if (type_is_invalid(elem_type))
1838118440 return ira->codegen->invalid_inst_gen->value->type;
1838218441 ZigValue *sentinel;
18383 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6,
18442 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 6,
1838418443 elem_type, &sentinel)))
1838518444 {
1838618445 return ira->codegen->invalid_inst_gen->value->type;
1838718446 }
1838818447 if (sentinel != nullptr && (size_enum_index == BuiltinPtrSizeOne || size_enum_index == BuiltinPtrSizeC)) {
18389 ir_add_error(ira, source_instr,
18448 ir_add_error_node(ira, source_node,
1839018449 buf_sprintf("sentinels are only allowed on slices and unknown-length pointers"));
1839118450 return ira->codegen->invalid_inst_gen->value->type;
1839218451 }
1839318452
18394 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
18453 BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 3);
1839518454 if (alignment == nullptr)
1839618455 return ira->codegen->invalid_inst_gen->value->type;
1839718456
1839818457 bool is_const;
18399 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))
18458 if ((err = get_const_field_bool(ira, source_node, payload, "is_const", 1, &is_const)))
1840018459 return ira->codegen->invalid_inst_gen->value->type;
1840118460
1840218461 bool is_volatile;
18403 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2,
18462 if ((err = get_const_field_bool(ira, source_node, payload, "is_volatile", 2,
1840418463 &is_volatile)))
1840518464 {
1840618465 return ira->codegen->invalid_inst_gen->value->type;
1840718466 }
1840818467
1840918468 bool is_allowzero;
18410 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5,
18469 if ((err = get_const_field_bool(ira, source_node, payload, "is_allowzero", 5,
1841118470 &is_allowzero)))
1841218471 {
1841318472 return ira->codegen->invalid_inst_gen->value->type;
......@@ -18431,16 +18490,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1843118490 case ZigTypeIdArray: {
1843218491 assert(payload->special == ConstValSpecialStatic);
1843318492 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
18434 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);
18493 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 1);
1843518494 if (type_is_invalid(elem_type))
1843618495 return ira->codegen->invalid_inst_gen->value->type;
1843718496 ZigValue *sentinel;
18438 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2,
18497 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 2,
1843918498 elem_type, &sentinel)))
1844018499 {
1844118500 return ira->codegen->invalid_inst_gen->value->type;
1844218501 }
18443 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);
18502 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "len", 0);
1844418503 if (bi == nullptr)
1844518504 return ira->codegen->invalid_inst_gen->value->type;
1844618505 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
......@@ -18448,7 +18507,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1844818507 case ZigTypeIdOptional: {
1844918508 assert(payload->special == ConstValSpecialStatic);
1845018509 assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr));
18451 ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 0);
18510 ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 0);
1845218511 if (type_is_invalid(child_type))
1845318512 return ira->codegen->invalid_inst_gen->value->type;
1845418513 return get_optional_type(ira->codegen, child_type);
......@@ -18456,11 +18515,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1845618515 case ZigTypeIdErrorUnion: {
1845718516 assert(payload->special == ConstValSpecialStatic);
1845818517 assert(payload->type == ir_type_info_get_type(ira, "ErrorUnion", nullptr));
18459 ZigType *err_set_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "error_set", 0);
18518 ZigType *err_set_type = get_const_field_meta_type(ira, source_node, payload, "error_set", 0);
1846018519 if (type_is_invalid(err_set_type))
1846118520 return ira->codegen->invalid_inst_gen->value->type;
1846218521
18463 ZigType *payload_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "payload", 1);
18522 ZigType *payload_type = get_const_field_meta_type(ira, source_node, payload, "payload", 1);
1846418523 if (type_is_invalid(payload_type))
1846518524 return ira->codegen->invalid_inst_gen->value->type;
1846618525
......@@ -18470,7 +18529,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1847018529 assert(payload->special == ConstValSpecialStatic);
1847118530 assert(payload->type == ir_type_info_get_type(ira, "Opaque", nullptr));
1847218531
18473 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 0);
18532 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 0);
1847418533 if (decls_value == nullptr)
1847518534 return ira->codegen->invalid_inst_gen->value->type;
1847618535 assert(decls_value->special == ConstValSpecialStatic);
......@@ -18478,25 +18537,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1847818537 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
1847918538 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
1848018539 if (decls_len != 0) {
18481 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
18540 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
1848218541 return ira->codegen->invalid_inst_gen->value->type;
1848318542 }
1848418543
1848518544 Buf *bare_name = buf_alloc();
1848618545 Buf *full_name = get_anon_type_name(ira->codegen,
18487 ira->zir, "opaque", source_instr->scope, source_instr->source_node, bare_name);
18546 ira->zir, "opaque", scope, source_node, bare_name);
1848818547 return get_opaque_type(ira->codegen,
18489 source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name);
18548 scope, source_node, buf_ptr(full_name), bare_name);
1849018549 }
1849118550 case ZigTypeIdVector: {
1849218551 assert(payload->special == ConstValSpecialStatic);
1849318552 assert(payload->type == ir_type_info_get_type(ira, "Vector", nullptr));
18494 BigInt *len = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);
18553 BigInt *len = get_const_field_lit_int(ira, source_node, payload, "len", 0);
1849518554 if (len == nullptr)
1849618555 return ira->codegen->invalid_inst_gen->value->type;
1849718556
18498 ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);
18499 if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, child_type))) {
18557 ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 1);
18558 if ((err = ir_validate_vector_elem_type(ira, source_node, child_type))) {
1850018559 return ira->codegen->invalid_inst_gen->value->type;
1850118560 }
1850218561 return get_vector_type(ira->codegen, bigint_as_u32(len), child_type);
......@@ -18504,7 +18563,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1850418563 case ZigTypeIdAnyFrame: {
1850518564 assert(payload->special == ConstValSpecialStatic);
1850618565 assert(payload->type == ir_type_info_get_type(ira, "AnyFrame", nullptr));
18507 ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);
18566 ZigType *child_type = get_const_field_meta_type_optional(ira, source_node, payload, "child", 0);
1850818567 if (child_type != nullptr && type_is_invalid(child_type))
1850918568 return ira->codegen->invalid_inst_gen->value->type;
1851018569
......@@ -18513,7 +18572,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1851318572 case ZigTypeIdFnFrame: {
1851418573 assert(payload->special == ConstValSpecialStatic);
1851518574 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
18516 ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);
18575 ZigValue *function = get_const_field(ira, source_node, payload, "function", 0);
1851718576 if (function == nullptr)
1851818577 return ira->codegen->invalid_inst_gen->value->type;
1851918578
......@@ -18531,7 +18590,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1853118590 assert(is_slice(slice->type));
1853218591 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
1853318592 Buf bare_name = BUF_INIT;
18534 buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", source_instr->scope, source_instr->source_node, &bare_name));
18593 buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", scope, source_node, &bare_name));
1853518594 err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits;
1853618595 err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align;
1853718596 err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size;
......@@ -18550,8 +18609,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1855018609 ZigValue *error = &arr->data.x_array.data.s_none.elements[i];
1855118610 assert(error->type == ir_type_info_get_type(ira, "Error", nullptr));
1855218611 ErrorTableEntry *err_entry = heap::c_allocator.create<ErrorTableEntry>();
18553 err_entry->decl_node = source_instr->source_node;
18554 if ((err = get_const_field_buf(ira, source_instr->source_node, error, "name", 0, &err_entry->name)))
18612 err_entry->decl_node = source_node;
18613 if ((err = get_const_field_buf(ira, source_node, error, "name", 0, &err_entry->name)))
1855518614 return ira->codegen->invalid_inst_gen->value->type;
1855618615 auto existing_entry = ira->codegen->error_table.put_unique(&err_entry->name, err_entry);
1855718616 if (existing_entry) {
......@@ -18563,7 +18622,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1856318622 ira->codegen->errors_by_index.append(err_entry);
1856418623 }
1856518624 if (already_set[err_entry->value]) {
18566 ir_add_error(ira, source_instr, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name)));
18625 ir_add_error_node(ira, source_node, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name)));
1856718626 return ira->codegen->invalid_inst_gen->value->type;
1856818627 } else {
1856918628 already_set[err_entry->value] = true;
......@@ -18576,14 +18635,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1857618635 assert(payload->special == ConstValSpecialStatic);
1857718636 assert(payload->type == ir_type_info_get_type(ira, "Struct", nullptr));
1857818637
18579 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);
18638 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
1858018639 if (layout_value == nullptr)
1858118640 return ira->codegen->invalid_inst_gen->value->type;
1858218641 assert(layout_value->special == ConstValSpecialStatic);
1858318642 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
1858418643 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1858518644
18586 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 1);
18645 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 1);
1858718646 if (fields_value == nullptr)
1858818647 return ira->codegen->invalid_inst_gen->value->type;
1858918648 assert(fields_value->special == ConstValSpecialStatic);
......@@ -18592,7 +18651,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1859218651 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
1859318652 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1859418653
18595 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 2);
18654 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 2);
1859618655 if (decls_value == nullptr)
1859718656 return ira->codegen->invalid_inst_gen->value->type;
1859818657 assert(decls_value->special == ConstValSpecialStatic);
......@@ -18600,18 +18659,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1860018659 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
1860118660 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
1860218661 if (decls_len != 0) {
18603 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
18662 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
1860418663 return ira->codegen->invalid_inst_gen->value->type;
1860518664 }
1860618665
1860718666 bool is_tuple;
18608 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_tuple", 3, &is_tuple)))
18667 if ((err = get_const_field_bool(ira, source_node, payload, "is_tuple", 3, &is_tuple)))
1860918668 return ira->codegen->invalid_inst_gen->value->type;
1861018669
1861118670 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
1861218671 buf_init_from_buf(&entry->name,
18613 get_anon_type_name(ira->codegen, ira->zir, "struct", source_instr->scope, source_instr->source_node, &entry->name));
18614 entry->data.structure.decl_node = source_instr->source_node;
18672 get_anon_type_name(ira->codegen, ira->zir, "struct", scope, source_node, &entry->name));
18673 entry->data.structure.decl_node = source_node;
1861518674 entry->data.structure.fields = alloc_type_struct_fields(fields_len);
1861618675 entry->data.structure.fields_by_name.init(fields_len);
1861718676 entry->data.structure.src_field_count = fields_len;
......@@ -18619,7 +18678,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1861918678 entry->data.structure.special = is_tuple ? StructSpecialInferredTuple : StructSpecialNone;
1862018679 entry->data.structure.created_by_at_type = true;
1862118680 entry->data.structure.decls_scope = create_decls_scope(
18622 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);
18681 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
1862318682
1862418683 assert(fields_ptr->data.x_ptr.special == ConstPtrSpecialBaseArray);
1862518684 assert(fields_ptr->data.x_ptr.data.base_array.elem_index == 0);
......@@ -18631,19 +18690,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1863118690 assert(field_value->type == ir_type_info_get_type(ira, "StructField", nullptr));
1863218691 TypeStructField *field = entry->data.structure.fields[i];
1863318692 field->name = buf_alloc();
18634 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))
18693 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
1863518694 return ira->codegen->invalid_inst_gen->value->type;
18636 field->decl_node = source_instr->source_node;
18637 ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1);
18695 field->decl_node = source_node;
18696 ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1);
1863818697 if (type_value == nullptr)
1863918698 return ira->codegen->invalid_inst_gen->value->type;
1864018699 field->type_val = type_value;
1864118700 field->type_entry = type_value->data.x_type;
1864218701 if (entry->data.structure.fields_by_name.put_unique(field->name, field) != nullptr) {
18643 ir_add_error(ira, source_instr, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name)));
18702 ir_add_error_node(ira, source_node, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name)));
1864418703 return ira->codegen->invalid_inst_gen->value->type;
1864518704 }
18646 ZigValue *default_value = get_const_field(ira, source_instr->source_node, field_value, "default_value", 2);
18705 ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2);
1864718706 if (default_value == nullptr)
1864818707 return ira->codegen->invalid_inst_gen->value->type;
1864918708 if (default_value->type->id == ZigTypeIdNull) {
......@@ -18653,15 +18712,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1865318712 } else if (default_value->type == field->type_entry) {
1865418713 field->init_val = default_value;
1865518714 } else {
18656 ir_add_error(ira, source_instr,
18715 ir_add_error_node(ira, source_node,
1865718716 buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'",
1865818717 buf_ptr(field->name), buf_ptr(&default_value->type->name),
1865918718 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));
1866018719 return ira->codegen->invalid_inst_gen->value->type;
1866118720 }
18662 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))
18721 if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime)))
1866318722 return ira->codegen->invalid_inst_gen->value->type;
18664 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 4);
18723 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4);
1866518724 if (alignment == nullptr)
1866618725 return ira->codegen->invalid_inst_gen->value->type;
1866718726 field->align = bigint_as_u32(alignment);
......@@ -18673,7 +18732,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1867318732 assert(payload->special == ConstValSpecialStatic);
1867418733 assert(payload->type == ir_type_info_get_type(ira, "Enum", nullptr));
1867518734
18676 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);
18735 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
1867718736 if (layout_value == nullptr)
1867818737 return ira->codegen->invalid_inst_gen->value->type;
1867918738
......@@ -18681,16 +18740,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1868118740 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
1868218741 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1868318742
18684 ZigType *tag_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "tag_type", 1);
18743 ZigType *tag_type = get_const_field_meta_type(ira, source_node, payload, "tag_type", 1);
1868518744 if (type_is_invalid(tag_type))
1868618745 return ira->codegen->invalid_inst_gen->value->type;
1868718746 if (tag_type->id != ZigTypeIdInt) {
18688 ir_add_error(ira, source_instr, buf_sprintf(
18747 ir_add_error_node(ira, source_node, buf_sprintf(
1868918748 "TypeInfo.Enum.tag_type must be an integer type, not '%s'", buf_ptr(&tag_type->name)));
1869018749 return ira->codegen->invalid_inst_gen->value->type;
1869118750 }
1869218751
18693 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2);
18752 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2);
1869418753 if (fields_value == nullptr)
1869518754 return ira->codegen->invalid_inst_gen->value->type;
1869618755
......@@ -18700,7 +18759,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1870018759 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
1870118760 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1870218761
18703 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3);
18762 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3);
1870418763 if (decls_value == nullptr)
1870518764 return ira->codegen->invalid_inst_gen->value->type;
1870618765
......@@ -18709,22 +18768,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1870918768 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
1871018769 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
1871118770 if (decls_len != 0) {
18712 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type"));
18771 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type"));
1871318772 return ira->codegen->invalid_inst_gen->value->type;
1871418773 }
1871518774
1871618775 Error err;
1871718776 bool is_exhaustive;
18718 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_exhaustive", 4, &is_exhaustive)))
18777 if ((err = get_const_field_bool(ira, source_node, payload, "is_exhaustive", 4, &is_exhaustive)))
1871918778 return ira->codegen->invalid_inst_gen->value->type;
1872018779
1872118780 ZigType *entry = new_type_table_entry(ZigTypeIdEnum);
1872218781 buf_init_from_buf(&entry->name,
18723 get_anon_type_name(ira->codegen, ira->zir, "enum", source_instr->scope, source_instr->source_node, &entry->name));
18724 entry->data.enumeration.decl_node = source_instr->source_node;
18782 get_anon_type_name(ira->codegen, ira->zir, "enum", scope, source_node, &entry->name));
18783 entry->data.enumeration.decl_node = source_node;
1872518784 entry->data.enumeration.tag_int_type = tag_type;
1872618785 entry->data.enumeration.decls_scope = create_decls_scope(
18727 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);
18786 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
1872818787 entry->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(fields_len);
1872918788 entry->data.enumeration.fields_by_name.init(fields_len);
1873018789 entry->data.enumeration.src_field_count = fields_len;
......@@ -18741,15 +18800,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1874118800 assert(field_value->type == ir_type_info_get_type(ira, "EnumField", nullptr));
1874218801 TypeEnumField *field = &entry->data.enumeration.fields[i];
1874318802 field->name = buf_alloc();
18744 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))
18803 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
1874518804 return ira->codegen->invalid_inst_gen->value->type;
1874618805 field->decl_index = i;
18747 field->decl_node = source_instr->source_node;
18806 field->decl_node = source_node;
1874818807 if (entry->data.enumeration.fields_by_name.put_unique(field->name, field) != nullptr) {
18749 ir_add_error(ira, source_instr, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name)));
18808 ir_add_error_node(ira, source_node, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name)));
1875018809 return ira->codegen->invalid_inst_gen->value->type;
1875118810 }
18752 BigInt *field_int_value = get_const_field_lit_int(ira, source_instr->source_node, field_value, "value", 1);
18811 BigInt *field_int_value = get_const_field_lit_int(ira, source_node, field_value, "value", 1);
1875318812 if (field_int_value == nullptr)
1875418813 return ira->codegen->invalid_inst_gen->value->type;
1875518814 field->value = *field_int_value;
......@@ -18760,24 +18819,24 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1876018819 assert(payload->special == ConstValSpecialStatic);
1876118820 assert(payload->type == ir_type_info_get_type(ira, "Union", nullptr));
1876218821
18763 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);
18822 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
1876418823 if (layout_value == nullptr)
1876518824 return ira->codegen->invalid_inst_gen->value->type;
1876618825 assert(layout_value->special == ConstValSpecialStatic);
1876718826 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
1876818827 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1876918828
18770 ZigType *tag_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "tag_type", 1);
18829 ZigType *tag_type = get_const_field_meta_type_optional(ira, source_node, payload, "tag_type", 1);
1877118830 if (tag_type != nullptr && type_is_invalid(tag_type)) {
1877218831 return ira->codegen->invalid_inst_gen->value->type;
1877318832 }
1877418833 if (tag_type != nullptr && tag_type->id != ZigTypeIdEnum) {
18775 ir_add_error(ira, source_instr, buf_sprintf(
18834 ir_add_error_node(ira, source_node, buf_sprintf(
1877618835 "expected enum type, found '%s'", type_id_name(tag_type->id)));
1877718836 return ira->codegen->invalid_inst_gen->value->type;
1877818837 }
1877918838
18780 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2);
18839 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2);
1878118840 if (fields_value == nullptr)
1878218841 return ira->codegen->invalid_inst_gen->value->type;
1878318842
......@@ -18787,7 +18846,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1878718846 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
1878818847 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1878918848
18790 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3);
18849 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3);
1879118850 if (decls_value == nullptr)
1879218851 return ira->codegen->invalid_inst_gen->value->type;
1879318852
......@@ -18796,18 +18855,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1879618855 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
1879718856 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
1879818857 if (decls_len != 0) {
18799 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type"));
18858 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type"));
1880018859 return ira->codegen->invalid_inst_gen->value->type;
1880118860 }
1880218861
1880318862 ZigType *entry = new_type_table_entry(ZigTypeIdUnion);
1880418863 buf_init_from_buf(&entry->name,
18805 get_anon_type_name(ira->codegen, ira->zir, "union", source_instr->scope, source_instr->source_node, &entry->name));
18806 entry->data.unionation.decl_node = source_instr->source_node;
18864 get_anon_type_name(ira->codegen, ira->zir, "union", scope, source_node, &entry->name));
18865 entry->data.unionation.decl_node = source_node;
1880718866 entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len);
1880818867 entry->data.unionation.fields_by_name.init(fields_len);
1880918868 entry->data.unionation.decls_scope = create_decls_scope(
18810 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);
18869 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
1881118870 entry->data.unionation.tag_type = tag_type;
1881218871 entry->data.unionation.src_field_count = fields_len;
1881318872 entry->data.unionation.layout = layout;
......@@ -18822,19 +18881,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1882218881 assert(field_value->type == ir_type_info_get_type(ira, "UnionField", nullptr));
1882318882 TypeUnionField *field = &entry->data.unionation.fields[i];
1882418883 field->name = buf_alloc();
18825 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))
18884 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
1882618885 return ira->codegen->invalid_inst_gen->value->type;
1882718886 if (entry->data.unionation.fields_by_name.put_unique(field->name, field) != nullptr) {
18828 ir_add_error(ira, source_instr, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name)));
18887 ir_add_error_node(ira, source_node, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name)));
1882918888 return ira->codegen->invalid_inst_gen->value->type;
1883018889 }
18831 field->decl_node = source_instr->source_node;
18832 ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1);
18890 field->decl_node = source_node;
18891 ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1);
1883318892 if (type_value == nullptr)
1883418893 return ira->codegen->invalid_inst_gen->value->type;
1883518894 field->type_val = type_value;
1883618895 field->type_entry = type_value->data.x_type;
18837 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 2);
18896 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 2);
1883818897 if (alignment == nullptr)
1883918898 return ira->codegen->invalid_inst_gen->value->type;
1884018899 field->align = bigint_as_u32(alignment);
......@@ -18846,41 +18905,41 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1884618905 assert(payload->special == ConstValSpecialStatic);
1884718906 assert(payload->type == ir_type_info_get_type(ira, "Fn", nullptr));
1884818907
18849 ZigValue *cc_value = get_const_field(ira, source_instr->source_node, payload, "calling_convention", 0);
18908 ZigValue *cc_value = get_const_field(ira, source_node, payload, "calling_convention", 0);
1885018909 if (cc_value == nullptr)
1885118910 return ira->codegen->invalid_inst_gen->value->type;
1885218911 assert(cc_value->special == ConstValSpecialStatic);
1885318912 assert(cc_value->type == get_builtin_type(ira->codegen, "CallingConvention"));
1885418913 CallingConvention cc = (CallingConvention)bigint_as_u32(&cc_value->data.x_enum_tag);
1885518914
18856 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 1);
18915 BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 1);
1885718916 if (alignment == nullptr)
1885818917 return ira->codegen->invalid_inst_gen->value->type;
1885918918
1886018919 Error err;
1886118920 bool is_generic;
18862 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_generic", 2, &is_generic)))
18921 if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 2, &is_generic)))
1886318922 return ira->codegen->invalid_inst_gen->value->type;
1886418923 if (is_generic) {
18865 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));
18924 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));
1886618925 return ira->codegen->invalid_inst_gen->value->type;
1886718926 }
1886818927
1886918928 bool is_var_args;
18870 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_var_args", 3, &is_var_args)))
18929 if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 3, &is_var_args)))
1887118930 return ira->codegen->invalid_inst_gen->value->type;
1887218931 if (is_var_args && cc != CallingConventionC) {
18873 ir_add_error(ira, source_instr, buf_sprintf("varargs functions must have C calling convention"));
18932 ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention"));
1887418933 return ira->codegen->invalid_inst_gen->value->type;
1887518934 }
1887618935
18877 ZigType *return_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "return_type", 4);
18936 ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 4);
1887818937 if (return_type == nullptr) {
18879 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));
18938 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));
1888018939 return ira->codegen->invalid_inst_gen->value->type;
1888118940 }
1888218941
18883 ZigValue *args_value = get_const_field(ira, source_instr->source_node, payload, "args", 5);
18942 ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 5);
1888418943 if (args_value == nullptr)
1888518944 return ira->codegen->invalid_inst_gen->value->type;
1888618945 assert(args_value->special == ConstValSpecialStatic);
......@@ -18909,18 +18968,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
1890918968 FnTypeParamInfo *info = &fn_type_id.param_info[i];
1891018969 Error err;
1891118970 bool is_generic;
18912 if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_generic", 0, &is_generic)))
18971 if ((err = get_const_field_bool(ira, source_node, arg_value, "is_generic", 0, &is_generic)))
1891318972 return ira->codegen->invalid_inst_gen->value->type;
1891418973 if (is_generic) {
18915 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type"));
18974 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type"));
1891618975 return ira->codegen->invalid_inst_gen->value->type;
1891718976 }
18918 if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_noalias", 1, &info->is_noalias)))
18977 if ((err = get_const_field_bool(ira, source_node, arg_value, "is_noalias", 1, &info->is_noalias)))
1891918978 return ira->codegen->invalid_inst_gen->value->type;
1892018979 ZigType *type = get_const_field_meta_type_optional(
18921 ira, source_instr->source_node, arg_value, "arg_type", 2);
18980 ira, source_node, arg_value, "arg_type", 2);
1892218981 if (type == nullptr) {
18923 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type"));
18982 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type"));
1892418983 return ira->codegen->invalid_inst_gen->value->type;
1892518984 }
1892618985 info->type = type;
......@@ -18958,11 +19017,11 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
1895819017 if (type_info_val == nullptr)
1895919018 return ira->codegen->invalid_inst_gen;
1896019019 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
18961 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,
18962 type_info_val->data.x_union.payload);
19020 ZigType *type = type_info_to_type(ira, uncasted_type_info->scope,
19021 uncasted_type_info->source_node, type_id_tag, type_info_val->data.x_union.payload);
1896319022 if (type_is_invalid(type))
1896419023 return ira->codegen->invalid_inst_gen;
18965 return ir_const_type(ira, &instruction->base.base, type);
19024 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, type);
1896619025}
1896719026
1896819027static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
......@@ -18976,7 +19035,7 @@ static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
1897619035 *ira->backward_branch_quota = new_quota;
1897719036 }
1897819037
18979 return ir_const_void(ira, &instruction->base.base);
19038 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1898019039}
1898119040
1898219041static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
......@@ -18988,18 +19047,18 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
1898819047 if (!type_entry->cached_const_name_val) {
1898919048 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
1899019049 }
18991 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
19050 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1899219051 copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val);
1899319052 return result;
1899419053}
1899519054
1899619055static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
1899719056 Error err;
18998 AstNode *node = instruction->base.base.source_node;
19057 AstNode *node = instruction->base.source_node;
1899919058 assert(node->type == NodeTypeFnCallExpr);
1900019059 AstNode *block_node = node->data.fn_call_expr.params.at(0);
1900119060
19002 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope);
19061 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope);
1900319062
1900419063 // Execute the C import block like an inline function
1900519064 ZigType *void_type = ira->codegen->builtin_types.entry_void;
......@@ -19015,7 +19074,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
1901519074 if (type_is_invalid(cimport_result->type))
1901619075 return ira->codegen->invalid_inst_gen;
1901719076
19018 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
19077 ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);
1901919078 RootStruct *root_struct = node->owner->data.structure.root_struct;
1902019079 TokenLoc tok_loc = root_struct->token_locs[node->main_token];
1902119080 Buf *namespace_name = buf_sprintf("%s.cimport:%" PRIu32 ":%" PRIu32,
......@@ -19072,7 +19131,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
1907219131 }
1907319132 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
1907419133 import_code, SourceKindCImport);
19075 return ir_const_type(ira, &instruction->base.base, child_import);
19134 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, child_import);
1907619135}
1907719136
1907819137static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
......@@ -19090,7 +19149,7 @@ static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInc
1909019149
1909119150 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
1909219151
19093 return ir_const_void(ira, &instruction->base.base);
19152 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1909419153}
1909519154
1909619155static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
......@@ -19121,7 +19180,7 @@ static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefi
1912119180 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
1912219181 define_value ? buf_ptr(define_value) : "");
1912319182
19124 return ir_const_void(ira, &instruction->base.base);
19183 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1912519184}
1912619185
1912719186static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
......@@ -19139,7 +19198,7 @@ static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef
1913919198
1914019199 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
1914119200
19142 return ir_const_void(ira, &instruction->base.base);
19201 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
1914319202}
1914419203
1914519204static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
......@@ -19151,7 +19210,7 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb
1915119210 if (!rel_file_path)
1915219211 return ira->codegen->invalid_inst_gen;
1915319212
19154 ZigType *import = get_scope_import(instruction->base.base.scope);
19213 ZigType *import = get_scope_import(instruction->base.scope);
1915519214 // figure out absolute path to resource
1915619215 Buf source_dir_path = BUF_INIT;
1915719216 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
......@@ -19168,17 +19227,17 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb
1916819227 Error err;
1916919228 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
1917019229 if (err == ErrorFileNotFound) {
19171 ir_add_error(ira, &instruction->name->base,
19230 ir_add_error_node(ira, instruction->name->source_node,
1917219231 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
1917319232 return ira->codegen->invalid_inst_gen;
1917419233 } else {
19175 ir_add_error(ira, &instruction->name->base,
19234 ir_add_error_node(ira, instruction->name->source_node,
1917619235 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
1917719236 return ira->codegen->invalid_inst_gen;
1917819237 }
1917919238 }
1918019239
19181 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
19240 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
1918219241 init_const_str_lit(ira->codegen, result->value, file_contents, true);
1918319242 return result;
1918419243}
......@@ -19189,7 +19248,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1918919248 return ira->codegen->invalid_inst_gen;
1919019249
1919119250 if (operand_type->id == ZigTypeIdFloat) {
19192 ir_add_error(ira, &instruction->type_value->child->base,
19251 ir_add_error(ira, instruction->type_value->child,
1919319252 buf_sprintf("expected bool, integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
1919419253 return ira->codegen->invalid_inst_gen;
1919519254 }
......@@ -19200,7 +19259,8 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1920019259
1920119260 // TODO let this be volatile
1920219261 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
19203 IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type);
19262 IrInstGen *casted_ptr = ir_implicit_cast2(ira, instruction->ptr->scope,
19263 instruction->ptr->source_node, ptr, ptr_type);
1920419264 if (type_is_invalid(casted_ptr->value->type))
1920519265 return ira->codegen->invalid_inst_gen;
1920619266
......@@ -19228,31 +19288,33 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1922819288 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
1922919289 return ira->codegen->invalid_inst_gen;
1923019290
19231 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type);
19291 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, instruction->cmp_value->scope,
19292 instruction->cmp_value->source_node, cmp_value, operand_type);
1923219293 if (type_is_invalid(casted_cmp_value->value->type))
1923319294 return ira->codegen->invalid_inst_gen;
1923419295
19235 IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type);
19296 IrInstGen *casted_new_value = ir_implicit_cast2(ira, instruction->new_value->scope,
19297 instruction->new_value->source_node, new_value, operand_type);
1923619298 if (type_is_invalid(casted_new_value->value->type))
1923719299 return ira->codegen->invalid_inst_gen;
1923819300
1923919301 if (success_order < AtomicOrderMonotonic) {
19240 ir_add_error(ira, &success_order_value->base,
19302 ir_add_error(ira, success_order_value,
1924119303 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
1924219304 return ira->codegen->invalid_inst_gen;
1924319305 }
1924419306 if (failure_order < AtomicOrderMonotonic) {
19245 ir_add_error(ira, &failure_order_value->base,
19307 ir_add_error(ira, failure_order_value,
1924619308 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
1924719309 return ira->codegen->invalid_inst_gen;
1924819310 }
1924919311 if (failure_order > success_order) {
19250 ir_add_error(ira, &failure_order_value->base,
19312 ir_add_error(ira, failure_order_value,
1925119313 buf_sprintf("failure atomic ordering must be no stricter than success"));
1925219314 return ira->codegen->invalid_inst_gen;
1925319315 }
1925419316 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
19255 ir_add_error(ira, &failure_order_value->base,
19317 ir_add_error(ira, failure_order_value,
1925619318 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
1925719319 return ira->codegen->invalid_inst_gen;
1925819320 }
......@@ -19264,7 +19326,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1926419326 case OnePossibleValueInvalid:
1926519327 return ira->codegen->invalid_inst_gen;
1926619328 case OnePossibleValueYes: {
19267 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
19329 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
1926819330 set_optional_value_to_null(result->value);
1926919331 return result;
1927019332 }
......@@ -19278,7 +19340,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1927819340 if (ptr_val == nullptr)
1927919341 return ira->codegen->invalid_inst_gen;
1928019342
19281 ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node);
19343 ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
1928219344 if (stored_val == nullptr)
1928319345 return ira->codegen->invalid_inst_gen;
1928419346
......@@ -19291,7 +19353,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1929119353 return ira->codegen->invalid_inst_gen;
1929219354
1929319355 bool eql = const_values_equal(ira->codegen, stored_val, expected_val);
19294 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
19356 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
1929519357 if (eql) {
1929619358 copy_const_val(ira->codegen, stored_val, new_val);
1929719359 set_optional_value_to_null(result->value);
......@@ -19303,7 +19365,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1930319365
1930419366 IrInstGen *result_loc;
1930519367 if (handle_is_ptr(ira->codegen, result_type)) {
19306 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
19368 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
1930719369 result_type, nullptr, true, true);
1930819370 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1930919371 return result_loc;
......@@ -19312,12 +19374,12 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1931219374 result_loc = nullptr;
1931319375 }
1931419376
19315 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,
19377 return ir_build_cmpxchg_gen(ira, instruction->base.scope, instruction->base.source_node, result_type,
1931619378 casted_ptr, casted_cmp_value, casted_new_value,
1931719379 success_order, failure_order, instruction->is_weak, result_loc);
1931819380}
1931919381
19320static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp op, ZigValue *value, ZigValue *out_value) {
19382static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, ZigValue *value, ZigValue *out_value) {
1932119383 assert(value->type->id == ZigTypeIdVector);
1932219384 ZigType *scalar_type = value->type->data.vector.elem_type;
1932319385 const size_t len = value->type->data.vector.len;
......@@ -19371,7 +19433,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
1937119433 default: zig_unreachable();
1937219434 }
1937319435
19374 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,
19436 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
1937519437 out_value, bin_op, elem_val, out_value);
1937619438 if (msg != nullptr)
1937719439 return msg;
......@@ -19407,7 +19469,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
1940719469 default: zig_unreachable();
1940819470 }
1940919471
19410 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,
19472 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
1941119473 out_value, bin_op, elem_val, out_value);
1941219474 if (msg != nullptr)
1941319475 return msg;
......@@ -19430,7 +19492,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
1943019492 default: zig_unreachable();
1943119493 }
1943219494
19433 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr,
19495 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node,
1943419496 elem_val, bin_op, candidate_elem_val, dummy_cmp_value);
1943519497 if (msg != nullptr)
1943619498 return msg;
......@@ -19456,7 +19518,7 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
1945619518
1945719519 ZigType *value_type = value_inst->value->type;
1945819520 if (value_type->id != ZigTypeIdVector) {
19459 ir_add_error(ira, &value_inst->base,
19521 ir_add_error(ira, value_inst,
1946019522 buf_sprintf("expected vector type, found '%s'",
1946119523 buf_ptr(&value_type->name)));
1946219524 return ira->codegen->invalid_inst_gen;
......@@ -19472,14 +19534,14 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
1947219534 break;
1947319535 case ZigTypeIdBool:
1947419536 if (op > ReduceOp_xor) {
19475 ir_add_error(ira, &op_inst->base,
19537 ir_add_error(ira, op_inst,
1947619538 buf_sprintf("invalid operation for '%s' type",
1947719539 buf_ptr(&elem_type->name)));
1947819540 return ira->codegen->invalid_inst_gen;
1947919541 } break;
1948019542 case ZigTypeIdFloat:
1948119543 if (op < ReduceOp_min) {
19482 ir_add_error(ira, &op_inst->base,
19544 ir_add_error(ira, op_inst,
1948319545 buf_sprintf("invalid operation for '%s' type",
1948419546 buf_ptr(&elem_type->name)));
1948519547 return ira->codegen->invalid_inst_gen;
......@@ -19494,20 +19556,20 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
1949419556 case OnePossibleValueInvalid:
1949519557 return ira->codegen->invalid_inst_gen;
1949619558 case OnePossibleValueYes:
19497 return ir_const_move(ira, &instruction->base.base,
19559 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node,
1949819560 get_the_one_possible_value(ira->codegen, elem_type));
1949919561 case OnePossibleValueNo:
1950019562 break;
1950119563 }
1950219564
1950319565 if (instr_is_comptime(value_inst)) {
19504 IrInstGen *result = ir_const(ira, &instruction->base.base, elem_type);
19505 if (ir_eval_reduce(ira, &instruction->base.base, op, value_inst->value, result->value))
19566 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, elem_type);
19567 if (ir_eval_reduce(ira, instruction->base.scope, instruction->base.source_node, op, value_inst->value, result->value))
1950619568 return ira->codegen->invalid_inst_gen;
1950719569 return result;
1950819570 }
1950919571
19510 return ir_build_reduce_gen(ira, &instruction->base.base, op, value_inst, elem_type);
19572 return ir_build_reduce_gen(ira, instruction->base.scope, instruction->base.source_node, op, value_inst, elem_type);
1951119573}
1951219574
1951319575static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
......@@ -19520,12 +19582,12 @@ static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *i
1952019582 return ira->codegen->invalid_inst_gen;
1952119583
1952219584 if (order < AtomicOrderAcquire) {
19523 ir_add_error(ira, &order_inst->base,
19585 ir_add_error(ira, order_inst,
1952419586 buf_sprintf("atomic ordering must be Acquire or stricter"));
1952519587 return ira->codegen->invalid_inst_gen;
1952619588 }
1952719589
19528 return ir_build_fence_gen(ira, &instruction->base.base, order);
19590 return ir_build_fence_gen(ira, instruction->base.scope, instruction->base.source_node, order);
1952919591}
1953019592
1953119593static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
......@@ -19537,7 +19599,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
1953719599 if (dest_type->id != ZigTypeIdInt &&
1953819600 dest_type->id != ZigTypeIdComptimeInt)
1953919601 {
19540 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19602 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
1954119603 return ira->codegen->invalid_inst_gen;
1954219604 }
1954319605
......@@ -19549,21 +19611,21 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
1954919611 if (src_type->id != ZigTypeIdInt &&
1955019612 src_type->id != ZigTypeIdComptimeInt)
1955119613 {
19552 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
19614 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
1955319615 return ira->codegen->invalid_inst_gen;
1955419616 }
1955519617
1955619618 if (dest_type->id == ZigTypeIdComptimeInt) {
19557 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
19619 return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type);
1955819620 }
1955919621
1956019622 if (src_type->id != ZigTypeIdComptimeInt) {
1956119623 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
1956219624 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
19563 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
19625 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
1956419626 return ira->codegen->invalid_inst_gen;
1956519627 } else if (src_type->data.integral.bit_count > 0 && src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
19566 ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
19628 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
1956719629 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
1956819630 return ira->codegen->invalid_inst_gen;
1956919631 }
......@@ -19574,19 +19636,19 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
1957419636 if (val == nullptr)
1957519637 return ira->codegen->invalid_inst_gen;
1957619638
19577 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
19639 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type);
1957819640 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
1957919641 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
1958019642 return result;
1958119643 }
1958219644
1958319645 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
19584 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
19646 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type);
1958519647 bigint_init_unsigned(&result->value->data.x_bigint, 0);
1958619648 return result;
1958719649 }
1958819650
19589 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);
19651 return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target);
1959019652}
1959119653
1959219654static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
......@@ -19598,7 +19660,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
1959819660 dest_type->data.vector.elem_type : dest_type;
1959919661
1960019662 if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) {
19601 ir_add_error(ira, &instruction->dest_type->base,
19663 ir_add_error_node(ira, instruction->dest_type->source_node,
1960219664 buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name)));
1960319665 return ira->codegen->invalid_inst_gen;
1960419666 }
......@@ -19611,7 +19673,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
1961119673 target->value->type->data.vector.elem_type : target->value->type;
1961219674
1961319675 if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) {
19614 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'",
19676 ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected integer type, found '%s'",
1961519677 buf_ptr(&scalar_target_type->name)));
1961619678 return ira->codegen->invalid_inst_gen;
1961719679 }
......@@ -19621,10 +19683,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
1962119683 if (val == nullptr)
1962219684 return ira->codegen->invalid_inst_gen;
1962319685
19624 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
19686 return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type);
1962519687 }
1962619688
19627 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
19689 return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
1962819690}
1962919691
1963019692static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
......@@ -19633,7 +19695,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
1963319695 return ira->codegen->invalid_inst_gen;
1963419696
1963519697 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {
19636 ir_add_error(ira, &instruction->dest_type->base,
19698 ir_add_error_node(ira, instruction->dest_type->source_node,
1963719699 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
1963819700 return ira->codegen->invalid_inst_gen;
1963919701 }
......@@ -19652,14 +19714,14 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
1965219714 } else {
1965319715 op = CastOpNumLitToConcrete;
1965419716 }
19655 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op);
19717 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, op);
1965619718 } else {
1965719719 return ira->codegen->invalid_inst_gen;
1965819720 }
1965919721 }
1966019722
1966119723 if (target->value->type->id != ZigTypeIdFloat) {
19662 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
19724 ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected float type, found '%s'",
1966319725 buf_ptr(&target->value->type->name)));
1966419726 return ira->codegen->invalid_inst_gen;
1966519727 }
......@@ -19670,10 +19732,11 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
1967019732 return ira->codegen->invalid_inst_gen;
1967119733
1967219734 // XXX: This will trigger an assertion failure if dest_type is comptime_float
19673 return ir_analyze_widen_or_shorten(ira, &instruction->target->base, target, dest_type);
19735 return ir_analyze_widen_or_shorten(ira, instruction->target->scope,
19736 instruction->target->source_node, target, dest_type);
1967419737 }
1967519738
19676 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
19739 return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
1967719740}
1967819741
1967919742static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {
......@@ -19682,7 +19745,7 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
1968219745 return ira->codegen->invalid_inst_gen;
1968319746
1968419747 if (dest_type->id != ZigTypeIdErrorSet) {
19685 ir_add_error(ira, &instruction->dest_type->base,
19748 ir_add_error_node(ira, instruction->dest_type->source_node,
1968619749 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
1968719750 return ira->codegen->invalid_inst_gen;
1968819751 }
......@@ -19692,12 +19755,12 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
1969219755 return ira->codegen->invalid_inst_gen;
1969319756
1969419757 if (target->value->type->id != ZigTypeIdErrorSet) {
19695 ir_add_error(ira, &instruction->target->base,
19758 ir_add_error_node(ira, instruction->target->source_node,
1969619759 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
1969719760 return ira->codegen->invalid_inst_gen;
1969819761 }
1969919762
19700 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
19763 return ir_analyze_err_set_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
1970119764}
1970219765
1970319766static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
......@@ -19731,7 +19794,7 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI
1973119794 return ira->codegen->invalid_inst_gen;
1973219795
1973319796 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {
19734 ir_add_error(ira, &instruction->dest_type->base,
19797 ir_add_error_node(ira, instruction->dest_type->source_node,
1973519798 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
1973619799 return ira->codegen->invalid_inst_gen;
1973719800 }
......@@ -19741,12 +19804,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI
1974119804 return ira->codegen->invalid_inst_gen;
1974219805
1974319806 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
19744 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'",
19745 buf_ptr(&target->value->type->name)));
19807 ir_add_error_node(ira, instruction->target->source_node,
19808 buf_sprintf("expected int type, found '%s'", buf_ptr(&target->value->type->name)));
1974619809 return ira->codegen->invalid_inst_gen;
1974719810 }
1974819811
19749 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);
19812 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpIntToFloat);
1975019813}
1975119814
1975219815static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {
......@@ -19755,7 +19818,8 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF
1975519818 return ira->codegen->invalid_inst_gen;
1975619819
1975719820 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {
19758 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19821 ir_add_error_node(ira, instruction->dest_type->source_node,
19822 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
1975919823 return ira->codegen->invalid_inst_gen;
1976019824 }
1976119825
......@@ -19768,12 +19832,12 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF
1976819832 }
1976919833
1977019834 if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) {
19771 ir_add_error_node(ira, target->base.source_node, buf_sprintf("expected float type, found '%s'",
19835 ir_add_error_node(ira, target->source_node, buf_sprintf("expected float type, found '%s'",
1977219836 buf_ptr(&target->value->type->name)));
1977319837 return ira->codegen->invalid_inst_gen;
1977419838 }
1977519839
19776 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpFloatToInt);
19840 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpFloatToInt);
1977719841}
1977819842
1977919843static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
......@@ -19790,7 +19854,7 @@ static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErr
1979019854 return ira->codegen->invalid_inst_gen;
1979119855 }
1979219856
19793 return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type);
19857 return ir_analyze_err_to_int(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->err_tag_type);
1979419858}
1979519859
1979619860static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
......@@ -19802,7 +19866,7 @@ static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcInt
1980219866 if (type_is_invalid(casted_target->value->type))
1980319867 return ira->codegen->invalid_inst_gen;
1980419868
19805 return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
19869 return ir_analyze_int_to_err(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->builtin_types.entry_global_error_set);
1980619870}
1980719871
1980819872static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
......@@ -19811,8 +19875,8 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
1981119875 return ira->codegen->invalid_inst_gen;
1981219876
1981319877 if (target->value->type->id != ZigTypeIdBool) {
19814 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'",
19815 buf_ptr(&target->value->type->name)));
19878 ir_add_error_node(ira, instruction->target->source_node,
19879 buf_sprintf("expected bool, found '%s'", buf_ptr(&target->value->type->name)));
1981619880 return ira->codegen->invalid_inst_gen;
1981719881 }
1981819882
......@@ -19821,11 +19885,11 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
1982119885 if (!ir_resolve_bool(ira, target, &is_true))
1982219886 return ira->codegen->invalid_inst_gen;
1982319887
19824 return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0);
19888 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, is_true ? 1 : 0);
1982519889 }
1982619890
1982719891 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
19828 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
19892 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, u1_type, CastOpBoolToInt);
1982919893}
1983019894
1983119895static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
......@@ -19839,16 +19903,16 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe
1983919903
1984019904 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);
1984119905
19842 return ir_const_type(ira, &instruction->base.base, vector_type);
19906 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, vector_type);
1984319907}
1984419908
19845static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
19909static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1984619910 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
1984719911{
1984819912 Error err;
19849 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
19913 src_assert(source_node && scalar_type && a && b && mask, source_node);
1985019914
19851 if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, scalar_type)))
19915 if ((err = ir_validate_vector_elem_type(ira, source_node, scalar_type)))
1985219916 return ira->codegen->invalid_inst_gen;
1985319917
1985419918 uint32_t len_mask;
......@@ -19857,7 +19921,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1985719921 } else if (mask->value->type->id == ZigTypeIdArray) {
1985819922 len_mask = mask->value->type->data.array.len;
1985919923 } else {
19860 ir_add_error(ira, &mask->base,
19924 ir_add_error(ira, mask,
1986119925 buf_sprintf("expected vector or array, found '%s'",
1986219926 buf_ptr(&mask->value->type->name)));
1986319927 return ira->codegen->invalid_inst_gen;
......@@ -19875,7 +19939,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1987519939 } else if (a->value->type->id == ZigTypeIdUndefined) {
1987619940 len_a = UINT32_MAX;
1987719941 } else {
19878 ir_add_error(ira, &a->base,
19942 ir_add_error(ira, a,
1987919943 buf_sprintf("expected vector or array with element type '%s', found '%s'",
1988019944 buf_ptr(&scalar_type->name),
1988119945 buf_ptr(&a->value->type->name)));
......@@ -19890,7 +19954,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1989019954 } else if (b->value->type->id == ZigTypeIdUndefined) {
1989119955 len_b = UINT32_MAX;
1989219956 } else {
19893 ir_add_error(ira, &b->base,
19957 ir_add_error(ira, b,
1989419958 buf_sprintf("expected vector or array with element type '%s', found '%s'",
1989519959 buf_ptr(&scalar_type->name),
1989619960 buf_ptr(&b->value->type->name)));
......@@ -19898,12 +19962,12 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1989819962 }
1989919963
1990019964 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {
19901 return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type));
19965 return ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_mask, scalar_type));
1990219966 }
1990319967
1990419968 if (len_a == UINT32_MAX) {
1990519969 len_a = len_b;
19906 a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type));
19970 a = ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_a, scalar_type));
1990719971 } else {
1990819972 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
1990919973 if (type_is_invalid(a->value->type))
......@@ -19912,7 +19976,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1991219976
1991319977 if (len_b == UINT32_MAX) {
1991419978 len_b = len_a;
19915 b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type));
19979 b = ir_const_undef(ira, b->scope, b->source_node, get_vector_type(ira->codegen, len_b, scalar_type));
1991619980 } else {
1991719981 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
1991819982 if (type_is_invalid(b->value->type))
......@@ -19940,13 +20004,13 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1994020004 chosen_operand = b;
1994120005 }
1994220006 if (v >= chosen_operand->value->type->data.vector.len) {
19943 ErrorMsg *msg = ir_add_error(ira, &mask->base,
20007 ErrorMsg *msg = ir_add_error(ira, mask,
1994420008 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
19945 add_error_note(ira->codegen, msg, chosen_operand->base.source_node,
20009 add_error_note(ira->codegen, msg, chosen_operand->source_node,
1994620010 buf_sprintf("selected index '%u' out of bounds of %s", v,
1994720011 buf_ptr(&chosen_operand->value->type->name)));
1994820012 if (chosen_operand == a && v < len_a + len_b) {
19949 add_error_note(ira->codegen, msg, b->base.source_node,
20013 add_error_note(ira->codegen, msg, b->source_node,
1995020014 buf_create_from_str("selections from the second vector are specified with negative numbers"));
1995120015 }
1995220016 return ira->codegen->invalid_inst_gen;
......@@ -19966,7 +20030,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1996620030 expand_undef_array(ira->codegen, a_val);
1996720031 expand_undef_array(ira->codegen, b_val);
1996820032
19969 IrInstGen *result = ir_const(ira, source_instr, result_type);
20033 IrInstGen *result = ir_const(ira, scope, source_node, result_type);
1997020034 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask);
1997120035 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
1997220036 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
......@@ -19982,7 +20046,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1998220046 &b->value->data.x_array.data.s_none.elements[~v];
1998320047 copy_const_val(ira->codegen, result_elem_val, src_elem_val);
1998420048
19985 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
20049 src_assert(result_elem_val->special == ConstValSpecialStatic, source_node);
1998620050 }
1998720051 result->value->special = ConstValSpecialStatic;
1998820052 return result;
......@@ -19998,7 +20062,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1999820062 uint32_t len_min = min(len_a, len_b);
1999920063 uint32_t len_max = max(len_a, len_b);
2000020064
20001 IrInstGen *expand_mask = ir_const(ira, &mask->base,
20065 IrInstGen *expand_mask = ir_const(ira, mask->scope, mask->source_node,
2000220066 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
2000320067 expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max);
2000420068 uint32_t i = 0;
......@@ -20007,17 +20071,17 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2000720071 for (; i < len_max; i += 1)
2000820072 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2000920073
20010 IrInstGen *undef = ir_const_undef(ira, source_instr,
20074 IrInstGen *undef = ir_const_undef(ira, scope, source_node,
2001120075 get_vector_type(ira->codegen, len_min, scalar_type));
2001220076
2001320077 if (len_b < len_a) {
20014 b = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, b, undef, expand_mask);
20078 b = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, b, undef, expand_mask);
2001520079 } else {
20016 a = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, a, undef, expand_mask);
20080 a = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, a, undef, expand_mask);
2001720081 }
2001820082 }
2001920083
20020 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,
20084 return ir_build_shuffle_vector_gen(ira, scope, source_node,
2002120085 result_type, a, b, mask);
2002220086}
2002320087
......@@ -20038,7 +20102,7 @@ static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSr
2003820102 if (type_is_invalid(mask->value->type))
2003920103 return ira->codegen->invalid_inst_gen;
2004020104
20041 return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask);
20105 return ir_analyze_shuffle_vector(ira, instruction->base.scope, instruction->base.source_node, scalar_type, a, b, mask);
2004220106}
2004320107
2004420108static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
......@@ -20057,7 +20121,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
2005720121 return ira->codegen->invalid_inst_gen;
2005820122 uint32_t len_int = len_u64;
2005920123
20060 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))
20124 if ((err = ir_validate_vector_elem_type(ira, scalar->source_node, scalar->value->type)))
2006120125 return ira->codegen->invalid_inst_gen;
2006220126
2006320127 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
......@@ -20067,9 +20131,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
2006720131 if (scalar_val == nullptr)
2006820132 return ira->codegen->invalid_inst_gen;
2006920133 if (scalar_val->special == ConstValSpecialUndef)
20070 return ir_const_undef(ira, &instruction->base.base, return_type);
20134 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, return_type);
2007120135
20072 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
20136 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
2007320137 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int);
2007420138 for (uint32_t i = 0; i < len_int; i += 1) {
2007520139 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val);
......@@ -20077,7 +20141,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
2007720141 return result;
2007820142 }
2007920143
20080 return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar);
20144 return ir_build_splat_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, scalar);
2008120145}
2008220146
2008320147static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
......@@ -20096,10 +20160,10 @@ static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolN
2009620160 if (value == nullptr)
2009720161 return ira->codegen->invalid_inst_gen;
2009820162
20099 return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool);
20163 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, !value->data.x_bool);
2010020164 }
2010120165
20102 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);
20166 return ir_build_bool_not_gen(ira, instruction->base.scope, instruction->base.source_node, casted_value);
2010320167}
2010420168
2010520169static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
......@@ -20206,7 +20270,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
2020620270 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2020720271 size_t end = start + count;
2020820272 if (end > bound_end) {
20209 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));
20273 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
2021020274 return ira->codegen->invalid_inst_gen;
2021120275 }
2021220276
......@@ -20214,11 +20278,11 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
2021420278 copy_const_val(ira->codegen, &dest_elements[i], byte_val);
2021520279 }
2021620280
20217 return ir_const_void(ira, &instruction->base.base);
20281 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2021820282 }
2021920283 }
2022020284
20221 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);
20285 return ir_build_memset_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_byte, casted_count);
2022220286}
2022320287
2022420288static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
......@@ -20338,7 +20402,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
2033820402 }
2033920403
2034020404 if (dest_start + count > dest_end) {
20341 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
20405 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access"));
2034220406 return ira->codegen->invalid_inst_gen;
2034320407 }
2034420408
......@@ -20382,7 +20446,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
2038220446 }
2038320447
2038420448 if (src_start + count > src_end) {
20385 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
20449 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access"));
2038620450 return ira->codegen->invalid_inst_gen;
2038720451 }
2038820452
......@@ -20392,11 +20456,11 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
2039220456 copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]);
2039320457 }
2039420458
20395 return ir_const_void(ira, &instruction->base.base);
20459 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2039620460 }
2039720461 }
2039820462
20399 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);
20463 return ir_build_memcpy_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_src_ptr, casted_count);
2040020464}
2040120465
2040220466static ZigType *get_result_loc_type(IrAnalyze *ira, ResultLoc *result_loc) {
......@@ -20465,7 +20529,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2046520529 PtrLenUnknown,
2046620530 array_type->data.pointer.explicit_alignment, 0, 0, false);
2046720531 } else {
20468 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));
20532 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of single-item pointer"));
2046920533 return ira->codegen->invalid_inst_gen;
2047020534 }
2047120535 } else {
......@@ -20484,7 +20548,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2048420548 ZigType *maybe_sentineled_slice_ptr_type = array_type;
2048520549 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2048620550 if (!end) {
20487 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));
20551 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of pointer must include end value"));
2048820552 return ira->codegen->invalid_inst_gen;
2048920553 }
2049020554 }
......@@ -20494,7 +20558,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2049420558 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2049520559 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
2049620560 } else {
20497 ir_add_error(ira, &instruction->base.base,
20561 ir_add_error_node(ira, instruction->base.source_node,
2049820562 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
2049920563 return ira->codegen->invalid_inst_gen;
2050020564 }
......@@ -20549,7 +20613,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2054920613 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
2055020614
2055120615 if (start_scalar > end_scalar) {
20552 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
20616 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
2055320617 return ira->codegen->invalid_inst_gen;
2055420618 }
2055520619
......@@ -20592,7 +20656,7 @@ done_with_return_type:
2059220656 bool ptr_is_undef = false;
2059320657 if (child_array_type->id == ZigTypeIdArray) {
2059420658 if (array_type->id == ZigTypeIdPointer) {
20595 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
20659 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
2059620660 if (parent_ptr == nullptr)
2059720661 return ira->codegen->invalid_inst_gen;
2059820662
......@@ -20606,7 +20670,7 @@ done_with_return_type:
2060620670 abs_offset = 0;
2060720671 rel_end = SIZE_MAX;
2060820672 } else {
20609 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node);
20673 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
2061020674 if (array_val == nullptr)
2061120675 return ira->codegen->invalid_inst_gen;
2061220676
......@@ -20614,7 +20678,7 @@ done_with_return_type:
2061420678 abs_offset = 0;
2061520679 }
2061620680 } else {
20617 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
20681 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
2061820682 if (array_val == nullptr)
2061920683 return ira->codegen->invalid_inst_gen;
2062020684 rel_end = array_type->data.array.len;
......@@ -20623,7 +20687,7 @@ done_with_return_type:
2062320687 }
2062420688 } else if (array_type->id == ZigTypeIdPointer) {
2062520689 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
20626 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
20690 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
2062720691 if (parent_ptr == nullptr)
2062820692 return ira->codegen->invalid_inst_gen;
2062920693
......@@ -20672,18 +20736,18 @@ done_with_return_type:
2067220736 zig_panic("TODO slice of null ptr");
2067320737 }
2067420738 } else if (is_slice(array_type)) {
20675 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
20739 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
2067620740 if (slice_ptr == nullptr)
2067720741 return ira->codegen->invalid_inst_gen;
2067820742
2067920743 if (slice_ptr->special == ConstValSpecialUndef) {
20680 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
20744 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined"));
2068120745 return ira->codegen->invalid_inst_gen;
2068220746 }
2068320747
2068420748 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
2068520749 if (parent_ptr->special == ConstValSpecialUndef) {
20686 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
20750 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined"));
2068720751 return ira->codegen->invalid_inst_gen;
2068820752 }
2068920753
......@@ -20732,7 +20796,7 @@ done_with_return_type:
2073220796
2073320797 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
2073420798 if (!ptr_is_undef && start_scalar > rel_end) {
20735 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
20799 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
2073620800 return ira->codegen->invalid_inst_gen;
2073720801 }
2073820802
......@@ -20745,16 +20809,16 @@ done_with_return_type:
2074520809 }
2074620810 if (!ptr_is_undef) {
2074720811 if (end_scalar > rel_end) {
20748 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
20812 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
2074920813 return ira->codegen->invalid_inst_gen;
2075020814 }
2075120815 if (start_scalar > end_scalar) {
20752 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));
20816 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice start is greater than end"));
2075320817 return ira->codegen->invalid_inst_gen;
2075420818 }
2075520819 }
2075620820 if (ptr_is_undef && start_scalar != end_scalar) {
20757 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));
20821 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("non-zero length slice of undefined pointer"));
2075820822 return ira->codegen->invalid_inst_gen;
2075920823 }
2076020824
......@@ -20773,7 +20837,7 @@ done_with_return_type:
2077320837 }
2077420838
2077520839 // prepare check parameters
20776 ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
20840 ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
2077720841 if (target == nullptr)
2077820842 return ira->codegen->invalid_inst_gen;
2077920843
......@@ -20790,7 +20854,7 @@ done_with_return_type:
2079020854 break;
2079120855 } else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {
2079220856 // handle `*[N]T`
20793 target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.base.source_node);
20857 target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.source_node);
2079420858 if (target == nullptr)
2079520859 return ira->codegen->invalid_inst_gen;
2079620860 assert(target->type->id == ZigTypeIdArray);
......@@ -20841,23 +20905,23 @@ done_with_return_type:
2084120905 // perform check
2084220906 if (target_sentinel == nullptr) {
2084320907 if (end_scalar >= target_len) {
20844 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel is out of bounds"));
20908 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel is out of bounds"));
2084520909 return ira->codegen->invalid_inst_gen;
2084620910 }
2084720911 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {
20848 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index"));
20912 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index"));
2084920913 return ira->codegen->invalid_inst_gen;
2085020914 }
2085120915 } else {
2085220916 assert(end_scalar <= target_len);
2085320917 if (end_scalar == target_len) {
2085420918 if (!const_values_equal(ira->codegen, sentinel_val, target_sentinel)) {
20855 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match target-sentinel"));
20919 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match target-sentinel"));
2085620920 return ira->codegen->invalid_inst_gen;
2085720921 }
2085820922 } else {
2085920923 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {
20860 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index"));
20924 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index"));
2086120925 return ira->codegen->invalid_inst_gen;
2086220926 }
2086320927 }
......@@ -20865,7 +20929,7 @@ done_with_return_type:
2086520929 }
2086620930 exit_check_sentinel:
2086720931
20868 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
20932 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
2086920933
2087020934 ZigValue *ptr_val;
2087120935 if (return_type->id == ZigTypeIdPointer) {
......@@ -20936,40 +21000,42 @@ done_with_return_type:
2093621000 }
2093721001
2093821002 if (generate_non_null_assert) {
20939 IrInstGen *ptr_val = ir_get_deref(ira, &instruction->base.base, ptr_ptr, nullptr);
21003 IrInstGen *ptr_val = ir_get_deref(ira, instruction->base.scope,
21004 instruction->base.source_node, ptr_ptr, nullptr);
2094021005
2094121006 if (type_is_invalid(ptr_val->value->type))
2094221007 return ira->codegen->invalid_inst_gen;
2094321008
20944 ir_build_assert_non_null(ira, &instruction->base.base, ptr_val);
21009 ir_build_assert_non_null(ira, instruction->base.scope, instruction->base.source_node, ptr_val);
2094521010 }
2094621011
2094721012 IrInstGen *result_loc = nullptr;
2094821013
2094921014 if (return_type->id != ZigTypeIdPointer) {
20950 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
21015 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2095121016 return_type, nullptr, true, true);
2095221017 if (result_loc != nullptr) {
2095321018 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2095421019 return result_loc;
2095521020 }
2095621021
20957 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
21022 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
2095821023 if (result_loc->value->type->data.pointer.is_const) {
20959 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
21024 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
2096021025 return ira->codegen->invalid_inst_gen;
2096121026 }
2096221027
20963 IrInstGen *dummy_value = ir_const(ira, &instruction->base.base, return_type);
21028 IrInstGen *dummy_value = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
2096421029 dummy_value->value->special = ConstValSpecialRuntime;
20965 IrInstGen *dummy_result = ir_implicit_cast2(ira, &instruction->base.base,
21030 IrInstGen *dummy_result = ir_implicit_cast2(ira,
21031 instruction->base.scope, instruction->base.source_node,
2096621032 dummy_value, result_loc->value->type->data.pointer.child_type);
2096721033 if (type_is_invalid(dummy_result->value->type))
2096821034 return ira->codegen->invalid_inst_gen;
2096921035 }
2097021036 }
2097121037
20972 return ir_build_slice_gen(ira, &instruction->base.base, return_type, ptr_ptr,
21038 return ir_build_slice_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, ptr_ptr,
2097321039 casted_start, end, instruction->safety_check_on, result_loc, sentinel_val);
2097421040}
2097521041
......@@ -20994,17 +21060,17 @@ static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasF
2099421060 } else if (container_type->id == ZigTypeIdUnion) {
2099521061 result = find_union_type_field(container_type, field_name) != nullptr;
2099621062 } else {
20997 ir_add_error(ira, &instruction->container_type->base,
21063 ir_add_error_node(ira, instruction->container_type->source_node,
2099821064 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));
2099921065 return ira->codegen->invalid_inst_gen;
2100021066 }
21001 return ir_const_bool(ira, &instruction->base.base, result);
21067 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result);
2100221068}
2100321069
2100421070static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInstSrcWasmMemorySize *instruction) {
2100521071 // TODO generate compile error for target_arch different than 32bit
2100621072 if (!target_is_wasm(ira->codegen->zig_target)) {
21007 ir_add_error_node(ira, instruction->base.base.source_node,
21073 ir_add_error_node(ira, instruction->base.source_node,
2100821074 buf_sprintf("@wasmMemorySize is a wasm32 feature only"));
2100921075 return ira->codegen->invalid_inst_gen;
2101021076 }
......@@ -21019,13 +21085,13 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInst
2101921085 if (type_is_invalid(casted_index->value->type))
2102021086 return ira->codegen->invalid_inst_gen;
2102121087
21022 return ir_build_wasm_memory_size_gen(ira, &instruction->base.base, casted_index);
21088 return ir_build_wasm_memory_size_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index);
2102321089}
2102421090
2102521091static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInstSrcWasmMemoryGrow *instruction) {
2102621092 // TODO generate compile error for target_arch different than 32bit
2102721093 if (!target_is_wasm(ira->codegen->zig_target)) {
21028 ir_add_error_node(ira, instruction->base.base.source_node,
21094 ir_add_error_node(ira, instruction->base.source_node,
2102921095 buf_sprintf("@wasmMemoryGrow is a wasm32 feature only"));
2103021096 return ira->codegen->invalid_inst_gen;
2103121097 }
......@@ -21048,33 +21114,33 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInst
2104821114 if (type_is_invalid(casted_delta->value->type))
2104921115 return ira->codegen->invalid_inst_gen;
2105021116
21051 return ir_build_wasm_memory_grow_gen(ira, &instruction->base.base, casted_index, casted_delta);
21117 return ir_build_wasm_memory_grow_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index, casted_delta);
2105221118}
2105321119
2105421120static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
21055 return ir_build_breakpoint_gen(ira, &instruction->base.base);
21121 return ir_build_breakpoint_gen(ira, instruction->base.scope, instruction->base.source_node);
2105621122}
2105721123
2105821124static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
21059 return ir_build_return_address_gen(ira, &instruction->base.base);
21125 return ir_build_return_address_gen(ira, instruction->base.scope, instruction->base.source_node);
2106021126}
2106121127
2106221128static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
21063 return ir_build_frame_address_gen(ira, &instruction->base.base);
21129 return ir_build_frame_address_gen(ira, instruction->base.scope, instruction->base.source_node);
2106421130}
2106521131
2106621132static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
2106721133 ZigFn *fn = ira->fn;
21068 ir_assert(fn != nullptr, &instruction->base.base);
21134 src_assert(fn != nullptr, instruction->base.source_node);
2106921135
2107021136 if (fn->inferred_async_node == nullptr) {
21071 fn->inferred_async_node = instruction->base.base.source_node;
21137 fn->inferred_async_node = instruction->base.source_node;
2107221138 }
2107321139
2107421140 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
2107521141 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2107621142
21077 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);
21143 return ir_build_handle_gen(ira, instruction->base.scope, instruction->base.source_node, ptr_frame_type);
2107821144}
2107921145
2108021146static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
......@@ -21083,13 +21149,13 @@ static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFra
2108321149 return ira->codegen->invalid_inst_gen;
2108421150
2108521151 if (fn->type_entry->data.fn.is_generic) {
21086 ir_add_error(ira, &instruction->base.base,
21152 ir_add_error_node(ira, instruction->base.source_node,
2108721153 buf_sprintf("@Frame() of generic function"));
2108821154 return ira->codegen->invalid_inst_gen;
2108921155 }
2109021156
2109121157 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
21092 return ir_const_type(ira, &instruction->base.base, ty);
21158 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ty);
2109321159}
2109421160
2109521161static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
......@@ -21098,14 +21164,14 @@ static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFra
2109821164 return ira->codegen->invalid_inst_gen;
2109921165
2110021166 if (fn->value->type->id != ZigTypeIdFn) {
21101 ir_add_error(ira, &fn->base,
21167 ir_add_error(ira, fn,
2110221168 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
2110321169 return ira->codegen->invalid_inst_gen;
2110421170 }
2110521171
2110621172 ira->codegen->need_frame_size_prefix_data = true;
2110721173
21108 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);
21174 return ir_build_frame_size_gen(ira, instruction->base.scope, instruction->base.source_node, fn);
2110921175}
2111021176
2111121177static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
......@@ -21114,7 +21180,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign
2111421180 // const Node = struct {
2111521181 // field: []align(@alignOf(Node)) Node,
2111621182 // };
21117 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
21183 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
2111821184 result->value->special = ConstValSpecialLazy;
2111921185
2112021186 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();
......@@ -21141,7 +21207,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2114121207 return ira->codegen->invalid_inst_gen;
2114221208
2114321209 if (dest_type->id != ZigTypeIdInt) {
21144 ir_add_error(ira, &type_value->base,
21210 ir_add_error(ira, type_value,
2114521211 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
2114621212 return ira->codegen->invalid_inst_gen;
2114721213 }
......@@ -21192,7 +21258,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2119221258
2119321259 // Don't write anything to the result pointer.
2119421260 if (dest_type->data.integral.bit_count == 0)
21195 return ir_const_bool(ira, &instruction->base.base, false);
21261 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2119621262
2119721263 if (instr_is_comptime(casted_op1) &&
2119821264 instr_is_comptime(casted_op2) &&
......@@ -21213,7 +21279,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2121321279 BigInt *op1_bigint = &op1_val->data.x_bigint;
2121421280 BigInt *op2_bigint = &op2_val->data.x_bigint;
2121521281 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
21216 casted_result_ptr->base.source_node);
21282 casted_result_ptr->source_node);
2121721283 if (pointee_val == nullptr)
2121821284 return ira->codegen->invalid_inst_gen;
2121921285 BigInt *dest_bigint = &pointee_val->data.x_bigint;
......@@ -21242,14 +21308,14 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2124221308 dest_type->data.integral.is_signed);
2124321309 }
2124421310 pointee_val->special = ConstValSpecialStatic;
21245 return ir_const_bool(ira, &instruction->base.base, result_bool);
21311 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result_bool);
2124621312 }
2124721313
21248 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,
21314 return ir_build_overflow_op_gen(ira, instruction->base.scope, instruction->base.source_node, instruction->op,
2124921315 casted_op1, casted_op2, casted_result_ptr, dest_type);
2125021316}
2125121317
21252static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type,
21318static void ir_eval_mul_add(IrAnalyze *ira, ZigType *float_type,
2125321319 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
2125421320 if (float_type->id == ZigTypeIdComptimeFloat) {
2125521321 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
......@@ -21288,7 +21354,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
2128821354 // Only allow float types, and vectors of floats.
2128921355 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
2129021356 if (float_type->id != ZigTypeIdFloat) {
21291 ir_add_error(ira, &type_value->base,
21357 ir_add_error(ira, type_value,
2129221358 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));
2129321359 return ira->codegen->invalid_inst_gen;
2129421360 }
......@@ -21330,7 +21396,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
2133021396 if (!op3_const)
2133121397 return ira->codegen->invalid_inst_gen;
2133221398
21333 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
21399 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
2133421400 ZigValue *out_val = result->value;
2133521401
2133621402 if (expr_type->id == ZigTypeIdVector) {
......@@ -21349,19 +21415,19 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
2134921415 assert(float_operand_op2->type == float_type);
2135021416 assert(float_operand_op3->type == float_type);
2135121417 assert(float_out_val->type == float_type);
21352 ir_eval_mul_add(ira, instruction, float_type,
21418 ir_eval_mul_add(ira, float_type,
2135321419 op1_const, op2_const, op3_const, float_out_val);
2135421420 float_out_val->type = float_type;
2135521421 }
2135621422 out_val->type = expr_type;
2135721423 out_val->special = ConstValSpecialStatic;
2135821424 } else {
21359 ir_eval_mul_add(ira, instruction, float_type, op1_const, op2_const, op3_const, out_val);
21425 ir_eval_mul_add(ira, float_type, op1_const, op2_const, op3_const, out_val);
2136021426 }
2136121427 return result;
2136221428 }
2136321429
21364 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);
21430 return ir_build_mul_add_gen(ira, instruction->base.scope, instruction->base.source_node, casted_op1, casted_op2, casted_op3, expr_type);
2136521431}
2136621432
2136721433static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
......@@ -21373,7 +21439,8 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE
2137321439 if (instruction->base_ptr_is_payload) {
2137421440 value = base_ptr;
2137521441 } else {
21376 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);
21442 value = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
21443 base_ptr, nullptr);
2137721444 }
2137821445
2137921446 ZigType *type_entry = value->value->type;
......@@ -21387,32 +21454,32 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE
2138721454
2138821455 if (err_union_val->special != ConstValSpecialRuntime) {
2138921456 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
21390 return ir_const_bool(ira, &instruction->base.base, (err != nullptr));
21457 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, (err != nullptr));
2139121458 }
2139221459 }
2139321460
2139421461 if (instruction->resolve_err_set) {
2139521462 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
21396 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {
21463 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
2139721464 return ira->codegen->invalid_inst_gen;
2139821465 }
2139921466 if (!type_is_global_error_set(err_set_type) &&
2140021467 err_set_type->data.error_set.err_count == 0)
2140121468 {
2140221469 assert(!err_set_type->data.error_set.incomplete);
21403 return ir_const_bool(ira, &instruction->base.base, false);
21470 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2140421471 }
2140521472 }
2140621473
21407 return ir_build_test_err_gen(ira, &instruction->base.base, value);
21474 return ir_build_test_err_gen(ira, instruction->base.scope, instruction->base.source_node, value);
2140821475 } else if (type_entry->id == ZigTypeIdErrorSet) {
21409 return ir_const_bool(ira, &instruction->base.base, true);
21476 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true);
2141021477 } else {
21411 return ir_const_bool(ira, &instruction->base.base, false);
21478 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2141221479 }
2141321480}
2141421481
21415static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
21482static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2141621483 IrInstGen *base_ptr, bool initializing)
2141721484{
2141821485 ZigType *ptr_type = base_ptr->value->type;
......@@ -21425,7 +21492,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2142521492 return ira->codegen->invalid_inst_gen;
2142621493
2142721494 if (type_entry->id != ZigTypeIdErrorUnion) {
21428 ir_add_error(ira, &base_ptr->base,
21495 ir_add_error(ira, base_ptr,
2142921496 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
2143021497 return ira->codegen->invalid_inst_gen;
2143121498 }
......@@ -21442,7 +21509,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2144221509 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2144321510 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
2144421511 {
21445 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
21512 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
2144621513 if (err_union_val == nullptr)
2144721514 return ira->codegen->invalid_inst_gen;
2144821515
......@@ -21465,15 +21532,15 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2146521532 err_union_val->data.x_err_union.error_set = err_set_val;
2146621533 err_union_val->data.x_err_union.payload = payload_val;
2146721534 }
21468 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);
21535 src_assert(err_union_val->special != ConstValSpecialRuntime, source_node);
2146921536
2147021537 IrInstGen *result;
2147121538 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21472 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,
21473 source_instr->source_node, base_ptr, result_type);
21539 result = ir_build_unwrap_err_code_gen(ira, scope,
21540 source_node, base_ptr, result_type);
2147421541 result->value->special = ConstValSpecialStatic;
2147521542 } else {
21476 result = ir_const(ira, source_instr, result_type);
21543 result = ir_const(ira, scope, source_node, result_type);
2147721544 }
2147821545 ZigValue *const_val = result->value;
2147921546 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;
......@@ -21483,17 +21550,17 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2148321550 }
2148421551 }
2148521552
21486 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);
21553 return ir_build_unwrap_err_code_gen(ira, scope, source_node, base_ptr, result_type);
2148721554}
2148821555
2148921556static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
2149021557 IrInstGen *base_ptr = instruction->err_union_ptr->child;
2149121558 if (type_is_invalid(base_ptr->value->type))
2149221559 return ira->codegen->invalid_inst_gen;
21493 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);
21560 return ir_analyze_unwrap_err_code(ira, instruction->base.scope, instruction->base.source_node, base_ptr, false);
2149421561}
2149521562
21496static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
21563static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2149721564 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
2149821565{
2149921566 ZigType *ptr_type = base_ptr->value->type;
......@@ -21506,7 +21573,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2150621573 return ira->codegen->invalid_inst_gen;
2150721574
2150821575 if (type_entry->id != ZigTypeIdErrorUnion) {
21509 ir_add_error(ira, &base_ptr->base,
21576 ir_add_error(ira, base_ptr,
2151021577 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
2151121578 return ira->codegen->invalid_inst_gen;
2151221579 }
......@@ -21524,7 +21591,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2152421591 if (!ptr_val)
2152521592 return ira->codegen->invalid_inst_gen;
2152621593 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21527 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
21594 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
2152821595 if (err_union_val == nullptr)
2152921596 return ira->codegen->invalid_inst_gen;
2153021597 if (initializing && err_union_val->special == ConstValSpecialUndef) {
......@@ -21547,18 +21614,18 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2154721614 if (err_union_val->special != ConstValSpecialRuntime) {
2154821615 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
2154921616 if (err != nullptr) {
21550 ir_add_error(ira, source_instr,
21617 ir_add_error_node(ira, source_node,
2155121618 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
2155221619 return ira->codegen->invalid_inst_gen;
2155321620 }
2155421621
2155521622 IrInstGen *result;
2155621623 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21557 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,
21558 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);
21624 result = ir_build_unwrap_err_payload_gen(ira, scope,
21625 source_node, base_ptr, safety_check_on, initializing, result_type);
2155921626 result->value->special = ConstValSpecialStatic;
2156021627 } else {
21561 result = ir_const(ira, source_instr, result_type);
21628 result = ir_const(ira, scope, source_node, result_type);
2156221629 }
2156321630 result->value->data.x_ptr.special = ConstPtrSpecialRef;
2156421631 result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;
......@@ -21568,7 +21635,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2156821635 }
2156921636 }
2157021637
21571 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,
21638 return ir_build_unwrap_err_payload_gen(ira, scope, source_node,
2157221639 base_ptr, safety_check_on, initializing, result_type);
2157321640}
2157421641
......@@ -21580,14 +21647,14 @@ static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
2158021647 if (type_is_invalid(value->value->type))
2158121648 return ira->codegen->invalid_inst_gen;
2158221649
21583 return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false);
21650 return ir_analyze_unwrap_error_payload(ira, instruction->base.scope, instruction->base.source_node, value, instruction->safety_check_on, false);
2158421651}
2158521652
2158621653static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
21587 AstNode *proto_node = instruction->base.base.source_node;
21654 AstNode *proto_node = instruction->base.source_node;
2158821655 assert(proto_node->type == NodeTypeFnProto);
2158921656
21590 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
21657 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
2159121658 result->value->special = ConstValSpecialLazy;
2159221659
2159321660 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();
......@@ -21596,7 +21663,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2159621663 lazy_fn_type->base.id = LazyValueIdFnType;
2159721664
2159821665 if (proto_node->data.fn_proto.auto_err_set) {
21599 ir_add_error(ira, &instruction->base.base,
21666 ir_add_error_node(ira, instruction->base.source_node,
2160021667 buf_sprintf("inferring error set of return type valid only for function definitions"));
2160121668 return ira->codegen->invalid_inst_gen;
2160221669 }
......@@ -21631,7 +21698,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2163121698 if (cc == CallingConventionC) {
2163221699 break;
2163321700 } else {
21634 ir_add_error(ira, &instruction->base.base,
21701 ir_add_error_node(ira, instruction->base.source_node,
2163521702 buf_sprintf("var args only allowed in functions with C calling convention"));
2163621703 return ira->codegen->invalid_inst_gen;
2163721704 }
......@@ -21668,7 +21735,7 @@ static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrc
2166821735 if (type_is_invalid(value->value->type))
2166921736 return ira->codegen->invalid_inst_gen;
2167021737
21671 return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value));
21738 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, instr_is_comptime(value));
2167221739}
2167321740
2167421741static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
......@@ -21713,7 +21780,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2171321780 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2171421781
2171521782 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
21716 ir_add_error(ira, &start_value->base,
21783 ir_add_error(ira, start_value,
2171721784 buf_sprintf("range start value is greater than the end value"));
2171821785 }
2171921786
......@@ -21724,12 +21791,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2172421791 if (cmp == CmpGT) {
2172521792 break;
2172621793 }
21727 auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node);
21794 auto entry = field_prev_uses.put_unique(field_index, start_value->source_node);
2172821795 if (entry) {
2172921796 AstNode *prev_node = entry->value;
2173021797 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
2173121798 assert(enum_field != nullptr);
21732 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
21799 ErrorMsg *msg = ir_add_error(ira, start_value,
2173321800 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
2173421801 buf_ptr(enum_field->name)));
2173521802 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
......@@ -21739,10 +21806,10 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2173921806 }
2174021807 if (have_underscore_prong) {
2174121808 if (!switch_type->data.enumeration.non_exhaustive) {
21742 ir_add_error(ira, &instruction->base.base,
21809 ir_add_error_node(ira, instruction->base.source_node,
2174321810 buf_sprintf("switch on exhaustive enum has `_` prong"));
2174421811 } else if (target_is_originally_union) {
21745 ir_add_error(ira, &instruction->base.base,
21812 ir_add_error_node(ira, instruction->base.source_node,
2174621813 buf_sprintf("`_` prong not allowed when switching on tagged union"));
2174721814 }
2174821815 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -21752,14 +21819,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2175221819
2175321820 auto entry = field_prev_uses.maybe_get(enum_field->value);
2175421821 if (!entry) {
21755 ir_add_error(ira, &instruction->base.base,
21822 ir_add_error_node(ira, instruction->base.source_node,
2175621823 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2175721824 buf_ptr(enum_field->name)));
2175821825 }
2175921826 }
2176021827 } else if (instruction->else_prong == nullptr) {
2176121828 if (switch_type->data.enumeration.non_exhaustive && !target_is_originally_union) {
21762 ir_add_error(ira, &instruction->base.base,
21829 ir_add_error_node(ira, instruction->base.source_node,
2176321830 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
2176421831 }
2176521832 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -21767,7 +21834,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2176721834
2176821835 auto entry = field_prev_uses.maybe_get(enum_field->value);
2176921836 if (!entry) {
21770 ir_add_error(ira, &instruction->base.base,
21837 ir_add_error_node(ira, instruction->base.source_node,
2177121838 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2177221839 buf_ptr(enum_field->name)));
2177321840 }
......@@ -21778,7 +21845,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2177821845 return ira->codegen->invalid_inst_gen;
2177921846 }
2178021847 } else if (switch_type->id == ZigTypeIdErrorSet) {
21781 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {
21848 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
2178221849 return ira->codegen->invalid_inst_gen;
2178321850 }
2178421851
......@@ -21802,29 +21869,29 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2180221869 if (type_is_invalid(end_value->value->type))
2180321870 return ira->codegen->invalid_inst_gen;
2180421871
21805 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
21872 src_assert(start_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node);
2180621873 uint32_t start_index = start_value->value->data.x_err_set->value;
2180721874
21808 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
21875 src_assert(end_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node);
2180921876 uint32_t end_index = end_value->value->data.x_err_set->value;
2181021877
2181121878 if (start_index != end_index) {
21812 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));
21879 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));
2181321880 return ira->codegen->invalid_inst_gen;
2181421881 }
2181521882
2181621883 AstNode *prev_node = field_prev_uses[start_index];
2181721884 if (prev_node != nullptr) {
2181821885 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
21819 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
21886 ErrorMsg *msg = ir_add_error(ira, start_value,
2182021887 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
2182121888 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
2182221889 }
21823 field_prev_uses[start_index] = start_value->base.source_node;
21890 field_prev_uses[start_index] = start_value->source_node;
2182421891 }
2182521892 if (instruction->else_prong == nullptr) {
2182621893 if (type_is_global_error_set(switch_type)) {
21827 ir_add_error(ira, &instruction->base.base,
21894 ir_add_error_node(ira, instruction->base.source_node,
2182821895 buf_sprintf("else prong required when switching on type 'anyerror'"));
2182921896 return ira->codegen->invalid_inst_gen;
2183021897 } else {
......@@ -21833,7 +21900,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2183321900
2183421901 AstNode *prev_node = field_prev_uses[err_entry->value];
2183521902 if (prev_node == nullptr) {
21836 ir_add_error(ira, &instruction->base.base,
21903 ir_add_error_node(ira, instruction->base.source_node,
2183721904 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
2183821905 }
2183921906 }
......@@ -21872,14 +21939,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2187221939 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2187321940
2187421941 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
21875 ir_add_error(ira, &start_value->base,
21942 ir_add_error(ira, start_value,
2187621943 buf_sprintf("range start value is greater than the end value"));
2187721944 }
2187821945
2187921946 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
21880 start_value->base.source_node);
21947 start_value->source_node);
2188121948 if (prev_node != nullptr) {
21882 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));
21949 ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value"));
2188321950 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here"));
2188421951 return ira->codegen->invalid_inst_gen;
2188521952 }
......@@ -21891,7 +21958,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2189121958 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
2189221959 bool handles_all_cases = rangeset_spans(&rs, &min_val, &max_val);
2189321960 if (!handles_all_cases && instruction->else_prong == nullptr) {
21894 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
21961 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities"));
2189521962 return ira->codegen->invalid_inst_gen;
2189621963 } else if(handles_all_cases && instruction->else_prong != nullptr) {
2189721964 ir_add_error_node(ira, instruction->else_prong,
......@@ -21923,12 +21990,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2192321990 }
2192421991
2192521992 if ((seenTrue > 1) || (seenFalse > 1)) {
21926 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
21993 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
2192721994 return ira->codegen->invalid_inst_gen;
2192821995 }
2192921996 }
2193021997 if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) {
21931 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
21998 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities"));
2193221999 return ira->codegen->invalid_inst_gen;
2193322000 }
2193422001
......@@ -21938,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2193822005 return ira->codegen->invalid_inst_gen;
2193922006 }
2194022007 } else if (instruction->else_prong == nullptr) {
21941 ir_add_error(ira, &instruction->base.base,
22008 ir_add_error_node(ira, instruction->base.source_node,
2194222009 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
2194322010 return ira->codegen->invalid_inst_gen;
2194422011 } else if(switch_type->id == ZigTypeIdMetaType) {
......@@ -21964,15 +22031,15 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2196422031
2196522032 auto entry = prevs.put_unique(const_expr_val->data.x_type, value);
2196622033 if(entry != nullptr) {
21967 ErrorMsg *msg = ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
21968 add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value here"));
22034 ErrorMsg *msg = ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
22035 add_error_note(ira->codegen, msg, entry->value->source_node, buf_sprintf("previous value here"));
2196922036 prevs.deinit();
2197022037 return ira->codegen->invalid_inst_gen;
2197122038 }
2197222039 }
2197322040 prevs.deinit();
2197422041 }
21975 return ir_const_void(ira, &instruction->base.base);
22042 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2197622043}
2197722044
2197822045static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
......@@ -21985,13 +22052,13 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
2198522052
2198622053 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {
2198722054 if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) {
21988 ir_add_error(ira, &instruction->base.base, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`"));
22055 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`"));
2198922056 }else{
21990 ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored"));
22057 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("expression value is ignored"));
2199122058 }
2199222059 }
2199322060
21994 return ir_const_void(ira, &instruction->base.base);
22061 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2199522062}
2199622063
2199722064static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
......@@ -21999,8 +22066,8 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i
2199922066 if (type_is_invalid(msg->value->type))
2200022067 return ir_unreach_error(ira);
2200122068
22002 if (ir_should_inline(ira->zir, instruction->base.base.scope)) {
22003 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));
22069 if (ir_should_inline(ira->zir, instruction->base.scope)) {
22070 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("encountered @panic at compile-time"));
2200422071 return ir_unreach_error(ira);
2200522072 }
2200622073
......@@ -22011,7 +22078,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i
2201122078 if (type_is_invalid(casted_msg->value->type))
2201222079 return ir_unreach_error(ira);
2201322080
22014 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);
22081 IrInstGen *new_instruction = ir_build_panic_gen(ira, instruction->base.scope, instruction->base.source_node, casted_msg);
2201522082 return ir_finish_anal(ira, new_instruction);
2201622083}
2201722084
......@@ -22032,7 +22099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2203222099 }
2203322100
2203422101 if (safety_check_on && !type_has_bits(ira->codegen, actual_ptr)) {
22035 ir_add_error(ira, &target->base,
22102 ir_add_error(ira, target,
2203622103 buf_sprintf("cannot adjust alignment of zero sized type '%s'", buf_ptr(&target_type->name)));
2203722104 return ira->codegen->invalid_inst_gen;
2203822105 }
......@@ -22050,7 +22117,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2205022117 if (align_bytes >= get_async_frame_align_bytes(ira->codegen)) {
2205122118 result_type = target_type;
2205222119 } else {
22053 ir_add_error(ira, &target->base, buf_sprintf("sub-aligned anyframe not allowed"));
22120 ir_add_error(ira, target, buf_sprintf("sub-aligned anyframe not allowed"));
2205422121 return ira->codegen->invalid_inst_gen;
2205522122 }
2205622123 } else if (target_type->id == ZigTypeIdOptional &&
......@@ -22077,7 +22144,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2207722144 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
2207822145 result_type = get_slice_type(ira->codegen, result_ptr_type);
2207922146 } else {
22080 ir_add_error(ira, &target->base,
22147 ir_add_error(ira, target,
2208122148 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
2208222149 return ira->codegen->invalid_inst_gen;
2208322150 }
......@@ -22090,28 +22157,28 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2209022157 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2209122158 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
2209222159 {
22093 ir_add_error(ira, &target->base,
22160 ir_add_error(ira, target,
2209422161 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
2209522162 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
2209622163 return ira->codegen->invalid_inst_gen;
2209722164 }
2209822165
22099 IrInstGen *result = ir_const(ira, &target->base, result_type);
22166 IrInstGen *result = ir_const(ira, target->scope, target->source_node, result_type);
2210022167 copy_const_val(ira->codegen, result->value, val);
2210122168 result->value->type = result_type;
2210222169 return result;
2210322170 }
2210422171
2210522172 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {
22106 return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type);
22173 return ir_build_align_cast_gen(ira, target->scope, target->source_node, target, result_type);
2210722174 } else {
22108 return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop);
22175 return ir_build_cast(ira, target->scope, target->source_node, result_type, target, CastOpNoop);
2210922176 }
2211022177}
2211122178
22112static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
22113 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on,
22114 bool keep_bigger_alignment)
22179static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22180 IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src,
22181 bool safety_check_on, bool keep_bigger_alignment)
2211522182{
2211622183 Error err;
2211722184
......@@ -22134,20 +22201,21 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2213422201
2213522202 ZigType *src_ptr_type = get_src_ptr_type(src_type);
2213622203 if (src_ptr_type == nullptr) {
22137 ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
22204 ir_add_error_node(ira, ptr_src,
22205 buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
2213822206 return ira->codegen->invalid_inst_gen;
2213922207 }
2214022208 }
2214122209
2214222210 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
2214322211 if (dest_ptr_type == nullptr) {
22144 ir_add_error(ira, dest_type_src,
22212 ir_add_error_node(ira, dest_type_src,
2214522213 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
2214622214 return ira->codegen->invalid_inst_gen;
2214722215 }
2214822216
2214922217 if (get_ptr_const(ira->codegen, src_type) && !get_ptr_const(ira->codegen, dest_type)) {
22150 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));
22218 ir_add_error_node(ira, source_node, buf_sprintf("cast discards const qualifier"));
2215122219 return ira->codegen->invalid_inst_gen;
2215222220 }
2215322221 uint32_t dest_align_bytes;
......@@ -22170,12 +22238,12 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2217022238 type_has_bits(ira->codegen, dest_type) &&
2217122239 !type_has_bits(ira->codegen, if_slice_ptr_type))
2217222240 {
22173 ErrorMsg *msg = ir_add_error(ira, source_instr,
22241 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2217422242 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
2217522243 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
22176 add_error_note(ira->codegen, msg, ptr_src->source_node,
22244 add_error_note(ira->codegen, msg, ptr_src,
2217722245 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
22178 add_error_note(ira->codegen, msg, dest_type_src->source_node,
22246 add_error_note(ira->codegen, msg, dest_type_src,
2217922247 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));
2218022248 return ira->codegen->invalid_inst_gen;
2218122249 }
......@@ -22183,9 +22251,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2218322251 // For slices, follow the `ptr` field.
2218422252 if (is_slice(src_type)) {
2218522253 TypeStructField *ptr_field = src_type->data.structure.fields[slice_ptr_index];
22186 IrInstGen *ptr_ref = ir_get_ref(ira, source_instr, ptr, true, false);
22187 IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, source_instr, ptr_field, ptr_ref, src_type, false);
22188 ptr = ir_get_deref(ira, source_instr, ptr_ptr, nullptr);
22254 IrInstGen *ptr_ref = ir_get_ref(ira, scope, source_node, ptr, true, false);
22255 IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, ptr_field, ptr_ref, src_type, false);
22256 ptr = ir_get_deref(ira, scope, source_node, ptr_ptr, nullptr);
2218922257 }
2219022258
2219122259 if (instr_is_comptime(ptr)) {
......@@ -22200,7 +22268,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2220022268 (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2220122269 val->data.x_ptr.data.hard_coded_addr.addr == 0);
2220222270 if (is_addr_zero && !dest_allows_addr_zero) {
22203 ir_add_error(ira, source_instr,
22271 ir_add_error_node(ira, source_node,
2220422272 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));
2220522273 return ira->codegen->invalid_inst_gen;
2220622274 }
......@@ -22208,9 +22276,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2220822276
2220922277 IrInstGen *result;
2221022278 if (val->data.x_ptr.mut == ConstPtrMutInfer) {
22211 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
22279 result = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on);
2221222280 } else {
22213 result = ir_const(ira, source_instr, dest_type);
22281 result = ir_const(ira, scope, source_node, dest_type);
2221422282 }
2221522283 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
2221622284 val->type->data.pointer.inferred_struct_field : nullptr;
......@@ -22243,15 +22311,15 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2224322311 }
2224422312
2224522313 if (src_align_bytes != 0 && dest_align_bytes > src_align_bytes) {
22246 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
22247 add_error_note(ira->codegen, msg, ptr_src->source_node,
22314 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment"));
22315 add_error_note(ira->codegen, msg, ptr_src,
2224822316 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
22249 add_error_note(ira->codegen, msg, dest_type_src->source_node,
22317 add_error_note(ira->codegen, msg, dest_type_src,
2225022318 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));
2225122319 return ira->codegen->invalid_inst_gen;
2225222320 }
2225322321
22254 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
22322 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on);
2225522323
2225622324 // Keep the bigger alignment, it can only help- unless the target is zero bits.
2225722325 IrInstGen *result;
......@@ -22277,8 +22345,9 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa
2227722345 return ira->codegen->invalid_inst_gen;
2227822346
2227922347 bool keep_bigger_alignment = true;
22280 return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base,
22281 dest_type, &dest_type_value->base, instruction->safety_check_on, keep_bigger_alignment);
22348 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node, ptr,
22349 instruction->ptr->source_node, dest_type, dest_type_value->source_node,
22350 instruction->safety_check_on, keep_bigger_alignment);
2228222351}
2228322352
2228422353static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {
......@@ -22622,19 +22691,19 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2262222691 zig_unreachable();
2262322692}
2262422693
22625static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
22694static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
2262622695 ZigType *dest_type)
2262722696{
2262822697 Error err;
2262922698
2263022699 ZigType *src_type = value->value->type;
22631 ir_assert(type_can_bit_cast(src_type), source_instr);
22632 ir_assert(type_can_bit_cast(dest_type), source_instr);
22700 src_assert(type_can_bit_cast(src_type), source_node);
22701 src_assert(type_can_bit_cast(dest_type), source_node);
2263322702
2263422703 if (dest_type->id == ZigTypeIdEnum) {
22635 ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node,
22704 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2263622705 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
22637 add_error_note(ira->codegen, msg, source_instr->source_node,
22706 add_error_note(ira->codegen, msg, source_node,
2263822707 buf_sprintf("use @intToEnum for type coercion"));
2263922708 return ira->codegen->invalid_inst_gen;
2264022709 }
......@@ -22651,7 +22720,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2265122720 const uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
2265222721 const uint64_t src_size_bytes = type_size(ira->codegen, src_type);
2265322722 if (dest_size_bytes != src_size_bytes) {
22654 ir_add_error(ira, source_instr,
22723 ir_add_error_node(ira, source_node,
2265522724 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
2265622725 buf_ptr(&dest_type->name), dest_size_bytes,
2265722726 buf_ptr(&src_type->name), src_size_bytes));
......@@ -22661,7 +22730,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2266122730 const uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
2266222731 const uint64_t src_size_bits = type_size_bits(ira->codegen, src_type);
2266322732 if (dest_size_bits != src_size_bits) {
22664 ir_add_error(ira, source_instr,
22733 ir_add_error_node(ira, source_node,
2266522734 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
2266622735 buf_ptr(&dest_type->name), dest_size_bits,
2266722736 buf_ptr(&src_type->name), src_size_bits));
......@@ -22673,10 +22742,10 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2267322742 if (!val)
2267422743 return ira->codegen->invalid_inst_gen;
2267522744
22676 IrInstGen *result = ir_const(ira, source_instr, dest_type);
22745 IrInstGen *result = ir_const(ira, scope, source_node, dest_type);
2267722746 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes);
2267822747 buf_write_value_bytes(ira->codegen, buf, val);
22679 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
22748 if ((err = buf_read_value_bytes(ira, ira->codegen, source_node, buf, result->value)))
2268022749 return ira->codegen->invalid_inst_gen;
2268122750 heap::c_allocator.deallocate(buf, src_size_bytes);
2268222751 return result;
......@@ -22684,19 +22753,19 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2268422753
2268522754 if (dest_is_ptr && !src_is_ptr) {
2268622755 // Spill the scalar into a local memory location and take its address
22687 value = ir_get_ref(ira, source_instr, value, false, false);
22756 value = ir_get_ref(ira, scope, source_node, value, false, false);
2268822757 }
2268922758
22690 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
22759 return ir_build_bit_cast_gen(ira, scope, source_node, value, dest_type);
2269122760}
2269222761
22693static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
22762static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
2269422763 ZigType *ptr_type)
2269522764{
2269622765 Error err;
2269722766
22698 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
22699 ir_assert(type_has_bits(ira->codegen, ptr_type), source_instr);
22767 src_assert(get_src_ptr_type(ptr_type) != nullptr, source_node);
22768 src_assert(type_has_bits(ira->codegen, ptr_type), source_node);
2270022769
2270122770 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
2270222771 if (type_is_invalid(casted_int->value->type))
......@@ -22709,7 +22778,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
2270922778
2271022779 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
2271122780 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
22712 ir_add_error(ira, source_instr,
22781 ir_add_error_node(ira, source_node,
2271322782 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
2271422783 return ira->codegen->invalid_inst_gen;
2271522784 }
......@@ -22719,13 +22788,13 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
2271922788 return ira->codegen->invalid_inst_gen;
2272022789
2272122790 if (addr != 0 && addr % align_bytes != 0) {
22722 ir_add_error(ira, source_instr,
22791 ir_add_error_node(ira, source_node,
2272322792 buf_sprintf("pointer type '%s' requires aligned address",
2272422793 buf_ptr(&ptr_type->name)));
2272522794 return ira->codegen->invalid_inst_gen;
2272622795 }
2272722796
22728 IrInstGen *result = ir_const(ira, source_instr, ptr_type);
22797 IrInstGen *result = ir_const(ira, scope, source_node, ptr_type);
2272922798 if (ptr_type->id == ZigTypeIdOptional && addr == 0) {
2273022799 result->value->data.x_ptr.special = ConstPtrSpecialNull;
2273122800 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
......@@ -22738,7 +22807,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
2273822807 return result;
2273922808 }
2274022809
22741 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);
22810 return ir_build_int_to_ptr_gen(ira, scope, source_node, casted_int, ptr_type);
2274222811}
2274322812
2274422813static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {
......@@ -22750,7 +22819,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
2275022819
2275122820 // We explicitly check for the size, so we can use get_src_ptr_type
2275222821 if (get_src_ptr_type(dest_type) == nullptr) {
22753 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
22822 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
2275422823 return ira->codegen->invalid_inst_gen;
2275522824 }
2275622825
......@@ -22759,7 +22828,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
2275922828 return ira->codegen->invalid_inst_gen;
2276022829
2276122830 if (!has_bits) {
22762 ir_add_error(ira, &dest_type_value->base,
22831 ir_add_error(ira, dest_type_value,
2276322832 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));
2276422833 return ira->codegen->invalid_inst_gen;
2276522834 }
......@@ -22768,11 +22837,11 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
2276822837 if (type_is_invalid(target->value->type))
2276922838 return ira->codegen->invalid_inst_gen;
2277022839
22771 return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type);
22840 return ir_analyze_int_to_ptr(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
2277222841}
2277322842
2277422843static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
22775 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);
22844 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, instruction->base.scope, instruction->base.source_node, instruction->tld);
2277622845 if (type_is_invalid(ref_instruction->value->type)) {
2277722846 return ira->codegen->invalid_inst_gen;
2277822847 }
......@@ -22780,7 +22849,7 @@ static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclR
2278022849 if (instruction->lval == LValPtr || instruction->lval == LValAssign) {
2278122850 return ref_instruction;
2278222851 } else {
22783 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);
22852 return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ref_instruction, nullptr);
2278422853 }
2278522854}
2278622855
......@@ -22794,7 +22863,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
2279422863
2279522864 ZigType *src_ptr_type = get_src_ptr_type(target->value->type);
2279622865 if (src_ptr_type == nullptr) {
22797 ir_add_error(ira, &target->base,
22866 ir_add_error(ira, target,
2279822867 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
2279922868 return ira->codegen->invalid_inst_gen;
2280022869 }
......@@ -22804,7 +22873,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
2280422873 return ira->codegen->invalid_inst_gen;
2280522874
2280622875 if (!has_bits) {
22807 ir_add_error(ira, &target->base,
22876 ir_add_error(ira, target,
2280822877 buf_sprintf("pointer to size 0 type has no address"));
2280922878 return ira->codegen->invalid_inst_gen;
2281022879 }
......@@ -22817,25 +22886,25 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
2281722886 // Since we've already run this type trough get_src_ptr_type it is
2281822887 // safe to access the x_ptr fields
2281922888 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
22820 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
22889 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize);
2282122890 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
2282222891 result->value->type = usize;
2282322892 return result;
2282422893 } else if (val->data.x_ptr.special == ConstPtrSpecialNull) {
22825 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
22894 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize);
2282622895 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2282722896 result->value->type = usize;
2282822897 return result;
2282922898 }
2283022899 }
2283122900
22832 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);
22901 return ir_build_ptr_to_int_gen(ira, instruction->base.scope, instruction->base.source_node, target);
2283322902}
2283422903
2283522904static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,
2283622905 IrInstSrcPtrTypeSimple *instruction, bool is_const)
2283722906{
22838 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
22907 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
2283922908 result->value->special = ConstValSpecialLazy;
2284022909
2284122910 LazyValuePtrTypeSimple *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrTypeSimple>();
......@@ -22851,7 +22920,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,
2285122920}
2285222921
2285322922static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
22854 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
22923 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
2285522924 result->value->special = ConstValSpecialLazy;
2285622925
2285722926 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();
......@@ -22861,7 +22930,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy
2286122930
2286222931 if (instruction->sentinel != nullptr) {
2286322932 if (instruction->ptr_len != PtrLenUnknown) {
22864 ir_add_error(ira, &instruction->base.base,
22933 ir_add_error_node(ira, instruction->base.source_node,
2286522934 buf_sprintf("sentinels are only allowed on unknown-length pointers"));
2286622935 return ira->codegen->invalid_inst_gen;
2286722936 }
......@@ -22923,36 +22992,36 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS
2292322992 return ira->codegen->invalid_inst_gen;
2292422993
2292522994 if (align_bytes > 256) {
22926 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
22995 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
2292722996 return ira->codegen->invalid_inst_gen;
2292822997 }
2292922998
2293022999 ZigFn *fn_entry = ira->fn;
2293123000 if (fn_entry == nullptr) {
22932 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));
23001 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack outside function"));
2293323002 return ira->codegen->invalid_inst_gen;
2293423003 }
2293523004 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {
22936 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));
23005 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in naked function"));
2293723006 return ira->codegen->invalid_inst_gen;
2293823007 }
2293923008
2294023009 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionInline) {
22941 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));
23010 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in inline function"));
2294223011 return ira->codegen->invalid_inst_gen;
2294323012 }
2294423013
2294523014 if (fn_entry->set_alignstack_node != nullptr) {
22946 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
23015 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
2294723016 buf_sprintf("alignstack set twice"));
2294823017 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));
2294923018 return ira->codegen->invalid_inst_gen;
2295023019 }
2295123020
22952 fn_entry->set_alignstack_node = instruction->base.base.source_node;
23021 fn_entry->set_alignstack_node = instruction->base.source_node;
2295323022 fn_entry->alignstack_value = align_bytes;
2295423023
22955 return ir_const_void(ira, &instruction->base.base);
23024 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2295623025}
2295723026
2295823027static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction,
......@@ -22973,7 +23042,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
2297323042 arg_index += 1;
2297423043 }
2297523044 if (fn_type->id != ZigTypeIdFn) {
22976 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
23045 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
2297723046 return ira->codegen->invalid_inst_gen;
2297823047 }
2297923048
......@@ -22981,9 +23050,9 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
2298123050 if (arg_index >= fn_type_id->param_count) {
2298223051 if (allow_var) {
2298323052 // TODO remove this with var args
22984 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
23053 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype);
2298523054 }
22986 ir_add_error(ira, &arg_index_inst->base,
23055 ir_add_error(ira, arg_index_inst,
2298723056 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)",
2298823057 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
2298923058 return ira->codegen->invalid_inst_gen;
......@@ -22992,18 +23061,18 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
2299223061 ZigType *result_type = fn_type_id->param_info[arg_index].type;
2299323062 if (result_type == nullptr) {
2299423063 // Args are only unresolved if our function is generic.
22995 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);
23064 src_assert(fn_type->data.fn.is_generic, instruction->base.source_node);
2299623065
2299723066 if (allow_var) {
22998 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
23067 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype);
2299923068 } else {
23000 ir_add_error(ira, &arg_index_inst->base,
23069 ir_add_error(ira, arg_index_inst,
2300123070 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
2300223071 arg_index, buf_ptr(&fn_type->name)));
2300323072 return ira->codegen->invalid_inst_gen;
2300423073 }
2300523074 }
23006 return ir_const_type(ira, &instruction->base.base, result_type);
23075 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type);
2300723076}
2300823077
2300923078static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
......@@ -23022,7 +23091,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2302223091 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2302323092
2302423093 if (bit_count > max_atomic_bits) {
23025 ir_add_error(ira, &op->base,
23094 ir_add_error(ira, op,
2302623095 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
2302723096 max_atomic_bits, bit_count));
2302823097 return ira->codegen->builtin_types.entry_invalid;
......@@ -23030,7 +23099,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2303023099 } else if (operand_type->id == ZigTypeIdFloat) {
2303123100 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2303223101 if (operand_type->data.floating.bit_count > max_atomic_bits) {
23033 ir_add_error(ira, &op->base,
23102 ir_add_error(ira, op,
2303423103 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
2303523104 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
2303623105 return ira->codegen->builtin_types.entry_invalid;
......@@ -23043,7 +23112,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2304323112 if ((err = get_codegen_ptr_type(ira->codegen, operand_type, &operand_ptr_type)))
2304423113 return ira->codegen->builtin_types.entry_invalid;
2304523114 if (operand_ptr_type == nullptr) {
23046 ir_add_error(ira, &op->base,
23115 ir_add_error(ira, op,
2304723116 buf_sprintf("expected bool, integer, float, enum or pointer type, found '%s'",
2304823117 buf_ptr(&operand_type->name)));
2304923118 return ira->codegen->builtin_types.entry_invalid;
......@@ -23074,15 +23143,15 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2307423143 }
2307523144
2307623145 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
23077 ir_add_error(ira, &instruction->op->base,
23146 ir_add_error_node(ira, instruction->op->source_node,
2307823147 buf_sprintf("@atomicRmw with enum only allowed with .Xchg"));
2307923148 return ira->codegen->invalid_inst_gen;
2308023149 } else if (operand_type->id == ZigTypeIdBool && op != AtomicRmwOp_xchg) {
23081 ir_add_error(ira, &instruction->op->base,
23150 ir_add_error_node(ira, instruction->op->source_node,
2308223151 buf_sprintf("@atomicRmw with bool only allowed with .Xchg"));
2308323152 return ira->codegen->invalid_inst_gen;
2308423153 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
23085 ir_add_error(ira, &instruction->op->base,
23154 ir_add_error_node(ira, instruction->op->source_node,
2308623155 buf_sprintf("@atomicRmw with float only allowed with .Xchg, .Add and .Sub"));
2308723156 return ira->codegen->invalid_inst_gen;
2308823157 }
......@@ -23099,7 +23168,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2309923168 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
2310023169 return ira->codegen->invalid_inst_gen;
2310123170 if (ordering == AtomicOrderUnordered) {
23102 ir_add_error(ira, &instruction->ordering->base,
23171 ir_add_error_node(ira, instruction->ordering->source_node,
2310323172 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
2310423173 return ira->codegen->invalid_inst_gen;
2310523174 }
......@@ -23109,18 +23178,19 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2310923178 case OnePossibleValueInvalid:
2311023179 return ira->codegen->invalid_inst_gen;
2311123180 case OnePossibleValueYes:
23112 return ir_const_move(ira, &instruction->base.base, get_the_one_possible_value(ira->codegen, operand_type));
23181 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, get_the_one_possible_value(ira->codegen, operand_type));
2311323182 case OnePossibleValueNo:
2311423183 break;
2311523184 }
2311623185
23117 IrInst *source_inst = &instruction->base.base;
23186 Scope *scope = instruction->base.scope;
23187 AstNode *source_node = instruction->base.source_node;
2311823188 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) {
2311923189 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
2312023190 if (ptr_val == nullptr)
2312123191 return ira->codegen->invalid_inst_gen;
2312223192
23123 ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node);
23193 ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
2312423194 if (op1_val == nullptr)
2312523195 return ira->codegen->invalid_inst_gen;
2312623196
......@@ -23128,7 +23198,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2312823198 if (op2_val == nullptr)
2312923199 return ira->codegen->invalid_inst_gen;
2313023200
23131 IrInstGen *result = ir_const(ira, source_inst, operand_type);
23201 IrInstGen *result = ir_const(ira, scope, source_node, operand_type);
2313223202 copy_const_val(ira->codegen, result->value, op1_val);
2313323203 if (op == AtomicRmwOp_xchg) {
2313423204 copy_const_val(ira->codegen, op1_val, op2_val);
......@@ -23136,7 +23206,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2313623206 }
2313723207
2313823208 if (operand_type->id == ZigTypeIdPointer || operand_type->id == ZigTypeIdOptional) {
23139 ir_add_error(ira, &instruction->ordering->base,
23209 ir_add_error_node(ira, instruction->ordering->source_node,
2314023210 buf_sprintf("TODO comptime @atomicRmw with pointers other than .Xchg"));
2314123211 return ira->codegen->invalid_inst_gen;
2314223212 }
......@@ -23151,8 +23221,8 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2315123221 // store op2 if op2 > op1
2315223222 bin_op = IrBinOpCmpLessThan;
2315323223
23154 IrInstGen *dummy_value = ir_const(ira, source_inst, operand_type);
23155 msg = ir_eval_bin_op_cmp_scalar(ira, source_inst, op1_val, bin_op, op2_val, dummy_value->value);
23224 IrInstGen *dummy_value = ir_const(ira, scope, source_node, operand_type);
23225 msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1_val, bin_op, op2_val, dummy_value->value);
2315623226 if (msg != nullptr) {
2315723227 return ira->codegen->invalid_inst_gen;
2315823228 }
......@@ -23188,7 +23258,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2318823258 bin_op = IrBinOpBinXor;
2318923259 break;
2319023260 }
23191 msg = ir_eval_math_op_scalar(ira, source_inst, operand_type, op1_val, bin_op, op2_val, op1_val);
23261 msg = ir_eval_math_op_scalar(ira, scope, source_node, operand_type, op1_val, bin_op, op2_val, op1_val);
2319223262 if (msg != nullptr) {
2319323263 return ira->codegen->invalid_inst_gen;
2319423264 }
......@@ -23200,7 +23270,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
2320023270 return result;
2320123271 }
2320223272
23203 return ir_build_atomic_rmw_gen(ira, source_inst, casted_ptr, casted_operand, op,
23273 return ir_build_atomic_rmw_gen(ira, scope, source_node, casted_ptr, casted_operand, op,
2320423274 ordering, operand_type);
2320523275}
2320623276
......@@ -23223,19 +23293,20 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt
2322323293 return ira->codegen->invalid_inst_gen;
2322423294
2322523295 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
23226 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
23227 ir_add_error(ira, &instruction->ordering->base,
23296 src_assert(instruction->ordering != nullptr, instruction->base.source_node);
23297 ir_add_error_node(ira, instruction->ordering->source_node,
2322823298 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
2322923299 return ira->codegen->invalid_inst_gen;
2323023300 }
2323123301
2323223302 if (instr_is_comptime(casted_ptr)) {
23233 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);
23234 ir_assert(result->value->type != nullptr, &instruction->base.base);
23303 IrInstGen *result = ir_get_deref(ira, instruction->base.scope,
23304 instruction->base.source_node, casted_ptr, nullptr);
23305 src_assert(result->value->type != nullptr, instruction->base.source_node);
2323523306 return result;
2323623307 }
2323723308
23238 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);
23309 return ir_build_atomic_load_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, ordering, operand_type);
2323923310}
2324023311
2324123312static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
......@@ -23266,8 +23337,8 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA
2326623337 return ira->codegen->invalid_inst_gen;
2326723338
2326823339 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
23269 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
23270 ir_add_error(ira, &instruction->ordering->base,
23340 src_assert(instruction->ordering != nullptr, instruction->base.source_node);
23341 ir_add_error_node(ira, instruction->ordering->source_node,
2327123342 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
2327223343 return ira->codegen->invalid_inst_gen;
2327323344 }
......@@ -23277,28 +23348,28 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA
2327723348 case OnePossibleValueInvalid:
2327823349 return ira->codegen->invalid_inst_gen;
2327923350 case OnePossibleValueYes:
23280 return ir_const_void(ira, &instruction->base.base);
23351 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2328123352 case OnePossibleValueNo:
2328223353 break;
2328323354 }
2328423355
2328523356 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
23286 IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false);
23357 IrInstGen *result = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, value, false);
2328723358 result->value->type = ira->codegen->builtin_types.entry_void;
2328823359 return result;
2328923360 }
2329023361
23291 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);
23362 return ir_build_atomic_store_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, casted_value, ordering);
2329223363}
2329323364
2329423365static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
23295 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);
23366 return ir_build_save_err_ret_addr_gen(ira, instruction->base.scope, instruction->base.source_node);
2329623367}
2329723368
23298static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type,
23369static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, Scope *scope, AstNode *source_node, BuiltinFnId fop, ZigType *float_type,
2329923370 ZigValue *op, ZigValue *out_val)
2330023371{
23301 assert(ira && source_instr && float_type && out_val && op);
23372 assert(ira && source_node && float_type && out_val && op);
2330223373 assert(float_type->id == ZigTypeIdFloat ||
2330323374 float_type->id == ZigTypeIdComptimeFloat);
2330423375
......@@ -23464,7 +23535,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF
2346423535 break;
2346523536 }
2346623537 case 80:
23467 return ir_add_error(ira, source_instr,
23538 return ir_add_error_node(ira, source_node,
2346823539 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",
2346923540 float_op_to_name(fop), buf_ptr(&float_type->name)));
2347023541 case 128: {
......@@ -23503,7 +23574,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF
2350323574 case BuiltinFnIdLog:
2350423575 case BuiltinFnIdLog10:
2350523576 case BuiltinFnIdLog2:
23506 return ir_add_error(ira, source_instr,
23577 return ir_add_error_node(ira, source_node,
2350723578 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",
2350823579 float_op_to_name(fop), buf_ptr(&float_type->name)));
2350923580 default:
......@@ -23529,7 +23600,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
2352923600 operand_type->data.vector.elem_type : operand_type;
2353023601
2353123602 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
23532 ir_add_error(ira, &operand->base,
23603 ir_add_error(ira, operand,
2353323604 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));
2353423605 return ira->codegen->invalid_inst_gen;
2353523606 }
......@@ -23539,9 +23610,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
2353923610 if (operand_val == nullptr)
2354023611 return ira->codegen->invalid_inst_gen;
2354123612 if (operand_val->special == ConstValSpecialUndef)
23542 return ir_const_undef(ira, &instruction->base.base, operand_type);
23613 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, operand_type);
2354323614
23544 IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type);
23615 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, operand_type);
2354523616 ZigValue *out_val = result->value;
2354623617
2354723618 if (operand_type->id == ZigTypeIdVector) {
......@@ -23552,12 +23623,12 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
2355223623 for (size_t i = 0; i < len; i += 1) {
2355323624 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
2355423625 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
23555 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);
23556 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);
23557 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
23626 src_assert(elem_operand->type == scalar_type, instruction->base.source_node);
23627 src_assert(float_out_val->type == scalar_type, instruction->base.source_node);
23628 ErrorMsg *msg = ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type,
2355823629 elem_operand, float_out_val);
2355923630 if (msg != nullptr) {
23560 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
23631 add_error_note(ira->codegen, msg, instruction->base.source_node,
2356123632 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
2356223633 return ira->codegen->invalid_inst_gen;
2356323634 }
......@@ -23566,7 +23637,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
2356623637 out_val->type = operand_type;
2356723638 out_val->special = ConstValSpecialStatic;
2356823639 } else {
23569 if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
23640 if (ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type,
2357023641 operand_val, out_val) != nullptr)
2357123642 {
2357223643 return ira->codegen->invalid_inst_gen;
......@@ -23575,9 +23646,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
2357523646 return result;
2357623647 }
2357723648
23578 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base);
23649 src_assert(scalar_type->id == ZigTypeIdFloat, instruction->base.source_node);
2357923650
23580 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);
23651 return ir_build_float_op_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->fn_id, operand_type);
2358123652}
2358223653
2358323654static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
......@@ -23617,7 +23688,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2361723688 return op;
2361823689
2361923690 if (int_type->data.integral.bit_count % 8 != 0) {
23620 ir_add_error(ira, &instruction->op->base,
23691 ir_add_error_node(ira, instruction->op->source_node,
2362123692 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
2362223693 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
2362323694 return ira->codegen->invalid_inst_gen;
......@@ -23628,9 +23699,9 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2362823699 if (val == nullptr)
2362923700 return ira->codegen->invalid_inst_gen;
2363023701 if (val->special == ConstValSpecialUndef)
23631 return ir_const_undef(ira, &instruction->base.base, op_type);
23702 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op_type);
2363223703
23633 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
23704 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, op_type);
2363423705 const size_t buf_size = int_type->data.integral.bit_count / 8;
2363523706 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
2363623707 if (is_vector) {
......@@ -23638,7 +23709,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2363823709 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len);
2363923710 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
2364023711 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
23641 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
23712 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
2364223713 op_elem_val, UndefOk)))
2364323714 {
2364423715 return ira->codegen->invalid_inst_gen;
......@@ -23663,7 +23734,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2366323734 return result;
2366423735 }
2366523736
23666 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);
23737 return ir_build_bswap_gen(ira, instruction->base.scope, instruction->base.source_node, op_type, op);
2366723738}
2366823739
2366923740static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
......@@ -23676,7 +23747,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
2367623747 return ira->codegen->invalid_inst_gen;
2367723748
2367823749 if (int_type->data.integral.bit_count == 0) {
23679 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
23750 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type);
2368023751 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2368123752 return result;
2368223753 }
......@@ -23686,9 +23757,9 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
2368623757 if (val == nullptr)
2368723758 return ira->codegen->invalid_inst_gen;
2368823759 if (val->special == ConstValSpecialUndef)
23689 return ir_const_undef(ira, &instruction->base.base, int_type);
23760 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, int_type);
2369023761
23691 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
23762 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type);
2369223763 size_t num_bits = int_type->data.integral.bit_count;
2369323764 size_t buf_size = (num_bits + 7) / 8;
2369423765 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
......@@ -23717,7 +23788,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
2371723788 return result;
2371823789 }
2371923790
23720 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);
23791 return ir_build_bit_reverse_gen(ira, instruction->base.scope, instruction->base.source_node, int_type, op);
2372123792}
2372223793
2372323794
......@@ -23726,7 +23797,7 @@ static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEn
2372623797 if (type_is_invalid(target->value->type))
2372723798 return ira->codegen->invalid_inst_gen;
2372823799
23729 return ir_analyze_enum_to_int(ira, &instruction->base.base, target);
23800 return ir_analyze_enum_to_int(ira, instruction->base.scope, instruction->base.source_node, target);
2373023801}
2373123802
2373223803static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {
......@@ -23737,7 +23808,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn
2373723808 return ira->codegen->invalid_inst_gen;
2373823809
2373923810 if (dest_type->id != ZigTypeIdEnum) {
23740 ir_add_error(ira, &instruction->dest_type->base,
23811 ir_add_error_node(ira, instruction->dest_type->source_node,
2374123812 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
2374223813 return ira->codegen->invalid_inst_gen;
2374323814 }
......@@ -23755,7 +23826,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn
2375523826 if (type_is_invalid(casted_target->value->type))
2375623827 return ira->codegen->invalid_inst_gen;
2375723828
23758 return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type);
23829 return ir_analyze_int_to_enum(ira, instruction->base.scope, instruction->base.source_node, casted_target, dest_type);
2375923830}
2376023831
2376123832static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
......@@ -23770,14 +23841,14 @@ static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrI
2377023841 return ira->codegen->invalid_inst_gen;
2377123842
2377223843 if (!scope_is_comptime && is_comptime) {
23773 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
23844 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
2377423845 buf_sprintf("comptime control flow inside runtime block"));
23775 add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node,
23846 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
2377623847 buf_sprintf("runtime block created here"));
2377723848 return ira->codegen->invalid_inst_gen;
2377823849 }
2377923850
23780 return ir_const_void(ira, &instruction->base.base);
23851 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2378123852}
2378223853
2378323854static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
......@@ -23790,7 +23861,7 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe
2379023861 return ira->codegen->invalid_inst_gen;
2379123862
2379223863 if (!is_container(container_type)) {
23793 ir_add_error(ira, &instruction->container->base,
23864 ir_add_error_node(ira, instruction->container->source_node,
2379423865 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));
2379523866 return ira->codegen->invalid_inst_gen;
2379623867 }
......@@ -23798,13 +23869,13 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe
2379823869 ScopeDecls *container_scope = get_container_scope(container_type);
2379923870 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
2380023871 if (tld == nullptr)
23801 return ir_const_bool(ira, &instruction->base.base, false);
23872 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2380223873
23803 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {
23804 return ir_const_bool(ira, &instruction->base.base, false);
23874 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) {
23875 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2380523876 }
2380623877
23807 return ir_const_bool(ira, &instruction->base.base, true);
23878 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true);
2380823879}
2380923880
2381023881static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode *node, Buf *var_name) {
......@@ -23826,9 +23897,9 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
2382623897static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
2382723898 // put a variable of same name with invalid type in global scope
2382823899 // so that future references to this same name will find a variable with an invalid type
23829 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,
23830 instruction->base.base.source_node, instruction->name);
23831 ir_add_error(ira, &instruction->base.base,
23900 populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope,
23901 instruction->base.source_node, instruction->name);
23902 ir_add_error_node(ira, instruction->base.source_node,
2383223903 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
2383323904 return ira->codegen->invalid_inst_gen;
2383423905}
......@@ -23839,7 +23910,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
2383923910 return ira->codegen->invalid_inst_gen;
2384023911
2384123912 bool was_written = instruction->result_loc->written;
23842 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
23913 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2384323914 value->value->type, value, false, true);
2384423915 if (result_loc != nullptr) {
2384523916 if (type_is_invalid(result_loc->value->type))
......@@ -23848,7 +23919,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
2384823919 return result_loc;
2384923920
2385023921 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
23851 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,
23922 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, result_loc, value,
2385223923 instruction->result_loc->allow_write_through_const);
2385323924 if (type_is_invalid(store_ptr->value->type)) {
2385423925 if (instruction->result_loc->id == ResultLocIdReturn &&
......@@ -23873,7 +23944,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
2387323944 }
2387423945 }
2387523946
23876 return ir_const_void(ira, &instruction->base.base);
23947 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2387723948}
2387823949
2387923950static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
......@@ -23884,7 +23955,8 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc
2388423955 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
2388523956 if (type_is_invalid(dest_type))
2388623957 return ira->codegen->invalid_inst_gen;
23887 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);
23958 return ir_implicit_cast2(ira, instruction->base.scope, instruction->base.source_node,
23959 operand, dest_type);
2388823960}
2388923961
2389023962static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
......@@ -23892,7 +23964,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB
2389223964 if (type_is_invalid(operand->value->type))
2389323965 return operand;
2389423966
23895 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
23967 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base,
2389623968 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true);
2389723969 if (result_loc != nullptr &&
2389823970 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
......@@ -23904,7 +23976,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB
2390423976 instruction->result_loc_bit_cast->base.source_instruction->child);
2390523977 if (type_is_invalid(dest_type))
2390623978 return ira->codegen->invalid_inst_gen;
23907 return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type);
23979 return ir_analyze_bit_cast(ira, instruction->base.scope, instruction->base.source_node, operand, dest_type);
2390823980}
2390923981
2391023982static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
......@@ -23915,7 +23987,7 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
2391523987 return ira->codegen->invalid_inst_gen;
2391623988
2391723989 if (union_type->id != ZigTypeIdUnion) {
23918 ir_add_error(ira, &instruction->union_type->base,
23990 ir_add_error_node(ira, instruction->union_type->source_node,
2391923991 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));
2392023992 return ira->codegen->invalid_inst_gen;
2392123993 }
......@@ -23932,32 +24004,32 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
2393224004 if (type_is_invalid(result_loc->value->type))
2393324005 return ira->codegen->invalid_inst_gen;
2393424006
23935 return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node,
24007 return ir_analyze_union_init(ira, instruction->base.scope, instruction->base.source_node, instruction->base.source_node,
2393624008 union_type, field_name, field_result_loc, result_loc);
2393724009}
2393824010
2393924011static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
23940 return ir_build_suspend_begin_gen(ira, &instruction->base.base);
24012 return ir_build_suspend_begin_gen(ira, instruction->base.scope, instruction->base.source_node);
2394124013}
2394224014
2394324015static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
2394424016 IrInstGen *begin_base = instruction->begin->base.child;
2394524017 if (type_is_invalid(begin_base->value->type))
2394624018 return ira->codegen->invalid_inst_gen;
23947 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);
24019 src_assert(begin_base->id == IrInstGenIdSuspendBegin, instruction->base.source_node);
2394824020 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2394924021
2395024022 ZigFn *fn_entry = ira->fn;
23951 ir_assert(fn_entry != nullptr, &instruction->base.base);
24023 src_assert(fn_entry != nullptr, instruction->base.source_node);
2395224024
2395324025 if (fn_entry->inferred_async_node == nullptr) {
23954 fn_entry->inferred_async_node = instruction->base.base.source_node;
24026 fn_entry->inferred_async_node = instruction->base.source_node;
2395524027 }
2395624028
23957 return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin);
24029 return ir_build_suspend_finish_gen(ira, instruction->base.scope, instruction->base.source_node, begin);
2395824030}
2395924031
23960static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,
24032static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2396124033 IrInstGen *frame_ptr, ZigFn **target_fn)
2396224034{
2396324035 if (type_is_invalid(frame_ptr->value->type))
......@@ -23976,7 +24048,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source
2397624048 *target_fn = func;
2397724049 frame = frame_ptr;
2397824050 } else {
23979 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);
24051 frame = ir_get_deref(ira, scope, source_node, frame_ptr, nullptr);
2398024052 if (frame->value->type->id == ZigTypeIdPointer &&
2398124053 frame->value->type->data.pointer.ptr_len == PtrLenSingle &&
2398224054 frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
......@@ -23987,7 +24059,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source
2398724059 } else if (frame->value->type->id != ZigTypeIdAnyFrame ||
2398824060 frame->value->type->data.any_frame.result_type == nullptr)
2398924061 {
23990 ir_add_error(ira, source_instr,
24062 ir_add_error_node(ira, source_node,
2399124063 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
2399224064 return ira->codegen->invalid_inst_gen;
2399324065 } else {
......@@ -24008,19 +24080,19 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
2400824080 if (type_is_invalid(operand->value->type))
2400924081 return ira->codegen->invalid_inst_gen;
2401024082 ZigFn *target_fn;
24011 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn);
24083 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, instruction->base.scope, instruction->base.source_node, operand, &target_fn);
2401224084 if (type_is_invalid(frame->value->type))
2401324085 return ira->codegen->invalid_inst_gen;
2401424086
2401524087 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2401624088
2401724089 ZigFn *fn_entry = ira->fn;
24018 ir_assert(fn_entry != nullptr, &instruction->base.base);
24090 src_assert(fn_entry != nullptr, instruction->base.source_node);
2401924091
2402024092 // If it's not @Frame(func) then it's definitely a suspend point
2402124093 if (target_fn == nullptr && !instruction->is_nosuspend) {
2402224094 if (fn_entry->inferred_async_node == nullptr) {
24023 fn_entry->inferred_async_node = instruction->base.base.source_node;
24095 fn_entry->inferred_async_node = instruction->base.source_node;
2402424096 }
2402524097 }
2402624098
......@@ -24030,7 +24102,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
2403024102
2403124103 IrInstGen *result_loc;
2403224104 if (type_has_bits(ira->codegen, result_type)) {
24033 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
24105 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
2403424106 result_type, nullptr, true, true);
2403524107 if (result_loc != nullptr &&
2403624108 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
......@@ -24041,7 +24113,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
2404124113 result_loc = nullptr;
2404224114 }
2404324115
24044 IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc,
24116 IrInstGenAwait *result = ir_build_await_gen(ira, instruction->base.scope, instruction->base.source_node, frame, result_type, result_loc,
2404524117 instruction->is_nosuspend);
2404624118 result->target_fn = target_fn;
2404724119 fn_entry->await_list.append(result);
......@@ -24060,27 +24132,29 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume
2406024132 {
2406124133 frame = frame_ptr;
2406224134 } else {
24063 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);
24135 frame = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
24136 frame_ptr, nullptr);
2406424137 }
2406524138
2406624139 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
24067 IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type);
24140 IrInstGen *casted_frame = ir_implicit_cast2(ira, instruction->frame->scope,
24141 instruction->frame->source_node, frame, any_frame_type);
2406824142 if (type_is_invalid(casted_frame->value->type))
2406924143 return ira->codegen->invalid_inst_gen;
2407024144
24071 return ir_build_resume_gen(ira, &instruction->base.base, casted_frame);
24145 return ir_build_resume_gen(ira, instruction->base.scope, instruction->base.source_node, casted_frame);
2407224146}
2407324147
2407424148static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
24075 if (ir_should_inline(ira->zir, instruction->base.base.scope))
24076 return ir_const_void(ira, &instruction->base.base);
24149 if (ir_should_inline(ira->zir, instruction->base.scope))
24150 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2407724151
2407824152 IrInstGen *operand = instruction->operand->child;
2407924153 if (type_is_invalid(operand->value->type))
2408024154 return ira->codegen->invalid_inst_gen;
2408124155
2408224156 if (!type_has_bits(ira->codegen, operand->value->type))
24083 return ir_const_void(ira, &instruction->base.base);
24157 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2408424158
2408524159 switch (instruction->spill_id) {
2408624160 case SpillIdInvalid:
......@@ -24090,7 +24164,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp
2409024164 break;
2409124165 }
2409224166
24093 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);
24167 return ir_build_spill_begin_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->spill_id);
2409424168}
2409524169
2409624170static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
......@@ -24098,23 +24172,23 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil
2409824172 if (type_is_invalid(operand->value->type))
2409924173 return ira->codegen->invalid_inst_gen;
2410024174
24101 if (ir_should_inline(ira->zir, instruction->base.base.scope) ||
24175 if (ir_should_inline(ira->zir, instruction->base.scope) ||
2410224176 !type_has_bits(ira->codegen, operand->value->type) ||
2410324177 instr_is_comptime(operand))
2410424178 {
2410524179 return operand;
2410624180 }
2410724181
24108 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);
24182 src_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, instruction->base.source_node);
2410924183 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2411024184
24111 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);
24185 return ir_build_spill_end_gen(ira, instruction->base.scope, instruction->base.source_node, begin, operand->value->type);
2411224186}
2411324187
2411424188static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instruction) {
24115 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);
24189 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
2411624190 if (fn_entry == nullptr) {
24117 ir_add_error(ira, &instruction->base.base, buf_sprintf("@src outside function"));
24191 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@src outside function"));
2411824192 return ira->codegen->invalid_inst_gen;
2411924193 }
2412024194
......@@ -24140,7 +24214,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
2414024214 ensure_field_index(source_location_type, "file", 0);
2414124215 fields[0]->special = ConstValSpecialStatic;
2414224216
24143 ZigType *import = instruction->base.base.source_node->owner;
24217 ZigType *import = instruction->base.source_node->owner;
2414424218 RootStruct *root_struct = import->data.structure.root_struct;
2414524219 Buf *path = root_struct->path;
2414624220 ZigValue *file_name = create_const_str_lit(ira->codegen, path)->data.x_ptr.data.ref.pointee;
......@@ -24156,7 +24230,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
2415624230 fields[1]->type = u8_slice;
2415724231
2415824232
24159 TokenLoc tok_loc = root_struct->token_locs[instruction->base.base.source_node->main_token];
24233 TokenLoc tok_loc = root_struct->token_locs[instruction->base.source_node->main_token];
2416024234
2416124235 // line: u32
2416224236 ensure_field_index(source_location_type, "line", 2);
......@@ -24170,7 +24244,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
2417024244 fields[3]->type = ira->codegen->builtin_types.entry_u32;
2417124245 bigint_init_unsigned(&fields[3]->data.x_bigint, tok_loc.column + 1);
2417224246
24173 return ir_const_move(ira, &instruction->base.base, result);
24247 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, result);
2417424248}
2417524249
2417624250static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
......@@ -24507,7 +24581,7 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
2450724581 while (ira->old_bb_index < ira->zir->basic_block_list.length) {
2450824582 IrInstSrc *old_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index);
2450924583
24510 if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
24584 if (old_instruction->ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
2451124585 ira->instruction_index += 1;
2451224586 continue;
2451324587 }
......@@ -24518,9 +24592,10 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
2451824592 fprintf(stderr, "~ ");
2451924593 ir_print_inst_src(codegen, stderr, old_instruction, 0);
2452024594 }
24595 ira->suspend_source_instr = old_instruction;
2452124596 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2452224597 if (new_instruction != nullptr) {
24523 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base);
24598 src_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction->source_node);
2452424599 old_instruction->child = new_instruction;
2452524600
2452624601 if (type_is_invalid(new_instruction->value->type)) {
......@@ -24534,11 +24609,11 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
2453424609 stage1_air->first_err_trace_msg = ira->codegen->trace_err;
2453524610 }
2453624611 if (stage1_air->first_err_trace_msg != nullptr &&
24537 !old_instruction->base.source_node->already_traced_this_node)
24612 !old_instruction->source_node->already_traced_this_node)
2453824613 {
24539 old_instruction->base.source_node->already_traced_this_node = true;
24614 old_instruction->source_node->already_traced_this_node = true;
2454024615 stage1_air->first_err_trace_msg = add_error_note(ira->codegen, stage1_air->first_err_trace_msg,
24541 old_instruction->base.source_node, buf_create_from_str("referenced here"));
24616 old_instruction->source_node, buf_create_from_str("referenced here"));
2454224617 }
2454324618 return ira->codegen->builtin_types.entry_invalid;
2454424619 } else if (ira->codegen->verbose_ir) {
......@@ -24908,10 +24983,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2490824983
2490924984 if(!is_valid_param_type(param_type)){
2491024985 if(param_type->id == ZigTypeIdOpaque){
24911 ir_add_error(ira, &param_type_inst->base,
24986 ir_add_error(ira, param_type_inst,
2491224987 buf_sprintf("parameter of opaque type '%s' not allowed", buf_ptr(&param_type->name)));
2491324988 } else {
24914 ir_add_error(ira, &param_type_inst->base,
24989 ir_add_error(ira, param_type_inst,
2491524990 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&param_type->name)));
2491624991 }
2491724992
......@@ -24921,7 +24996,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2492124996 switch (type_requires_comptime(ira->codegen, param_type)) {
2492224997 case ReqCompTimeYes:
2492324998 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
24924 ir_add_error(ira, &param_type_inst->base,
24999 ir_add_error(ira, param_type_inst,
2492525000 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
2492625001 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2492725002 return nullptr;
......@@ -24939,7 +25014,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2493925014 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
2494025015 return nullptr;
2494125016 if (!has_bits) {
24942 ir_add_error(ira, &param_type_inst->base,
25017 ir_add_error(ira, param_type_inst,
2494325018 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
2494425019 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2494525020 return nullptr;
......@@ -24958,7 +25033,8 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2495825033 if (type_is_invalid(fn_type_id.return_type))
2495925034 return nullptr;
2496025035 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
24961 ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque"));
25036 ir_add_error_node(ira, lazy_fn_type->return_type->source_node,
25037 buf_create_from_str("return type cannot be opaque"));
2496225038 return nullptr;
2496325039 }
2496425040
......@@ -24976,7 +25052,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2497625052 LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);
2497725053 IrAnalyze *ira = type_info_decls->ira;
2497825054
24979 if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true)))
25055 if ((err = ir_make_type_info_decls(ira, type_info_decls->source_node, val, type_info_decls->decls_scope, true)))
2498025056 {
2498125057 return err;
2498225058 };
......@@ -25002,7 +25078,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2500225078 case ZigTypeIdBoundFn:
2500325079 case ZigTypeIdVoid:
2500425080 case ZigTypeIdOpaque:
25005 ir_add_error(ira, &lazy_align_of->target_type->base,
25081 ir_add_error_node(ira, lazy_align_of->target_type->source_node,
2500625082 buf_sprintf("no align available for type '%s'",
2500725083 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
2500825084 return ErrorSemanticAnalyzeFail;
......@@ -25052,7 +25128,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2505225128 case ZigTypeIdNull:
2505325129 case ZigTypeIdBoundFn:
2505425130 case ZigTypeIdOpaque:
25055 ir_add_error(ira, &lazy_size_of->target_type->base,
25131 ir_add_error_node(ira, lazy_size_of->target_type->source_node,
2505625132 buf_sprintf("no size available for type '%s'",
2505725133 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
2505825134 return ErrorSemanticAnalyzeFail;
......@@ -25133,7 +25209,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2513325209 case ZigTypeIdUndefined:
2513425210 case ZigTypeIdNull:
2513525211 case ZigTypeIdOpaque:
25136 ir_add_error(ira, &lazy_slice_type->elem_type->base,
25212 ir_add_error_node(ira, lazy_slice_type->elem_type->source_node,
2513725213 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
2513825214 return ErrorSemanticAnalyzeFail;
2513925215 case ZigTypeIdMetaType:
......@@ -25206,11 +25282,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2520625282 }
2520725283
2520825284 if (elem_type->id == ZigTypeIdUnreachable) {
25209 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25285 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2521025286 buf_create_from_str("pointer to noreturn not allowed"));
2521125287 return ErrorSemanticAnalyzeFail;
2521225288 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {
25213 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25289 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2521425290 buf_create_from_str("unknown-length pointer to opaque"));
2521525291 return ErrorSemanticAnalyzeFail;
2521625292 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
......@@ -25218,16 +25294,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2521825294 if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type)))
2521925295 return err;
2522025296 if (!ok_type) {
25221 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25297 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2522225298 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
2522325299 buf_ptr(&elem_type->name)));
2522425300 return ErrorSemanticAnalyzeFail;
2522525301 } else if (elem_type->id == ZigTypeIdOpaque) {
25226 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25302 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2522725303 buf_sprintf("C pointers cannot point to opaque types"));
2522825304 return ErrorSemanticAnalyzeFail;
2522925305 } else if (lazy_ptr_type->is_allowzero) {
25230 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25306 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2523125307 buf_sprintf("C pointers always allow address zero"));
2523225308 return ErrorSemanticAnalyzeFail;
2523325309 }
......@@ -25259,7 +25335,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2525925335 return ErrorSemanticAnalyzeFail;
2526025336
2526125337 if (elem_type->id == ZigTypeIdUnreachable) {
25262 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25338 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2526325339 buf_create_from_str("pointer to noreturn not allowed"));
2526425340 return ErrorSemanticAnalyzeFail;
2526525341 }
......@@ -25283,7 +25359,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2528325359 return ErrorSemanticAnalyzeFail;
2528425360
2528525361 if (elem_type->id == ZigTypeIdUnreachable) {
25286 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
25362 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
2528725363 buf_create_from_str("pointer to noreturn not allowed"));
2528825364 return ErrorSemanticAnalyzeFail;
2528925365 }
......@@ -25313,7 +25389,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2531325389 case ZigTypeIdUndefined:
2531425390 case ZigTypeIdNull:
2531525391 case ZigTypeIdOpaque:
25316 ir_add_error(ira, &lazy_array_type->elem_type->base,
25392 ir_add_error_node(ira, lazy_array_type->elem_type->source_node,
2531725393 buf_sprintf("array of type '%s' not allowed",
2531825394 buf_ptr(&elem_type->name)));
2531925395 return ErrorSemanticAnalyzeFail;
......@@ -25377,7 +25453,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2537725453 return ErrorSemanticAnalyzeFail;
2537825454
2537925455 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {
25380 ir_add_error(ira, &lazy_opt_type->payload_type->base,
25456 ir_add_error_node(ira, lazy_opt_type->payload_type->source_node,
2538125457 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
2538225458 return ErrorSemanticAnalyzeFail;
2538325459 }
......@@ -25419,7 +25495,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2541925495 return ErrorSemanticAnalyzeFail;
2542025496
2542125497 if (err_set_type->id != ZigTypeIdErrorSet) {
25422 ir_add_error(ira, &lazy_err_union_type->err_set_type->base,
25498 ir_add_error_node(ira, lazy_err_union_type->err_set_type->source_node,
2542325499 buf_sprintf("expected error set type, found type '%s'",
2542425500 buf_ptr(&err_set_type->name)));
2542525501 return ErrorSemanticAnalyzeFail;
......@@ -25455,8 +25531,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2545525531 return ErrorNone;
2545625532}
2545725533
25458void IrInst::src() {
25459 IrInst *inst = this;
25534void IrInstGen::src() {
25535 IrInstGen *inst = this;
2546025536 if (inst->source_node != nullptr) {
2546125537 inst->source_node->src();
2546225538 } else {
......@@ -25464,37 +25540,13 @@ void IrInst::src() {
2546425540 }
2546525541}
2546625542
25467void IrInst::dump() {
25468 this->src();
25469 fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id);
25470}
25471
25472void IrInstSrc::src() {
25473 this->base.src();
25474}
25475
25476void IrInstGen::src() {
25477 this->base.src();
25478}
25479
25480void IrInstSrc::dump() {
25481 IrInstSrc *inst = this;
25482 inst->src();
25483 if (inst->base.scope == nullptr) {
25484 fprintf(stderr, "(null scope)\n");
25485 } else {
25486 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
25487 fprintf(stderr, "-> ");
25488 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
25489 }
25490}
2549125543void IrInstGen::dump() {
2549225544 IrInstGen *inst = this;
2549325545 inst->src();
25494 if (inst->base.scope == nullptr) {
25546 if (inst->scope == nullptr) {
2549525547 fprintf(stderr, "(null scope)\n");
2549625548 } else {
25497 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0);
25549 ir_print_inst_gen(inst->scope->codegen, stderr, inst, 0);
2549825550 }
2549925551}
2550025552
src/stage1/ir_print.cpp+24-12
......@@ -581,8 +581,8 @@ static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool tr
581581 type_name = "(unknown)";
582582 }
583583 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?
584 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
585 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
584 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
585 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
586586 ir_inst_src_type_str(instruction->id), type_name, ref_count);
587587}
588588
......@@ -591,17 +591,17 @@ static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool tr
591591 const char mark = trailing ? ':' : '#';
592592 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
593593 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
594 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
595 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
594 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
595 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
596596 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
597597}
598598
599599static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
600 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
600 fprintf(irp->f, "#%" PRIu32 "", inst->debug_id);
601601}
602602
603603static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
604 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
604 fprintf(irp->f, "#%" PRIu32 "", inst->debug_id);
605605 if (irp->printed.maybe_get(inst) == nullptr) {
606606 irp->printed.put(inst, 0);
607607 irp->pending.append(inst);
......@@ -1231,8 +1231,8 @@ static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *inst
12311231}
12321232
12331233static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
1234 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1235 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
1234 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1235 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
12361236 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
12371237 fprintf(irp->f, "asm%s (", volatile_kw);
12381238 ir_print_other_inst_src(irp, instruction->asm_template);
......@@ -1274,8 +1274,8 @@ static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
12741274}
12751275
12761276static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1277 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1278 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
1277 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1278 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
12791279 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
12801280 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
12811281
......@@ -2003,10 +2003,10 @@ static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *
20032003
20042004static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
20052005 fprintf(irp->f, "fn(");
2006 for (size_t i = 0; i < instruction->base.base.source_node->data.fn_proto.params.length; i += 1) {
2006 for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
20072007 if (i != 0)
20082008 fprintf(irp->f, ",");
2009 if (instruction->is_var_args && i == instruction->base.base.source_node->data.fn_proto.params.length - 1) {
2009 if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {
20102010 fprintf(irp->f, "...");
20112011 } else {
20122012 ir_print_other_inst_src(irp, instruction->param_types[i]);
......@@ -3450,3 +3450,15 @@ void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int in
34503450
34513451 ir_print_inst_gen(irp, instruction, false);
34523452}
3453
3454void IrInstSrc::dump() {
3455 IrInstSrc *inst = this;
3456 inst->src();
3457 if (inst->scope == nullptr) {
3458 fprintf(stderr, "(null scope)\n");
3459 } else {
3460 ir_print_inst_src(inst->scope->codegen, stderr, inst, 0);
3461 fprintf(stderr, "-> ");
3462 ir_print_inst_gen(inst->scope->codegen, stderr, inst->child, 0);
3463 }
3464}