authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 12:23:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 12:23:47-04:00
log0ba2bc38d76537a83bd6c27143779857dbb711cf
treeaf80d99786b2df44a1a570340096b2eb7522169a
parent60cda3713fdc2d8bce01bfc229109a3c8b3efb6f

await checks the cancel bit


1 files changed, 12 insertions(+), 5 deletions(-)

src/ir.cpp+12-5
......@@ -6824,6 +6824,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68246824
68256825 IrBasicBlock *already_awaited_block = ir_create_basic_block(irb, scope, "AlreadyAwaited");
68266826 IrBasicBlock *not_awaited_block = ir_create_basic_block(irb, scope, "NotAwaited");
6827 IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, scope, "NotCanceled");
6828 IrBasicBlock *yes_suspend_block = ir_create_basic_block(irb, scope, "YesSuspend");
6829 IrBasicBlock *no_suspend_block = ir_create_basic_block(irb, scope, "NoSuspend");
6830 IrBasicBlock *merge_block = ir_create_basic_block(irb, scope, "MergeSuspend");
6831 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");
6832 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");
68276833
68286834 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
68296835 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
......@@ -6836,6 +6842,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68366842 IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111
68376843 IrInstruction *ptr_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, inverted_ptr_mask); // 0b111...000
68386844 IrInstruction *await_mask = ir_build_const_usize(irb, scope, node, 0x4); // 0b100
6845 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
68396846
68406847 VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr,
68416848 false, false, true, const_bool_false);
......@@ -6861,11 +6868,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68616868 ir_build_unreachable(irb, scope, node);
68626869
68636870 ir_set_cursor_at_end_and_append_block(irb, not_awaited_block);
6871 IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
6872 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
6873 ir_build_cond_br(irb, scope, node, is_canceled_bool, cleanup_block, not_canceled_block, const_bool_false);
6874
6875 ir_set_cursor_at_end_and_append_block(irb, not_canceled_block);
68646876 IrInstruction *await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
68656877 IrInstruction *is_non_null = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, await_handle_addr, zero, false);
6866 IrBasicBlock *yes_suspend_block = ir_create_basic_block(irb, scope, "YesSuspend");
6867 IrBasicBlock *no_suspend_block = ir_create_basic_block(irb, scope, "NoSuspend");
6868 IrBasicBlock *merge_block = ir_create_basic_block(irb, scope, "MergeSuspend");
68696878 ir_build_cond_br(irb, scope, node, is_non_null, no_suspend_block, yes_suspend_block, const_bool_false);
68706879
68716880 ir_set_cursor_at_end_and_append_block(irb, no_suspend_block);
......@@ -6886,8 +6895,6 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68866895
68876896 ir_set_cursor_at_end_and_append_block(irb, yes_suspend_block);
68886897 IrInstruction *suspend_code = ir_build_coro_suspend(irb, scope, node, save_token, const_bool_false);
6889 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");
6890 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");
68916898
68926899 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(2);
68936900 cases[0].value = ir_build_const_u8(irb, scope, node, 0);