authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-05-30 10:34:20+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-05-30 10:34:20+02:00
log1b3aaacba260e4c8d89ac98ab856ff9b3c77dac4
tree2bc1d01d4daa8db2451fd91834b241a0018d6c9d
parent2b3af4ef6b79b8fe178656b069f837eff82ae8c3

Removed copy-pasted resolve_inferred_error_set

both ir.cpp and analyze.cpp have a function resolve_inferred_error_set, which is a nearly exact copy-paste. This commit removes the one in ir.cpp and exposes then one in analyze.cpp. This also allows us to make analyze_fn_body local to analyze.cpp, as it is not used anywhere in ir.cpp after this change

3 files changed, 25 insertions(+), 46 deletions(-)

src/analyze.cpp+4-3
......@@ -25,6 +25,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type);
2525static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type);
2626static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
2727static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
28static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
2829
2930ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
3031 if (node->owner->c_import_node != nullptr) {
......@@ -3880,7 +3881,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
38803881 }
38813882}
38823883
3883static bool analyze_resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
3884bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
38843885 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
38853886 if (infer_fn != nullptr) {
38863887 if (infer_fn->anal_state == FnAnalStateInvalid) {
......@@ -3932,7 +3933,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
39323933 }
39333934
39343935 if (inferred_err_set_type->data.error_set.infer_fn != nullptr) {
3935 if (!analyze_resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
3936 if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
39363937 fn_table_entry->anal_state = FnAnalStateInvalid;
39373938 return;
39383939 }
......@@ -3962,7 +3963,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
39623963 fn_table_entry->anal_state = FnAnalStateComplete;
39633964}
39643965
3965void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
3966static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
39663967 assert(fn_table_entry->anal_state != FnAnalStateProbing);
39673968 if (fn_table_entry->anal_state != FnAnalStateReady)
39683969 return;
src/analyze.hpp+1-1
......@@ -191,7 +191,7 @@ void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, G
191191
192192ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
193193TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);
194void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
194bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node);
195195
196196TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
197197
src/ir.cpp+20-42
......@@ -7633,38 +7633,16 @@ static bool slice_is_const(TypeTableEntry *type) {
76337633 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
76347634}
76357635
7636static 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
76587636static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2,
76597637 AstNode *source_node)
76607638{
76617639 assert(set1->id == TypeTableEntryIdErrorSet);
76627640 assert(set2->id == TypeTableEntryIdErrorSet);
76637641
7664 if (!resolve_inferred_error_set(ira, set1, source_node)) {
7642 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
76657643 return ira->codegen->builtin_types.entry_invalid;
76667644 }
7667 if (!resolve_inferred_error_set(ira, set2, source_node)) {
7645 if (!resolve_inferred_error_set(ira->codegen, set2, source_node)) {
76687646 return ira->codegen->builtin_types.entry_invalid;
76697647 }
76707648 if (type_is_global_error_set(set1)) {
......@@ -7803,7 +7781,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
78037781 return result;
78047782 }
78057783
7806 if (!resolve_inferred_error_set(ira, contained_set, source_node)) {
7784 if (!resolve_inferred_error_set(ira->codegen, contained_set, source_node)) {
78077785 result.id = ConstCastResultIdUnresolvedInferredErrSet;
78087786 return result;
78097787 }
......@@ -8192,7 +8170,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
81928170 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
81938171 } else {
81948172 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)) {
81968174 return ira->codegen->builtin_types.entry_invalid;
81978175 }
81988176 update_errors_helper(ira->codegen, &errors, &errors_count);
......@@ -8231,7 +8209,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
82318209 if (type_is_global_error_set(err_set_type)) {
82328210 continue;
82338211 }
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)) {
82358213 return ira->codegen->builtin_types.entry_invalid;
82368214 }
82378215 if (type_is_global_error_set(cur_type)) {
......@@ -8297,7 +8275,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
82978275 continue;
82988276 }
82998277 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)) {
83018279 return ira->codegen->builtin_types.entry_invalid;
83028280 }
83038281 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
83608338 if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) {
83618339 continue;
83628340 }
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)) {
83648342 return ira->codegen->builtin_types.entry_invalid;
83658343 }
83668344
......@@ -8417,11 +8395,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
84178395 TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
84188396 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
84198397
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)) {
84218399 return ira->codegen->builtin_types.entry_invalid;
84228400 }
84238401
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)) {
84258403 return ira->codegen->builtin_types.entry_invalid;
84268404 }
84278405
......@@ -8531,7 +8509,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
85318509 {
85328510 if (err_set_type != nullptr) {
85338511 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)) {
85358513 return ira->codegen->builtin_types.entry_invalid;
85368514 }
85378515 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
92139191 if (!val)
92149192 return ira->codegen->invalid_instruction;
92159193
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)) {
92179195 return ira->codegen->invalid_instruction;
92189196 }
92199197 if (!type_is_global_error_set(wanted_type)) {
......@@ -9654,7 +9632,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
96549632 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
96559633 source_instr->source_node, wanted_type);
96569634
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)) {
96589636 return ira->codegen->invalid_instruction;
96599637 }
96609638
......@@ -9752,7 +9730,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
97529730 zig_unreachable();
97539731 }
97549732 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)) {
97569734 return ira->codegen->invalid_instruction;
97579735 }
97589736 if (err_set_type->data.error_set.err_count == 0) {
......@@ -10647,7 +10625,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1064710625 return ira->codegen->builtin_types.entry_invalid;
1064810626 }
1064910627
10650 if (!resolve_inferred_error_set(ira, intersect_type, source_node)) {
10628 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
1065110629 return ira->codegen->builtin_types.entry_invalid;
1065210630 }
1065310631
......@@ -11503,11 +11481,11 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
1150311481 return ira->codegen->builtin_types.entry_type;
1150411482 }
1150511483
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)) {
1150711485 return ira->codegen->builtin_types.entry_invalid;
1150811486 }
1150911487
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)) {
1151111489 return ira->codegen->builtin_types.entry_invalid;
1151211490 }
1151311491
......@@ -13851,7 +13829,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1385113829 }
1385213830 err_set_type = err_entry->set_with_only_this_in_it;
1385313831 } 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)) {
1385513833 return ira->codegen->builtin_types.entry_invalid;
1385613834 }
1385713835 err_entry = find_err_table_entry(child_type, field_name);
......@@ -17559,7 +17537,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1755917537 } else if (container_type->id == TypeTableEntryIdUnion) {
1756017538 result = container_type->data.unionation.src_field_count;
1756117539 } 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)) {
1756317541 return ira->codegen->builtin_types.entry_invalid;
1756417542 }
1756517543 if (type_is_global_error_set(container_type)) {
......@@ -17863,7 +17841,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1786317841 }
1786417842
1786517843 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)) {
1786717845 return ira->codegen->builtin_types.entry_invalid;
1786817846 }
1786917847 if (!type_is_global_error_set(err_set_type) &&
......@@ -18131,7 +18109,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1813118109 }
1813218110 }
1813318111 } 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)) {
1813518113 return ira->codegen->builtin_types.entry_invalid;
1813618114 }
1813718115