| ... | ... | @@ -2708,14 +2708,16 @@ static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *s |
| 2708 | 2708 | } |
| 2709 | 2709 | |
| 2710 | 2710 | static IrInstruction *ir_build_merge_err_ret_traces(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2711 | | IrInstruction *coro_promise_ptr, IrInstruction *err_ret_trace_ptr) |
| 2711 | IrInstruction *coro_promise_ptr, IrInstruction *src_err_ret_trace_ptr, IrInstruction *dest_err_ret_trace_ptr) |
| 2712 | 2712 | { |
| 2713 | 2713 | IrInstructionMergeErrRetTraces *instruction = ir_build_instruction<IrInstructionMergeErrRetTraces>(irb, scope, source_node); |
| 2714 | 2714 | instruction->coro_promise_ptr = coro_promise_ptr; |
| 2715 | | instruction->err_ret_trace_ptr = err_ret_trace_ptr; |
| 2715 | instruction->src_err_ret_trace_ptr = src_err_ret_trace_ptr; |
| 2716 | instruction->dest_err_ret_trace_ptr = dest_err_ret_trace_ptr; |
| 2716 | 2717 | |
| 2717 | 2718 | ir_ref_instruction(coro_promise_ptr, irb->current_basic_block); |
| 2718 | | ir_ref_instruction(err_ret_trace_ptr, irb->current_basic_block); |
| 2719 | ir_ref_instruction(src_err_ret_trace_ptr, irb->current_basic_block); |
| 2720 | ir_ref_instruction(dest_err_ret_trace_ptr, irb->current_basic_block); |
| 2719 | 2721 | |
| 2720 | 2722 | return &instruction->base; |
| 2721 | 2723 | } |
| ... | ... | @@ -6115,6 +6117,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast |
| 6115 | 6117 | Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME); |
| 6116 | 6118 | IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, result_ptr_field_name); |
| 6117 | 6119 | |
| 6120 | if (irb->codegen->have_err_ret_tracing) { |
| 6121 | IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, parent_scope, node, IrInstructionErrorReturnTrace::NonNull); |
| 6122 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); |
| 6123 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name); |
| 6124 | ir_build_store_ptr(irb, parent_scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr); |
| 6125 | } |
| 6126 | |
| 6118 | 6127 | Buf *awaiter_handle_field_name = buf_create_from_str(AWAITER_HANDLE_FIELD_NAME); |
| 6119 | 6128 | IrInstruction *awaiter_field_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, |
| 6120 | 6129 | awaiter_handle_field_name); |
| ... | ... | @@ -6144,8 +6153,9 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast |
| 6144 | 6153 | ir_set_cursor_at_end_and_append_block(irb, no_suspend_block); |
| 6145 | 6154 | if (irb->codegen->have_err_ret_tracing) { |
| 6146 | 6155 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); |
| 6147 | | IrInstruction *err_ret_trace_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, err_ret_trace_field_name); |
| 6148 | | ir_build_merge_err_ret_traces(irb, parent_scope, node, coro_promise_ptr, err_ret_trace_ptr); |
| 6156 | IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, err_ret_trace_field_name); |
| 6157 | IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, parent_scope, node, IrInstructionErrorReturnTrace::NonNull); |
| 6158 | ir_build_merge_err_ret_traces(irb, parent_scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 6149 | 6159 | } |
| 6150 | 6160 | Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME); |
| 6151 | 6161 | IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, parent_scope, node, coro_promise_ptr, result_field_name); |
| ... | ... | @@ -6402,6 +6412,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6402 | 6412 | IrInstruction *coro_id; |
| 6403 | 6413 | IrInstruction *u8_ptr_type; |
| 6404 | 6414 | IrInstruction *const_bool_false; |
| 6415 | IrInstruction *coro_promise_ptr; |
| 6416 | IrInstruction *err_ret_trace_ptr; |
| 6405 | 6417 | TypeTableEntry *return_type; |
| 6406 | 6418 | Buf *result_ptr_field_name; |
| 6407 | 6419 | VariableTableEntry *coro_size_var; |
| ... | ... | @@ -6417,7 +6429,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6417 | 6429 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| 6418 | 6430 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 6419 | 6431 | ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); |
| 6420 | | IrInstruction *coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var, false, false); |
| 6432 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var, false, false); |
| 6421 | 6433 | |
| 6422 | 6434 | VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 6423 | 6435 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| ... | ... | @@ -6471,7 +6483,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6471 | 6483 | IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name); |
| 6472 | 6484 | |
| 6473 | 6485 | Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME); |
| 6474 | | IrInstruction *err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name); |
| 6486 | err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name); |
| 6475 | 6487 | ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr); |
| 6476 | 6488 | |
| 6477 | 6489 | // coordinate with builtin.zig |
| ... | ... | @@ -6536,6 +6548,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6536 | 6548 | IrInstruction *size_of_ret_val = ir_build_size_of(irb, scope, node, return_type_inst); |
| 6537 | 6549 | ir_build_memcpy(irb, scope, node, result_ptr_as_u8_ptr, return_value_ptr_as_u8_ptr, size_of_ret_val); |
| 6538 | 6550 | } |
| 6551 | if (irb->codegen->have_err_ret_tracing) { |
| 6552 | Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME); |
| 6553 | IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name); |
| 6554 | IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr); |
| 6555 | ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 6556 | } |
| 6539 | 6557 | ir_build_br(irb, scope, node, check_free_block, const_bool_false); |
| 6540 | 6558 | |
| 6541 | 6559 | ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_final_cleanup_block); |
| ... | ... | @@ -13098,6 +13116,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 13098 | 13116 | { |
| 13099 | 13117 | if (!is_slice(bare_struct_type)) { |
| 13100 | 13118 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| 13119 | assert(container_scope != nullptr); |
| 13101 | 13120 | auto entry = container_scope->decl_table.maybe_get(field_name); |
| 13102 | 13121 | Tld *tld = entry ? entry->value : nullptr; |
| 13103 | 13122 | if (tld && tld->id == TldIdFn) { |
| ... | ... | @@ -17948,12 +17967,16 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir |
| 17948 | 17967 | return out_val->type; |
| 17949 | 17968 | } |
| 17950 | 17969 | |
| 17951 | | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; |
| 17952 | | if (type_is_invalid(err_ret_trace_ptr->value.type)) |
| 17970 | IrInstruction *src_err_ret_trace_ptr = instruction->src_err_ret_trace_ptr->other; |
| 17971 | if (type_is_invalid(src_err_ret_trace_ptr->value.type)) |
| 17972 | return ira->codegen->builtin_types.entry_invalid; |
| 17973 | |
| 17974 | IrInstruction *dest_err_ret_trace_ptr = instruction->dest_err_ret_trace_ptr->other; |
| 17975 | if (type_is_invalid(dest_err_ret_trace_ptr->value.type)) |
| 17953 | 17976 | return ira->codegen->builtin_types.entry_invalid; |
| 17954 | 17977 | |
| 17955 | 17978 | IrInstruction *result = ir_build_merge_err_ret_traces(&ira->new_irb, instruction->base.scope, |
| 17956 | | instruction->base.source_node, coro_promise_ptr, err_ret_trace_ptr); |
| 17979 | instruction->base.source_node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 17957 | 17980 | ir_link_new_instruction(result, &instruction->base); |
| 17958 | 17981 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 17959 | 17982 | return result->value.type; |