authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-09 13:34:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-09 13:35:19-04:00
log2286003666e8216d809b30e164963a52cdb2d4f8
treecf27578b3cecf3b0570aa0766e3fa0ee5af2e167
parent8a547d9e811ab3d78b88b2a802338a0550b38902
signaturelock-open Commit is signed but in an unrecognized format.

improve names of error sets when using merge error sets operator


4 files changed, 111 insertions(+), 26 deletions(-)

src/all_types.hpp+11-1
...@@ -398,6 +398,7 @@ struct LazyValueErrUnionType {...@@ -398,6 +398,7 @@ struct LazyValueErrUnionType {
398 IrAnalyze *ira;398 IrAnalyze *ira;
399 IrInstruction *err_set_type;399 IrInstruction *err_set_type;
400 IrInstruction *payload_type;400 IrInstruction *payload_type;
401 Buf *type_name;
401};402};
402403
403struct ConstExprValue {404struct ConstExprValue {
...@@ -2407,6 +2408,7 @@ enum IrInstructionId {...@@ -2407,6 +2408,7 @@ enum IrInstructionId {
2407 IrInstructionIdPhi,2408 IrInstructionIdPhi,
2408 IrInstructionIdUnOp,2409 IrInstructionIdUnOp,
2409 IrInstructionIdBinOp,2410 IrInstructionIdBinOp,
2411 IrInstructionIdMergeErrSets,
2410 IrInstructionIdLoadPtr,2412 IrInstructionIdLoadPtr,
2411 IrInstructionIdLoadPtrGen,2413 IrInstructionIdLoadPtrGen,
2412 IrInstructionIdStorePtr,2414 IrInstructionIdStorePtr,
...@@ -2713,7 +2715,6 @@ enum IrBinOp {...@@ -2713,7 +2715,6 @@ enum IrBinOp {
2713 IrBinOpRemMod,2715 IrBinOpRemMod,
2714 IrBinOpArrayCat,2716 IrBinOpArrayCat,
2715 IrBinOpArrayMult,2717 IrBinOpArrayMult,
2716 IrBinOpMergeErrorSets,
2717};2718};
27182719
2719struct IrInstructionBinOp {2720struct IrInstructionBinOp {
...@@ -2725,6 +2726,14 @@ struct IrInstructionBinOp {...@@ -2725,6 +2726,14 @@ struct IrInstructionBinOp {
2725 bool safety_check_on;2726 bool safety_check_on;
2726};2727};
27272728
2729struct IrInstructionMergeErrSets {
2730 IrInstruction base;
2731
2732 IrInstruction *op1;
2733 IrInstruction *op2;
2734 Buf *type_name;
2735};
2736
2728struct IrInstructionLoadPtr {2737struct IrInstructionLoadPtr {
2729 IrInstruction base;2738 IrInstruction base;
27302739
...@@ -3633,6 +3642,7 @@ struct IrInstructionErrorUnion {...@@ -3633,6 +3642,7 @@ struct IrInstructionErrorUnion {
36333642
3634 IrInstruction *err_set;3643 IrInstruction *err_set;
3635 IrInstruction *payload;3644 IrInstruction *payload;
3645 Buf *type_name;
3636};3646};
36373647
3638struct IrInstructionAtomicRmw {3648struct IrInstructionAtomicRmw {
src/codegen.cpp+1-1
...@@ -2776,7 +2776,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2776,7 +2776,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2776 case IrBinOpArrayCat:2776 case IrBinOpArrayCat:
2777 case IrBinOpArrayMult:2777 case IrBinOpArrayMult:
2778 case IrBinOpRemUnspecified:2778 case IrBinOpRemUnspecified:
2779 case IrBinOpMergeErrorSets:
2780 zig_unreachable();2779 zig_unreachable();
2781 case IrBinOpBoolOr:2780 case IrBinOpBoolOr:
2782 return LLVMBuildOr(g->builder, op1_value, op2_value, "");2781 return LLVMBuildOr(g->builder, op1_value, op2_value, "");
...@@ -6040,6 +6039,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -6040,6 +6039,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
6040 case IrInstructionIdAllocaGen:6039 case IrInstructionIdAllocaGen:
6041 case IrInstructionIdAwaitSrc:6040 case IrInstructionIdAwaitSrc:
6042 case IrInstructionIdSplatSrc:6041 case IrInstructionIdSplatSrc:
6042 case IrInstructionIdMergeErrSets:
6043 zig_unreachable();6043 zig_unreachable();
60446044
6045 case IrInstructionIdDeclVarGen:6045 case IrInstructionIdDeclVarGen:
src/ir.cpp+85-22
...@@ -198,6 +198,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo...@@ -198,6 +198,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
198 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,198 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
199 LVal lval, ResultLoc *parent_result_loc);199 LVal lval, ResultLoc *parent_result_loc);
200static void ir_reset_result(ResultLoc *result_loc);200static void ir_reset_result(ResultLoc *result_loc);
201static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
202 Scope *scope, AstNode *source_node, Buf *out_bare_name);
201203
202static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {204static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
203 assert(get_src_ptr_type(const_val->type) != nullptr);205 assert(get_src_ptr_type(const_val->type) != nullptr);
...@@ -469,6 +471,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {...@@ -469,6 +471,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {
469 return IrInstructionIdBinOp;471 return IrInstructionIdBinOp;
470}472}
471473
474static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) {
475 return IrInstructionIdMergeErrSets;
476}
477
472static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {478static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {
473 return IrInstructionIdExport;479 return IrInstructionIdExport;
474}480}
...@@ -1290,6 +1296,20 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -1290,6 +1296,20 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *sou
1290 return &bin_op_instruction->base;1296 return &bin_op_instruction->base;
1291}1297}
12921298
1299static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node,
1300 IrInstruction *op1, IrInstruction *op2, Buf *type_name)
1301{
1302 IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node);
1303 merge_err_sets_instruction->op1 = op1;
1304 merge_err_sets_instruction->op2 = op2;
1305 merge_err_sets_instruction->type_name = type_name;
1306
1307 ir_ref_instruction(op1, irb->current_basic_block);
1308 ir_ref_instruction(op2, irb->current_basic_block);
1309
1310 return &merge_err_sets_instruction->base;
1311}
1312
1293static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,1313static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
1294 ScopeFnDef *crossed_fndef_scope)1314 ScopeFnDef *crossed_fndef_scope)
1295{1315{
...@@ -3894,6 +3914,20 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no...@@ -3894,6 +3914,20 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
3894 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);3914 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
3895}3915}
38963916
3917static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
3918 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
3919 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3920
3921 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)
3922 return irb->codegen->invalid_instruction;
3923
3924 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
3925 Buf bare_name = BUF_INIT;
3926 Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", scope, node, &bare_name);
3927
3928 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);
3929}
3930
3897static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {3931static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
3898 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);3932 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
3899 if (lvalue == irb->codegen->invalid_instruction)3933 if (lvalue == irb->codegen->invalid_instruction)
...@@ -3913,6 +3947,19 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -3913,6 +3947,19 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
3913 return ir_build_const_void(irb, scope, node);3947 return ir_build_const_void(irb, scope, node);
3914}3948}
39153949
3950static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
3951 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
3952 if (lvalue == irb->codegen->invalid_instruction)
3953 return lvalue;
3954 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
3955 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3956 if (op2 == irb->codegen->invalid_instruction)
3957 return op2;
3958 IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
3959 ir_build_store_ptr(irb, scope, node, lvalue, result);
3960 return ir_build_const_void(irb, scope, node);
3961}
3962
3916static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {3963static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
3917 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);3964 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
3918 if (lvalue == irb->codegen->invalid_instruction)3965 if (lvalue == irb->codegen->invalid_instruction)
...@@ -4153,7 +4200,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4153,7 +4200,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
4153 case BinOpTypeAssignBitOr:4200 case BinOpTypeAssignBitOr:
4154 return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBinOr), lval, result_loc);4201 return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpBinOr), lval, result_loc);
4155 case BinOpTypeAssignMergeErrorSets:4202 case BinOpTypeAssignMergeErrorSets:
4156 return ir_lval_wrap(irb, scope, ir_gen_assign_op(irb, scope, node, IrBinOpMergeErrorSets), lval, result_loc);4203 return ir_lval_wrap(irb, scope, ir_gen_assign_merge_err_sets(irb, scope, node), lval, result_loc);
4157 case BinOpTypeBoolOr:4204 case BinOpTypeBoolOr:
4158 return ir_lval_wrap(irb, scope, ir_gen_bool_or(irb, scope, node), lval, result_loc);4205 return ir_lval_wrap(irb, scope, ir_gen_bool_or(irb, scope, node), lval, result_loc);
4159 case BinOpTypeBoolAnd:4206 case BinOpTypeBoolAnd:
...@@ -4201,7 +4248,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4201,7 +4248,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
4201 case BinOpTypeArrayMult:4248 case BinOpTypeArrayMult:
4202 return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult), lval, result_loc);4249 return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult), lval, result_loc);
4203 case BinOpTypeMergeErrorSets:4250 case BinOpTypeMergeErrorSets:
4204 return ir_lval_wrap(irb, scope, ir_gen_bin_op_id(irb, scope, node, IrBinOpMergeErrorSets), lval, result_loc);4251 return ir_lval_wrap(irb, scope, ir_gen_merge_err_sets(irb, scope, node), lval, result_loc);
4205 case BinOpTypeUnwrapOptional:4252 case BinOpTypeUnwrapOptional:
4206 return ir_gen_orelse(irb, scope, node, lval, result_loc);4253 return ir_gen_orelse(irb, scope, node, lval, result_loc);
4207 case BinOpTypeErrorUnion:4254 case BinOpTypeErrorUnion:
...@@ -7859,7 +7906,9 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,...@@ -7859,7 +7906,9 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
7859}7906}
78607907
7861// errors should be populated with set1's values7908// errors should be populated with set1's values
7862static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {7909static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2,
7910 Buf *type_name)
7911{
7863 assert(set1->id == ZigTypeIdErrorSet);7912 assert(set1->id == ZigTypeIdErrorSet);
7864 assert(set2->id == ZigTypeIdErrorSet);7913 assert(set2->id == ZigTypeIdErrorSet);
78657914
...@@ -7867,8 +7916,12 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp...@@ -7867,8 +7916,12 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
7867 err_set_type->size_in_bits = g->builtin_types.entry_global_error_set->size_in_bits;7916 err_set_type->size_in_bits = g->builtin_types.entry_global_error_set->size_in_bits;
7868 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;7917 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
7869 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;7918 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
7870 buf_resize(&err_set_type->name, 0);7919 if (type_name == nullptr) {
7871 buf_appendf(&err_set_type->name, "error{");7920 buf_resize(&err_set_type->name, 0);
7921 buf_appendf(&err_set_type->name, "error{");
7922 } else {
7923 buf_init_from_buf(&err_set_type->name, type_name);
7924 }
78727925
7873 for (uint32_t i = 0, count = set1->data.error_set.err_count; i < count; i += 1) {7926 for (uint32_t i = 0, count = set1->data.error_set.err_count; i < count; i += 1) {
7874 assert(errors[set1->data.error_set.errors[i]->value] == set1->data.error_set.errors[i]);7927 assert(errors[set1->data.error_set.errors[i]->value] == set1->data.error_set.errors[i]);
...@@ -7885,21 +7938,27 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp...@@ -7885,21 +7938,27 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
7885 err_set_type->data.error_set.err_count = count;7938 err_set_type->data.error_set.err_count = count;
7886 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(count);7939 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(count);
78877940
7941 bool need_comma = false;
7888 for (uint32_t i = 0; i < set1->data.error_set.err_count; i += 1) {7942 for (uint32_t i = 0; i < set1->data.error_set.err_count; i += 1) {
7889 ErrorTableEntry *error_entry = set1->data.error_set.errors[i];7943 ErrorTableEntry *error_entry = set1->data.error_set.errors[i];
7890 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));7944 if (type_name == nullptr) {
7945 const char *comma = need_comma ? "," : "";
7946 need_comma = true;
7947 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&error_entry->name));
7948 }
7891 err_set_type->data.error_set.errors[i] = error_entry;7949 err_set_type->data.error_set.errors[i] = error_entry;
7892 }7950 }
78937951
7894 uint32_t index = set1->data.error_set.err_count;7952 uint32_t index = set1->data.error_set.err_count;
7895 bool need_comma = false;
7896 for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) {7953 for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) {
7897 ErrorTableEntry *error_entry = set2->data.error_set.errors[i];7954 ErrorTableEntry *error_entry = set2->data.error_set.errors[i];
7898 if (errors[error_entry->value] == nullptr) {7955 if (errors[error_entry->value] == nullptr) {
7899 errors[error_entry->value] = error_entry;7956 errors[error_entry->value] = error_entry;
7900 const char *comma = need_comma ? "," : "";7957 if (type_name == nullptr) {
7901 need_comma = true;7958 const char *comma = need_comma ? "," : "";
7902 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&error_entry->name));7959 need_comma = true;
7960 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&error_entry->name));
7961 }
7903 err_set_type->data.error_set.errors[index] = error_entry;7962 err_set_type->data.error_set.errors[index] = error_entry;
7904 index += 1;7963 index += 1;
7905 }7964 }
...@@ -7907,7 +7966,9 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp...@@ -7907,7 +7966,9 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
7907 assert(index == count);7966 assert(index == count);
7908 assert(count != 0);7967 assert(count != 0);
79097968
7910 buf_appendf(&err_set_type->name, "}");7969 if (type_name == nullptr) {
7970 buf_appendf(&err_set_type->name, "}");
7971 }
79117972
7912 return err_set_type;7973 return err_set_type;
79137974
...@@ -9967,7 +10028,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9967,7 +10028,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9967 }10028 }
996810029
9969 // neither of them are supersets. so we invent a new error set type that is a union of both of them10030 // neither of them are supersets. so we invent a new error set type that is a union of both of them
9970 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);10031 err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type, nullptr);
9971 assert(errors != nullptr);10032 assert(errors != nullptr);
9972 continue;10033 continue;
9973 } else if (cur_type->id == ZigTypeIdErrorUnion) {10034 } else if (cur_type->id == ZigTypeIdErrorUnion) {
...@@ -10018,7 +10079,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10018,7 +10079,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10018 }10079 }
1001910080
10020 // not a subset. invent new error set type, union of both of them10081 // not a subset. invent new error set type, union of both of them
10021 err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, err_set_type);10082 err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, err_set_type, nullptr);
10022 prev_inst = cur_inst;10083 prev_inst = cur_inst;
10023 assert(errors != nullptr);10084 assert(errors != nullptr);
10024 continue;10085 continue;
...@@ -10074,7 +10135,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10074,7 +10135,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10074 continue;10135 continue;
10075 }10136 }
10076 // not a subset. invent new error set type, union of both of them10137 // not a subset. invent new error set type, union of both of them
10077 err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_type);10138 err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_type, nullptr);
10078 assert(errors != nullptr);10139 assert(errors != nullptr);
10079 continue;10140 continue;
10080 }10141 }
...@@ -10160,7 +10221,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10160,7 +10221,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10160 continue;10221 continue;
10161 }10222 }
1016210223
10163 err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, prev_err_set_type);10224 err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, prev_err_set_type, nullptr);
10164 continue;10225 continue;
10165 }10226 }
10166 }10227 }
...@@ -10286,7 +10347,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10286,7 +10347,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1028610347
10287 update_errors_helper(ira->codegen, &errors, &errors_count);10348 update_errors_helper(ira->codegen, &errors, &errors_count);
1028810349
10289 err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_err_set_type);10350 err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_err_set_type, nullptr);
10290 }10351 }
10291 prev_inst = cur_inst;10352 prev_inst = cur_inst;
10292 continue;10353 continue;
...@@ -13795,7 +13856,6 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -13795,7 +13856,6 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
13795 case IrBinOpArrayCat:13856 case IrBinOpArrayCat:
13796 case IrBinOpArrayMult:13857 case IrBinOpArrayMult:
13797 case IrBinOpRemUnspecified:13858 case IrBinOpRemUnspecified:
13798 case IrBinOpMergeErrorSets:
13799 zig_unreachable();13859 zig_unreachable();
13800 case IrBinOpBinOr:13860 case IrBinOpBinOr:
13801 assert(is_int);13861 assert(is_int);
...@@ -14102,7 +14162,6 @@ static bool ok_float_op(IrBinOp op) {...@@ -14102,7 +14162,6 @@ static bool ok_float_op(IrBinOp op) {
14102 case IrBinOpRemUnspecified:14162 case IrBinOpRemUnspecified:
14103 case IrBinOpArrayCat:14163 case IrBinOpArrayCat:
14104 case IrBinOpArrayMult:14164 case IrBinOpArrayMult:
14105 case IrBinOpMergeErrorSets:
14106 return false;14165 return false;
14107 }14166 }
14108 zig_unreachable();14167 zig_unreachable();
...@@ -14603,7 +14662,9 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -14603,7 +14662,9 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
14603 return result;14662 return result;
14604}14663}
1460514664
14606static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {14665static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
14666 IrInstructionMergeErrSets *instruction)
14667{
14607 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child);14668 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child);
14608 if (type_is_invalid(op1_type))14669 if (type_is_invalid(op1_type))
14609 return ira->codegen->invalid_instruction;14670 return ira->codegen->invalid_instruction;
...@@ -14632,12 +14693,13 @@ static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionB...@@ -14632,12 +14693,13 @@ static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionB
14632 assert(errors[error_entry->value] == nullptr);14693 assert(errors[error_entry->value] == nullptr);
14633 errors[error_entry->value] = error_entry;14694 errors[error_entry->value] = error_entry;
14634 }14695 }
14635 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type);14696 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
14636 free(errors);14697 free(errors);
1463714698
14638 return ir_const_type(ira, &instruction->base, result_type);14699 return ir_const_type(ira, &instruction->base, result_type);
14639}14700}
1464014701
14702
14641static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {14703static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
14642 IrBinOp op_id = bin_op_instruction->op_id;14704 IrBinOp op_id = bin_op_instruction->op_id;
14643 switch (op_id) {14705 switch (op_id) {
...@@ -14679,8 +14741,6 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio...@@ -14679,8 +14741,6 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio
14679 return ir_analyze_array_cat(ira, bin_op_instruction);14741 return ir_analyze_array_cat(ira, bin_op_instruction);
14680 case IrBinOpArrayMult:14742 case IrBinOpArrayMult:
14681 return ir_analyze_array_mult(ira, bin_op_instruction);14743 return ir_analyze_array_mult(ira, bin_op_instruction);
14682 case IrBinOpMergeErrorSets:
14683 return ir_analyze_merge_error_sets(ira, bin_op_instruction);
14684 }14744 }
14685 zig_unreachable();14745 zig_unreachable();
14686}14746}
...@@ -25945,6 +26005,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -25945,6 +26005,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
25945 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);26005 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);
25946 case IrInstructionIdBinOp:26006 case IrInstructionIdBinOp:
25947 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);26007 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);
26008 case IrInstructionIdMergeErrSets:
26009 return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction);
25948 case IrInstructionIdDeclVarSrc:26010 case IrInstructionIdDeclVarSrc:
25949 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);26011 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);
25950 case IrInstructionIdLoadPtr:26012 case IrInstructionIdLoadPtr:
...@@ -26370,6 +26432,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -26370,6 +26432,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
26370 case IrInstructionIdPhi:26432 case IrInstructionIdPhi:
26371 case IrInstructionIdUnOp:26433 case IrInstructionIdUnOp:
26372 case IrInstructionIdBinOp:26434 case IrInstructionIdBinOp:
26435 case IrInstructionIdMergeErrSets:
26373 case IrInstructionIdLoadPtr:26436 case IrInstructionIdLoadPtr:
26374 case IrInstructionIdConst:26437 case IrInstructionIdConst:
26375 case IrInstructionIdCast:26438 case IrInstructionIdCast:
src/ir_print.cpp+14-2
...@@ -70,6 +70,8 @@ static const char* ir_instruction_type_str(IrInstruction* instruction) {...@@ -70,6 +70,8 @@ static const char* ir_instruction_type_str(IrInstruction* instruction) {
70 return "UnOp";70 return "UnOp";
71 case IrInstructionIdBinOp:71 case IrInstructionIdBinOp:
72 return "BinOp";72 return "BinOp";
73 case IrInstructionIdMergeErrSets:
74 return "MergeErrSets";
73 case IrInstructionIdLoadPtr:75 case IrInstructionIdLoadPtr:
74 return "LoadPtr";76 return "LoadPtr";
75 case IrInstructionIdLoadPtrGen:77 case IrInstructionIdLoadPtrGen:
...@@ -497,8 +499,6 @@ static const char *ir_bin_op_id_str(IrBinOp op_id) {...@@ -497,8 +499,6 @@ static const char *ir_bin_op_id_str(IrBinOp op_id) {
497 return "++";499 return "++";
498 case IrBinOpArrayMult:500 case IrBinOpArrayMult:
499 return "**";501 return "**";
500 case IrBinOpMergeErrorSets:
501 return "||";
502 }502 }
503 zig_unreachable();503 zig_unreachable();
504}504}
...@@ -535,6 +535,15 @@ static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction...@@ -535,6 +535,15 @@ static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction
535 }535 }
536}536}
537537
538static void ir_print_merge_err_sets(IrPrint *irp, IrInstructionMergeErrSets *instruction) {
539 ir_print_other_instruction(irp, instruction->op1);
540 fprintf(irp->f, " || ");
541 ir_print_other_instruction(irp, instruction->op2);
542 if (instruction->type_name != nullptr) {
543 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));
544 }
545}
546
538static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {547static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {
539 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";548 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
540 const char *name = decl_var_instruction->var->name;549 const char *name = decl_var_instruction->var->name;
...@@ -1974,6 +1983,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool...@@ -1974,6 +1983,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
1974 case IrInstructionIdBinOp:1983 case IrInstructionIdBinOp:
1975 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);1984 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
1976 break;1985 break;
1986 case IrInstructionIdMergeErrSets:
1987 ir_print_merge_err_sets(irp, (IrInstructionMergeErrSets *)instruction);
1988 break;
1977 case IrInstructionIdDeclVarSrc:1989 case IrInstructionIdDeclVarSrc:
1978 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);1990 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);
1979 break;1991 break;