authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-20 18:03:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-20 18:03:55-04:00
log057b105fadb1b60d0927cb878e795c9e7ac9bdb1
tree2c59db03a6222d653a5b4a558da473a86fef40ca
parent3c541d7be38d625645276f8a0dee57774fe94134
signaturelock-open Commit is signed but in an unrecognized format.

one more test passing


3 files changed, 60 insertions(+), 37 deletions(-)

src/all_types.hpp+1
......@@ -2157,6 +2157,7 @@ struct IrBasicBlock {
21572157 IrInstruction *suspend_instruction_ref;
21582158 bool already_appended;
21592159 bool suspended;
2160 bool in_resume_stack;
21602161};
21612162
21622163// These instructions are in transition to having "pass 1" instructions
src/ir.cpp+58-36
......@@ -6958,6 +6958,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
69586958 peer_parent->peers = allocate<ResultLocPeer>(prong_count);
69596959 peer_parent->peer_count = 0;
69606960
6961 ir_build_reset_result(irb, scope, node, &peer_parent->base);
6962
69616963 // First do the else and the ranges
69626964 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
69636965 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
......@@ -7117,8 +7119,6 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
71177119 IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
71187120 check_ranges.items, check_ranges.length, else_prong != nullptr);
71197121
7120 ir_build_reset_result(irb, scope, node, &peer_parent->base);
7121
71227122 IrInstruction *br_instruction;
71237123 if (cases.length == 0) {
71247124 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);
......@@ -10880,6 +10880,7 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,
1088010880}
1088110881
1088210882static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
10883 assert(!old_bb->suspended);
1088310884 ira->instruction_index = 0;
1088410885 ira->old_irb.current_basic_block = old_bb;
1088510886 ira->const_predecessor_bb = const_predecessor_bb;
......@@ -10889,20 +10890,14 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons
1088910890static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
1089010891 IrSuspendPosition *suspend_pos)
1089110892{
10892 // reserve block position
10893 if (!ira->new_irb.current_basic_block->already_appended) {
10894 ira->new_irb.current_basic_block->already_appended = true;
10895 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
10893 if (ira->codegen->verbose_ir) {
10894 fprintf(stderr, "suspend %s_%zu %s_%zu #%zu (%zu,%zu)\n", ira->old_irb.current_basic_block->name_hint,
10895 ira->old_irb.current_basic_block->debug_id,
10896 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
10897 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
10898 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
10899 ira->old_bb_index, ira->instruction_index);
1089610900 }
10897
10898 //if (ira->codegen->verbose_ir) {
10899 // fprintf(stderr, "suspend %s_%zu %s_%zu #%zu (%zu,%zu)\n", ira->old_irb.current_basic_block->name_hint,
10900 // ira->old_irb.current_basic_block->debug_id,
10901 // ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
10902 // ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
10903 // ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
10904 // ira->old_bb_index, ira->instruction_index);
10905 //}
1090610901 suspend_pos->basic_block_index = ira->old_bb_index;
1090710902 suspend_pos->instruction_index = ira->instruction_index;
1090810903
......@@ -10923,19 +10918,21 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1092310918
1092410919static IrInstruction *ira_resume(IrAnalyze *ira) {
1092510920 IrSuspendPosition pos = ira->resume_stack.pop();
10926 //if (ira->codegen->verbose_ir) {
10927 // fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
10928 //}
10921 if (ira->codegen->verbose_ir) {
10922 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
10923 }
1092910924 ira->old_bb_index = pos.basic_block_index;
1093010925 ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
10926 assert(ira->old_irb.current_basic_block->in_resume_stack);
10927 ira->old_irb.current_basic_block->in_resume_stack = false;
1093110928 ira->old_irb.current_basic_block->suspended = false;
1093210929 ira->instruction_index = pos.instruction_index;
1093310930 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
10934 //if (ira->codegen->verbose_ir) {
10935 // fprintf(stderr, "%s_%zu #%zu\n", ira->old_irb.current_basic_block->name_hint,
10936 // ira->old_irb.current_basic_block->debug_id,
10937 // ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
10938 //}
10931 if (ira->codegen->verbose_ir) {
10932 fprintf(stderr, "%s_%zu #%zu\n", ira->old_irb.current_basic_block->name_hint,
10933 ira->old_irb.current_basic_block->debug_id,
10934 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
10935 }
1093910936 ira->const_predecessor_bb = nullptr;
1094010937 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
1094110938 assert(ira->new_irb.current_basic_block != nullptr);
......@@ -10945,6 +10942,10 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {
1094510942static void ir_finish_bb(IrAnalyze *ira) {
1094610943 if (!ira->new_irb.current_basic_block->already_appended) {
1094710944 ira->new_irb.current_basic_block->already_appended = true;
10945 if (ira->codegen->verbose_ir) {
10946 fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint,
10947 ira->new_irb.current_basic_block->debug_id);
10948 }
1094810949 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
1094910950 }
1095010951 ira->instruction_index += 1;
......@@ -10957,7 +10958,6 @@ static void ir_finish_bb(IrAnalyze *ira) {
1095710958 ira->instruction_index += 1;
1095810959 }
1095910960
10960 size_t my_old_bb_index = ira->old_bb_index;
1096110961 ira->old_bb_index += 1;
1096210962
1096310963 bool need_repeat = true;
......@@ -10968,17 +10968,17 @@ static void ir_finish_bb(IrAnalyze *ira) {
1096810968 ira->old_bb_index += 1;
1096910969 continue;
1097010970 }
10971 // If it's the block we just finished, or
10972 // if it's already a finished block, or
10971 // if it's already started, or
1097310972 // if it's a suspended block,
1097410973 // then skip it
10975 if (ira->old_bb_index == my_old_bb_index ||
10976 old_bb->suspended ||
10977 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0))
10974 if (old_bb->suspended ||
10975 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) ||
10976 (old_bb->other != nullptr && old_bb->other->already_appended))
1097810977 {
1097910978 ira->old_bb_index += 1;
1098010979 continue;
1098110980 }
10981
1098210982 // if there is a resume_stack, pop one from there rather than moving on.
1098310983 // the last item of the resume stack will be a basic block that will
1098410984 // move on to the next one below
......@@ -15520,7 +15520,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1552015520 // ConstPtrMutComptimeVar, thus defeating the logic below.
1552115521 bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar;
1552215522 copy_const_val(dest_val, &value->value, same_global_refs);
15523 if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
15523 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar &&
15524 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
15525 {
1552415526 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;
1552515527 }
1552615528 return ir_const_void(ira, source_instr);
......@@ -16484,6 +16486,19 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1648416486 zig_unreachable();
1648516487}
1648616488
16489static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {
16490 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
16491 if (old_bb->in_resume_stack) return;
16492 ira->resume_stack.append(pos);
16493 old_bb->in_resume_stack = true;
16494}
16495
16496static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) {
16497 if (ira->resume_stack.length != 0) {
16498 ir_push_resume(ira, {old_bb->index, 0});
16499 }
16500}
16501
1648716502static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
1648816503 IrBasicBlock *old_dest_block = br_instruction->dest_block;
1648916504
......@@ -16498,6 +16513,8 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
1649816513 if (new_bb == nullptr)
1649916514 return ir_unreach_error(ira);
1650016515
16516 ir_push_resume_block(ira, old_dest_block);
16517
1650116518 IrInstruction *result = ir_build_br(&ira->new_irb,
1650216519 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
1650316520 result->value.type = ira->codegen->builtin_types.entry_unreachable;
......@@ -16526,13 +16543,15 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1652616543 IrBasicBlock *old_dest_block = cond_is_true ?
1652716544 cond_br_instruction->then_block : cond_br_instruction->else_block;
1652816545
16529 if (is_comptime || old_dest_block->ref_count == 1)
16546 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
1653016547 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);
1653116548
1653216549 IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
1653316550 if (new_dest_block == nullptr)
1653416551 return ir_unreach_error(ira);
1653516552
16553 ir_push_resume_block(ira, old_dest_block);
16554
1653616555 IrInstruction *result = ir_build_br(&ira->new_irb,
1653716556 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);
1653816557 result->value.type = ira->codegen->builtin_types.entry_unreachable;
......@@ -16548,6 +16567,9 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1654816567 if (new_else_block == nullptr)
1654916568 return ir_unreach_error(ira);
1655016569
16570 ir_push_resume_block(ira, cond_br_instruction->else_block);
16571 ir_push_resume_block(ira, cond_br_instruction->then_block);
16572
1655116573 IrInstruction *result = ir_build_cond_br(&ira->new_irb,
1655216574 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,
1655316575 casted_condition, new_then_block, new_else_block, nullptr);
......@@ -16643,14 +16665,14 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1664316665
1664416666 IrSuspendPosition suspend_pos;
1664516667 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);
16646 ira->resume_stack.append(suspend_pos);
16668 ir_push_resume(ira, suspend_pos);
1664716669
1664816670 for (size_t i = 0; i < peer_parent->peer_count; i += 1) {
1664916671 ResultLocPeer *opposite_peer = &peer_parent->peers[peer_parent->peer_count - i - 1];
1665016672 if (opposite_peer->base.implicit_elem_type != nullptr &&
1665116673 opposite_peer->base.implicit_elem_type->id != ZigTypeIdUnreachable)
1665216674 {
16653 ira->resume_stack.append(opposite_peer->suspend_pos);
16675 ir_push_resume(ira, opposite_peer->suspend_pos);
1665416676 }
1665516677 }
1665616678
......@@ -25017,9 +25039,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2501725039 continue;
2501825040 }
2501925041
25020 //if (ira->codegen->verbose_ir) {
25021 // fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
25022 //}
25042 if (ira->codegen->verbose_ir) {
25043 fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
25044 }
2502325045 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2502425046 if (new_instruction != nullptr) {
2502525047 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
test/stage1/behavior.zig+1-1
......@@ -80,7 +80,7 @@ comptime {
8080 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
8181 _ = @import("behavior/struct_contains_slice_of_itself.zig");
8282 _ = @import("behavior/switch.zig");
83 //_ = @import("behavior/switch_prong_err_enum.zig");
83 _ = @import("behavior/switch_prong_err_enum.zig");
8484 _ = @import("behavior/switch_prong_implicit_cast.zig");
8585 _ = @import("behavior/syntax.zig");
8686 _ = @import("behavior/this.zig");