| ... | @@ -1066,7 +1066,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio | ... | @@ -1066,7 +1066,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio |
| 1066 | | 1066 | |
| 1067 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1067 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1068 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, | 1068 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1069 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *alloc_fn, IrInstruction *free_fn) | 1069 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator) |
| 1070 | { | 1070 | { |
| 1071 | IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, scope, source_node); | 1071 | IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, scope, source_node); |
| 1072 | call_instruction->fn_entry = fn_entry; | 1072 | call_instruction->fn_entry = fn_entry; |
| ... | @@ -1077,8 +1077,6 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc | ... | @@ -1077,8 +1077,6 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 1077 | call_instruction->arg_count = arg_count; | 1077 | call_instruction->arg_count = arg_count; |
| 1078 | call_instruction->is_async = is_async; | 1078 | call_instruction->is_async = is_async; |
| 1079 | call_instruction->async_allocator = async_allocator; | 1079 | call_instruction->async_allocator = async_allocator; |
| 1080 | call_instruction->alloc_fn = alloc_fn; | | |
| 1081 | call_instruction->free_fn = free_fn; | | |
| 1082 | | 1080 | |
| 1083 | if (fn_ref) | 1081 | if (fn_ref) |
| 1084 | ir_ref_instruction(fn_ref, irb->current_basic_block); | 1082 | ir_ref_instruction(fn_ref, irb->current_basic_block); |
| ... | @@ -1086,20 +1084,16 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc | ... | @@ -1086,20 +1084,16 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 1086 | ir_ref_instruction(args[i], irb->current_basic_block); | 1084 | ir_ref_instruction(args[i], irb->current_basic_block); |
| 1087 | if (async_allocator) | 1085 | if (async_allocator) |
| 1088 | ir_ref_instruction(async_allocator, irb->current_basic_block); | 1086 | ir_ref_instruction(async_allocator, irb->current_basic_block); |
| 1089 | if (alloc_fn) | | |
| 1090 | ir_ref_instruction(alloc_fn, irb->current_basic_block); | | |
| 1091 | if (free_fn) | | |
| 1092 | ir_ref_instruction(free_fn, irb->current_basic_block); | | |
| 1093 | | 1087 | |
| 1094 | return &call_instruction->base; | 1088 | return &call_instruction->base; |
| 1095 | } | 1089 | } |
| 1096 | | 1090 | |
| 1097 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, | 1091 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1098 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, | 1092 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1099 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *alloc_fn, IrInstruction *free_fn) | 1093 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator) |
| 1100 | { | 1094 | { |
| 1101 | IrInstruction *new_instruction = ir_build_call(irb, old_instruction->scope, | 1095 | IrInstruction *new_instruction = ir_build_call(irb, old_instruction->scope, |
| 1102 | old_instruction->source_node, fn_entry, fn_ref, arg_count, args, is_comptime, fn_inline, is_async, async_allocator, alloc_fn, free_fn); | 1096 | old_instruction->source_node, fn_entry, fn_ref, arg_count, args, is_comptime, fn_inline, is_async, async_allocator); |
| 1103 | ir_link_new_instruction(new_instruction, old_instruction); | 1097 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1104 | return new_instruction; | 1098 | return new_instruction; |
| 1105 | } | 1099 | } |
| ... | @@ -2501,9 +2495,8 @@ static IrInstruction *ir_build_cancel(IrBuilder *irb, Scope *scope, AstNode *sou | ... | @@ -2501,9 +2495,8 @@ static IrInstruction *ir_build_cancel(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2501 | return &instruction->base; | 2495 | return &instruction->base; |
| 2502 | } | 2496 | } |
| 2503 | | 2497 | |
| 2504 | static IrInstruction *ir_build_get_implicit_allocator(IrBuilder *irb, Scope *scope, AstNode *source_node, ImplicitAllocatorId id) { | 2498 | static IrInstruction *ir_build_get_implicit_allocator(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2505 | IrInstructionGetImplicitAllocator *instruction = ir_build_instruction<IrInstructionGetImplicitAllocator>(irb, scope, source_node); | 2499 | IrInstructionGetImplicitAllocator *instruction = ir_build_instruction<IrInstructionGetImplicitAllocator>(irb, scope, source_node); |
| 2506 | instruction->id = id; | | |
| 2507 | | 2500 | |
| 2508 | return &instruction->base; | 2501 | return &instruction->base; |
| 2509 | } | 2502 | } |
| ... | @@ -3977,7 +3970,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -3977,7 +3970,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 3977 | } | 3970 | } |
| 3978 | FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever; | 3971 | FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever; |
| 3979 | | 3972 | |
| 3980 | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, fn_inline, false, nullptr, nullptr, nullptr); | 3973 | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, fn_inline, false, nullptr); |
| 3981 | } | 3974 | } |
| 3982 | case BuiltinFnIdTypeId: | 3975 | case BuiltinFnIdTypeId: |
| 3983 | { | 3976 | { |
| ... | @@ -4113,25 +4106,15 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node | ... | @@ -4113,25 +4106,15 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node |
| 4113 | | 4106 | |
| 4114 | bool is_async = node->data.fn_call_expr.is_async; | 4107 | bool is_async = node->data.fn_call_expr.is_async; |
| 4115 | IrInstruction *async_allocator = nullptr; | 4108 | IrInstruction *async_allocator = nullptr; |
| 4116 | IrInstruction *alloc_fn = nullptr; | | |
| 4117 | IrInstruction *free_fn = nullptr; | | |
| 4118 | if (is_async) { | 4109 | if (is_async) { |
| 4119 | if (node->data.fn_call_expr.async_allocator) { | 4110 | if (node->data.fn_call_expr.async_allocator) { |
| 4120 | async_allocator = ir_gen_node(irb, node->data.fn_call_expr.async_allocator, scope); | 4111 | async_allocator = ir_gen_node(irb, node->data.fn_call_expr.async_allocator, scope); |
| 4121 | if (async_allocator == irb->codegen->invalid_instruction) | 4112 | if (async_allocator == irb->codegen->invalid_instruction) |
| 4122 | return async_allocator; | 4113 | return async_allocator; |
| 4123 | | | |
| 4124 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); | | |
| 4125 | IrInstruction *alloc_fn_ptr = ir_build_field_ptr(irb, scope, node, async_allocator, alloc_field_name); | | |
| 4126 | alloc_fn = ir_build_load_ptr(irb, scope, node, alloc_fn_ptr); | | |
| 4127 | | | |
| 4128 | Buf *free_field_name = buf_create_from_str(ASYNC_FREE_FIELD_NAME); | | |
| 4129 | IrInstruction *free_fn_ptr = ir_build_field_ptr(irb, scope, node, async_allocator, free_field_name); | | |
| 4130 | free_fn = ir_build_load_ptr(irb, scope, node, free_fn_ptr); | | |
| 4131 | } | 4114 | } |
| 4132 | } | 4115 | } |
| 4133 | | 4116 | |
| 4134 | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto, is_async, async_allocator, alloc_fn, free_fn); | 4117 | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto, is_async, async_allocator); |
| 4135 | } | 4118 | } |
| 4136 | | 4119 | |
| 4137 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) { | 4120 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | @@ -6113,16 +6096,20 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -6113,16 +6096,20 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6113 | IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_promise_ptr); | 6096 | IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_promise_ptr); |
| 6114 | coro_id = ir_build_coro_id(irb, scope, node, promise_as_u8_ptr); | 6097 | coro_id = ir_build_coro_id(irb, scope, node, promise_as_u8_ptr); |
| 6115 | IrInstruction *coro_size = ir_build_coro_size(irb, scope, node); | 6098 | IrInstruction *coro_size = ir_build_coro_size(irb, scope, node); |
| 6116 | irb->exec->implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdContext); | 6099 | irb->exec->implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node); |
| 6117 | IrInstruction *alloc_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdAlloc); | 6100 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); |
| 6118 | IrInstruction *alignment = ir_build_const_u29(irb, scope, node, get_coro_frame_align_bytes(irb->codegen)); | 6101 | IrInstruction *alloc_fn_ptr = ir_build_field_ptr(irb, scope, node, irb->exec->implicit_allocator_ptr, |
| | 6102 | alloc_field_name); |
| | 6103 | IrInstruction *alloc_fn = ir_build_load_ptr(irb, scope, node, alloc_fn_ptr); |
| | 6104 | IrInstruction *alignment = ir_build_const_u29(irb, scope, node, |
| | 6105 | get_coro_frame_align_bytes(irb->codegen)); |
| 6119 | size_t arg_count = 3; | 6106 | size_t arg_count = 3; |
| 6120 | IrInstruction **args = allocate<IrInstruction *>(arg_count); | 6107 | IrInstruction **args = allocate<IrInstruction *>(arg_count); |
| 6121 | args[0] = irb->exec->implicit_allocator_ptr; // self | 6108 | args[0] = irb->exec->implicit_allocator_ptr; // self |
| 6122 | args[1] = coro_size; // byte_count | 6109 | args[1] = coro_size; // byte_count |
| 6123 | args[2] = alignment; // alignment | 6110 | args[2] = alignment; // alignment |
| 6124 | IrInstruction *alloc_result = ir_build_call(irb, scope, node, nullptr, alloc_fn, arg_count, args, false, | 6111 | IrInstruction *alloc_result = ir_build_call(irb, scope, node, nullptr, alloc_fn, arg_count, args, false, |
| 6125 | FnInlineAuto, false, nullptr, nullptr, nullptr); | 6112 | FnInlineAuto, false, nullptr); |
| 6126 | IrInstruction *alloc_result_ptr = ir_build_ref(irb, scope, node, alloc_result, true, false); | 6113 | IrInstruction *alloc_result_ptr = ir_build_ref(irb, scope, node, alloc_result, true, false); |
| 6127 | IrInstruction *alloc_result_is_err = ir_build_test_err(irb, scope, node, alloc_result); | 6114 | IrInstruction *alloc_result_is_err = ir_build_test_err(irb, scope, node, alloc_result); |
| 6128 | IrBasicBlock *alloc_err_block = ir_create_basic_block(irb, scope, "AllocError"); | 6115 | IrBasicBlock *alloc_err_block = ir_create_basic_block(irb, scope, "AllocError"); |
| ... | @@ -6216,12 +6203,15 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -6216,12 +6203,15 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6216 | incoming_values[1] = const_bool_true; | 6203 | incoming_values[1] = const_bool_true; |
| 6217 | IrInstruction *resume_awaiter = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); | 6204 | IrInstruction *resume_awaiter = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); |
| 6218 | | 6205 | |
| 6219 | IrInstruction *free_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdFree); | 6206 | Buf *free_field_name = buf_create_from_str(ASYNC_FREE_FIELD_NAME); |
| | 6207 | IrInstruction *free_fn_ptr = ir_build_field_ptr(irb, scope, node, irb->exec->implicit_allocator_ptr, |
| | 6208 | free_field_name); |
| | 6209 | IrInstruction *free_fn = ir_build_load_ptr(irb, scope, node, free_fn_ptr); |
| 6220 | size_t arg_count = 2; | 6210 | size_t arg_count = 2; |
| 6221 | IrInstruction **args = allocate<IrInstruction *>(arg_count); | 6211 | IrInstruction **args = allocate<IrInstruction *>(arg_count); |
| 6222 | args[0] = irb->exec->implicit_allocator_ptr; // self | 6212 | args[0] = irb->exec->implicit_allocator_ptr; // self |
| 6223 | args[1] = ir_build_load_ptr(irb, scope, node, coro_unwrapped_mem_ptr); // old_mem | 6213 | args[1] = ir_build_load_ptr(irb, scope, node, coro_unwrapped_mem_ptr); // old_mem |
| 6224 | ir_build_call(irb, scope, node, nullptr, free_fn, arg_count, args, false, FnInlineAuto, false, nullptr, nullptr, nullptr); | 6214 | ir_build_call(irb, scope, node, nullptr, free_fn, arg_count, args, false, FnInlineAuto, false, nullptr); |
| 6225 | | 6215 | |
| 6226 | IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume"); | 6216 | IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume"); |
| 6227 | IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "Return"); | 6217 | IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "Return"); |
| ... | @@ -11240,7 +11230,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, | ... | @@ -11240,7 +11230,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 11240 | return ira->codegen->builtin_types.entry_type; | 11230 | return ira->codegen->builtin_types.entry_type; |
| 11241 | } | 11231 | } |
| 11242 | | 11232 | |
| 11243 | IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) { | 11233 | IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr) { |
| 11244 | FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); | 11234 | FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 11245 | if (parent_fn_entry == nullptr) { | 11235 | if (parent_fn_entry == nullptr) { |
| 11246 | ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); | 11236 | ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); |
| ... | @@ -11254,39 +11244,27 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -11254,39 +11244,27 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i |
| 11254 | } | 11244 | } |
| 11255 | | 11245 | |
| 11256 | assert(parent_fn_type->async_allocator_type != nullptr); | 11246 | assert(parent_fn_type->async_allocator_type != nullptr); |
| 11257 | IrInstruction *result = ir_build_get_implicit_allocator(&ira->new_irb, source_instr->scope, source_instr->source_node, id); | 11247 | IrInstruction *result = ir_build_get_implicit_allocator(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 11258 | switch (id) { | 11248 | result->value.type = parent_fn_type->async_allocator_type; |
| 11259 | case ImplicitAllocatorIdContext: | | |
| 11260 | result->value.type = parent_fn_type->async_allocator_type; | | |
| 11261 | break; | | |
| 11262 | case ImplicitAllocatorIdAlloc: | | |
| 11263 | { | | |
| 11264 | assert(parent_fn_type->async_allocator_type->id == TypeTableEntryIdPointer); | | |
| 11265 | TypeTableEntry *struct_type = parent_fn_type->async_allocator_type->data.pointer.child_type; | | |
| 11266 | TypeStructField *alloc_fn_field = find_struct_type_field(struct_type, buf_create_from_str(ASYNC_ALLOC_FIELD_NAME)); | | |
| 11267 | assert(alloc_fn_field->type_entry->id == TypeTableEntryIdFn); | | |
| 11268 | result->value.type = alloc_fn_field->type_entry; | | |
| 11269 | break; | | |
| 11270 | } | | |
| 11271 | case ImplicitAllocatorIdFree: | | |
| 11272 | { | | |
| 11273 | assert(parent_fn_type->async_allocator_type->id == TypeTableEntryIdPointer); | | |
| 11274 | TypeTableEntry *struct_type = parent_fn_type->async_allocator_type->data.pointer.child_type; | | |
| 11275 | TypeStructField *free_fn_field = find_struct_type_field(struct_type, buf_create_from_str(ASYNC_FREE_FIELD_NAME)); | | |
| 11276 | assert(free_fn_field->type_entry->id == TypeTableEntryIdFn); | | |
| 11277 | result->value.type = free_fn_field->type_entry; | | |
| 11278 | break; | | |
| 11279 | } | | |
| 11280 | } | | |
| 11281 | return result; | 11249 | return result; |
| 11282 | } | 11250 | } |
| 11283 | | 11251 | |
| 11284 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type, | 11252 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type, |
| 11285 | IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst, IrInstruction *alloc_fn, IrInstruction *free_fn) | 11253 | IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) |
| 11286 | { | 11254 | { |
| | 11255 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); |
| | 11256 | //Buf *free_field_name = buf_create_from_str("freeFn"); |
| 11287 | assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); | 11257 | assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); |
| | 11258 | TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type; |
| | 11259 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, |
| | 11260 | async_allocator_inst, container_type); |
| | 11261 | if (type_is_invalid(field_ptr_inst->value.type)) { |
| | 11262 | return ira->codegen->invalid_instruction; |
| | 11263 | } |
| | 11264 | TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type; |
| | 11265 | assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer); |
| 11288 | | 11266 | |
| 11289 | TypeTableEntry *alloc_fn_type = alloc_fn->value.type; | 11267 | TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; |
| 11290 | if (alloc_fn_type->id != TypeTableEntryIdFn) { | 11268 | if (alloc_fn_type->id != TypeTableEntryIdFn) { |
| 11291 | ir_add_error(ira, &call_instruction->base, | 11269 | ir_add_error(ira, &call_instruction->base, |
| 11292 | buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); | 11270 | buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); |
| ... | @@ -11305,7 +11283,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c | ... | @@ -11305,7 +11283,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c |
| 11305 | TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); | 11283 | TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); |
| 11306 | | 11284 | |
| 11307 | IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, | 11285 | IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, |
| 11308 | fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, alloc_fn, free_fn); | 11286 | fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst); |
| 11309 | result->value.type = async_return_type; | 11287 | result->value.type = async_return_type; |
| 11310 | return result; | 11288 | return result; |
| 11311 | } | 11289 | } |
| ... | @@ -11828,7 +11806,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -11828,7 +11806,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 11828 | } | 11806 | } |
| 11829 | IrInstruction *uncasted_async_allocator_inst; | 11807 | IrInstruction *uncasted_async_allocator_inst; |
| 11830 | if (call_instruction->async_allocator == nullptr) { | 11808 | if (call_instruction->async_allocator == nullptr) { |
| 11831 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, ImplicitAllocatorIdContext); | 11809 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base); |
| 11832 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) | 11810 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 11833 | return ira->codegen->builtin_types.entry_invalid; | 11811 | return ira->codegen->builtin_types.entry_invalid; |
| 11834 | } else { | 11812 | } else { |
| ... | @@ -11872,16 +11850,8 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -11872,16 +11850,8 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 11872 | | 11850 | |
| 11873 | size_t impl_param_count = impl_fn->type_entry->data.fn.fn_type_id.param_count; | 11851 | size_t impl_param_count = impl_fn->type_entry->data.fn.fn_type_id.param_count; |
| 11874 | if (call_instruction->is_async) { | 11852 | if (call_instruction->is_async) { |
| 11875 | IrInstruction *alloc_fn = call_instruction->alloc_fn->other; | | |
| 11876 | if (type_is_invalid(alloc_fn->value.type)) | | |
| 11877 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11878 | | | |
| 11879 | IrInstruction *free_fn = call_instruction->free_fn->other; | | |
| 11880 | if (type_is_invalid(free_fn->value.type)) | | |
| 11881 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11882 | | | |
| 11883 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry, fn_ref, casted_args, impl_param_count, | 11853 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry, fn_ref, casted_args, impl_param_count, |
| 11884 | async_allocator_inst, alloc_fn, free_fn); | 11854 | async_allocator_inst); |
| 11885 | ir_link_new_instruction(result, &call_instruction->base); | 11855 | ir_link_new_instruction(result, &call_instruction->base); |
| 11886 | ir_add_alloca(ira, result, result->value.type); | 11856 | ir_add_alloca(ira, result, result->value.type); |
| 11887 | return ir_finish_anal(ira, result->value.type); | 11857 | return ir_finish_anal(ira, result->value.type); |
| ... | @@ -11890,7 +11860,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -11890,7 +11860,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 11890 | assert(async_allocator_inst == nullptr); | 11860 | assert(async_allocator_inst == nullptr); |
| 11891 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, | 11861 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 11892 | impl_fn, nullptr, impl_param_count, casted_args, false, fn_inline, | 11862 | impl_fn, nullptr, impl_param_count, casted_args, false, fn_inline, |
| 11893 | call_instruction->is_async, nullptr, nullptr, nullptr); | 11863 | call_instruction->is_async, nullptr); |
| 11894 | | 11864 | |
| 11895 | ir_add_alloca(ira, new_call_instruction, return_type); | 11865 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 11896 | | 11866 | |
| ... | @@ -11957,40 +11927,22 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -11957,40 +11927,22 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 11957 | | 11927 | |
| 11958 | if (call_instruction->is_async) { | 11928 | if (call_instruction->is_async) { |
| 11959 | IrInstruction *uncasted_async_allocator_inst; | 11929 | IrInstruction *uncasted_async_allocator_inst; |
| 11960 | IrInstruction *uncasted_alloc_fn_inst; | | |
| 11961 | IrInstruction *uncasted_free_fn_inst; | | |
| 11962 | if (call_instruction->async_allocator == nullptr) { | 11930 | if (call_instruction->async_allocator == nullptr) { |
| 11963 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, ImplicitAllocatorIdContext); | 11931 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base); |
| 11964 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) | 11932 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 11965 | return ira->codegen->builtin_types.entry_invalid; | 11933 | return ira->codegen->builtin_types.entry_invalid; |
| 11966 | | | |
| 11967 | uncasted_alloc_fn_inst = ir_get_implicit_allocator(ira, &call_instruction->base, ImplicitAllocatorIdAlloc); | | |
| 11968 | if (type_is_invalid(uncasted_alloc_fn_inst->value.type)) | | |
| 11969 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11970 | | | |
| 11971 | uncasted_free_fn_inst = ir_get_implicit_allocator(ira, &call_instruction->base, ImplicitAllocatorIdFree); | | |
| 11972 | if (type_is_invalid(uncasted_free_fn_inst->value.type)) | | |
| 11973 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11974 | } else { | 11934 | } else { |
| 11975 | uncasted_async_allocator_inst = call_instruction->async_allocator->other; | 11935 | uncasted_async_allocator_inst = call_instruction->async_allocator->other; |
| 11976 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) | 11936 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 11977 | return ira->codegen->builtin_types.entry_invalid; | 11937 | return ira->codegen->builtin_types.entry_invalid; |
| 11978 | | 11938 | |
| 11979 | uncasted_alloc_fn_inst = call_instruction->alloc_fn->other; | | |
| 11980 | if (type_is_invalid(uncasted_alloc_fn_inst->value.type)) | | |
| 11981 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11982 | | | |
| 11983 | uncasted_free_fn_inst = call_instruction->free_fn->other; | | |
| 11984 | if (type_is_invalid(uncasted_free_fn_inst->value.type)) | | |
| 11985 | return ira->codegen->builtin_types.entry_invalid; | | |
| 11986 | | | |
| 11987 | } | 11939 | } |
| 11988 | IrInstruction *async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, fn_type_id->async_allocator_type); | 11940 | IrInstruction *async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, fn_type_id->async_allocator_type); |
| 11989 | if (type_is_invalid(async_allocator_inst->value.type)) | 11941 | if (type_is_invalid(async_allocator_inst->value.type)) |
| 11990 | return ira->codegen->builtin_types.entry_invalid; | 11942 | return ira->codegen->builtin_types.entry_invalid; |
| 11991 | | 11943 | |
| 11992 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref, casted_args, call_param_count, | 11944 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref, casted_args, call_param_count, |
| 11993 | async_allocator_inst, uncasted_alloc_fn_inst, uncasted_free_fn_inst); | 11945 | async_allocator_inst); |
| 11994 | ir_link_new_instruction(result, &call_instruction->base); | 11946 | ir_link_new_instruction(result, &call_instruction->base); |
| 11995 | ir_add_alloca(ira, result, result->value.type); | 11947 | ir_add_alloca(ira, result, result->value.type); |
| 11996 | return ir_finish_anal(ira, result->value.type); | 11948 | return ir_finish_anal(ira, result->value.type); |
| ... | @@ -11998,7 +11950,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -11998,7 +11950,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 11998 | | 11950 | |
| 11999 | | 11951 | |
| 12000 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, | 11952 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 12001 | fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, nullptr, nullptr); | 11953 | fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr); |
| 12002 | | 11954 | |
| 12003 | ir_add_alloca(ira, new_call_instruction, return_type); | 11955 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 12004 | return ir_finish_anal(ira, return_type); | 11956 | return ir_finish_anal(ira, return_type); |
| ... | @@ -17238,7 +17190,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr | ... | @@ -17238,7 +17190,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr |
| 17238 | } | 17190 | } |
| 17239 | | 17191 | |
| 17240 | static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { | 17192 | static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { |
| 17241 | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); | 17193 | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base); |
| 17242 | ir_link_new_instruction(result, &instruction->base); | 17194 | ir_link_new_instruction(result, &instruction->base); |
| 17243 | return result->value.type; | 17195 | return result->value.type; |
| 17244 | } | 17196 | } |