authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-08 07:41:39+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-08 07:41:39+02:00
logfc2c1883b36a6ba8c7303d12b57147656dc7dd70
tree8b68413d10d994377456b9a6a71473caa8e564d0
parent9e49652757da1946abd57a1a3af15a7bbcf8491c
parent4ba0e7d424a7c0af55c8085c659e9205560d3095
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24362 (remove async, await, usingnamespace)

remove `async` and `await` keywords; remove `usingnamespace`

84 files changed, 90 insertions(+), 3860 deletions(-)

build.zig+2-2
......@@ -460,8 +460,8 @@ pub fn build(b: *std.Build) !void {
460460 .skip_linux = skip_linux,
461461 .skip_llvm = skip_llvm,
462462 .skip_libc = skip_libc,
463 // 2923515904 was observed on an x86_64-linux-gnu host.
464 .max_rss = 3100000000,
463 // 3888779264 was observed on an x86_64-linux-gnu host.
464 .max_rss = 4000000000,
465465 }));
466466
467467 test_modules_step.dependOn(tests.addModuleTests(b, .{
doc/langref.html.in+8-87
......@@ -3842,37 +3842,6 @@ void do_a_thing(struct Foo *foo) {
38423842 {#header_close#}
38433843 {#header_close#}
38443844
3845 {#header_open|usingnamespace#}
3846 <p>
3847 {#syntax#}usingnamespace{#endsyntax#} is a declaration that mixes all the public
3848 declarations of the operand, which must be a {#link|struct#}, {#link|union#}, {#link|enum#},
3849 or {#link|opaque#}, into the namespace:
3850 </p>
3851 {#code|test_usingnamespace.zig#}
3852
3853 <p>
3854 {#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
3855 API of a file or package. For example, one might have <code class="file">c.zig</code> with all of the
3856 {#link|C imports|Import from C Header File#}:
3857 </p>
3858 {#syntax_block|zig|c.zig#}
3859pub usingnamespace @cImport({
3860 @cInclude("epoxy/gl.h");
3861 @cInclude("GLFW/glfw3.h");
3862 @cDefine("STBI_ONLY_PNG", "");
3863 @cDefine("STBI_NO_STDIO", "");
3864 @cInclude("stb_image.h");
3865});
3866 {#end_syntax_block#}
3867 <p>
3868 The above example demonstrates using {#syntax#}pub{#endsyntax#} to qualify the
3869 {#syntax#}usingnamespace{#endsyntax#} additionally makes the imported declarations
3870 {#syntax#}pub{#endsyntax#}. This can be used to forward declarations, giving precise control
3871 over what declarations a given file exposes.
3872 </p>
3873 {#header_close#}
3874
3875
38763845 {#header_open|comptime#}
38773846 <p>
38783847 Zig places importance on the concept of whether an expression is known at compile-time.
......@@ -4279,16 +4248,9 @@ pub fn print(self: *Writer, arg0: []const u8, arg1: i32) !void {
42794248 {#header_close#}
42804249
42814250 {#header_open|Async Functions#}
4282 <p>Async functions regressed with the release of 0.11.0. Their future in
4283 the Zig language is unclear due to multiple unsolved problems:</p>
4284 <ul>
4285 <li>LLVM's lack of ability to optimize them.</li>
4286 <li>Third-party debuggers' lack of ability to debug them.</li>
4287 <li><a href="https://github.com/ziglang/zig/issues/5913">The cancellation problem</a>.</li>
4288 <li>Async function pointers preventing the stack size from being known.</li>
4289 </ul>
4290 <p>These problems are surmountable, but it will take time. The Zig team
4291 is currently focused on other priorities.</p>
4251 <p>Async functions regressed with the release of 0.11.0. The current plan is to
4252 reintroduce them as a lower level primitive that powers I/O implementations.</p>
4253 <p>Tracking issue: <a href="https://github.com/ziglang/zig/issues/23446">Proposal: stackless coroutines as low-level primitives</a></p>
42924254 {#header_close#}
42934255
42944256 {#header_open|Builtin Functions|2col#}
......@@ -6552,7 +6514,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
65526514 </p>
65536515 <ul>
65546516 <li>If a call to {#syntax#}@import{#endsyntax#} is analyzed, the file being imported is analyzed.</li>
6555 <li>If a type (including a file) is analyzed, all {#syntax#}comptime{#endsyntax#}, {#syntax#}usingnamespace{#endsyntax#}, and {#syntax#}export{#endsyntax#} declarations within it are analyzed.</li>
6517 <li>If a type (including a file) is analyzed, all {#syntax#}comptime{#endsyntax#} and {#syntax#}export{#endsyntax#} declarations within it are analyzed.</li>
65566518 <li>If a type (including a file) is analyzed, and the compilation is for a {#link|test|Zig Test#}, and the module the type is within is the root module of the compilation, then all {#syntax#}test{#endsyntax#} declarations within it are also analyzed.</li>
65576519 <li>If a reference to a named declaration (i.e. a usage of it) is analyzed, the declaration being referenced is analyzed. Declarations are order-independent, so this reference may be above or below the declaration being referenced, or even in another file entirely.</li>
65586520 </ul>
......@@ -7372,29 +7334,6 @@ fn readU32Be() u32 {}
73727334 </ul>
73737335 </td>
73747336 </tr>
7375 <tr>
7376 <th scope="row">
7377 <pre>{#syntax#}async{#endsyntax#}</pre>
7378 </th>
7379 <td>
7380 {#syntax#}async{#endsyntax#} can be used before a function call to get a pointer to the function's frame when it suspends.
7381 <ul>
7382 <li>See also {#link|Async Functions#}</li>
7383 </ul>
7384 </td>
7385 </tr>
7386 <tr>
7387 <th scope="row">
7388 <pre>{#syntax#}await{#endsyntax#}</pre>
7389 </th>
7390 <td>
7391 {#syntax#}await{#endsyntax#} can be used to suspend the current function until the frame provided after the {#syntax#}await{#endsyntax#} completes.
7392 {#syntax#}await{#endsyntax#} copies the value returned from the target function's frame to the caller.
7393 <ul>
7394 <li>See also {#link|Async Functions#}</li>
7395 </ul>
7396 </td>
7397 </tr>
73987337 <tr>
73997338 <th scope="row">
74007339 <pre>{#syntax#}break{#endsyntax#}</pre>
......@@ -7812,18 +7751,6 @@ fn readU32Be() u32 {}
78127751 </ul>
78137752 </td>
78147753 </tr>
7815 <tr>
7816 <th scope="row">
7817 <pre>{#syntax#}usingnamespace{#endsyntax#}</pre>
7818 </th>
7819 <td>
7820 {#syntax#}usingnamespace{#endsyntax#} is a top-level declaration that imports all the public declarations of the operand,
7821 which must be a struct, union, or enum, into the current scope.
7822 <ul>
7823 <li>See also {#link|usingnamespace#}</li>
7824 </ul>
7825 </td>
7826 </tr>
78277754 <tr>
78287755 <th scope="row">
78297756 <pre>{#syntax#}var{#endsyntax#}</pre>
......@@ -7893,7 +7820,6 @@ ComptimeDecl <- KEYWORD_comptime Block
78937820Decl
78947821 <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)
78957822 / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? GlobalVarDecl
7896 / KEYWORD_usingnamespace Expr SEMICOLON
78977823
78987824FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
78997825
......@@ -8006,8 +7932,7 @@ TypeExpr <- PrefixTypeOp* ErrorUnionExpr
80067932ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)?
80077933
80087934SuffixExpr
8009 <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
8010 / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
7935 <- PrimaryTypeExpr (SuffixOp / FnCallArguments)*
80117936
80127937PrimaryTypeExpr
80137938 <- BUILTINIDENTIFIER FnCallArguments
......@@ -8183,7 +8108,6 @@ PrefixOp
81838108 / MINUSPERCENT
81848109 / AMPERSAND
81858110 / KEYWORD_try
8186 / KEYWORD_await
81878111
81888112PrefixTypeOp
81898113 <- QUESTIONMARK
......@@ -8404,8 +8328,6 @@ KEYWORD_and <- 'and' end_of_word
84048328KEYWORD_anyframe <- 'anyframe' end_of_word
84058329KEYWORD_anytype <- 'anytype' end_of_word
84068330KEYWORD_asm <- 'asm' end_of_word
8407KEYWORD_async <- 'async' end_of_word
8408KEYWORD_await <- 'await' end_of_word
84098331KEYWORD_break <- 'break' end_of_word
84108332KEYWORD_callconv <- 'callconv' end_of_word
84118333KEYWORD_catch <- 'catch' end_of_word
......@@ -8442,14 +8364,13 @@ KEYWORD_threadlocal <- 'threadlocal' end_of_word
84428364KEYWORD_try <- 'try' end_of_word
84438365KEYWORD_union <- 'union' end_of_word
84448366KEYWORD_unreachable <- 'unreachable' end_of_word
8445KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
84468367KEYWORD_var <- 'var' end_of_word
84478368KEYWORD_volatile <- 'volatile' end_of_word
84488369KEYWORD_while <- 'while' end_of_word
84498370
84508371keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
8451 / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm / KEYWORD_async
8452 / KEYWORD_await / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
8372 / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm
8373 / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
84538374 / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer
84548375 / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
84558376 / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
......@@ -8458,7 +8379,7 @@ keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
84588379 / KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
84598380 / KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test
84608381 / KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable
8461 / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
8382 / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
84628383 {#end_syntax_block#}
84638384 {#header_close#}
84648385 {#header_open|Zen#}
doc/langref/test_usingnamespace.zig deleted-8
......@@ -1,8 +0,0 @@
1test "using std namespace" {
2 const S = struct {
3 usingnamespace @import("std");
4 };
5 try S.testing.expect(true);
6}
7
8// test
lib/compiler/reduce/Walk.zig-12
......@@ -160,12 +160,6 @@ fn walkMember(w: *Walk, decl: Ast.Node.Index) Error!void {
160160 try walkExpression(w, decl);
161161 },
162162
163 .@"usingnamespace" => {
164 try w.transformations.append(.{ .delete_node = decl });
165 const expr = ast.nodeData(decl).node;
166 try walkExpression(w, expr);
167 },
168
169163 .global_var_decl,
170164 .local_var_decl,
171165 .simple_var_decl,
......@@ -335,7 +329,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
335329 .address_of,
336330 .@"try",
337331 .@"resume",
338 .@"await",
339332 .deref,
340333 => {
341334 return walkExpression(w, ast.nodeData(node).node);
......@@ -379,12 +372,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
379372
380373 .call_one,
381374 .call_one_comma,
382 .async_call_one,
383 .async_call_one_comma,
384375 .call,
385376 .call_comma,
386 .async_call,
387 .async_call_comma,
388377 => {
389378 var buf: [1]Ast.Node.Index = undefined;
390379 return walkCall(w, ast.fullCall(&buf, node).?);
......@@ -525,7 +514,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
525514 .local_var_decl => unreachable,
526515 .simple_var_decl => unreachable,
527516 .aligned_var_decl => unreachable,
528 .@"usingnamespace" => unreachable,
529517 .test_decl => unreachable,
530518 .asm_output => unreachable,
531519 .asm_input => unreachable,
lib/docs/wasm/Walk.zig-11
......@@ -238,12 +238,8 @@ pub const File = struct {
238238
239239 .call_one,
240240 .call_one_comma,
241 .async_call_one,
242 .async_call_one_comma,
243241 .call,
244242 .call_comma,
245 .async_call,
246 .async_call_comma,
247243 => {
248244 var buf: [1]Ast.Node.Index = undefined;
249245 return categorize_call(file_index, node, ast.fullCall(&buf, node).?);
......@@ -571,7 +567,6 @@ fn struct_decl(
571567 },
572568
573569 .@"comptime",
574 .@"usingnamespace",
575570 => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).node),
576571
577572 .test_decl => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).opt_token_and_node[1]),
......@@ -643,7 +638,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
643638 const ast = w.file.get_ast();
644639 switch (ast.nodeTag(node)) {
645640 .root => unreachable, // Top-level declaration.
646 .@"usingnamespace" => unreachable, // Top-level declaration.
647641 .test_decl => unreachable, // Top-level declaration.
648642 .container_field_init => unreachable, // Top-level declaration.
649643 .container_field_align => unreachable, // Top-level declaration.
......@@ -743,7 +737,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
743737 .@"comptime",
744738 .@"nosuspend",
745739 .@"suspend",
746 .@"await",
747740 .@"resume",
748741 .@"try",
749742 => try expr(w, scope, parent_decl, ast.nodeData(node).node),
......@@ -806,12 +799,8 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
806799
807800 .call_one,
808801 .call_one_comma,
809 .async_call_one,
810 .async_call_one_comma,
811802 .call,
812803 .call_comma,
813 .async_call,
814 .async_call_comma,
815804 => {
816805 var buf: [1]Ast.Node.Index = undefined;
817806 const full = ast.fullCall(&buf, node).?;
lib/docs/wasm/html_render.zig-3
......@@ -101,8 +101,6 @@ pub fn fileSourceHtml(
101101 .keyword_align,
102102 .keyword_and,
103103 .keyword_asm,
104 .keyword_async,
105 .keyword_await,
106104 .keyword_break,
107105 .keyword_catch,
108106 .keyword_comptime,
......@@ -139,7 +137,6 @@ pub fn fileSourceHtml(
139137 .keyword_try,
140138 .keyword_union,
141139 .keyword_unreachable,
142 .keyword_usingnamespace,
143140 .keyword_var,
144141 .keyword_volatile,
145142 .keyword_allowzero,
lib/std/Build/Module.zig+1-1
......@@ -572,7 +572,7 @@ pub fn appendZigProcessFlags(
572572 try zig_args.append(switch (unwind_tables) {
573573 .none => "-fno-unwind-tables",
574574 .sync => "-funwind-tables",
575 .@"async" => "-fasync-unwind-tables",
575 .async => "-fasync-unwind-tables",
576576 });
577577 }
578578
lib/std/Target.zig+1-1
......@@ -1691,7 +1691,7 @@ pub const Cpu = struct {
16911691 pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch {
16921692 return switch (cc) {
16931693 .auto,
1694 .@"async",
1694 .async,
16951695 .naked,
16961696 .@"inline",
16971697 => unreachable,
lib/std/builtin.zig+3-14
......@@ -199,8 +199,6 @@ pub const CallingConvention = union(enum(u8)) {
199199 pub const C: CallingConvention = .c;
200200 /// Deprecated; use `.naked`.
201201 pub const Naked: CallingConvention = .naked;
202 /// Deprecated; use `.@"async"`.
203 pub const Async: CallingConvention = .@"async";
204202 /// Deprecated; use `.@"inline"`.
205203 pub const Inline: CallingConvention = .@"inline";
206204 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.
......@@ -248,7 +246,7 @@ pub const CallingConvention = union(enum(u8)) {
248246 /// The calling convention of a function that can be called with `async` syntax. An `async` call
249247 /// of a runtime-known function must target a function with this calling convention.
250248 /// Comptime-known functions with other calling conventions may be coerced to this one.
251 @"async",
249 async,
252250
253251 /// Functions with this calling convention have no prologue or epilogue, making the function
254252 /// uncallable in regular Zig code. This can be useful when integrating with assembly.
......@@ -851,7 +849,7 @@ pub const LinkMode = enum {
851849pub const UnwindTables = enum {
852850 none,
853851 sync,
854 @"async",
852 async,
855853};
856854
857855/// This data structure is used by the Zig language code generation and
......@@ -866,32 +864,23 @@ pub const WasiExecModel = enum {
866864pub const CallModifier = enum {
867865 /// Equivalent to function call syntax.
868866 auto,
869
870 /// Equivalent to async keyword used with function call syntax.
871 async_kw,
872
873867 /// Prevents tail call optimization. This guarantees that the return
874868 /// address will point to the callsite, as opposed to the callsite's
875869 /// callsite. If the call is otherwise required to be tail-called
876870 /// or inlined, a compile error is emitted instead.
877871 never_tail,
878
879872 /// Guarantees that the call will not be inlined. If the call is
880873 /// otherwise required to be inlined, a compile error is emitted instead.
881874 never_inline,
882
883875 /// Asserts that the function call will not suspend. This allows a
884876 /// non-async function to call an async function.
885 no_async,
886
877 no_suspend,
887878 /// Guarantees that the call will be generated with tail call optimization.
888879 /// If this is not possible, a compile error is emitted instead.
889880 always_tail,
890
891881 /// Guarantees that the call will be inlined at the callsite.
892882 /// If this is not possible, a compile error is emitted instead.
893883 always_inline,
894
895884 /// Evaluates the call at compile-time. If the call cannot be completed at
896885 /// compile-time, a compile error is emitted instead.
897886 compile_time,
lib/std/zig/Ast.zig+7-78
......@@ -606,7 +606,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
606606 .negation_wrap,
607607 .address_of,
608608 .@"try",
609 .@"await",
610609 .optional_type,
611610 .@"switch",
612611 .switch_comma,
......@@ -756,27 +755,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
756755 return i - end_offset;
757756 },
758757
759 .@"usingnamespace" => {
760 const main_token: TokenIndex = tree.nodeMainToken(n);
761 const has_visib_token = tree.isTokenPrecededByTags(main_token, &.{.keyword_pub});
762 end_offset += @intFromBool(has_visib_token);
763 return main_token - end_offset;
764 },
765
766 .async_call_one,
767 .async_call_one_comma,
768 => {
769 end_offset += 1; // async token
770 n = tree.nodeData(n).node_and_opt_node[0];
771 },
772
773 .async_call,
774 .async_call_comma,
775 => {
776 end_offset += 1; // async token
777 n = tree.nodeData(n).node_and_extra[0];
778 },
779
780758 .container_field_init,
781759 .container_field_align,
782760 .container_field,
......@@ -896,14 +874,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
896874 while (true) switch (tree.nodeTag(n)) {
897875 .root => return @intCast(tree.tokens.len - 1),
898876
899 .@"usingnamespace",
900877 .bool_not,
901878 .negation,
902879 .bit_not,
903880 .negation_wrap,
904881 .address_of,
905882 .@"try",
906 .@"await",
907883 .optional_type,
908884 .@"suspend",
909885 .@"resume",
......@@ -1022,7 +998,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1022998 };
1023999 },
10241000
1025 .call, .async_call => {
1001 .call => {
10261002 _, const extra_index = tree.nodeData(n).node_and_extra;
10271003 const params = tree.extraData(extra_index, Node.SubRange);
10281004 assert(params.start != params.end);
......@@ -1041,7 +1017,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
10411017 }
10421018 },
10431019 .call_comma,
1044 .async_call_comma,
10451020 .tagged_union_enum_tag_trailing,
10461021 => {
10471022 _, const extra_index = tree.nodeData(n).node_and_extra;
......@@ -1122,7 +1097,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
11221097 n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member
11231098 },
11241099 .call_one,
1125 .async_call_one,
11261100 => {
11271101 _, const first_param = tree.nodeData(n).node_and_opt_node;
11281102 end_offset += 1; // for the rparen
......@@ -1271,7 +1245,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
12711245 n = first_element;
12721246 },
12731247 .call_one_comma,
1274 .async_call_one_comma,
12751248 .struct_init_one_comma,
12761249 => {
12771250 _, const first_field = tree.nodeData(n).node_and_opt_node;
......@@ -1988,21 +1961,21 @@ pub fn forFull(tree: Ast, node: Node.Index) full.For {
19881961pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call {
19891962 const fn_expr, const first_param = tree.nodeData(node).node_and_opt_node;
19901963 const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param});
1991 return tree.fullCallComponents(.{
1964 return .{ .ast = .{
19921965 .lparen = tree.nodeMainToken(node),
19931966 .fn_expr = fn_expr,
19941967 .params = params,
1995 });
1968 } };
19961969}
19971970
19981971pub fn callFull(tree: Ast, node: Node.Index) full.Call {
19991972 const fn_expr, const extra_index = tree.nodeData(node).node_and_extra;
20001973 const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index);
2001 return tree.fullCallComponents(.{
1974 return .{ .ast = .{
20021975 .lparen = tree.nodeMainToken(node),
20031976 .fn_expr = fn_expr,
20041977 .params = params,
2005 });
1978 } };
20061979}
20071980
20081981fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl {
......@@ -2336,18 +2309,6 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For {
23362309 return result;
23372310}
23382311
2339fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call {
2340 var result: full.Call = .{
2341 .ast = info,
2342 .async_token = null,
2343 };
2344 const first_token = tree.firstToken(info.fn_expr);
2345 if (tree.isTokenPrecededByTags(first_token, &.{.keyword_async})) {
2346 result.async_token = first_token - 1;
2347 }
2348 return result;
2349}
2350
23512312pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl {
23522313 return switch (tree.nodeTag(node)) {
23532314 .global_var_decl => tree.globalVarDecl(node),
......@@ -2488,8 +2449,8 @@ pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm {
24882449
24892450pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call {
24902451 return switch (tree.nodeTag(node)) {
2491 .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),
2492 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node),
2452 .call, .call_comma => tree.callFull(node),
2453 .call_one, .call_one_comma => tree.callOne(buffer, node),
24932454 else => null,
24942455 };
24952456}
......@@ -2882,7 +2843,6 @@ pub const full = struct {
28822843
28832844 pub const Call = struct {
28842845 ast: Components,
2885 async_token: ?TokenIndex,
28862846
28872847 pub const Components = struct {
28882848 lparen: TokenIndex,
......@@ -3065,12 +3025,6 @@ pub const Node = struct {
30653025 ///
30663026 /// The `main_token` field is the first token for the source file.
30673027 root,
3068 /// `usingnamespace expr;`.
3069 ///
3070 /// The `data` field is a `.node` to expr.
3071 ///
3072 /// The `main_token` field is the `usingnamespace` token.
3073 @"usingnamespace",
30743028 /// `test {}`,
30753029 /// `test "name" {}`,
30763030 /// `test identifier {}`.
......@@ -3301,8 +3255,6 @@ pub const Node = struct {
33013255 address_of,
33023256 /// `try expr`. The `main_token` field is the `try` token.
33033257 @"try",
3304 /// `await expr`. The `main_token` field is the `await` token.
3305 @"await",
33063258 /// `?expr`. The `main_token` field is the `?` token.
33073259 optional_type,
33083260 /// `[lhs]rhs`. The `main_token` field is the `[` token.
......@@ -3498,17 +3450,6 @@ pub const Node = struct {
34983450 /// Same as `call_one` except there is known to be a trailing comma
34993451 /// before the final rparen.
35003452 call_one_comma,
3501 /// `async a(b)`, `async a()`.
3502 ///
3503 /// The `data` field is a `.node_and_opt_node`:
3504 /// 1. a `Node.Index` to the function expression.
3505 /// 2. a `Node.OptionalIndex` to the first argument, if any.
3506 ///
3507 /// The `main_token` field is the `(` token.
3508 async_call_one,
3509 /// Same as `async_call_one` except there is known to be a trailing
3510 /// comma before the final rparen.
3511 async_call_one_comma,
35123453 /// `a(b, c, d)`.
35133454 ///
35143455 /// The `data` field is a `.node_and_extra`:
......@@ -3521,18 +3462,6 @@ pub const Node = struct {
35213462 /// Same as `call` except there is known to be a trailing comma before
35223463 /// the final rparen.
35233464 call_comma,
3524 /// `async a(b, c, d)`.
3525 ///
3526 /// The `data` field is a `.node_and_extra`:
3527 /// 1. a `Node.Index` to the function expression.
3528 /// 2. a `ExtraIndex` to a `SubRange` that stores a `Node.Index` for
3529 /// each argument.
3530 ///
3531 /// The `main_token` field is the `(` token.
3532 async_call,
3533 /// Same as `async_call` except there is known to be a trailing comma
3534 /// before the final rparen.
3535 async_call_comma,
35363465 /// `switch(a) {}`.
35373466 ///
35383467 /// The `data` field is a `.node_and_extra`:
lib/std/zig/AstGen.zig+2-157
......@@ -442,7 +442,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
442442 const tree = astgen.tree;
443443 switch (tree.nodeTag(node)) {
444444 .root => unreachable,
445 .@"usingnamespace" => unreachable,
446445 .test_decl => unreachable,
447446 .global_var_decl => unreachable,
448447 .local_var_decl => unreachable,
......@@ -510,12 +509,8 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
510509 .number_literal,
511510 .call,
512511 .call_comma,
513 .async_call,
514 .async_call_comma,
515512 .call_one,
516513 .call_one_comma,
517 .async_call_one,
518 .async_call_one_comma,
519514 .unreachable_literal,
520515 .@"return",
521516 .@"if",
......@@ -547,7 +542,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
547542 .merge_error_sets,
548543 .switch_range,
549544 .for_range,
550 .@"await",
551545 .bit_not,
552546 .negation,
553547 .negation_wrap,
......@@ -642,7 +636,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
642636
643637 switch (tree.nodeTag(node)) {
644638 .root => unreachable, // Top-level declaration.
645 .@"usingnamespace" => unreachable, // Top-level declaration.
646639 .test_decl => unreachable, // Top-level declaration.
647640 .container_field_init => unreachable, // Top-level declaration.
648641 .container_field_align => unreachable, // Top-level declaration.
......@@ -836,12 +829,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
836829
837830 .call_one,
838831 .call_one_comma,
839 .async_call_one,
840 .async_call_one_comma,
841832 .call,
842833 .call_comma,
843 .async_call,
844 .async_call_comma,
845834 => {
846835 var buf: [1]Ast.Node.Index = undefined;
847836 return callExpr(gz, scope, ri, .none, node, tree.fullCall(&buf, node).?);
......@@ -1114,7 +1103,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
11141103
11151104 .@"nosuspend" => return nosuspendExpr(gz, scope, ri, node),
11161105 .@"suspend" => return suspendExpr(gz, scope, node),
1117 .@"await" => return awaitExpr(gz, scope, ri, node),
11181106 .@"resume" => return resumeExpr(gz, scope, ri, node),
11191107
11201108 .@"try" => return tryExpr(gz, scope, ri, node, tree.nodeData(node).node),
......@@ -1259,33 +1247,6 @@ fn suspendExpr(
12591247 return suspend_inst.toRef();
12601248}
12611249
1262fn awaitExpr(
1263 gz: *GenZir,
1264 scope: *Scope,
1265 ri: ResultInfo,
1266 node: Ast.Node.Index,
1267) InnerError!Zir.Inst.Ref {
1268 const astgen = gz.astgen;
1269 const tree = astgen.tree;
1270 const rhs_node = tree.nodeData(node).node;
1271
1272 if (gz.suspend_node.unwrap()) |suspend_node| {
1273 return astgen.failNodeNotes(node, "cannot await inside suspend block", .{}, &[_]u32{
1274 try astgen.errNoteNode(suspend_node, "suspend block here", .{}),
1275 });
1276 }
1277 const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node);
1278 const result = if (gz.nosuspend_node != .none)
1279 try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{
1280 .node = gz.nodeIndexToRelative(node),
1281 .operand = operand,
1282 })
1283 else
1284 try gz.addUnNode(.@"await", operand, node);
1285
1286 return rvalue(gz, ri, result, node);
1287}
1288
12891250fn resumeExpr(
12901251 gz: *GenZir,
12911252 scope: *Scope,
......@@ -2853,7 +2814,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
28532814 .tag_name,
28542815 .type_name,
28552816 .frame_type,
2856 .frame_size,
28572817 .int_from_float,
28582818 .float_from_int,
28592819 .ptr_from_int,
......@@ -2887,7 +2847,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
28872847 .min,
28882848 .c_import,
28892849 .@"resume",
2890 .@"await",
28912850 .ret_err_value_code,
28922851 .ret_ptr,
28932852 .ret_type,
......@@ -4739,69 +4698,6 @@ fn comptimeDecl(
47394698 });
47404699}
47414700
4742fn usingnamespaceDecl(
4743 astgen: *AstGen,
4744 gz: *GenZir,
4745 scope: *Scope,
4746 wip_members: *WipMembers,
4747 node: Ast.Node.Index,
4748) InnerError!void {
4749 const tree = astgen.tree;
4750
4751 const old_hasher = astgen.src_hasher;
4752 defer astgen.src_hasher = old_hasher;
4753 astgen.src_hasher = std.zig.SrcHasher.init(.{});
4754 astgen.src_hasher.update(tree.getNodeSource(node));
4755 astgen.src_hasher.update(std.mem.asBytes(&astgen.source_column));
4756
4757 const type_expr = tree.nodeData(node).node;
4758 const is_pub = tree.isTokenPrecededByTags(tree.nodeMainToken(node), &.{.keyword_pub});
4759
4760 // Up top so the ZIR instruction index marks the start range of this
4761 // top-level declaration.
4762 const decl_inst = try gz.makeDeclaration(node);
4763 wip_members.nextDecl(decl_inst);
4764 astgen.advanceSourceCursorToNode(node);
4765
4766 // This is just needed for the `setDeclaration` call.
4767 var dummy_gz = gz.makeSubBlock(scope);
4768 defer dummy_gz.unstack();
4769
4770 var usingnamespace_gz: GenZir = .{
4771 .is_comptime = true,
4772 .decl_node_index = node,
4773 .decl_line = astgen.source_line,
4774 .parent = scope,
4775 .astgen = astgen,
4776 .instructions = gz.instructions,
4777 .instructions_top = gz.instructions.items.len,
4778 };
4779 defer usingnamespace_gz.unstack();
4780
4781 const decl_column = astgen.source_column;
4782
4783 const namespace_inst = try typeExpr(&usingnamespace_gz, &usingnamespace_gz.base, type_expr);
4784 _ = try usingnamespace_gz.addBreak(.break_inline, decl_inst, namespace_inst);
4785
4786 var hash: std.zig.SrcHash = undefined;
4787 astgen.src_hasher.final(&hash);
4788 try setDeclaration(decl_inst, .{
4789 .src_hash = hash,
4790 .src_line = usingnamespace_gz.decl_line,
4791 .src_column = decl_column,
4792 .kind = .@"usingnamespace",
4793 .name = .empty,
4794 .is_pub = is_pub,
4795 .is_threadlocal = false,
4796 .linkage = .normal,
4797 .type_gz = &dummy_gz,
4798 .align_gz = &dummy_gz,
4799 .linksection_gz = &dummy_gz,
4800 .addrspace_gz = &dummy_gz,
4801 .value_gz = &usingnamespace_gz,
4802 });
4803}
4804
48054701fn testDecl(
48064702 astgen: *AstGen,
48074703 gz: *GenZir,
......@@ -5971,23 +5867,6 @@ fn containerMember(
59715867 },
59725868 };
59735869 },
5974 .@"usingnamespace" => {
5975 const prev_decl_index = wip_members.decl_index;
5976 astgen.usingnamespaceDecl(gz, scope, wip_members, member_node) catch |err| switch (err) {
5977 error.OutOfMemory => return error.OutOfMemory,
5978 error.AnalysisFail => {
5979 wip_members.decl_index = prev_decl_index;
5980 try addFailedDeclaration(
5981 wip_members,
5982 gz,
5983 .@"usingnamespace",
5984 .empty,
5985 member_node,
5986 tree.isTokenPrecededByTags(tree.nodeMainToken(member_node), &.{.keyword_pub}),
5987 );
5988 },
5989 };
5990 },
59915870 .test_decl => {
59925871 const prev_decl_index = wip_members.decl_index;
59935872 // We need to have *some* decl here so that the decl count matches what's expected.
......@@ -9501,7 +9380,6 @@ fn builtinCall(
95019380 .tag_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .tag_name),
95029381 .type_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .type_name),
95039382 .Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),
9504 .frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size),
95059383
95069384 .int_from_float => return typeCast(gz, scope, ri, node, params[0], .int_from_float, builtin_name),
95079385 .float_from_int => return typeCast(gz, scope, ri, node, params[0], .float_from_int, builtin_name),
......@@ -9767,16 +9645,6 @@ fn builtinCall(
97679645 });
97689646 return rvalue(gz, ri, result, node);
97699647 },
9770 .async_call => {
9771 const result = try gz.addExtendedPayload(.builtin_async_call, Zir.Inst.AsyncCall{
9772 .node = gz.nodeIndexToRelative(node),
9773 .frame_buffer = try expr(gz, scope, .{ .rl = .none }, params[0]),
9774 .result_ptr = try expr(gz, scope, .{ .rl = .none }, params[1]),
9775 .fn_ptr = try expr(gz, scope, .{ .rl = .none }, params[2]),
9776 .args = try expr(gz, scope, .{ .rl = .none }, params[3]),
9777 });
9778 return rvalue(gz, ri, result, node);
9779 },
97809648 .Vector => {
97819649 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{
97829650 .lhs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .type),
......@@ -10175,11 +10043,8 @@ fn callExpr(
1017510043
1017610044 const callee = try calleeExpr(gz, scope, ri.rl, override_decl_literal_type, call.ast.fn_expr);
1017710045 const modifier: std.builtin.CallModifier = blk: {
10178 if (call.async_token != null) {
10179 break :blk .async_kw;
10180 }
1018110046 if (gz.nosuspend_node != .none) {
10182 break :blk .no_async;
10047 break :blk .no_suspend;
1018310048 }
1018410049 break :blk .auto;
1018510050 };
......@@ -10451,7 +10316,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
1045110316 while (true) {
1045210317 switch (tree.nodeTag(node)) {
1045310318 .root,
10454 .@"usingnamespace",
1045510319 .test_decl,
1045610320 .switch_case,
1045710321 .switch_case_inline,
......@@ -10483,12 +10347,8 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
1048310347 .switch_comma,
1048410348 .call_one,
1048510349 .call_one_comma,
10486 .async_call_one,
10487 .async_call_one_comma,
1048810350 .call,
1048910351 .call_comma,
10490 .async_call,
10491 .async_call_comma,
1049210352 => return .maybe,
1049310353
1049410354 .@"return",
......@@ -10613,7 +10473,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
1061310473
1061410474 // Forward the question to the LHS sub-expression.
1061510475 .@"try",
10616 .@"await",
1061710476 .@"comptime",
1061810477 .@"nosuspend",
1061910478 => node = tree.nodeData(node).node,
......@@ -10664,7 +10523,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
1066410523 while (true) {
1066510524 switch (tree.nodeTag(node)) {
1066610525 .root,
10667 .@"usingnamespace",
1066810526 .test_decl,
1066910527 .switch_case,
1067010528 .switch_case_inline,
......@@ -10803,12 +10661,8 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
1080310661 .switch_comma,
1080410662 .call_one,
1080510663 .call_one_comma,
10806 .async_call_one,
10807 .async_call_one_comma,
1080810664 .call,
1080910665 .call_comma,
10810 .async_call,
10811 .async_call_comma,
1081210666 .block_two,
1081310667 .block_two_semicolon,
1081410668 .block,
......@@ -10826,7 +10680,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
1082610680
1082710681 // Forward the question to the LHS sub-expression.
1082810682 .@"try",
10829 .@"await",
1083010683 .@"comptime",
1083110684 .@"nosuspend",
1083210685 => node = tree.nodeData(node).node,
......@@ -10908,7 +10761,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
1090810761 while (true) {
1090910762 switch (tree.nodeTag(node)) {
1091010763 .root,
10911 .@"usingnamespace",
1091210764 .test_decl,
1091310765 .switch_case,
1091410766 .switch_case_inline,
......@@ -11047,12 +10899,8 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
1104710899 .switch_comma,
1104810900 .call_one,
1104910901 .call_one_comma,
11050 .async_call_one,
11051 .async_call_one_comma,
1105210902 .call,
1105310903 .call_comma,
11054 .async_call,
11055 .async_call_comma,
1105610904 .block_two,
1105710905 .block_two_semicolon,
1105810906 .block,
......@@ -11079,7 +10927,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
1107910927
1108010928 // Forward the question to the LHS sub-expression.
1108110929 .@"try",
11082 .@"await",
1108310930 .@"comptime",
1108410931 .@"nosuspend",
1108510932 => node = tree.nodeData(node).node,
......@@ -13586,7 +13433,7 @@ fn scanContainer(
1358613433 break :blk .{ .decl, ident };
1358713434 },
1358813435
13589 .@"comptime", .@"usingnamespace" => {
13436 .@"comptime" => {
1359013437 decl_count += 1;
1359113438 continue;
1359213439 },
......@@ -13964,7 +13811,6 @@ const DeclarationName = union(enum) {
1396413811 decltest: Ast.TokenIndex,
1396513812 unnamed_test,
1396613813 @"comptime",
13967 @"usingnamespace",
1396813814};
1396913815
1397013816fn addFailedDeclaration(
......@@ -14054,7 +13900,6 @@ fn setDeclaration(
1405413900 .@"test" => .@"test",
1405513901 .decltest => .decltest,
1405613902 .@"comptime" => .@"comptime",
14057 .@"usingnamespace" => if (args.is_pub) .pub_usingnamespace else .@"usingnamespace",
1405813903 .@"const" => switch (args.linkage) {
1405913904 .normal => if (args.is_pub) id: {
1406013905 if (has_special_body) break :id .pub_const;
lib/std/zig/AstRlAnnotate.zig-22
......@@ -165,10 +165,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
165165 }
166166 return false;
167167 },
168 .@"usingnamespace" => {
169 _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only);
170 return false;
171 },
172168 .test_decl => {
173169 _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none);
174170 return false;
......@@ -334,12 +330,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
334330
335331 .call_one,
336332 .call_one_comma,
337 .async_call_one,
338 .async_call_one_comma,
339333 .call,
340334 .call_comma,
341 .async_call,
342 .async_call_comma,
343335 => {
344336 var buf: [1]Ast.Node.Index = undefined;
345337 const full = tree.fullCall(&buf, node).?;
......@@ -353,11 +345,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
353345 .call,
354346 .call_comma,
355347 => false, // TODO: once function calls are passed result locations this will change
356 .async_call_one,
357 .async_call_one_comma,
358 .async_call,
359 .async_call_comma,
360 => ri.have_ptr, // always use result ptr for frames
361348 else => unreachable,
362349 };
363350 },
......@@ -503,7 +490,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
503490 return false;
504491 },
505492 .@"try",
506 .@"await",
507493 .@"nosuspend",
508494 => return astrl.expr(tree.nodeData(node).node, block, ri),
509495 .grouped_expression,
......@@ -948,7 +934,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
948934 .tag_name,
949935 .type_name,
950936 .Frame,
951 .frame_size,
952937 .int_from_float,
953938 .float_from_int,
954939 .ptr_from_int,
......@@ -1079,13 +1064,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
10791064 _ = try astrl.expr(args[3], block, ResultInfo.none);
10801065 return false;
10811066 },
1082 .async_call => {
1083 _ = try astrl.expr(args[0], block, ResultInfo.none);
1084 _ = try astrl.expr(args[1], block, ResultInfo.none);
1085 _ = try astrl.expr(args[2], block, ResultInfo.none);
1086 _ = try astrl.expr(args[3], block, ResultInfo.none);
1087 return false; // buffer passed as arg for frame data
1088 },
10891067 .Vector => {
10901068 _ = try astrl.expr(args[0], block, ResultInfo.type_only);
10911069 _ = try astrl.expr(args[1], block, ResultInfo.type_only);
lib/std/zig/BuiltinFn.zig-16
......@@ -4,7 +4,6 @@ pub const Tag = enum {
44 align_cast,
55 align_of,
66 as,
7 async_call,
87 atomic_load,
98 atomic_rmw,
109 atomic_store,
......@@ -55,7 +54,6 @@ pub const Tag = enum {
5554 frame,
5655 Frame,
5756 frame_address,
58 frame_size,
5957 has_decl,
6058 has_field,
6159 import,
......@@ -184,13 +182,6 @@ pub const list = list: {
184182 .param_count = 2,
185183 },
186184 },
187 .{
188 "@asyncCall",
189 .{
190 .tag = .async_call,
191 .param_count = 4,
192 },
193 },
194185 .{
195186 "@atomicLoad",
196187 .{
......@@ -550,13 +541,6 @@ pub const list = list: {
550541 .illegal_outside_function = true,
551542 },
552543 },
553 .{
554 "@frameSize",
555 .{
556 .tag = .frame_size,
557 .param_count = 1,
558 },
559 },
560544 .{
561545 "@hasDecl",
562546 .{
lib/std/zig/Parse.zig+2-90
......@@ -359,16 +359,6 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
359359 }
360360 trailing = p.tokenTag(p.tok_i - 1) == .semicolon;
361361 },
362 .keyword_usingnamespace => {
363 const opt_node = try p.expectUsingNamespaceRecoverable();
364 if (opt_node) |node| {
365 if (field_state == .seen) {
366 field_state = .{ .end = node };
367 }
368 try p.scratch.append(p.gpa, node);
369 }
370 trailing = p.tokenTag(p.tok_i - 1) == .semicolon;
371 },
372362 .keyword_const,
373363 .keyword_var,
374364 .keyword_threadlocal,
......@@ -496,7 +486,6 @@ fn findNextContainerMember(p: *Parse) void {
496486 .keyword_extern,
497487 .keyword_inline,
498488 .keyword_noinline,
499 .keyword_usingnamespace,
500489 .keyword_threadlocal,
501490 .keyword_const,
502491 .keyword_var,
......@@ -601,7 +590,6 @@ fn expectTestDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
601590/// Decl
602591/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)
603592/// / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
604/// / KEYWORD_usingnamespace Expr SEMICOLON
605593fn expectTopLevelDecl(p: *Parse) !?Node.Index {
606594 const extern_export_inline_token = p.nextToken();
607595 var is_extern: bool = false;
......@@ -664,10 +652,7 @@ fn expectTopLevelDecl(p: *Parse) !?Node.Index {
664652 if (expect_var_or_fn) {
665653 return p.fail(.expected_var_decl_or_fn);
666654 }
667 if (p.tokenTag(p.tok_i) != .keyword_usingnamespace) {
668 return p.fail(.expected_pub_item);
669 }
670 return try p.expectUsingNamespace();
655 return p.fail(.expected_pub_item);
671656}
672657
673658fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
......@@ -680,27 +665,6 @@ fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
680665 };
681666}
682667
683fn expectUsingNamespace(p: *Parse) !Node.Index {
684 const usingnamespace_token = p.assertToken(.keyword_usingnamespace);
685 const expr = try p.expectExpr();
686 try p.expectSemicolon(.expected_semi_after_decl, false);
687 return p.addNode(.{
688 .tag = .@"usingnamespace",
689 .main_token = usingnamespace_token,
690 .data = .{ .node = expr },
691 });
692}
693
694fn expectUsingNamespaceRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
695 return p.expectUsingNamespace() catch |err| switch (err) {
696 error.OutOfMemory => return error.OutOfMemory,
697 error.ParseError => {
698 p.findNextContainerMember();
699 return null;
700 },
701 };
702}
703
704668/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
705669fn parseFnProto(p: *Parse) !?Node.Index {
706670 const fn_token = p.eatToken(.keyword_fn) orelse return null;
......@@ -1688,7 +1652,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
16881652/// / MINUSPERCENT
16891653/// / AMPERSAND
16901654/// / KEYWORD_try
1691/// / KEYWORD_await
16921655fn parsePrefixExpr(p: *Parse) Error!?Node.Index {
16931656 const tag: Node.Tag = switch (p.tokenTag(p.tok_i)) {
16941657 .bang => .bool_not,
......@@ -1697,7 +1660,6 @@ fn parsePrefixExpr(p: *Parse) Error!?Node.Index {
16971660 .minus_percent => .negation_wrap,
16981661 .ampersand => .address_of,
16991662 .keyword_try => .@"try",
1700 .keyword_await => .@"await",
17011663 else => return p.parsePrimaryExpr(),
17021664 };
17031665 return try p.addNode(.{
......@@ -2385,62 +2347,12 @@ fn parseErrorUnionExpr(p: *Parse) !?Node.Index {
23852347}
23862348
23872349/// SuffixExpr
2388/// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
2389/// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
2350/// <- PrimaryTypeExpr (SuffixOp / FnCallArguments)*
23902351///
23912352/// FnCallArguments <- LPAREN ExprList RPAREN
23922353///
23932354/// ExprList <- (Expr COMMA)* Expr?
23942355fn parseSuffixExpr(p: *Parse) !?Node.Index {
2395 if (p.eatToken(.keyword_async)) |_| {
2396 var res = try p.expectPrimaryTypeExpr();
2397 while (true) {
2398 res = try p.parseSuffixOp(res) orelse break;
2399 }
2400 const lparen = p.eatToken(.l_paren) orelse {
2401 try p.warn(.expected_param_list);
2402 return res;
2403 };
2404 const scratch_top = p.scratch.items.len;
2405 defer p.scratch.shrinkRetainingCapacity(scratch_top);
2406 while (true) {
2407 if (p.eatToken(.r_paren)) |_| break;
2408 const param = try p.expectExpr();
2409 try p.scratch.append(p.gpa, param);
2410 switch (p.tokenTag(p.tok_i)) {
2411 .comma => p.tok_i += 1,
2412 .r_paren => {
2413 p.tok_i += 1;
2414 break;
2415 },
2416 .colon, .r_brace, .r_bracket => return p.failExpected(.r_paren),
2417 // Likely just a missing comma; give error but continue parsing.
2418 else => try p.warn(.expected_comma_after_arg),
2419 }
2420 }
2421 const comma = (p.tokenTag(p.tok_i - 2)) == .comma;
2422 const params = p.scratch.items[scratch_top..];
2423 if (params.len <= 1) {
2424 return try p.addNode(.{
2425 .tag = if (comma) .async_call_one_comma else .async_call_one,
2426 .main_token = lparen,
2427 .data = .{ .node_and_opt_node = .{
2428 res,
2429 if (params.len >= 1) params[0].toOptional() else .none,
2430 } },
2431 });
2432 } else {
2433 return try p.addNode(.{
2434 .tag = if (comma) .async_call_comma else .async_call,
2435 .main_token = lparen,
2436 .data = .{ .node_and_extra = .{
2437 res,
2438 try p.addExtra(try p.listToSpan(params)),
2439 } },
2440 });
2441 }
2442 }
2443
24442356 var res = try p.parsePrimaryTypeExpr() orelse return null;
24452357 while (true) {
24462358 const opt_suffix_op = try p.parseSuffixOp(res);
lib/std/zig/Zir.zig+4-43
......@@ -899,8 +899,6 @@ pub const Inst = struct {
899899 type_name,
900900 /// Implement builtin `@Frame`. Uses `un_node`.
901901 frame_type,
902 /// Implement builtin `@frameSize`. Uses `un_node`.
903 frame_size,
904902
905903 /// Implements the `@intFromFloat` builtin.
906904 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
......@@ -1044,7 +1042,6 @@ pub const Inst = struct {
10441042
10451043 /// Implements `resume` syntax. Uses `un_node` field.
10461044 @"resume",
1047 @"await",
10481045
10491046 /// A defer statement.
10501047 /// Uses the `defer` union field.
......@@ -1241,7 +1238,6 @@ pub const Inst = struct {
12411238 .tag_name,
12421239 .type_name,
12431240 .frame_type,
1244 .frame_size,
12451241 .int_from_float,
12461242 .float_from_int,
12471243 .ptr_from_int,
......@@ -1279,7 +1275,6 @@ pub const Inst = struct {
12791275 .min,
12801276 .c_import,
12811277 .@"resume",
1282 .@"await",
12831278 .ret_err_value_code,
12841279 .extended,
12851280 .ret_ptr,
......@@ -1526,7 +1521,6 @@ pub const Inst = struct {
15261521 .tag_name,
15271522 .type_name,
15281523 .frame_type,
1529 .frame_size,
15301524 .int_from_float,
15311525 .float_from_int,
15321526 .ptr_from_int,
......@@ -1560,7 +1554,6 @@ pub const Inst = struct {
15601554 .min,
15611555 .c_import,
15621556 .@"resume",
1563 .@"await",
15641557 .ret_err_value_code,
15651558 .@"break",
15661559 .break_inline,
......@@ -1791,7 +1784,6 @@ pub const Inst = struct {
17911784 .tag_name = .un_node,
17921785 .type_name = .un_node,
17931786 .frame_type = .un_node,
1794 .frame_size = .un_node,
17951787
17961788 .int_from_float = .pl_node,
17971789 .float_from_int = .pl_node,
......@@ -1852,7 +1844,6 @@ pub const Inst = struct {
18521844 .make_ptr_const = .un_node,
18531845
18541846 .@"resume" = .un_node,
1855 .@"await" = .un_node,
18561847
18571848 .@"defer" = .@"defer",
18581849 .defer_err_code = .defer_err_code,
......@@ -2016,8 +2007,6 @@ pub const Inst = struct {
20162007 /// Implements the `@errorCast` builtin.
20172008 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
20182009 error_cast,
2019 /// `operand` is payload index to `UnNode`.
2020 await_nosuspend,
20212010 /// Implements `@breakpoint`.
20222011 /// `operand` is `src_node: Ast.Node.Offset`.
20232012 breakpoint,
......@@ -2038,9 +2027,6 @@ pub const Inst = struct {
20382027 /// `operand` is payload index to `Reify`.
20392028 /// `small` contains `NameStrategy`.
20402029 reify,
2041 /// Implements the `@asyncCall` builtin.
2042 /// `operand` is payload index to `AsyncCall`.
2043 builtin_async_call,
20442030 /// Implements the `@cmpxchgStrong` and `@cmpxchgWeak` builtins.
20452031 /// `small` 0=>weak 1=>strong
20462032 /// `operand` is payload index to `Cmpxchg`.
......@@ -2689,7 +2675,6 @@ pub const Inst = struct {
26892675 @"test",
26902676 decltest,
26912677 @"comptime",
2692 @"usingnamespace",
26932678 @"const",
26942679 @"var",
26952680 };
......@@ -2706,7 +2691,7 @@ pub const Inst = struct {
27062691 src_column: u32,
27072692
27082693 kind: Kind,
2709 /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"`, `.@"usingnamespace"`.
2694 /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"`
27102695 name: NullTerminatedString,
27112696 /// Always `false` for `kind` of `unnamed_test`, `.@"test"`, `.decltest`, `.@"comptime"`.
27122697 is_pub: bool,
......@@ -2737,9 +2722,6 @@ pub const Inst = struct {
27372722 decltest,
27382723 @"comptime",
27392724
2740 @"usingnamespace",
2741 pub_usingnamespace,
2742
27432725 const_simple,
27442726 const_typed,
27452727 @"const",
......@@ -2776,8 +2758,6 @@ pub const Inst = struct {
27762758 return switch (id) {
27772759 .unnamed_test,
27782760 .@"comptime",
2779 .@"usingnamespace",
2780 .pub_usingnamespace,
27812761 => false,
27822762 else => true,
27832763 };
......@@ -2802,8 +2782,6 @@ pub const Inst = struct {
28022782 .@"test",
28032783 .decltest,
28042784 .@"comptime",
2805 .@"usingnamespace",
2806 .pub_usingnamespace,
28072785 => false, // these constructs are untyped
28082786 .const_simple,
28092787 .pub_const_simple,
......@@ -2835,8 +2813,6 @@ pub const Inst = struct {
28352813 .@"test",
28362814 .decltest,
28372815 .@"comptime",
2838 .@"usingnamespace",
2839 .pub_usingnamespace,
28402816 => false, // these constructs are untyped
28412817 .const_simple,
28422818 .const_typed,
......@@ -2879,7 +2855,6 @@ pub const Inst = struct {
28792855 .@"test" => .@"test",
28802856 .decltest => .decltest,
28812857 .@"comptime" => .@"comptime",
2882 .@"usingnamespace", .pub_usingnamespace => .@"usingnamespace",
28832858 .const_simple,
28842859 .const_typed,
28852860 .@"const",
......@@ -2913,7 +2888,6 @@ pub const Inst = struct {
29132888
29142889 pub fn isPub(id: Id) bool {
29152890 return switch (id) {
2916 .pub_usingnamespace,
29172891 .pub_const_simple,
29182892 .pub_const_typed,
29192893 .pub_const,
......@@ -2949,8 +2923,7 @@ pub const Inst = struct {
29492923
29502924 pub const Name = enum(u32) {
29512925 @"comptime" = std.math.maxInt(u32),
2952 @"usingnamespace" = std.math.maxInt(u32) - 1,
2953 unnamed_test = std.math.maxInt(u32) - 2,
2926 unnamed_test = std.math.maxInt(u32) - 1,
29542927 /// Other values are `NullTerminatedString` values, i.e. index into
29552928 /// `string_bytes`. If the byte referenced is 0, the decl is a named
29562929 /// test, and the actual name begins at the following byte.
......@@ -2958,13 +2931,13 @@ pub const Inst = struct {
29582931
29592932 pub fn isNamedTest(name: Name, zir: Zir) bool {
29602933 return switch (name) {
2961 .@"comptime", .@"usingnamespace", .unnamed_test => false,
2934 .@"comptime", .unnamed_test => false,
29622935 _ => zir.string_bytes[@intFromEnum(name)] == 0,
29632936 };
29642937 }
29652938 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {
29662939 switch (name) {
2967 .@"comptime", .@"usingnamespace", .unnamed_test => return null,
2940 .@"comptime", .unnamed_test => return null,
29682941 _ => {},
29692942 }
29702943 const idx: u32 = @intFromEnum(name);
......@@ -3771,14 +3744,6 @@ pub const Inst = struct {
37713744 b: Ref,
37723745 };
37733746
3774 pub const AsyncCall = struct {
3775 node: Ast.Node.Offset,
3776 frame_buffer: Ref,
3777 result_ptr: Ref,
3778 fn_ptr: Ref,
3779 args: Ref,
3780 };
3781
37823747 /// Trailing: inst: Index // for every body_len
37833748 pub const Param = struct {
37843749 /// Null-terminated string index.
......@@ -4297,7 +4262,6 @@ fn findTrackableInner(
42974262 .tag_name,
42984263 .type_name,
42994264 .frame_type,
4300 .frame_size,
43014265 .int_from_float,
43024266 .float_from_int,
43034267 .ptr_from_int,
......@@ -4337,7 +4301,6 @@ fn findTrackableInner(
43374301 .resolve_inferred_alloc,
43384302 .make_ptr_const,
43394303 .@"resume",
4340 .@"await",
43414304 .save_err_ret_index,
43424305 .restore_err_ret_index_unconditional,
43434306 .restore_err_ret_index_fn_entry,
......@@ -4380,14 +4343,12 @@ fn findTrackableInner(
43804343 .prefetch,
43814344 .set_float_mode,
43824345 .error_cast,
4383 .await_nosuspend,
43844346 .breakpoint,
43854347 .disable_instrumentation,
43864348 .disable_intrinsics,
43874349 .select,
43884350 .int_from_error,
43894351 .error_from_int,
4390 .builtin_async_call,
43914352 .cmpxchg,
43924353 .c_va_arg,
43934354 .c_va_copy,
lib/std/zig/ZonGen.zig-6
......@@ -100,7 +100,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
100100
101101 switch (tree.nodeTag(node)) {
102102 .root => unreachable,
103 .@"usingnamespace" => unreachable,
104103 .test_decl => unreachable,
105104 .container_field_init => unreachable,
106105 .container_field_align => unreachable,
......@@ -204,12 +203,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
204203
205204 .call_one,
206205 .call_one_comma,
207 .async_call_one,
208 .async_call_one_comma,
209206 .call,
210207 .call_comma,
211 .async_call,
212 .async_call_comma,
213208 .@"return",
214209 .if_simple,
215210 .@"if",
......@@ -226,7 +221,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
226221 .switch_comma,
227222 .@"nosuspend",
228223 .@"suspend",
229 .@"await",
230224 .@"resume",
231225 .@"try",
232226 .unreachable_literal,
lib/std/zig/llvm/Builder.zig+2-2
......@@ -1521,9 +1521,9 @@ pub const Attribute = union(Kind) {
15211521 pub const UwTable = enum(u32) {
15221522 none,
15231523 sync,
1524 @"async",
1524 async,
15251525
1526 pub const default = UwTable.@"async";
1526 pub const default = UwTable.async;
15271527 };
15281528
15291529 pub const VScaleRange = packed struct(u32) {
lib/std/zig/parser_test.zig-139
......@@ -341,15 +341,6 @@ test "zig fmt: nosuspend block" {
341341 );
342342}
343343
344test "zig fmt: nosuspend await" {
345 try testCanonical(
346 \\fn foo() void {
347 \\ x = nosuspend await y;
348 \\}
349 \\
350 );
351}
352
353344test "zig fmt: container declaration, single line" {
354345 try testCanonical(
355346 \\const X = struct { foo: i32 };
......@@ -1093,18 +1084,6 @@ test "zig fmt: block in slice expression" {
10931084 );
10941085}
10951086
1096test "zig fmt: async function" {
1097 try testCanonical(
1098 \\pub const Server = struct {
1099 \\ handleRequestFn: fn (*Server, *const std.net.Address, File) callconv(.@"async") void,
1100 \\};
1101 \\test "hi" {
1102 \\ var ptr: fn (i32) callconv(.@"async") void = @ptrCast(other);
1103 \\}
1104 \\
1105 );
1106}
1107
11081087test "zig fmt: whitespace fixes" {
11091088 try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n",
11101089 \\test "" {
......@@ -1549,17 +1528,6 @@ test "zig fmt: spaces around slice operator" {
15491528 );
15501529}
15511530
1552test "zig fmt: async call in if condition" {
1553 try testCanonical(
1554 \\comptime {
1555 \\ if (async b()) {
1556 \\ a();
1557 \\ }
1558 \\}
1559 \\
1560 );
1561}
1562
15631531test "zig fmt: 2nd arg multiline string" {
15641532 try testCanonical(
15651533 \\comptime {
......@@ -3946,27 +3914,6 @@ test "zig fmt: inline asm" {
39463914 );
39473915}
39483916
3949test "zig fmt: async functions" {
3950 try testCanonical(
3951 \\fn simpleAsyncFn() void {
3952 \\ const a = async a.b();
3953 \\ x += 1;
3954 \\ suspend {}
3955 \\ x += 1;
3956 \\ suspend {}
3957 \\ const p: anyframe->void = async simpleAsyncFn() catch unreachable;
3958 \\ await p;
3959 \\}
3960 \\
3961 \\test "suspend, resume, await" {
3962 \\ const p: anyframe = async testAsyncSeq();
3963 \\ resume p;
3964 \\ await p;
3965 \\}
3966 \\
3967 );
3968}
3969
39703917test "zig fmt: nosuspend" {
39713918 try testCanonical(
39723919 \\const a = nosuspend foo();
......@@ -3989,14 +3936,6 @@ test "zig fmt: Block after if" {
39893936 );
39903937}
39913938
3992test "zig fmt: usingnamespace" {
3993 try testCanonical(
3994 \\usingnamespace @import("std");
3995 \\pub usingnamespace @import("std");
3996 \\
3997 );
3998}
3999
40003939test "zig fmt: string identifier" {
40013940 try testCanonical(
40023941 \\const @"a b" = @"c d".@"e f";
......@@ -5140,17 +5079,6 @@ test "zig fmt: line comment after multiline single expr if statement with multil
51405079 );
51415080}
51425081
5143test "zig fmt: respect extra newline between fn and pub usingnamespace" {
5144 try testCanonical(
5145 \\fn foo() void {
5146 \\ bar();
5147 \\}
5148 \\
5149 \\pub usingnamespace baz;
5150 \\
5151 );
5152}
5153
51545082test "zig fmt: respect extra newline between switch items" {
51555083 try testCanonical(
51565084 \\const a = switch (b) {
......@@ -5719,34 +5647,6 @@ test "zig fmt: canonicalize symbols (primitive types)" {
57195647 );
57205648}
57215649
5722// Never unescape names spelled like keywords.
5723test "zig fmt: canonicalize symbols (keywords)" {
5724 try testCanonical(
5725 \\const @"enum" = struct {
5726 \\ @"error": @"struct" = true,
5727 \\ const @"struct" = bool;
5728 \\};
5729 \\
5730 \\fn @"usingnamespace"(@"union": @"enum") error{@"try"}!void {
5731 \\ var @"struct" = @"union";
5732 \\ @"struct".@"error" = false;
5733 \\ if (@"struct".@"error") {
5734 \\ return @"usingnamespace"(.{ .@"error" = false });
5735 \\ } else {
5736 \\ return error.@"try";
5737 \\ }
5738 \\}
5739 \\
5740 \\test @"usingnamespace" {
5741 \\ try @"usingnamespace"(.{});
5742 \\ _ = @"return": {
5743 \\ break :@"return" 4;
5744 \\ };
5745 \\}
5746 \\
5747 );
5748}
5749
57505650test "zig fmt: no space before newline before multiline string" {
57515651 try testCanonical(
57525652 \\const S = struct {
......@@ -6181,29 +6081,6 @@ test "recovery: missing return type" {
61816081 });
61826082}
61836083
6184test "recovery: continue after invalid decl" {
6185 try testError(
6186 \\fn foo {
6187 \\ inline;
6188 \\}
6189 \\pub test "" {
6190 \\ async a & b;
6191 \\}
6192 , &[_]Error{
6193 .expected_token,
6194 .expected_pub_item,
6195 .expected_param_list,
6196 });
6197 try testError(
6198 \\threadlocal test "" {
6199 \\ @a & b;
6200 \\}
6201 , &[_]Error{
6202 .expected_var_decl,
6203 .expected_param_list,
6204 });
6205}
6206
62076084test "recovery: invalid extern/inline" {
62086085 try testError(
62096086 \\inline test "" { a & b; }
......@@ -6232,22 +6109,6 @@ test "recovery: missing semicolon" {
62326109 });
62336110}
62346111
6235test "recovery: invalid container members" {
6236 try testError(
6237 \\usingnamespace;
6238 \\@foo()+
6239 \\@bar()@,
6240 \\while (a == 2) { test "" {}}
6241 \\test "" {
6242 \\ a & b
6243 \\}
6244 , &[_]Error{
6245 .expected_expr,
6246 .expected_comma_after_field,
6247 .expected_semi_after_stmt,
6248 });
6249}
6250
62516112// TODO after https://github.com/ziglang/zig/issues/35 is implemented,
62526113// we should be able to recover from this *at any indentation level*,
62536114// reporting a parse error and yet also parsing all the decls even
lib/std/zig/render.zig-20
......@@ -262,17 +262,6 @@ fn renderMember(
262262 return renderToken(r, tree.lastToken(decl) + 1, space); // semicolon
263263 },
264264
265 .@"usingnamespace" => {
266 const main_token = tree.nodeMainToken(decl);
267 const expr = tree.nodeData(decl).node;
268 if (tree.isTokenPrecededByTags(main_token, &.{.keyword_pub})) {
269 try renderToken(r, main_token - 1, .space); // pub
270 }
271 try renderToken(r, main_token, .space); // usingnamespace
272 try renderExpression(r, expr, .none);
273 return renderToken(r, tree.lastToken(expr) + 1, space); // ;
274 },
275
276265 .global_var_decl,
277266 .local_var_decl,
278267 .simple_var_decl,
......@@ -591,7 +580,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
591580
592581 .@"try",
593582 .@"resume",
594 .@"await",
595583 => {
596584 try renderToken(r, tree.nodeMainToken(node), .space);
597585 return renderExpression(r, tree.nodeData(node).node, space);
......@@ -635,12 +623,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
635623
636624 .call_one,
637625 .call_one_comma,
638 .async_call_one,
639 .async_call_one_comma,
640626 .call,
641627 .call_comma,
642 .async_call,
643 .async_call_comma,
644628 => {
645629 var buf: [1]Ast.Node.Index = undefined;
646630 return renderCall(r, tree.fullCall(&buf, node).?, space);
......@@ -882,7 +866,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
882866 .local_var_decl => unreachable,
883867 .simple_var_decl => unreachable,
884868 .aligned_var_decl => unreachable,
885 .@"usingnamespace" => unreachable,
886869 .test_decl => unreachable,
887870 .asm_output => unreachable,
888871 .asm_input => unreachable,
......@@ -2551,9 +2534,6 @@ fn renderCall(
25512534 call: Ast.full.Call,
25522535 space: Space,
25532536) Error!void {
2554 if (call.async_token) |async_token| {
2555 try renderToken(r, async_token, .space);
2556 }
25572537 try renderExpression(r, call.ast.fn_expr, .none);
25582538 try renderParamList(r, call.ast.lparen, call.ast.params, space);
25592539}
lib/std/zig/tokenizer.zig-9
......@@ -17,8 +17,6 @@ pub const Token = struct {
1717 .{ "anyframe", .keyword_anyframe },
1818 .{ "anytype", .keyword_anytype },
1919 .{ "asm", .keyword_asm },
20 .{ "async", .keyword_async },
21 .{ "await", .keyword_await },
2220 .{ "break", .keyword_break },
2321 .{ "callconv", .keyword_callconv },
2422 .{ "catch", .keyword_catch },
......@@ -55,7 +53,6 @@ pub const Token = struct {
5553 .{ "try", .keyword_try },
5654 .{ "union", .keyword_union },
5755 .{ "unreachable", .keyword_unreachable },
58 .{ "usingnamespace", .keyword_usingnamespace },
5956 .{ "var", .keyword_var },
6057 .{ "volatile", .keyword_volatile },
6158 .{ "while", .keyword_while },
......@@ -146,8 +143,6 @@ pub const Token = struct {
146143 keyword_anyframe,
147144 keyword_anytype,
148145 keyword_asm,
149 keyword_async,
150 keyword_await,
151146 keyword_break,
152147 keyword_callconv,
153148 keyword_catch,
......@@ -184,7 +179,6 @@ pub const Token = struct {
184179 keyword_try,
185180 keyword_union,
186181 keyword_unreachable,
187 keyword_usingnamespace,
188182 keyword_var,
189183 keyword_volatile,
190184 keyword_while,
......@@ -273,8 +267,6 @@ pub const Token = struct {
273267 .keyword_anyframe => "anyframe",
274268 .keyword_anytype => "anytype",
275269 .keyword_asm => "asm",
276 .keyword_async => "async",
277 .keyword_await => "await",
278270 .keyword_break => "break",
279271 .keyword_callconv => "callconv",
280272 .keyword_catch => "catch",
......@@ -311,7 +303,6 @@ pub const Token = struct {
311303 .keyword_try => "try",
312304 .keyword_union => "union",
313305 .keyword_unreachable => "unreachable",
314 .keyword_usingnamespace => "usingnamespace",
315306 .keyword_var => "var",
316307 .keyword_volatile => "volatile",
317308 .keyword_while => "while",
src/Compilation.zig+1-1
......@@ -6466,7 +6466,7 @@ pub fn addCCArgs(
64666466 try argv.append("-fno-asynchronous-unwind-tables");
64676467 try argv.append("-funwind-tables");
64686468 },
6469 .@"async" => try argv.append("-fasynchronous-unwind-tables"),
6469 .async => try argv.append("-fasynchronous-unwind-tables"),
64706470 }
64716471
64726472 try argv.append("-nostdinc");
src/InternPool.zig+1-13
......@@ -518,8 +518,6 @@ pub const Nav = struct {
518518 namespace: NamespaceIndex,
519519 zir_index: TrackedInst.Index,
520520 },
521 /// TODO: this is a hack! If #20663 isn't accepted, let's figure out something a bit better.
522 is_usingnamespace: bool,
523521 status: union(enum) {
524522 /// This `Nav` is pending semantic analysis.
525523 unresolved,
......@@ -735,7 +733,7 @@ pub const Nav = struct {
735733 @"addrspace": std.builtin.AddressSpace,
736734 /// Populated only if `bits.status == .type_resolved`.
737735 is_threadlocal: bool,
738 is_usingnamespace: bool,
736 _: u1 = 0,
739737 };
740738
741739 fn unpack(repr: Repr) Nav {
......@@ -749,7 +747,6 @@ pub const Nav = struct {
749747 assert(repr.analysis_zir_index == .none);
750748 break :a null;
751749 },
752 .is_usingnamespace = repr.bits.is_usingnamespace,
753750 .status = switch (repr.bits.status) {
754751 .unresolved => .unresolved,
755752 .type_resolved, .type_resolved_extern_decl => .{ .type_resolved = .{
......@@ -797,7 +794,6 @@ pub const Nav = struct {
797794 .is_const = false,
798795 .alignment = .none,
799796 .@"addrspace" = .generic,
800 .is_usingnamespace = nav.is_usingnamespace,
801797 .is_threadlocal = false,
802798 },
803799 .type_resolved => |r| .{
......@@ -805,7 +801,6 @@ pub const Nav = struct {
805801 .is_const = r.is_const,
806802 .alignment = r.alignment,
807803 .@"addrspace" = r.@"addrspace",
808 .is_usingnamespace = nav.is_usingnamespace,
809804 .is_threadlocal = r.is_threadlocal,
810805 },
811806 .fully_resolved => |r| .{
......@@ -813,7 +808,6 @@ pub const Nav = struct {
813808 .is_const = r.is_const,
814809 .alignment = r.alignment,
815810 .@"addrspace" = r.@"addrspace",
816 .is_usingnamespace = nav.is_usingnamespace,
817811 .is_threadlocal = false,
818812 },
819813 },
......@@ -6865,8 +6859,6 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {
68656859 {
68666860 namespace.pub_decls.deinit(gpa);
68676861 namespace.priv_decls.deinit(gpa);
6868 namespace.pub_usingnamespace.deinit(gpa);
6869 namespace.priv_usingnamespace.deinit(gpa);
68706862 namespace.comptime_decls.deinit(gpa);
68716863 namespace.test_decls.deinit(gpa);
68726864 }
......@@ -11503,7 +11495,6 @@ pub fn createNav(
1150311495 .@"linksection" = opts.@"linksection",
1150411496 .@"addrspace" = opts.@"addrspace",
1150511497 } },
11506 .is_usingnamespace = false,
1150711498 }));
1150811499 return index_unwrapped.wrap(ip);
1150911500}
......@@ -11518,8 +11509,6 @@ pub fn createDeclNav(
1151811509 fqn: NullTerminatedString,
1151911510 zir_index: TrackedInst.Index,
1152011511 namespace: NamespaceIndex,
11521 /// TODO: this is hacky! See `Nav.is_usingnamespace`.
11522 is_usingnamespace: bool,
1152311512) Allocator.Error!Nav.Index {
1152411513 const navs = ip.getLocal(tid).getMutableNavs(gpa);
1152511514
......@@ -11538,7 +11527,6 @@ pub fn createDeclNav(
1153811527 .zir_index = zir_index,
1153911528 },
1154011529 .status = .unresolved,
11541 .is_usingnamespace = is_usingnamespace,
1154211530 }));
1154311531
1154411532 return nav;
src/Sema.zig+19-155
......@@ -1280,7 +1280,6 @@ fn analyzeBodyInner(
12801280 .tag_name => try sema.zirTagName(block, inst),
12811281 .type_name => try sema.zirTypeName(block, inst),
12821282 .frame_type => try sema.zirFrameType(block, inst),
1283 .frame_size => try sema.zirFrameSize(block, inst),
12841283 .int_from_float => try sema.zirIntFromFloat(block, inst),
12851284 .float_from_int => try sema.zirFloatFromInt(block, inst),
12861285 .ptr_from_int => try sema.zirPtrFromInt(block, inst),
......@@ -1302,7 +1301,6 @@ fn analyzeBodyInner(
13021301 .mul_add => try sema.zirMulAdd(block, inst),
13031302 .builtin_call => try sema.zirBuiltinCall(block, inst),
13041303 .@"resume" => try sema.zirResume(block, inst),
1305 .@"await" => try sema.zirAwait(block, inst),
13061304 .for_len => try sema.zirForLen(block, inst),
13071305 .validate_array_init_ref_ty => try sema.zirValidateArrayInitRefTy(block, inst),
13081306 .opt_eu_base_ptr_init => try sema.zirOptEuBasePtrInit(block, inst),
......@@ -1410,12 +1408,10 @@ fn analyzeBodyInner(
14101408 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),
14111409 .prefetch => try sema.zirPrefetch( block, extended),
14121410 .error_cast => try sema.zirErrorCast( block, extended),
1413 .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),
14141411 .select => try sema.zirSelect( block, extended),
14151412 .int_from_error => try sema.zirIntFromError( block, extended),
14161413 .error_from_int => try sema.zirErrorFromInt( block, extended),
14171414 .reify => try sema.zirReify( block, extended, inst),
1418 .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended),
14191415 .cmpxchg => try sema.zirCmpxchg( block, extended),
14201416 .c_va_arg => try sema.zirCVaArg( block, extended),
14211417 .c_va_copy => try sema.zirCVaCopy( block, extended),
......@@ -2864,7 +2860,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
28642860 sema.code.nullTerminatedString(str),
28652861 .no_embedded_nulls,
28662862 );
2867 const nav = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
2863 const nav = try sema.lookupIdentifier(block, decl_name);
28682864 break :capture InternPool.CaptureValue.wrap(.{ .nav_val = nav });
28692865 },
28702866 .decl_ref => |str| capture: {
......@@ -2874,7 +2870,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
28742870 sema.code.nullTerminatedString(str),
28752871 .no_embedded_nulls,
28762872 );
2877 const nav = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
2873 const nav = try sema.lookupIdentifier(block, decl_name);
28782874 break :capture InternPool.CaptureValue.wrap(.{ .nav_ref = nav });
28792875 },
28802876 };
......@@ -6929,7 +6925,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
69296925 inst_data.get(sema.code),
69306926 .no_embedded_nulls,
69316927 );
6932 const nav_index = try sema.lookupIdentifier(block, src, decl_name);
6928 const nav_index = try sema.lookupIdentifier(block, decl_name);
69336929 return sema.analyzeNavRef(block, src, nav_index);
69346930}
69356931
......@@ -6944,16 +6940,16 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
69446940 inst_data.get(sema.code),
69456941 .no_embedded_nulls,
69466942 );
6947 const nav = try sema.lookupIdentifier(block, src, decl_name);
6943 const nav = try sema.lookupIdentifier(block, decl_name);
69486944 return sema.analyzeNavVal(block, src, nav);
69496945}
69506946
6951fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.Nav.Index {
6947fn lookupIdentifier(sema: *Sema, block: *Block, name: InternPool.NullTerminatedString) !InternPool.Nav.Index {
69526948 const pt = sema.pt;
69536949 const zcu = pt.zcu;
69546950 var namespace = block.namespace;
69556951 while (true) {
6956 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| {
6952 if (try sema.lookupInNamespace(block, namespace, name)) |lookup| {
69576953 assert(lookup.accessible);
69586954 return lookup.nav;
69596955 }
......@@ -6962,15 +6958,12 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo
69626958 unreachable; // AstGen detects use of undeclared identifiers.
69636959}
69646960
6965/// This looks up a member of a specific namespace. It is affected by `usingnamespace` but
6966/// only for ones in the specified namespace.
6961/// This looks up a member of a specific namespace.
69676962fn lookupInNamespace(
69686963 sema: *Sema,
69696964 block: *Block,
6970 src: LazySrcLoc,
69716965 namespace_index: InternPool.NamespaceIndex,
69726966 ident_name: InternPool.NullTerminatedString,
6973 observe_usingnamespace: bool,
69746967) CompileError!?struct {
69756968 nav: InternPool.Nav.Index,
69766969 /// If `false`, the declaration is in a different file and is not `pub`.
......@@ -6979,7 +6972,6 @@ fn lookupInNamespace(
69796972} {
69806973 const pt = sema.pt;
69816974 const zcu = pt.zcu;
6982 const ip = &zcu.intern_pool;
69836975
69846976 try pt.ensureNamespaceUpToDate(namespace_index);
69856977
......@@ -6996,75 +6988,7 @@ fn lookupInNamespace(
69966988 } });
69976989 }
69986990
6999 if (observe_usingnamespace and (namespace.pub_usingnamespace.items.len != 0 or namespace.priv_usingnamespace.items.len != 0)) {
7000 const gpa = sema.gpa;
7001 var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .empty;
7002 defer checked_namespaces.deinit(gpa);
7003
7004 // Keep track of name conflicts for error notes.
7005 var candidates: std.ArrayListUnmanaged(InternPool.Nav.Index) = .empty;
7006 defer candidates.deinit(gpa);
7007
7008 try checked_namespaces.put(gpa, namespace, {});
7009 var check_i: usize = 0;
7010
7011 while (check_i < checked_namespaces.count()) : (check_i += 1) {
7012 const check_ns = checked_namespaces.keys()[check_i];
7013 const Pass = enum { @"pub", priv };
7014 for ([2]Pass{ .@"pub", .priv }) |pass| {
7015 if (pass == .priv and src_file != check_ns.file_scope) {
7016 continue;
7017 }
7018
7019 const decls, const usingnamespaces = switch (pass) {
7020 .@"pub" => .{ &check_ns.pub_decls, &check_ns.pub_usingnamespace },
7021 .priv => .{ &check_ns.priv_decls, &check_ns.priv_usingnamespace },
7022 };
7023
7024 if (decls.getKeyAdapted(ident_name, adapter)) |nav_index| {
7025 try candidates.append(gpa, nav_index);
7026 }
7027
7028 for (usingnamespaces.items) |sub_ns_nav| {
7029 try sema.ensureNavResolved(block, src, sub_ns_nav, .fully);
7030 const sub_ns_ty: Type = .fromInterned(ip.getNav(sub_ns_nav).status.fully_resolved.val);
7031 const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu));
7032 try checked_namespaces.put(gpa, sub_ns, {});
7033 }
7034 }
7035 }
7036
7037 ignore_self: {
7038 const skip_nav = switch (sema.owner.unwrap()) {
7039 .@"comptime", .type, .func, .memoized_state => break :ignore_self,
7040 .nav_ty, .nav_val => |nav| nav,
7041 };
7042 var i: usize = 0;
7043 while (i < candidates.items.len) {
7044 if (candidates.items[i] == skip_nav) {
7045 _ = candidates.orderedRemove(i);
7046 } else {
7047 i += 1;
7048 }
7049 }
7050 }
7051
7052 switch (candidates.items.len) {
7053 0 => {},
7054 1 => return .{
7055 .nav = candidates.items[0],
7056 .accessible = true,
7057 },
7058 else => return sema.failWithOwnedErrorMsg(block, msg: {
7059 const msg = try sema.errMsg(src, "ambiguous reference", .{});
7060 errdefer msg.destroy(gpa);
7061 for (candidates.items) |candidate| {
7062 try sema.errNote(zcu.navSrcLoc(candidate), msg, "declared here", .{});
7063 }
7064 break :msg msg;
7065 }),
7066 }
7067 } else if (namespace.pub_decls.getKeyAdapted(ident_name, adapter)) |nav_index| {
6991 if (namespace.pub_decls.getKeyAdapted(ident_name, adapter)) |nav_index| {
70686992 return .{
70696993 .nav = nav_index,
70706994 .accessible = true,
......@@ -7653,10 +7577,6 @@ fn analyzeCall(
76537577 const ip = &zcu.intern_pool;
76547578 const arena = sema.arena;
76557579
7656 if (modifier == .async_kw) {
7657 return sema.failWithUseOfAsync(block, call_src);
7658 }
7659
76607580 const maybe_func_inst = try sema.funcDeclSrcInst(callee);
76617581 const func_ret_ty_src: LazySrcLoc = if (maybe_func_inst) |fn_decl_inst| .{
76627582 .base_node_inst = fn_decl_inst,
......@@ -8048,14 +7968,13 @@ fn analyzeCall(
80487968 }
80497969
80507970 const call_tag: Air.Inst.Tag = switch (modifier) {
8051 .auto, .no_async => .call,
7971 .auto, .no_suspend => .call,
80527972 .never_tail => .call_never_tail,
80537973 .never_inline => .call_never_inline,
80547974 .always_tail => .call_always_tail,
80557975
80567976 .always_inline,
80577977 .compile_time,
8058 .async_kw,
80597978 => unreachable,
80607979 };
80617980
......@@ -13955,7 +13874,6 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1395513874 const zcu = pt.zcu;
1395613875 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1395713876 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13958 const src = block.nodeOffset(inst_data.src_node);
1395913877 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1396013878 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1396113879 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
......@@ -13964,7 +13882,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1396413882 try sema.checkNamespaceType(block, lhs_src, container_type);
1396513883
1396613884 const namespace = container_type.getNamespace(zcu).unwrap() orelse return .bool_false;
13967 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| {
13885 if (try sema.lookupInNamespace(block, namespace, decl_name)) |lookup| {
1396813886 if (lookup.accessible) {
1396913887 return .bool_true;
1397013888 }
......@@ -17745,7 +17663,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1774517663 } });
1774617664 };
1774717665
17748 const decls_val = try sema.typeInfoDecls(block, src, ip.loadEnumType(ty.toIntern()).namespace.toOptional());
17666 const decls_val = try sema.typeInfoDecls(src, ip.loadEnumType(ty.toIntern()).namespace.toOptional());
1774917667
1775017668 const type_enum_ty = try sema.getBuiltinType(src, .@"Type.Enum");
1775117669
......@@ -17858,7 +17776,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1785817776 } });
1785917777 };
1786017778
17861 const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespaceIndex(zcu).toOptional());
17779 const decls_val = try sema.typeInfoDecls(src, ty.getNamespaceIndex(zcu).toOptional());
1786217780
1786317781 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
1786417782 .ty = (try pt.optionalType(.type_type)).toIntern(),
......@@ -18053,7 +17971,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1805317971 } });
1805417972 };
1805517973
18056 const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespace(zcu));
17974 const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu));
1805717975
1805817976 const backing_integer_val = try pt.intern(.{ .opt = .{
1805917977 .ty = (try pt.optionalType(.type_type)).toIntern(),
......@@ -18092,7 +18010,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1809218010 const type_opaque_ty = try sema.getBuiltinType(src, .@"Type.Opaque");
1809318011
1809418012 try ty.resolveFields(pt);
18095 const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespace(zcu));
18013 const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu));
1809618014
1809718015 const field_values = .{
1809818016 // decls: []const Declaration,
......@@ -18114,7 +18032,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1811418032
1811518033fn typeInfoDecls(
1811618034 sema: *Sema,
18117 block: *Block,
1811818035 src: LazySrcLoc,
1811918036 opt_namespace: InternPool.OptionalNamespaceIndex,
1812018037) CompileError!InternPool.Index {
......@@ -18130,7 +18047,7 @@ fn typeInfoDecls(
1813018047 var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa);
1813118048 defer seen_namespaces.deinit();
1813218049
18133 try sema.typeInfoNamespaceDecls(block, src, opt_namespace, declaration_ty, &decl_vals, &seen_namespaces);
18050 try sema.typeInfoNamespaceDecls(opt_namespace, declaration_ty, &decl_vals, &seen_namespaces);
1813418051
1813518052 const array_decl_ty = try pt.arrayType(.{
1813618053 .len = decl_vals.items.len,
......@@ -18164,8 +18081,6 @@ fn typeInfoDecls(
1816418081
1816518082fn typeInfoNamespaceDecls(
1816618083 sema: *Sema,
18167 block: *Block,
18168 src: LazySrcLoc,
1816918084 opt_namespace_index: InternPool.OptionalNamespaceIndex,
1817018085 declaration_ty: Type,
1817118086 decl_vals: *std.ArrayList(InternPool.Index),
......@@ -18221,15 +18136,6 @@ fn typeInfoNamespaceDecls(
1822118136 .storage = .{ .elems = &fields },
1822218137 } }));
1822318138 }
18224
18225 for (namespace.pub_usingnamespace.items) |nav| {
18226 if (zcu.analysis_in_progress.contains(.wrap(.{ .nav_val = nav }))) {
18227 continue;
18228 }
18229 try sema.ensureNavResolved(block, src, nav, .fully);
18230 const namespace_ty: Type = .fromInterned(ip.getNav(nav).status.fully_resolved.val);
18231 try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu).toOptional(), declaration_ty, decl_vals, seen_namespaces);
18232 }
1823318139}
1823418140
1823518141fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -22133,12 +22039,6 @@ fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2213322039 return sema.failWithUseOfAsync(block, src);
2213422040}
2213522041
22136fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22137 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22138 const src = block.nodeOffset(inst_data.src_node);
22139 return sema.failWithUseOfAsync(block, src);
22140}
22141
2214222042fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2214322043 const pt = sema.pt;
2214422044 const zcu = pt.zcu;
......@@ -24776,14 +24676,14 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2477624676 var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier);
2477724677 switch (modifier) {
2477824678 // These can be upgraded to comptime or nosuspend calls.
24779 .auto, .never_tail, .no_async => {
24679 .auto, .never_tail, .no_suspend => {
2478024680 if (block.isComptime()) {
2478124681 if (modifier == .never_tail) {
2478224682 return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{});
2478324683 }
2478424684 modifier = .compile_time;
2478524685 } else if (extra.flags.is_nosuspend) {
24786 modifier = .no_async;
24686 modifier = .no_suspend;
2478724687 }
2478824688 },
2478924689 // These can be upgraded to comptime. nosuspend bit can be safely ignored.
......@@ -24801,14 +24701,6 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2480124701 modifier = .compile_time;
2480224702 }
2480324703 },
24804 .async_kw => {
24805 if (extra.flags.is_nosuspend) {
24806 return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{});
24807 }
24808 if (block.isComptime()) {
24809 return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used in combination with comptime function call", .{});
24810 }
24811 },
2481224704 .never_inline => {
2481324705 if (block.isComptime()) {
2481424706 return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{});
......@@ -25797,40 +25689,12 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2579725689 });
2579825690}
2579925691
25800fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
25801 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25802 const src = block.nodeOffset(extra.node);
25803 return sema.failWithUseOfAsync(block, src);
25804}
25805
2580625692fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2580725693 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2580825694 const src = block.nodeOffset(inst_data.src_node);
2580925695 return sema.failWithUseOfAsync(block, src);
2581025696}
2581125697
25812fn zirAwait(
25813 sema: *Sema,
25814 block: *Block,
25815 inst: Zir.Inst.Index,
25816) CompileError!Air.Inst.Ref {
25817 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
25818 const src = block.nodeOffset(inst_data.src_node);
25819
25820 return sema.failWithUseOfAsync(block, src);
25821}
25822
25823fn zirAwaitNosuspend(
25824 sema: *Sema,
25825 block: *Block,
25826 extended: Zir.Inst.Extended.InstData,
25827) CompileError!Air.Inst.Ref {
25828 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25829 const src = block.nodeOffset(extra.node);
25830
25831 return sema.failWithUseOfAsync(block, src);
25832}
25833
2583425698fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2583525699 const tracy = trace(@src());
2583625700 defer tracy.end();
......@@ -26738,7 +26602,7 @@ fn explainWhyTypeIsNotExtern(
2673826602 }
2673926603 switch (ty.fnCallingConvention(zcu)) {
2674026604 .auto => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
26741 .@"async" => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
26605 .async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
2674226606 .@"inline" => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
2674326607 else => return,
2674426608 }
......@@ -27760,7 +27624,7 @@ fn namespaceLookup(
2776027624 const pt = sema.pt;
2776127625 const zcu = pt.zcu;
2776227626 const gpa = sema.gpa;
27763 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| {
27627 if (try sema.lookupInNamespace(block, namespace, decl_name)) |lookup| {
2776427628 if (!lookup.accessible) {
2776527629 return sema.failWithOwnedErrorMsg(block, msg: {
2776627630 const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{
src/Type.zig+1-1
......@@ -382,7 +382,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
382382 }
383383 }
384384 switch (fn_info.cc) {
385 .auto, .@"async", .naked, .@"inline" => try writer.print("callconv(.{}) ", .{std.zig.fmtId(@tagName(fn_info.cc))}),
385 .auto, .async, .naked, .@"inline" => try writer.print("callconv(.{}) ", .{std.zig.fmtId(@tagName(fn_info.cc))}),
386386 else => try writer.print("callconv({any}) ", .{fn_info.cc}),
387387 }
388388 }
src/Zcu.zig+1-34
......@@ -792,10 +792,6 @@ pub const Namespace = struct {
792792 pub_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty,
793793 /// Members of the namespace which are *not* marked `pub`.
794794 priv_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty,
795 /// All `usingnamespace` declarations in this namespace which are marked `pub`.
796 pub_usingnamespace: std.ArrayListUnmanaged(InternPool.Nav.Index) = .empty,
797 /// All `usingnamespace` declarations in this namespace which are *not* marked `pub`.
798 priv_usingnamespace: std.ArrayListUnmanaged(InternPool.Nav.Index) = .empty,
799795 /// All `comptime` declarations in this namespace. We store these purely so that incremental
800796 /// compilation can re-use the existing `ComptimeUnit`s when a namespace changes.
801797 comptime_decls: std.ArrayListUnmanaged(InternPool.ComptimeUnit.Id) = .empty,
......@@ -1303,9 +1299,6 @@ pub const SrcLoc = struct {
13031299 .simple_var_decl,
13041300 .aligned_var_decl,
13051301 => tree.fullVarDecl(node).?,
1306 .@"usingnamespace" => {
1307 return tree.nodeToSpan(tree.nodeData(node).node);
1308 },
13091302 else => unreachable,
13101303 };
13111304 if (full.ast.type_node.unwrap()) |type_node| {
......@@ -1443,12 +1436,8 @@ pub const SrcLoc = struct {
14431436 .field_access => tree.nodeData(node).node_and_token[1],
14441437 .call_one,
14451438 .call_one_comma,
1446 .async_call_one,
1447 .async_call_one_comma,
14481439 .call,
14491440 .call_comma,
1450 .async_call,
1451 .async_call_comma,
14521441 => blk: {
14531442 const full = tree.fullCall(&buf, node).?;
14541443 break :blk tree.lastToken(full.ast.fn_expr);
......@@ -3395,9 +3384,6 @@ pub fn mapOldZirToNew(
33953384 // All comptime declarations, in order, for a best-effort match.
33963385 var comptime_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;
33973386 defer comptime_decls.deinit(gpa);
3398 // All usingnamespace declarations, in order, for a best-effort match.
3399 var usingnamespace_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;
3400 defer usingnamespace_decls.deinit(gpa);
34013387
34023388 {
34033389 var old_decl_it = old_zir.declIterator(match_item.old_inst);
......@@ -3405,7 +3391,6 @@ pub fn mapOldZirToNew(
34053391 const old_decl = old_zir.getDeclaration(old_decl_inst);
34063392 switch (old_decl.kind) {
34073393 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),
3408 .@"usingnamespace" => try usingnamespace_decls.append(gpa, old_decl_inst),
34093394 .unnamed_test => try unnamed_tests.append(gpa, old_decl_inst),
34103395 .@"test" => try named_tests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),
34113396 .decltest => try named_decltests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),
......@@ -3416,7 +3401,6 @@ pub fn mapOldZirToNew(
34163401
34173402 var unnamed_test_idx: u32 = 0;
34183403 var comptime_decl_idx: u32 = 0;
3419 var usingnamespace_decl_idx: u32 = 0;
34203404
34213405 var new_decl_it = new_zir.declIterator(match_item.new_inst);
34223406 while (new_decl_it.next()) |new_decl_inst| {
......@@ -3426,7 +3410,6 @@ pub fn mapOldZirToNew(
34263410 // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name.
34273411 // * For unnamed tests, we match based on order.
34283412 // * For comptime blocks, we match based on order.
3429 // * For usingnamespace decls, we match based on order.
34303413 // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`.
34313414 const old_decl_inst = switch (new_decl.kind) {
34323415 .@"comptime" => inst: {
......@@ -3434,11 +3417,6 @@ pub fn mapOldZirToNew(
34343417 defer comptime_decl_idx += 1;
34353418 break :inst comptime_decls.items[comptime_decl_idx];
34363419 },
3437 .@"usingnamespace" => inst: {
3438 if (usingnamespace_decl_idx == usingnamespace_decls.items.len) continue;
3439 defer usingnamespace_decl_idx += 1;
3440 break :inst usingnamespace_decls.items[usingnamespace_decl_idx];
3441 },
34423420 .unnamed_test => inst: {
34433421 if (unnamed_test_idx == unnamed_tests.items.len) continue;
34443422 defer unnamed_test_idx += 1;
......@@ -4147,7 +4125,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
41474125 if (!comp.config.is_test or file.mod != zcu.main_mod) continue;
41484126
41494127 const want_analysis = switch (decl.kind) {
4150 .@"usingnamespace" => unreachable,
41514128 .@"const", .@"var" => unreachable,
41524129 .@"comptime" => unreachable,
41534130 .unnamed_test => true,
......@@ -4205,16 +4182,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
42054182 }
42064183 }
42074184 }
4208 // Incremental compilation does not support `usingnamespace`.
4209 // These are only included to keep good reference traces in non-incremental updates.
4210 for (zcu.namespacePtr(ns).pub_usingnamespace.items) |nav| {
4211 const unit: AnalUnit = .wrap(.{ .nav_val = nav });
4212 if (!result.contains(unit)) try unit_queue.put(gpa, unit, referencer);
4213 }
4214 for (zcu.namespacePtr(ns).priv_usingnamespace.items) |nav| {
4215 const unit: AnalUnit = .wrap(.{ .nav_val = nav });
4216 if (!result.contains(unit)) try unit_queue.put(gpa, unit, referencer);
4217 }
42184185 continue;
42194186 }
42204187 if (unit_queue.pop()) |kv| {
......@@ -4457,7 +4424,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
44574424 const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm);
44584425 switch (cc) {
44594426 .auto, .@"inline" => return .ok,
4460 .@"async" => return .{ .bad_backend = backend }, // nothing supports async currently
4427 .async => return .{ .bad_backend = backend }, // nothing supports async currently
44614428 .naked => {}, // depends only on backend
44624429 else => for (cc.archs()) |allowed_arch| {
44634430 if (allowed_arch == target.cpu.arch) break;
src/Zcu/PerThread.zig+3-54
......@@ -1111,7 +1111,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
11111111 defer block.instructions.deinit(gpa);
11121112
11131113 const zir_decl = zir.getDeclaration(inst_resolved.inst);
1114 assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace"));
11151114
11161115 const ty_src = block.src(.{ .node_offset_var_decl_ty = .zero });
11171116 const init_src = block.src(.{ .node_offset_var_decl_init = .zero });
......@@ -1160,7 +1159,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
11601159 assert(nav_ty.zigTypeTag(zcu) == .@"fn");
11611160 break :is_const true;
11621161 },
1163 .@"usingnamespace", .@"const" => true,
1162 .@"const" => true,
11641163 .@"var" => {
11651164 try sema.validateVarType(
11661165 &block,
......@@ -1240,26 +1239,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
12401239 // this resolves the type `type` (which needs no resolution), not the struct itself.
12411240 try nav_ty.resolveLayout(pt);
12421241
1243 // TODO: this is jank. If #20663 is rejected, let's think about how to better model `usingnamespace`.
1244 if (zir_decl.kind == .@"usingnamespace") {
1245 if (nav_ty.toIntern() != .type_type) {
1246 return sema.fail(&block, ty_src, "expected type, found {}", .{nav_ty.fmt(pt)});
1247 }
1248 if (nav_val.toType().getNamespace(zcu) == .none) {
1249 return sema.fail(&block, ty_src, "type {} has no namespace", .{nav_val.toType().fmt(pt)});
1250 }
1251 ip.resolveNavValue(nav_id, .{
1252 .val = nav_val.toIntern(),
1253 .is_const = is_const,
1254 .alignment = .none,
1255 .@"linksection" = .none,
1256 .@"addrspace" = .generic,
1257 });
1258 // TODO: usingnamespace cannot participate in incremental compilation
1259 assert(zcu.analysis_in_progress.swapRemove(anal_unit));
1260 return .{ .val_changed = true };
1261 }
1262
12631242 const queue_linker_work, const is_owned_fn = switch (ip.indexToKey(nav_val.toIntern())) {
12641243 .func => |f| .{ true, f.owner_nav == nav_id }, // note that this lets function aliases reach codegen
12651244 .variable => |v| .{ v.owner_nav == nav_id, false },
......@@ -1464,7 +1443,6 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr
14641443 defer _ = zcu.analysis_in_progress.swapRemove(anal_unit);
14651444
14661445 const zir_decl = zir.getDeclaration(inst_resolved.inst);
1467 assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace"));
14681446 const type_body = zir_decl.type_body.?;
14691447
14701448 var analysis_arena: std.heap.ArenaAllocator = .init(gpa);
......@@ -1527,7 +1505,7 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr
15271505
15281506 const is_const = switch (zir_decl.kind) {
15291507 .@"comptime" => unreachable,
1530 .unnamed_test, .@"test", .decltest, .@"usingnamespace", .@"const" => true,
1508 .unnamed_test, .@"test", .decltest, .@"const" => true,
15311509 .@"var" => false,
15321510 };
15331511
......@@ -2541,7 +2519,6 @@ pub fn scanNamespace(
25412519
25422520 try existing_by_inst.ensureTotalCapacity(gpa, @intCast(
25432521 namespace.pub_decls.count() + namespace.priv_decls.count() +
2544 namespace.pub_usingnamespace.items.len + namespace.priv_usingnamespace.items.len +
25452522 namespace.comptime_decls.items.len +
25462523 namespace.test_decls.items.len,
25472524 ));
......@@ -2554,14 +2531,6 @@ pub fn scanNamespace(
25542531 const zir_index = ip.getNav(nav).analysis.?.zir_index;
25552532 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .nav_val = nav }));
25562533 }
2557 for (namespace.pub_usingnamespace.items) |nav| {
2558 const zir_index = ip.getNav(nav).analysis.?.zir_index;
2559 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .nav_val = nav }));
2560 }
2561 for (namespace.priv_usingnamespace.items) |nav| {
2562 const zir_index = ip.getNav(nav).analysis.?.zir_index;
2563 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .nav_val = nav }));
2564 }
25652534 for (namespace.comptime_decls.items) |cu| {
25662535 const zir_index = ip.getComptimeUnit(cu).zir_index;
25672536 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .@"comptime" = cu }));
......@@ -2578,8 +2547,6 @@ pub fn scanNamespace(
25782547
25792548 namespace.pub_decls.clearRetainingCapacity();
25802549 namespace.priv_decls.clearRetainingCapacity();
2581 namespace.pub_usingnamespace.clearRetainingCapacity();
2582 namespace.priv_usingnamespace.clearRetainingCapacity();
25832550 namespace.comptime_decls.clearRetainingCapacity();
25842551 namespace.test_decls.clearRetainingCapacity();
25852552
......@@ -2607,7 +2574,6 @@ const ScanDeclIter = struct {
26072574 /// Decl scanning is run in two passes, so that we can detect when a generated
26082575 /// name would clash with an explicit name and use a different one.
26092576 pass: enum { named, unnamed },
2610 usingnamespace_index: usize = 0,
26112577 unnamed_test_index: usize = 0,
26122578
26132579 fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString {
......@@ -2646,12 +2612,6 @@ const ScanDeclIter = struct {
26462612 if (iter.pass != .unnamed) return;
26472613 break :name .none;
26482614 },
2649 .@"usingnamespace" => name: {
2650 if (iter.pass != .unnamed) return;
2651 const i = iter.usingnamespace_index;
2652 iter.usingnamespace_index += 1;
2653 break :name (try iter.avoidNameConflict("usingnamespace_{d}", .{i})).toOptional();
2654 },
26552615 .unnamed_test => name: {
26562616 if (iter.pass != .unnamed) return;
26572617 const i = iter.unnamed_test_index;
......@@ -2710,7 +2670,7 @@ const ScanDeclIter = struct {
27102670 const name = maybe_name.unwrap().?;
27112671 const fqn = try namespace.internFullyQualifiedName(ip, gpa, pt.tid, name);
27122672 const nav = if (existing_unit) |eu| eu.unwrap().nav_val else nav: {
2713 const nav = try ip.createDeclNav(gpa, pt.tid, name, fqn, tracked_inst, namespace_index, decl.kind == .@"usingnamespace");
2673 const nav = try ip.createDeclNav(gpa, pt.tid, name, fqn, tracked_inst, namespace_index);
27142674 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newNav(zcu, nav);
27152675 break :nav nav;
27162676 };
......@@ -2722,17 +2682,6 @@ const ScanDeclIter = struct {
27222682
27232683 const want_analysis = switch (decl.kind) {
27242684 .@"comptime" => unreachable,
2725 .@"usingnamespace" => a: {
2726 if (comp.incremental) {
2727 @panic("'usingnamespace' is not supported by incremental compilation");
2728 }
2729 if (decl.is_pub) {
2730 try namespace.pub_usingnamespace.append(gpa, nav);
2731 } else {
2732 try namespace.priv_usingnamespace.append(gpa, nav);
2733 }
2734 break :a true;
2735 },
27362685 .unnamed_test, .@"test", .decltest => a: {
27372686 const is_named = decl.kind != .unnamed_test;
27382687 try namespace.test_decls.append(gpa, nav);
src/codegen/llvm.zig+7-7
......@@ -2758,7 +2758,7 @@ pub const Object = struct {
27582758 llvm_arg_i += 1;
27592759 }
27602760
2761 if (fn_info.cc == .@"async") {
2761 if (fn_info.cc == .async) {
27622762 @panic("TODO: LLVM backend lower async function");
27632763 }
27642764
......@@ -2910,7 +2910,7 @@ pub const Object = struct {
29102910 try attributes.addFnAttr(.nounwind, &o.builder);
29112911 if (owner_mod.unwind_tables != .none) {
29122912 try attributes.addFnAttr(
2913 .{ .uwtable = if (owner_mod.unwind_tables == .@"async") .@"async" else .sync },
2913 .{ .uwtable = if (owner_mod.unwind_tables == .async) .async else .sync },
29142914 &o.builder,
29152915 );
29162916 }
......@@ -5273,7 +5273,7 @@ pub const FuncGen = struct {
52735273 switch (modifier) {
52745274 .auto, .always_tail => {},
52755275 .never_tail, .never_inline => try attributes.addFnAttr(.@"noinline", &o.builder),
5276 .async_kw, .no_async, .always_inline, .compile_time => unreachable,
5276 .no_suspend, .always_inline, .compile_time => unreachable,
52775277 }
52785278
52795279 const ret_ptr = if (!sret) null else blk: {
......@@ -5488,7 +5488,7 @@ pub const FuncGen = struct {
54885488 .auto, .never_inline => .normal,
54895489 .never_tail => .notail,
54905490 .always_tail => .musttail,
5491 .async_kw, .no_async, .always_inline, .compile_time => unreachable,
5491 .no_suspend, .always_inline, .compile_time => unreachable,
54925492 },
54935493 toLlvmCallConvTag(fn_info.cc, target).?,
54945494 try attributes.finish(&o.builder),
......@@ -11861,7 +11861,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
1186111861 }
1186211862 return switch (cc_tag) {
1186311863 .@"inline" => unreachable,
11864 .auto, .@"async" => .fastcc,
11864 .auto, .async => .fastcc,
1186511865 .naked => .ccc,
1186611866 .x86_64_sysv => .x86_64_sysvcc,
1186711867 .x86_64_win => .win64cc,
......@@ -12369,7 +12369,7 @@ const ParamTypeIterator = struct {
1236912369 return .byval;
1237012370 }
1237112371 },
12372 .@"async" => {
12372 .async => {
1237312373 @panic("TODO implement async function lowering in the LLVM backend");
1237412374 },
1237512375 .x86_64_sysv => return it.nextSystemV(ty),
......@@ -12624,7 +12624,7 @@ fn ccAbiPromoteInt(
1262412624) ?std.builtin.Signedness {
1262512625 const target = zcu.getTarget();
1262612626 switch (cc) {
12627 .auto, .@"inline", .@"async" => return null,
12627 .auto, .@"inline", .async => return null,
1262812628 else => {},
1262912629 }
1263012630 const int_info = switch (ty.zigTypeTag(zcu)) {
src/libs/libcxx.zig+1-1
......@@ -325,7 +325,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
325325 // See the `-fno-exceptions` logic for WASI.
326326 // The old 32-bit x86 variant of SEH doesn't use tables.
327327 const unwind_tables: std.builtin.UnwindTables =
328 if (target.os.tag == .wasi or (target.cpu.arch == .x86 and target.os.tag == .windows)) .none else .@"async";
328 if (target.os.tag == .wasi or (target.cpu.arch == .x86 and target.os.tag == .windows)) .none else .async;
329329
330330 const config = Compilation.Config.resolve(.{
331331 .output_mode = output_mode,
src/libs/libtsan.zig+1-1
......@@ -48,7 +48,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
4848 const optimize_mode = comp.compilerRtOptMode();
4949 const strip = comp.compilerRtStrip();
5050 const unwind_tables: std.builtin.UnwindTables =
51 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
51 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .async;
5252 const link_libcpp = target.os.tag.isDarwin();
5353
5454 const config = Compilation.Config.resolve(.{
src/libs/libunwind.zig+1-1
......@@ -29,7 +29,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
2929 const output_mode = .Lib;
3030 const target = &comp.root_mod.resolved_target.result;
3131 const unwind_tables: std.builtin.UnwindTables =
32 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
32 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .async;
3333 const config = Compilation.Config.resolve(.{
3434 .output_mode = output_mode,
3535 .resolved_target = comp.root_mod.resolved_target,
src/libs/mingw.zig+1-1
......@@ -29,7 +29,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
2929 const target = comp.getTarget();
3030
3131 // The old 32-bit x86 variant of SEH doesn't use tables.
32 const unwind_tables: std.builtin.UnwindTables = if (target.cpu.arch != .x86) .@"async" else .none;
32 const unwind_tables: std.builtin.UnwindTables = if (target.cpu.arch != .x86) .async else .none;
3333
3434 switch (crt_file) {
3535 .crt2_o => {
src/link/Dwarf.zig+3-3
......@@ -2489,7 +2489,7 @@ fn initWipNavInner(
24892489 const addr: Loc = .{ .addr_reloc = sym_index };
24902490 const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr;
24912491 switch (decl.kind) {
2492 .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable,
2492 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
24932493 .@"const" => {
24942494 const const_ty_reloc_index = try wip_nav.refForward();
24952495 try wip_nav.infoExprLoc(loc);
......@@ -2775,7 +2775,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
27752775
27762776 const is_test = switch (decl.kind) {
27772777 .unnamed_test, .@"test", .decltest => true,
2778 .@"comptime", .@"usingnamespace", .@"const", .@"var" => false,
2778 .@"comptime", .@"const", .@"var" => false,
27792779 };
27802780 if (is_test) {
27812781 // This isn't actually a comptime Nav! It's a test, so it'll definitely never be referenced at comptime.
......@@ -3596,7 +3596,7 @@ fn updateLazyType(
35963596 // For better or worse, we try to match what Clang emits.
35973597 break :cc switch (func_type.cc) {
35983598 .@"inline" => .nocall,
3599 .@"async", .auto, .naked => .normal,
3599 .async, .auto, .naked => .normal,
36003600 .x86_64_sysv => .LLVM_X86_64SysV,
36013601 .x86_64_win => .LLVM_Win64,
36023602 .x86_64_regcall_v3_sysv => .LLVM_X86RegCall,
src/main.zig+6-6
......@@ -1416,7 +1416,7 @@ fn buildOutputType(
14161416 } else if (mem.eql(u8, arg, "-funwind-tables")) {
14171417 mod_opts.unwind_tables = .sync;
14181418 } else if (mem.eql(u8, arg, "-fasync-unwind-tables")) {
1419 mod_opts.unwind_tables = .@"async";
1419 mod_opts.unwind_tables = .async;
14201420 } else if (mem.eql(u8, arg, "-fno-unwind-tables")) {
14211421 mod_opts.unwind_tables = .none;
14221422 } else if (mem.eql(u8, arg, "-fstack-check")) {
......@@ -2035,15 +2035,15 @@ fn buildOutputType(
20352035 .none => {
20362036 mod_opts.unwind_tables = .sync;
20372037 },
2038 .sync, .@"async" => {},
2038 .sync, .async => {},
20392039 } else {
20402040 mod_opts.unwind_tables = .sync;
20412041 },
20422042 .no_unwind_tables => mod_opts.unwind_tables = .none,
2043 .asynchronous_unwind_tables => mod_opts.unwind_tables = .@"async",
2043 .asynchronous_unwind_tables => mod_opts.unwind_tables = .async,
20442044 .no_asynchronous_unwind_tables => if (mod_opts.unwind_tables) |uwt| switch (uwt) {
20452045 .none, .sync => {},
2046 .@"async" => {
2046 .async => {
20472047 mod_opts.unwind_tables = .sync;
20482048 },
20492049 } else {
......@@ -2951,7 +2951,7 @@ fn buildOutputType(
29512951 create_module.opts.any_fuzz = true;
29522952 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
29532953 .none => {},
2954 .sync, .@"async" => create_module.opts.any_unwind_tables = true,
2954 .sync, .async => create_module.opts.any_unwind_tables = true,
29552955 };
29562956 if (mod_opts.strip == false)
29572957 create_module.opts.any_non_stripped = true;
......@@ -7413,7 +7413,7 @@ fn handleModArg(
74137413 create_module.opts.any_fuzz = true;
74147414 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
74157415 .none => {},
7416 .sync, .@"async" => create_module.opts.any_unwind_tables = true,
7416 .sync, .async => create_module.opts.any_unwind_tables = true,
74177417 };
74187418 if (mod_opts.strip == false)
74197419 create_module.opts.any_non_stripped = true;
src/print_zir.zig-18
......@@ -261,14 +261,12 @@ const Writer = struct {
261261 .tag_name,
262262 .type_name,
263263 .frame_type,
264 .frame_size,
265264 .clz,
266265 .ctz,
267266 .pop_count,
268267 .byte_swap,
269268 .bit_reverse,
270269 .@"resume",
271 .@"await",
272270 .make_ptr_const,
273271 .validate_deref,
274272 .validate_const,
......@@ -565,7 +563,6 @@ const Writer = struct {
565563
566564 .tuple_decl => try self.writeTupleDecl(stream, extended),
567565
568 .await_nosuspend,
569566 .c_undef,
570567 .c_include,
571568 .set_float_mode,
......@@ -611,7 +608,6 @@ const Writer = struct {
611608 try self.writeSrcNode(stream, inst_data.node);
612609 },
613610
614 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
615611 .cmpxchg => try self.writeCmpxchg(stream, extended),
616612 .ptr_cast_full => try self.writePtrCastFull(stream, extended),
617613 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),
......@@ -932,19 +928,6 @@ const Writer = struct {
932928 try self.writeSrcNode(stream, extra.src_node);
933929 }
934930
935 fn writeBuiltinAsyncCall(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
936 const extra = self.code.extraData(Zir.Inst.AsyncCall, extended.operand).data;
937 try self.writeInstRef(stream, extra.frame_buffer);
938 try stream.writeAll(", ");
939 try self.writeInstRef(stream, extra.result_ptr);
940 try stream.writeAll(", ");
941 try self.writeInstRef(stream, extra.fn_ptr);
942 try stream.writeAll(", ");
943 try self.writeInstRef(stream, extra.args);
944 try stream.writeAll(") ");
945 try self.writeSrcNode(stream, extra.node);
946 }
947
948931 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
949932 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
950933 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
......@@ -2605,7 +2588,6 @@ const Writer = struct {
26052588 }
26062589 switch (decl.kind) {
26072590 .@"comptime" => try stream.writeAll("comptime"),
2608 .@"usingnamespace" => try stream.writeAll("usingnamespace"),
26092591 .unnamed_test => try stream.writeAll("test"),
26102592 .@"test", .decltest, .@"const", .@"var" => {
26112593 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });
src/target.zig+6-6
......@@ -483,12 +483,12 @@ pub fn clangSupportsNoImplicitFloatArg(target: *const std.Target) bool {
483483pub fn defaultUnwindTables(target: *const std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables {
484484 if (target.os.tag == .windows) {
485485 // The old 32-bit x86 variant of SEH doesn't use tables.
486 return if (target.cpu.arch != .x86) .@"async" else .none;
486 return if (target.cpu.arch != .x86) .async else .none;
487487 }
488 if (target.os.tag.isDarwin()) return .@"async";
489 if (libunwind) return .@"async";
490 if (libtsan) return .@"async";
491 if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .@"async";
488 if (target.os.tag.isDarwin()) return .async;
489 if (libunwind) return .async;
490 if (libtsan) return .async;
491 if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .async;
492492 return .none;
493493}
494494
......@@ -815,7 +815,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {
815815
816816pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
817817 return switch (cc) {
818 .auto, .@"async", .@"inline" => true,
818 .auto, .async, .@"inline" => true,
819819 // For now we want to authorize PTX kernel to use zig objects, even if
820820 // we end up exposing the ABI. The goal is to experiment with more
821821 // integrated CPU/GPU code.
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior.zig-3
......@@ -5,9 +5,7 @@ test {
55 _ = @import("behavior/align.zig");
66 _ = @import("behavior/alignof.zig");
77 _ = @import("behavior/array.zig");
8 _ = @import("behavior/async_fn.zig");
98 _ = @import("behavior/atomics.zig");
10 _ = @import("behavior/await_struct.zig");
119 _ = @import("behavior/basic.zig");
1210 _ = @import("behavior/bit_shifting.zig");
1311 _ = @import("behavior/bitcast.zig");
......@@ -103,7 +101,6 @@ test {
103101 _ = @import("behavior/underscore.zig");
104102 _ = @import("behavior/union.zig");
105103 _ = @import("behavior/union_with_members.zig");
106 _ = @import("behavior/usingnamespace.zig");
107104 _ = @import("behavior/var_args.zig");
108105 // https://github.com/llvm/llvm-project/issues/118879
109106 // https://github.com/llvm/llvm-project/issues/134659
test/behavior/align.zig-24
......@@ -425,30 +425,6 @@ test "struct field explicit alignment" {
425425 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);
426426}
427427
428test "align(@alignOf(T)) T does not force resolution of T" {
429 if (true) return error.SkipZigTest; // TODO
430
431 const S = struct {
432 const A = struct {
433 a: *align(@alignOf(A)) A,
434 };
435 fn doTheTest() void {
436 suspend {
437 resume @frame();
438 }
439 _ = bar(@Frame(doTheTest));
440 }
441 fn bar(comptime T: type) *align(@alignOf(T)) T {
442 ok = true;
443 return undefined;
444 }
445
446 var ok = false;
447 };
448 _ = async S.doTheTest();
449 try expect(S.ok);
450}
451
452428test "align(N) on functions" {
453429 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
454430 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
test/behavior/async_fn.zig deleted-1911
......@@ -1,1911 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const assert = std.debug.assert;
4const expect = std.testing.expect;
5const expectEqual = std.testing.expectEqual;
6const expectEqualStrings = std.testing.expectEqualStrings;
7const expectError = std.testing.expectError;
8
9var global_x: i32 = 1;
10
11test "simple coroutine suspend and resume" {
12 if (true) return error.SkipZigTest; // TODO
13 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
14
15 var frame = async simpleAsyncFn();
16 try expect(global_x == 2);
17 resume frame;
18 try expect(global_x == 3);
19 const af: anyframe->void = &frame;
20 _ = af;
21 resume frame;
22 try expect(global_x == 4);
23}
24fn simpleAsyncFn() void {
25 global_x += 1;
26 suspend {}
27 global_x += 1;
28 suspend {}
29 global_x += 1;
30}
31
32var global_y: i32 = 1;
33
34test "pass parameter to coroutine" {
35 if (true) return error.SkipZigTest; // TODO
36 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
37
38 var p = async simpleAsyncFnWithArg(2);
39 try expect(global_y == 3);
40 resume p;
41 try expect(global_y == 5);
42}
43fn simpleAsyncFnWithArg(delta: i32) void {
44 global_y += delta;
45 suspend {}
46 global_y += delta;
47}
48
49test "suspend at end of function" {
50 if (true) return error.SkipZigTest; // TODO
51 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
52
53 const S = struct {
54 var x: i32 = 1;
55
56 fn doTheTest() !void {
57 try expect(x == 1);
58 const p = async suspendAtEnd();
59 _ = p;
60 try expect(x == 2);
61 }
62
63 fn suspendAtEnd() void {
64 x += 1;
65 suspend {}
66 }
67 };
68 try S.doTheTest();
69}
70
71test "local variable in async function" {
72 if (true) return error.SkipZigTest; // TODO
73 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
74
75 const S = struct {
76 var x: i32 = 0;
77
78 fn doTheTest() !void {
79 try expect(x == 0);
80 var p = async add(1, 2);
81 try expect(x == 0);
82 resume p;
83 try expect(x == 0);
84 resume p;
85 try expect(x == 0);
86 resume p;
87 try expect(x == 3);
88 }
89
90 fn add(a: i32, b: i32) void {
91 var accum: i32 = 0;
92 suspend {}
93 accum += a;
94 suspend {}
95 accum += b;
96 suspend {}
97 x = accum;
98 }
99 };
100 try S.doTheTest();
101}
102
103test "calling an inferred async function" {
104 if (true) return error.SkipZigTest; // TODO
105 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
106
107 const S = struct {
108 var x: i32 = 1;
109 var other_frame: *@Frame(other) = undefined;
110
111 fn doTheTest() !void {
112 _ = async first();
113 try expect(x == 1);
114 resume other_frame.*;
115 try expect(x == 2);
116 }
117
118 fn first() void {
119 other();
120 }
121 fn other() void {
122 other_frame = @frame();
123 suspend {}
124 x += 1;
125 }
126 };
127 try S.doTheTest();
128}
129
130test "@frameSize" {
131 if (true) return error.SkipZigTest; // TODO
132 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
133
134 if (builtin.target.cpu.arch == .thumb or builtin.target.cpu.arch == .thumbeb)
135 return error.SkipZigTest;
136
137 const S = struct {
138 fn doTheTest() !void {
139 {
140 var ptr = @as(fn (i32) callconv(.@"async") void, @ptrCast(other));
141 _ = &ptr;
142 const size = @frameSize(ptr);
143 try expect(size == @sizeOf(@Frame(other)));
144 }
145 {
146 var ptr = @as(fn () callconv(.@"async") void, @ptrCast(first));
147 _ = &ptr;
148 const size = @frameSize(ptr);
149 try expect(size == @sizeOf(@Frame(first)));
150 }
151 }
152
153 fn first() void {
154 other(1);
155 }
156 fn other(param: i32) void {
157 _ = param;
158 var local: i32 = undefined;
159 _ = &local;
160 suspend {}
161 }
162 };
163 try S.doTheTest();
164}
165
166test "coroutine suspend, resume" {
167 if (true) return error.SkipZigTest; // TODO
168 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
169
170 const S = struct {
171 var frame: anyframe = undefined;
172
173 fn doTheTest() !void {
174 _ = async amain();
175 seq('d');
176 resume frame;
177 seq('h');
178
179 try expect(std.mem.eql(u8, &points, "abcdefgh"));
180 }
181
182 fn amain() void {
183 seq('a');
184 var f = async testAsyncSeq();
185 seq('c');
186 await f;
187 seq('g');
188 }
189
190 fn testAsyncSeq() void {
191 defer seq('f');
192
193 seq('b');
194 suspend {
195 frame = @frame();
196 }
197 seq('e');
198 }
199 var points = [_]u8{'x'} ** "abcdefgh".len;
200 var index: usize = 0;
201
202 fn seq(c: u8) void {
203 points[index] = c;
204 index += 1;
205 }
206 };
207 try S.doTheTest();
208}
209
210test "coroutine suspend with block" {
211 if (true) return error.SkipZigTest; // TODO
212 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
213
214 const p = async testSuspendBlock();
215 _ = p;
216 try expect(!global_result);
217 resume a_promise;
218 try expect(global_result);
219}
220
221var a_promise: anyframe = undefined;
222var global_result = false;
223fn testSuspendBlock() callconv(.@"async") void {
224 suspend {
225 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
226 a_promise = @frame();
227 }
228
229 // Test to make sure that @frame() works as advertised (issue #1296)
230 // var our_handle: anyframe = @frame();
231 expect(a_promise == @as(anyframe, @frame())) catch @panic("test failed");
232
233 global_result = true;
234}
235
236var await_a_promise: anyframe = undefined;
237var await_final_result: i32 = 0;
238
239test "coroutine await" {
240 if (true) return error.SkipZigTest; // TODO
241 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
242
243 await_seq('a');
244 var p = async await_amain();
245 _ = &p;
246 await_seq('f');
247 resume await_a_promise;
248 await_seq('i');
249 try expect(await_final_result == 1234);
250 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
251}
252fn await_amain() callconv(.@"async") void {
253 await_seq('b');
254 var p = async await_another();
255 await_seq('e');
256 await_final_result = await p;
257 await_seq('h');
258}
259fn await_another() callconv(.@"async") i32 {
260 await_seq('c');
261 suspend {
262 await_seq('d');
263 await_a_promise = @frame();
264 }
265 await_seq('g');
266 return 1234;
267}
268
269var await_points = [_]u8{0} ** "abcdefghi".len;
270var await_seq_index: usize = 0;
271
272fn await_seq(c: u8) void {
273 await_points[await_seq_index] = c;
274 await_seq_index += 1;
275}
276
277var early_final_result: i32 = 0;
278
279test "coroutine await early return" {
280 if (true) return error.SkipZigTest; // TODO
281 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
282
283 early_seq('a');
284 var p = async early_amain();
285 _ = &p;
286 early_seq('f');
287 try expect(early_final_result == 1234);
288 try expect(std.mem.eql(u8, &early_points, "abcdef"));
289}
290fn early_amain() callconv(.@"async") void {
291 early_seq('b');
292 var p = async early_another();
293 early_seq('d');
294 early_final_result = await p;
295 early_seq('e');
296}
297fn early_another() callconv(.@"async") i32 {
298 early_seq('c');
299 return 1234;
300}
301
302var early_points = [_]u8{0} ** "abcdef".len;
303var early_seq_index: usize = 0;
304
305fn early_seq(c: u8) void {
306 early_points[early_seq_index] = c;
307 early_seq_index += 1;
308}
309
310test "async function with dot syntax" {
311 if (true) return error.SkipZigTest; // TODO
312 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
313
314 const S = struct {
315 var y: i32 = 1;
316 fn foo() callconv(.@"async") void {
317 y += 1;
318 suspend {}
319 }
320 };
321 const p = async S.foo();
322 _ = p;
323 try expect(S.y == 2);
324}
325
326test "async fn pointer in a struct field" {
327 if (true) return error.SkipZigTest; // TODO
328 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
329
330 var data: i32 = 1;
331 const Foo = struct {
332 bar: fn (*i32) callconv(.@"async") void,
333 };
334 var foo = Foo{ .bar = simpleAsyncFn2 };
335 _ = &foo;
336 var bytes: [64]u8 align(16) = undefined;
337 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
338 comptime assert(@TypeOf(f) == anyframe->void);
339 try expect(data == 2);
340 resume f;
341 try expect(data == 4);
342 _ = async doTheAwait(f);
343 try expect(data == 4);
344}
345
346fn doTheAwait(f: anyframe->void) void {
347 await f;
348}
349fn simpleAsyncFn2(y: *i32) callconv(.@"async") void {
350 defer y.* += 2;
351 y.* += 1;
352 suspend {}
353}
354
355test "@asyncCall with return type" {
356 if (true) return error.SkipZigTest; // TODO
357 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
358
359 const Foo = struct {
360 bar: fn () callconv(.@"async") i32,
361
362 var global_frame: anyframe = undefined;
363 fn middle() callconv(.@"async") i32 {
364 return afunc();
365 }
366
367 fn afunc() i32 {
368 global_frame = @frame();
369 suspend {}
370 return 1234;
371 }
372 };
373 var foo = Foo{ .bar = Foo.middle };
374 _ = &foo;
375 var bytes: [150]u8 align(16) = undefined;
376 var aresult: i32 = 0;
377 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});
378 try expect(aresult == 0);
379 resume Foo.global_frame;
380 try expect(aresult == 1234);
381}
382
383test "async fn with inferred error set" {
384 if (true) return error.SkipZigTest; // TODO
385 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
386
387 const S = struct {
388 var global_frame: anyframe = undefined;
389
390 fn doTheTest() !void {
391 var frame: [1]@Frame(middle) = undefined;
392 var fn_ptr = middle;
393 _ = &fn_ptr;
394 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).@"fn".return_type.?).error_union.error_set!void = undefined;
395 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
396 resume global_frame;
397 try std.testing.expectError(error.Fail, result);
398 }
399 fn middle() callconv(.@"async") !void {
400 var f = async middle2();
401 return await f;
402 }
403
404 fn middle2() !void {
405 return failing();
406 }
407
408 fn failing() !void {
409 global_frame = @frame();
410 suspend {}
411 return error.Fail;
412 }
413 };
414 try S.doTheTest();
415}
416
417test "error return trace across suspend points - early return" {
418 if (true) return error.SkipZigTest; // TODO
419 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
420
421 const p = nonFailing();
422 resume p;
423 const p2 = async printTrace(p);
424 _ = p2;
425}
426
427test "error return trace across suspend points - async return" {
428 if (true) return error.SkipZigTest; // TODO
429 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
430
431 const p = nonFailing();
432 const p2 = async printTrace(p);
433 _ = p2;
434 resume p;
435}
436
437fn nonFailing() (anyframe->anyerror!void) {
438 const Static = struct {
439 var frame: @Frame(suspendThenFail) = undefined;
440 };
441 Static.frame = async suspendThenFail();
442 return &Static.frame;
443}
444fn suspendThenFail() callconv(.@"async") anyerror!void {
445 suspend {}
446 return error.Fail;
447}
448fn printTrace(p: anyframe->(anyerror!void)) callconv(.@"async") void {
449 (await p) catch |e| {
450 std.testing.expect(e == error.Fail) catch @panic("test failure");
451 if (@errorReturnTrace()) |trace| {
452 expect(trace.index == 1) catch @panic("test failure");
453 } else switch (builtin.mode) {
454 .Debug, .ReleaseSafe => @panic("expected return trace"),
455 .ReleaseFast, .ReleaseSmall => {},
456 }
457 };
458}
459
460test "break from suspend" {
461 if (true) return error.SkipZigTest; // TODO
462 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
463
464 var my_result: i32 = 1;
465 const p = async testBreakFromSuspend(&my_result);
466 _ = p;
467 try std.testing.expect(my_result == 2);
468}
469fn testBreakFromSuspend(my_result: *i32) callconv(.@"async") void {
470 suspend {
471 resume @frame();
472 }
473 my_result.* += 1;
474 suspend {}
475 my_result.* += 1;
476}
477
478test "heap allocated async function frame" {
479 if (true) return error.SkipZigTest; // TODO
480 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
481
482 const S = struct {
483 var x: i32 = 42;
484
485 fn doTheTest() !void {
486 const frame = try std.testing.allocator.create(@Frame(someFunc));
487 defer std.testing.allocator.destroy(frame);
488
489 try expect(x == 42);
490 frame.* = async someFunc();
491 try expect(x == 43);
492 resume frame;
493 try expect(x == 44);
494 }
495
496 fn someFunc() void {
497 x += 1;
498 suspend {}
499 x += 1;
500 }
501 };
502 try S.doTheTest();
503}
504
505test "async function call return value" {
506 if (true) return error.SkipZigTest; // TODO
507 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
508
509 const S = struct {
510 var frame: anyframe = undefined;
511 var pt = Point{ .x = 10, .y = 11 };
512
513 fn doTheTest() !void {
514 try expectEqual(pt.x, 10);
515 try expectEqual(pt.y, 11);
516 _ = async first();
517 try expectEqual(pt.x, 10);
518 try expectEqual(pt.y, 11);
519 resume frame;
520 try expectEqual(pt.x, 1);
521 try expectEqual(pt.y, 2);
522 }
523
524 fn first() void {
525 pt = second(1, 2);
526 }
527
528 fn second(x: i32, y: i32) Point {
529 return other(x, y);
530 }
531
532 fn other(x: i32, y: i32) Point {
533 frame = @frame();
534 suspend {}
535 return Point{
536 .x = x,
537 .y = y,
538 };
539 }
540
541 const Point = struct {
542 x: i32,
543 y: i32,
544 };
545 };
546 try S.doTheTest();
547}
548
549test "suspension points inside branching control flow" {
550 if (true) return error.SkipZigTest; // TODO
551 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
552
553 const S = struct {
554 var result: i32 = 10;
555
556 fn doTheTest() !void {
557 try expect(10 == result);
558 var frame = async func(true);
559 try expect(10 == result);
560 resume frame;
561 try expect(11 == result);
562 resume frame;
563 try expect(12 == result);
564 resume frame;
565 try expect(13 == result);
566 }
567
568 fn func(b: bool) void {
569 while (b) {
570 suspend {}
571 result += 1;
572 }
573 }
574 };
575 try S.doTheTest();
576}
577
578test "call async function which has struct return type" {
579 if (true) return error.SkipZigTest; // TODO
580 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
581
582 const S = struct {
583 var frame: anyframe = undefined;
584
585 fn doTheTest() void {
586 _ = async atest();
587 resume frame;
588 }
589
590 fn atest() void {
591 const result = func();
592 expect(result.x == 5) catch @panic("test failed");
593 expect(result.y == 6) catch @panic("test failed");
594 }
595
596 const Point = struct {
597 x: usize,
598 y: usize,
599 };
600
601 fn func() Point {
602 suspend {
603 frame = @frame();
604 }
605 return Point{
606 .x = 5,
607 .y = 6,
608 };
609 }
610 };
611 S.doTheTest();
612}
613
614test "pass string literal to async function" {
615 if (true) return error.SkipZigTest; // TODO
616 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
617
618 const S = struct {
619 var frame: anyframe = undefined;
620 var ok: bool = false;
621
622 fn doTheTest() !void {
623 _ = async hello("hello");
624 resume frame;
625 try expect(ok);
626 }
627
628 fn hello(msg: []const u8) void {
629 frame = @frame();
630 suspend {}
631 expectEqualStrings("hello", msg) catch @panic("test failed");
632 ok = true;
633 }
634 };
635 try S.doTheTest();
636}
637
638test "await inside an errdefer" {
639 if (true) return error.SkipZigTest; // TODO
640 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
641
642 const S = struct {
643 var frame: anyframe = undefined;
644
645 fn doTheTest() !void {
646 _ = async amainWrap();
647 resume frame;
648 }
649
650 fn amainWrap() !void {
651 var foo = async func();
652 errdefer await foo;
653 return error.Bad;
654 }
655
656 fn func() void {
657 frame = @frame();
658 suspend {}
659 }
660 };
661 try S.doTheTest();
662}
663
664test "try in an async function with error union and non-zero-bit payload" {
665 if (true) return error.SkipZigTest; // TODO
666 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
667
668 const S = struct {
669 var frame: anyframe = undefined;
670 var ok = false;
671
672 fn doTheTest() !void {
673 _ = async amain();
674 resume frame;
675 try expect(ok);
676 }
677
678 fn amain() void {
679 std.testing.expectError(error.Bad, theProblem()) catch @panic("test failed");
680 ok = true;
681 }
682
683 fn theProblem() ![]u8 {
684 frame = @frame();
685 suspend {}
686 const result = try other();
687 return result;
688 }
689
690 fn other() ![]u8 {
691 return error.Bad;
692 }
693 };
694 try S.doTheTest();
695}
696
697test "returning a const error from async function" {
698 if (true) return error.SkipZigTest; // TODO
699 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
700
701 const S = struct {
702 var frame: anyframe = undefined;
703 var ok = false;
704
705 fn doTheTest() !void {
706 _ = async amain();
707 resume frame;
708 try expect(ok);
709 }
710
711 fn amain() !void {
712 var download_frame = async fetchUrl(10, "a string");
713 const download_text = try await download_frame;
714 _ = download_text;
715
716 @panic("should not get here");
717 }
718
719 fn fetchUrl(unused: i32, url: []const u8) ![]u8 {
720 _ = unused;
721 _ = url;
722 frame = @frame();
723 suspend {}
724 ok = true;
725 return error.OutOfMemory;
726 }
727 };
728 try S.doTheTest();
729}
730
731test "async/await typical usage" {
732 if (true) return error.SkipZigTest; // TODO
733 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
734
735 inline for ([_]bool{ false, true }) |b1| {
736 inline for ([_]bool{ false, true }) |b2| {
737 inline for ([_]bool{ false, true }) |b3| {
738 inline for ([_]bool{ false, true }) |b4| {
739 testAsyncAwaitTypicalUsage(b1, b2, b3, b4).doTheTest();
740 }
741 }
742 }
743 }
744}
745
746fn testAsyncAwaitTypicalUsage(
747 comptime simulate_fail_download: bool,
748 comptime simulate_fail_file: bool,
749 comptime suspend_download: bool,
750 comptime suspend_file: bool,
751) type {
752 return struct {
753 fn doTheTest() void {
754 _ = async amainWrap();
755 if (suspend_file) {
756 resume global_file_frame;
757 }
758 if (suspend_download) {
759 resume global_download_frame;
760 }
761 }
762 fn amainWrap() void {
763 if (amain()) |_| {
764 expect(!simulate_fail_download) catch @panic("test failure");
765 expect(!simulate_fail_file) catch @panic("test failure");
766 } else |e| switch (e) {
767 error.NoResponse => expect(simulate_fail_download) catch @panic("test failure"),
768 error.FileNotFound => expect(simulate_fail_file) catch @panic("test failure"),
769 else => @panic("test failure"),
770 }
771 }
772
773 fn amain() !void {
774 const allocator = std.testing.allocator;
775 var download_frame = async fetchUrl(allocator, "https://example.com/");
776 var download_awaited = false;
777 errdefer if (!download_awaited) {
778 if (await download_frame) |x| allocator.free(x) else |_| {}
779 };
780
781 var file_frame = async readFile(allocator, "something.txt");
782 var file_awaited = false;
783 errdefer if (!file_awaited) {
784 if (await file_frame) |x| allocator.free(x) else |_| {}
785 };
786
787 download_awaited = true;
788 const download_text = try await download_frame;
789 defer allocator.free(download_text);
790
791 file_awaited = true;
792 const file_text = try await file_frame;
793 defer allocator.free(file_text);
794
795 try expect(std.mem.eql(u8, "expected download text", download_text));
796 try expect(std.mem.eql(u8, "expected file text", file_text));
797 }
798
799 var global_download_frame: anyframe = undefined;
800 fn fetchUrl(allocator: std.mem.Allocator, url: []const u8) anyerror![]u8 {
801 _ = url;
802 const result = try allocator.dupe(u8, "expected download text");
803 errdefer allocator.free(result);
804 if (suspend_download) {
805 suspend {
806 global_download_frame = @frame();
807 }
808 }
809 if (simulate_fail_download) return error.NoResponse;
810 return result;
811 }
812
813 var global_file_frame: anyframe = undefined;
814 fn readFile(allocator: std.mem.Allocator, filename: []const u8) anyerror![]u8 {
815 _ = filename;
816 const result = try allocator.dupe(u8, "expected file text");
817 errdefer allocator.free(result);
818 if (suspend_file) {
819 suspend {
820 global_file_frame = @frame();
821 }
822 }
823 if (simulate_fail_file) return error.FileNotFound;
824 return result;
825 }
826 };
827}
828
829test "alignment of local variables in async functions" {
830 if (true) return error.SkipZigTest; // TODO
831 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
832
833 const S = struct {
834 fn doTheTest() !void {
835 var y: u8 = 123;
836 _ = &y;
837 var x: u8 align(128) = 1;
838 try expect(@intFromPtr(&x) % 128 == 0);
839 }
840 };
841 try S.doTheTest();
842}
843
844test "no reason to resolve frame still works" {
845 if (true) return error.SkipZigTest; // TODO
846 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
847
848 _ = async simpleNothing();
849}
850fn simpleNothing() void {
851 var x: i32 = 1234;
852 _ = &x;
853}
854
855test "async call a generic function" {
856 if (true) return error.SkipZigTest; // TODO
857 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
858
859 const S = struct {
860 fn doTheTest() !void {
861 var f = async func(i32, 2);
862 const result = await f;
863 try expect(result == 3);
864 }
865
866 fn func(comptime T: type, inc: T) T {
867 var x: T = 1;
868 suspend {
869 resume @frame();
870 }
871 x += inc;
872 return x;
873 }
874 };
875 _ = async S.doTheTest();
876}
877
878test "return from suspend block" {
879 if (true) return error.SkipZigTest; // TODO
880 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
881
882 const S = struct {
883 fn doTheTest() !void {
884 expect(func() == 1234) catch @panic("test failure");
885 }
886 fn func() i32 {
887 suspend {
888 return 1234;
889 }
890 }
891 };
892 _ = async S.doTheTest();
893}
894
895test "struct parameter to async function is copied to the frame" {
896 if (true) return error.SkipZigTest; // TODO
897 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
898
899 const S = struct {
900 const Point = struct {
901 x: i32,
902 y: i32,
903 };
904
905 var frame: anyframe = undefined;
906
907 fn doTheTest() void {
908 _ = async atest();
909 resume frame;
910 }
911
912 fn atest() void {
913 var f: @Frame(foo) = undefined;
914 bar(&f);
915 clobberStack(10);
916 }
917
918 fn clobberStack(x: i32) void {
919 if (x == 0) return;
920 clobberStack(x - 1);
921 var y: i32 = x;
922 _ = &y;
923 }
924
925 fn bar(f: *@Frame(foo)) void {
926 var pt = Point{ .x = 1, .y = 2 };
927 _ = &pt;
928 f.* = async foo(pt);
929 const result = await f;
930 expect(result == 1) catch @panic("test failure");
931 }
932
933 fn foo(point: Point) i32 {
934 suspend {
935 frame = @frame();
936 }
937 return point.x;
938 }
939 };
940 S.doTheTest();
941}
942
943test "cast fn to async fn when it is inferred to be async" {
944 if (true) return error.SkipZigTest; // TODO
945 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
946
947 const S = struct {
948 var frame: anyframe = undefined;
949 var ok = false;
950
951 fn doTheTest() void {
952 var ptr: fn () callconv(.@"async") i32 = undefined;
953 ptr = func;
954 var buf: [100]u8 align(16) = undefined;
955 var result: i32 = undefined;
956 const f = @asyncCall(&buf, &result, ptr, .{});
957 _ = await f;
958 expect(result == 1234) catch @panic("test failure");
959 ok = true;
960 }
961
962 fn func() i32 {
963 suspend {
964 frame = @frame();
965 }
966 return 1234;
967 }
968 };
969 _ = async S.doTheTest();
970 resume S.frame;
971 try expect(S.ok);
972}
973
974test "cast fn to async fn when it is inferred to be async, awaited directly" {
975 if (true) return error.SkipZigTest; // TODO
976 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
977
978 const S = struct {
979 var frame: anyframe = undefined;
980 var ok = false;
981
982 fn doTheTest() void {
983 var ptr: fn () callconv(.@"async") i32 = undefined;
984 ptr = func;
985 var buf: [100]u8 align(16) = undefined;
986 var result: i32 = undefined;
987 _ = await @asyncCall(&buf, &result, ptr, .{});
988 expect(result == 1234) catch @panic("test failure");
989 ok = true;
990 }
991
992 fn func() i32 {
993 suspend {
994 frame = @frame();
995 }
996 return 1234;
997 }
998 };
999 _ = async S.doTheTest();
1000 resume S.frame;
1001 try expect(S.ok);
1002}
1003
1004test "await does not force async if callee is blocking" {
1005 if (true) return error.SkipZigTest; // TODO
1006 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1007
1008 const S = struct {
1009 fn simple() i32 {
1010 return 1234;
1011 }
1012 };
1013 var x = async S.simple();
1014 try expect(await x == 1234);
1015}
1016
1017test "recursive async function" {
1018 if (true) return error.SkipZigTest; // TODO
1019 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1020
1021 try expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
1022 try expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
1023}
1024
1025fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
1026 return struct {
1027 fn fib(allocator: std.mem.Allocator, x: u32) error{OutOfMemory}!u32 {
1028 if (x <= 1) return x;
1029
1030 if (suspending_implementation) {
1031 suspend {
1032 resume @frame();
1033 }
1034 }
1035
1036 const f1 = try allocator.create(@Frame(fib));
1037 defer allocator.destroy(f1);
1038
1039 const f2 = try allocator.create(@Frame(fib));
1040 defer allocator.destroy(f2);
1041
1042 f1.* = async fib(allocator, x - 1);
1043 var f1_awaited = false;
1044 errdefer if (!f1_awaited) {
1045 _ = await f1;
1046 };
1047
1048 f2.* = async fib(allocator, x - 2);
1049 var f2_awaited = false;
1050 errdefer if (!f2_awaited) {
1051 _ = await f2;
1052 };
1053
1054 var sum: u32 = 0;
1055
1056 f1_awaited = true;
1057 sum += try await f1;
1058
1059 f2_awaited = true;
1060 sum += try await f2;
1061
1062 return sum;
1063 }
1064
1065 fn doTheTest() u32 {
1066 if (suspending_implementation) {
1067 var result: u32 = undefined;
1068 _ = async amain(&result);
1069 return result;
1070 } else {
1071 return fib(std.testing.allocator, 10) catch unreachable;
1072 }
1073 }
1074
1075 fn amain(result: *u32) void {
1076 var x = async fib(std.testing.allocator, 10);
1077 result.* = (await x) catch unreachable;
1078 }
1079 };
1080}
1081
1082test "@asyncCall with comptime-known function, but not awaited directly" {
1083 if (true) return error.SkipZigTest; // TODO
1084 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1085
1086 const S = struct {
1087 var global_frame: anyframe = undefined;
1088
1089 fn doTheTest() !void {
1090 var frame: [1]@Frame(middle) = undefined;
1091 var result: @typeInfo(@typeInfo(@TypeOf(middle)).@"fn".return_type.?).error_union.error_set!void = undefined;
1092 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});
1093 resume global_frame;
1094 try std.testing.expectError(error.Fail, result);
1095 }
1096 fn middle() callconv(.@"async") !void {
1097 var f = async middle2();
1098 return await f;
1099 }
1100
1101 fn middle2() !void {
1102 return failing();
1103 }
1104
1105 fn failing() !void {
1106 global_frame = @frame();
1107 suspend {}
1108 return error.Fail;
1109 }
1110 };
1111 try S.doTheTest();
1112}
1113
1114test "@asyncCall with actual frame instead of byte buffer" {
1115 if (true) return error.SkipZigTest; // TODO
1116 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1117
1118 const S = struct {
1119 fn func() i32 {
1120 suspend {}
1121 return 1234;
1122 }
1123 };
1124 var frame: @Frame(S.func) = undefined;
1125 var result: i32 = undefined;
1126 const ptr = @asyncCall(&frame, &result, S.func, .{});
1127 resume ptr;
1128 try expect(result == 1234);
1129}
1130
1131test "@asyncCall using the result location inside the frame" {
1132 if (true) return error.SkipZigTest; // TODO
1133 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1134
1135 const S = struct {
1136 fn simple2(y: *i32) callconv(.@"async") i32 {
1137 defer y.* += 2;
1138 y.* += 1;
1139 suspend {}
1140 return 1234;
1141 }
1142 fn getAnswer(f: anyframe->i32, out: *i32) void {
1143 out.* = await f;
1144 }
1145 };
1146 var data: i32 = 1;
1147 const Foo = struct {
1148 bar: fn (*i32) callconv(.@"async") i32,
1149 };
1150 var foo = Foo{ .bar = S.simple2 };
1151 _ = &foo;
1152 var bytes: [64]u8 align(16) = undefined;
1153 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1154 comptime assert(@TypeOf(f) == anyframe->i32);
1155 try expect(data == 2);
1156 resume f;
1157 try expect(data == 4);
1158 _ = async S.getAnswer(f, &data);
1159 try expect(data == 1234);
1160}
1161
1162test "@TypeOf an async function call of generic fn with error union type" {
1163 if (true) return error.SkipZigTest; // TODO
1164 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1165
1166 const S = struct {
1167 fn func(comptime x: anytype) anyerror!i32 {
1168 const T = @TypeOf(async func(x));
1169 comptime assert(T == @typeInfo(@TypeOf(@frame())).pointer.child);
1170 return undefined;
1171 }
1172 };
1173 _ = async S.func(i32);
1174}
1175
1176test "using @TypeOf on a generic function call" {
1177 if (true) return error.SkipZigTest; // TODO
1178 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1179
1180 const S = struct {
1181 var global_frame: anyframe = undefined;
1182 var global_ok = false;
1183
1184 var buf: [100]u8 align(16) = undefined;
1185
1186 fn amain(x: anytype) void {
1187 if (x == 0) {
1188 global_ok = true;
1189 return;
1190 }
1191 suspend {
1192 global_frame = @frame();
1193 }
1194 const F = @TypeOf(async amain(x - 1));
1195 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
1196 return await @asyncCall(frame, {}, amain, .{x - 1});
1197 }
1198 };
1199 _ = async S.amain(@as(u32, 1));
1200 resume S.global_frame;
1201 try expect(S.global_ok);
1202}
1203
1204test "recursive call of await @asyncCall with struct return type" {
1205 if (true) return error.SkipZigTest; // TODO
1206 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1207
1208 const S = struct {
1209 var global_frame: anyframe = undefined;
1210 var global_ok = false;
1211
1212 var buf: [100]u8 align(16) = undefined;
1213
1214 fn amain(x: anytype) Foo {
1215 if (x == 0) {
1216 global_ok = true;
1217 return Foo{ .x = 1, .y = 2, .z = 3 };
1218 }
1219 suspend {
1220 global_frame = @frame();
1221 }
1222 const F = @TypeOf(async amain(x - 1));
1223 const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf)));
1224 return await @asyncCall(frame, {}, amain, .{x - 1});
1225 }
1226
1227 const Foo = struct {
1228 x: u64,
1229 y: u64,
1230 z: u64,
1231 };
1232 };
1233 var res: S.Foo = undefined;
1234 var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
1235 _ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)});
1236 resume S.global_frame;
1237 try expect(S.global_ok);
1238 try expect(res.x == 1);
1239 try expect(res.y == 2);
1240 try expect(res.z == 3);
1241}
1242
1243test "nosuspend function call" {
1244 if (true) return error.SkipZigTest; // TODO
1245 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1246
1247 const S = struct {
1248 fn doTheTest() !void {
1249 const result = nosuspend add(50, 100);
1250 try expect(result == 150);
1251 }
1252 fn add(a: i32, b: i32) i32 {
1253 if (a > 100) {
1254 suspend {}
1255 }
1256 return a + b;
1257 }
1258 };
1259 try S.doTheTest();
1260}
1261
1262test "await used in expression and awaiting fn with no suspend but async calling convention" {
1263 if (true) return error.SkipZigTest; // TODO
1264 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1265
1266 const S = struct {
1267 fn atest() void {
1268 var f1 = async add(1, 2);
1269 var f2 = async add(3, 4);
1270
1271 const sum = (await f1) + (await f2);
1272 expect(sum == 10) catch @panic("test failure");
1273 }
1274 fn add(a: i32, b: i32) callconv(.@"async") i32 {
1275 return a + b;
1276 }
1277 };
1278 _ = async S.atest();
1279}
1280
1281test "await used in expression after a fn call" {
1282 if (true) return error.SkipZigTest; // TODO
1283 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1284
1285 const S = struct {
1286 fn atest() void {
1287 var f1 = async add(3, 4);
1288 var sum: i32 = 0;
1289 sum = foo() + await f1;
1290 expect(sum == 8) catch @panic("test failure");
1291 }
1292 fn add(a: i32, b: i32) callconv(.@"async") i32 {
1293 return a + b;
1294 }
1295 fn foo() i32 {
1296 return 1;
1297 }
1298 };
1299 _ = async S.atest();
1300}
1301
1302test "async fn call used in expression after a fn call" {
1303 if (true) return error.SkipZigTest; // TODO
1304 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1305
1306 const S = struct {
1307 fn atest() void {
1308 var sum: i32 = 0;
1309 sum = foo() + add(3, 4);
1310 expect(sum == 8) catch @panic("test failure");
1311 }
1312 fn add(a: i32, b: i32) callconv(.@"async") i32 {
1313 return a + b;
1314 }
1315 fn foo() i32 {
1316 return 1;
1317 }
1318 };
1319 _ = async S.atest();
1320}
1321
1322test "suspend in for loop" {
1323 if (true) return error.SkipZigTest; // TODO
1324 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1325
1326 const S = struct {
1327 var global_frame: ?anyframe = null;
1328
1329 fn doTheTest() void {
1330 _ = async atest();
1331 while (global_frame) |f| resume f;
1332 }
1333
1334 fn atest() void {
1335 expect(func(&[_]u8{ 1, 2, 3 }) == 6) catch @panic("test failure");
1336 }
1337 fn func(stuff: []const u8) u32 {
1338 global_frame = @frame();
1339 var sum: u32 = 0;
1340 for (stuff) |x| {
1341 suspend {}
1342 sum += x;
1343 }
1344 global_frame = null;
1345 return sum;
1346 }
1347 };
1348 S.doTheTest();
1349}
1350
1351test "suspend in while loop" {
1352 if (true) return error.SkipZigTest; // TODO
1353 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1354
1355 const S = struct {
1356 var global_frame: ?anyframe = null;
1357
1358 fn doTheTest() void {
1359 _ = async atest();
1360 while (global_frame) |f| resume f;
1361 }
1362
1363 fn atest() void {
1364 expect(optional(6) == 6) catch @panic("test failure");
1365 expect(errunion(6) == 6) catch @panic("test failure");
1366 }
1367 fn optional(stuff: ?u32) u32 {
1368 global_frame = @frame();
1369 defer global_frame = null;
1370 while (stuff) |val| {
1371 suspend {}
1372 return val;
1373 }
1374 return 0;
1375 }
1376 fn errunion(stuff: anyerror!u32) u32 {
1377 global_frame = @frame();
1378 defer global_frame = null;
1379 while (stuff) |val| {
1380 suspend {}
1381 return val;
1382 } else |err| {
1383 err catch {};
1384 return 0;
1385 }
1386 }
1387 };
1388 S.doTheTest();
1389}
1390
1391test "correctly spill when returning the error union result of another async fn" {
1392 if (true) return error.SkipZigTest; // TODO
1393 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1394
1395 const S = struct {
1396 var global_frame: anyframe = undefined;
1397
1398 fn doTheTest() !void {
1399 expect((atest() catch unreachable) == 1234) catch @panic("test failure");
1400 }
1401
1402 fn atest() !i32 {
1403 return fallible1();
1404 }
1405
1406 fn fallible1() anyerror!i32 {
1407 suspend {
1408 global_frame = @frame();
1409 }
1410 return 1234;
1411 }
1412 };
1413 _ = async S.doTheTest();
1414 resume S.global_frame;
1415}
1416
1417test "spill target expr in a for loop" {
1418 if (true) return error.SkipZigTest; // TODO
1419 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1420
1421 const S = struct {
1422 var global_frame: anyframe = undefined;
1423
1424 fn doTheTest() !void {
1425 var foo = Foo{
1426 .slice = &[_]i32{ 1, 2 },
1427 };
1428 expect(atest(&foo) == 3) catch @panic("test failure");
1429 }
1430
1431 const Foo = struct {
1432 slice: []const i32,
1433 };
1434
1435 fn atest(foo: *Foo) i32 {
1436 var sum: i32 = 0;
1437 for (foo.slice) |x| {
1438 suspend {
1439 global_frame = @frame();
1440 }
1441 sum += x;
1442 }
1443 return sum;
1444 }
1445 };
1446 _ = async S.doTheTest();
1447 resume S.global_frame;
1448 resume S.global_frame;
1449}
1450
1451test "spill target expr in a for loop, with a var decl in the loop body" {
1452 if (true) return error.SkipZigTest; // TODO
1453 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1454
1455 const S = struct {
1456 var global_frame: anyframe = undefined;
1457
1458 fn doTheTest() !void {
1459 var foo = Foo{
1460 .slice = &[_]i32{ 1, 2 },
1461 };
1462 expect(atest(&foo) == 3) catch @panic("test failure");
1463 }
1464
1465 const Foo = struct {
1466 slice: []const i32,
1467 };
1468
1469 fn atest(foo: *Foo) i32 {
1470 var sum: i32 = 0;
1471 for (foo.slice) |x| {
1472 // Previously this var decl would prevent spills. This test makes sure
1473 // the for loop spills still happen even though there is a VarDecl in scope
1474 // before the suspend.
1475 var anything = true;
1476 _ = &anything;
1477 suspend {
1478 global_frame = @frame();
1479 }
1480 sum += x;
1481 }
1482 return sum;
1483 }
1484 };
1485 _ = async S.doTheTest();
1486 resume S.global_frame;
1487 resume S.global_frame;
1488}
1489
1490test "async call with @call" {
1491 if (true) return error.SkipZigTest; // TODO
1492 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1493
1494 const S = struct {
1495 var global_frame: anyframe = undefined;
1496 fn doTheTest() void {
1497 _ = @call(.{ .modifier = .async_kw }, atest, .{});
1498 resume global_frame;
1499 }
1500 fn atest() void {
1501 var frame = @call(.{ .modifier = .async_kw }, afoo, .{});
1502 const res = await frame;
1503 expect(res == 42) catch @panic("test failure");
1504 }
1505 fn afoo() i32 {
1506 suspend {
1507 global_frame = @frame();
1508 }
1509 return 42;
1510 }
1511 };
1512 S.doTheTest();
1513}
1514
1515test "async function passed 0-bit arg after non-0-bit arg" {
1516 if (true) return error.SkipZigTest; // TODO
1517 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1518
1519 const S = struct {
1520 var global_frame: anyframe = undefined;
1521 var global_int: i32 = 0;
1522
1523 fn foo() void {
1524 bar(1, .{}) catch unreachable;
1525 }
1526
1527 fn bar(x: i32, args: anytype) anyerror!void {
1528 _ = args;
1529 global_frame = @frame();
1530 suspend {}
1531 global_int = x;
1532 }
1533 };
1534 _ = async S.foo();
1535 resume S.global_frame;
1536 try expect(S.global_int == 1);
1537}
1538
1539test "async function passed align(16) arg after align(8) arg" {
1540 if (true) return error.SkipZigTest; // TODO
1541 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1542
1543 const S = struct {
1544 var global_frame: anyframe = undefined;
1545 var global_int: u128 = 0;
1546
1547 fn foo() void {
1548 var a: u128 = 99;
1549 _ = &a;
1550 bar(10, .{a}) catch unreachable;
1551 }
1552
1553 fn bar(x: u64, args: anytype) anyerror!void {
1554 try expect(x == 10);
1555 global_frame = @frame();
1556 suspend {}
1557 global_int = args[0];
1558 }
1559 };
1560 _ = async S.foo();
1561 resume S.global_frame;
1562 try expect(S.global_int == 99);
1563}
1564
1565test "async function call resolves target fn frame, comptime func" {
1566 if (true) return error.SkipZigTest; // TODO
1567 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1568
1569 const S = struct {
1570 var global_frame: anyframe = undefined;
1571 var global_int: i32 = 9;
1572
1573 fn foo() anyerror!void {
1574 const stack_size = 1000;
1575 var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined;
1576 return await @asyncCall(&stack_frame, {}, bar, .{});
1577 }
1578
1579 fn bar() anyerror!void {
1580 global_frame = @frame();
1581 suspend {}
1582 global_int += 1;
1583 }
1584 };
1585 _ = async S.foo();
1586 resume S.global_frame;
1587 try expect(S.global_int == 10);
1588}
1589
1590test "async function call resolves target fn frame, runtime func" {
1591 if (true) return error.SkipZigTest; // TODO
1592 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1593
1594 const S = struct {
1595 var global_frame: anyframe = undefined;
1596 var global_int: i32 = 9;
1597
1598 fn foo() anyerror!void {
1599 const stack_size = 1000;
1600 var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined;
1601 var func: fn () callconv(.@"async") anyerror!void = bar;
1602 _ = &func;
1603 return await @asyncCall(&stack_frame, {}, func, .{});
1604 }
1605
1606 fn bar() anyerror!void {
1607 global_frame = @frame();
1608 suspend {}
1609 global_int += 1;
1610 }
1611 };
1612 _ = async S.foo();
1613 resume S.global_frame;
1614 try expect(S.global_int == 10);
1615}
1616
1617test "properly spill optional payload capture value" {
1618 if (true) return error.SkipZigTest; // TODO
1619 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1620
1621 const S = struct {
1622 var global_frame: anyframe = undefined;
1623 var global_int: usize = 2;
1624
1625 fn foo() void {
1626 var opt: ?usize = 1234;
1627 _ = &opt;
1628 if (opt) |x| {
1629 bar();
1630 global_int += x;
1631 }
1632 }
1633
1634 fn bar() void {
1635 global_frame = @frame();
1636 suspend {}
1637 global_int += 1;
1638 }
1639 };
1640 _ = async S.foo();
1641 resume S.global_frame;
1642 try expect(S.global_int == 1237);
1643}
1644
1645test "handle defer interfering with return value spill" {
1646 if (true) return error.SkipZigTest; // TODO
1647 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1648
1649 const S = struct {
1650 var global_frame1: anyframe = undefined;
1651 var global_frame2: anyframe = undefined;
1652 var finished = false;
1653 var baz_happened = false;
1654
1655 fn doTheTest() !void {
1656 _ = async testFoo();
1657 resume global_frame1;
1658 resume global_frame2;
1659 try expect(baz_happened);
1660 try expect(finished);
1661 }
1662
1663 fn testFoo() void {
1664 expectError(error.Bad, foo()) catch @panic("test failure");
1665 finished = true;
1666 }
1667
1668 fn foo() anyerror!void {
1669 defer baz();
1670 return bar() catch |err| return err;
1671 }
1672
1673 fn bar() anyerror!void {
1674 global_frame1 = @frame();
1675 suspend {}
1676 return error.Bad;
1677 }
1678
1679 fn baz() void {
1680 global_frame2 = @frame();
1681 suspend {}
1682 baz_happened = true;
1683 }
1684 };
1685 try S.doTheTest();
1686}
1687
1688test "take address of temporary async frame" {
1689 if (true) return error.SkipZigTest; // TODO
1690 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1691
1692 const S = struct {
1693 var global_frame: anyframe = undefined;
1694 var finished = false;
1695
1696 fn doTheTest() !void {
1697 _ = async asyncDoTheTest();
1698 resume global_frame;
1699 try expect(finished);
1700 }
1701
1702 fn asyncDoTheTest() void {
1703 expect(finishIt(&async foo(10)) == 1245) catch @panic("test failure");
1704 finished = true;
1705 }
1706
1707 fn foo(arg: i32) i32 {
1708 global_frame = @frame();
1709 suspend {}
1710 return arg + 1234;
1711 }
1712
1713 fn finishIt(frame: anyframe->i32) i32 {
1714 return (await frame) + 1;
1715 }
1716 };
1717 try S.doTheTest();
1718}
1719
1720test "nosuspend await" {
1721 if (true) return error.SkipZigTest; // TODO
1722 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1723
1724 const S = struct {
1725 var finished = false;
1726
1727 fn doTheTest() !void {
1728 var frame = async foo(false);
1729 try expect(nosuspend await frame == 42);
1730 finished = true;
1731 }
1732
1733 fn foo(want_suspend: bool) i32 {
1734 if (want_suspend) {
1735 suspend {}
1736 }
1737 return 42;
1738 }
1739 };
1740 try S.doTheTest();
1741 try expect(S.finished);
1742}
1743
1744test "nosuspend on function calls" {
1745 if (true) return error.SkipZigTest; // TODO
1746 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1747
1748 const S0 = struct {
1749 b: i32 = 42,
1750 };
1751 const S1 = struct {
1752 fn c() S0 {
1753 return S0{};
1754 }
1755 fn d() !S0 {
1756 return S0{};
1757 }
1758 };
1759 try expectEqual(@as(i32, 42), nosuspend S1.c().b);
1760 try expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
1761}
1762
1763test "nosuspend on async function calls" {
1764 if (true) return error.SkipZigTest; // TODO
1765 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1766
1767 const S0 = struct {
1768 b: i32 = 42,
1769 };
1770 const S1 = struct {
1771 fn c() S0 {
1772 return S0{};
1773 }
1774 fn d() !S0 {
1775 return S0{};
1776 }
1777 };
1778 var frame_c = nosuspend async S1.c();
1779 try expectEqual(@as(i32, 42), (await frame_c).b);
1780 var frame_d = nosuspend async S1.d();
1781 try expectEqual(@as(i32, 42), (try await frame_d).b);
1782}
1783
1784// test "resume nosuspend async function calls" {
1785// if (true) return error.SkipZigTest; // if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1786// const S0 = struct {
1787// b: i32 = 42,
1788// };
1789// const S1 = struct {
1790// fn c() S0 {
1791// suspend {}
1792// return S0{};
1793// }
1794// fn d() !S0 {
1795// suspend {}
1796// return S0{};
1797// }
1798// };
1799// var frame_c = nosuspend async S1.c();
1800// resume frame_c;
1801// try expectEqual(@as(i32, 42), (await frame_c).b);
1802// var frame_d = nosuspend async S1.d();
1803// resume frame_d;
1804// try expectEqual(@as(i32, 42), (try await frame_d).b);
1805// }
1806
1807test "nosuspend resume async function calls" {
1808 if (true) return error.SkipZigTest; // TODO
1809 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1810
1811 const S0 = struct {
1812 b: i32 = 42,
1813 };
1814 const S1 = struct {
1815 fn c() S0 {
1816 suspend {}
1817 return S0{};
1818 }
1819 fn d() !S0 {
1820 suspend {}
1821 return S0{};
1822 }
1823 };
1824 var frame_c = async S1.c();
1825 nosuspend resume frame_c;
1826 try expectEqual(@as(i32, 42), (await frame_c).b);
1827 var frame_d = async S1.d();
1828 nosuspend resume frame_d;
1829 try expectEqual(@as(i32, 42), (try await frame_d).b);
1830}
1831
1832test "avoid forcing frame alignment resolution implicit cast to *anyopaque" {
1833 if (true) return error.SkipZigTest; // TODO
1834 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1835
1836 const S = struct {
1837 var x: ?*anyopaque = null;
1838
1839 fn foo() bool {
1840 suspend {
1841 x = @frame();
1842 }
1843 return true;
1844 }
1845 };
1846 var frame = async S.foo();
1847 resume @as(anyframe->bool, @ptrCast(@alignCast(S.x)));
1848 try expect(nosuspend await frame);
1849}
1850
1851test "@asyncCall with pass-by-value arguments" {
1852 if (true) return error.SkipZigTest; // TODO
1853 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1854
1855 const F0: u64 = 0xbeefbeefbeefbeef;
1856 const F1: u64 = 0xf00df00df00df00d;
1857 const F2: u64 = 0xcafecafecafecafe;
1858
1859 const S = struct {
1860 pub const ST = struct { f0: usize, f1: usize };
1861 pub const AT = [5]u8;
1862
1863 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.@"async") void {
1864 _ = s;
1865 _ = a;
1866 // Check that the array and struct arguments passed by value don't
1867 // end up overflowing the adjacent fields in the frame structure.
1868 expectEqual(F0, _fill0) catch @panic("test failure");
1869 expectEqual(F1, _fill1) catch @panic("test failure");
1870 expectEqual(F2, _fill2) catch @panic("test failure");
1871 }
1872 };
1873
1874 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
1875 // The function pointer must not be comptime-known.
1876 var t = S.f;
1877 _ = &t;
1878 var frame_ptr = @asyncCall(&buffer, {}, t, .{
1879 F0,
1880 .{ .f0 = 1, .f1 = 2 },
1881 F1,
1882 [_]u8{ 1, 2, 3, 4, 5 },
1883 F2,
1884 });
1885 _ = &frame_ptr;
1886}
1887
1888test "@asyncCall with arguments having non-standard alignment" {
1889 if (true) return error.SkipZigTest; // TODO
1890 if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO
1891
1892 const F0: u64 = 0xbeefbeef;
1893 const F1: u64 = 0xf00df00df00df00d;
1894
1895 const S = struct {
1896 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.@"async") void {
1897 _ = s;
1898 // The compiler inserts extra alignment for s, check that the
1899 // generated code picks the right slot for fill1.
1900 expectEqual(F0, _fill0) catch @panic("test failure");
1901 expectEqual(F1, _fill1) catch @panic("test failure");
1902 }
1903 };
1904
1905 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
1906 // The function pointer must not be comptime-known.
1907 var t = S.f;
1908 _ = &t;
1909 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });
1910 _ = &frame_ptr;
1911}
test/behavior/await_struct.zig deleted-47
......@@ -1,47 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
4
5const Foo = struct {
6 x: i32,
7};
8
9var await_a_promise: anyframe = undefined;
10var await_final_result = Foo{ .x = 0 };
11
12test "coroutine await struct" {
13 if (true) return error.SkipZigTest; // TODO
14
15 await_seq('a');
16 var p = async await_amain();
17 _ = &p;
18 await_seq('f');
19 resume await_a_promise;
20 await_seq('i');
21 try expect(await_final_result.x == 1234);
22 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
23}
24fn await_amain() callconv(.@"async") void {
25 await_seq('b');
26 var p = async await_another();
27 await_seq('e');
28 await_final_result = await p;
29 await_seq('h');
30}
31fn await_another() callconv(.@"async") Foo {
32 await_seq('c');
33 suspend {
34 await_seq('d');
35 await_a_promise = @frame();
36 }
37 await_seq('g');
38 return Foo{ .x = 1234 };
39}
40
41var await_points = [_]u8{0} ** "abcdefghi".len;
42var await_seq_index: usize = 0;
43
44fn await_seq(c: u8) void {
45 await_points[await_seq_index] = c;
46 await_seq_index += 1;
47}
test/behavior/basic.zig-21
......@@ -1107,27 +1107,6 @@ test "inline call of function with a switch inside the return statement" {
11071107 try expect(S.foo(1) == 1);
11081108}
11091109
1110test "ambiguous reference error ignores current declaration" {
1111 const S = struct {
1112 const foo = 666;
1113
1114 const a = @This();
1115 const b = struct {
1116 const foo = a.foo;
1117 const bar = struct {
1118 bar: u32 = b.foo,
1119 };
1120
1121 comptime {
1122 _ = b.foo;
1123 }
1124 };
1125
1126 usingnamespace b;
1127 };
1128 try expect(S.b.foo == 666);
1129}
1130
11311110test "pointer to zero sized global is mutable" {
11321111 const S = struct {
11331112 const Thing = struct {};
test/behavior/call.zig+3-26
......@@ -37,7 +37,7 @@ test "basic invocations" {
3737 comptime {
3838 // comptime calls with supported modifiers
3939 try expect(@call(.auto, foo, .{2}) == 1234);
40 try expect(@call(.no_async, foo, .{3}) == 1234);
40 try expect(@call(.no_suspend, foo, .{3}) == 1234);
4141 try expect(@call(.always_tail, foo, .{4}) == 1234);
4242 try expect(@call(.always_inline, foo, .{5}) == 1234);
4343 }
......@@ -45,7 +45,7 @@ test "basic invocations" {
4545 const result = @call(.compile_time, foo, .{6}) == 1234;
4646 comptime assert(result);
4747 // runtime calls of comptime-known function
48 try expect(@call(.no_async, foo, .{7}) == 1234);
48 try expect(@call(.no_suspend, foo, .{7}) == 1234);
4949 try expect(@call(.never_tail, foo, .{8}) == 1234);
5050 try expect(@call(.never_inline, foo, .{9}) == 1234);
5151 // CBE does not support attributes on runtime functions
......@@ -53,7 +53,7 @@ test "basic invocations" {
5353 // runtime calls of non comptime-known function
5454 var alias_foo = &foo;
5555 _ = &alias_foo;
56 try expect(@call(.no_async, alias_foo, .{10}) == 1234);
56 try expect(@call(.no_suspend, alias_foo, .{10}) == 1234);
5757 try expect(@call(.never_tail, alias_foo, .{11}) == 1234);
5858 try expect(@call(.never_inline, alias_foo, .{12}) == 1234);
5959 }
......@@ -507,29 +507,6 @@ test "call inline fn through pointer" {
507507 try f(123);
508508}
509509
510test "call coerced function" {
511 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
512
513 const T = struct {
514 x: f64,
515 const T = @This();
516 usingnamespace Implement(1);
517 const F = fn (comptime f64) type;
518 const Implement: F = opaque {
519 fn implementer(comptime val: anytype) type {
520 return opaque {
521 fn incr(self: T) T {
522 return .{ .x = self.x + val };
523 }
524 };
525 }
526 }.implementer;
527 };
528
529 const a = T{ .x = 3 };
530 try std.testing.expect(a.incr().x == 4);
531}
532
533510test "call function in comptime field" {
534511 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
535512
test/behavior/import.zig-10
......@@ -18,16 +18,6 @@ test "importing the same thing gives the same import" {
1818 try expect(@import("std") == @import("std"));
1919}
2020
21test "import in non-toplevel scope" {
22 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
23 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
24
25 const S = struct {
26 usingnamespace @import("import/a_namespace.zig");
27 };
28 try expect(@as(i32, 1234) == S.foo());
29}
30
3121test "import empty file" {
3222 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
3323 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
test/behavior/struct.zig-11
......@@ -236,17 +236,6 @@ test "call method with mutable reference to struct with no fields" {
236236 try expect(s.do());
237237}
238238
239test "usingnamespace within struct scope" {
240 const S = struct {
241 usingnamespace struct {
242 pub fn inner() i32 {
243 return 42;
244 }
245 };
246 };
247 try expect(@as(i32, 42) == S.inner());
248}
249
250239test "struct field init with catch" {
251240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
252241 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/type_info.zig-83
......@@ -592,24 +592,6 @@ test "StructField.is_comptime" {
592592 try expect(info.fields[1].is_comptime);
593593}
594594
595test "typeInfo resolves usingnamespace declarations" {
596 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
597
598 const A = struct {
599 pub const f1 = 42;
600 };
601
602 const B = struct {
603 pub const f0 = 42;
604 pub usingnamespace A;
605 };
606
607 const decls = @typeInfo(B).@"struct".decls;
608 try expect(decls.len == 2);
609 try expectEqualStrings(decls[0].name, "f0");
610 try expectEqualStrings(decls[1].name, "f1");
611}
612
613595test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
614596 comptime {
615597 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr;
......@@ -617,77 +599,12 @@ test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
617599 }
618600}
619601
620test "@typeInfo decls and usingnamespace" {
621 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
622 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
623 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
624
625 const A = struct {
626 pub const x = 5;
627 pub const y = 34;
628
629 comptime {}
630 };
631 const B = struct {
632 pub usingnamespace A;
633 pub const z = 56;
634
635 test {}
636 };
637 const decls = @typeInfo(B).@"struct".decls;
638 try expect(decls.len == 3);
639 try expectEqualStrings(decls[0].name, "z");
640 try expectEqualStrings(decls[1].name, "x");
641 try expectEqualStrings(decls[2].name, "y");
642}
643
644test "@typeInfo decls ignore dependency loops" {
645 const S = struct {
646 pub fn Def(comptime T: type) type {
647 std.debug.assert(@typeInfo(T).@"struct".decls.len == 1);
648 return struct {
649 const foo = u32;
650 };
651 }
652 usingnamespace Def(@This());
653 };
654 _ = S.foo;
655}
656
657602test "type info of tuple of string literal default value" {
658603 const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];
659604 const value = struct_field.defaultValue().?;
660605 comptime std.debug.assert(value[0] == 'h');
661606}
662607
663test "@typeInfo only contains pub decls" {
664 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
665
666 const other = struct {
667 const std = @import("std");
668
669 usingnamespace struct {
670 pub const inside_non_pub_usingnamespace = 0;
671 };
672
673 pub const Enum = enum {
674 a,
675 b,
676 c,
677 };
678
679 pub const Struct = struct {
680 foo: i32,
681 };
682 };
683 const ti = @typeInfo(other);
684 const decls = ti.@"struct".decls;
685
686 try std.testing.expectEqual(2, decls.len);
687 try std.testing.expectEqualStrings("Enum", decls[0].name);
688 try std.testing.expectEqualStrings("Struct", decls[1].name);
689}
690
691608test "@typeInfo function with generic return type and inferred error set" {
692609 const S = struct {
693610 fn testFn(comptime T: type) !T {}
test/behavior/usingnamespace.zig deleted-125
......@@ -1,125 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
4
5const A = struct {
6 pub const B = bool;
7};
8
9const C = struct {
10 usingnamespace A;
11};
12
13test "basic usingnamespace" {
14 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
15 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
16
17 try std.testing.expect(C.B == bool);
18}
19
20fn Foo(comptime T: type) type {
21 return struct {
22 usingnamespace T;
23 };
24}
25
26test "usingnamespace inside a generic struct" {
27 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
29
30 const std2 = Foo(std);
31 const testing2 = Foo(std.testing);
32 try std2.testing.expect(true);
33 try testing2.expect(true);
34}
35
36usingnamespace struct {
37 pub const foo = 42;
38};
39
40test "usingnamespace does not redeclare an imported variable" {
41 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
42 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
43
44 try comptime std.testing.expect(@This().foo == 42);
45}
46
47usingnamespace @import("usingnamespace/foo.zig");
48test "usingnamespace omits mixing in private functions" {
49 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
50 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
51 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
52 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
53
54 try expect(@This().privateFunction());
55 try expect(!@This().printText());
56}
57fn privateFunction() bool {
58 return true;
59}
60
61test {
62 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
63 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
64
65 _ = @import("usingnamespace/import_segregation.zig");
66}
67
68usingnamespace @import("usingnamespace/a.zig");
69test "two files usingnamespace import each other" {
70 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
71 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
72 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
73 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
74
75 try expect(@This().ok());
76}
77
78test {
79 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
80 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
81 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
82 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
83
84 const AA = struct {
85 x: i32,
86 fn b(x: i32) @This() {
87 return .{ .x = x };
88 }
89 fn c() type {
90 return if (true) struct {
91 const expected: i32 = 42;
92 } else struct {};
93 }
94 usingnamespace c();
95 };
96 const a = AA.b(42);
97 try expect(a.x == AA.c().expected);
98}
99
100const Bar = struct {
101 usingnamespace Mixin;
102};
103
104const Mixin = struct {
105 pub fn two(self: Bar) void {
106 _ = self;
107 }
108};
109
110test "container member access usingnamespace decls" {
111 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
112 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
113
114 var foo = Bar{};
115 foo.two();
116}
117
118usingnamespace opaque {};
119
120usingnamespace @Type(.{ .@"struct" = .{
121 .layout = .auto,
122 .fields = &.{},
123 .decls = &.{},
124 .is_tuple = false,
125} });
test/behavior/usingnamespace/a.zig deleted-7
......@@ -1,7 +0,0 @@
1usingnamespace @import("b.zig");
2
3pub const a_text = "OK\n";
4
5pub fn ok() bool {
6 return @import("std").mem.eql(u8, @This().b_text, "OK\n");
7}
test/behavior/usingnamespace/b.zig deleted-3
......@@ -1,3 +0,0 @@
1usingnamespace @import("a.zig");
2
3pub const b_text = @This().a_text;
test/behavior/usingnamespace/bar.zig deleted-8
......@@ -1,8 +0,0 @@
1usingnamespace @import("other.zig");
2
3pub var saw_bar_function = false;
4pub fn bar_function() void {
5 if (@This().foo_function()) {
6 saw_bar_function = true;
7 }
8}
test/behavior/usingnamespace/foo.zig deleted-14
......@@ -1,14 +0,0 @@
1// purposefully conflicting function with main source file
2// but it's private so it should be OK
3fn privateFunction() bool {
4 return false;
5}
6
7pub fn printText() bool {
8 return privateFunction();
9}
10
11pub var saw_foo_function = false;
12pub fn foo_function() void {
13 saw_foo_function = true;
14}
test/behavior/usingnamespace/import_segregation.zig deleted-20
......@@ -1,20 +0,0 @@
1const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
3
4usingnamespace @import("foo.zig");
5usingnamespace @import("bar.zig");
6
7test "no clobbering happened" {
8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
9 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
10
11 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) {
12 // https://github.com/ziglang/zig/issues/16846
13 return error.SkipZigTest;
14 }
15
16 @This().foo_function();
17 @This().bar_function();
18 try expect(@This().saw_foo_function);
19 try expect(@This().saw_bar_function);
20}
test/behavior/usingnamespace/other.zig deleted-4
......@@ -1,4 +0,0 @@
1pub fn foo_function() bool {
2 // this one conflicts with the one from foo
3 return true;
4}
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.@"async") void {
5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = &x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.@"async") void {
5 other();
6}
7fn other() void {
8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = &x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:1: error: unable to determine async function frame of 'amain'
17// tmp.zig:5:10: note: analysis of function 'other' depends on the frame
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn a() void {
2 const f = async func();
3 resume f;
4}
5export fn b() void {
6 const f = async func();
7 var x: anyframe = &f;
8 _ = &x;
9}
10fn func() void {
11 suspend {}
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'
19// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'
test/cases/compile_errors/async/function_with_ccc_indirectly_calling_async_function.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 foo();
3}
4fn foo() void {
5 bar();
6}
7fn bar() void {
8 suspend {}
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
16// tmp.zig:2:8: note: async function call here
17// tmp.zig:5:8: note: async function call here
18// tmp.zig:8:5: note: suspends here
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig deleted-36
......@@ -1,36 +0,0 @@
1var frame: ?anyframe = null;
2
3export fn a() void {
4 _ = async rangeSum(10);
5 while (frame) |f| resume f;
6}
7
8fn rangeSum(x: i32) i32 {
9 suspend {
10 frame = @frame();
11 }
12 frame = null;
13
14 if (x == 0) return 0;
15 const child = rangeSumIndirect(x - 1);
16 return child + 1;
17}
18
19fn rangeSumIndirect(x: i32) i32 {
20 suspend {
21 frame = @frame();
22 }
23 frame = null;
24
25 if (x == 0) return 0;
26 const child = rangeSum(x - 1);
27 return child + 1;
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
35// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var frame = async func();
3 var result = await frame;
4 _ = &result;
5}
6fn func() void {
7 suspend {}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
15// tmp.zig:3:18: note: await here is a suspend point
test/cases/compile_errors/async/returning_error_from_void_async_function.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.@"async") void {
5 return error.ShouldBeCompileError;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'
test/cases/compile_errors/async/runtime-known_async_function_called.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() void {
5 var ptr = afunc;
6 _ = ptr();
7 _ = &ptr;
8}
9fn afunc() callconv(.@"async") void {}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 var ptr = afunc;
3 _ = async ptr();
4 _ = &ptr;
5}
6
7fn afunc() callconv(.@"async") void {}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required
test/cases/compile_errors/async/wrong_frame_type_used_for_async_call.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 var frame: @Frame(foo) = undefined;
3 frame = async bar();
4}
5fn foo() void {
6 suspend {}
7}
8fn bar() void {
9 suspend {}
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'
test/cases/compile_errors/async/wrong_type_for_result_ptr_to_asyncCall.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() i32 {
5 var frame: @Frame(foo) = undefined;
6 return await @asyncCall(&frame, false, foo, .{});
7}
8fn foo() i32 {
9 return 1234;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:37: error: expected type '*i32', found 'bool'
test/cases/compile_errors/bad_usingnamespace_transitive_failure.zig deleted-31
......@@ -1,31 +0,0 @@
1//! The full test name would be:
2//! struct field type resolution marks transitive error from bad usingnamespace in @typeInfo call from non-initial field type
3//!
4//! This test is rather esoteric. It's ensuring that errors triggered by `@typeInfo` analyzing
5//! a bad `usingnamespace` correctly trigger transitive errors when analyzed by struct field type
6//! resolution, meaning we don't incorrectly analyze code past the uses of `S`.
7
8const S = struct {
9 ok: u32,
10 bad: @typeInfo(T),
11};
12
13const T = struct {
14 pub usingnamespace @compileError("usingnamespace analyzed");
15};
16
17comptime {
18 const a: S = .{ .ok = 123, .bad = undefined };
19 _ = a;
20 @compileError("should not be reached");
21}
22
23comptime {
24 const b: S = .{ .ok = 123, .bad = undefined };
25 _ = b;
26 @compileError("should not be reached");
27}
28
29// error
30//
31// :14:24: error: usingnamespace analyzed
test/cases/compile_errors/combination_of_nosuspend_and_async.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 nosuspend {
3 const bar = async foo();
4 suspend {}
5 resume bar;
6 }
7}
8fn foo() void {}
9
10// error
11// backend=stage2
12// target=native
13//
14// :4:9: error: suspend inside nosuspend block
15// :2:5: note: nosuspend block here
test/cases/compile_errors/suspend_inside_suspend_block.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 _ = async foo();
3}
4fn foo() void {
5 suspend {
6 suspend {}
7 }
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :6:9: error: cannot suspend inside suspend block
15// :5:5: note: other suspend block here
test/cases/compile_errors/usingnamespace_with_wrong_type.zig deleted-7
......@@ -1,7 +0,0 @@
1usingnamespace void;
2
3// error
4// backend=stage2
5// target=native
6//
7// :1:16: error: type void has no namespace
test/cases/safety/@asyncCall with too small a frame.zig deleted-26
......@@ -1,26 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
5 _ = message;
6 _ = stack_trace;
7 std.process.exit(0);
8}
9pub fn main() !void {
10 if (builtin.zig_backend == .stage1 and builtin.os.tag == .wasi) {
11 // TODO file a bug for this failure
12 std.process.exit(0); // skip the test
13 }
14 var bytes: [1]u8 align(16) = undefined;
15 var ptr = other;
16 _ = &ptr;
17 var frame = @asyncCall(&bytes, {}, ptr, .{});
18 _ = &frame;
19 return error.TestFailed;
20}
21fn other() callconv(.@"async") void {
22 suspend {}
23}
24// run
25// backend=stage1
26// target=native
test/cases/safety/awaiting twice.zig deleted-29
......@@ -1,29 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8var frame: anyframe = undefined;
9
10pub fn main() !void {
11 _ = async amain();
12 resume frame;
13 return error.TestFailed;
14}
15
16fn amain() void {
17 var f = async func();
18 await f;
19 await f;
20}
21
22fn func() void {
23 suspend {
24 frame = @frame();
25 }
26}
27// run
28// backend=stage1
29// target=native
test/cases/safety/error return trace across suspend points.zig deleted-38
......@@ -1,38 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8
9var failing_frame: @Frame(failing) = undefined;
10
11pub fn main() !void {
12 const p = nonFailing();
13 resume p;
14 const p2 = async printTrace(p);
15 _ = p2;
16 return error.TestFailed;
17}
18
19fn nonFailing() anyframe->anyerror!void {
20 failing_frame = async failing();
21 return &failing_frame;
22}
23
24fn failing() anyerror!void {
25 suspend {}
26 return second();
27}
28
29fn second() callconv(.@"async") anyerror!void {
30 return error.Fail;
31}
32
33fn printTrace(p: anyframe->anyerror!void) void {
34 (await p) catch unreachable;
35}
36// run
37// backend=stage1
38// target=native
test/cases/safety/invalid resume of async function.zig deleted-19
......@@ -1,19 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8pub fn main() !void {
9 var p = async suspendOnce();
10 resume p; //ok
11 resume p; //bad
12 return error.TestFailed;
13}
14fn suspendOnce() void {
15 suspend {}
16}
17// run
18// backend=stage1
19// target=native
test/cases/safety/resuming a function which is awaiting a call.zig deleted-21
......@@ -1,21 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8pub fn main() !void {
9 var frame = async first();
10 resume frame;
11 return error.TestFailed;
12}
13fn first() void {
14 other();
15}
16fn other() void {
17 suspend {}
18}
19// run
20// backend=stage1
21// target=native
test/cases/safety/resuming a function which is awaiting a frame.zig deleted-22
......@@ -1,22 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8pub fn main() !void {
9 var frame = async first();
10 resume frame;
11 return error.TestFailed;
12}
13fn first() void {
14 var frame = async other();
15 await frame;
16}
17fn other() void {
18 suspend {}
19}
20// run
21// backend=stage1
22// target=native
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig deleted-32
......@@ -1,32 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8fn foo() void {
9 suspend {
10 global_frame = @frame();
11 }
12 var f = async bar(@frame());
13 _ = &f;
14 std.process.exit(1);
15}
16
17fn bar(frame: anyframe) void {
18 suspend {
19 resume frame;
20 }
21 std.process.exit(1);
22}
23
24var global_frame: anyframe = undefined;
25pub fn main() !void {
26 _ = async foo();
27 resume global_frame;
28 std.process.exit(1);
29}
30// run
31// backend=stage1
32// target=native
test/cases/safety/resuming a non-suspended function which never been suspended.zig deleted-27
......@@ -1,27 +0,0 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = message;
5 _ = stack_trace;
6 std.process.exit(0);
7}
8fn foo() void {
9 var f = async bar(@frame());
10 _ = &f;
11 std.process.exit(1);
12}
13
14fn bar(frame: anyframe) void {
15 suspend {
16 resume frame;
17 }
18 std.process.exit(1);
19}
20
21pub fn main() !void {
22 _ = async foo();
23 return error.TestFailed;
24}
25// run
26// backend=stage1
27// target=native
test/standalone/build.zig.zon-3
......@@ -48,9 +48,6 @@
4848 .pkg_import = .{
4949 .path = "pkg_import",
5050 },
51 .use_alias = .{
52 .path = "use_alias",
53 },
5451 .install_raw_hex = .{
5552 .path = "install_raw_hex",
5653 },
test/standalone/stack_iterator/build.zig+3-3
......@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
2929 .root_source_file = b.path("unwind.zig"),
3030 .target = target,
3131 .optimize = optimize,
32 .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" else null,
32 .unwind_tables = if (target.result.os.tag.isDarwin()) .async else null,
3333 .omit_frame_pointer = false,
3434 }),
3535 });
......@@ -54,7 +54,7 @@ pub fn build(b: *std.Build) void {
5454 .root_source_file = b.path("unwind.zig"),
5555 .target = target,
5656 .optimize = optimize,
57 .unwind_tables = .@"async",
57 .unwind_tables = .async,
5858 .omit_frame_pointer = true,
5959 }),
6060 // self-hosted lacks omit_frame_pointer support
......@@ -101,7 +101,7 @@ pub fn build(b: *std.Build) void {
101101 .root_source_file = b.path("shared_lib_unwind.zig"),
102102 .target = target,
103103 .optimize = optimize,
104 .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" else null,
104 .unwind_tables = if (target.result.os.tag.isDarwin()) .async else null,
105105 .omit_frame_pointer = true,
106106 }),
107107 // zig objcopy doesn't support incremental binaries
test/standalone/use_alias/build.zig deleted-17
......@@ -1,17 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const optimize: std.builtin.OptimizeMode = .Debug;
8
9 const main = b.addTest(.{ .root_module = b.createModule(.{
10 .root_source_file = b.path("main.zig"),
11 .target = b.graph.host,
12 .optimize = optimize,
13 }) });
14 main.root_module.addIncludePath(b.path("."));
15
16 test_step.dependOn(&b.addRunArtifact(main).step);
17}
test/standalone/use_alias/c.zig deleted-1
......@@ -1 +0,0 @@
1pub usingnamespace @cImport(@cInclude("foo.h"));
test/standalone/use_alias/foo.h deleted-4
......@@ -1,4 +0,0 @@
1struct Foo {
2 int a;
3 int b;
4};
test/standalone/use_alias/main.zig deleted-11
......@@ -1,11 +0,0 @@
1const c = @import("c.zig");
2const expect = @import("std").testing.expect;
3
4test "symbol exists" {
5 var foo = c.Foo{
6 .a = 1,
7 .b = 1,
8 };
9 _ = &foo;
10 try expect(foo.a + foo.b == 2);
11}
tools/docgen.zig-3
......@@ -710,8 +710,6 @@ fn tokenizeAndPrintRaw(
710710 .keyword_align,
711711 .keyword_and,
712712 .keyword_asm,
713 .keyword_async,
714 .keyword_await,
715713 .keyword_break,
716714 .keyword_catch,
717715 .keyword_comptime,
......@@ -748,7 +746,6 @@ fn tokenizeAndPrintRaw(
748746 .keyword_try,
749747 .keyword_union,
750748 .keyword_unreachable,
751 .keyword_usingnamespace,
752749 .keyword_var,
753750 .keyword_volatile,
754751 .keyword_allowzero,
tools/doctest.zig-3
......@@ -653,8 +653,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
653653 .keyword_align,
654654 .keyword_and,
655655 .keyword_asm,
656 .keyword_async,
657 .keyword_await,
658656 .keyword_break,
659657 .keyword_catch,
660658 .keyword_comptime,
......@@ -691,7 +689,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
691689 .keyword_try,
692690 .keyword_union,
693691 .keyword_unreachable,
694 .keyword_usingnamespace,
695692 .keyword_var,
696693 .keyword_volatile,
697694 .keyword_allowzero,
tools/lldb_pretty_printers.py-3
......@@ -50,8 +50,6 @@ zig_keywords = {
5050 'anyframe',
5151 'anytype',
5252 'asm',
53 'async',
54 'await',
5553 'break',
5654 'callconv',
5755 'catch',
......@@ -88,7 +86,6 @@ zig_keywords = {
8886 'try',
8987 'union',
9088 'unreachable',
91 'usingnamespace',
9289 'var',
9390 'volatile',
9491 'while',