| ... | @@ -33,7 +33,8 @@ struct IrBuilderGen { | ... | @@ -33,7 +33,8 @@ struct IrBuilderGen { |
| 33 | | 33 | |
| 34 | struct IrAnalyze { | 34 | struct IrAnalyze { |
| 35 | CodeGen *codegen; | 35 | CodeGen *codegen; |
| 36 | IrBuilderSrc old_irb; | 36 | Stage1Zir *zir; |
| | 37 | IrBasicBlockSrc *zir_current_basic_block; |
| 37 | IrBuilderGen new_irb; | 38 | IrBuilderGen new_irb; |
| 38 | size_t old_bb_index; | 39 | size_t old_bb_index; |
| 39 | size_t instruction_index; | 40 | size_t instruction_index; |
| ... | @@ -476,17 +477,17 @@ static void ira_deref(IrAnalyze *ira) { | ... | @@ -476,17 +477,17 @@ static void ira_deref(IrAnalyze *ira) { |
| 476 | } | 477 | } |
| 477 | assert(ira->ref_count != 0); | 478 | assert(ira->ref_count != 0); |
| 478 | | 479 | |
| 479 | for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) { | 480 | for (size_t bb_i = 0; bb_i < ira->zir->basic_block_list.length; bb_i += 1) { |
| 480 | IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i]; | 481 | IrBasicBlockSrc *pass1_bb = ira->zir->basic_block_list.items[bb_i]; |
| 481 | for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) { | 482 | for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) { |
| 482 | IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i]; | 483 | IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i]; |
| 483 | destroy_instruction_src(pass1_inst); | 484 | destroy_instruction_src(pass1_inst); |
| 484 | } | 485 | } |
| 485 | heap::c_allocator.destroy(pass1_bb); | 486 | heap::c_allocator.destroy(pass1_bb); |
| 486 | } | 487 | } |
| 487 | ira->old_irb.exec->basic_block_list.deinit(); | 488 | ira->zir->basic_block_list.deinit(); |
| 488 | ira->old_irb.exec->tld_list.deinit(); | 489 | ira->zir->tld_list.deinit(); |
| 489 | heap::c_allocator.destroy(ira->old_irb.exec); | 490 | heap::c_allocator.destroy(ira->zir); |
| 490 | ira->src_implicit_return_type_list.deinit(); | 491 | ira->src_implicit_return_type_list.deinit(); |
| 491 | ira->resume_stack.deinit(); | 492 | ira->resume_stack.deinit(); |
| 492 | | 493 | |
| ... | @@ -2630,7 +2631,7 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *ex | ... | @@ -2630,7 +2631,7 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *ex |
| 2630 | } | 2631 | } |
| 2631 | | 2632 | |
| 2632 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) { | 2633 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) { |
| 2633 | if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) { | 2634 | if (ir_should_inline(ira->zir, source_instruction->scope)) { |
| 2634 | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); | 2635 | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); |
| 2635 | return false; | 2636 | return false; |
| 2636 | } | 2637 | } |
| ... | @@ -5287,7 +5288,7 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *o | ... | @@ -5287,7 +5288,7 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *o |
| 5287 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) { | 5288 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) { |
| 5288 | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr); | 5289 | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr); |
| 5289 | ira->instruction_index = 0; | 5290 | ira->instruction_index = 0; |
| 5290 | ira->old_irb.current_basic_block = old_bb; | 5291 | ira->zir_current_basic_block = old_bb; |
| 5291 | ira->const_predecessor_bb = const_predecessor_bb; | 5292 | ira->const_predecessor_bb = const_predecessor_bb; |
| 5292 | ira->old_bb_index = old_bb->index; | 5293 | ira->old_bb_index = old_bb->index; |
| 5293 | } | 5294 | } |
| ... | @@ -5297,23 +5298,23 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBl | ... | @@ -5297,23 +5298,23 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBl |
| 5297 | { | 5298 | { |
| 5298 | if (ira->codegen->verbose_ir) { | 5299 | if (ira->codegen->verbose_ir) { |
| 5299 | fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n", | 5300 | fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n", |
| 5300 | ira->old_irb.current_basic_block->name_hint, | 5301 | ira->zir_current_basic_block->name_hint, |
| 5301 | ira->old_irb.current_basic_block->debug_id, | 5302 | ira->zir_current_basic_block->debug_id, |
| 5302 | ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint, | 5303 | ira->zir->basic_block_list.at(ira->old_bb_index)->name_hint, |
| 5303 | ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id, | 5304 | ira->zir->basic_block_list.at(ira->old_bb_index)->debug_id, |
| 5304 | ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id, | 5305 | ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id, |
| 5305 | ira->old_bb_index, ira->instruction_index); | 5306 | ira->old_bb_index, ira->instruction_index); |
| 5306 | } | 5307 | } |
| 5307 | suspend_pos->basic_block_index = ira->old_bb_index; | 5308 | suspend_pos->basic_block_index = ira->old_bb_index; |
| 5308 | suspend_pos->instruction_index = ira->instruction_index; | 5309 | suspend_pos->instruction_index = ira->instruction_index; |
| 5309 | | 5310 | |
| 5310 | ira->old_irb.current_basic_block->suspended = true; | 5311 | ira->zir_current_basic_block->suspended = true; |
| 5311 | | 5312 | |
| 5312 | // null next_bb means that the caller plans to call ira_resume before returning | 5313 | // null next_bb means that the caller plans to call ira_resume before returning |
| 5313 | if (next_bb != nullptr) { | 5314 | if (next_bb != nullptr) { |
| 5314 | ira->old_bb_index = next_bb->index; | 5315 | ira->old_bb_index = next_bb->index; |
| 5315 | ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); | 5316 | ira->zir_current_basic_block = ira->zir->basic_block_list.at(ira->old_bb_index); |
| 5316 | assert(ira->old_irb.current_basic_block == next_bb); | 5317 | assert(ira->zir_current_basic_block == next_bb); |
| 5317 | ira->instruction_index = 0; | 5318 | ira->instruction_index = 0; |
| 5318 | ira->const_predecessor_bb = nullptr; | 5319 | ira->const_predecessor_bb = nullptr; |
| 5319 | next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction); | 5320 | next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction); |
| ... | @@ -5328,19 +5329,19 @@ static IrInstGen *ira_resume(IrAnalyze *ira) { | ... | @@ -5328,19 +5329,19 @@ static IrInstGen *ira_resume(IrAnalyze *ira) { |
| 5328 | fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index); | 5329 | fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index); |
| 5329 | } | 5330 | } |
| 5330 | ira->old_bb_index = pos.basic_block_index; | 5331 | ira->old_bb_index = pos.basic_block_index; |
| 5331 | ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); | 5332 | ira->zir_current_basic_block = ira->zir->basic_block_list.at(ira->old_bb_index); |
| 5332 | assert(ira->old_irb.current_basic_block->in_resume_stack); | 5333 | assert(ira->zir_current_basic_block->in_resume_stack); |
| 5333 | ira->old_irb.current_basic_block->in_resume_stack = false; | 5334 | ira->zir_current_basic_block->in_resume_stack = false; |
| 5334 | ira->old_irb.current_basic_block->suspended = false; | 5335 | ira->zir_current_basic_block->suspended = false; |
| 5335 | ira->instruction_index = pos.instruction_index; | 5336 | ira->instruction_index = pos.instruction_index; |
| 5336 | assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length); | 5337 | assert(pos.instruction_index < ira->zir_current_basic_block->instruction_list.length); |
| 5337 | if (ira->codegen->verbose_ir) { | 5338 | if (ira->codegen->verbose_ir) { |
| 5338 | fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint, | 5339 | fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->zir_current_basic_block->name_hint, |
| 5339 | ira->old_irb.current_basic_block->debug_id, | 5340 | ira->zir_current_basic_block->debug_id, |
| 5340 | ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id); | 5341 | ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id); |
| 5341 | } | 5342 | } |
| 5342 | ira->const_predecessor_bb = nullptr; | 5343 | ira->const_predecessor_bb = nullptr; |
| 5343 | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child; | 5344 | ira->new_irb.current_basic_block = ira->zir_current_basic_block->child; |
| 5344 | assert(ira->new_irb.current_basic_block != nullptr); | 5345 | assert(ira->new_irb.current_basic_block != nullptr); |
| 5345 | return ira->codegen->unreach_instruction; | 5346 | return ira->codegen->unreach_instruction; |
| 5346 | } | 5347 | } |
| ... | @@ -5350,8 +5351,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { | ... | @@ -5350,8 +5351,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 5350 | | 5351 | |
| 5351 | bool need_repeat = true; | 5352 | bool need_repeat = true; |
| 5352 | for (;;) { | 5353 | for (;;) { |
| 5353 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { | 5354 | while (ira->old_bb_index < ira->zir->basic_block_list.length) { |
| 5354 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); | 5355 | IrBasicBlockSrc *old_bb = ira->zir->basic_block_list.at(ira->old_bb_index); |
| 5355 | if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) { | 5356 | if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) { |
| 5356 | ira->old_bb_index += 1; | 5357 | ira->old_bb_index += 1; |
| 5357 | continue; | 5358 | continue; |
| ... | @@ -5403,8 +5404,8 @@ static void ir_finish_bb(IrAnalyze *ira) { | ... | @@ -5403,8 +5404,8 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 5403 | } | 5404 | } |
| 5404 | } | 5405 | } |
| 5405 | ira->instruction_index += 1; | 5406 | ira->instruction_index += 1; |
| 5406 | while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) { | 5407 | while (ira->instruction_index < ira->zir_current_basic_block->instruction_list.length) { |
| 5407 | IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 5408 | IrInstSrc *next_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index); |
| 5408 | if (!next_instruction->is_gen) { | 5409 | if (!next_instruction->is_gen) { |
| 5409 | ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code")); | 5410 | ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code")); |
| 5410 | break; | 5411 | break; |
| ... | @@ -5443,13 +5444,13 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) | ... | @@ -5443,13 +5444,13 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) |
| 5443 | } | 5444 | } |
| 5444 | | 5445 | |
| 5445 | static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) { | 5446 | static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) { |
| 5446 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { | 5447 | if (old_bb->debug_id <= ira->zir_current_basic_block->debug_id) { |
| 5447 | if (!ir_emit_backward_branch(ira, source_instruction)) | 5448 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 5448 | return ir_unreach_error(ira); | 5449 | return ir_unreach_error(ira); |
| 5449 | } | 5450 | } |
| 5450 | | 5451 | |
| 5451 | old_bb->child = ira->old_irb.current_basic_block->child; | 5452 | old_bb->child = ira->zir_current_basic_block->child; |
| 5452 | ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block); | 5453 | ir_start_bb(ira, old_bb, ira->zir_current_basic_block); |
| 5453 | return ira->codegen->unreach_instruction; | 5454 | return ira->codegen->unreach_instruction; |
| 5454 | } | 5455 | } |
| 5455 | | 5456 | |
| ... | @@ -5587,7 +5588,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -5587,7 +5588,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 5587 | if (type_is_invalid(return_ptr->type)) | 5588 | if (type_is_invalid(return_ptr->type)) |
| 5588 | return ErrorSemanticAnalyzeFail; | 5589 | return ErrorSemanticAnalyzeFail; |
| 5589 | | 5590 | |
| 5590 | IrExecutableSrc *ir_executable = heap::c_allocator.create<IrExecutableSrc>(); | 5591 | Stage1Zir *ir_executable = heap::c_allocator.create<Stage1Zir>(); |
| 5591 | ir_executable->source_node = source_node; | 5592 | ir_executable->source_node = source_node; |
| 5592 | ir_executable->parent_exec = parent_exec; | 5593 | ir_executable->parent_exec = parent_exec; |
| 5593 | ir_executable->name = exec_name; | 5594 | ir_executable->name = exec_name; |
| ... | @@ -6914,7 +6915,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou | ... | @@ -6914,7 +6915,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6914 | size_t instr_field_count = actual_type->data.structure.src_field_count; | 6915 | size_t instr_field_count = actual_type->data.structure.src_field_count; |
| 6915 | assert(array_len == instr_field_count); | 6916 | assert(array_len == instr_field_count); |
| 6916 | | 6917 | |
| 6917 | bool need_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope) | 6918 | bool need_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 6918 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; | 6919 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; |
| 6919 | bool is_comptime = true; | 6920 | bool is_comptime = true; |
| 6920 | | 6921 | |
| ... | @@ -7004,7 +7005,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so | ... | @@ -7004,7 +7005,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7004 | size_t actual_field_count = wanted_type->data.structure.src_field_count; | 7005 | size_t actual_field_count = wanted_type->data.structure.src_field_count; |
| 7005 | size_t instr_field_count = actual_type->data.structure.src_field_count; | 7006 | size_t instr_field_count = actual_type->data.structure.src_field_count; |
| 7006 | | 7007 | |
| 7007 | bool need_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope) | 7008 | bool need_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 7008 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; | 7009 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; |
| 7009 | bool is_comptime = true; | 7010 | bool is_comptime = true; |
| 7010 | | 7011 | |
| ... | @@ -11419,7 +11420,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern | ... | @@ -11419,7 +11420,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11419 | is_thread_local, expr_type); | 11420 | is_thread_local, expr_type); |
| 11420 | } | 11421 | } |
| 11421 | | 11422 | |
| 11422 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) { | 11423 | static bool exec_has_err_ret_trace(CodeGen *g, Stage1Zir *exec) { |
| 11423 | ZigFn *fn_entry = exec->fn_entry; | 11424 | ZigFn *fn_entry = exec->fn_entry; |
| 11424 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; | 11425 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 11425 | } | 11426 | } |
| ... | @@ -11430,7 +11431,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, | ... | @@ -11430,7 +11431,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 11430 | ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false); | 11431 | ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false); |
| 11431 | if (instruction->optional == IrInstErrorReturnTraceNull) { | 11432 | if (instruction->optional == IrInstErrorReturnTraceNull) { |
| 11432 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); | 11433 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 11433 | if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) { | 11434 | if (!exec_has_err_ret_trace(ira->codegen, ira->zir)) { |
| 11434 | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); | 11435 | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); |
| 11435 | ZigValue *out_val = result->value; | 11436 | ZigValue *out_val = result->value; |
| 11436 | assert(get_src_ptr_type(optional_type) != nullptr); | 11437 | assert(get_src_ptr_type(optional_type) != nullptr); |
| ... | @@ -13213,7 +13214,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -13213,7 +13214,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13213 | return ira->codegen->invalid_inst_gen; | 13214 | return ira->codegen->invalid_inst_gen; |
| 13214 | CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag); | 13215 | CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag); |
| 13215 | | 13216 | |
| 13216 | if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) { | 13217 | if (ir_should_inline(ira->zir, source_instr->scope)) { |
| 13217 | switch (modifier) { | 13218 | switch (modifier) { |
| 13218 | case CallModifierBuiltin: | 13219 | case CallModifierBuiltin: |
| 13219 | zig_unreachable(); | 13220 | zig_unreachable(); |
| ... | @@ -13302,7 +13303,7 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins | ... | @@ -13302,7 +13303,7 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins |
| 13302 | if (type_is_invalid(fn_ref->value->type)) | 13303 | if (type_is_invalid(fn_ref->value->type)) |
| 13303 | return ira->codegen->invalid_inst_gen; | 13304 | return ira->codegen->invalid_inst_gen; |
| 13304 | | 13305 | |
| 13305 | if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) { | 13306 | if (ir_should_inline(ira->zir, source_instr->scope)) { |
| 13306 | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @asyncCall")); | 13307 | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @asyncCall")); |
| 13307 | return ira->codegen->invalid_inst_gen; | 13308 | return ira->codegen->invalid_inst_gen; |
| 13308 | } | 13309 | } |
| ... | @@ -13415,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal | ... | @@ -13415,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 13415 | return ira->codegen->invalid_inst_gen; | 13416 | return ira->codegen->invalid_inst_gen; |
| 13416 | | 13417 | |
| 13417 | bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) || | 13418 | bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) || |
| 13418 | ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope); | 13419 | ir_should_inline(ira->zir, call_instruction->base.base.scope); |
| 13419 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; | 13420 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 13420 | | 13421 | |
| 13421 | if (is_comptime || instr_is_comptime(fn_ref)) { | 13422 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| ... | @@ -13777,7 +13778,7 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in | ... | @@ -13777,7 +13778,7 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in |
| 13777 | } | 13778 | } |
| 13778 | | 13779 | |
| 13779 | static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) { | 13780 | static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) { |
| 13780 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index); | 13781 | IrBasicBlockSrc *old_bb = ira->zir->basic_block_list.at(pos.basic_block_index); |
| 13781 | if (old_bb->in_resume_stack) return; | 13782 | if (old_bb->in_resume_stack) return; |
| 13782 | ira->resume_stack.append(pos); | 13783 | ira->resume_stack.append(pos); |
| 13783 | old_bb->in_resume_stack = true; | 13784 | old_bb->in_resume_stack = true; |
| ... | @@ -13864,7 +13865,7 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr | ... | @@ -13864,7 +13865,7 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr |
| 13864 | static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira, | 13865 | static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 13865 | IrInstSrcUnreachable *unreachable_instruction) | 13866 | IrInstSrcUnreachable *unreachable_instruction) |
| 13866 | { | 13867 | { |
| 13867 | if (ir_should_inline(ira->old_irb.exec, unreachable_instruction->base.base.scope)) { | 13868 | if (ir_should_inline(ira->zir, unreachable_instruction->base.base.scope)) { |
| 13868 | ir_add_error(ira, &unreachable_instruction->base.base, buf_sprintf("reached unreachable code")); | 13869 | ir_add_error(ira, &unreachable_instruction->base.base, buf_sprintf("reached unreachable code")); |
| 13869 | return ir_unreach_error(ira); | 13870 | return ir_unreach_error(ira); |
| 13870 | } | 13871 | } |
| ... | @@ -16479,7 +16480,7 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi | ... | @@ -16479,7 +16480,7 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi |
| 16479 | } | 16480 | } |
| 16480 | } | 16481 | } |
| 16481 | | 16482 | |
| 16482 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope) | 16483 | bool is_comptime = ir_should_inline(ira->zir, source_instruction->scope) |
| 16483 | || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes; | 16484 | || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes; |
| 16484 | | 16485 | |
| 16485 | IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); | 16486 | IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| ... | @@ -16532,7 +16533,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc | ... | @@ -16532,7 +16533,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16532 | AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count); | 16533 | AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count); |
| 16533 | ZigList<IrInstGen *> const_ptrs = {}; | 16534 | ZigList<IrInstGen *> const_ptrs = {}; |
| 16534 | | 16535 | |
| 16535 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope) | 16536 | bool is_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 16536 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; | 16537 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; |
| 16537 | | 16538 | |
| 16538 | | 16539 | |
| ... | @@ -16719,7 +16720,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, | ... | @@ -16719,7 +16720,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16719 | case ReqCompTimeInvalid: | 16720 | case ReqCompTimeInvalid: |
| 16720 | return ira->codegen->invalid_inst_gen; | 16721 | return ira->codegen->invalid_inst_gen; |
| 16721 | case ReqCompTimeNo: | 16722 | case ReqCompTimeNo: |
| 16722 | is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope); | 16723 | is_comptime = ir_should_inline(ira->zir, instruction->base.base.scope); |
| 16723 | break; | 16724 | break; |
| 16724 | case ReqCompTimeYes: | 16725 | case ReqCompTimeYes: |
| 16725 | is_comptime = true; | 16726 | is_comptime = true; |
| ... | @@ -18491,7 +18492,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -18491,7 +18492,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18491 | | 18492 | |
| 18492 | Buf *bare_name = buf_alloc(); | 18493 | Buf *bare_name = buf_alloc(); |
| 18493 | Buf *full_name = get_anon_type_name(ira->codegen, | 18494 | Buf *full_name = get_anon_type_name(ira->codegen, |
| 18494 | ira->old_irb.exec, "opaque", source_instr->scope, source_instr->source_node, bare_name); | 18495 | ira->zir, "opaque", source_instr->scope, source_instr->source_node, bare_name); |
| 18495 | return get_opaque_type(ira->codegen, | 18496 | return get_opaque_type(ira->codegen, |
| 18496 | source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name); | 18497 | source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name); |
| 18497 | } | 18498 | } |
| ... | @@ -18538,7 +18539,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -18538,7 +18539,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18538 | assert(is_slice(slice->type)); | 18539 | assert(is_slice(slice->type)); |
| 18539 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); | 18540 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 18540 | Buf bare_name = BUF_INIT; | 18541 | Buf bare_name = BUF_INIT; |
| 18541 | buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->old_irb.exec, "error", source_instr->scope, source_instr->source_node, &bare_name)); | 18542 | 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)); |
| 18542 | err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits; | 18543 | err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits; |
| 18543 | err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align; | 18544 | err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align; |
| 18544 | err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size; | 18545 | err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size; |
| ... | @@ -18617,7 +18618,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -18617,7 +18618,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18617 | | 18618 | |
| 18618 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); | 18619 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); |
| 18619 | buf_init_from_buf(&entry->name, | 18620 | buf_init_from_buf(&entry->name, |
| 18620 | get_anon_type_name(ira->codegen, ira->old_irb.exec, "struct", source_instr->scope, source_instr->source_node, &entry->name)); | 18621 | get_anon_type_name(ira->codegen, ira->zir, "struct", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18621 | entry->data.structure.decl_node = source_instr->source_node; | 18622 | entry->data.structure.decl_node = source_instr->source_node; |
| 18622 | entry->data.structure.fields = alloc_type_struct_fields(fields_len); | 18623 | entry->data.structure.fields = alloc_type_struct_fields(fields_len); |
| 18623 | entry->data.structure.fields_by_name.init(fields_len); | 18624 | entry->data.structure.fields_by_name.init(fields_len); |
| ... | @@ -18727,7 +18728,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -18727,7 +18728,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18727 | | 18728 | |
| 18728 | ZigType *entry = new_type_table_entry(ZigTypeIdEnum); | 18729 | ZigType *entry = new_type_table_entry(ZigTypeIdEnum); |
| 18729 | buf_init_from_buf(&entry->name, | 18730 | buf_init_from_buf(&entry->name, |
| 18730 | get_anon_type_name(ira->codegen, ira->old_irb.exec, "enum", source_instr->scope, source_instr->source_node, &entry->name)); | 18731 | get_anon_type_name(ira->codegen, ira->zir, "enum", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18731 | entry->data.enumeration.decl_node = source_instr->source_node; | 18732 | entry->data.enumeration.decl_node = source_instr->source_node; |
| 18732 | entry->data.enumeration.tag_int_type = tag_type; | 18733 | entry->data.enumeration.tag_int_type = tag_type; |
| 18733 | entry->data.enumeration.decls_scope = create_decls_scope( | 18734 | entry->data.enumeration.decls_scope = create_decls_scope( |
| ... | @@ -18809,7 +18810,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -18809,7 +18810,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18809 | | 18810 | |
| 18810 | ZigType *entry = new_type_table_entry(ZigTypeIdUnion); | 18811 | ZigType *entry = new_type_table_entry(ZigTypeIdUnion); |
| 18811 | buf_init_from_buf(&entry->name, | 18812 | buf_init_from_buf(&entry->name, |
| 18812 | get_anon_type_name(ira->codegen, ira->old_irb.exec, "union", source_instr->scope, source_instr->source_node, &entry->name)); | 18813 | get_anon_type_name(ira->codegen, ira->zir, "union", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18813 | entry->data.unionation.decl_node = source_instr->source_node; | 18814 | entry->data.unionation.decl_node = source_instr->source_node; |
| 18814 | entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len); | 18815 | entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len); |
| 18815 | entry->data.unionation.fields_by_name.init(fields_len); | 18816 | entry->data.unionation.fields_by_name.init(fields_len); |
| ... | @@ -22004,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i | ... | @@ -22004,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i |
| 22004 | if (type_is_invalid(msg->value->type)) | 22005 | if (type_is_invalid(msg->value->type)) |
| 22005 | return ir_unreach_error(ira); | 22006 | return ir_unreach_error(ira); |
| 22006 | | 22007 | |
| 22007 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) { | 22008 | if (ir_should_inline(ira->zir, instruction->base.base.scope)) { |
| 22008 | ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time")); | 22009 | ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time")); |
| 22009 | return ir_unreach_error(ira); | 22010 | return ir_unreach_error(ira); |
| 22010 | } | 22011 | } |
| ... | @@ -24077,7 +24078,7 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume | ... | @@ -24077,7 +24078,7 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume |
| 24077 | } | 24078 | } |
| 24078 | | 24079 | |
| 24079 | static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) { | 24080 | static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) { |
| 24080 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) | 24081 | if (ir_should_inline(ira->zir, instruction->base.base.scope)) |
| 24081 | return ir_const_void(ira, &instruction->base.base); | 24082 | return ir_const_void(ira, &instruction->base.base); |
| 24082 | | 24083 | |
| 24083 | IrInstGen *operand = instruction->operand->child; | 24084 | IrInstGen *operand = instruction->operand->child; |
| ... | @@ -24103,7 +24104,7 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil | ... | @@ -24103,7 +24104,7 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil |
| 24103 | if (type_is_invalid(operand->value->type)) | 24104 | if (type_is_invalid(operand->value->type)) |
| 24104 | return ira->codegen->invalid_inst_gen; | 24105 | return ira->codegen->invalid_inst_gen; |
| 24105 | | 24106 | |
| 24106 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || | 24107 | if (ir_should_inline(ira->zir, instruction->base.base.scope) || |
| 24107 | !type_has_bits(ira->codegen, operand->value->type) || | 24108 | !type_has_bits(ira->codegen, operand->value->type) || |
| 24108 | instr_is_comptime(operand)) | 24109 | instr_is_comptime(operand)) |
| 24109 | { | 24110 | { |
| ... | @@ -24467,7 +24468,7 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc | ... | @@ -24467,7 +24468,7 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc |
| 24467 | | 24468 | |
| 24468 | // This function attempts to evaluate IR code while doing type checking and other analysis. | 24469 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 24469 | // It emits to a new IrExecutableGen which is partially evaluated IR code. | 24470 | // It emits to a new IrExecutableGen which is partially evaluated IR code. |
| 24470 | ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec, | 24471 | ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *old_exec, IrExecutableGen *new_exec, |
| 24471 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) | 24472 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) |
| 24472 | { | 24473 | { |
| 24473 | assert(old_exec->first_err_trace_msg == nullptr); | 24474 | assert(old_exec->first_err_trace_msg == nullptr); |
| ... | @@ -24481,13 +24482,12 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen | ... | @@ -24481,13 +24482,12 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen |
| 24481 | ira->explicit_return_type = expected_type; | 24482 | ira->explicit_return_type = expected_type; |
| 24482 | ira->explicit_return_type_source_node = expected_type_source_node; | 24483 | ira->explicit_return_type_source_node = expected_type_source_node; |
| 24483 | | 24484 | |
| 24484 | ira->old_irb.codegen = codegen; | 24485 | ira->zir = old_exec; |
| 24485 | ira->old_irb.exec = old_exec; | | |
| 24486 | | 24486 | |
| 24487 | ira->new_irb.codegen = codegen; | 24487 | ira->new_irb.codegen = codegen; |
| 24488 | ira->new_irb.exec = new_exec; | 24488 | ira->new_irb.exec = new_exec; |
| 24489 | | 24489 | |
| 24490 | IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); | 24490 | IrBasicBlockSrc *old_entry_bb = ira->zir->basic_block_list.at(0); |
| 24491 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); | 24491 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 24492 | ira->new_irb.current_basic_block = new_entry_bb; | 24492 | ira->new_irb.current_basic_block = new_entry_bb; |
| 24493 | ira->old_bb_index = 0; | 24493 | ira->old_bb_index = 0; |
| ... | @@ -24507,8 +24507,8 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen | ... | @@ -24507,8 +24507,8 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen |
| 24507 | get_pointer_to_type(codegen, expected_type, false)); | 24507 | get_pointer_to_type(codegen, expected_type, false)); |
| 24508 | } | 24508 | } |
| 24509 | | 24509 | |
| 24510 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { | 24510 | while (ira->old_bb_index < ira->zir->basic_block_list.length) { |
| 24511 | IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 24511 | IrInstSrc *old_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index); |
| 24512 | | 24512 | |
| 24513 | if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { | 24513 | if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { |
| 24514 | ira->instruction_index += 1; | 24514 | ira->instruction_index += 1; |