| ... | ... | @@ -7633,38 +7633,16 @@ static bool slice_is_const(TypeTableEntry *type) { |
| 7633 | 7633 | return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; |
| 7634 | 7634 | } |
| 7635 | 7635 | |
| 7636 | | static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) { |
| 7637 | | assert(err_set_type->id == TypeTableEntryIdErrorSet); |
| 7638 | | FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; |
| 7639 | | if (infer_fn != nullptr) { |
| 7640 | | if (infer_fn->anal_state == FnAnalStateInvalid) { |
| 7641 | | return false; |
| 7642 | | } else if (infer_fn->anal_state == FnAnalStateReady) { |
| 7643 | | analyze_fn_body(ira->codegen, infer_fn); |
| 7644 | | if (err_set_type->data.error_set.infer_fn != nullptr) { |
| 7645 | | assert(ira->codegen->errors.length != 0); |
| 7646 | | return false; |
| 7647 | | } |
| 7648 | | } else { |
| 7649 | | ir_add_error_node(ira, source_node, |
| 7650 | | buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet", |
| 7651 | | buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name))); |
| 7652 | | return false; |
| 7653 | | } |
| 7654 | | } |
| 7655 | | return true; |
| 7656 | | } |
| 7657 | | |
| 7658 | 7636 | static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2, |
| 7659 | 7637 | AstNode *source_node) |
| 7660 | 7638 | { |
| 7661 | 7639 | assert(set1->id == TypeTableEntryIdErrorSet); |
| 7662 | 7640 | assert(set2->id == TypeTableEntryIdErrorSet); |
| 7663 | 7641 | |
| 7664 | | if (!resolve_inferred_error_set(ira, set1, source_node)) { |
| 7642 | if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { |
| 7665 | 7643 | return ira->codegen->builtin_types.entry_invalid; |
| 7666 | 7644 | } |
| 7667 | | if (!resolve_inferred_error_set(ira, set2, source_node)) { |
| 7645 | if (!resolve_inferred_error_set(ira->codegen, set2, source_node)) { |
| 7668 | 7646 | return ira->codegen->builtin_types.entry_invalid; |
| 7669 | 7647 | } |
| 7670 | 7648 | if (type_is_global_error_set(set1)) { |
| ... | ... | @@ -7803,7 +7781,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 7803 | 7781 | return result; |
| 7804 | 7782 | } |
| 7805 | 7783 | |
| 7806 | | if (!resolve_inferred_error_set(ira, contained_set, source_node)) { |
| 7784 | if (!resolve_inferred_error_set(ira->codegen, contained_set, source_node)) { |
| 7807 | 7785 | result.id = ConstCastResultIdUnresolvedInferredErrSet; |
| 7808 | 7786 | return result; |
| 7809 | 7787 | } |
| ... | ... | @@ -8192,7 +8170,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8192 | 8170 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 8193 | 8171 | } else { |
| 8194 | 8172 | err_set_type = prev_inst->value.type; |
| 8195 | | if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) { |
| 8173 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, prev_inst->source_node)) { |
| 8196 | 8174 | return ira->codegen->builtin_types.entry_invalid; |
| 8197 | 8175 | } |
| 8198 | 8176 | update_errors_helper(ira->codegen, &errors, &errors_count); |
| ... | ... | @@ -8231,7 +8209,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8231 | 8209 | if (type_is_global_error_set(err_set_type)) { |
| 8232 | 8210 | continue; |
| 8233 | 8211 | } |
| 8234 | | if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { |
| 8212 | if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 8235 | 8213 | return ira->codegen->builtin_types.entry_invalid; |
| 8236 | 8214 | } |
| 8237 | 8215 | if (type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -8297,7 +8275,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8297 | 8275 | continue; |
| 8298 | 8276 | } |
| 8299 | 8277 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8300 | | if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { |
| 8278 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 8301 | 8279 | return ira->codegen->builtin_types.entry_invalid; |
| 8302 | 8280 | } |
| 8303 | 8281 | if (type_is_global_error_set(cur_err_set_type)) { |
| ... | ... | @@ -8360,7 +8338,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8360 | 8338 | if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) { |
| 8361 | 8339 | continue; |
| 8362 | 8340 | } |
| 8363 | | if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { |
| 8341 | if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 8364 | 8342 | return ira->codegen->builtin_types.entry_invalid; |
| 8365 | 8343 | } |
| 8366 | 8344 | |
| ... | ... | @@ -8417,11 +8395,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8417 | 8395 | TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; |
| 8418 | 8396 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8419 | 8397 | |
| 8420 | | if (!resolve_inferred_error_set(ira, prev_err_set_type, cur_inst->source_node)) { |
| 8398 | if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 8421 | 8399 | return ira->codegen->builtin_types.entry_invalid; |
| 8422 | 8400 | } |
| 8423 | 8401 | |
| 8424 | | if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { |
| 8402 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 8425 | 8403 | return ira->codegen->builtin_types.entry_invalid; |
| 8426 | 8404 | } |
| 8427 | 8405 | |
| ... | ... | @@ -8531,7 +8509,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8531 | 8509 | { |
| 8532 | 8510 | if (err_set_type != nullptr) { |
| 8533 | 8511 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8534 | | if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { |
| 8512 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 8535 | 8513 | return ira->codegen->builtin_types.entry_invalid; |
| 8536 | 8514 | } |
| 8537 | 8515 | if (type_is_global_error_set(cur_err_set_type) || type_is_global_error_set(err_set_type)) { |
| ... | ... | @@ -9213,7 +9191,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 9213 | 9191 | if (!val) |
| 9214 | 9192 | return ira->codegen->invalid_instruction; |
| 9215 | 9193 | |
| 9216 | | if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) { |
| 9194 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 9217 | 9195 | return ira->codegen->invalid_instruction; |
| 9218 | 9196 | } |
| 9219 | 9197 | if (!type_is_global_error_set(wanted_type)) { |
| ... | ... | @@ -9654,7 +9632,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 9654 | 9632 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 9655 | 9633 | source_instr->source_node, wanted_type); |
| 9656 | 9634 | |
| 9657 | | if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) { |
| 9635 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 9658 | 9636 | return ira->codegen->invalid_instruction; |
| 9659 | 9637 | } |
| 9660 | 9638 | |
| ... | ... | @@ -9752,7 +9730,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 9752 | 9730 | zig_unreachable(); |
| 9753 | 9731 | } |
| 9754 | 9732 | if (!type_is_global_error_set(err_set_type)) { |
| 9755 | | if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) { |
| 9733 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) { |
| 9756 | 9734 | return ira->codegen->invalid_instruction; |
| 9757 | 9735 | } |
| 9758 | 9736 | if (err_set_type->data.error_set.err_count == 0) { |
| ... | ... | @@ -10647,7 +10625,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 10647 | 10625 | return ira->codegen->builtin_types.entry_invalid; |
| 10648 | 10626 | } |
| 10649 | 10627 | |
| 10650 | | if (!resolve_inferred_error_set(ira, intersect_type, source_node)) { |
| 10628 | if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) { |
| 10651 | 10629 | return ira->codegen->builtin_types.entry_invalid; |
| 10652 | 10630 | } |
| 10653 | 10631 | |
| ... | ... | @@ -11503,11 +11481,11 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction |
| 11503 | 11481 | return ira->codegen->builtin_types.entry_type; |
| 11504 | 11482 | } |
| 11505 | 11483 | |
| 11506 | | if (!resolve_inferred_error_set(ira, op1_type, instruction->op1->other->source_node)) { |
| 11484 | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->other->source_node)) { |
| 11507 | 11485 | return ira->codegen->builtin_types.entry_invalid; |
| 11508 | 11486 | } |
| 11509 | 11487 | |
| 11510 | | if (!resolve_inferred_error_set(ira, op2_type, instruction->op2->other->source_node)) { |
| 11488 | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->other->source_node)) { |
| 11511 | 11489 | return ira->codegen->builtin_types.entry_invalid; |
| 11512 | 11490 | } |
| 11513 | 11491 | |
| ... | ... | @@ -13851,7 +13829,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 13851 | 13829 | } |
| 13852 | 13830 | err_set_type = err_entry->set_with_only_this_in_it; |
| 13853 | 13831 | } else { |
| 13854 | | if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) { |
| 13832 | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { |
| 13855 | 13833 | return ira->codegen->builtin_types.entry_invalid; |
| 13856 | 13834 | } |
| 13857 | 13835 | err_entry = find_err_table_entry(child_type, field_name); |
| ... | ... | @@ -17559,7 +17537,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 17559 | 17537 | } else if (container_type->id == TypeTableEntryIdUnion) { |
| 17560 | 17538 | result = container_type->data.unionation.src_field_count; |
| 17561 | 17539 | } else if (container_type->id == TypeTableEntryIdErrorSet) { |
| 17562 | | if (!resolve_inferred_error_set(ira, container_type, instruction->base.source_node)) { |
| 17540 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 17563 | 17541 | return ira->codegen->builtin_types.entry_invalid; |
| 17564 | 17542 | } |
| 17565 | 17543 | if (type_is_global_error_set(container_type)) { |
| ... | ... | @@ -17863,7 +17841,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 17863 | 17841 | } |
| 17864 | 17842 | |
| 17865 | 17843 | TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type; |
| 17866 | | if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) { |
| 17844 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 17867 | 17845 | return ira->codegen->builtin_types.entry_invalid; |
| 17868 | 17846 | } |
| 17869 | 17847 | if (!type_is_global_error_set(err_set_type) && |
| ... | ... | @@ -18131,7 +18109,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 18131 | 18109 | } |
| 18132 | 18110 | } |
| 18133 | 18111 | } else if (switch_type->id == TypeTableEntryIdErrorSet) { |
| 18134 | | if (!resolve_inferred_error_set(ira, switch_type, target_value->source_node)) { |
| 18112 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 18135 | 18113 | return ira->codegen->builtin_types.entry_invalid; |
| 18136 | 18114 | } |
| 18137 | 18115 | |