authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 17:46:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-03 17:46:58-04:00
logeb8a132d23c5c2a365eb3a8034a381cb74c3436c
treed92dd1651af35c6a27ce8bdc5eea32d376365eec
parent735543d502d19152d4f834cc02207a8e4ddc378a
signaturelock-open Commit is signed but in an unrecognized format.

var types, alignment, and comptime


5 files changed, 141 insertions(+), 84 deletions(-)

BRANCH_TODO+47
...@@ -1,6 +1,14 @@...@@ -1,6 +1,14 @@
1Scratch pad for stuff to do before merging master1Scratch pad for stuff to do before merging master
2=================================================2=================================================
33
4 * alignment of consts
5 * implicit casts
6 * for loops
7 * switch expression
8 * struct initializations
9 * function call parameters
10 * bitCast
11
4look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated12look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
513
6migrate all the alloca_list to alloca_gen_list14migrate all the alloca_list to alloca_gen_list
...@@ -22,3 +30,42 @@ inferred comptime...@@ -22,3 +30,42 @@ inferred comptime
22 return ir_build_ref(irb, scope, value->source_node, value, false, false);30 return ir_build_ref(irb, scope, value->source_node, value, false, false);
2331
24handle if with no else32handle if with no else
33
34for loops:
35 IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr);
36
37 IrInstruction *elem_var_type;
38 if (node->data.for_expr.elem_is_ptr) {
39 elem_var_type = pointer_type;
40 } else {
41 elem_var_type = ir_build_ptr_type_child(irb, parent_scope, elem_node, pointer_type);
42 }
43 IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize);
44- do they need to have an implicit cast in there for the elem variable?
45static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {
46 IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node);
47 instruction->ptr = ptr;
48
49 ir_ref_instruction(ptr, irb->current_basic_block);
50
51 return &instruction->base;
52}
53
54static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node,
55 IrInstruction *value)
56{
57 IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>(
58 irb, scope, source_node);
59 instruction->value = value;
60
61 ir_ref_instruction(value, irb->current_basic_block);
62
63 return &instruction->base;
64}
65
66coroutines
67 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
68 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
69- implicit cast for the var decl
70 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
71 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
src/all_types.hpp+8-1
...@@ -2277,6 +2277,7 @@ enum IrInstructionId {...@@ -2277,6 +2277,7 @@ enum IrInstructionId {
2277 IrInstructionIdSetEvalBranchQuota,2277 IrInstructionIdSetEvalBranchQuota,
2278 IrInstructionIdPtrType,2278 IrInstructionIdPtrType,
2279 IrInstructionIdAlignCast,2279 IrInstructionIdAlignCast,
2280 IrInstructionIdImplicitCast,
2280 IrInstructionIdOpaqueType,2281 IrInstructionIdOpaqueType,
2281 IrInstructionIdSetAlignStack,2282 IrInstructionIdSetAlignStack,
2282 IrInstructionIdArgType,2283 IrInstructionIdArgType,
...@@ -3581,7 +3582,13 @@ struct IrInstructionEndExpr {...@@ -3581,7 +3582,13 @@ struct IrInstructionEndExpr {
35813582
3582 IrInstruction *value;3583 IrInstruction *value;
3583 ResultLoc *result_loc;3584 ResultLoc *result_loc;
3584 LVal lval;3585};
3586
3587struct IrInstructionImplicitCast {
3588 IrInstruction base;
3589
3590 IrInstruction *dest_type;
3591 IrInstruction *target;
3585};3592};
35863593
3587enum ResultLocId {3594enum ResultLocId {
src/codegen.cpp+1
...@@ -5612,6 +5612,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5612,6 +5612,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5612 case IrInstructionIdAllocaSrc:5612 case IrInstructionIdAllocaSrc:
5613 case IrInstructionIdEndExpr:5613 case IrInstructionIdEndExpr:
5614 case IrInstructionIdAllocaGen:5614 case IrInstructionIdAllocaGen:
5615 case IrInstructionIdImplicitCast:
5615 zig_unreachable();5616 zig_unreachable();
56165617
5617 case IrInstructionIdDeclVarGen:5618 case IrInstructionIdDeclVarGen:
src/ir.cpp+73-72
...@@ -891,6 +891,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {...@@ -891,6 +891,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
891 return IrInstructionIdAlignCast;891 return IrInstructionIdAlignCast;
892}892}
893893
894static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {
895 return IrInstructionIdImplicitCast;
896}
897
894static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {898static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {
895 return IrInstructionIdOpaqueType;899 return IrInstructionIdOpaqueType;
896}900}
...@@ -1574,17 +1578,15 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *...@@ -1574,17 +1578,15 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *
1574}1578}
15751579
1576static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,1580static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1577 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *ptr)1581 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)
1578{1582{
1579 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);1583 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
1580 decl_var_instruction->base.value.special = ConstValSpecialStatic;1584 decl_var_instruction->base.value.special = ConstValSpecialStatic;
1581 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;1585 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
1582 decl_var_instruction->var = var;1586 decl_var_instruction->var = var;
1583 decl_var_instruction->var_type = var_type;
1584 decl_var_instruction->align_value = align_value;1587 decl_var_instruction->align_value = align_value;
1585 decl_var_instruction->ptr = ptr;1588 decl_var_instruction->ptr = ptr;
15861589
1587 if (var_type != nullptr) ir_ref_instruction(var_type, irb->current_basic_block);
1588 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);1590 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
1589 ir_ref_instruction(ptr, irb->current_basic_block);1591 ir_ref_instruction(ptr, irb->current_basic_block);
15901592
...@@ -1655,27 +1657,6 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -1655,27 +1657,6 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
1655 return &instruction->base;1657 return &instruction->base;
1656}1658}
16571659
1658static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {
1659 IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node);
1660 instruction->ptr = ptr;
1661
1662 ir_ref_instruction(ptr, irb->current_basic_block);
1663
1664 return &instruction->base;
1665}
1666
1667static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node,
1668 IrInstruction *value)
1669{
1670 IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>(
1671 irb, scope, source_node);
1672 instruction->value = value;
1673
1674 ir_ref_instruction(value, irb->current_basic_block);
1675
1676 return &instruction->base;
1677}
1678
1679static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {1660static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {
1680 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);1661 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);
1681 instruction->is_cold = is_cold;1662 instruction->is_cold = is_cold;
...@@ -2780,6 +2761,19 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode...@@ -2780,6 +2761,19 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode
2780 return &instruction->base;2761 return &instruction->base;
2781}2762}
27822763
2764static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
2765 IrInstruction *dest_type, IrInstruction *target)
2766{
2767 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
2768 instruction->dest_type = dest_type;
2769 instruction->target = target;
2770
2771 ir_ref_instruction(dest_type, irb->current_basic_block);
2772 ir_ref_instruction(target, irb->current_basic_block);
2773
2774 return &instruction->base;
2775}
2776
2783static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {2777static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2784 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);2778 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);
27852779
...@@ -3199,11 +3193,10 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio...@@ -3199,11 +3193,10 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio
3199}3193}
32003194
3201static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,3195static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3202 IrInstruction *value, LVal lval, ResultLoc *result_loc)3196 IrInstruction *value, ResultLoc *result_loc)
3203{3197{
3204 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);3198 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);
3205 instruction->value = value;3199 instruction->value = value;
3206 instruction->lval = lval;
3207 instruction->result_loc = result_loc;3200 instruction->result_loc = result_loc;
32083201
3209 ir_ref_instruction(value, irb->current_basic_block);3202 ir_ref_instruction(value, irb->current_basic_block);
...@@ -5399,8 +5392,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode...@@ -5399,8 +5392,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode
5399}5392}
54005393
5401static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {5394static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {
5402 // TODO remove the lval parameter here5395 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);
5403 ir_build_end_expr(irb, scope, inst->source_node, inst, LValNone, result_loc);
5404 return inst;5396 return inst;
5405}5397}
54065398
...@@ -5607,9 +5599,12 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5607,9 +5599,12 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5607 return irb->codegen->invalid_instruction;5599 return irb->codegen->invalid_instruction;
5608 }5600 }
56095601
5602 // Used for the type expr and the align expr
5603 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
5604
5610 IrInstruction *type_instruction;5605 IrInstruction *type_instruction;
5611 if (variable_declaration->type != nullptr) {5606 if (variable_declaration->type != nullptr) {
5612 type_instruction = ir_gen_node(irb, variable_declaration->type, scope);5607 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);
5613 if (type_instruction == irb->codegen->invalid_instruction)5608 if (type_instruction == irb->codegen->invalid_instruction)
5614 return type_instruction;5609 return type_instruction;
5615 } else {5610 } else {
...@@ -5635,7 +5630,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5635,7 +5630,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
56355630
5636 IrInstruction *align_value = nullptr;5631 IrInstruction *align_value = nullptr;
5637 if (variable_declaration->align_expr != nullptr) {5632 if (variable_declaration->align_expr != nullptr) {
5638 align_value = ir_gen_node(irb, variable_declaration->align_expr, scope);5633 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);
5639 if (align_value == irb->codegen->invalid_instruction)5634 if (align_value == irb->codegen->invalid_instruction)
5640 return align_value;5635 return align_value;
5641 }5636 }
...@@ -5656,19 +5651,24 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5656,19 +5651,24 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5656 result_loc_var->base.id = ResultLocIdVar;5651 result_loc_var->base.id = ResultLocIdVar;
5657 result_loc_var->base.source_instruction = alloca;5652 result_loc_var->base.source_instruction = alloca;
5658 result_loc_var->var = var;5653 result_loc_var->var = var;
5654 ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;
56595655
5660 // Temporarily set the name of the IrExecutable to the VariableDeclaration5656 // Temporarily set the name of the IrExecutable to the VariableDeclaration
5661 // so that the struct or enum from the init expression inherits the name.5657 // so that the struct or enum from the init expression inherits the name.
5662 Buf *old_exec_name = irb->exec->name;5658 Buf *old_exec_name = irb->exec->name;
5663 irb->exec->name = variable_declaration->symbol;5659 irb->exec->name = variable_declaration->symbol;
5664 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone,5660 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone, init_result_loc);
5665 &result_loc_var->base);
5666 irb->exec->name = old_exec_name;5661 irb->exec->name = old_exec_name;
56675662
5668 if (init_value == irb->codegen->invalid_instruction)5663 if (init_value == irb->codegen->invalid_instruction)
5669 return init_value;5664 return irb->codegen->invalid_instruction;
5665
5666 if (type_instruction != nullptr) {
5667 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, type_instruction, init_value);
5668 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
5669 }
56705670
5671 return ir_build_var_decl_src(irb, scope, node, var, type_instruction, align_value, alloca);5671 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);
5672}5672}
56735673
5674static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {5674static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -5725,7 +5725,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5725,7 +5725,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5725 err_val_ptr, false);5725 err_val_ptr, false);
5726 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?5726 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?
5727 var_ptr_value : ir_build_load_ptr(irb, payload_scope, symbol_node, var_ptr_value);5727 var_ptr_value : ir_build_load_ptr(irb, payload_scope, symbol_node, var_ptr_value);
5728 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, nullptr, var_value);5728 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_value);
5729 }5729 }
57305730
5731 ZigList<IrInstruction *> incoming_values = {0};5731 ZigList<IrInstruction *> incoming_values = {0};
...@@ -5767,7 +5767,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5767,7 +5767,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5767 true, false, false, is_comptime);5767 true, false, false, is_comptime);
5768 Scope *err_scope = err_var->child_scope;5768 Scope *err_scope = err_var->child_scope;
5769 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);5769 IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
5770 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, nullptr, err_var_value);5770 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_var_value);
57715771
5772 IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope);5772 IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope);
5773 if (else_result == irb->codegen->invalid_instruction)5773 if (else_result == irb->codegen->invalid_instruction)
...@@ -5811,7 +5811,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5811,7 +5811,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5811 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false);5811 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false);
5812 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?5812 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?
5813 var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value);5813 var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value);
5814 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, nullptr, var_value);5814 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_value);
58155815
5816 ZigList<IrInstruction *> incoming_values = {0};5816 ZigList<IrInstruction *> incoming_values = {0};
5817 ZigList<IrBasicBlock *> incoming_blocks = {0};5817 ZigList<IrBasicBlock *> incoming_blocks = {0};
...@@ -5953,14 +5953,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5953,14 +5953,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5953 if (array_val_ptr == irb->codegen->invalid_instruction)5953 if (array_val_ptr == irb->codegen->invalid_instruction)
5954 return array_val_ptr;5954 return array_val_ptr;
59555955
5956 IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr);
5957 IrInstruction *elem_var_type;
5958 if (node->data.for_expr.elem_is_ptr) {
5959 elem_var_type = pointer_type;
5960 } else {
5961 elem_var_type = ir_build_ptr_type_child(irb, parent_scope, elem_node, pointer_type);
5962 }
5963
5964 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,5956 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,
5965 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);5957 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
59665958
...@@ -5970,7 +5962,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5970,7 +5962,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5970 Scope *child_scope = elem_var->child_scope;5962 Scope *child_scope = elem_var->child_scope;
59715963
5972 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);5964 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
5973 ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value);5965 ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, nullptr, undefined_value);
5974 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);5966 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
59755967
5976 AstNode *index_var_source_node;5968 AstNode *index_var_source_node;
...@@ -5985,10 +5977,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5985,10 +5977,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5985 }5977 }
5986 child_scope = index_var->child_scope;5978 child_scope = index_var->child_scope;
59875979
5988 IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize);
5989 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);5980 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
5990 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);5981 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
5991 ir_build_var_decl_src(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero);5982 ir_build_var_decl_src(irb, child_scope, index_var_source_node, index_var, nullptr, zero);
5992 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);5983 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);
59935984
59945985
...@@ -6380,7 +6371,6 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -6380,7 +6371,6 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
6380 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);6371 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6381 Scope *var_scope;6372 Scope *var_scope;
6382 if (var_symbol) {6373 if (var_symbol) {
6383 IrInstruction *var_type = nullptr;
6384 bool is_shadowable = false;6374 bool is_shadowable = false;
6385 bool is_const = true;6375 bool is_const = true;
6386 ZigVar *var = ir_create_var(irb, node, subexpr_scope,6376 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
...@@ -6388,7 +6378,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -6388,7 +6378,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
63886378
6389 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false);6379 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false);
6390 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);6380 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
6391 ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value);6381 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value);
6392 var_scope = var->child_scope;6382 var_scope = var->child_scope;
6393 } else {6383 } else {
6394 var_scope = subexpr_scope;6384 var_scope = subexpr_scope;
...@@ -6455,7 +6445,6 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6455,7 +6445,6 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
6455 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);6445 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6456 Scope *var_scope;6446 Scope *var_scope;
6457 if (var_symbol) {6447 if (var_symbol) {
6458 IrInstruction *var_type = nullptr;
6459 bool is_shadowable = false;6448 bool is_shadowable = false;
6460 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);6449 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
6461 ZigVar *var = ir_create_var(irb, node, subexpr_scope,6450 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
...@@ -6463,7 +6452,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6463,7 +6452,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64636452
6464 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);6453 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);
6465 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);6454 IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
6466 ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value);6455 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value);
6467 var_scope = var->child_scope;6456 var_scope = var->child_scope;
6468 } else {6457 } else {
6469 var_scope = subexpr_scope;6458 var_scope = subexpr_scope;
...@@ -6481,14 +6470,13 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6481,14 +6470,13 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
6481 if (else_node) {6470 if (else_node) {
6482 Scope *err_var_scope;6471 Scope *err_var_scope;
6483 if (err_symbol) {6472 if (err_symbol) {
6484 IrInstruction *var_type = nullptr;
6485 bool is_shadowable = false;6473 bool is_shadowable = false;
6486 bool is_const = true;6474 bool is_const = true;
6487 ZigVar *var = ir_create_var(irb, node, subexpr_scope,6475 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
6488 err_symbol, is_const, is_const, is_shadowable, is_comptime);6476 err_symbol, is_const, is_const, is_shadowable, is_comptime);
64896477
6490 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);6478 IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
6491 ir_build_var_decl_src(irb, subexpr_scope, node, var, var_type, nullptr, var_value);6479 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value);
6492 err_var_scope = var->child_scope;6480 err_var_scope = var->child_scope;
6493 } else {6481 } else {
6494 err_var_scope = subexpr_scope;6482 err_var_scope = subexpr_scope;
...@@ -6551,8 +6539,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit...@@ -6551,8 +6539,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
6551 var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, 6539 var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node,
6552target_value_ptr);6540target_value_ptr);
6553 }6541 }
6554 IrInstruction *var_type = nullptr; // infer the type6542 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_value);
6555 ir_build_var_decl_src(irb, scope, var_symbol_node, var, var_type, nullptr, var_value);
6556 } else {6543 } else {
6557 child_scope = scope;6544 child_scope = scope;
6558 }6545 }
...@@ -7018,7 +7005,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -7018,7 +7005,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
7018 is_const, is_const, is_shadowable, is_comptime);7005 is_const, is_const, is_shadowable, is_comptime);
7019 err_scope = var->child_scope;7006 err_scope = var->child_scope;
7020 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);7007 IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
7021 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, nullptr, err_val);7008 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_val);
7022 } else {7009 } else {
7023 err_scope = parent_scope;7010 err_scope = parent_scope;
7024 }7011 }
...@@ -7509,7 +7496,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7509,7 +7496,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
7509 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);7496 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
7510 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);7497 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
7511 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);7498 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);
7512 ir_build_var_decl_src(irb, scope, node, result_var, promise_result_type, nullptr, undefined_value);7499 ir_build_var_decl_src(irb, scope, node, result_var, nullptr, undefined_value);
7513 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);7500 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);
7514 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);7501 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);
7515 IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle);7502 IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle);
...@@ -7940,17 +7927,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7940,17 +7927,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
79407927
7941 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;7928 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
7942 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);7929 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);
7943 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
7944 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
7945 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa7930 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
7946 ir_build_var_decl_src(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);7931 ir_build_var_decl_src(irb, coro_scope, node, promise_var, nullptr, undef);
7947 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);7932 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
79487933
7949 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7934 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7950 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);7935 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
7951 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,7936 ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_value);
7952 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
7953 ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value);
7954 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);7937 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
79557938
7956 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,7939 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
...@@ -7960,11 +7943,11 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7960,11 +7943,11 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7960 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);7943 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);
7961 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);7944 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
7962 IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node);7945 IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node);
7963 ir_build_var_decl_src(irb, coro_scope, node, coro_size_var, nullptr, nullptr, coro_size);7946 ir_build_var_decl_src(irb, coro_scope, node, coro_size_var, nullptr, coro_size);
7964 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,7947 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,
7965 ImplicitAllocatorIdArg);7948 ImplicitAllocatorIdArg);
7966 irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false);7949 irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false);
7967 ir_build_var_decl_src(irb, coro_scope, node, irb->exec->coro_allocator_var, nullptr, nullptr, implicit_allocator_ptr);7950 ir_build_var_decl_src(irb, coro_scope, node, irb->exec->coro_allocator_var, nullptr, implicit_allocator_ptr);
7968 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);7951 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
7969 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);7952 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);
7970 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);7953 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);
...@@ -14375,20 +14358,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z...@@ -14375,20 +14358,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
14375 case ResultLocIdNone:14358 case ResultLocIdNone:
14376 return nullptr;14359 return nullptr;
14377 case ResultLocIdVar: {14360 case ResultLocIdVar: {
14378 // TODO implicit cast?
14379 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);14361 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
14380 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);14362 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
14381 IrInstructionAllocaSrc *alloca_src =14363 IrInstructionAllocaSrc *alloca_src =
14382 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);14364 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
14383 if (alloca_src->base.child == nullptr) {14365 if (alloca_src->base.child == nullptr) {
14384 uint32_t align = 0; // TODO
14385 bool force_comptime = false; // TODO
14386 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&14366 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
14387 result_loc_var->var->gen_is_const;14367 result_loc_var->var->gen_is_const;
14388 IrInstruction *alloca_gen;14368 IrInstruction *alloca_gen;
14389 if (is_comptime) {14369 if (is_comptime) {
14390 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);14370 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
14391 } else {14371 } else {
14372 uint32_t align = 0;
14373 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) {
14374 return ira->codegen->invalid_instruction;
14375 }
14376 bool force_comptime;
14377 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
14378 return ira->codegen->invalid_instruction;
14392 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,14379 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
14393 alloca_src->name_hint, force_comptime);14380 alloca_src->name_hint, force_comptime);
14394 }14381 }
...@@ -14409,6 +14396,19 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z...@@ -14409,6 +14396,19 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
14409 zig_unreachable();14396 zig_unreachable();
14410}14397}
1441114398
14399static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
14400 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
14401 if (type_is_invalid(dest_type))
14402 return ira->codegen->invalid_instruction;
14403
14404 IrInstruction *target = instruction->target->child;
14405 if (type_is_invalid(target->value.type))
14406 return ira->codegen->invalid_instruction;
14407
14408 return ir_implicit_cast(ira, target, dest_type);
14409}
14410
14411
14412static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,14412static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,
14413 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,14413 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
14414 IrInstruction *async_allocator_inst)14414 IrInstruction *async_allocator_inst)
...@@ -23612,8 +23612,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -23612,8 +23612,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
23612 if (type_is_invalid(value->value.type))23612 if (type_is_invalid(value->value.type))
23613 return ira->codegen->invalid_instruction;23613 return ira->codegen->invalid_instruction;
2361423614
23615 assert(instruction->lval == LValNone);
23616
23617 if (instruction->result_loc->id == ResultLocIdPeer) {23615 if (instruction->result_loc->id == ResultLocIdPeer) {
23618 ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(instruction->result_loc);23616 ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(instruction->result_loc);
23619 ResultLocPeerParent *peer_parent = result_peer->parent;23617 ResultLocPeerParent *peer_parent = result_peer->parent;
...@@ -23640,7 +23638,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -23640,7 +23638,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
23640 }23638 }
23641 }23639 }
23642 IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value->value.type, value);23640 IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value->value.type, value);
23643 if (result_loc != nullptr) {23641 if (result_loc != nullptr && !type_is_invalid(result_loc->value.type)) {
23644 ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);23642 ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
23645 }23643 }
2364623644
...@@ -23874,6 +23872,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -23874,6 +23872,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
23874 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);23872 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
23875 case IrInstructionIdAlignCast:23873 case IrInstructionIdAlignCast:
23876 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);23874 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
23875 case IrInstructionIdImplicitCast:
23876 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);
23877 case IrInstructionIdOpaqueType:23877 case IrInstructionIdOpaqueType:
23878 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);23878 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);
23879 case IrInstructionIdSetAlignStack:23879 case IrInstructionIdSetAlignStack:
...@@ -24165,6 +24165,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -24165,6 +24165,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
24165 case IrInstructionIdTypeInfo:24165 case IrInstructionIdTypeInfo:
24166 case IrInstructionIdTypeId:24166 case IrInstructionIdTypeId:
24167 case IrInstructionIdAlignCast:24167 case IrInstructionIdAlignCast:
24168 case IrInstructionIdImplicitCast:
24168 case IrInstructionIdOpaqueType:24169 case IrInstructionIdOpaqueType:
24169 case IrInstructionIdArgType:24170 case IrInstructionIdArgType:
24170 case IrInstructionIdTagType:24171 case IrInstructionIdTagType:
src/ir_print.cpp+12-11
...@@ -158,16 +158,6 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {...@@ -158,16 +158,6 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
158 zig_unreachable();158 zig_unreachable();
159}159}
160160
161static const char *ir_lval_str(LVal lval) {
162 switch (lval) {
163 case LValNone:
164 return "None";
165 case LValPtr:
166 return "Ptr";
167 }
168 zig_unreachable();
169}
170
171static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {161static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
172 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));162 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
173 ir_print_other_instruction(irp, un_op_instruction->value);163 ir_print_other_instruction(irp, un_op_instruction->value);
...@@ -1149,7 +1139,7 @@ static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {...@@ -1149,7 +1139,7 @@ static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {
1149 ir_print_result_loc(irp, instruction->result_loc);1139 ir_print_result_loc(irp, instruction->result_loc);
1150 fprintf(irp->f, ",value=");1140 fprintf(irp->f, ",value=");
1151 ir_print_other_instruction(irp, instruction->value);1141 ir_print_other_instruction(irp, instruction->value);
1152 fprintf(irp->f, ",lval=%s)", ir_lval_str(instruction->lval));1142 fprintf(irp->f, ")");
1153}1143}
11541144
1155static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {1145static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
...@@ -1274,6 +1264,14 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio...@@ -1274,6 +1264,14 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio
1274 fprintf(irp->f, ")");1264 fprintf(irp->f, ")");
1275}1265}
12761266
1267static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
1268 fprintf(irp->f, "@implicitCast(");
1269 ir_print_other_instruction(irp, instruction->dest_type);
1270 fprintf(irp->f, ",");
1271 ir_print_other_instruction(irp, instruction->target);
1272 fprintf(irp->f, ")");
1273}
1274
1277static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {1275static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
1278 fprintf(irp->f, "@OpaqueType()");1276 fprintf(irp->f, "@OpaqueType()");
1279}1277}
...@@ -1912,6 +1910,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1912,6 +1910,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1912 case IrInstructionIdAlignCast:1910 case IrInstructionIdAlignCast:
1913 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);1911 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);
1914 break;1912 break;
1913 case IrInstructionIdImplicitCast:
1914 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);
1915 break;
1915 case IrInstructionIdOpaqueType:1916 case IrInstructionIdOpaqueType:
1916 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);1917 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
1917 break;1918 break;