| ... | ... | @@ -2752,6 +2752,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode |
| 2752 | 2752 | IrInstruction *maybe_await_handle = ir_build_atomic_rmw(irb, scope, node, |
| 2753 | 2753 | promise_type_val, irb->exec->coro_awaiter_field_ptr, nullptr, replacement_value, nullptr, |
| 2754 | 2754 | AtomicRmwOp_xchg, AtomicOrderSeqCst); |
| 2755 | ir_build_store_ptr(irb, scope, node, irb->exec->await_handle_var_ptr, maybe_await_handle); |
| 2755 | 2756 | IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_await_handle); |
| 2756 | 2757 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false); |
| 2757 | 2758 | return ir_build_cond_br(irb, scope, node, is_non_null, irb->exec->coro_normal_final, irb->exec->coro_early_final, |
| ... | ... | @@ -6020,7 +6021,6 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast |
| 6020 | 6021 | ir_build_br(irb, parent_scope, node, merge_block, const_bool_false); |
| 6021 | 6022 | |
| 6022 | 6023 | ir_set_cursor_at_end_and_append_block(irb, yes_suspend_block); |
| 6023 | | ir_build_coro_resume(irb, parent_scope, node, target_inst); |
| 6024 | 6024 | IrInstruction *suspend_code = ir_build_coro_suspend(irb, parent_scope, node, save_token, const_bool_false); |
| 6025 | 6025 | IrBasicBlock *cleanup_block = ir_create_basic_block(irb, parent_scope, "SuspendCleanup"); |
| 6026 | 6026 | IrBasicBlock *resume_block = ir_create_basic_block(irb, parent_scope, "SuspendResume"); |
| ... | ... | @@ -6277,13 +6277,20 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6277 | 6277 | // create the coro promise |
| 6278 | 6278 | const_bool_false = ir_build_const_bool(irb, scope, node, false); |
| 6279 | 6279 | VariableTableEntry *promise_var = ir_create_var(irb, node, scope, nullptr, false, false, true, const_bool_false); |
| 6280 | | //scope = promise_var->child_scope; |
| 6281 | 6280 | |
| 6282 | 6281 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 6283 | 6282 | IrInstruction *promise_init = ir_build_const_promise_init(irb, scope, node, return_type); |
| 6284 | 6283 | ir_build_var_decl(irb, scope, node, promise_var, nullptr, nullptr, promise_init); |
| 6285 | 6284 | IrInstruction *coro_promise_ptr = ir_build_var_ptr(irb, scope, node, promise_var, false, false); |
| 6286 | 6285 | |
| 6286 | VariableTableEntry *await_handle_var = ir_create_var(irb, node, scope, nullptr, false, false, true, const_bool_false); |
| 6287 | IrInstruction *null_value = ir_build_const_null(irb, scope, node); |
| 6288 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, scope, node, |
| 6289 | get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); |
| 6290 | ir_build_var_decl(irb, scope, node, await_handle_var, await_handle_type_val, nullptr, null_value); |
| 6291 | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, scope, node, |
| 6292 | await_handle_var, false, false); |
| 6293 | |
| 6287 | 6294 | u8_ptr_type = ir_build_const_type(irb, scope, node, |
| 6288 | 6295 | get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false)); |
| 6289 | 6296 | IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_promise_ptr); |
| ... | ... | @@ -6409,7 +6416,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6409 | 6416 | |
| 6410 | 6417 | ir_set_cursor_at_end_and_append_block(irb, resume_block); |
| 6411 | 6418 | IrInstruction *unwrapped_await_handle_ptr = ir_build_unwrap_maybe(irb, scope, node, |
| 6412 | | irb->exec->coro_awaiter_field_ptr, false); |
| 6419 | irb->exec->await_handle_var_ptr, false); |
| 6413 | 6420 | IrInstruction *awaiter_handle = ir_build_load_ptr(irb, scope, node, unwrapped_await_handle_ptr); |
| 6414 | 6421 | ir_build_coro_resume(irb, scope, node, awaiter_handle); |
| 6415 | 6422 | ir_build_br(irb, scope, node, irb->exec->coro_suspend_block, const_bool_false); |