authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 16:29:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 16:29:46-04:00
log96931228af745b8e69c138b3b83893dafa166cfe
treeec7233505cf5529a825d66948bcd70d8032dc999
parent974db231a08731f642dbf72d716f669fed2bd2ab
signaturelock-open Commit is signed but in an unrecognized format.

fix comptime test error for empty error set


4 files changed, 35 insertions(+), 14 deletions(-)

src/all_types.hpp+1
...@@ -3085,6 +3085,7 @@ struct IrInstructionAlignOf {...@@ -3085,6 +3085,7 @@ struct IrInstructionAlignOf {
3085struct IrInstructionTestErrSrc {3085struct IrInstructionTestErrSrc {
3086 IrInstruction base;3086 IrInstruction base;
30873087
3088 bool resolve_err_set;
3088 IrInstruction *base_ptr;3089 IrInstruction *base_ptr;
3089};3090};
30903091
src/codegen.cpp+6
...@@ -4913,6 +4913,9 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI...@@ -4913,6 +4913,9 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
4913static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,4913static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
4914 IrInstructionUnwrapErrCode *instruction)4914 IrInstructionUnwrapErrCode *instruction)
4915{4915{
4916 if (instruction->base.value.special != ConstValSpecialRuntime)
4917 return nullptr;
4918
4916 ZigType *ptr_type = instruction->err_union_ptr->value.type;4919 ZigType *ptr_type = instruction->err_union_ptr->value.type;
4917 assert(ptr_type->id == ZigTypeIdPointer);4920 assert(ptr_type->id == ZigTypeIdPointer);
4918 ZigType *err_union_type = ptr_type->data.pointer.child_type;4921 ZigType *err_union_type = ptr_type->data.pointer.child_type;
...@@ -4930,6 +4933,9 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab...@@ -4930,6 +4933,9 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
4930static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,4933static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
4931 IrInstructionUnwrapErrPayload *instruction)4934 IrInstructionUnwrapErrPayload *instruction)
4932{4935{
4936 if (instruction->base.value.special != ConstValSpecialRuntime)
4937 return nullptr;
4938
4933 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&4939 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&
4934 g->errors_by_index.length > 1;4940 g->errors_by_index.length > 1;
4935 if (!want_safety && !type_has_bits(instruction->base.value.type))4941 if (!want_safety && !type_has_bits(instruction->base.value.type))
src/ir.cpp+20-6
...@@ -2446,10 +2446,11 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2446,10 +2446,11 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
2446}2446}
24472447
2448static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2448static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2449 IrInstruction *base_ptr)2449 IrInstruction *base_ptr, bool resolve_err_set)
2450{2450{
2451 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);2451 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);
2452 instruction->base_ptr = base_ptr;2452 instruction->base_ptr = base_ptr;
2453 instruction->resolve_err_set = resolve_err_set;
24532454
2454 ir_ref_instruction(base_ptr, irb->current_basic_block);2455 ir_ref_instruction(base_ptr, irb->current_basic_block);
24552456
...@@ -3593,7 +3594,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3593,7 +3594,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
35933594
3594 IrInstruction *ret_ptr = ir_build_result_ptr(irb, scope, node, &result_loc_ret->base,3595 IrInstruction *ret_ptr = ir_build_result_ptr(irb, scope, node, &result_loc_ret->base,
3595 return_value);3596 return_value);
3596 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr);3597 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr, false);
35973598
3598 bool should_inline = ir_should_inline(irb->exec, scope);3599 bool should_inline = ir_should_inline(irb->exec, scope);
3599 IrInstruction *is_comptime;3600 IrInstruction *is_comptime;
...@@ -3639,7 +3640,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3639,7 +3640,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3639 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);3640 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
3640 if (err_union_ptr == irb->codegen->invalid_instruction)3641 if (err_union_ptr == irb->codegen->invalid_instruction)
3641 return irb->codegen->invalid_instruction;3642 return irb->codegen->invalid_instruction;
3642 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr);3643 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true);
36433644
3644 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");3645 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
3645 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");3646 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
...@@ -5987,7 +5988,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5987,7 +5988,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5987 LValPtr, nullptr);5988 LValPtr, nullptr);
5988 if (err_val_ptr == irb->codegen->invalid_instruction)5989 if (err_val_ptr == irb->codegen->invalid_instruction)
5989 return err_val_ptr;5990 return err_val_ptr;
5990 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr);5991 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, true);
5991 IrBasicBlock *after_cond_block = irb->current_basic_block;5992 IrBasicBlock *after_cond_block = irb->current_basic_block;
5992 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));5993 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
5993 IrInstruction *cond_br_inst;5994 IrInstruction *cond_br_inst;
...@@ -6771,7 +6772,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6771,7 +6772,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
6771 return err_val_ptr;6772 return err_val_ptr;
67726773
6773 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);6774 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
6774 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr);6775 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true);
67756776
6776 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");6777 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");
6777 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");6778 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");
...@@ -7381,7 +7382,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -7381,7 +7382,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
7381 if (err_union_ptr == irb->codegen->invalid_instruction)7382 if (err_union_ptr == irb->codegen->invalid_instruction)
7382 return irb->codegen->invalid_instruction;7383 return irb->codegen->invalid_instruction;
73837384
7384 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr);7385 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true);
73857386
7386 IrInstruction *is_comptime;7387 IrInstruction *is_comptime;
7387 if (ir_should_inline(irb->exec, parent_scope)) {7388 if (ir_should_inline(irb->exec, parent_scope)) {
...@@ -22512,6 +22513,19 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -22512,6 +22513,19 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
22512 }22513 }
22513 }22514 }
2251422515
22516 if (instruction->resolve_err_set) {
22517 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
22518 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
22519 return ira->codegen->invalid_instruction;
22520 }
22521 if (!type_is_global_error_set(err_set_type) &&
22522 err_set_type->data.error_set.err_count == 0)
22523 {
22524 assert(err_set_type->data.error_set.infer_fn == nullptr);
22525 return ir_const_bool(ira, &instruction->base, false);
22526 }
22527 }
22528
22515 return ir_build_test_err_gen(ira, &instruction->base, value);22529 return ir_build_test_err_gen(ira, &instruction->base, value);
22516 } else if (type_entry->id == ZigTypeIdErrorSet) {22530 } else if (type_entry->id == ZigTypeIdErrorSet) {
22517 return ir_const_bool(ira, &instruction->base, true);22531 return ir_const_bool(ira, &instruction->base, true);
test/stage1/behavior/error.zig+8-8
...@@ -130,10 +130,10 @@ fn testExplicitErrorSetCast(set1: Set1) void {...@@ -130,10 +130,10 @@ fn testExplicitErrorSetCast(set1: Set1) void {
130 expect(y == error.A);130 expect(y == error.A);
131}131}
132132
133//test "comptime test error for empty error set" {133test "comptime test error for empty error set" {
134// testComptimeTestErrorEmptySet(1234);134 testComptimeTestErrorEmptySet(1234);
135// comptime testComptimeTestErrorEmptySet(1234);135 comptime testComptimeTestErrorEmptySet(1234);
136//}136}
137137
138const EmptyErrorSet = error{};138const EmptyErrorSet = error{};
139139
...@@ -204,10 +204,10 @@ fn foo2(f: fn () anyerror!void) void {...@@ -204,10 +204,10 @@ fn foo2(f: fn () anyerror!void) void {
204204
205fn bar2() (error{}!void) {}205fn bar2() (error{}!void) {}
206206
207//test "error: Zero sized error set returned with value payload crash" {207test "error: Zero sized error set returned with value payload crash" {
208// _ = foo3(0) catch {};208 _ = foo3(0) catch {};
209// _ = comptime foo3(0) catch {};209 _ = comptime foo3(0) catch {};
210//}210}
211211
212const Error = error{};212const Error = error{};
213fn foo3(b: usize) Error!usize {213fn foo3(b: usize) Error!usize {