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 @@
66 * cancel
77 * defer and errdefer
88 * safety for resuming when it is awaiting
9 * safety for double await
910 * implicit cast of normal function to async function should be allowed when it is inferred to be async
1011 * go over the commented out tests
1112 * revive std.event.Loop
1213 * @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
2438024380 IrInstruction *frame;
2438124381 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
2438224382 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
24383 frame_ptr->value.type->data.pointer.is_const &&
2438424383 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdAnyFrame)
2438524384 {
2438624385 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);
test/stage1/behavior/coroutines.zig+53-54
......@@ -132,56 +132,55 @@ test "@frameSize" {
132132 S.doTheTest();
133133}
134134
135//test "coroutine suspend, resume" {
136// seq('a');
137// const p = try async<allocator> testAsyncSeq();
138// seq('c');
139// resume p;
140// seq('f');
141// cancel p;
142// seq('g');
143//
144// expect(std.mem.eql(u8, points, "abcdefg"));
145//}
146//async fn testAsyncSeq() void {
147// defer seq('e');
148//
149// seq('b');
150// suspend;
151// seq('d');
152//}
153//var points = [_]u8{0} ** "abcdefg".len;
154//var index: usize = 0;
155//
156//fn seq(c: u8) void {
157// points[index] = c;
158// index += 1;
159//}
160//
161//test "coroutine suspend with block" {
162// const p = try async<allocator> testSuspendBlock();
163// std.testing.expect(!result);
164// resume a_promise;
165// std.testing.expect(result);
166// cancel p;
167//}
168//
169//var a_promise: promise = undefined;
170//var result = false;
171//async fn testSuspendBlock() void {
172// suspend {
173// comptime expect(@typeOf(@handle()) == promise->void);
174// a_promise = @handle();
175// }
176//
177// //Test to make sure that @handle() works as advertised (issue #1296)
178// //var our_handle: promise = @handle();
179// expect(a_promise == @handle());
180//
181// result = true;
182//}
183//
184//var await_a_promise: promise = undefined;
135test "coroutine suspend, resume" {
136 seq('a');
137 const p = async testAsyncSeq();
138 seq('c');
139 resume p;
140 seq('f');
141 // `cancel` is now a suspend point so it cannot be done here
142 seq('g');
143
144 expect(std.mem.eql(u8, points, "abcdefg"));
145}
146async fn testAsyncSeq() void {
147 defer seq('e');
148
149 seq('b');
150 suspend;
151 seq('d');
152}
153var points = [_]u8{0} ** "abcdefg".len;
154var index: usize = 0;
155
156fn seq(c: u8) void {
157 points[index] = c;
158 index += 1;
159}
160
161test "coroutine suspend with block" {
162 const p = async testSuspendBlock();
163 expect(!result);
164 resume a_promise;
165 expect(result);
166}
167
168var a_promise: anyframe = undefined;
169var result = false;
170async fn testSuspendBlock() void {
171 suspend {
172 comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock));
173 a_promise = @frame();
174 }
175
176 // Test to make sure that @frame() works as advertised (issue #1296)
177 // var our_handle: anyframe = @frame();
178 expect(a_promise == anyframe(@frame()));
179
180 result = true;
181}
182
183//var await_a_promise: anyframe = undefined;
185184//var await_final_result: i32 = 0;
186185//
187186//test "coroutine await" {
......@@ -204,7 +203,7 @@ test "@frameSize" {
204203// await_seq('c');
205204// suspend {
206205// await_seq('d');
207// await_a_promise = @handle();
206// await_a_promise = @frame();
208207// }
209208// await_seq('g');
210209// return 1234;
......@@ -314,14 +313,14 @@ test "@frameSize" {
314313// cancel p2;
315314//}
316315//
317//fn nonFailing() (promise->anyerror!void) {
316//fn nonFailing() (anyframe->anyerror!void) {
318317// return async<std.debug.global_allocator> suspendThenFail() catch unreachable;
319318//}
320319//async fn suspendThenFail() anyerror!void {
321320// suspend;
322321// return error.Fail;
323322//}
324//async fn printTrace(p: promise->(anyerror!void)) void {
323//async fn printTrace(p: anyframe->(anyerror!void)) void {
325324// (await p) catch |e| {
326325// std.testing.expect(e == error.Fail);
327326// if (@errorReturnTrace()) |trace| {
......@@ -343,7 +342,7 @@ test "@frameSize" {
343342//}
344343//async fn testBreakFromSuspend(my_result: *i32) void {
345344// suspend {
346// resume @handle();
345// resume @frame();
347346// }
348347// my_result.* += 1;
349348// suspend;