authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:34:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:34:41-04:00
log93840f8610974109d129e6940a851c1f7a8c9fce
tree27340e91d8a841dded09df37c762ebe8875495a7
parentcfe84423c97eb2121138c2de5876c47782cd6dda
signaturelock-open Commit is signed but in an unrecognized format.

fix var args call on non-generic function


2 files changed, 64 insertions(+), 17 deletions(-)

src/ir.cpp+49-15
...@@ -15799,26 +15799,60 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -15799,26 +15799,60 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
15799 casted_args[next_arg_index] = casted_arg;15799 casted_args[next_arg_index] = casted_arg;
15800 next_arg_index += 1;15800 next_arg_index += 1;
15801 }15801 }
15802 size_t iter_count = (call_param_count < call_instruction->arg_count) ?15802 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
15803 call_param_count : call_instruction->arg_count;
15804 for (size_t call_i = 0; call_i < iter_count; call_i += 1) {
15805 IrInstruction *old_arg = call_instruction->args[call_i]->child;15803 IrInstruction *old_arg = call_instruction->args[call_i]->child;
15806 if (type_is_invalid(old_arg->value.type))15804 if (type_is_invalid(old_arg->value.type))
15807 return ira->codegen->invalid_instruction;15805 return ira->codegen->invalid_instruction;
15808 IrInstruction *casted_arg;15806
15809 if (next_arg_index < src_param_count) {15807 if (old_arg->value.type->id == ZigTypeIdArgTuple) {
15810 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;15808 for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index;
15811 if (type_is_invalid(param_type))15809 arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
15812 return ira->codegen->invalid_instruction;15810 {
15813 casted_arg = ir_implicit_cast(ira, old_arg, param_type);15811 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
15814 if (type_is_invalid(casted_arg->value.type))15812 if (arg_var == nullptr) {
15815 return ira->codegen->invalid_instruction;15813 ir_add_error(ira, old_arg,
15814 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
15815 return ira->codegen->invalid_instruction;
15816 }
15817 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var);
15818 if (type_is_invalid(arg_var_ptr_inst->value.type))
15819 return ira->codegen->invalid_instruction;
15820
15821 IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr);
15822 if (type_is_invalid(arg_tuple_arg->value.type))
15823 return ira->codegen->invalid_instruction;
15824
15825 IrInstruction *casted_arg;
15826 if (next_arg_index < src_param_count) {
15827 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
15828 if (type_is_invalid(param_type))
15829 return ira->codegen->invalid_instruction;
15830 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);
15831 if (type_is_invalid(casted_arg->value.type))
15832 return ira->codegen->invalid_instruction;
15833 } else {
15834 casted_arg = arg_tuple_arg;
15835 }
15836
15837 casted_args[next_arg_index] = casted_arg;
15838 next_arg_index += 1;
15839 }
15816 } else {15840 } else {
15817 casted_arg = old_arg;15841 IrInstruction *casted_arg;
15818 }15842 if (next_arg_index < src_param_count) {
15843 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
15844 if (type_is_invalid(param_type))
15845 return ira->codegen->invalid_instruction;
15846 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
15847 if (type_is_invalid(casted_arg->value.type))
15848 return ira->codegen->invalid_instruction;
15849 } else {
15850 casted_arg = old_arg;
15851 }
1581915852
15820 casted_args[next_arg_index] = casted_arg;15853 casted_args[next_arg_index] = casted_arg;
15821 next_arg_index += 1;15854 next_arg_index += 1;
15855 }
15822 }15856 }
1582315857
15824 assert(next_arg_index == call_param_count);15858 assert(next_arg_index == call_param_count);
std/event/loop.zig+15-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const root = @import("root");
3const assert = std.debug.assert;4const assert = std.debug.assert;
4const testing = std.testing;5const testing = std.testing;
5const mem = std.mem;6const mem = std.mem;
...@@ -85,6 +86,18 @@ pub const Loop = struct {...@@ -85,6 +86,18 @@ pub const Loop = struct {
85 };86 };
86 };87 };
8788
89 pub const IoMode = enum {
90 blocking,
91 evented,
92 };
93 pub const io_mode: IoMode = if (@hasDecl(root, "io_mode")) root.io_mode else IoMode.blocking;
94 var global_instance_state: Loop = undefined;
95 const default_instance: ?*Loop = switch (io_mode) {
96 .blocking => null,
97 .evented => &global_instance_state,
98 };
99 pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance;
100
88 /// After initialization, call run().101 /// After initialization, call run().
89 /// TODO copy elision / named return values so that the threads referencing *Loop102 /// TODO copy elision / named return values so that the threads referencing *Loop
90 /// have the correct pointer value.103 /// have the correct pointer value.
...@@ -599,7 +612,7 @@ pub const Loop = struct {...@@ -599,7 +612,7 @@ pub const Loop = struct {
599 /// If the build is multi-threaded and there is an event loop, then it calls `yield`. Otherwise,612 /// If the build is multi-threaded and there is an event loop, then it calls `yield`. Otherwise,
600 /// does nothing.613 /// does nothing.
601 pub fn startCpuBoundOperation() void {614 pub fn startCpuBoundOperation() void {
602 if (builtin.is_single_threaded) {615 if (builtin.single_threaded) {
603 return;616 return;
604 } else if (instance) |event_loop| {617 } else if (instance) |event_loop| {
605 event_loop.yield();618 event_loop.yield();
...@@ -881,7 +894,7 @@ test "std.event.Loop - call" {...@@ -881,7 +894,7 @@ test "std.event.Loop - call" {
881894
882 var did_it = false;895 var did_it = false;
883 const handle = async Loop.call(testEventLoop);896 const handle = async Loop.call(testEventLoop);
884 const handle2 = async Loop.call(testEventLoop2, handle, &did_it);897 const handle2 = async Loop.call(testEventLoop2, &handle, &did_it);
885898
886 loop.run();899 loop.run();
887900