From 1b3aaacba260e4c8d89ac98ab856ff9b3c77dac4 Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Wed, 30 May 2018 10:34:20 +0200 Subject: [PATCH] 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 --- src/analyze.cpp | 7 +++--- src/analyze.hpp | 2 +- src/ir.cpp | 62 ++++++++++++++++--------------------------------- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index c59fde8ef6..b00e18a9a1 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -25,6 +25,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type); static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type); static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type); static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type); +static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { if (node->owner->c_import_node != nullptr) { @@ -3880,7 +3881,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr } } -static bool analyze_resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) { +bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) { FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; if (infer_fn != nullptr) { if (infer_fn->anal_state == FnAnalStateInvalid) { @@ -3932,7 +3933,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ } if (inferred_err_set_type->data.error_set.infer_fn != nullptr) { - if (!analyze_resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) { + if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) { fn_table_entry->anal_state = FnAnalStateInvalid; return; } @@ -3962,7 +3963,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ fn_table_entry->anal_state = FnAnalStateComplete; } -void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { +static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { assert(fn_table_entry->anal_state != FnAnalStateProbing); if (fn_table_entry->anal_state != FnAnalStateReady) return; diff --git a/src/analyze.hpp b/src/analyze.hpp index 56ca21a93f..d538f042ce 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -191,7 +191,7 @@ void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, G ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name); TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g); -void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry); +bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node); TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry); diff --git a/src/ir.cpp b/src/ir.cpp index 5d182fe9b0..8d32a81e25 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7633,38 +7633,16 @@ static bool slice_is_const(TypeTableEntry *type) { return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; } -static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) { - assert(err_set_type->id == TypeTableEntryIdErrorSet); - FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; - if (infer_fn != nullptr) { - if (infer_fn->anal_state == FnAnalStateInvalid) { - return false; - } else if (infer_fn->anal_state == FnAnalStateReady) { - analyze_fn_body(ira->codegen, infer_fn); - if (err_set_type->data.error_set.infer_fn != nullptr) { - assert(ira->codegen->errors.length != 0); - return false; - } - } else { - ir_add_error_node(ira, source_node, - buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet", - buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name))); - return false; - } - } - return true; -} - static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2, AstNode *source_node) { assert(set1->id == TypeTableEntryIdErrorSet); assert(set2->id == TypeTableEntryIdErrorSet); - if (!resolve_inferred_error_set(ira, set1, source_node)) { + if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { return ira->codegen->builtin_types.entry_invalid; } - if (!resolve_inferred_error_set(ira, set2, source_node)) { + if (!resolve_inferred_error_set(ira->codegen, set2, source_node)) { return ira->codegen->builtin_types.entry_invalid; } if (type_is_global_error_set(set1)) { @@ -7803,7 +7781,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry return result; } - if (!resolve_inferred_error_set(ira, contained_set, source_node)) { + if (!resolve_inferred_error_set(ira->codegen, contained_set, source_node)) { result.id = ConstCastResultIdUnresolvedInferredErrSet; return result; } @@ -8192,7 +8170,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod err_set_type = ira->codegen->builtin_types.entry_global_error_set; } else { err_set_type = prev_inst->value.type; - if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, err_set_type, prev_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } update_errors_helper(ira->codegen, &errors, &errors_count); @@ -8231,7 +8209,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod if (type_is_global_error_set(err_set_type)) { continue; } - if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } if (type_is_global_error_set(cur_type)) { @@ -8297,7 +8275,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod continue; } TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; - if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } 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 if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) { continue; } - if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -8417,11 +8395,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; - if (!resolve_inferred_error_set(ira, prev_err_set_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } - if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -8531,7 +8509,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod { if (err_set_type != nullptr) { TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; - if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } 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 if (!val) return ira->codegen->invalid_instruction; - if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { return ira->codegen->invalid_instruction; } if (!type_is_global_error_set(wanted_type)) { @@ -9654,7 +9632,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type); - if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { return ira->codegen->invalid_instruction; } @@ -9752,7 +9730,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc zig_unreachable(); } if (!type_is_global_error_set(err_set_type)) { - if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) { return ira->codegen->invalid_instruction; } if (err_set_type->data.error_set.err_count == 0) { @@ -10647,7 +10625,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp return ira->codegen->builtin_types.entry_invalid; } - if (!resolve_inferred_error_set(ira, intersect_type, source_node)) { + if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -11503,11 +11481,11 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction return ira->codegen->builtin_types.entry_type; } - if (!resolve_inferred_error_set(ira, op1_type, instruction->op1->other->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->other->source_node)) { return ira->codegen->builtin_types.entry_invalid; } - if (!resolve_inferred_error_set(ira, op2_type, instruction->op2->other->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->other->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -13851,7 +13829,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru } err_set_type = err_entry->set_with_only_this_in_it; } else { - if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) { + if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } err_entry = find_err_table_entry(child_type, field_name); @@ -17559,7 +17537,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns } else if (container_type->id == TypeTableEntryIdUnion) { result = container_type->data.unionation.src_field_count; } else if (container_type->id == TypeTableEntryIdErrorSet) { - if (!resolve_inferred_error_set(ira, container_type, instruction->base.source_node)) { + if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } if (type_is_global_error_set(container_type)) { @@ -17863,7 +17841,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc } TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type; - if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) { + if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } if (!type_is_global_error_set(err_set_type) && @@ -18131,7 +18109,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira } } } else if (switch_type->id == TypeTableEntryIdErrorSet) { - if (!resolve_inferred_error_set(ira, switch_type, target_value->source_node)) { + if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { return ira->codegen->builtin_types.entry_invalid; }