| ... | ... | @@ -49,6 +49,7 @@ struct IrAnalyze { |
| 49 | 49 | Stage1Air *parent_exec; |
| 50 | 50 | size_t *backward_branch_count; |
| 51 | 51 | size_t *backward_branch_quota; |
| 52 | ZigFn *fn; |
| 52 | 53 | |
| 53 | 54 | // For the purpose of using in a debugger |
| 54 | 55 | void dump(); |
| ... | ... | @@ -4259,7 +4260,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4259 | 4260 | continue; |
| 4260 | 4261 | } |
| 4261 | 4262 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 4262 | | cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4263 | cur_type->data.error_set.infer_fn == ira->fn; |
| 4263 | 4264 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 4264 | 4265 | return ira->codegen->builtin_types.entry_invalid; |
| 4265 | 4266 | } |
| ... | ... | @@ -4327,7 +4328,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4327 | 4328 | } |
| 4328 | 4329 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 4329 | 4330 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4330 | | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4331 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4331 | 4332 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 4332 | 4333 | return ira->codegen->builtin_types.entry_invalid; |
| 4333 | 4334 | } |
| ... | ... | @@ -4382,7 +4383,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4382 | 4383 | |
| 4383 | 4384 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 4384 | 4385 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 4385 | | cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4386 | cur_type->data.error_set.infer_fn == ira->fn; |
| 4386 | 4387 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 4387 | 4388 | return ira->codegen->builtin_types.entry_invalid; |
| 4388 | 4389 | } |
| ... | ... | @@ -4401,7 +4402,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4401 | 4402 | if (prev_type->id == ZigTypeIdErrorUnion) { |
| 4402 | 4403 | err_set_type = prev_type->data.error_union.err_set_type; |
| 4403 | 4404 | allow_infer = err_set_type->data.error_set.infer_fn != nullptr && |
| 4404 | | err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4405 | err_set_type->data.error_set.infer_fn == ira->fn; |
| 4405 | 4406 | } else { |
| 4406 | 4407 | err_set_type = cur_type; |
| 4407 | 4408 | } |
| ... | ... | @@ -4465,9 +4466,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4465 | 4466 | continue; |
| 4466 | 4467 | |
| 4467 | 4468 | bool allow_infer_prev = prev_err_set_type->data.error_set.infer_fn != nullptr && |
| 4468 | | prev_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4469 | prev_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4469 | 4470 | bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4470 | | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4471 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4471 | 4472 | |
| 4472 | 4473 | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) { |
| 4473 | 4474 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -4651,7 +4652,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4651 | 4652 | if (err_set_type != nullptr) { |
| 4652 | 4653 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 4653 | 4654 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4654 | | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 4655 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4655 | 4656 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 4656 | 4657 | return ira->codegen->builtin_types.entry_invalid; |
| 4657 | 4658 | } |
| ... | ... | @@ -5595,11 +5596,10 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 5595 | 5596 | ir_executable->source_node = source_node; |
| 5596 | 5597 | ir_executable->name = exec_name; |
| 5597 | 5598 | ir_executable->is_inline = true; |
| 5598 | | ir_executable->fn_entry = fn_entry; |
| 5599 | 5599 | ir_executable->c_import_buf = c_import_buf; |
| 5600 | 5600 | ir_executable->begin_scope = scope; |
| 5601 | 5601 | |
| 5602 | | if (!ir_gen(codegen, node, scope, ir_executable)) |
| 5602 | if (!stage1_astgen(codegen, node, scope, ir_executable, fn_entry)) |
| 5603 | 5603 | return ErrorSemanticAnalyzeFail; |
| 5604 | 5604 | |
| 5605 | 5605 | if (ir_executable->first_err_trace_msg != nullptr) { |
| ... | ... | @@ -5618,12 +5618,12 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 5618 | 5618 | analyzed_executable->source_exec = ir_executable; |
| 5619 | 5619 | analyzed_executable->name = exec_name; |
| 5620 | 5620 | analyzed_executable->is_inline = true; |
| 5621 | | analyzed_executable->fn_entry = fn_entry; |
| 5622 | 5621 | analyzed_executable->c_import_buf = c_import_buf; |
| 5623 | 5622 | analyzed_executable->begin_scope = scope; |
| 5624 | 5623 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, |
| 5625 | 5624 | backward_branch_count, backward_branch_quota, |
| 5626 | | return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr); |
| 5625 | return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr, |
| 5626 | fn_entry); |
| 5627 | 5627 | if (type_is_invalid(result_type)) { |
| 5628 | 5628 | return ErrorSemanticAnalyzeFail; |
| 5629 | 5629 | } |
| ... | ... | @@ -11025,7 +11025,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 11025 | 11025 | return ira->codegen->invalid_inst_gen; |
| 11026 | 11026 | } |
| 11027 | 11027 | |
| 11028 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 11028 | ZigFn *fn_entry = ira->fn; |
| 11029 | 11029 | if (fn_entry) |
| 11030 | 11030 | fn_entry->variable_list.append(var); |
| 11031 | 11031 | |
| ... | ... | @@ -11421,9 +11421,9 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11421 | 11421 | is_thread_local, expr_type); |
| 11422 | 11422 | } |
| 11423 | 11423 | |
| 11424 | | static bool exec_has_err_ret_trace(CodeGen *g, Stage1Zir *exec) { |
| 11425 | | ZigFn *fn_entry = exec->fn_entry; |
| 11426 | | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 11424 | static bool ira_has_err_ret_trace(IrAnalyze *ira) { |
| 11425 | ZigFn *fn = ira->fn; |
| 11426 | return fn != nullptr && fn->calls_or_awaits_errorable_fn && ira->codegen->have_err_ret_tracing; |
| 11427 | 11427 | } |
| 11428 | 11428 | |
| 11429 | 11429 | static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| ... | ... | @@ -11432,7 +11432,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 11432 | 11432 | ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false); |
| 11433 | 11433 | if (instruction->optional == IrInstErrorReturnTraceNull) { |
| 11434 | 11434 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 11435 | | if (!exec_has_err_ret_trace(ira->codegen, ira->zir)) { |
| 11435 | if (!ira_has_err_ret_trace(ira)) { |
| 11436 | 11436 | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); |
| 11437 | 11437 | ZigValue *out_val = result->value; |
| 11438 | 11438 | assert(get_src_ptr_type(optional_type) != nullptr); |
| ... | ... | @@ -11504,7 +11504,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 11504 | 11504 | PtrLenSingle, align, 0, 0, false); |
| 11505 | 11505 | |
| 11506 | 11506 | if (!force_comptime) { |
| 11507 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 11507 | ZigFn *fn_entry = ira->fn; |
| 11508 | 11508 | if (fn_entry != nullptr) { |
| 11509 | 11509 | fn_entry->alloca_gen_list.append(result); |
| 11510 | 11510 | } |
| ... | ... | @@ -11603,7 +11603,7 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc |
| 11603 | 11603 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 11604 | 11604 | PtrLenSingle, 0, 0, 0, false); |
| 11605 | 11605 | set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base); |
| 11606 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 11606 | ZigFn *fn_entry = ira->fn; |
| 11607 | 11607 | if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) { |
| 11608 | 11608 | fn_entry->alloca_gen_list.append(alloca_gen); |
| 11609 | 11609 | } |
| ... | ... | @@ -12131,7 +12131,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 12131 | 12131 | if (result_loc != nullptr) |
| 12132 | 12132 | return result_loc; |
| 12133 | 12133 | |
| 12134 | | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 12134 | ZigFn *fn = ira->fn; |
| 12135 | 12135 | if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 12136 | 12136 | instruction->result_loc->id == ResultLocIdReturn) |
| 12137 | 12137 | { |
| ... | ... | @@ -12849,7 +12849,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12849 | 12849 | } |
| 12850 | 12850 | } |
| 12851 | 12851 | |
| 12852 | | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 12852 | ZigFn *parent_fn_entry = ira->fn; |
| 12853 | 12853 | assert(parent_fn_entry); |
| 12854 | 12854 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 12855 | 12855 | IrInstGen *arg = args_ptr[call_i]; |
| ... | ... | @@ -13017,7 +13017,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13017 | 13017 | return ir_finish_anal(ira, &new_call_instruction->base); |
| 13018 | 13018 | } |
| 13019 | 13019 | |
| 13020 | | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 13020 | ZigFn *parent_fn_entry = ira->fn; |
| 13021 | 13021 | assert(fn_type_id->return_type != nullptr); |
| 13022 | 13022 | assert(parent_fn_entry != nullptr); |
| 13023 | 13023 | if (fn_type_can_fail(fn_type_id)) { |
| ... | ... | @@ -21069,7 +21069,7 @@ static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrc |
| 21069 | 21069 | } |
| 21070 | 21070 | |
| 21071 | 21071 | static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) { |
| 21072 | | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 21072 | ZigFn *fn = ira->fn; |
| 21073 | 21073 | ir_assert(fn != nullptr, &instruction->base.base); |
| 21074 | 21074 | |
| 21075 | 21075 | if (fn->inferred_async_node == nullptr) { |
| ... | ... | @@ -22932,7 +22932,7 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS |
| 22932 | 22932 | return ira->codegen->invalid_inst_gen; |
| 22933 | 22933 | } |
| 22934 | 22934 | |
| 22935 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 22935 | ZigFn *fn_entry = ira->fn; |
| 22936 | 22936 | if (fn_entry == nullptr) { |
| 22937 | 22937 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function")); |
| 22938 | 22938 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -23952,7 +23952,7 @@ static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSr |
| 23952 | 23952 | ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base); |
| 23953 | 23953 | IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base); |
| 23954 | 23954 | |
| 23955 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 23955 | ZigFn *fn_entry = ira->fn; |
| 23956 | 23956 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 23957 | 23957 | |
| 23958 | 23958 | if (fn_entry->inferred_async_node == nullptr) { |
| ... | ... | @@ -24019,7 +24019,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i |
| 24019 | 24019 | |
| 24020 | 24020 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 24021 | 24021 | |
| 24022 | | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 24022 | ZigFn *fn_entry = ira->fn; |
| 24023 | 24023 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 24024 | 24024 | |
| 24025 | 24025 | // If it's not @Frame(func) then it's definitely a suspend point |
| ... | ... | @@ -24465,16 +24465,17 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc |
| 24465 | 24465 | zig_unreachable(); |
| 24466 | 24466 | } |
| 24467 | 24467 | |
| 24468 | | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 24468 | // This function attempts to evaluate stage1 ZIR code while doing type checking and other analysis. |
| 24469 | 24469 | // It emits to a new Stage1Air which is partially evaluated IR code. |
| 24470 | 24470 | ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_air, |
| 24471 | 24471 | size_t *backward_branch_count, size_t *backward_branch_quota, |
| 24472 | | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) |
| 24472 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr, ZigFn *fn) |
| 24473 | 24473 | { |
| 24474 | 24474 | assert(stage1_zir->first_err_trace_msg == nullptr); |
| 24475 | 24475 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| 24476 | 24476 | |
| 24477 | 24477 | IrAnalyze *ira = heap::c_allocator.create<IrAnalyze>(); |
| 24478 | ira->fn = fn; |
| 24478 | 24479 | ira->backward_branch_count = backward_branch_count; |
| 24479 | 24480 | ira->backward_branch_quota = backward_branch_quota; |
| 24480 | 24481 | ira->ref_count = 1; |