Skip to content

Commit 138d6f9

Browse files
committed
revert workaround for alloc and free as coro params
reverts 4ac6c4d the workaround didn't work
1 parent 132e604 commit 138d6f9

File tree

5 files changed

+55
-165
lines changed

5 files changed

+55
-165
lines changed

src/all_types.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,6 @@ struct IrInstructionCall {
22102210
bool is_async;
22112211

22122212
IrInstruction *async_allocator;
2213-
IrInstruction *alloc_fn;
2214-
IrInstruction *free_fn;
22152213
};
22162214

22172215
struct IrInstructionConst {
@@ -2852,16 +2850,8 @@ struct IrInstructionCancel {
28522850
IrInstruction *target;
28532851
};
28542852

2855-
enum ImplicitAllocatorId {
2856-
ImplicitAllocatorIdContext,
2857-
ImplicitAllocatorIdAlloc,
2858-
ImplicitAllocatorIdFree,
2859-
};
2860-
28612853
struct IrInstructionGetImplicitAllocator {
28622854
IrInstruction base;
2863-
2864-
ImplicitAllocatorId id;
28652855
};
28662856

28672857
struct IrInstructionCoroId {

src/analyze.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,13 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10061006
fn_type_id->return_type->id == TypeTableEntryIdErrorSet);
10071007
// +1 for maybe making the first argument the return value
10081008
// +1 for maybe first argument the error return trace
1009-
// +4 for maybe arguments async allocator and error code pointer
1010-
LLVMTypeRef *gen_param_types = allocate<LLVMTypeRef>(6 + fn_type_id->param_count);
1009+
// +2 for maybe arguments async allocator and error code pointer
1010+
LLVMTypeRef *gen_param_types = allocate<LLVMTypeRef>(4 + fn_type_id->param_count);
10111011
// +1 because 0 is the return type and
10121012
// +1 for maybe making first arg ret val and
10131013
// +1 for maybe first argument the error return trace
1014-
// +4 for maybe arguments async allocator and error code pointer
1015-
ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(7 + fn_type_id->param_count);
1014+
// +2 for maybe arguments async allocator and error code pointer
1015+
ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(5 + fn_type_id->param_count);
10161016
param_di_types[0] = fn_type_id->return_type->di_type;
10171017
size_t gen_param_index = 0;
10181018
TypeTableEntry *gen_return_type;
@@ -1052,32 +1052,6 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10521052
param_di_types[gen_param_index] = gen_type->di_type;
10531053
}
10541054

1055-
{
1056-
// async alloc fn param
1057-
assert(fn_type_id->async_allocator_type->id == TypeTableEntryIdPointer);
1058-
TypeTableEntry *struct_type = fn_type_id->async_allocator_type->data.pointer.child_type;
1059-
TypeStructField *alloc_fn_field = find_struct_type_field(struct_type, buf_create_from_str("allocFn"));
1060-
assert(alloc_fn_field->type_entry->id == TypeTableEntryIdFn);
1061-
TypeTableEntry *gen_type = alloc_fn_field->type_entry;
1062-
gen_param_types[gen_param_index] = gen_type->type_ref;
1063-
gen_param_index += 1;
1064-
// after the gen_param_index += 1 because 0 is the return type
1065-
param_di_types[gen_param_index] = gen_type->di_type;
1066-
}
1067-
1068-
{
1069-
// async free fn param
1070-
assert(fn_type_id->async_allocator_type->id == TypeTableEntryIdPointer);
1071-
TypeTableEntry *struct_type = fn_type_id->async_allocator_type->data.pointer.child_type;
1072-
TypeStructField *free_fn_field = find_struct_type_field(struct_type, buf_create_from_str("freeFn"));
1073-
assert(free_fn_field->type_entry->id == TypeTableEntryIdFn);
1074-
TypeTableEntry *gen_type = free_fn_field->type_entry;
1075-
gen_param_types[gen_param_index] = gen_type->type_ref;
1076-
gen_param_index += 1;
1077-
// after the gen_param_index += 1 because 0 is the return type
1078-
param_di_types[gen_param_index] = gen_type->di_type;
1079-
}
1080-
10811055
{
10821056
// error code pointer
10831057
TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);

src/codegen.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,15 +2673,15 @@ static bool get_prefix_arg_err_ret_stack(CodeGen *g, TypeTableEntry *src_return_
26732673
}
26742674

26752675
static size_t get_async_allocator_arg_index(CodeGen *g, TypeTableEntry *src_return_type) {
2676-
// 0 1 2 3 4 5
2677-
// err_ret_stack allocator_ptr alloc free err_code other_args...
2676+
// 0 1 2 3
2677+
// err_ret_stack allocator_ptr err_code other_args...
26782678
return get_prefix_arg_err_ret_stack(g, src_return_type) ? 1 : 0;
26792679
}
26802680

26812681
static size_t get_async_err_code_arg_index(CodeGen *g, TypeTableEntry *src_return_type) {
2682-
// 0 1 2 3 4 5
2683-
// err_ret_stack allocator_ptr alloc free err_code other_args...
2684-
return 3 + get_async_allocator_arg_index(g, src_return_type);
2682+
// 0 1 2 3
2683+
// err_ret_stack allocator_ptr err_code other_args...
2684+
return 1 + get_async_allocator_arg_index(g, src_return_type);
26852685
}
26862686

26872687
static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
@@ -2704,8 +2704,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
27042704
bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) &&
27052705
calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc);
27062706
bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, src_return_type);
2707-
// +4 for the async args
2708-
size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0) + 4;
2707+
// +2 for the async args
2708+
size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0) + 2;
27092709
bool is_var_args = fn_type_id->is_var_args;
27102710
LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
27112711
size_t gen_param_index = 0;
@@ -2721,12 +2721,6 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
27212721
gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->async_allocator);
27222722
gen_param_index += 1;
27232723

2724-
gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->alloc_fn);
2725-
gen_param_index += 1;
2726-
2727-
gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->free_fn);
2728-
gen_param_index += 1;
2729-
27302724
LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");
27312725
LLVMBuildStore(g->builder, LLVMConstNull(g->builtin_types.entry_global_error_set->type_ref), err_val_ptr);
27322726
gen_param_values[gen_param_index] = err_val_ptr;
@@ -3308,15 +3302,7 @@ static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *e
33083302
{
33093303
TypeTableEntry *src_return_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
33103304
size_t allocator_arg_index = get_async_allocator_arg_index(g, src_return_type);
3311-
switch (instruction->id) {
3312-
case ImplicitAllocatorIdContext:
3313-
return LLVMGetParam(g->cur_fn_val, allocator_arg_index + 0);
3314-
case ImplicitAllocatorIdAlloc:
3315-
return LLVMGetParam(g->cur_fn_val, allocator_arg_index + 1);
3316-
case ImplicitAllocatorIdFree:
3317-
return LLVMGetParam(g->cur_fn_val, allocator_arg_index + 2);
3318-
}
3319-
zig_unreachable();
3305+
return LLVMGetParam(g->cur_fn_val, allocator_arg_index);
33203306
}
33213307

33223308
static LLVMAtomicOrdering to_LLVMAtomicOrdering(AtomicOrder atomic_order) {

0 commit comments

Comments
 (0)