| ... | ... | @@ -3885,11 +3885,12 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 3885 | 3885 | } |
| 3886 | 3886 | |
| 3887 | 3887 | static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_inst, |
| 3888 | | IrBasicBlock *else_block, IrBasicBlock *endif_block, ResultLoc *parent) |
| 3888 | IrBasicBlock *else_block, IrBasicBlock *endif_block, ResultLoc *parent, IrInstruction *is_comptime) |
| 3889 | 3889 | { |
| 3890 | 3890 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 3891 | 3891 | peer_parent->base.id = ResultLocIdPeerParent; |
| 3892 | 3892 | peer_parent->base.source_instruction = cond_br_inst; |
| 3893 | peer_parent->is_comptime = is_comptime; |
| 3893 | 3894 | peer_parent->parent = parent; |
| 3894 | 3895 | peer_parent->peer_count = 2; |
| 3895 | 3896 | peer_parent->peers = allocate<ResultLocPeer>(2); |
| ... | ... | @@ -3931,7 +3932,8 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3931 | 3932 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); |
| 3932 | 3933 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 3933 | 3934 | |
| 3934 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc); |
| 3935 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc, |
| 3936 | is_comptime); |
| 3935 | 3937 | |
| 3936 | 3938 | ir_set_cursor_at_end_and_append_block(irb, null_block); |
| 3937 | 3939 | IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, lval, &peer_parent->peers[0].base); |
| ... | ... | @@ -5438,7 +5440,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5438 | 5440 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition, |
| 5439 | 5441 | then_block, else_block, is_comptime); |
| 5440 | 5442 | |
| 5441 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, result_loc); |
| 5443 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, |
| 5444 | result_loc, is_comptime); |
| 5442 | 5445 | |
| 5443 | 5446 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 5444 | 5447 | |
| ... | ... | @@ -5459,6 +5462,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5459 | 5462 | return irb->codegen->invalid_instruction; |
| 5460 | 5463 | } else { |
| 5461 | 5464 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 5465 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers[1].base); |
| 5462 | 5466 | } |
| 5463 | 5467 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 5464 | 5468 | if (!instr_is_unreachable(else_expr_result)) |
| ... | ... | @@ -5930,7 +5934,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5930 | 5934 | cond_br_inst = is_err; // for the purposes of the source instruction to create_binary_result_peers |
| 5931 | 5935 | } |
| 5932 | 5936 | |
| 5933 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc); |
| 5937 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, |
| 5938 | result_loc, is_comptime); |
| 5934 | 5939 | |
| 5935 | 5940 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5936 | 5941 | if (var_symbol) { |
| ... | ... | @@ -6031,7 +6036,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6031 | 6036 | cond_br_inst = is_non_null; // for the purposes of source instruction for create_binary_result_peers |
| 6032 | 6037 | } |
| 6033 | 6038 | |
| 6034 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc); |
| 6039 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, |
| 6040 | result_loc, is_comptime); |
| 6035 | 6041 | |
| 6036 | 6042 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6037 | 6043 | IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false); |
| ... | ... | @@ -6113,7 +6119,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6113 | 6119 | cond_br_inst = cond_val; // for the source instruction arg to create_binary_result_peers |
| 6114 | 6120 | } |
| 6115 | 6121 | |
| 6116 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc); |
| 6122 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, |
| 6123 | result_loc, is_comptime); |
| 6117 | 6124 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6118 | 6125 | |
| 6119 | 6126 | ZigList<IrInstruction *> incoming_values = {0}; |
| ... | ... | @@ -6244,7 +6251,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6244 | 6251 | IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 6245 | 6252 | body_block, else_block, is_comptime)); |
| 6246 | 6253 | |
| 6247 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc); |
| 6254 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc, |
| 6255 | is_comptime); |
| 6248 | 6256 | |
| 6249 | 6257 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6250 | 6258 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false, PtrLenSingle); |
| ... | ... | @@ -6622,7 +6630,8 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 6622 | 6630 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 6623 | 6631 | then_block, else_block, is_comptime); |
| 6624 | 6632 | |
| 6625 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, result_loc); |
| 6633 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, |
| 6634 | result_loc, is_comptime); |
| 6626 | 6635 | |
| 6627 | 6636 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 6628 | 6637 | |
| ... | ... | @@ -6657,6 +6666,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 6657 | 6666 | return else_expr_result; |
| 6658 | 6667 | } else { |
| 6659 | 6668 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 6669 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers[1].base); |
| 6660 | 6670 | } |
| 6661 | 6671 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 6662 | 6672 | if (!instr_is_unreachable(else_expr_result)) |
| ... | ... | @@ -6702,7 +6712,8 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6702 | 6712 | IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); |
| 6703 | 6713 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 6704 | 6714 | |
| 6705 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, result_loc); |
| 6715 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, |
| 6716 | result_loc, is_comptime); |
| 6706 | 6717 | |
| 6707 | 6718 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 6708 | 6719 | |
| ... | ... | @@ -6752,6 +6763,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6752 | 6763 | return else_expr_result; |
| 6753 | 6764 | } else { |
| 6754 | 6765 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 6766 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers[1].base); |
| 6755 | 6767 | } |
| 6756 | 6768 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 6757 | 6769 | if (!instr_is_unreachable(else_expr_result)) |
| ... | ... | @@ -6863,6 +6875,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6863 | 6875 | |
| 6864 | 6876 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 6865 | 6877 | peer_parent->base.id = ResultLocIdPeerParent; |
| 6878 | peer_parent->is_comptime = is_comptime; |
| 6866 | 6879 | peer_parent->parent = result_loc; |
| 6867 | 6880 | peer_parent->peers = allocate<ResultLocPeer>(prong_count); |
| 6868 | 6881 | peer_parent->peer_count = 0; |
| ... | ... | @@ -7311,7 +7324,8 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7311 | 7324 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 7312 | 7325 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 7313 | 7326 | |
| 7314 | | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc); |
| 7327 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc, |
| 7328 | is_comptime); |
| 7315 | 7329 | |
| 7316 | 7330 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 7317 | 7331 | Scope *err_scope; |
| ... | ... | @@ -14880,8 +14894,10 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14880 | 14894 | ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(result_loc); |
| 14881 | 14895 | ResultLocPeerParent *peer_parent = result_peer->parent; |
| 14882 | 14896 | |
| 14883 | | if (ira->const_predecessor_bb) |
| 14884 | | return nullptr; |
| 14897 | bool is_comptime; |
| 14898 | if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_comptime)) |
| 14899 | return ira->codegen->invalid_instruction; |
| 14900 | if (is_comptime) return nullptr; |
| 14885 | 14901 | |
| 14886 | 14902 | if (peer_parent->resolved_type == nullptr) { |
| 14887 | 14903 | ResultLocPeer *last_peer = &peer_parent->peers[peer_parent->peer_count - 1]; |
| ... | ... | @@ -16357,6 +16373,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 16357 | 16373 | |
| 16358 | 16374 | ResultLocPeerParent *peer_parent = phi_instruction->peer_parent; |
| 16359 | 16375 | if (peer_parent != nullptr && peer_parent->resolved_type == nullptr) { |
| 16376 | bool is_comptime; |
| 16377 | if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_comptime)) |
| 16378 | return ira->codegen->invalid_instruction; |
| 16379 | if (is_comptime) goto skip_peer_stuff; |
| 16380 | |
| 16360 | 16381 | // Suspend the phi first so that it gets resumed last |
| 16361 | 16382 | IrSuspendPosition suspend_pos; |
| 16362 | 16383 | ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos); |
| ... | ... | @@ -16393,6 +16414,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 16393 | 16414 | |
| 16394 | 16415 | return ira_resume(ira); |
| 16395 | 16416 | } |
| 16417 | skip_peer_stuff: |
| 16396 | 16418 | |
| 16397 | 16419 | ZigList<IrBasicBlock*> new_incoming_blocks = {0}; |
| 16398 | 16420 | ZigList<IrInstruction*> new_incoming_values = {0}; |