authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-01 19:14:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-01 19:14:48-04:00
log0f879d02a4c4b1de0e28c2863c1e5f3760eb5b19
tree4dd598cc5bd16e95b5c60ebdeb94141780f9dc7b
parent1dd0c3d49f929fc280d5bb4bbeed6538b50b2535
signature Commit is signed but in an unrecognized format.

more passing coroutine tests


3 files changed, 56 insertions(+), 55 deletions(-)

BRANCH_TODO+3
...@@ -6,7 +6,10 @@...@@ -6,7 +6,10 @@
6 * cancel6 * cancel
7 * defer and errdefer7 * defer and errdefer
8 * safety for resuming when it is awaiting8 * safety for resuming when it is awaiting
9 * safety for double await
9 * implicit cast of normal function to async function should be allowed when it is inferred to be async10 * implicit cast of normal function to async function should be allowed when it is inferred to be async
10 * go over the commented out tests11 * go over the commented out tests
11 * revive std.event.Loop12 * revive std.event.Loop
12 * @typeInfo for @Frame(func)13 * @typeInfo for @Frame(func)
14 * peer type resolution of *@Frame(func) and anyframe
15 * peer type resolution of *@Frame(func) and anyframe->T when the return type matches
src/ir.cpp-1
...@@ -24380,7 +24380,6 @@ static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstr...@@ -24380,7 +24380,6 @@ static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstr
24380 IrInstruction *frame;24380 IrInstruction *frame;
24381 if (frame_ptr->value.type->id == ZigTypeIdPointer &&24381 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
24382 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&24382 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
24383 frame_ptr->value.type->data.pointer.is_const &&
24384 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdAnyFrame)24383 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdAnyFrame)
24385 {24384 {
24386 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);24385 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);
test/stage1/behavior/coroutines.zig+53-54
...@@ -132,56 +132,55 @@ test "@frameSize" {...@@ -132,56 +132,55 @@ test "@frameSize" {
132 S.doTheTest();132 S.doTheTest();
133}133}
134134
135//test "coroutine suspend, resume" {135test "coroutine suspend, resume" {
136// seq('a');136 seq('a');
137// const p = try async<allocator> testAsyncSeq();137 const p = async testAsyncSeq();
138// seq('c');138 seq('c');
139// resume p;139 resume p;
140// seq('f');140 seq('f');
141// cancel p;141 // `cancel` is now a suspend point so it cannot be done here
142// seq('g');142 seq('g');
143//143
144// expect(std.mem.eql(u8, points, "abcdefg"));144 expect(std.mem.eql(u8, points, "abcdefg"));
145//}145}
146//async fn testAsyncSeq() void {146async fn testAsyncSeq() void {
147// defer seq('e');147 defer seq('e');
148//148
149// seq('b');149 seq('b');
150// suspend;150 suspend;
151// seq('d');151 seq('d');
152//}152}
153//var points = [_]u8{0} ** "abcdefg".len;153var points = [_]u8{0} ** "abcdefg".len;
154//var index: usize = 0;154var index: usize = 0;
155//155
156//fn seq(c: u8) void {156fn seq(c: u8) void {
157// points[index] = c;157 points[index] = c;
158// index += 1;158 index += 1;
159//}159}
160//160
161//test "coroutine suspend with block" {161test "coroutine suspend with block" {
162// const p = try async<allocator> testSuspendBlock();162 const p = async testSuspendBlock();
163// std.testing.expect(!result);163 expect(!result);
164// resume a_promise;164 resume a_promise;
165// std.testing.expect(result);165 expect(result);
166// cancel p;166}
167//}167
168//168var a_promise: anyframe = undefined;
169//var a_promise: promise = undefined;169var result = false;
170//var result = false;170async fn testSuspendBlock() void {
171//async fn testSuspendBlock() void {171 suspend {
172// suspend {172 comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock));
173// comptime expect(@typeOf(@handle()) == promise->void);173 a_promise = @frame();
174// a_promise = @handle();174 }
175// }175
176//176 // Test to make sure that @frame() works as advertised (issue #1296)
177// //Test to make sure that @handle() works as advertised (issue #1296)177 // var our_handle: anyframe = @frame();
178// //var our_handle: promise = @handle();178 expect(a_promise == anyframe(@frame()));
179// expect(a_promise == @handle());179
180//180 result = true;
181// result = true;181}
182//}182
183//183//var await_a_promise: anyframe = undefined;
184//var await_a_promise: promise = undefined;
185//var await_final_result: i32 = 0;184//var await_final_result: i32 = 0;
186//185//
187//test "coroutine await" {186//test "coroutine await" {
...@@ -204,7 +203,7 @@ test "@frameSize" {...@@ -204,7 +203,7 @@ test "@frameSize" {
204// await_seq('c');203// await_seq('c');
205// suspend {204// suspend {
206// await_seq('d');205// await_seq('d');
207// await_a_promise = @handle();206// await_a_promise = @frame();
208// }207// }
209// await_seq('g');208// await_seq('g');
210// return 1234;209// return 1234;
...@@ -314,14 +313,14 @@ test "@frameSize" {...@@ -314,14 +313,14 @@ test "@frameSize" {
314// cancel p2;313// cancel p2;
315//}314//}
316//315//
317//fn nonFailing() (promise->anyerror!void) {316//fn nonFailing() (anyframe->anyerror!void) {
318// return async<std.debug.global_allocator> suspendThenFail() catch unreachable;317// return async<std.debug.global_allocator> suspendThenFail() catch unreachable;
319//}318//}
320//async fn suspendThenFail() anyerror!void {319//async fn suspendThenFail() anyerror!void {
321// suspend;320// suspend;
322// return error.Fail;321// return error.Fail;
323//}322//}
324//async fn printTrace(p: promise->(anyerror!void)) void {323//async fn printTrace(p: anyframe->(anyerror!void)) void {
325// (await p) catch |e| {324// (await p) catch |e| {
326// std.testing.expect(e == error.Fail);325// std.testing.expect(e == error.Fail);
327// if (@errorReturnTrace()) |trace| {326// if (@errorReturnTrace()) |trace| {
...@@ -343,7 +342,7 @@ test "@frameSize" {...@@ -343,7 +342,7 @@ test "@frameSize" {
343//}342//}
344//async fn testBreakFromSuspend(my_result: *i32) void {343//async fn testBreakFromSuspend(my_result: *i32) void {
345// suspend {344// suspend {
346// resume @handle();345// resume @frame();
347// }346// }
348// my_result.* += 1;347// my_result.* += 1;
349// suspend;348// suspend;