authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-07 10:56:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-07 10:56:37-04:00
loge11cafbd4f11fa5eae0cbdf03854291834b4cd77
tree92587f54fbc5aebb46f5081e5086c76c0284cac0
parentf587fa1cd73c3c0382e1bd2da2e24a7473421a2c
signaturelock-open Commit is signed but in an unrecognized format.

cancel works on non-pointers


2 files changed, 29 insertions(+), 3 deletions(-)

src/ir.cpp+13-3
...@@ -7845,7 +7845,7 @@ static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -7845,7 +7845,7 @@ static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node)
7845 return irb->codegen->invalid_instruction;7845 return irb->codegen->invalid_instruction;
7846 }7846 }
78477847
7848 IrInstruction *operand = ir_gen_node(irb, node->data.cancel_expr.expr, scope);7848 IrInstruction *operand = ir_gen_node_extra(irb, node->data.cancel_expr.expr, scope, LValPtr, nullptr);
7849 if (operand == irb->codegen->invalid_instruction)7849 if (operand == irb->codegen->invalid_instruction)
7850 return irb->codegen->invalid_instruction;7850 return irb->codegen->invalid_instruction;
78517851
...@@ -24496,10 +24496,20 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,...@@ -24496,10 +24496,20 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
24496}24496}
2449724497
24498static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {24498static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
24499 IrInstruction *frame = instruction->frame->child;24499 IrInstruction *frame_ptr = instruction->frame->child;
24500 if (type_is_invalid(frame->value.type))24500 if (type_is_invalid(frame_ptr->value.type))
24501 return ira->codegen->invalid_instruction;24501 return ira->codegen->invalid_instruction;
2450224502
24503 IrInstruction *frame;
24504 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
24505 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
24506 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdCoroFrame)
24507 {
24508 frame = frame_ptr;
24509 } else {
24510 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);
24511 }
24512
24503 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);24513 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
24504 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);24514 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
24505 if (type_is_invalid(casted_frame->value.type))24515 if (type_is_invalid(casted_frame->value.type))
test/stage1/behavior/cancel.zig+16
...@@ -92,3 +92,19 @@ async fn b4() void {...@@ -92,3 +92,19 @@ async fn b4() void {
92 }92 }
93 suspend;93 suspend;
94}94}
95
96test "cancel on a non-pointer" {
97 const S = struct {
98 fn doTheTest() void {
99 _ = async atest();
100 }
101 fn atest() void {
102 var f = async func();
103 cancel f;
104 }
105 fn func() void {
106 suspend;
107 }
108 };
109 S.doTheTest();
110}