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 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4 * alignment of consts
5 * implicit casts
6 * for loops
7 * switch expression
8 * struct initializations
9 * function call parameters
10 * bitCast
11
412look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
513
614migrate all the alloca_list to alloca_gen_list
......@@ -22,3 +30,42 @@ inferred comptime
2230 return ir_build_ref(irb, scope, value->source_node, value, false, false);
2331
2432handle 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 {
22772277 IrInstructionIdSetEvalBranchQuota,
22782278 IrInstructionIdPtrType,
22792279 IrInstructionIdAlignCast,
2280 IrInstructionIdImplicitCast,
22802281 IrInstructionIdOpaqueType,
22812282 IrInstructionIdSetAlignStack,
22822283 IrInstructionIdArgType,
......@@ -3581,7 +3582,13 @@ struct IrInstructionEndExpr {
35813582
35823583 IrInstruction *value;
35833584 ResultLoc *result_loc;
3584 LVal lval;
3585};
3586
3587struct IrInstructionImplicitCast {
3588 IrInstruction base;
3589
3590 IrInstruction *dest_type;
3591 IrInstruction *target;
35853592};
35863593
35873594enum ResultLocId {
src/codegen.cpp+1
......@@ -5612,6 +5612,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
56125612 case IrInstructionIdAllocaSrc:
56135613 case IrInstructionIdEndExpr:
56145614 case IrInstructionIdAllocaGen:
5615 case IrInstructionIdImplicitCast:
56155616 zig_unreachable();
56165617
56175618 case IrInstructionIdDeclVarGen:
src/ir.cpp+73-72
......@@ -891,6 +891,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
891891 return IrInstructionIdAlignCast;
892892}
893893
894static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {
895 return IrInstructionIdImplicitCast;
896}
897
894898static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {
895899 return IrInstructionIdOpaqueType;
896900}
......@@ -1574,17 +1578,15 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *
15741578}
15751579
15761580static 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)
15781582{
15791583 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
15801584 decl_var_instruction->base.value.special = ConstValSpecialStatic;
15811585 decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void;
15821586 decl_var_instruction->var = var;
1583 decl_var_instruction->var_type = var_type;
15841587 decl_var_instruction->align_value = align_value;
15851588 decl_var_instruction->ptr = ptr;
15861589
1587 if (var_type != nullptr) ir_ref_instruction(var_type, irb->current_basic_block);
15881590 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
15891591 ir_ref_instruction(ptr, irb->current_basic_block);
15901592
......@@ -1655,27 +1657,6 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
16551657 return &instruction->base;
16561658}
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
16791660static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {
16801661 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);
16811662 instruction->is_cold = is_cold;
......@@ -2780,6 +2761,19 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode
27802761 return &instruction->base;
27812762}
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
27832777static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {
27842778 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);
27852779
......@@ -3199,11 +3193,10 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio
31993193}
32003194
32013195static 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)
32033197{
32043198 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);
32053199 instruction->value = value;
3206 instruction->lval = lval;
32073200 instruction->result_loc = result_loc;
32083201
32093202 ir_ref_instruction(value, irb->current_basic_block);
......@@ -5399,8 +5392,7 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode
53995392}
54005393
54015394static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {
5402 // TODO remove the lval parameter here
5403 ir_build_end_expr(irb, scope, inst->source_node, inst, LValNone, result_loc);
5395 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);
54045396 return inst;
54055397}
54065398
......@@ -5607,9 +5599,12 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
56075599 return irb->codegen->invalid_instruction;
56085600 }
56095601
5602 // Used for the type expr and the align expr
5603 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
5604
56105605 IrInstruction *type_instruction;
56115606 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);
56135608 if (type_instruction == irb->codegen->invalid_instruction)
56145609 return type_instruction;
56155610 } else {
......@@ -5635,7 +5630,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
56355630
56365631 IrInstruction *align_value = nullptr;
56375632 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);
56395634 if (align_value == irb->codegen->invalid_instruction)
56405635 return align_value;
56415636 }
......@@ -5656,19 +5651,24 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
56565651 result_loc_var->base.id = ResultLocIdVar;
56575652 result_loc_var->base.source_instruction = alloca;
56585653 result_loc_var->var = var;
5654 ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr;
56595655
56605656 // Temporarily set the name of the IrExecutable to the VariableDeclaration
56615657 // so that the struct or enum from the init expression inherits the name.
56625658 Buf *old_exec_name = irb->exec->name;
56635659 irb->exec->name = variable_declaration->symbol;
5664 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone,
5665 &result_loc_var->base);
5660 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone, init_result_loc);
56665661 irb->exec->name = old_exec_name;
56675662
56685663 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);
56725672}
56735673
56745674static 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
57255725 err_val_ptr, false);
57265726 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?
57275727 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);
57295729 }
57305730
57315731 ZigList<IrInstruction *> incoming_values = {0};
......@@ -5767,7 +5767,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
57675767 true, false, false, is_comptime);
57685768 Scope *err_scope = err_var->child_scope;
57695769 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
57725772 IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope);
57735773 if (else_result == irb->codegen->invalid_instruction)
......@@ -5811,7 +5811,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
58115811 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false);
58125812 IrInstruction *var_value = node->data.while_expr.var_is_ptr ?
58135813 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
58165816 ZigList<IrInstruction *> incoming_values = {0};
58175817 ZigList<IrBasicBlock *> incoming_blocks = {0};
......@@ -5953,14 +5953,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
59535953 if (array_val_ptr == irb->codegen->invalid_instruction)
59545954 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
59645956 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,
59655957 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
59705962 Scope *child_scope = elem_var->child_scope;
59715963
59725964 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);
59745966 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
59755967
59765968 AstNode *index_var_source_node;
......@@ -5985,10 +5977,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
59855977 }
59865978 child_scope = index_var->child_scope;
59875979
5988 IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize);
59895980 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
59905981 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);
59925983 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
63806371 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
63816372 Scope *var_scope;
63826373 if (var_symbol) {
6383 IrInstruction *var_type = nullptr;
63846374 bool is_shadowable = false;
63856375 bool is_const = true;
63866376 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
63886378
63896379 IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false);
63906380 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);
63926382 var_scope = var->child_scope;
63936383 } else {
63946384 var_scope = subexpr_scope;
......@@ -6455,7 +6445,6 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64556445 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
64566446 Scope *var_scope;
64576447 if (var_symbol) {
6458 IrInstruction *var_type = nullptr;
64596448 bool is_shadowable = false;
64606449 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);
64616450 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 *
64636452
64646453 IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);
64656454 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);
64676456 var_scope = var->child_scope;
64686457 } else {
64696458 var_scope = subexpr_scope;
......@@ -6481,14 +6470,13 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
64816470 if (else_node) {
64826471 Scope *err_var_scope;
64836472 if (err_symbol) {
6484 IrInstruction *var_type = nullptr;
64856473 bool is_shadowable = false;
64866474 bool is_const = true;
64876475 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
64886476 err_symbol, is_const, is_const, is_shadowable, is_comptime);
64896477
64906478 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);
64926480 err_var_scope = var->child_scope;
64936481 } else {
64946482 err_var_scope = subexpr_scope;
......@@ -6551,8 +6539,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
65516539 var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node,
65526540target_value_ptr);
65536541 }
6554 IrInstruction *var_type = nullptr; // infer the type
6555 ir_build_var_decl_src(irb, scope, var_symbol_node, var, var_type, nullptr, var_value);
6542 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_value);
65566543 } else {
65576544 child_scope = scope;
65586545 }
......@@ -7018,7 +7005,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
70187005 is_const, is_const, is_shadowable, is_comptime);
70197006 err_scope = var->child_scope;
70207007 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);
70227009 } else {
70237010 err_scope = parent_scope;
70247011 }
......@@ -7509,7 +7496,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
75097496 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
75107497 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
75117498 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);
75137500 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);
75147501 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);
75157502 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
79407927
79417928 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
79427929 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);
79457930 // 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);
79477932 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
79487933
79497934 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
79507935 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,
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);
7936 ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_value);
79547937 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
79557938
79567939 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
79607943 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);
79617944 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
79627945 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);
79647947 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,
79657948 ImplicitAllocatorIdArg);
79667949 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);
79687951 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
79697952 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);
79707953 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
1437514358 case ResultLocIdNone:
1437614359 return nullptr;
1437714360 case ResultLocIdVar: {
14378 // TODO implicit cast?
1437914361 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
1438014362 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
1438114363 IrInstructionAllocaSrc *alloca_src =
1438214364 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
1438314365 if (alloca_src->base.child == nullptr) {
14384 uint32_t align = 0; // TODO
14385 bool force_comptime = false; // TODO
1438614366 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
1438714367 result_loc_var->var->gen_is_const;
1438814368 IrInstruction *alloca_gen;
1438914369 if (is_comptime) {
1439014370 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
1439114371 } 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;
1439214379 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
1439314380 alloca_src->name_hint, force_comptime);
1439414381 }
......@@ -14409,6 +14396,19 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
1440914396 zig_unreachable();
1441014397}
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
1441214412static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,
1441314413 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
1441414414 IrInstruction *async_allocator_inst)
......@@ -23612,8 +23612,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2361223612 if (type_is_invalid(value->value.type))
2361323613 return ira->codegen->invalid_instruction;
2361423614
23615 assert(instruction->lval == LValNone);
23616
2361723615 if (instruction->result_loc->id == ResultLocIdPeer) {
2361823616 ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(instruction->result_loc);
2361923617 ResultLocPeerParent *peer_parent = result_peer->parent;
......@@ -23640,7 +23638,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2364023638 }
2364123639 }
2364223640 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)) {
2364423642 ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
2364523643 }
2364623644
......@@ -23874,6 +23872,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2387423872 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
2387523873 case IrInstructionIdAlignCast:
2387623874 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
23875 case IrInstructionIdImplicitCast:
23876 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);
2387723877 case IrInstructionIdOpaqueType:
2387823878 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);
2387923879 case IrInstructionIdSetAlignStack:
......@@ -24165,6 +24165,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2416524165 case IrInstructionIdTypeInfo:
2416624166 case IrInstructionIdTypeId:
2416724167 case IrInstructionIdAlignCast:
24168 case IrInstructionIdImplicitCast:
2416824169 case IrInstructionIdOpaqueType:
2416924170 case IrInstructionIdArgType:
2417024171 case IrInstructionIdTagType:
src/ir_print.cpp+12-11
......@@ -158,16 +158,6 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
158158 zig_unreachable();
159159}
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
171161static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
172162 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
173163 ir_print_other_instruction(irp, un_op_instruction->value);
......@@ -1149,7 +1139,7 @@ static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {
11491139 ir_print_result_loc(irp, instruction->result_loc);
11501140 fprintf(irp->f, ",value=");
11511141 ir_print_other_instruction(irp, instruction->value);
1152 fprintf(irp->f, ",lval=%s)", ir_lval_str(instruction->lval));
1142 fprintf(irp->f, ")");
11531143}
11541144
11551145static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
......@@ -1274,6 +1264,14 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio
12741264 fprintf(irp->f, ")");
12751265}
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
12771275static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
12781276 fprintf(irp->f, "@OpaqueType()");
12791277}
......@@ -1912,6 +1910,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
19121910 case IrInstructionIdAlignCast:
19131911 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);
19141912 break;
1913 case IrInstructionIdImplicitCast:
1914 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);
1915 break;
19151916 case IrInstructionIdOpaqueType:
19161917 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
19171918 break;