authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 13:20:19-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 13:20:19-05:00
logb59841a80f564c63c667f6142832407086b67b56
tree6deba3561e0eee83dea2eca702de94df0dfdb04f
parent0cdfd5c1411a3e6af1ba7d579ef8bb5e752cbc2d

IR: fix err variable in ErrOkOr instruction


4 files changed, 2 insertions(+), 59 deletions(-)

src/all_types.hpp-7
......@@ -1442,7 +1442,6 @@ enum IrInstructionId {
14421442 IrInstructionIdTestErr,
14431443 IrInstructionIdUnwrapErrCode,
14441444 IrInstructionIdUnwrapErrPayload,
1445 IrInstructionIdErrUnionTypeChild,
14461445 IrInstructionIdErrWrapCode,
14471446 IrInstructionIdErrWrapPayload,
14481447};
......@@ -2036,12 +2035,6 @@ struct IrInstructionUnwrapErrPayload {
20362035 bool safety_check_on;
20372036};
20382037
2039struct IrInstructionErrUnionTypeChild {
2040 IrInstruction base;
2041
2042 IrInstruction *type_value;
2043};
2044
20452038struct IrInstructionMaybeWrap {
20462039 IrInstruction base;
20472040
src/codegen.cpp-1
......@@ -2191,7 +2191,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
21912191 case IrInstructionIdIntType:
21922192 case IrInstructionIdMemberCount:
21932193 case IrInstructionIdAlignOf:
2194 case IrInstructionIdErrUnionTypeChild:
21952194 zig_unreachable();
21962195 case IrInstructionIdReturn:
21972196 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);
src/ir.cpp+2-42
......@@ -427,10 +427,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload
427427 return IrInstructionIdUnwrapErrPayload;
428428}
429429
430static constexpr IrInstructionId ir_instruction_id(IrInstructionErrUnionTypeChild *) {
431 return IrInstructionIdErrUnionTypeChild;
432}
433
434430static constexpr IrInstructionId ir_instruction_id(IrInstructionMaybeWrap *) {
435431 return IrInstructionIdMaybeWrap;
436432}
......@@ -1830,17 +1826,6 @@ static IrInstruction *ir_build_unwrap_err_payload_from(IrBuilder *irb, IrInstruc
18301826 return new_instruction;
18311827}
18321828
1833static IrInstruction *ir_build_err_union_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node,
1834 IrInstruction *type_value)
1835{
1836 IrInstructionErrUnionTypeChild *instruction = ir_build_instruction<IrInstructionErrUnionTypeChild>(irb, scope, source_node);
1837 instruction->type_value = type_value;
1838
1839 ir_ref_instruction(type_value);
1840
1841 return &instruction->base;
1842}
1843
18441829static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
18451830 results[ReturnKindUnconditional] = 0;
18461831 results[ReturnKindError] = 0;
......@@ -3841,9 +3826,8 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
38413826 Scope *err_scope;
38423827 if (var_node) {
38433828 assert(var_node->type == NodeTypeSymbol);
3844 IrInstruction *err_union_ptr_type = ir_build_typeof(irb, parent_scope, var_node, err_union_ptr);
3845 IrInstruction *err_union_type = ir_build_ptr_type_child(irb, parent_scope, var_node, err_union_ptr_type);
3846 IrInstruction *var_type = ir_build_err_union_type_child(irb, parent_scope, var_node, err_union_type);
3829 IrInstruction *var_type = ir_build_const_type(irb, parent_scope, node,
3830 irb->codegen->builtin_types.entry_pure_error);
38473831 Buf *var_name = var_node->data.symbol_expr.symbol;
38483832 bool is_const = true;
38493833 bool is_shadowable = false;
......@@ -9339,27 +9323,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
93399323
93409324}
93419325
9342static TypeTableEntry *ir_analyze_instruction_err_union_type_child(IrAnalyze *ira,
9343 IrInstructionErrUnionTypeChild *instruction)
9344{
9345 IrInstruction *type_value = instruction->type_value->other;
9346 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
9347 if (type_entry->id == TypeTableEntryIdInvalid)
9348 return type_entry;
9349
9350 // TODO handle typedefs
9351 if (type_entry->id != TypeTableEntryIdErrorUnion) {
9352 add_node_error(ira->codegen, instruction->base.source_node,
9353 buf_sprintf("expected error type, found '%s'", buf_ptr(&type_entry->name)));
9354 return ira->codegen->builtin_types.entry_invalid;
9355 }
9356
9357 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base,
9358 type_value->static_value.depends_on_compile_var);
9359 out_val->data.x_type = type_entry->data.error.child_type;
9360 return ira->codegen->builtin_types.entry_type;
9361}
9362
93639326static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
93649327 switch (instruction->id) {
93659328 case IrInstructionIdInvalid:
......@@ -9500,8 +9463,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
95009463 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);
95019464 case IrInstructionIdUnwrapErrPayload:
95029465 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);
9503 case IrInstructionIdErrUnionTypeChild:
9504 return ir_analyze_instruction_err_union_type_child(ira, (IrInstructionErrUnionTypeChild *)instruction);
95059466 case IrInstructionIdMaybeWrap:
95069467 case IrInstructionIdErrWrapCode:
95079468 case IrInstructionIdErrWrapPayload:
......@@ -9659,7 +9620,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
96599620 case IrInstructionIdTestErr:
96609621 case IrInstructionIdUnwrapErrCode:
96619622 case IrInstructionIdUnwrapErrPayload:
9662 case IrInstructionIdErrUnionTypeChild:
96639623 case IrInstructionIdMaybeWrap:
96649624 case IrInstructionIdErrWrapCode:
96659625 case IrInstructionIdErrWrapPayload:
src/ir_print.cpp-9
......@@ -849,12 +849,6 @@ static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) {
849849 fprintf(irp->f, ")");
850850}
851851
852static void ir_print_err_union_type_child(IrPrint *irp, IrInstructionErrUnionTypeChild *instruction) {
853 fprintf(irp->f, "@errorUnionTypeChild(");
854 ir_print_other_instruction(irp, instruction->type_value);
855 fprintf(irp->f, ")");
856}
857
858852static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
859853 fprintf(irp->f, "@unwrapErrorCode(");
860854 ir_print_other_instruction(irp, instruction->value);
......@@ -1109,9 +1103,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
11091103 case IrInstructionIdUnwrapErrPayload:
11101104 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
11111105 break;
1112 case IrInstructionIdErrUnionTypeChild:
1113 ir_print_err_union_type_child(irp, (IrInstructionErrUnionTypeChild *)instruction);
1114 break;
11151106 case IrInstructionIdMaybeWrap:
11161107 ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);
11171108 break;