authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 12:36:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 12:36:02-04:00
logdd272d13161d7a7069af78669d891d280c65529f
tree1d3b8183c6979973582246b7708b4bf88d14d6bf
parent0ba2bc38d76537a83bd6c27143779857dbb711cf

await cancels the await target when it is canceled


1 files changed, 8 insertions(+), 1 deletions(-)

src/ir.cpp+8-1
...@@ -6830,11 +6830,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -6830,11 +6830,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
6830 IrBasicBlock *merge_block = ir_create_basic_block(irb, scope, "MergeSuspend");6830 IrBasicBlock *merge_block = ir_create_basic_block(irb, scope, "MergeSuspend");
6831 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");6831 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");
6832 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");6832 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");
6833 IrBasicBlock *cancel_target_block = ir_create_basic_block(irb, scope, "CancelTarget");
68336834
6834 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);6835 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
6835 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,6836 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
6836 atomic_state_field_name);6837 atomic_state_field_name);
68376838
6839 IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise);
6838 IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false);6840 IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false);
6839 IrInstruction *undefined_value = ir_build_const_undefined(irb, scope, node);6841 IrInstruction *undefined_value = ir_build_const_undefined(irb, scope, node);
6840 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);6842 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
...@@ -6900,10 +6902,15 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -6900,10 +6902,15 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
6900 cases[0].value = ir_build_const_u8(irb, scope, node, 0);6902 cases[0].value = ir_build_const_u8(irb, scope, node, 0);
6901 cases[0].block = resume_block;6903 cases[0].block = resume_block;
6902 cases[1].value = ir_build_const_u8(irb, scope, node, 1);6904 cases[1].value = ir_build_const_u8(irb, scope, node, 1);
6903 cases[1].block = cleanup_block;6905 cases[1].block = cancel_target_block;
6904 ir_build_switch_br(irb, scope, node, suspend_code, irb->exec->coro_suspend_block,6906 ir_build_switch_br(irb, scope, node, suspend_code, irb->exec->coro_suspend_block,
6905 2, cases, const_bool_false, nullptr);6907 2, cases, const_bool_false, nullptr);
69066908
6909 ir_set_cursor_at_end_and_append_block(irb, cancel_target_block);
6910 IrInstruction *await_handle = ir_build_int_to_ptr(irb, scope, node, promise_type_val, await_handle_addr);
6911 ir_gen_cancel_target(irb, scope, node, await_handle);
6912 ir_mark_gen(ir_build_br(irb, scope, node, cleanup_block, const_bool_false));
6913
6907 ir_set_cursor_at_end_and_append_block(irb, cleanup_block);6914 ir_set_cursor_at_end_and_append_block(irb, cleanup_block);
6908 ir_gen_defers_for_block(irb, scope, outer_scope, true);6915 ir_gen_defers_for_block(irb, scope, outer_scope, true);
6909 ir_mark_gen(ir_build_br(irb, scope, node, irb->exec->coro_final_cleanup_block, const_bool_false));6916 ir_mark_gen(ir_build_br(irb, scope, node, irb->exec->coro_final_cleanup_block, const_bool_false));