authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-13 14:14:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-13 14:14:19-04:00
log50926341036c3ba377215d1c70c3e97adb07a292
tree3c282b9bae56f4bfbf0748af62a4138084b72985
parent82d4ebe53a9d86559dee4e82cde97ab26e76a375
signaturelock-open Commit is signed but in an unrecognized format.

avoid the word "coroutine", they're "async functions"


23 files changed, 175 insertions(+), 199 deletions(-)

BRANCH_TODO+1-1
......@@ -1,4 +1,4 @@
1 * grep for "coroutine" and "coro" and replace all that nomenclature with "async functions"
1 * zig fmt support for the syntax
22 * alignment of variables not being respected in async functions
33 * await of a non async function
44 * async call on a non async function
doc/langref.html.in+20-20
......@@ -5968,9 +5968,10 @@ test "global assembly" {
59685968 <p>TODO: @atomic rmw</p>
59695969 <p>TODO: builtin atomic memory ordering enum</p>
59705970 {#header_close#}
5971 {#header_open|Coroutines#}
5971 {#header_open|Async Functions#}
59725972 <p>
5973 A coroutine is a generalization of a function.
5973 An async function is a function whose callsite is split into an {#syntax#}async{#endsyntax#} initiation,
5974 followed by an {#syntax#}await{#endsyntax#} completion. They can also be canceled.
59745975 </p>
59755976 <p>
59765977 When you call a function, it creates a stack frame,
......@@ -5980,14 +5981,14 @@ test "global assembly" {
59805981 until the function returns.
59815982 </p>
59825983 <p>
5983 A coroutine is like a function, but it can be suspended
5984 An async function is like a function, but it can be suspended
59845985 and resumed any number of times, and then it must be
5985 explicitly destroyed. When a coroutine suspends, it
5986 explicitly destroyed. When an async function suspends, it
59865987 returns to the resumer.
59875988 </p>
5988 {#header_open|Minimal Coroutine Example#}
5989 {#header_open|Minimal Async Function Example#}
59895990 <p>
5990 Declare a coroutine with the {#syntax#}async{#endsyntax#} keyword.
5991 Declare an async function with the {#syntax#}async{#endsyntax#} keyword.
59915992 The expression in angle brackets must evaluate to a struct
59925993 which has these fields:
59935994 </p>
......@@ -6006,8 +6007,8 @@ test "global assembly" {
60066007 the function generic. Zig will infer the allocator type when the async function is called.
60076008 </p>
60086009 <p>
6009 Call a coroutine with the {#syntax#}async{#endsyntax#} keyword. Here, the expression in angle brackets
6010 is a pointer to the allocator struct that the coroutine expects.
6010 Call an async function with the {#syntax#}async{#endsyntax#} keyword. Here, the expression in angle brackets
6011 is a pointer to the allocator struct that the async function expects.
60116012 </p>
60126013 <p>
60136014 The result of an async function call is a {#syntax#}promise->T{#endsyntax#} type, where {#syntax#}T{#endsyntax#}
......@@ -6058,7 +6059,7 @@ const assert = std.debug.assert;
60586059var the_frame: anyframe = undefined;
60596060var result = false;
60606061
6061test "coroutine suspend with block" {
6062test "async function suspend with block" {
60626063 _ = async testSuspendBlock();
60636064 std.debug.assert(!result);
60646065 resume the_frame;
......@@ -6074,7 +6075,7 @@ fn testSuspendBlock() void {
60746075}
60756076 {#code_end#}
60766077 <p>
6077 Every suspend point in an async function represents a point at which the coroutine
6078 Every suspend point in an async function represents a point at which the async function
60786079 could be destroyed. If that happens, {#syntax#}defer{#endsyntax#} expressions that are in
60796080 scope are run, as well as {#syntax#}errdefer{#endsyntax#} expressions.
60806081 </p>
......@@ -6083,14 +6084,14 @@ fn testSuspendBlock() void {
60836084 </p>
60846085 {#header_open|Resuming from Suspend Blocks#}
60856086 <p>
6086 Upon entering a {#syntax#}suspend{#endsyntax#} block, the coroutine is already considered
6087 Upon entering a {#syntax#}suspend{#endsyntax#} block, the async function is already considered
60876088 suspended, and can be resumed. For example, if you started another kernel thread,
60886089 and had that thread call {#syntax#}resume{#endsyntax#} on the promise handle provided by the
60896090 {#syntax#}suspend{#endsyntax#} block, the new thread would begin executing after the suspend
60906091 block, while the old thread continued executing the suspend block.
60916092 </p>
60926093 <p>
6093 However, the coroutine can be directly resumed from the suspend block, in which case it
6094 However, the async function can be directly resumed from the suspend block, in which case it
60946095 never returns to its resumer and continues executing.
60956096 </p>
60966097 {#code_begin|test#}
......@@ -6127,8 +6128,8 @@ async fn testResumeFromSuspend(my_result: *i32) void {
61276128 If the async function associated with the promise handle has already returned,
61286129 then {#syntax#}await{#endsyntax#} destroys the target async function, and gives the return value.
61296130 Otherwise, {#syntax#}await{#endsyntax#} suspends the current async function, registering its
6130 promise handle with the target coroutine. It becomes the target coroutine's responsibility
6131 to have ensured that it will be resumed or destroyed. When the target coroutine reaches
6131 promise handle with the target async function. It becomes the target async function's responsibility
6132 to have ensured that it will be resumed or destroyed. When the target async function reaches
61326133 its return statement, it gives the return value to the awaiter, destroys itself, and then
61336134 resumes the awaiter.
61346135 </p>
......@@ -6137,7 +6138,7 @@ async fn testResumeFromSuspend(my_result: *i32) void {
61376138 </p>
61386139 <p>
61396140 {#syntax#}await{#endsyntax#} counts as a suspend point, and therefore at every {#syntax#}await{#endsyntax#},
6140 a coroutine can be potentially destroyed, which would run {#syntax#}defer{#endsyntax#} and {#syntax#}errdefer{#endsyntax#} expressions.
6141 a async function can be potentially destroyed, which would run {#syntax#}defer{#endsyntax#} and {#syntax#}errdefer{#endsyntax#} expressions.
61416142 </p>
61426143 {#code_begin|test#}
61436144const std = @import("std");
......@@ -6146,7 +6147,7 @@ const assert = std.debug.assert;
61466147var the_frame: anyframe = undefined;
61476148var final_result: i32 = 0;
61486149
6149test "coroutine await" {
6150test "async function await" {
61506151 seq('a');
61516152 _ = async amain();
61526153 seq('f');
......@@ -6188,7 +6189,7 @@ fn seq(c: u8) void {
61886189 {#header_close#}
61896190 {#header_open|Open Issues#}
61906191 <p>
6191 There are a few issues with coroutines that are considered unresolved. Best be aware of them,
6192 There are a few issues with async function that are considered unresolved. Best be aware of them,
61926193 as the situation is likely to change before 1.0.0:
61936194 </p>
61946195 <ul>
......@@ -6202,7 +6203,7 @@ fn seq(c: u8) void {
62026203 </li>
62036204 <li>
62046205 Zig does not take advantage of LLVM's allocation elision optimization for
6205 coroutines. It crashed LLVM when I tried to do it the first time. This is
6206 async function. It crashed LLVM when I tried to do it the first time. This is
62066207 related to the other 2 bullet points here. See
62076208 <a href="https://github.com/ziglang/zig/issues/802">#802</a>.
62086209 </li>
......@@ -8016,8 +8017,7 @@ pub fn build(b: *Builder) void {
80168017 <p>Zig has a compile option <code>--single-threaded</code> which has the following effects:
80178018 <ul>
80188019 <li>All {#link|Thread Local Variables#} are treated as {#link|Global Variables#}.</li>
8019 <li>The overhead of {#link|Coroutines#} becomes equivalent to function call overhead.
8020 TODO: please note this will not be implemented until the upcoming Coroutine Rewrite</li>
8020 <li>The overhead of {#link|Async Functions#} becomes equivalent to function call overhead.</li>
80218021 <li>The {#syntax#}@import("builtin").single_threaded{#endsyntax#} becomes {#syntax#}true{#endsyntax#}
80228022 and therefore various userland APIs which read this variable become more efficient.
80238023 For example {#syntax#}std.Mutex{#endsyntax#} becomes
src-self-hosted/ir.zig-14
......@@ -1904,20 +1904,6 @@ pub const Builder = struct {
19041904 }
19051905 return error.Unimplemented;
19061906
1907 //ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_field_ptr, return_value);
1908 //IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node,
1909 // get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
1910 //// TODO replace replacement_value with @intToPtr(?promise, 0x1) when it doesn't crash zig
1911 //IrInstruction *replacement_value = irb->exec->coro_handle;
1912 //IrInstruction *maybe_await_handle = ir_build_atomic_rmw(irb, scope, node,
1913 // promise_type_val, irb->exec->coro_awaiter_field_ptr, nullptr, replacement_value, nullptr,
1914 // AtomicRmwOp_xchg, AtomicOrderSeqCst);
1915 //ir_build_store_ptr(irb, scope, node, irb->exec->await_handle_var_ptr, maybe_await_handle);
1916 //IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_await_handle);
1917 //IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false);
1918 //return ir_build_cond_br(irb, scope, node, is_non_null, irb->exec->coro_normal_final, irb->exec->coro_early_final,
1919 // is_comptime);
1920 //// the above blocks are rendered by ir_gen after the rest of codegen
19211907 }
19221908
19231909 const Ident = union(enum) {
src-self-hosted/link.zig+1-1
......@@ -627,7 +627,7 @@ fn constructLinkerArgsWasm(ctx: *Context) void {
627627
628628fn addFnObjects(ctx: *Context) !void {
629629 // at this point it's guaranteed nobody else has this lock, so we circumvent it
630 // and avoid having to be a coroutine
630 // and avoid having to be an async function
631631 const fn_link_set = &ctx.comp.fn_link_set.private_data;
632632
633633 var it = fn_link_set.first;
src-self-hosted/main.zig+1-1
......@@ -52,7 +52,7 @@ const Command = struct {
5252
5353pub fn main() !void {
5454 // This allocator needs to be thread-safe because we use it for the event.Loop
55 // which multiplexes coroutines onto kernel threads.
55 // which multiplexes async functions onto kernel threads.
5656 // libc allocator is guaranteed to have this property.
5757 const allocator = std.heap.c_allocator;
5858
src-self-hosted/stage1.zig+2-1
......@@ -142,7 +142,8 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
142142 return Error.None;
143143}
144144
145// TODO: just use the actual self-hosted zig fmt. Until the coroutine rewrite, we use a blocking implementation.
145// TODO: just use the actual self-hosted zig fmt. Until https://github.com/ziglang/zig/issues/2377,
146// we use a blocking implementation.
146147export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {
147148 if (std.debug.runtime_safety) {
148149 fmtMain(argc, argv) catch unreachable;
src/all_types.hpp+12-12
......@@ -1265,7 +1265,7 @@ enum ZigTypeId {
12651265 ZigTypeIdBoundFn,
12661266 ZigTypeIdArgTuple,
12671267 ZigTypeIdOpaque,
1268 ZigTypeIdCoroFrame,
1268 ZigTypeIdFnFrame,
12691269 ZigTypeIdAnyFrame,
12701270 ZigTypeIdVector,
12711271 ZigTypeIdEnumLiteral,
......@@ -1281,7 +1281,7 @@ struct ZigTypeOpaque {
12811281 Buf *bare_name;
12821282};
12831283
1284struct ZigTypeCoroFrame {
1284struct ZigTypeFnFrame {
12851285 ZigFn *fn;
12861286 ZigType *locals_struct;
12871287};
......@@ -1315,7 +1315,7 @@ struct ZigType {
13151315 ZigTypeBoundFn bound_fn;
13161316 ZigTypeVector vector;
13171317 ZigTypeOpaque opaque;
1318 ZigTypeCoroFrame frame;
1318 ZigTypeFnFrame frame;
13191319 ZigTypeAnyFrame any_frame;
13201320 } data;
13211321
......@@ -1376,7 +1376,7 @@ struct ZigFn {
13761376 LLVMTypeRef raw_type_ref;
13771377 ZigLLVMDIType *raw_di_type;
13781378
1379 ZigType *frame_type; // coro frame type
1379 ZigType *frame_type;
13801380 // in the case of normal functions this is the implicit return type
13811381 // in the case of async functions this is the implicit return type according to the
13821382 // zig source code, not according to zig ir
......@@ -2368,7 +2368,7 @@ enum IrInstructionId {
23682368 IrInstructionIdSuspendFinish,
23692369 IrInstructionIdAwaitSrc,
23702370 IrInstructionIdAwaitGen,
2371 IrInstructionIdCoroResume,
2371 IrInstructionIdResume,
23722372 IrInstructionIdTestCancelRequested,
23732373 IrInstructionIdSpillBegin,
23742374 IrInstructionIdSpillEnd,
......@@ -3640,7 +3640,7 @@ struct IrInstructionAwaitGen {
36403640 IrInstruction *result_loc;
36413641};
36423642
3643struct IrInstructionCoroResume {
3643struct IrInstructionResume {
36443644 IrInstruction base;
36453645
36463646 IrInstruction *frame;
......@@ -3751,12 +3751,12 @@ static const size_t maybe_null_index = 1;
37513751static const size_t err_union_payload_index = 0;
37523752static const size_t err_union_err_index = 1;
37533753
3754// label (grep this): [coro_frame_struct_layout]
3755static const size_t coro_fn_ptr_index = 0;
3756static const size_t coro_resume_index = 1;
3757static const size_t coro_awaiter_index = 2;
3758static const size_t coro_prev_val_index = 3;
3759static const size_t coro_ret_start = 4;
3754// label (grep this): [fn_frame_struct_layout]
3755static const size_t frame_fn_ptr_index = 0;
3756static const size_t frame_resume_index = 1;
3757static const size_t frame_awaiter_index = 2;
3758static const size_t frame_prev_val_index = 3;
3759static const size_t frame_ret_start = 4;
37603760
37613761// TODO https://github.com/ziglang/zig/issues/3056
37623762// We require this to be a power of 2 so that we can use shifting rather than
src/analyze.cpp+45-45
......@@ -234,7 +234,7 @@ AstNode *type_decl_node(ZigType *type_entry) {
234234 return type_entry->data.enumeration.decl_node;
235235 case ZigTypeIdUnion:
236236 return type_entry->data.unionation.decl_node;
237 case ZigTypeIdCoroFrame:
237 case ZigTypeIdFnFrame:
238238 return type_entry->data.frame.fn->proto_node;
239239 case ZigTypeIdOpaque:
240240 case ZigTypeIdMetaType:
......@@ -271,7 +271,7 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
271271 return type_entry->data.structure.resolve_status >= status;
272272 case ZigTypeIdUnion:
273273 return type_entry->data.unionation.resolve_status >= status;
274 case ZigTypeIdCoroFrame:
274 case ZigTypeIdFnFrame:
275275 switch (status) {
276276 case ResolveStatusInvalid:
277277 zig_unreachable();
......@@ -394,18 +394,18 @@ static const char *ptr_len_to_star_str(PtrLen ptr_len) {
394394 zig_unreachable();
395395}
396396
397ZigType *get_coro_frame_type(CodeGen *g, ZigFn *fn) {
397ZigType *get_fn_frame_type(CodeGen *g, ZigFn *fn) {
398398 if (fn->frame_type != nullptr) {
399399 return fn->frame_type;
400400 }
401401
402 ZigType *entry = new_type_table_entry(ZigTypeIdCoroFrame);
402 ZigType *entry = new_type_table_entry(ZigTypeIdFnFrame);
403403 buf_resize(&entry->name, 0);
404404 buf_appendf(&entry->name, "@Frame(%s)", buf_ptr(&fn->symbol_name));
405405
406406 entry->data.frame.fn = fn;
407407
408 // Coroutine frames are always non-zero bits because they always have a resume index.
408 // Async function frames are always non-zero bits because they always have a resume index.
409409 entry->abi_size = SIZE_MAX;
410410 entry->size_in_bits = SIZE_MAX;
411411
......@@ -1108,7 +1108,7 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType
11081108 case ZigTypeIdBoundFn:
11091109 case ZigTypeIdArgTuple:
11101110 case ZigTypeIdOpaque:
1111 case ZigTypeIdCoroFrame:
1111 case ZigTypeIdFnFrame:
11121112 case ZigTypeIdAnyFrame:
11131113 add_node_error(g, source_node,
11141114 buf_sprintf("type '%s' not allowed in packed struct; no guaranteed in-memory representation",
......@@ -1198,7 +1198,7 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
11981198 case ZigTypeIdBoundFn:
11991199 case ZigTypeIdArgTuple:
12001200 case ZigTypeIdVoid:
1201 case ZigTypeIdCoroFrame:
1201 case ZigTypeIdFnFrame:
12021202 case ZigTypeIdAnyFrame:
12031203 return false;
12041204 case ZigTypeIdOpaque:
......@@ -1370,7 +1370,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
13701370 case ZigTypeIdUnion:
13711371 case ZigTypeIdFn:
13721372 case ZigTypeIdVector:
1373 case ZigTypeIdCoroFrame:
1373 case ZigTypeIdFnFrame:
13741374 case ZigTypeIdAnyFrame:
13751375 switch (type_requires_comptime(g, type_entry)) {
13761376 case ReqCompTimeNo:
......@@ -1467,7 +1467,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
14671467 case ZigTypeIdUnion:
14681468 case ZigTypeIdFn:
14691469 case ZigTypeIdVector:
1470 case ZigTypeIdCoroFrame:
1470 case ZigTypeIdFnFrame:
14711471 case ZigTypeIdAnyFrame:
14721472 switch (type_requires_comptime(g, fn_type_id.return_type)) {
14731473 case ReqCompTimeInvalid:
......@@ -3080,7 +3080,7 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
30803080 case ZigTypeIdFn:
30813081 case ZigTypeIdBoundFn:
30823082 case ZigTypeIdVector:
3083 case ZigTypeIdCoroFrame:
3083 case ZigTypeIdFnFrame:
30843084 case ZigTypeIdAnyFrame:
30853085 return type_entry;
30863086 }
......@@ -3582,7 +3582,7 @@ bool is_container(ZigType *type_entry) {
35823582 case ZigTypeIdArgTuple:
35833583 case ZigTypeIdOpaque:
35843584 case ZigTypeIdVector:
3585 case ZigTypeIdCoroFrame:
3585 case ZigTypeIdFnFrame:
35863586 case ZigTypeIdAnyFrame:
35873587 return false;
35883588 }
......@@ -3640,7 +3640,7 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {
36403640 case ZigTypeIdArgTuple:
36413641 case ZigTypeIdOpaque:
36423642 case ZigTypeIdVector:
3643 case ZigTypeIdCoroFrame:
3643 case ZigTypeIdFnFrame:
36443644 case ZigTypeIdAnyFrame:
36453645 zig_unreachable();
36463646 }
......@@ -3672,7 +3672,7 @@ bool type_is_nonnull_ptr(ZigType *type) {
36723672 return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
36733673}
36743674
3675static uint32_t get_coro_frame_align_bytes(CodeGen *g) {
3675static uint32_t get_async_frame_align_bytes(CodeGen *g) {
36763676 uint32_t a = g->pointer_size_bytes * 2;
36773677 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
36783678 if (a < 8) a = 8;
......@@ -3691,7 +3691,7 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
36913691 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html
36923692 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
36933693 } else if (ptr_type->id == ZigTypeIdAnyFrame) {
3694 return get_coro_frame_align_bytes(g);
3694 return get_async_frame_align_bytes(g);
36953695 } else {
36963696 zig_unreachable();
36973697 }
......@@ -3779,7 +3779,7 @@ bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *sour
37793779}
37803780
37813781static void resolve_async_fn_frame(CodeGen *g, ZigFn *fn) {
3782 ZigType *frame_type = get_coro_frame_type(g, fn);
3782 ZigType *frame_type = get_fn_frame_type(g, fn);
37833783 Error err;
37843784 if ((err = type_resolve(g, frame_type, ResolveStatusSizeKnown))) {
37853785 fn->anal_state = FnAnalStateInvalid;
......@@ -4218,7 +4218,7 @@ bool handle_is_ptr(ZigType *type_entry) {
42184218 return false;
42194219 case ZigTypeIdArray:
42204220 case ZigTypeIdStruct:
4221 case ZigTypeIdCoroFrame:
4221 case ZigTypeIdFnFrame:
42224222 return type_has_bits(type_entry);
42234223 case ZigTypeIdErrorUnion:
42244224 return type_has_bits(type_entry->data.error_union.payload_type);
......@@ -4463,7 +4463,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
44634463 case ZigTypeIdVector:
44644464 // TODO better hashing algorithm
44654465 return 3647867726;
4466 case ZigTypeIdCoroFrame:
4466 case ZigTypeIdFnFrame:
44674467 // TODO better hashing algorithm
44684468 return 675741936;
44694469 case ZigTypeIdAnyFrame:
......@@ -4533,7 +4533,7 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
45334533 case ZigTypeIdOpaque:
45344534 case ZigTypeIdErrorSet:
45354535 case ZigTypeIdEnum:
4536 case ZigTypeIdCoroFrame:
4536 case ZigTypeIdFnFrame:
45374537 case ZigTypeIdAnyFrame:
45384538 return false;
45394539
......@@ -4606,7 +4606,7 @@ static bool return_type_is_cacheable(ZigType *return_type) {
46064606 case ZigTypeIdEnum:
46074607 case ZigTypeIdPointer:
46084608 case ZigTypeIdVector:
4609 case ZigTypeIdCoroFrame:
4609 case ZigTypeIdFnFrame:
46104610 case ZigTypeIdAnyFrame:
46114611 return true;
46124612
......@@ -4739,7 +4739,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
47394739 case ZigTypeIdBool:
47404740 case ZigTypeIdFloat:
47414741 case ZigTypeIdErrorUnion:
4742 case ZigTypeIdCoroFrame:
4742 case ZigTypeIdFnFrame:
47434743 case ZigTypeIdAnyFrame:
47444744 return OnePossibleValueNo;
47454745 case ZigTypeIdUndefined:
......@@ -4828,7 +4828,7 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
48284828 case ZigTypeIdFloat:
48294829 case ZigTypeIdVoid:
48304830 case ZigTypeIdUnreachable:
4831 case ZigTypeIdCoroFrame:
4831 case ZigTypeIdFnFrame:
48324832 case ZigTypeIdAnyFrame:
48334833 return ReqCompTimeNo;
48344834 }
......@@ -5161,7 +5161,7 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
51615161 return fn_type;
51625162}
51635163
5164static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
5164static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
51655165 Error err;
51665166
51675167 if (frame_type->data.frame.locals_struct != nullptr)
......@@ -5231,7 +5231,7 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
52315231 if (!fn_is_async(callee))
52325232 continue;
52335233
5234 ZigType *callee_frame_type = get_coro_frame_type(g, callee);
5234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
52355235
52365236 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
52375237 alloca_gen->base.id = IrInstructionIdAllocaGen;
......@@ -5244,7 +5244,7 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
52445244 call->frame_result_loc = &alloca_gen->base;
52455245 }
52465246
5247 // label (grep this): [coro_frame_struct_layout]
5247 // label (grep this): [fn_frame_struct_layout]
52485248 ZigList<ZigType *> field_types = {};
52495249 ZigList<const char *> field_names = {};
52505250
......@@ -5366,8 +5366,8 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
53665366 return resolve_enum_zero_bits(g, ty);
53675367 } else if (ty->id == ZigTypeIdUnion) {
53685368 return resolve_union_alignment(g, ty);
5369 } else if (ty->id == ZigTypeIdCoroFrame) {
5370 return resolve_coro_frame(g, ty);
5369 } else if (ty->id == ZigTypeIdFnFrame) {
5370 return resolve_async_frame(g, ty);
53715371 }
53725372 return ErrorNone;
53735373 case ResolveStatusSizeKnown:
......@@ -5377,8 +5377,8 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
53775377 return resolve_enum_zero_bits(g, ty);
53785378 } else if (ty->id == ZigTypeIdUnion) {
53795379 return resolve_union_type(g, ty);
5380 } else if (ty->id == ZigTypeIdCoroFrame) {
5381 return resolve_coro_frame(g, ty);
5380 } else if (ty->id == ZigTypeIdFnFrame) {
5381 return resolve_async_frame(g, ty);
53825382 }
53835383 return ErrorNone;
53845384 case ResolveStatusLLVMFwdDecl:
......@@ -5573,7 +5573,7 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
55735573 return false;
55745574 }
55755575 return true;
5576 case ZigTypeIdCoroFrame:
5576 case ZigTypeIdFnFrame:
55775577 zig_panic("TODO");
55785578 case ZigTypeIdAnyFrame:
55795579 zig_panic("TODO");
......@@ -5929,7 +5929,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
59295929 buf_appendf(buf, "(args value)");
59305930 return;
59315931 }
5932 case ZigTypeIdCoroFrame:
5932 case ZigTypeIdFnFrame:
59335933 buf_appendf(buf, "(TODO: async function frame value)");
59345934 return;
59355935
......@@ -5992,7 +5992,7 @@ uint32_t type_id_hash(TypeId x) {
59925992 case ZigTypeIdFn:
59935993 case ZigTypeIdBoundFn:
59945994 case ZigTypeIdArgTuple:
5995 case ZigTypeIdCoroFrame:
5995 case ZigTypeIdFnFrame:
59965996 case ZigTypeIdAnyFrame:
59975997 zig_unreachable();
59985998 case ZigTypeIdErrorUnion:
......@@ -6042,7 +6042,7 @@ bool type_id_eql(TypeId a, TypeId b) {
60426042 case ZigTypeIdBoundFn:
60436043 case ZigTypeIdArgTuple:
60446044 case ZigTypeIdOpaque:
6045 case ZigTypeIdCoroFrame:
6045 case ZigTypeIdFnFrame:
60466046 case ZigTypeIdAnyFrame:
60476047 zig_unreachable();
60486048 case ZigTypeIdErrorUnion:
......@@ -6209,7 +6209,7 @@ static const ZigTypeId all_type_ids[] = {
62096209 ZigTypeIdBoundFn,
62106210 ZigTypeIdArgTuple,
62116211 ZigTypeIdOpaque,
6212 ZigTypeIdCoroFrame,
6212 ZigTypeIdFnFrame,
62136213 ZigTypeIdAnyFrame,
62146214 ZigTypeIdVector,
62156215 ZigTypeIdEnumLiteral,
......@@ -6274,7 +6274,7 @@ size_t type_id_index(ZigType *entry) {
62746274 return 20;
62756275 case ZigTypeIdOpaque:
62766276 return 21;
6277 case ZigTypeIdCoroFrame:
6277 case ZigTypeIdFnFrame:
62786278 return 22;
62796279 case ZigTypeIdAnyFrame:
62806280 return 23;
......@@ -6338,7 +6338,7 @@ const char *type_id_name(ZigTypeId id) {
63386338 return "Opaque";
63396339 case ZigTypeIdVector:
63406340 return "Vector";
6341 case ZigTypeIdCoroFrame:
6341 case ZigTypeIdFnFrame:
63426342 return "Frame";
63436343 case ZigTypeIdAnyFrame:
63446344 return "AnyFrame";
......@@ -6782,7 +6782,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
67826782}
67836783
67846784static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveStatus wanted_resolve_status,
6785 ZigType *coro_frame_type)
6785 ZigType *async_frame_type)
67866786{
67876787 assert(struct_type->id == ZigTypeIdStruct);
67886788 assert(struct_type->data.structure.resolve_status != ResolveStatusInvalid);
......@@ -6887,11 +6887,11 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
68876887 packed_bits_offset = next_packed_bits_offset;
68886888 } else {
68896889 LLVMTypeRef llvm_type;
6890 if (i == 0 && coro_frame_type != nullptr) {
6891 assert(coro_frame_type->id == ZigTypeIdCoroFrame);
6890 if (i == 0 && async_frame_type != nullptr) {
6891 assert(async_frame_type->id == ZigTypeIdFnFrame);
68926892 assert(field_type->id == ZigTypeIdFn);
6893 resolve_llvm_types_fn(g, coro_frame_type->data.frame.fn);
6894 llvm_type = LLVMPointerType(coro_frame_type->data.frame.fn->raw_type_ref, 0);
6893 resolve_llvm_types_fn(g, async_frame_type->data.frame.fn);
6894 llvm_type = LLVMPointerType(async_frame_type->data.frame.fn->raw_type_ref, 0);
68956895 } else {
68966896 llvm_type = get_llvm_type(g, field_type);
68976897 }
......@@ -7594,7 +7594,7 @@ void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn) {
75947594 // first "parameter" is return value
75957595 param_di_types.append(get_llvm_di_type(g, gen_return_type));
75967596
7597 ZigType *frame_type = get_coro_frame_type(g, fn);
7597 ZigType *frame_type = get_fn_frame_type(g, fn);
75987598 ZigType *ptr_type = get_pointer_to_type(g, frame_type, false);
75997599 if ((err = type_resolve(g, ptr_type, ResolveStatusLLVMFwdDecl)))
76007600 zig_unreachable();
......@@ -7634,7 +7634,7 @@ static void resolve_llvm_types_anyerror(CodeGen *g) {
76347634 get_llvm_di_type(g, g->err_tag_type), "");
76357635}
76367636
7637static void resolve_llvm_types_coro_frame(CodeGen *g, ZigType *frame_type, ResolveStatus wanted_resolve_status) {
7637static void resolve_llvm_types_async_frame(CodeGen *g, ZigType *frame_type, ResolveStatus wanted_resolve_status) {
76387638 resolve_llvm_types_struct(g, frame_type->data.frame.locals_struct, wanted_resolve_status, frame_type);
76397639 frame_type->llvm_type = frame_type->data.frame.locals_struct->llvm_type;
76407640 frame_type->llvm_di_type = frame_type->data.frame.locals_struct->llvm_di_type;
......@@ -7673,7 +7673,7 @@ static void resolve_llvm_types_any_frame(CodeGen *g, ZigType *any_frame_type, Re
76737673 ZigList<LLVMTypeRef> field_types = {};
76747674 ZigList<ZigLLVMDIType *> di_element_types = {};
76757675
7676 // label (grep this): [coro_frame_struct_layout]
7676 // label (grep this): [fn_frame_struct_layout]
76777677 field_types.append(ptr_fn_llvm_type); // fn_ptr
76787678 field_types.append(usize_type_ref); // resume_index
76797679 field_types.append(usize_type_ref); // awaiter
......@@ -7824,8 +7824,8 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r
78247824 type->abi_align, get_llvm_di_type(g, type->data.vector.elem_type), type->data.vector.len);
78257825 return;
78267826 }
7827 case ZigTypeIdCoroFrame:
7828 return resolve_llvm_types_coro_frame(g, type, wanted_resolve_status);
7827 case ZigTypeIdFnFrame:
7828 return resolve_llvm_types_async_frame(g, type, wanted_resolve_status);
78297829 case ZigTypeIdAnyFrame:
78307830 return resolve_llvm_types_any_frame(g, type, wanted_resolve_status);
78317831 }
src/analyze.hpp+1-1
......@@ -16,7 +16,7 @@ ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
1616ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node, Buf *msg);
1717void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg);
1818ZigType *new_type_table_entry(ZigTypeId id);
19ZigType *get_coro_frame_type(CodeGen *g, ZigFn *fn);
19ZigType *get_fn_frame_type(CodeGen *g, ZigFn *fn);
2020ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
2121ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
2222 bool is_volatile, PtrLen ptr_len,
src/codegen.cpp+30-32
......@@ -305,16 +305,16 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) {
305305 zig_unreachable();
306306}
307307
308// label (grep this): [coro_frame_struct_layout]
308// label (grep this): [fn_frame_struct_layout]
309309static uint32_t frame_index_trace_arg(CodeGen *g, ZigType *return_type) {
310310 // [0] *ReturnType (callee's)
311311 // [1] *ReturnType (awaiter's)
312312 // [2] ReturnType
313313 uint32_t return_field_count = type_has_bits(return_type) ? 3 : 0;
314 return coro_ret_start + return_field_count;
314 return frame_ret_start + return_field_count;
315315}
316316
317// label (grep this): [coro_frame_struct_layout]
317// label (grep this): [fn_frame_struct_layout]
318318static uint32_t frame_index_arg(CodeGen *g, ZigType *return_type) {
319319 bool have_stack_trace = codegen_fn_has_err_ret_tracing_arg(g, return_type);
320320 // [0] *StackTrace
......@@ -322,7 +322,7 @@ static uint32_t frame_index_arg(CodeGen *g, ZigType *return_type) {
322322 return frame_index_trace_arg(g, return_type) + trace_field_count;
323323}
324324
325// label (grep this): [coro_frame_struct_layout]
325// label (grep this): [fn_frame_struct_layout]
326326static uint32_t frame_index_trace_stack(CodeGen *g, FnTypeId *fn_type_id) {
327327 uint32_t result = frame_index_arg(g, fn_type_id->return_type);
328328 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
......@@ -2224,7 +2224,7 @@ static LLVMValueRef gen_resume(CodeGen *g, LLVMValueRef fn_val, LLVMValueRef tar
22242224{
22252225 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
22262226 if (fn_val == nullptr) {
2227 LLVMValueRef fn_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, coro_fn_ptr_index, "");
2227 LLVMValueRef fn_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_fn_ptr_index, "");
22282228 fn_val = LLVMBuildLoad(g->builder, fn_ptr_ptr, "");
22292229 }
22302230 if (arg_val == nullptr) {
......@@ -2373,7 +2373,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
23732373 // If the awaiter result pointer is non-null, we need to copy the result to there.
23742374 LLVMBasicBlockRef copy_block = LLVMAppendBasicBlock(g->cur_fn_val, "CopyResult");
23752375 LLVMBasicBlockRef copy_end_block = LLVMAppendBasicBlock(g->cur_fn_val, "CopyResultEnd");
2376 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, coro_ret_start + 1, "");
2376 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_ret_start + 1, "");
23772377 LLVMValueRef awaiter_ret_ptr = LLVMBuildLoad(g->builder, awaiter_ret_ptr_ptr, "");
23782378 LLVMValueRef zero_ptr = LLVMConstNull(LLVMTypeOf(awaiter_ret_ptr));
23792379 LLVMValueRef need_copy_bit = LLVMBuildICmp(g->builder, LLVMIntNE, awaiter_ret_ptr, zero_ptr, "");
......@@ -3858,7 +3858,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
38583858
38593859 if (ret_has_bits) {
38603860 // Use the result location which is inside the frame if this is an async call.
3861 ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_ret_start + 2, "");
3861 ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
38623862 }
38633863 } else {
38643864 LLVMValueRef frame_slice_ptr = ir_llvm_value(g, instruction->new_stack);
......@@ -3897,14 +3897,14 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
38973897 if (ret_has_bits) {
38983898 if (result_loc == nullptr) {
38993899 // return type is a scalar, but we still need a pointer to it. Use the async fn frame.
3900 ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_ret_start + 2, "");
3900 ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
39013901 } else {
39023902 // Use the call instruction's result location.
39033903 ret_ptr = result_loc;
39043904 }
39053905
39063906 // Store a zero in the awaiter's result ptr to indicate we do not need a copy made.
3907 LLVMValueRef awaiter_ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_ret_start + 1, "");
3907 LLVMValueRef awaiter_ret_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 1, "");
39083908 LLVMValueRef zero_ptr = LLVMConstNull(LLVMGetElementType(LLVMTypeOf(awaiter_ret_ptr)));
39093909 LLVMBuildStore(g->builder, zero_ptr, awaiter_ret_ptr);
39103910 }
......@@ -3919,19 +3919,19 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
39193919 if (instruction->is_async || callee_is_async) {
39203920 assert(frame_result_loc != nullptr);
39213921
3922 LLVMValueRef fn_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_fn_ptr_index, "");
3922 LLVMValueRef fn_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_fn_ptr_index, "");
39233923 LLVMValueRef bitcasted_fn_val = LLVMBuildBitCast(g->builder, fn_val,
39243924 LLVMGetElementType(LLVMTypeOf(fn_ptr_ptr)), "");
39253925 LLVMBuildStore(g->builder, bitcasted_fn_val, fn_ptr_ptr);
39263926
3927 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_resume_index, "");
3927 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_resume_index, "");
39283928 LLVMBuildStore(g->builder, zero, resume_index_ptr);
39293929
3930 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_awaiter_index, "");
3930 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_awaiter_index, "");
39313931 LLVMBuildStore(g->builder, awaiter_init_val, awaiter_ptr);
39323932
39333933 if (ret_has_bits) {
3934 LLVMValueRef ret_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_ret_start, "");
3934 LLVMValueRef ret_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start, "");
39353935 LLVMBuildStore(g->builder, ret_ptr, ret_ptr_ptr);
39363936 }
39373937 } else {
......@@ -4018,7 +4018,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
40184018 if (result_loc != nullptr)
40194019 return get_handle_value(g, result_loc, src_return_type, ptr_result_type);
40204020
4021 LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, coro_ret_start + 2, "");
4021 LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
40224022 return LLVMBuildLoad(g->builder, result_ptr, "");
40234023 }
40244024
......@@ -5491,7 +5491,7 @@ static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrIns
54915491
54925492 // supply null for the awaiter return pointer (no copy needed)
54935493 if (type_has_bits(result_type)) {
5494 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, coro_ret_start + 1, "");
5494 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");
54955495 LLVMBuildStore(g->builder, LLVMConstNull(LLVMGetElementType(LLVMTypeOf(awaiter_ret_ptr_ptr))),
54965496 awaiter_ret_ptr_ptr);
54975497 }
......@@ -5506,7 +5506,7 @@ static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrIns
55065506
55075507 LLVMValueRef awaiter_val = LLVMBuildPtrToInt(g->builder, g->cur_frame_ptr, usize_type_ref, "");
55085508 LLVMValueRef awaiter_ored_val = LLVMBuildOr(g->builder, awaiter_val, one, "");
5509 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, coro_awaiter_index, "");
5509 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_awaiter_index, "");
55105510
55115511 LLVMValueRef prev_val = gen_maybe_atomic_op(g, LLVMAtomicRMWBinOpXchg, awaiter_ptr, awaiter_ored_val,
55125512 LLVMAtomicOrderingRelease);
......@@ -5549,7 +5549,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
55495549 LLVMValueRef result_loc = (instruction->result_loc == nullptr) ?
55505550 nullptr : ir_llvm_value(g, instruction->result_loc);
55515551 if (type_has_bits(result_type)) {
5552 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, coro_ret_start + 1, "");
5552 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");
55535553 if (result_loc == nullptr) {
55545554 // no copy needed
55555555 LLVMBuildStore(g->builder, LLVMConstNull(LLVMGetElementType(LLVMTypeOf(awaiter_ret_ptr_ptr))),
......@@ -5570,7 +5570,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
55705570
55715571 // caller's own frame pointer
55725572 LLVMValueRef awaiter_init_val = LLVMBuildPtrToInt(g->builder, g->cur_frame_ptr, usize_type_ref, "");
5573 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, coro_awaiter_index, "");
5573 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_awaiter_index, "");
55745574 LLVMValueRef prev_val = LLVMBuildAtomicRMW(g->builder, LLVMAtomicRMWBinOpXchg, awaiter_ptr, awaiter_init_val,
55755575 LLVMAtomicOrderingRelease, g->is_single_threaded);
55765576
......@@ -5608,9 +5608,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
56085608 return nullptr;
56095609}
56105610
5611static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable,
5612 IrInstructionCoroResume *instruction)
5613{
5611static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {
56145612 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
56155613 ZigType *frame_type = instruction->frame->value.type;
56165614 assert(frame_type->id == ZigTypeIdAnyFrame);
......@@ -5921,8 +5919,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
59215919 return ir_render_suspend_begin(g, executable, (IrInstructionSuspendBegin *)instruction);
59225920 case IrInstructionIdSuspendFinish:
59235921 return ir_render_suspend_finish(g, executable, (IrInstructionSuspendFinish *)instruction);
5924 case IrInstructionIdCoroResume:
5925 return ir_render_coro_resume(g, executable, (IrInstructionCoroResume *)instruction);
5922 case IrInstructionIdResume:
5923 return ir_render_resume(g, executable, (IrInstructionResume *)instruction);
59265924 case IrInstructionIdFrameSizeGen:
59275925 return ir_render_frame_size(g, executable, (IrInstructionFrameSizeGen *)instruction);
59285926 case IrInstructionIdAwaitGen:
......@@ -6195,7 +6193,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
61956193 }
61966194 return val;
61976195 }
6198 case ZigTypeIdCoroFrame:
6196 case ZigTypeIdFnFrame:
61996197 zig_panic("TODO bit pack an async function frame");
62006198 case ZigTypeIdAnyFrame:
62016199 zig_panic("TODO bit pack an anyframe");
......@@ -6727,7 +6725,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
67276725 case ZigTypeIdArgTuple:
67286726 case ZigTypeIdOpaque:
67296727 zig_unreachable();
6730 case ZigTypeIdCoroFrame:
6728 case ZigTypeIdFnFrame:
67316729 zig_panic("TODO");
67326730 case ZigTypeIdAnyFrame:
67336731 zig_panic("TODO");
......@@ -7171,12 +7169,12 @@ static void do_code_gen(CodeGen *g) {
71717169
71727170 LLVMPositionBuilderAtEnd(g->builder, g->cur_preamble_llvm_block);
71737171 render_async_spills(g);
7174 g->cur_async_awaiter_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, coro_awaiter_index, "");
7175 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, coro_resume_index, "");
7172 g->cur_async_awaiter_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_awaiter_index, "");
7173 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_resume_index, "");
71767174 g->cur_async_resume_index_ptr = resume_index_ptr;
71777175
71787176 if (type_has_bits(fn_type_id->return_type)) {
7179 LLVMValueRef cur_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, coro_ret_start, "");
7177 LLVMValueRef cur_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_ret_start, "");
71807178 g->cur_ret_ptr = LLVMBuildLoad(g->builder, cur_ret_ptr_ptr, "");
71817179 }
71827180 if (codegen_fn_has_err_ret_tracing_arg(g, fn_type_id->return_type)) {
......@@ -7190,7 +7188,7 @@ static void do_code_gen(CodeGen *g) {
71907188 trace_field_index_stack, "");
71917189 }
71927190 g->cur_async_prev_val_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr,
7193 coro_prev_val_index, "");
7191 frame_prev_val_index, "");
71947192
71957193 LLVMValueRef resume_index = LLVMBuildLoad(g->builder, resume_index_ptr, "");
71967194 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, resume_index, bad_resume_block, 4);
......@@ -9229,7 +9227,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
92299227 case ZigTypeIdArgTuple:
92309228 case ZigTypeIdErrorUnion:
92319229 case ZigTypeIdErrorSet:
9232 case ZigTypeIdCoroFrame:
9230 case ZigTypeIdFnFrame:
92339231 case ZigTypeIdAnyFrame:
92349232 zig_unreachable();
92359233 case ZigTypeIdVoid:
......@@ -9414,7 +9412,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
94149412 case ZigTypeIdUndefined:
94159413 case ZigTypeIdNull:
94169414 case ZigTypeIdArgTuple:
9417 case ZigTypeIdCoroFrame:
9415 case ZigTypeIdFnFrame:
94189416 case ZigTypeIdAnyFrame:
94199417 zig_unreachable();
94209418 }
......@@ -9583,7 +9581,7 @@ static void gen_h_file(CodeGen *g) {
95839581 case ZigTypeIdOptional:
95849582 case ZigTypeIdFn:
95859583 case ZigTypeIdVector:
9586 case ZigTypeIdCoroFrame:
9584 case ZigTypeIdFnFrame:
95879585 case ZigTypeIdAnyFrame:
95889586 zig_unreachable();
95899587
src/ir.cpp+30-32
......@@ -321,7 +321,7 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
321321 case ZigTypeIdFn:
322322 case ZigTypeIdArgTuple:
323323 case ZigTypeIdVector:
324 case ZigTypeIdCoroFrame:
324 case ZigTypeIdFnFrame:
325325 return false;
326326 }
327327 zig_unreachable();
......@@ -1058,8 +1058,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) {
10581058 return IrInstructionIdAwaitGen;
10591059}
10601060
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroResume *) {
1062 return IrInstructionIdCoroResume;
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) {
1062 return IrInstructionIdResume;
10631063}
10641064
10651065static constexpr IrInstructionId ir_instruction_id(IrInstructionTestCancelRequested *) {
......@@ -3321,10 +3321,8 @@ static IrInstruction *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_i
33213321 return &instruction->base;
33223322}
33233323
3324static IrInstruction *ir_build_coro_resume(IrBuilder *irb, Scope *scope, AstNode *source_node,
3325 IrInstruction *frame)
3326{
3327 IrInstructionCoroResume *instruction = ir_build_instruction<IrInstructionCoroResume>(irb, scope, source_node);
3324static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {
3325 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);
33283326 instruction->base.value.type = irb->codegen->builtin_types.entry_void;
33293327 instruction->frame = frame;
33303328
......@@ -7964,7 +7962,7 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node)
79647962 if (target_inst == irb->codegen->invalid_instruction)
79657963 return irb->codegen->invalid_instruction;
79667964
7967 return ir_build_coro_resume(irb, scope, node, target_inst);
7965 return ir_build_resume(irb, scope, node, target_inst);
79687966}
79697967
79707968static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
......@@ -12223,7 +12221,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1222312221
1222412222 // *@Frame(func) to anyframe->T or anyframe
1222512223 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
12226 actual_type->data.pointer.child_type->id == ZigTypeIdCoroFrame && wanted_type->id == ZigTypeIdAnyFrame)
12224 actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame && wanted_type->id == ZigTypeIdAnyFrame)
1222712225 {
1222812226 bool ok = true;
1222912227 if (wanted_type->data.any_frame.result_type != nullptr) {
......@@ -13123,7 +13121,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1312313121 case ZigTypeIdNull:
1312413122 case ZigTypeIdErrorUnion:
1312513123 case ZigTypeIdUnion:
13126 case ZigTypeIdCoroFrame:
13124 case ZigTypeIdFnFrame:
1312713125 operator_allowed = false;
1312813126 break;
1312913127 case ZigTypeIdOptional:
......@@ -14488,7 +14486,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1448814486 case ZigTypeIdBoundFn:
1448914487 case ZigTypeIdArgTuple:
1449014488 case ZigTypeIdOpaque:
14491 case ZigTypeIdCoroFrame:
14489 case ZigTypeIdFnFrame:
1449214490 case ZigTypeIdAnyFrame:
1449314491 ir_add_error(ira, target,
1449414492 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
......@@ -14514,7 +14512,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1451414512 case ZigTypeIdArgTuple:
1451514513 case ZigTypeIdOpaque:
1451614514 case ZigTypeIdEnumLiteral:
14517 case ZigTypeIdCoroFrame:
14515 case ZigTypeIdFnFrame:
1451814516 case ZigTypeIdAnyFrame:
1451914517 ir_add_error(ira, target,
1452014518 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
......@@ -15060,7 +15058,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
1506015058 return ira->codegen->invalid_instruction;
1506115059 }
1506215060
15063 ZigType *frame_type = get_coro_frame_type(ira->codegen, fn_entry);
15061 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
1506415062 IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
1506515063 frame_type, nullptr, true, true, false);
1506615064 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) {
......@@ -16121,7 +16119,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1612116119 case ZigTypeIdFn:
1612216120 case ZigTypeIdBoundFn:
1612316121 case ZigTypeIdArgTuple:
16124 case ZigTypeIdCoroFrame:
16122 case ZigTypeIdFnFrame:
1612516123 case ZigTypeIdAnyFrame:
1612616124 return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry));
1612716125
......@@ -17910,7 +17908,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1791017908 case ZigTypeIdFn:
1791117909 case ZigTypeIdBoundFn:
1791217910 case ZigTypeIdVector:
17913 case ZigTypeIdCoroFrame:
17911 case ZigTypeIdFnFrame:
1791417912 case ZigTypeIdAnyFrame:
1791517913 {
1791617914 ResolveStatus needed_status = (align_bytes == 0) ?
......@@ -18026,7 +18024,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1802618024 case ZigTypeIdFn:
1802718025 case ZigTypeIdBoundFn:
1802818026 case ZigTypeIdVector:
18029 case ZigTypeIdCoroFrame:
18027 case ZigTypeIdFnFrame:
1803018028 case ZigTypeIdAnyFrame:
1803118029 {
1803218030 if ((err = ensure_complete_type(ira->codegen, child_type)))
......@@ -18078,7 +18076,7 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
1807818076 case ZigTypeIdUnion:
1807918077 case ZigTypeIdFn:
1808018078 case ZigTypeIdVector:
18081 case ZigTypeIdCoroFrame:
18079 case ZigTypeIdFnFrame:
1808218080 case ZigTypeIdAnyFrame:
1808318081 {
1808418082 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
......@@ -18643,7 +18641,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1864318641 case ZigTypeIdArgTuple:
1864418642 case ZigTypeIdOpaque:
1864518643 case ZigTypeIdVector:
18646 case ZigTypeIdCoroFrame:
18644 case ZigTypeIdFnFrame:
1864718645 case ZigTypeIdAnyFrame:
1864818646 ir_add_error(ira, &switch_target_instruction->base,
1864918647 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
......@@ -20500,7 +20498,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2050020498
2050120499 break;
2050220500 }
20503 case ZigTypeIdCoroFrame:
20501 case ZigTypeIdFnFrame:
2050420502 zig_panic("TODO @typeInfo for async function frames");
2050520503 }
2050620504
......@@ -22219,7 +22217,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst
2221922217 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);
2222022218 ir_assert(fn != nullptr, &instruction->base);
2222122219
22222 ZigType *frame_type = get_coro_frame_type(ira->codegen, fn);
22220 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
2222322221 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2222422222
2222522223 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
......@@ -22232,7 +22230,7 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru
2223222230 if (fn == nullptr)
2223322231 return ira->codegen->invalid_instruction;
2223422232
22235 ZigType *ty = get_coro_frame_type(ira->codegen, fn);
22233 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
2223622234 return ir_const_type(ira, &instruction->base, ty);
2223722235}
2223822236
......@@ -22293,7 +22291,7 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2229322291 case ZigTypeIdUnion:
2229422292 case ZigTypeIdFn:
2229522293 case ZigTypeIdVector:
22296 case ZigTypeIdCoroFrame:
22294 case ZigTypeIdFnFrame:
2229722295 case ZigTypeIdAnyFrame:
2229822296 {
2229922297 uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);
......@@ -23438,7 +23436,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
2343823436 zig_panic("TODO buf_write_value_bytes fn type");
2343923437 case ZigTypeIdUnion:
2344023438 zig_panic("TODO buf_write_value_bytes union type");
23441 case ZigTypeIdCoroFrame:
23439 case ZigTypeIdFnFrame:
2344223440 zig_panic("TODO buf_write_value_bytes async fn frame type");
2344323441 case ZigTypeIdAnyFrame:
2344423442 zig_panic("TODO buf_write_value_bytes anyframe type");
......@@ -23621,7 +23619,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2362123619 zig_panic("TODO buf_read_value_bytes fn type");
2362223620 case ZigTypeIdUnion:
2362323621 zig_panic("TODO buf_read_value_bytes union type");
23624 case ZigTypeIdCoroFrame:
23622 case ZigTypeIdFnFrame:
2362523623 zig_panic("TODO buf_read_value_bytes async fn frame type");
2362623624 case ZigTypeIdAnyFrame:
2362723625 zig_panic("TODO buf_read_value_bytes anyframe type");
......@@ -24674,7 +24672,7 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2467424672 IrInstruction *frame;
2467524673 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
2467624674 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
24677 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdCoroFrame)
24675 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2467824676 {
2467924677 result_type = frame_ptr->value.type->data.pointer.child_type->data.frame.fn->type_entry->data.fn.fn_type_id.return_type;
2468024678 frame = frame_ptr;
......@@ -24682,7 +24680,7 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2468224680 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);
2468324681 if (frame->value.type->id == ZigTypeIdPointer &&
2468424682 frame->value.type->data.pointer.ptr_len == PtrLenSingle &&
24685 frame->value.type->data.pointer.child_type->id == ZigTypeIdCoroFrame)
24683 frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2468624684 {
2468724685 result_type = frame->value.type->data.pointer.child_type->data.frame.fn->type_entry->data.fn.fn_type_id.return_type;
2468824686 } else if (frame->value.type->id != ZigTypeIdAnyFrame ||
......@@ -24751,7 +24749,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2475124749 return ir_finish_anal(ira, result);
2475224750}
2475324751
24754static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
24752static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {
2475524753 IrInstruction *frame_ptr = instruction->frame->child;
2475624754 if (type_is_invalid(frame_ptr->value.type))
2475724755 return ira->codegen->invalid_instruction;
......@@ -24759,7 +24757,7 @@ static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstr
2475924757 IrInstruction *frame;
2476024758 if (frame_ptr->value.type->id == ZigTypeIdPointer &&
2476124759 frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle &&
24762 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdCoroFrame)
24760 frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2476324761 {
2476424762 frame = frame_ptr;
2476524763 } else {
......@@ -24771,7 +24769,7 @@ static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstr
2477124769 if (type_is_invalid(casted_frame->value.type))
2477224770 return ira->codegen->invalid_instruction;
2477324771
24774 return ir_build_coro_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);
24772 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);
2477524773}
2477624774
2477724775static IrInstruction *ir_analyze_instruction_test_cancel_requested(IrAnalyze *ira,
......@@ -25112,8 +25110,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2511225110 return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction);
2511325111 case IrInstructionIdSuspendFinish:
2511425112 return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction);
25115 case IrInstructionIdCoroResume:
25116 return ir_analyze_instruction_coro_resume(ira, (IrInstructionCoroResume *)instruction);
25113 case IrInstructionIdResume:
25114 return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction);
2511725115 case IrInstructionIdAwaitSrc:
2511825116 return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction);
2511925117 case IrInstructionIdTestCancelRequested:
......@@ -25256,7 +25254,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2525625254 case IrInstructionIdResetResult:
2525725255 case IrInstructionIdSuspendBegin:
2525825256 case IrInstructionIdSuspendFinish:
25259 case IrInstructionIdCoroResume:
25257 case IrInstructionIdResume:
2526025258 case IrInstructionIdAwaitSrc:
2526125259 case IrInstructionIdAwaitGen:
2526225260 case IrInstructionIdSpillBegin:
src/ir_print.cpp+4-5
......@@ -1528,10 +1528,9 @@ static void ir_print_suspend_finish(IrPrint *irp, IrInstructionSuspendFinish *in
15281528 fprintf(irp->f, "@suspendFinish()");
15291529}
15301530
1531static void ir_print_coro_resume(IrPrint *irp, IrInstructionCoroResume *instruction) {
1532 fprintf(irp->f, "@coroResume(");
1531static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {
1532 fprintf(irp->f, "resume ");
15331533 ir_print_other_instruction(irp, instruction->frame);
1534 fprintf(irp->f, ")");
15351534}
15361535
15371536static void ir_print_await_src(IrPrint *irp, IrInstructionAwaitSrc *instruction) {
......@@ -2039,8 +2038,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
20392038 case IrInstructionIdSuspendFinish:
20402039 ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);
20412040 break;
2042 case IrInstructionIdCoroResume:
2043 ir_print_coro_resume(irp, (IrInstructionCoroResume *)instruction);
2041 case IrInstructionIdResume:
2042 ir_print_resume(irp, (IrInstructionResume *)instruction);
20442043 break;
20452044 case IrInstructionIdAwaitSrc:
20462045 ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);
src/zig_llvm.cpp-3
......@@ -42,7 +42,6 @@
4242#include <llvm/Support/TargetRegistry.h>
4343#include <llvm/Target/TargetMachine.h>
4444#include <llvm/Target/CodeGenCWrappers.h>
45#include <llvm/Transforms/Coroutines.h>
4645#include <llvm/Transforms/IPO.h>
4746#include <llvm/Transforms/IPO/AlwaysInliner.h>
4847#include <llvm/Transforms/IPO/PassManagerBuilder.h>
......@@ -203,8 +202,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
203202 PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);
204203 }
205204
206 addCoroutinePassesToExtensionPoints(*PMBuilder);
207
208205 // Set up the per-function pass manager.
209206 legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module);
210207 auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii);
std/event/fs.zig+3-3
......@@ -799,7 +799,7 @@ pub const WatchEventId = enum {
799799// pub fn destroy(self: *Self) void {
800800// switch (builtin.os) {
801801// .macosx, .freebsd, .netbsd => {
802// // TODO we need to cancel the coroutines before destroying the lock
802// // TODO we need to cancel the frames before destroying the lock
803803// self.os_data.table_lock.deinit();
804804// var it = self.os_data.file_table.iterator();
805805// while (it.next()) |entry| {
......@@ -1088,7 +1088,7 @@ pub const WatchEventId = enum {
10881088//
10891089// while (true) {
10901090// {
1091// // TODO only 1 beginOneEvent for the whole coroutine
1091// // TODO only 1 beginOneEvent for the whole function
10921092// self.channel.loop.beginOneEvent();
10931093// errdefer self.channel.loop.finishOneEvent();
10941094// errdefer {
......@@ -1252,7 +1252,7 @@ pub const WatchEventId = enum {
12521252
12531253const test_tmp_dir = "std_event_fs_test";
12541254
1255// TODO this test is disabled until the coroutine rewrite is finished.
1255// TODO this test is disabled until the async function rewrite is finished.
12561256//test "write a file, watch it, write it again" {
12571257// return error.SkipZigTest;
12581258// const allocator = std.heap.direct_allocator;
std/event/future.zig+1-1
......@@ -6,7 +6,7 @@ const Lock = std.event.Lock;
66const Loop = std.event.Loop;
77
88/// This is a value that starts out unavailable, until resolve() is called
9/// While it is unavailable, coroutines suspend when they try to get() it,
9/// While it is unavailable, functions suspend when they try to get() it,
1010/// and then are resumed when resolve() is called.
1111/// At this point the value remains forever available, and another resolve() is not allowed.
1212pub fn Future(comptime T: type) type {
std/event/group.zig+6-6
......@@ -7,7 +7,7 @@ const testing = std.testing;
77/// ReturnType must be `void` or `E!void`
88pub fn Group(comptime ReturnType: type) type {
99 return struct {
10 coro_stack: Stack,
10 frame_stack: Stack,
1111 alloc_stack: Stack,
1212 lock: Lock,
1313
......@@ -21,7 +21,7 @@ pub fn Group(comptime ReturnType: type) type {
2121
2222 pub fn init(loop: *Loop) Self {
2323 return Self{
24 .coro_stack = Stack.init(),
24 .frame_stack = Stack.init(),
2525 .alloc_stack = Stack.init(),
2626 .lock = Lock.init(loop),
2727 };
......@@ -29,7 +29,7 @@ pub fn Group(comptime ReturnType: type) type {
2929
3030 /// Cancel all the outstanding frames. Can be called even if wait was already called.
3131 pub fn deinit(self: *Self) void {
32 while (self.coro_stack.pop()) |node| {
32 while (self.frame_stack.pop()) |node| {
3333 cancel node.data;
3434 }
3535 while (self.alloc_stack.pop()) |node| {
......@@ -50,11 +50,11 @@ pub fn Group(comptime ReturnType: type) type {
5050
5151 /// Add a node to the group. Thread-safe. Cannot fail.
5252 /// `node.data` should be the frame handle to add to the group.
53 /// The node's memory should be in the coroutine frame of
53 /// The node's memory should be in the function frame of
5454 /// the handle that is in the node, or somewhere guaranteed to live
5555 /// at least as long.
5656 pub fn addNode(self: *Self, node: *Stack.Node) void {
57 self.coro_stack.push(node);
57 self.frame_stack.push(node);
5858 }
5959
6060 /// Wait for all the calls and promises of the group to complete.
......@@ -64,7 +64,7 @@ pub fn Group(comptime ReturnType: type) type {
6464 const held = self.lock.acquire();
6565 defer held.release();
6666
67 while (self.coro_stack.pop()) |node| {
67 while (self.frame_stack.pop()) |node| {
6868 if (Error == void) {
6969 await node.data;
7070 } else {
std/event/lock.zig+2-3
......@@ -6,7 +6,7 @@ const mem = std.mem;
66const Loop = std.event.Loop;
77
88/// Thread-safe async/await lock.
9/// coroutines which are waiting for the lock are suspended, and
9/// Functions which are waiting for the lock are suspended, and
1010/// are resumed when the lock is released, in order.
1111/// Allows only one actor to hold the lock.
1212pub const Lock = struct {
......@@ -96,8 +96,7 @@ pub const Lock = struct {
9696 suspend {
9797 self.queue.put(&my_tick_node);
9898
99 // At this point, we are in the queue, so we might have already been resumed and this coroutine
100 // frame might be destroyed. For the rest of the suspend block we cannot access the coroutine frame.
99 // At this point, we are in the queue, so we might have already been resumed.
101100
102101 // We set this bit so that later we can rely on the fact, that if queue_empty_bit is 1, some actor
103102 // will attempt to grab the lock.
std/event/locked.zig+1-1
......@@ -3,7 +3,7 @@ const Lock = std.event.Lock;
33const Loop = std.event.Loop;
44
55/// Thread-safe async/await lock that protects one piece of data.
6/// coroutines which are waiting for the lock are suspended, and
6/// Functions which are waiting for the lock are suspended, and
77/// are resumed when the lock is released, in order.
88pub fn Locked(comptime T: type) type {
99 return struct {
std/event/loop.zig+1-1
......@@ -118,7 +118,7 @@ pub const Loop = struct {
118118 }
119119
120120 /// The allocator must be thread-safe because we use it for multiplexing
121 /// coroutines onto kernel threads.
121 /// async functions onto kernel threads.
122122 /// After initialization, call run().
123123 /// TODO copy elision / named return values so that the threads referencing *Loop
124124 /// have the correct pointer value.
std/event/net.zig+7-7
......@@ -13,7 +13,7 @@ pub const Server = struct {
1313
1414 loop: *Loop,
1515 sockfd: ?i32,
16 accept_coro: ?anyframe,
16 accept_frame: ?anyframe,
1717 listen_address: std.net.Address,
1818
1919 waiting_for_emfile_node: PromiseNode,
......@@ -22,11 +22,11 @@ pub const Server = struct {
2222 const PromiseNode = std.TailQueue(anyframe).Node;
2323
2424 pub fn init(loop: *Loop) Server {
25 // TODO can't initialize handler coroutine here because we need well defined copy elision
25 // TODO can't initialize handler here because we need well defined copy elision
2626 return Server{
2727 .loop = loop,
2828 .sockfd = null,
29 .accept_coro = null,
29 .accept_frame = null,
3030 .handleRequestFn = undefined,
3131 .waiting_for_emfile_node = undefined,
3232 .listen_address = undefined,
......@@ -53,10 +53,10 @@ pub const Server = struct {
5353 try os.listen(sockfd, os.SOMAXCONN);
5454 self.listen_address = std.net.Address.initPosix(try os.getsockname(sockfd));
5555
56 self.accept_coro = async Server.handler(self);
57 errdefer cancel self.accept_coro.?;
56 self.accept_frame = async Server.handler(self);
57 errdefer cancel self.accept_frame.?;
5858
59 self.listen_resume_node.handle = self.accept_coro.?;
59 self.listen_resume_node.handle = self.accept_frame.?;
6060 try self.loop.linuxAddFd(sockfd, &self.listen_resume_node, os.EPOLLIN | os.EPOLLOUT | os.EPOLLET);
6161 errdefer self.loop.removeFd(sockfd);
6262 }
......@@ -71,7 +71,7 @@ pub const Server = struct {
7171 }
7272
7373 pub fn deinit(self: *Server) void {
74 if (self.accept_coro) |accept_coro| cancel accept_coro;
74 if (self.accept_frame) |accept_frame| cancel accept_frame;
7575 if (self.sockfd) |sockfd| os.close(sockfd);
7676 }
7777
std/event/rwlock.zig+3-5
......@@ -6,7 +6,7 @@ const mem = std.mem;
66const Loop = std.event.Loop;
77
88/// Thread-safe async/await lock.
9/// coroutines which are waiting for the lock are suspended, and
9/// Functions which are waiting for the lock are suspended, and
1010/// are resumed when the lock is released, in order.
1111/// Many readers can hold the lock at the same time; however locking for writing is exclusive.
1212/// When a read lock is held, it will not be released until the reader queue is empty.
......@@ -107,8 +107,7 @@ pub const RwLock = struct {
107107
108108 self.reader_queue.put(&my_tick_node);
109109
110 // At this point, we are in the reader_queue, so we might have already been resumed and this coroutine
111 // frame might be destroyed. For the rest of the suspend block we cannot access the coroutine frame.
110 // At this point, we are in the reader_queue, so we might have already been resumed.
112111
113112 // We set this bit so that later we can rely on the fact, that if reader_queue_empty_bit is 1,
114113 // some actor will attempt to grab the lock.
......@@ -139,8 +138,7 @@ pub const RwLock = struct {
139138
140139 self.writer_queue.put(&my_tick_node);
141140
142 // At this point, we are in the writer_queue, so we might have already been resumed and this coroutine
143 // frame might be destroyed. For the rest of the suspend block we cannot access the coroutine frame.
141 // At this point, we are in the writer_queue, so we might have already been resumed.
144142
145143 // We set this bit so that later we can rely on the fact, that if writer_queue_empty_bit is 1,
146144 // some actor will attempt to grab the lock.
std/event/rwlocked.zig+1-1
......@@ -3,7 +3,7 @@ const RwLock = std.event.RwLock;
33const Loop = std.event.Loop;
44
55/// Thread-safe async/await RW lock that protects one piece of data.
6/// coroutines which are waiting for the lock are suspended, and
6/// Functions which are waiting for the lock are suspended, and
77/// are resumed when the lock is released, in order.
88pub fn RwLocked(comptime T: type) type {
99 return struct {
std/zig/parser_test.zig+3-3
......@@ -2103,7 +2103,7 @@ test "zig fmt: inline asm" {
21032103 );
21042104}
21052105
2106test "zig fmt: coroutines" {
2106test "zig fmt: async functions" {
21072107 try testCanonical(
21082108 \\async fn simpleAsyncFn() void {
21092109 \\ const a = async a.b();
......@@ -2115,8 +2115,8 @@ test "zig fmt: coroutines" {
21152115 \\ await p;
21162116 \\}
21172117 \\
2118 \\test "coroutine suspend, resume, cancel" {
2119 \\ const p: anyframe = try async<std.debug.global_allocator> testAsyncSeq();
2118 \\test "suspend, resume, cancel" {
2119 \\ const p: anyframe = async testAsyncSeq();
21202120 \\ resume p;
21212121 \\ cancel p;
21222122 \\}