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 {...@@ -1442,7 +1442,6 @@ enum IrInstructionId {
1442 IrInstructionIdTestErr,1442 IrInstructionIdTestErr,
1443 IrInstructionIdUnwrapErrCode,1443 IrInstructionIdUnwrapErrCode,
1444 IrInstructionIdUnwrapErrPayload,1444 IrInstructionIdUnwrapErrPayload,
1445 IrInstructionIdErrUnionTypeChild,
1446 IrInstructionIdErrWrapCode,1445 IrInstructionIdErrWrapCode,
1447 IrInstructionIdErrWrapPayload,1446 IrInstructionIdErrWrapPayload,
1448};1447};
...@@ -2036,12 +2035,6 @@ struct IrInstructionUnwrapErrPayload {...@@ -2036,12 +2035,6 @@ struct IrInstructionUnwrapErrPayload {
2036 bool safety_check_on;2035 bool safety_check_on;
2037};2036};
20382037
2039struct IrInstructionErrUnionTypeChild {
2040 IrInstruction base;
2041
2042 IrInstruction *type_value;
2043};
2044
2045struct IrInstructionMaybeWrap {2038struct IrInstructionMaybeWrap {
2046 IrInstruction base;2039 IrInstruction base;
20472040
src/codegen.cpp-1
...@@ -2191,7 +2191,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -2191,7 +2191,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
2191 case IrInstructionIdIntType:2191 case IrInstructionIdIntType:
2192 case IrInstructionIdMemberCount:2192 case IrInstructionIdMemberCount:
2193 case IrInstructionIdAlignOf:2193 case IrInstructionIdAlignOf:
2194 case IrInstructionIdErrUnionTypeChild:
2195 zig_unreachable();2194 zig_unreachable();
2196 case IrInstructionIdReturn:2195 case IrInstructionIdReturn:
2197 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);2196 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);
src/ir.cpp+2-42
...@@ -427,10 +427,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload...@@ -427,10 +427,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload
427 return IrInstructionIdUnwrapErrPayload;427 return IrInstructionIdUnwrapErrPayload;
428}428}
429429
430static constexpr IrInstructionId ir_instruction_id(IrInstructionErrUnionTypeChild *) {
431 return IrInstructionIdErrUnionTypeChild;
432}
433
434static constexpr IrInstructionId ir_instruction_id(IrInstructionMaybeWrap *) {430static constexpr IrInstructionId ir_instruction_id(IrInstructionMaybeWrap *) {
435 return IrInstructionIdMaybeWrap;431 return IrInstructionIdMaybeWrap;
436}432}
...@@ -1830,17 +1826,6 @@ static IrInstruction *ir_build_unwrap_err_payload_from(IrBuilder *irb, IrInstruc...@@ -1830,17 +1826,6 @@ static IrInstruction *ir_build_unwrap_err_payload_from(IrBuilder *irb, IrInstruc
1830 return new_instruction;1826 return new_instruction;
1831}1827}
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
1844static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {1829static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
1845 results[ReturnKindUnconditional] = 0;1830 results[ReturnKindUnconditional] = 0;
1846 results[ReturnKindError] = 0;1831 results[ReturnKindError] = 0;
...@@ -3841,9 +3826,8 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN...@@ -3841,9 +3826,8 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
3841 Scope *err_scope;3826 Scope *err_scope;
3842 if (var_node) {3827 if (var_node) {
3843 assert(var_node->type == NodeTypeSymbol);3828 assert(var_node->type == NodeTypeSymbol);
3844 IrInstruction *err_union_ptr_type = ir_build_typeof(irb, parent_scope, var_node, err_union_ptr);3829 IrInstruction *var_type = ir_build_const_type(irb, parent_scope, node,
3845 IrInstruction *err_union_type = ir_build_ptr_type_child(irb, parent_scope, var_node, err_union_ptr_type);3830 irb->codegen->builtin_types.entry_pure_error);
3846 IrInstruction *var_type = ir_build_err_union_type_child(irb, parent_scope, var_node, err_union_type);
3847 Buf *var_name = var_node->data.symbol_expr.symbol;3831 Buf *var_name = var_node->data.symbol_expr.symbol;
3848 bool is_const = true;3832 bool is_const = true;
3849 bool is_shadowable = false;3833 bool is_shadowable = false;
...@@ -9339,27 +9323,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -9339,27 +9323,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
93399323
9340}9324}
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
9363static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {9326static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
9364 switch (instruction->id) {9327 switch (instruction->id) {
9365 case IrInstructionIdInvalid:9328 case IrInstructionIdInvalid:
...@@ -9500,8 +9463,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -9500,8 +9463,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
9500 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);9463 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);
9501 case IrInstructionIdUnwrapErrPayload:9464 case IrInstructionIdUnwrapErrPayload:
9502 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);9465 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);
9505 case IrInstructionIdMaybeWrap:9466 case IrInstructionIdMaybeWrap:
9506 case IrInstructionIdErrWrapCode:9467 case IrInstructionIdErrWrapCode:
9507 case IrInstructionIdErrWrapPayload:9468 case IrInstructionIdErrWrapPayload:
...@@ -9659,7 +9620,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -9659,7 +9620,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
9659 case IrInstructionIdTestErr:9620 case IrInstructionIdTestErr:
9660 case IrInstructionIdUnwrapErrCode:9621 case IrInstructionIdUnwrapErrCode:
9661 case IrInstructionIdUnwrapErrPayload:9622 case IrInstructionIdUnwrapErrPayload:
9662 case IrInstructionIdErrUnionTypeChild:
9663 case IrInstructionIdMaybeWrap:9623 case IrInstructionIdMaybeWrap:
9664 case IrInstructionIdErrWrapCode:9624 case IrInstructionIdErrWrapCode:
9665 case IrInstructionIdErrWrapPayload:9625 case IrInstructionIdErrWrapPayload:
src/ir_print.cpp-9
...@@ -849,12 +849,6 @@ static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) {...@@ -849,12 +849,6 @@ static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) {
849 fprintf(irp->f, ")");849 fprintf(irp->f, ")");
850}850}
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
858static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {852static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
859 fprintf(irp->f, "@unwrapErrorCode(");853 fprintf(irp->f, "@unwrapErrorCode(");
860 ir_print_other_instruction(irp, instruction->value);854 ir_print_other_instruction(irp, instruction->value);
...@@ -1109,9 +1103,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1109,9 +1103,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1109 case IrInstructionIdUnwrapErrPayload:1103 case IrInstructionIdUnwrapErrPayload:
1110 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);1104 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
1111 break;1105 break;
1112 case IrInstructionIdErrUnionTypeChild:
1113 ir_print_err_union_type_child(irp, (IrInstructionErrUnionTypeChild *)instruction);
1114 break;
1115 case IrInstructionIdMaybeWrap:1106 case IrInstructionIdMaybeWrap:
1116 ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);1107 ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);
1117 break;1108 break;