authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-22 09:30:55-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-22 09:30:55-05:00
log37c07d4f3f52f2227e86943cf84aebdc729684b7
tree1f9d5d931ca6afffa1670f18a73e124a4927506f
parentb261da067248c4003b0008f6aaeefde43290a061

coroutines: analyze get_implicit_allocator instruction

see #727

2 files changed, 19 insertions(+), 5 deletions(-)

src/ir.cpp+17-5
...@@ -5884,7 +5884,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -5884,7 +5884,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
5884 IrInstruction **incoming_values = allocate<IrInstruction *>(2);5884 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
5885 incoming_blocks[0] = entry_block;5885 incoming_blocks[0] = entry_block;
5886 incoming_values[0] = null_ptr;5886 incoming_values[0] = null_ptr;
5887 incoming_blocks[1] = dyn_alloc_block;5887 incoming_blocks[1] = alloc_ok_block;
5888 incoming_values[1] = coro_mem_ptr;5888 incoming_values[1] = coro_mem_ptr;
5889 IrInstruction *coro_mem = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);5889 IrInstruction *coro_mem = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
5890 irb->exec->coro_handle = ir_build_coro_begin(irb, scope, node, coro_id, coro_mem);5890 irb->exec->coro_handle = ir_build_coro_begin(irb, scope, node, coro_id, coro_mem);
...@@ -10897,7 +10897,13 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -10897,7 +10897,13 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
10897 return ira->codegen->builtin_types.entry_type;10897 return ira->codegen->builtin_types.entry_type;
10898}10898}
1089910899
10900IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, FnTableEntry *parent_fn_entry) {10900IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr) {
10901 FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
10902 if (parent_fn_entry == nullptr) {
10903 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
10904 return ira->codegen->invalid_instruction;
10905 }
10906
10901 FnTypeId *parent_fn_type = &parent_fn_entry->type_entry->data.fn.fn_type_id;10907 FnTypeId *parent_fn_type = &parent_fn_entry->type_entry->data.fn.fn_type_id;
10902 if (parent_fn_type->cc != CallingConventionAsync) {10908 if (parent_fn_type->cc != CallingConventionAsync) {
10903 ir_add_error(ira, source_instr, buf_sprintf("async function call from non-async caller requires allocator parameter"));10909 ir_add_error(ira, source_instr, buf_sprintf("async function call from non-async caller requires allocator parameter"));
...@@ -11467,7 +11473,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -11467,7 +11473,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
11467 }11473 }
11468 IrInstruction *uncasted_async_allocator_inst;11474 IrInstruction *uncasted_async_allocator_inst;
11469 if (call_instruction->async_allocator == nullptr) {11475 if (call_instruction->async_allocator == nullptr) {
11470 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, parent_fn_entry);11476 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base);
11471 if (type_is_invalid(uncasted_async_allocator_inst->value.type))11477 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
11472 return ira->codegen->builtin_types.entry_invalid;11478 return ira->codegen->builtin_types.entry_invalid;
11473 } else {11479 } else {
...@@ -11586,7 +11592,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -11586,7 +11592,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
11586 if (call_instruction->is_async) {11592 if (call_instruction->is_async) {
11587 IrInstruction *uncasted_async_allocator_inst;11593 IrInstruction *uncasted_async_allocator_inst;
11588 if (call_instruction->async_allocator == nullptr) {11594 if (call_instruction->async_allocator == nullptr) {
11589 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, parent_fn_entry);11595 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base);
11590 if (type_is_invalid(uncasted_async_allocator_inst->value.type))11596 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
11591 return ira->codegen->builtin_types.entry_invalid;11597 return ira->codegen->builtin_types.entry_invalid;
11592 } else {11598 } else {
...@@ -16816,6 +16822,11 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr...@@ -16816,6 +16822,11 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
16816 zig_panic("TODO ir_analyze_instruction_coro_begin");16822 zig_panic("TODO ir_analyze_instruction_coro_begin");
16817}16823}
1681816824
16825static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
16826 IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base);
16827 return result->value.type;
16828}
16829
16819static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {16830static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
16820 switch (instruction->id) {16831 switch (instruction->id) {
16821 case IrInstructionIdInvalid:16832 case IrInstructionIdInvalid:
...@@ -16831,7 +16842,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -16831,7 +16842,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
16831 case IrInstructionIdErrWrapCode:16842 case IrInstructionIdErrWrapCode:
16832 case IrInstructionIdErrWrapPayload:16843 case IrInstructionIdErrWrapPayload:
16833 case IrInstructionIdCast:16844 case IrInstructionIdCast:
16834 case IrInstructionIdGetImplicitAllocator:
16835 zig_unreachable();16845 zig_unreachable();
16836 case IrInstructionIdReturn:16846 case IrInstructionIdReturn:
16837 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);16847 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);
...@@ -17029,6 +17039,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -17029,6 +17039,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
17029 return ir_analyze_instruction_coro_size(ira, (IrInstructionCoroSize *)instruction);17039 return ir_analyze_instruction_coro_size(ira, (IrInstructionCoroSize *)instruction);
17030 case IrInstructionIdCoroBegin:17040 case IrInstructionIdCoroBegin:
17031 return ir_analyze_instruction_coro_begin(ira, (IrInstructionCoroBegin *)instruction);17041 return ir_analyze_instruction_coro_begin(ira, (IrInstructionCoroBegin *)instruction);
17042 case IrInstructionIdGetImplicitAllocator:
17043 return ir_analyze_instruction_get_implicit_allocator(ira, (IrInstructionGetImplicitAllocator *)instruction);
17032 }17044 }
17033 zig_unreachable();17045 zig_unreachable();
17034}17046}
src/ir_print.cpp+2
...@@ -839,6 +839,8 @@ static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction...@@ -839,6 +839,8 @@ static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction
839839
840static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {840static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
841 fprintf(irp->f, "@intToPtr(");841 fprintf(irp->f, "@intToPtr(");
842 ir_print_other_instruction(irp, instruction->dest_type);
843 fprintf(irp->f, ",");
842 ir_print_other_instruction(irp, instruction->target);844 ir_print_other_instruction(irp, instruction->target);
843 fprintf(irp->f, ")");845 fprintf(irp->f, ")");
844}846}