| ... | @@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { | ... | @@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 616 | return IrInstructionIdRef; | 616 | return IrInstructionIdRef; |
| 617 | } | 617 | } |
| 618 | | 618 | |
| 619 | static constexpr IrInstructionId ir_instruction_id(IrInstructionStructInit *) { | | |
| 620 | return IrInstructionIdStructInit; | | |
| 621 | } | | |
| 622 | | | |
| 623 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) { | 619 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) { |
| 624 | return IrInstructionIdUnionInit; | 620 | return IrInstructionIdUnionInit; |
| 625 | } | 621 | } |
| ... | @@ -888,6 +884,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) | ... | @@ -888,6 +884,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) |
| 888 | return IrInstructionIdImplicitCast; | 884 | return IrInstructionIdImplicitCast; |
| 889 | } | 885 | } |
| 890 | | 886 | |
| | 887 | static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) { |
| | 888 | return IrInstructionIdResolveResult; |
| | 889 | } |
| | 890 | |
| 891 | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { | 891 | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { |
| 892 | return IrInstructionIdOpaqueType; | 892 | return IrInstructionIdOpaqueType; |
| 893 | } | 893 | } |
| ... | @@ -1517,20 +1517,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop | ... | @@ -1517,20 +1517,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1517 | return &container_init_fields_instruction->base; | 1517 | return &container_init_fields_instruction->base; |
| 1518 | } | 1518 | } |
| 1519 | | 1519 | |
| 1520 | static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node, | | |
| 1521 | ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) | | |
| 1522 | { | | |
| 1523 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node); | | |
| 1524 | struct_init_instruction->struct_type = struct_type; | | |
| 1525 | struct_init_instruction->field_count = field_count; | | |
| 1526 | struct_init_instruction->fields = fields; | | |
| 1527 | | | |
| 1528 | for (size_t i = 0; i < field_count; i += 1) | | |
| 1529 | ir_ref_instruction(fields[i].value, irb->current_basic_block); | | |
| 1530 | | | |
| 1531 | return &struct_init_instruction->base; | | |
| 1532 | } | | |
| 1533 | | | |
| 1534 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1520 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1535 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) | 1521 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) |
| 1536 | { | 1522 | { |
| ... | @@ -2764,6 +2750,18 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -2764,6 +2750,18 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo |
| 2764 | return &instruction->base; | 2750 | return &instruction->base; |
| 2765 | } | 2751 | } |
| 2766 | | 2752 | |
| | 2753 | static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 2754 | ResultLoc *result_loc, IrInstruction *ty) |
| | 2755 | { |
| | 2756 | IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node); |
| | 2757 | instruction->result_loc = result_loc; |
| | 2758 | instruction->ty = ty; |
| | 2759 | |
| | 2760 | ir_ref_instruction(ty, irb->current_basic_block); |
| | 2761 | |
| | 2762 | return &instruction->base; |
| | 2763 | } |
| | 2764 | |
| 2767 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 2765 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2768 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); | 2766 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| 2769 | | 2767 | |
| ... | @@ -3220,6 +3218,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco | ... | @@ -3220,6 +3218,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 3220 | case ScopeIdSuspend: | 3218 | case ScopeIdSuspend: |
| 3221 | case ScopeIdCompTime: | 3219 | case ScopeIdCompTime: |
| 3222 | case ScopeIdRuntime: | 3220 | case ScopeIdRuntime: |
| | 3221 | case ScopeIdElide: |
| 3223 | scope = scope->parent; | 3222 | scope = scope->parent; |
| 3224 | continue; | 3223 | continue; |
| 3225 | case ScopeIdDeferExpr: | 3224 | case ScopeIdDeferExpr: |
| ... | @@ -3276,6 +3275,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o | ... | @@ -3276,6 +3275,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3276 | case ScopeIdSuspend: | 3275 | case ScopeIdSuspend: |
| 3277 | case ScopeIdCompTime: | 3276 | case ScopeIdCompTime: |
| 3278 | case ScopeIdRuntime: | 3277 | case ScopeIdRuntime: |
| | 3278 | case ScopeIdElide: |
| 3279 | scope = scope->parent; | 3279 | scope = scope->parent; |
| 3280 | continue; | 3280 | continue; |
| 3281 | case ScopeIdDeferExpr: | 3281 | case ScopeIdDeferExpr: |
| ... | @@ -5549,7 +5549,9 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod | ... | @@ -5549,7 +5549,9 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 5549 | zig_unreachable(); | 5549 | zig_unreachable(); |
| 5550 | } | 5550 | } |
| 5551 | | 5551 | |
| 5552 | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node) { | 5552 | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| | 5553 | ResultLoc *result_loc) |
| | 5554 | { |
| 5553 | assert(node->type == NodeTypeContainerInitExpr); | 5555 | assert(node->type == NodeTypeContainerInitExpr); |
| 5554 | | 5556 | |
| 5555 | AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr; | 5557 | AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr; |
| ... | @@ -5559,39 +5561,61 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A | ... | @@ -5559,39 +5561,61 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5559 | if (container_type == irb->codegen->invalid_instruction) | 5561 | if (container_type == irb->codegen->invalid_instruction) |
| 5560 | return container_type; | 5562 | return container_type; |
| 5561 | | 5563 | |
| 5562 | if (kind == ContainerInitKindStruct) { | 5564 | switch (kind) { |
| 5563 | size_t field_count = container_init_expr->entries.length; | 5565 | case ContainerInitKindStruct: { |
| 5564 | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count); | 5566 | src_assert(result_loc->scope_elide == nullptr, node); |
| 5565 | for (size_t i = 0; i < field_count; i += 1) { | 5567 | result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope); |
| 5566 | AstNode *entry_node = container_init_expr->entries.at(i); | 5568 | size_t field_count = container_init_expr->entries.length; |
| 5567 | assert(entry_node->type == NodeTypeStructValueField); | 5569 | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count); |
| 5568 | | 5570 | for (size_t i = 0; i < field_count; i += 1) { |
| 5569 | Buf *name = entry_node->data.struct_val_field.name; | 5571 | AstNode *entry_node = container_init_expr->entries.at(i); |
| 5570 | AstNode *expr_node = entry_node->data.struct_val_field.expr; | 5572 | assert(entry_node->type == NodeTypeStructValueField); |
| 5571 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, scope); | 5573 | |
| 5572 | if (expr_value == irb->codegen->invalid_instruction) | 5574 | Buf *name = entry_node->data.struct_val_field.name; |
| 5573 | return expr_value; | 5575 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 5574 | | 5576 | |
| 5575 | fields[i].name = name; | 5577 | ResultLoc *child_result_loc = nullptr; |
| 5576 | fields[i].value = expr_value; | 5578 | if (result_loc != nullptr) { |
| 5577 | fields[i].source_node = entry_node; | 5579 | IrInstruction *container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base, |
| 5578 | } | 5580 | expr_node, result_loc, container_type); |
| 5579 | return ir_build_container_init_fields(irb, scope, node, container_type, field_count, fields); | 5581 | IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node, |
| 5580 | } else if (kind == ContainerInitKindArray) { | 5582 | container_ptr, name); |
| 5581 | size_t item_count = container_init_expr->entries.length; | 5583 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 5582 | IrInstruction **values = allocate<IrInstruction *>(item_count); | 5584 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5583 | for (size_t i = 0; i < item_count; i += 1) { | 5585 | result_loc_inst->base.source_instruction = field_ptr; |
| 5584 | AstNode *expr_node = container_init_expr->entries.at(i); | 5586 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 5585 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, scope); | 5587 | child_result_loc = &result_loc_inst->base; |
| 5586 | if (expr_value == irb->codegen->invalid_instruction) | 5588 | } |
| 5587 | return expr_value; | 5589 | |
| 5588 | | 5590 | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, &result_loc->scope_elide->base, |
| 5589 | values[i] = expr_value; | 5591 | LValNone, child_result_loc); |
| 5590 | } | 5592 | if (expr_value == irb->codegen->invalid_instruction) |
| 5591 | return ir_build_container_init_list(irb, scope, node, container_type, item_count, values); | 5593 | return expr_value; |
| 5592 | } else { | 5594 | |
| 5593 | zig_unreachable(); | 5595 | fields[i].name = name; |
| | 5596 | fields[i].value = expr_value; |
| | 5597 | fields[i].source_node = entry_node; |
| | 5598 | } |
| | 5599 | IrInstruction *init_fields = ir_build_container_init_fields(irb, scope, node, container_type, field_count, fields); |
| | 5600 | |
| | 5601 | return ir_lval_wrap(irb, scope, init_fields, lval, result_loc); |
| | 5602 | } |
| | 5603 | case ContainerInitKindArray: { |
| | 5604 | size_t item_count = container_init_expr->entries.length; |
| | 5605 | IrInstruction **values = allocate<IrInstruction *>(item_count); |
| | 5606 | for (size_t i = 0; i < item_count; i += 1) { |
| | 5607 | AstNode *expr_node = container_init_expr->entries.at(i); |
| | 5608 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, scope); |
| | 5609 | if (expr_value == irb->codegen->invalid_instruction) |
| | 5610 | return expr_value; |
| | 5611 | |
| | 5612 | values[i] = expr_value; |
| | 5613 | } |
| | 5614 | IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, item_count, values); |
| | 5615 | return ir_lval_wrap(irb, scope, init_list, lval, result_loc); |
| | 5616 | } |
| 5594 | } | 5617 | } |
| | 5618 | zig_unreachable(); |
| 5595 | } | 5619 | } |
| 5596 | | 5620 | |
| 5597 | static ResultLocVar *create_var_result_loc(IrInstruction *alloca, ZigVar *var) { | 5621 | static ResultLocVar *create_var_result_loc(IrInstruction *alloca, ZigVar *var) { |
| ... | @@ -7885,7 +7909,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7885,7 +7909,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7885 | case NodeTypePrefixOpExpr: | 7909 | case NodeTypePrefixOpExpr: |
| 7886 | return ir_gen_prefix_op_expr(irb, scope, node, lval, result_loc); | 7910 | return ir_gen_prefix_op_expr(irb, scope, node, lval, result_loc); |
| 7887 | case NodeTypeContainerInitExpr: | 7911 | case NodeTypeContainerInitExpr: |
| 7888 | return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval, result_loc); | 7912 | return ir_gen_container_init_expr(irb, scope, node, lval, result_loc); |
| 7889 | case NodeTypeVariableDeclaration: | 7913 | case NodeTypeVariableDeclaration: |
| 7890 | return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval, result_loc); | 7914 | return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval, result_loc); |
| 7891 | case NodeTypeWhileExpr: | 7915 | case NodeTypeWhileExpr: |
| ... | @@ -14468,7 +14492,9 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -14468,7 +14492,9 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 14468 | return &result->base; | 14492 | return &result->base; |
| 14469 | } | 14493 | } |
| 14470 | | 14494 | |
| 14471 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_loc) { | 14495 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| | 14496 | ResultLoc *result_loc) |
| | 14497 | { |
| 14472 | switch (result_loc->id) { | 14498 | switch (result_loc->id) { |
| 14473 | case ResultLocIdInvalid: | 14499 | case ResultLocIdInvalid: |
| 14474 | case ResultLocIdPeerParent: | 14500 | case ResultLocIdPeerParent: |
| ... | @@ -14476,6 +14502,30 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_lo | ... | @@ -14476,6 +14502,30 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_lo |
| 14476 | case ResultLocIdNone: | 14502 | case ResultLocIdNone: |
| 14477 | case ResultLocIdVar: | 14503 | case ResultLocIdVar: |
| 14478 | return nullptr; | 14504 | return nullptr; |
| | 14505 | case ResultLocIdInstruction: |
| | 14506 | return result_loc->source_instruction->child->value.type; |
| | 14507 | case ResultLocIdField: { |
| | 14508 | if (result_loc->resolved_loc != nullptr) { |
| | 14509 | ZigType *ptr_type = result_loc->resolved_loc->value.type; |
| | 14510 | assert(ptr_type->id == ZigTypeIdPointer); |
| | 14511 | return ptr_type->data.pointer.child_type; |
| | 14512 | } |
| | 14513 | ResultLocField *result_loc_field = reinterpret_cast<ResultLocField *>(result_loc); |
| | 14514 | ZigType *container_type = ir_resolve_type(ira, result_loc_field->container_type->child); |
| | 14515 | if (type_is_invalid(container_type)) |
| | 14516 | return ira->codegen->builtin_types.entry_invalid; |
| | 14517 | if (container_type->id == ZigTypeIdStruct) { |
| | 14518 | TypeStructField *field = find_struct_type_field(container_type, result_loc_field->name); |
| | 14519 | if (field == nullptr) { |
| | 14520 | return ira->codegen->builtin_types.entry_invalid; |
| | 14521 | } |
| | 14522 | return field->type_entry; |
| | 14523 | } else if (container_type->id == ZigTypeIdUnion) { |
| | 14524 | zig_panic("TODO"); |
| | 14525 | } else { |
| | 14526 | zig_unreachable(); |
| | 14527 | } |
| | 14528 | } |
| 14479 | case ResultLocIdReturn: | 14529 | case ResultLocIdReturn: |
| 14480 | return ira->explicit_return_type; | 14530 | return ira->explicit_return_type; |
| 14481 | case ResultLocIdPeer: | 14531 | case ResultLocIdPeer: |
| ... | @@ -14491,7 +14541,10 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -14491,7 +14541,10 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14491 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value) | 14541 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value) |
| 14492 | { | 14542 | { |
| 14493 | if (result_loc->resolved_loc != nullptr) { | 14543 | if (result_loc->resolved_loc != nullptr) { |
| 14494 | return result_loc->resolved_loc; | 14544 | // allow to redo the result location if the value is known and comptime and the previous one isn't |
| | 14545 | if (value == nullptr || !instr_is_comptime(value) || instr_is_comptime(result_loc->resolved_loc)) { |
| | 14546 | return result_loc->resolved_loc; |
| | 14547 | } |
| 14495 | } | 14548 | } |
| 14496 | result_loc->gen_instruction = value; | 14549 | result_loc->gen_instruction = value; |
| 14497 | result_loc->implicit_elem_type = value_type; | 14550 | result_loc->implicit_elem_type = value_type; |
| ... | @@ -14524,7 +14577,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -14524,7 +14577,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14524 | return ira->codegen->invalid_instruction; | 14577 | return ira->codegen->invalid_instruction; |
| 14525 | bool is_comptime = force_comptime || (value != nullptr && | 14578 | bool is_comptime = force_comptime || (value != nullptr && |
| 14526 | value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); | 14579 | value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 14527 | if (alloca_src->base.child == nullptr) { | 14580 | if (alloca_src->base.child == nullptr || is_comptime) { |
| 14528 | uint32_t align = 0; | 14581 | uint32_t align = 0; |
| 14529 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) { | 14582 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) { |
| 14530 | return ira->codegen->invalid_instruction; | 14583 | return ira->codegen->invalid_instruction; |
| ... | @@ -14539,12 +14592,40 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -14539,12 +14592,40 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14539 | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, | 14592 | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, |
| 14540 | alloca_src->name_hint, force_comptime); | 14593 | alloca_src->name_hint, force_comptime); |
| 14541 | } | 14594 | } |
| | 14595 | if (alloca_src->base.child != nullptr) { |
| | 14596 | alloca_src->base.child->ref_count = 0; |
| | 14597 | } |
| 14542 | alloca_src->base.child = alloca_gen; | 14598 | alloca_src->base.child = alloca_gen; |
| 14543 | } | 14599 | } |
| 14544 | result_loc->written = true; | 14600 | result_loc->written = true; |
| 14545 | result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child; | 14601 | result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child; |
| 14546 | return result_loc->resolved_loc; | 14602 | return result_loc->resolved_loc; |
| 14547 | } | 14603 | } |
| | 14604 | case ResultLocIdInstruction: { |
| | 14605 | result_loc->written = true; |
| | 14606 | result_loc->resolved_loc = result_loc->source_instruction->child; |
| | 14607 | return result_loc->resolved_loc; |
| | 14608 | } |
| | 14609 | case ResultLocIdField: { |
| | 14610 | ResultLocField *result_loc_field = reinterpret_cast<ResultLocField *>(result_loc); |
| | 14611 | |
| | 14612 | ZigType *container_type = ir_resolve_type(ira, result_loc_field->container_type->child); |
| | 14613 | if (type_is_invalid(container_type)) |
| | 14614 | return ira->codegen->invalid_instruction; |
| | 14615 | |
| | 14616 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, |
| | 14617 | result_loc_field->parent, container_type, nullptr); |
| | 14618 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| | 14619 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| | 14620 | { |
| | 14621 | return parent_result_loc; |
| | 14622 | } |
| | 14623 | |
| | 14624 | result_loc->written = true; |
| | 14625 | result_loc->resolved_loc = ir_analyze_container_field_ptr(ira, result_loc_field->name, |
| | 14626 | suspend_source_instr, parent_result_loc, container_type); |
| | 14627 | return result_loc->resolved_loc; |
| | 14628 | } |
| 14548 | case ResultLocIdReturn: { | 14629 | case ResultLocIdReturn: { |
| 14549 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; | 14630 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; |
| 14550 | if (is_comptime) return nullptr; | 14631 | if (is_comptime) return nullptr; |
| ... | @@ -14593,7 +14674,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -14593,7 +14674,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14593 | ira->resume_stack.append(opposite_peer->suspend_pos); | 14674 | ira->resume_stack.append(opposite_peer->suspend_pos); |
| 14594 | } | 14675 | } |
| 14595 | } | 14676 | } |
| 14596 | ZigType *expected_type = ir_result_loc_expected_type(ira, peer_parent->parent); | 14677 | ZigType *expected_type = ir_result_loc_expected_type(ira, suspend_source_instr, peer_parent->parent); |
| 14597 | peer_parent->resolved_type = ir_resolve_peer_types(ira, | 14678 | peer_parent->resolved_type = ir_resolve_peer_types(ira, |
| 14598 | peer_parent->base.source_instruction->source_node, expected_type, instructions, | 14679 | peer_parent->base.source_instruction->source_node, expected_type, instructions, |
| 14599 | peer_parent->peer_count); | 14680 | peer_parent->peer_count); |
| ... | @@ -14626,6 +14707,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns | ... | @@ -14626,6 +14707,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns |
| 14626 | return ir_implicit_cast(ira, target, dest_type); | 14707 | return ir_implicit_cast(ira, target, dest_type); |
| 14627 | } | 14708 | } |
| 14628 | | 14709 | |
| | 14710 | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) { |
| | 14711 | ZigType *ty = ir_resolve_type(ira, instruction->ty->child); |
| | 14712 | if (type_is_invalid(ty)) |
| | 14713 | return ira->codegen->invalid_instruction; |
| | 14714 | return ir_resolve_result(ira, &instruction->base, instruction->result_loc, ty, nullptr); |
| | 14715 | } |
| 14629 | | 14716 | |
| 14630 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, | 14717 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, |
| 14631 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, | 14718 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| ... | @@ -18330,8 +18417,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18330,8 +18417,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18330 | | 18417 | |
| 18331 | AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count); | 18418 | AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count); |
| 18332 | | 18419 | |
| 18333 | IrInstructionStructInitField *new_fields = allocate<IrInstructionStructInitField>(actual_field_count); | | |
| 18334 | | | |
| 18335 | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope) | 18420 | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope) |
| 18336 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; | 18421 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; |
| 18337 | | 18422 | |
| ... | @@ -18371,9 +18456,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18371,9 +18456,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18371 | } | 18456 | } |
| 18372 | field_assign_nodes[field_index] = field->source_node; | 18457 | field_assign_nodes[field_index] = field->source_node; |
| 18373 | | 18458 | |
| 18374 | new_fields[field_index].value = casted_field_value; | | |
| 18375 | new_fields[field_index].type_struct_field = type_field; | | |
| 18376 | | | |
| 18377 | if (const_val.special == ConstValSpecialStatic) { | 18459 | if (const_val.special == ConstValSpecialStatic) { |
| 18378 | if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime) { | 18460 | if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime) { |
| 18379 | ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk); | 18461 | ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk); |
| ... | @@ -18416,9 +18498,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18416,9 +18498,6 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18416 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); | 18498 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 18417 | copy_const_val(&runtime_inst->value, field->init_val, true); | 18499 | copy_const_val(&runtime_inst->value, field->init_val, true); |
| 18418 | | 18500 | |
| 18419 | new_fields[i].value = runtime_inst; | | |
| 18420 | new_fields[i].type_struct_field = field; | | |
| 18421 | | | |
| 18422 | if (const_val.special == ConstValSpecialStatic) { | 18501 | if (const_val.special == ConstValSpecialStatic) { |
| 18423 | copy_const_val(&const_val.data.x_struct.fields[i], field->init_val, true); | 18502 | copy_const_val(&const_val.data.x_struct.fields[i], field->init_val, true); |
| 18424 | } | 18503 | } |
| ... | @@ -18451,12 +18530,11 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18451,12 +18530,11 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18451 | return ira->codegen->invalid_instruction; | 18530 | return ira->codegen->invalid_instruction; |
| 18452 | } | 18531 | } |
| 18453 | | 18532 | |
| 18454 | IrInstruction *new_instruction = ir_build_struct_init(&ira->new_irb, | 18533 | // this instruction should not get to codegen |
| 18455 | instruction->scope, instruction->source_node, | 18534 | IrInstruction *result = ir_const(ira, instruction, container_type); |
| 18456 | container_type, actual_field_count, new_fields); | 18535 | // this is how we signal to EndExpr the value is not comptime known |
| 18457 | new_instruction->value.type = container_type; | 18536 | result->value.special = ConstValSpecialRuntime; |
| 18458 | ir_add_alloca(ira, new_instruction, container_type); | 18537 | return result; |
| 18459 | return new_instruction; | | |
| 18460 | } | 18538 | } |
| 18461 | | 18539 | |
| 18462 | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, | 18540 | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| ... | @@ -23794,7 +23872,18 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -23794,7 +23872,18 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 23794 | if (type_is_invalid(value->value.type)) | 23872 | if (type_is_invalid(value->value.type)) |
| 23795 | return ira->codegen->invalid_instruction; | 23873 | return ira->codegen->invalid_instruction; |
| 23796 | | 23874 | |
| 23797 | if (!instruction->result_loc->written) { | 23875 | bool want_resolve_result = instruction->result_loc->written; |
| | 23876 | if (instruction->result_loc->written) { |
| | 23877 | if (instruction->result_loc->scope_elide != nullptr && instr_is_comptime(value)) { |
| | 23878 | want_resolve_result = true; |
| | 23879 | instruction->result_loc->scope_elide->activated = true; |
| | 23880 | } else { |
| | 23881 | want_resolve_result = false; |
| | 23882 | } |
| | 23883 | } else { |
| | 23884 | want_resolve_result = true; |
| | 23885 | } |
| | 23886 | if (want_resolve_result) { |
| 23798 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 23887 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23799 | value->value.type, value); | 23888 | value->value.type, value); |
| 23800 | if (result_loc != nullptr) { | 23889 | if (result_loc != nullptr) { |
| ... | @@ -23815,7 +23904,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -23815,7 +23904,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 23815 | switch (instruction->id) { | 23904 | switch (instruction->id) { |
| 23816 | case IrInstructionIdInvalid: | 23905 | case IrInstructionIdInvalid: |
| 23817 | case IrInstructionIdWidenOrShorten: | 23906 | case IrInstructionIdWidenOrShorten: |
| 23818 | case IrInstructionIdStructInit: | | |
| 23819 | case IrInstructionIdUnionInit: | 23907 | case IrInstructionIdUnionInit: |
| 23820 | case IrInstructionIdStructFieldPtr: | 23908 | case IrInstructionIdStructFieldPtr: |
| 23821 | case IrInstructionIdUnionFieldPtr: | 23909 | case IrInstructionIdUnionFieldPtr: |
| ... | @@ -24036,6 +24124,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -24036,6 +24124,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24036 | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); | 24124 | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); |
| 24037 | case IrInstructionIdImplicitCast: | 24125 | case IrInstructionIdImplicitCast: |
| 24038 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); | 24126 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| | 24127 | case IrInstructionIdResolveResult: |
| | 24128 | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); |
| 24039 | case IrInstructionIdOpaqueType: | 24129 | case IrInstructionIdOpaqueType: |
| 24040 | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); | 24130 | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 24041 | case IrInstructionIdSetAlignStack: | 24131 | case IrInstructionIdSetAlignStack: |
| ... | @@ -24260,7 +24350,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24260,7 +24350,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24260 | case IrInstructionIdCast: | 24350 | case IrInstructionIdCast: |
| 24261 | case IrInstructionIdContainerInitList: | 24351 | case IrInstructionIdContainerInitList: |
| 24262 | case IrInstructionIdContainerInitFields: | 24352 | case IrInstructionIdContainerInitFields: |
| 24263 | case IrInstructionIdStructInit: | | |
| 24264 | case IrInstructionIdUnionInit: | 24353 | case IrInstructionIdUnionInit: |
| 24265 | case IrInstructionIdFieldPtr: | 24354 | case IrInstructionIdFieldPtr: |
| 24266 | case IrInstructionIdElemPtr: | 24355 | case IrInstructionIdElemPtr: |
| ... | @@ -24326,6 +24415,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24326,6 +24415,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24326 | case IrInstructionIdTypeId: | 24415 | case IrInstructionIdTypeId: |
| 24327 | case IrInstructionIdAlignCast: | 24416 | case IrInstructionIdAlignCast: |
| 24328 | case IrInstructionIdImplicitCast: | 24417 | case IrInstructionIdImplicitCast: |
| | 24418 | case IrInstructionIdResolveResult: |
| 24329 | case IrInstructionIdOpaqueType: | 24419 | case IrInstructionIdOpaqueType: |
| 24330 | case IrInstructionIdArgType: | 24420 | case IrInstructionIdArgType: |
| 24331 | case IrInstructionIdTagType: | 24421 | case IrInstructionIdTagType: |