| ... | @@ -17519,7 +17519,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17519,7 +17519,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17519 | { | 17519 | { |
| 17520 | result_loc_pass1 = no_result_loc(); | 17520 | result_loc_pass1 = no_result_loc(); |
| 17521 | } | 17521 | } |
| 17522 | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; | | |
| 17523 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 17522 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17524 | value, force_runtime, allow_discard); | 17523 | value, force_runtime, allow_discard); |
| 17525 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) | 17524 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| ... | @@ -17532,56 +17531,63 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17532,56 +17531,63 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17532 | } | 17531 | } |
| 17533 | | 17532 | |
| 17534 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; | 17533 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; |
| 17535 | if (!was_already_resolved && isf != nullptr) { | 17534 | if (isf != nullptr) { |
| 17536 | // Now it's time to add the field to the struct type. | 17535 | TypeStructField *field; |
| 17537 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; | | |
| 17538 | uint32_t new_field_count = old_field_count + 1; | | |
| 17539 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; | | |
| 17540 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( | | |
| 17541 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); | | |
| 17542 | | | |
| 17543 | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; | | |
| 17544 | field->name = isf->field_name; | | |
| 17545 | field->type_entry = value_type; | | |
| 17546 | field->type_val = create_const_type(ira->codegen, field->type_entry); | | |
| 17547 | field->src_index = old_field_count; | | |
| 17548 | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; | | |
| 17549 | if (value && instr_is_comptime(value)) { | | |
| 17550 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); | | |
| 17551 | if (!val) | | |
| 17552 | return ira->codegen->invalid_instruction; | | |
| 17553 | field->is_comptime = true; | | |
| 17554 | field->init_val = create_const_vals(1); | | |
| 17555 | copy_const_val(field->init_val, val); | | |
| 17556 | return result_loc; | | |
| 17557 | } | | |
| 17558 | | | |
| 17559 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); | | |
| 17560 | IrInstruction *casted_ptr; | 17536 | IrInstruction *casted_ptr; |
| 17561 | if (instr_is_comptime(result_loc)) { | 17537 | if (isf->already_resolved) { |
| 17562 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); | 17538 | field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| 17563 | copy_const_val(casted_ptr->value, result_loc->value); | | |
| 17564 | casted_ptr->value->type = struct_ptr_type; | | |
| 17565 | } else { | | |
| 17566 | casted_ptr = result_loc; | 17539 | casted_ptr = result_loc; |
| 17567 | } | 17540 | } else { |
| 17568 | if (instr_is_comptime(casted_ptr)) { | 17541 | isf->already_resolved = true; |
| 17569 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); | 17542 | // Now it's time to add the field to the struct type. |
| 17570 | if (!ptr_val) | 17543 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 17571 | return ira->codegen->invalid_instruction; | 17544 | uint32_t new_field_count = old_field_count + 1; |
| 17572 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | 17545 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; |
| 17573 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, | 17546 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( |
| 17574 | suspend_source_instr->source_node); | 17547 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); |
| 17575 | struct_val->special = ConstValSpecialStatic; | 17548 | |
| 17576 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, | 17549 | field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 17577 | old_field_count, new_field_count); | 17550 | field->name = isf->field_name; |
| 17578 | | 17551 | field->type_entry = value_type; |
| 17579 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; | 17552 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 17580 | field_val->special = ConstValSpecialUndef; | 17553 | field->src_index = old_field_count; |
| 17581 | field_val->type = field->type_entry; | 17554 | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; |
| 17582 | field_val->parent.id = ConstParentIdStruct; | 17555 | if (value && instr_is_comptime(value)) { |
| 17583 | field_val->parent.data.p_struct.struct_val = struct_val; | 17556 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 17584 | field_val->parent.data.p_struct.field_index = old_field_count; | 17557 | if (!val) |
| | 17558 | return ira->codegen->invalid_instruction; |
| | 17559 | field->is_comptime = true; |
| | 17560 | field->init_val = create_const_vals(1); |
| | 17561 | copy_const_val(field->init_val, val); |
| | 17562 | return result_loc; |
| | 17563 | } |
| | 17564 | |
| | 17565 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| | 17566 | if (instr_is_comptime(result_loc)) { |
| | 17567 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| | 17568 | copy_const_val(casted_ptr->value, result_loc->value); |
| | 17569 | casted_ptr->value->type = struct_ptr_type; |
| | 17570 | } else { |
| | 17571 | casted_ptr = result_loc; |
| | 17572 | } |
| | 17573 | if (instr_is_comptime(casted_ptr)) { |
| | 17574 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| | 17575 | if (!ptr_val) |
| | 17576 | return ira->codegen->invalid_instruction; |
| | 17577 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| | 17578 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| | 17579 | suspend_source_instr->source_node); |
| | 17580 | struct_val->special = ConstValSpecialStatic; |
| | 17581 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, |
| | 17582 | old_field_count, new_field_count); |
| | 17583 | |
| | 17584 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| | 17585 | field_val->special = ConstValSpecialUndef; |
| | 17586 | field_val->type = field->type_entry; |
| | 17587 | field_val->parent.id = ConstParentIdStruct; |
| | 17588 | field_val->parent.data.p_struct.struct_val = struct_val; |
| | 17589 | field_val->parent.data.p_struct.field_index = old_field_count; |
| | 17590 | } |
| 17585 | } | 17591 | } |
| 17586 | } | 17592 | } |
| 17587 | | 17593 | |