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 {...@@ -460,8 +460,8 @@ pub fn build(b: *std.Build) !void {
460 .skip_linux = skip_linux,460 .skip_linux = skip_linux,
461 .skip_llvm = skip_llvm,461 .skip_llvm = skip_llvm,
462 .skip_libc = skip_libc,462 .skip_libc = skip_libc,
463 // 2923515904 was observed on an x86_64-linux-gnu host.463 // 3888779264 was observed on an x86_64-linux-gnu host.
464 .max_rss = 3100000000,464 .max_rss = 4000000000,
465 }));465 }));
466466
467 test_modules_step.dependOn(tests.addModuleTests(b, .{467 test_modules_step.dependOn(tests.addModuleTests(b, .{
doc/langref.html.in+8-87
...@@ -3842,37 +3842,6 @@ void do_a_thing(struct Foo *foo) {...@@ -3842,37 +3842,6 @@ void do_a_thing(struct Foo *foo) {
3842 {#header_close#}3842 {#header_close#}
3843 {#header_close#}3843 {#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
3876 {#header_open|comptime#}3845 {#header_open|comptime#}
3877 <p>3846 <p>
3878 Zig places importance on the concept of whether an expression is known at compile-time.3847 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 {...@@ -4279,16 +4248,9 @@ pub fn print(self: *Writer, arg0: []const u8, arg1: i32) !void {
4279 {#header_close#}4248 {#header_close#}
42804249
4281 {#header_open|Async Functions#}4250 {#header_open|Async Functions#}
4282 <p>Async functions regressed with the release of 0.11.0. Their future in4251 <p>Async functions regressed with the release of 0.11.0. The current plan is to
4283 the Zig language is unclear due to multiple unsolved problems:</p>4252 reintroduce them as a lower level primitive that powers I/O implementations.</p>
4284 <ul>4253 <p>Tracking issue: <a href="https://github.com/ziglang/zig/issues/23446">Proposal: stackless coroutines as low-level primitives</a></p>
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>
4292 {#header_close#}4254 {#header_close#}
42934255
4294 {#header_open|Builtin Functions|2col#}4256 {#header_open|Builtin Functions|2col#}
...@@ -6552,7 +6514,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -6552,7 +6514,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
6552 </p>6514 </p>
6553 <ul>6515 <ul>
6554 <li>If a call to {#syntax#}@import{#endsyntax#} is analyzed, the file being imported is analyzed.</li>6516 <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>
6556 <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>6518 <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>
6557 <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>6519 <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>
6558 </ul>6520 </ul>
...@@ -7372,29 +7334,6 @@ fn readU32Be() u32 {}...@@ -7372,29 +7334,6 @@ fn readU32Be() u32 {}
7372 </ul>7334 </ul>
7373 </td>7335 </td>
7374 </tr>7336 </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>
7398 <tr>7337 <tr>
7399 <th scope="row">7338 <th scope="row">
7400 <pre>{#syntax#}break{#endsyntax#}</pre>7339 <pre>{#syntax#}break{#endsyntax#}</pre>
...@@ -7812,18 +7751,6 @@ fn readU32Be() u32 {}...@@ -7812,18 +7751,6 @@ fn readU32Be() u32 {}
7812 </ul>7751 </ul>
7813 </td>7752 </td>
7814 </tr>7753 </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>
7827 <tr>7754 <tr>
7828 <th scope="row">7755 <th scope="row">
7829 <pre>{#syntax#}var{#endsyntax#}</pre>7756 <pre>{#syntax#}var{#endsyntax#}</pre>
...@@ -7893,7 +7820,6 @@ ComptimeDecl <- KEYWORD_comptime Block...@@ -7893,7 +7820,6 @@ ComptimeDecl <- KEYWORD_comptime Block
7893Decl7820Decl
7894 <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)7821 <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)
7895 / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? GlobalVarDecl7822 / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? GlobalVarDecl
7896 / KEYWORD_usingnamespace Expr SEMICOLON
78977823
7898FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr7824FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
78997825
...@@ -8006,8 +7932,7 @@ TypeExpr <- PrefixTypeOp* ErrorUnionExpr...@@ -8006,8 +7932,7 @@ TypeExpr <- PrefixTypeOp* ErrorUnionExpr
8006ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)?7932ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)?
80077933
8008SuffixExpr7934SuffixExpr
8009 <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments7935 <- PrimaryTypeExpr (SuffixOp / FnCallArguments)*
8010 / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
80117936
8012PrimaryTypeExpr7937PrimaryTypeExpr
8013 <- BUILTINIDENTIFIER FnCallArguments7938 <- BUILTINIDENTIFIER FnCallArguments
...@@ -8183,7 +8108,6 @@ PrefixOp...@@ -8183,7 +8108,6 @@ PrefixOp
8183 / MINUSPERCENT8108 / MINUSPERCENT
8184 / AMPERSAND8109 / AMPERSAND
8185 / KEYWORD_try8110 / KEYWORD_try
8186 / KEYWORD_await
81878111
8188PrefixTypeOp8112PrefixTypeOp
8189 <- QUESTIONMARK8113 <- QUESTIONMARK
...@@ -8404,8 +8328,6 @@ KEYWORD_and <- 'and' end_of_word...@@ -8404,8 +8328,6 @@ KEYWORD_and <- 'and' end_of_word
8404KEYWORD_anyframe <- 'anyframe' end_of_word8328KEYWORD_anyframe <- 'anyframe' end_of_word
8405KEYWORD_anytype <- 'anytype' end_of_word8329KEYWORD_anytype <- 'anytype' end_of_word
8406KEYWORD_asm <- 'asm' end_of_word8330KEYWORD_asm <- 'asm' end_of_word
8407KEYWORD_async <- 'async' end_of_word
8408KEYWORD_await <- 'await' end_of_word
8409KEYWORD_break <- 'break' end_of_word8331KEYWORD_break <- 'break' end_of_word
8410KEYWORD_callconv <- 'callconv' end_of_word8332KEYWORD_callconv <- 'callconv' end_of_word
8411KEYWORD_catch <- 'catch' end_of_word8333KEYWORD_catch <- 'catch' end_of_word
...@@ -8442,14 +8364,13 @@ KEYWORD_threadlocal <- 'threadlocal' end_of_word...@@ -8442,14 +8364,13 @@ KEYWORD_threadlocal <- 'threadlocal' end_of_word
8442KEYWORD_try <- 'try' end_of_word8364KEYWORD_try <- 'try' end_of_word
8443KEYWORD_union <- 'union' end_of_word8365KEYWORD_union <- 'union' end_of_word
8444KEYWORD_unreachable <- 'unreachable' end_of_word8366KEYWORD_unreachable <- 'unreachable' end_of_word
8445KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
8446KEYWORD_var <- 'var' end_of_word8367KEYWORD_var <- 'var' end_of_word
8447KEYWORD_volatile <- 'volatile' end_of_word8368KEYWORD_volatile <- 'volatile' end_of_word
8448KEYWORD_while <- 'while' end_of_word8369KEYWORD_while <- 'while' end_of_word
84498370
8450keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and8371keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
8451 / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm / KEYWORD_async8372 / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm
8452 / KEYWORD_await / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch8373 / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
8453 / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer8374 / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer
8454 / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export8375 / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
8455 / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if8376 / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
...@@ -8458,7 +8379,7 @@ keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and...@@ -8458,7 +8379,7 @@ keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
8458 / KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection8379 / KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
8459 / KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test8380 / KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test
8460 / KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable8381 / KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable
8461 / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while8382 / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
8462 {#end_syntax_block#}8383 {#end_syntax_block#}
8463 {#header_close#}8384 {#header_close#}
8464 {#header_open|Zen#}8385 {#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 {...@@ -160,12 +160,6 @@ fn walkMember(w: *Walk, decl: Ast.Node.Index) Error!void {
160 try walkExpression(w, decl);160 try walkExpression(w, decl);
161 },161 },
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
169 .global_var_decl,163 .global_var_decl,
170 .local_var_decl,164 .local_var_decl,
171 .simple_var_decl,165 .simple_var_decl,
...@@ -335,7 +329,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {...@@ -335,7 +329,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
335 .address_of,329 .address_of,
336 .@"try",330 .@"try",
337 .@"resume",331 .@"resume",
338 .@"await",
339 .deref,332 .deref,
340 => {333 => {
341 return walkExpression(w, ast.nodeData(node).node);334 return walkExpression(w, ast.nodeData(node).node);
...@@ -379,12 +372,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {...@@ -379,12 +372,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
379372
380 .call_one,373 .call_one,
381 .call_one_comma,374 .call_one_comma,
382 .async_call_one,
383 .async_call_one_comma,
384 .call,375 .call,
385 .call_comma,376 .call_comma,
386 .async_call,
387 .async_call_comma,
388 => {377 => {
389 var buf: [1]Ast.Node.Index = undefined;378 var buf: [1]Ast.Node.Index = undefined;
390 return walkCall(w, ast.fullCall(&buf, node).?);379 return walkCall(w, ast.fullCall(&buf, node).?);
...@@ -525,7 +514,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {...@@ -525,7 +514,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
525 .local_var_decl => unreachable,514 .local_var_decl => unreachable,
526 .simple_var_decl => unreachable,515 .simple_var_decl => unreachable,
527 .aligned_var_decl => unreachable,516 .aligned_var_decl => unreachable,
528 .@"usingnamespace" => unreachable,
529 .test_decl => unreachable,517 .test_decl => unreachable,
530 .asm_output => unreachable,518 .asm_output => unreachable,
531 .asm_input => unreachable,519 .asm_input => unreachable,
lib/docs/wasm/Walk.zig-11
...@@ -238,12 +238,8 @@ pub const File = struct {...@@ -238,12 +238,8 @@ pub const File = struct {
238238
239 .call_one,239 .call_one,
240 .call_one_comma,240 .call_one_comma,
241 .async_call_one,
242 .async_call_one_comma,
243 .call,241 .call,
244 .call_comma,242 .call_comma,
245 .async_call,
246 .async_call_comma,
247 => {243 => {
248 var buf: [1]Ast.Node.Index = undefined;244 var buf: [1]Ast.Node.Index = undefined;
249 return categorize_call(file_index, node, ast.fullCall(&buf, node).?);245 return categorize_call(file_index, node, ast.fullCall(&buf, node).?);
...@@ -571,7 +567,6 @@ fn struct_decl(...@@ -571,7 +567,6 @@ fn struct_decl(
571 },567 },
572568
573 .@"comptime",569 .@"comptime",
574 .@"usingnamespace",
575 => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).node),570 => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).node),
576571
577 .test_decl => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).opt_token_and_node[1]),572 .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)...@@ -643,7 +638,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
643 const ast = w.file.get_ast();638 const ast = w.file.get_ast();
644 switch (ast.nodeTag(node)) {639 switch (ast.nodeTag(node)) {
645 .root => unreachable, // Top-level declaration.640 .root => unreachable, // Top-level declaration.
646 .@"usingnamespace" => unreachable, // Top-level declaration.
647 .test_decl => unreachable, // Top-level declaration.641 .test_decl => unreachable, // Top-level declaration.
648 .container_field_init => unreachable, // Top-level declaration.642 .container_field_init => unreachable, // Top-level declaration.
649 .container_field_align => unreachable, // Top-level declaration.643 .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)...@@ -743,7 +737,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
743 .@"comptime",737 .@"comptime",
744 .@"nosuspend",738 .@"nosuspend",
745 .@"suspend",739 .@"suspend",
746 .@"await",
747 .@"resume",740 .@"resume",
748 .@"try",741 .@"try",
749 => try expr(w, scope, parent_decl, ast.nodeData(node).node),742 => 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)...@@ -806,12 +799,8 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index)
806799
807 .call_one,800 .call_one,
808 .call_one_comma,801 .call_one_comma,
809 .async_call_one,
810 .async_call_one_comma,
811 .call,802 .call,
812 .call_comma,803 .call_comma,
813 .async_call,
814 .async_call_comma,
815 => {804 => {
816 var buf: [1]Ast.Node.Index = undefined;805 var buf: [1]Ast.Node.Index = undefined;
817 const full = ast.fullCall(&buf, node).?;806 const full = ast.fullCall(&buf, node).?;
lib/docs/wasm/html_render.zig-3
...@@ -101,8 +101,6 @@ pub fn fileSourceHtml(...@@ -101,8 +101,6 @@ pub fn fileSourceHtml(
101 .keyword_align,101 .keyword_align,
102 .keyword_and,102 .keyword_and,
103 .keyword_asm,103 .keyword_asm,
104 .keyword_async,
105 .keyword_await,
106 .keyword_break,104 .keyword_break,
107 .keyword_catch,105 .keyword_catch,
108 .keyword_comptime,106 .keyword_comptime,
...@@ -139,7 +137,6 @@ pub fn fileSourceHtml(...@@ -139,7 +137,6 @@ pub fn fileSourceHtml(
139 .keyword_try,137 .keyword_try,
140 .keyword_union,138 .keyword_union,
141 .keyword_unreachable,139 .keyword_unreachable,
142 .keyword_usingnamespace,
143 .keyword_var,140 .keyword_var,
144 .keyword_volatile,141 .keyword_volatile,
145 .keyword_allowzero,142 .keyword_allowzero,
lib/std/Build/Module.zig+1-1
...@@ -572,7 +572,7 @@ pub fn appendZigProcessFlags(...@@ -572,7 +572,7 @@ pub fn appendZigProcessFlags(
572 try zig_args.append(switch (unwind_tables) {572 try zig_args.append(switch (unwind_tables) {
573 .none => "-fno-unwind-tables",573 .none => "-fno-unwind-tables",
574 .sync => "-funwind-tables",574 .sync => "-funwind-tables",
575 .@"async" => "-fasync-unwind-tables",575 .async => "-fasync-unwind-tables",
576 });576 });
577 }577 }
578578
lib/std/Target.zig+1-1
...@@ -1691,7 +1691,7 @@ pub const Cpu = struct {...@@ -1691,7 +1691,7 @@ pub const Cpu = struct {
1691 pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch {1691 pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch {
1692 return switch (cc) {1692 return switch (cc) {
1693 .auto,1693 .auto,
1694 .@"async",1694 .async,
1695 .naked,1695 .naked,
1696 .@"inline",1696 .@"inline",
1697 => unreachable,1697 => unreachable,
lib/std/builtin.zig+3-14
...@@ -199,8 +199,6 @@ pub const CallingConvention = union(enum(u8)) {...@@ -199,8 +199,6 @@ pub const CallingConvention = union(enum(u8)) {
199 pub const C: CallingConvention = .c;199 pub const C: CallingConvention = .c;
200 /// Deprecated; use `.naked`.200 /// Deprecated; use `.naked`.
201 pub const Naked: CallingConvention = .naked;201 pub const Naked: CallingConvention = .naked;
202 /// Deprecated; use `.@"async"`.
203 pub const Async: CallingConvention = .@"async";
204 /// Deprecated; use `.@"inline"`.202 /// Deprecated; use `.@"inline"`.
205 pub const Inline: CallingConvention = .@"inline";203 pub const Inline: CallingConvention = .@"inline";
206 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.204 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.
...@@ -248,7 +246,7 @@ pub const CallingConvention = union(enum(u8)) {...@@ -248,7 +246,7 @@ pub const CallingConvention = union(enum(u8)) {
248 /// The calling convention of a function that can be called with `async` syntax. An `async` call246 /// The calling convention of a function that can be called with `async` syntax. An `async` call
249 /// of a runtime-known function must target a function with this calling convention.247 /// of a runtime-known function must target a function with this calling convention.
250 /// Comptime-known functions with other calling conventions may be coerced to this one.248 /// Comptime-known functions with other calling conventions may be coerced to this one.
251 @"async",249 async,
252250
253 /// Functions with this calling convention have no prologue or epilogue, making the function251 /// Functions with this calling convention have no prologue or epilogue, making the function
254 /// uncallable in regular Zig code. This can be useful when integrating with assembly.252 /// uncallable in regular Zig code. This can be useful when integrating with assembly.
...@@ -851,7 +849,7 @@ pub const LinkMode = enum {...@@ -851,7 +849,7 @@ pub const LinkMode = enum {
851pub const UnwindTables = enum {849pub const UnwindTables = enum {
852 none,850 none,
853 sync,851 sync,
854 @"async",852 async,
855};853};
856854
857/// This data structure is used by the Zig language code generation and855/// This data structure is used by the Zig language code generation and
...@@ -866,32 +864,23 @@ pub const WasiExecModel = enum {...@@ -866,32 +864,23 @@ pub const WasiExecModel = enum {
866pub const CallModifier = enum {864pub const CallModifier = enum {
867 /// Equivalent to function call syntax.865 /// Equivalent to function call syntax.
868 auto,866 auto,
869
870 /// Equivalent to async keyword used with function call syntax.
871 async_kw,
872
873 /// Prevents tail call optimization. This guarantees that the return867 /// Prevents tail call optimization. This guarantees that the return
874 /// address will point to the callsite, as opposed to the callsite's868 /// address will point to the callsite, as opposed to the callsite's
875 /// callsite. If the call is otherwise required to be tail-called869 /// callsite. If the call is otherwise required to be tail-called
876 /// or inlined, a compile error is emitted instead.870 /// or inlined, a compile error is emitted instead.
877 never_tail,871 never_tail,
878
879 /// Guarantees that the call will not be inlined. If the call is872 /// Guarantees that the call will not be inlined. If the call is
880 /// otherwise required to be inlined, a compile error is emitted instead.873 /// otherwise required to be inlined, a compile error is emitted instead.
881 never_inline,874 never_inline,
882
883 /// Asserts that the function call will not suspend. This allows a875 /// Asserts that the function call will not suspend. This allows a
884 /// non-async function to call an async function.876 /// non-async function to call an async function.
885 no_async,877 no_suspend,
886
887 /// Guarantees that the call will be generated with tail call optimization.878 /// Guarantees that the call will be generated with tail call optimization.
888 /// If this is not possible, a compile error is emitted instead.879 /// If this is not possible, a compile error is emitted instead.
889 always_tail,880 always_tail,
890
891 /// Guarantees that the call will be inlined at the callsite.881 /// Guarantees that the call will be inlined at the callsite.
892 /// If this is not possible, a compile error is emitted instead.882 /// If this is not possible, a compile error is emitted instead.
893 always_inline,883 always_inline,
894
895 /// Evaluates the call at compile-time. If the call cannot be completed at884 /// Evaluates the call at compile-time. If the call cannot be completed at
896 /// compile-time, a compile error is emitted instead.885 /// compile-time, a compile error is emitted instead.
897 compile_time,886 compile_time,
lib/std/zig/Ast.zig+7-78
...@@ -606,7 +606,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -606,7 +606,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
606 .negation_wrap,606 .negation_wrap,
607 .address_of,607 .address_of,
608 .@"try",608 .@"try",
609 .@"await",
610 .optional_type,609 .optional_type,
611 .@"switch",610 .@"switch",
612 .switch_comma,611 .switch_comma,
...@@ -756,27 +755,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -756,27 +755,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
756 return i - end_offset;755 return i - end_offset;
757 },756 },
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
780 .container_field_init,758 .container_field_init,
781 .container_field_align,759 .container_field_align,
782 .container_field,760 .container_field,
...@@ -896,14 +874,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -896,14 +874,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
896 while (true) switch (tree.nodeTag(n)) {874 while (true) switch (tree.nodeTag(n)) {
897 .root => return @intCast(tree.tokens.len - 1),875 .root => return @intCast(tree.tokens.len - 1),
898876
899 .@"usingnamespace",
900 .bool_not,877 .bool_not,
901 .negation,878 .negation,
902 .bit_not,879 .bit_not,
903 .negation_wrap,880 .negation_wrap,
904 .address_of,881 .address_of,
905 .@"try",882 .@"try",
906 .@"await",
907 .optional_type,883 .optional_type,
908 .@"suspend",884 .@"suspend",
909 .@"resume",885 .@"resume",
...@@ -1022,7 +998,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1022,7 +998,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1022 };998 };
1023 },999 },
10241000
1025 .call, .async_call => {1001 .call => {
1026 _, const extra_index = tree.nodeData(n).node_and_extra;1002 _, const extra_index = tree.nodeData(n).node_and_extra;
1027 const params = tree.extraData(extra_index, Node.SubRange);1003 const params = tree.extraData(extra_index, Node.SubRange);
1028 assert(params.start != params.end);1004 assert(params.start != params.end);
...@@ -1041,7 +1017,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1041,7 +1017,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1041 }1017 }
1042 },1018 },
1043 .call_comma,1019 .call_comma,
1044 .async_call_comma,
1045 .tagged_union_enum_tag_trailing,1020 .tagged_union_enum_tag_trailing,
1046 => {1021 => {
1047 _, const extra_index = tree.nodeData(n).node_and_extra;1022 _, const extra_index = tree.nodeData(n).node_and_extra;
...@@ -1122,7 +1097,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1122,7 +1097,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1122 n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member1097 n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member
1123 },1098 },
1124 .call_one,1099 .call_one,
1125 .async_call_one,
1126 => {1100 => {
1127 _, const first_param = tree.nodeData(n).node_and_opt_node;1101 _, const first_param = tree.nodeData(n).node_and_opt_node;
1128 end_offset += 1; // for the rparen1102 end_offset += 1; // for the rparen
...@@ -1271,7 +1245,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1271,7 +1245,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
1271 n = first_element;1245 n = first_element;
1272 },1246 },
1273 .call_one_comma,1247 .call_one_comma,
1274 .async_call_one_comma,
1275 .struct_init_one_comma,1248 .struct_init_one_comma,
1276 => {1249 => {
1277 _, const first_field = tree.nodeData(n).node_and_opt_node;1250 _, const first_field = tree.nodeData(n).node_and_opt_node;
...@@ -1988,21 +1961,21 @@ pub fn forFull(tree: Ast, node: Node.Index) full.For {...@@ -1988,21 +1961,21 @@ pub fn forFull(tree: Ast, node: Node.Index) full.For {
1988pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call {1961pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call {
1989 const fn_expr, const first_param = tree.nodeData(node).node_and_opt_node;1962 const fn_expr, const first_param = tree.nodeData(node).node_and_opt_node;
1990 const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param});1963 const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param});
1991 return tree.fullCallComponents(.{1964 return .{ .ast = .{
1992 .lparen = tree.nodeMainToken(node),1965 .lparen = tree.nodeMainToken(node),
1993 .fn_expr = fn_expr,1966 .fn_expr = fn_expr,
1994 .params = params,1967 .params = params,
1995 });1968 } };
1996}1969}
19971970
1998pub fn callFull(tree: Ast, node: Node.Index) full.Call {1971pub fn callFull(tree: Ast, node: Node.Index) full.Call {
1999 const fn_expr, const extra_index = tree.nodeData(node).node_and_extra;1972 const fn_expr, const extra_index = tree.nodeData(node).node_and_extra;
2000 const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index);1973 const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index);
2001 return tree.fullCallComponents(.{1974 return .{ .ast = .{
2002 .lparen = tree.nodeMainToken(node),1975 .lparen = tree.nodeMainToken(node),
2003 .fn_expr = fn_expr,1976 .fn_expr = fn_expr,
2004 .params = params,1977 .params = params,
2005 });1978 } };
2006}1979}
20071980
2008fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl {1981fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl {
...@@ -2336,18 +2309,6 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For {...@@ -2336,18 +2309,6 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For {
2336 return result;2309 return result;
2337}2310}
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
2351pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl {2312pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl {
2352 return switch (tree.nodeTag(node)) {2313 return switch (tree.nodeTag(node)) {
2353 .global_var_decl => tree.globalVarDecl(node),2314 .global_var_decl => tree.globalVarDecl(node),
...@@ -2488,8 +2449,8 @@ pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm {...@@ -2488,8 +2449,8 @@ pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm {
24882449
2489pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call {2450pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call {
2490 return switch (tree.nodeTag(node)) {2451 return switch (tree.nodeTag(node)) {
2491 .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),2452 .call, .call_comma => tree.callFull(node),
2492 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node),2453 .call_one, .call_one_comma => tree.callOne(buffer, node),
2493 else => null,2454 else => null,
2494 };2455 };
2495}2456}
...@@ -2882,7 +2843,6 @@ pub const full = struct {...@@ -2882,7 +2843,6 @@ pub const full = struct {
28822843
2883 pub const Call = struct {2844 pub const Call = struct {
2884 ast: Components,2845 ast: Components,
2885 async_token: ?TokenIndex,
28862846
2887 pub const Components = struct {2847 pub const Components = struct {
2888 lparen: TokenIndex,2848 lparen: TokenIndex,
...@@ -3065,12 +3025,6 @@ pub const Node = struct {...@@ -3065,12 +3025,6 @@ pub const Node = struct {
3065 ///3025 ///
3066 /// The `main_token` field is the first token for the source file.3026 /// The `main_token` field is the first token for the source file.
3067 root,3027 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",
3074 /// `test {}`,3028 /// `test {}`,
3075 /// `test "name" {}`,3029 /// `test "name" {}`,
3076 /// `test identifier {}`.3030 /// `test identifier {}`.
...@@ -3301,8 +3255,6 @@ pub const Node = struct {...@@ -3301,8 +3255,6 @@ pub const Node = struct {
3301 address_of,3255 address_of,
3302 /// `try expr`. The `main_token` field is the `try` token.3256 /// `try expr`. The `main_token` field is the `try` token.
3303 @"try",3257 @"try",
3304 /// `await expr`. The `main_token` field is the `await` token.
3305 @"await",
3306 /// `?expr`. The `main_token` field is the `?` token.3258 /// `?expr`. The `main_token` field is the `?` token.
3307 optional_type,3259 optional_type,
3308 /// `[lhs]rhs`. The `main_token` field is the `[` token.3260 /// `[lhs]rhs`. The `main_token` field is the `[` token.
...@@ -3498,17 +3450,6 @@ pub const Node = struct {...@@ -3498,17 +3450,6 @@ pub const Node = struct {
3498 /// Same as `call_one` except there is known to be a trailing comma3450 /// Same as `call_one` except there is known to be a trailing comma
3499 /// before the final rparen.3451 /// before the final rparen.
3500 call_one_comma,3452 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,
3512 /// `a(b, c, d)`.3453 /// `a(b, c, d)`.
3513 ///3454 ///
3514 /// The `data` field is a `.node_and_extra`:3455 /// The `data` field is a `.node_and_extra`:
...@@ -3521,18 +3462,6 @@ pub const Node = struct {...@@ -3521,18 +3462,6 @@ pub const Node = struct {
3521 /// Same as `call` except there is known to be a trailing comma before3462 /// Same as `call` except there is known to be a trailing comma before
3522 /// the final rparen.3463 /// the final rparen.
3523 call_comma,3464 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,
3536 /// `switch(a) {}`.3465 /// `switch(a) {}`.
3537 ///3466 ///
3538 /// The `data` field is a `.node_and_extra`:3467 /// 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...@@ -442,7 +442,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
442 const tree = astgen.tree;442 const tree = astgen.tree;
443 switch (tree.nodeTag(node)) {443 switch (tree.nodeTag(node)) {
444 .root => unreachable,444 .root => unreachable,
445 .@"usingnamespace" => unreachable,
446 .test_decl => unreachable,445 .test_decl => unreachable,
447 .global_var_decl => unreachable,446 .global_var_decl => unreachable,
448 .local_var_decl => unreachable,447 .local_var_decl => unreachable,
...@@ -510,12 +509,8 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins...@@ -510,12 +509,8 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
510 .number_literal,509 .number_literal,
511 .call,510 .call,
512 .call_comma,511 .call_comma,
513 .async_call,
514 .async_call_comma,
515 .call_one,512 .call_one,
516 .call_one_comma,513 .call_one_comma,
517 .async_call_one,
518 .async_call_one_comma,
519 .unreachable_literal,514 .unreachable_literal,
520 .@"return",515 .@"return",
521 .@"if",516 .@"if",
...@@ -547,7 +542,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins...@@ -547,7 +542,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
547 .merge_error_sets,542 .merge_error_sets,
548 .switch_range,543 .switch_range,
549 .for_range,544 .for_range,
550 .@"await",
551 .bit_not,545 .bit_not,
552 .negation,546 .negation,
553 .negation_wrap,547 .negation_wrap,
...@@ -642,7 +636,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE...@@ -642,7 +636,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
642636
643 switch (tree.nodeTag(node)) {637 switch (tree.nodeTag(node)) {
644 .root => unreachable, // Top-level declaration.638 .root => unreachable, // Top-level declaration.
645 .@"usingnamespace" => unreachable, // Top-level declaration.
646 .test_decl => unreachable, // Top-level declaration.639 .test_decl => unreachable, // Top-level declaration.
647 .container_field_init => unreachable, // Top-level declaration.640 .container_field_init => unreachable, // Top-level declaration.
648 .container_field_align => unreachable, // Top-level declaration.641 .container_field_align => unreachable, // Top-level declaration.
...@@ -836,12 +829,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE...@@ -836,12 +829,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
836829
837 .call_one,830 .call_one,
838 .call_one_comma,831 .call_one_comma,
839 .async_call_one,
840 .async_call_one_comma,
841 .call,832 .call,
842 .call_comma,833 .call_comma,
843 .async_call,
844 .async_call_comma,
845 => {834 => {
846 var buf: [1]Ast.Node.Index = undefined;835 var buf: [1]Ast.Node.Index = undefined;
847 return callExpr(gz, scope, ri, .none, node, tree.fullCall(&buf, node).?);836 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...@@ -1114,7 +1103,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
11141103
1115 .@"nosuspend" => return nosuspendExpr(gz, scope, ri, node),1104 .@"nosuspend" => return nosuspendExpr(gz, scope, ri, node),
1116 .@"suspend" => return suspendExpr(gz, scope, node),1105 .@"suspend" => return suspendExpr(gz, scope, node),
1117 .@"await" => return awaitExpr(gz, scope, ri, node),
1118 .@"resume" => return resumeExpr(gz, scope, ri, node),1106 .@"resume" => return resumeExpr(gz, scope, ri, node),
11191107
1120 .@"try" => return tryExpr(gz, scope, ri, node, tree.nodeData(node).node),1108 .@"try" => return tryExpr(gz, scope, ri, node, tree.nodeData(node).node),
...@@ -1259,33 +1247,6 @@ fn suspendExpr(...@@ -1259,33 +1247,6 @@ fn suspendExpr(
1259 return suspend_inst.toRef();1247 return suspend_inst.toRef();
1260}1248}
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
1289fn resumeExpr(1250fn resumeExpr(
1290 gz: *GenZir,1251 gz: *GenZir,
1291 scope: *Scope,1252 scope: *Scope,
...@@ -2853,7 +2814,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2853,7 +2814,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2853 .tag_name,2814 .tag_name,
2854 .type_name,2815 .type_name,
2855 .frame_type,2816 .frame_type,
2856 .frame_size,
2857 .int_from_float,2817 .int_from_float,
2858 .float_from_int,2818 .float_from_int,
2859 .ptr_from_int,2819 .ptr_from_int,
...@@ -2887,7 +2847,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2887,7 +2847,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2887 .min,2847 .min,
2888 .c_import,2848 .c_import,
2889 .@"resume",2849 .@"resume",
2890 .@"await",
2891 .ret_err_value_code,2850 .ret_err_value_code,
2892 .ret_ptr,2851 .ret_ptr,
2893 .ret_type,2852 .ret_type,
...@@ -4739,69 +4698,6 @@ fn comptimeDecl(...@@ -4739,69 +4698,6 @@ fn comptimeDecl(
4739 });4698 });
4740}4699}
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
4805fn testDecl(4701fn testDecl(
4806 astgen: *AstGen,4702 astgen: *AstGen,
4807 gz: *GenZir,4703 gz: *GenZir,
...@@ -5971,23 +5867,6 @@ fn containerMember(...@@ -5971,23 +5867,6 @@ fn containerMember(
5971 },5867 },
5972 };5868 };
5973 },5869 },
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 },
5991 .test_decl => {5870 .test_decl => {
5992 const prev_decl_index = wip_members.decl_index;5871 const prev_decl_index = wip_members.decl_index;
5993 // We need to have *some* decl here so that the decl count matches what's expected.5872 // We need to have *some* decl here so that the decl count matches what's expected.
...@@ -9501,7 +9380,6 @@ fn builtinCall(...@@ -9501,7 +9380,6 @@ fn builtinCall(
9501 .tag_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .tag_name),9380 .tag_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .tag_name),
9502 .type_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .type_name),9381 .type_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .type_name),
9503 .Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),9382 .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
9506 .int_from_float => return typeCast(gz, scope, ri, node, params[0], .int_from_float, builtin_name),9384 .int_from_float => return typeCast(gz, scope, ri, node, params[0], .int_from_float, builtin_name),
9507 .float_from_int => return typeCast(gz, scope, ri, node, params[0], .float_from_int, builtin_name),9385 .float_from_int => return typeCast(gz, scope, ri, node, params[0], .float_from_int, builtin_name),
...@@ -9767,16 +9645,6 @@ fn builtinCall(...@@ -9767,16 +9645,6 @@ fn builtinCall(
9767 });9645 });
9768 return rvalue(gz, ri, result, node);9646 return rvalue(gz, ri, result, node);
9769 },9647 },
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 },
9780 .Vector => {9648 .Vector => {
9781 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{9649 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{
9782 .lhs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .type),9650 .lhs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .type),
...@@ -10175,11 +10043,8 @@ fn callExpr(...@@ -10175,11 +10043,8 @@ fn callExpr(
1017510043
10176 const callee = try calleeExpr(gz, scope, ri.rl, override_decl_literal_type, call.ast.fn_expr);10044 const callee = try calleeExpr(gz, scope, ri.rl, override_decl_literal_type, call.ast.fn_expr);
10177 const modifier: std.builtin.CallModifier = blk: {10045 const modifier: std.builtin.CallModifier = blk: {
10178 if (call.async_token != null) {
10179 break :blk .async_kw;
10180 }
10181 if (gz.nosuspend_node != .none) {10046 if (gz.nosuspend_node != .none) {
10182 break :blk .no_async;10047 break :blk .no_suspend;
10183 }10048 }
10184 break :blk .auto;10049 break :blk .auto;
10185 };10050 };
...@@ -10451,7 +10316,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev...@@ -10451,7 +10316,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
10451 while (true) {10316 while (true) {
10452 switch (tree.nodeTag(node)) {10317 switch (tree.nodeTag(node)) {
10453 .root,10318 .root,
10454 .@"usingnamespace",
10455 .test_decl,10319 .test_decl,
10456 .switch_case,10320 .switch_case,
10457 .switch_case_inline,10321 .switch_case_inline,
...@@ -10483,12 +10347,8 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev...@@ -10483,12 +10347,8 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
10483 .switch_comma,10347 .switch_comma,
10484 .call_one,10348 .call_one,
10485 .call_one_comma,10349 .call_one_comma,
10486 .async_call_one,
10487 .async_call_one_comma,
10488 .call,10350 .call,
10489 .call_comma,10351 .call_comma,
10490 .async_call,
10491 .async_call_comma,
10492 => return .maybe,10352 => return .maybe,
1049310353
10494 .@"return",10354 .@"return",
...@@ -10613,7 +10473,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev...@@ -10613,7 +10473,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
1061310473
10614 // Forward the question to the LHS sub-expression.10474 // Forward the question to the LHS sub-expression.
10615 .@"try",10475 .@"try",
10616 .@"await",
10617 .@"comptime",10476 .@"comptime",
10618 .@"nosuspend",10477 .@"nosuspend",
10619 => node = tree.nodeData(node).node,10478 => node = tree.nodeData(node).node,
...@@ -10664,7 +10523,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In...@@ -10664,7 +10523,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
10664 while (true) {10523 while (true) {
10665 switch (tree.nodeTag(node)) {10524 switch (tree.nodeTag(node)) {
10666 .root,10525 .root,
10667 .@"usingnamespace",
10668 .test_decl,10526 .test_decl,
10669 .switch_case,10527 .switch_case,
10670 .switch_case_inline,10528 .switch_case_inline,
...@@ -10803,12 +10661,8 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In...@@ -10803,12 +10661,8 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
10803 .switch_comma,10661 .switch_comma,
10804 .call_one,10662 .call_one,
10805 .call_one_comma,10663 .call_one_comma,
10806 .async_call_one,
10807 .async_call_one_comma,
10808 .call,10664 .call,
10809 .call_comma,10665 .call_comma,
10810 .async_call,
10811 .async_call_comma,
10812 .block_two,10666 .block_two,
10813 .block_two_semicolon,10667 .block_two_semicolon,
10814 .block,10668 .block,
...@@ -10826,7 +10680,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In...@@ -10826,7 +10680,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
1082610680
10827 // Forward the question to the LHS sub-expression.10681 // Forward the question to the LHS sub-expression.
10828 .@"try",10682 .@"try",
10829 .@"await",
10830 .@"comptime",10683 .@"comptime",
10831 .@"nosuspend",10684 .@"nosuspend",
10832 => node = tree.nodeData(node).node,10685 => node = tree.nodeData(node).node,
...@@ -10908,7 +10761,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {...@@ -10908,7 +10761,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
10908 while (true) {10761 while (true) {
10909 switch (tree.nodeTag(node)) {10762 switch (tree.nodeTag(node)) {
10910 .root,10763 .root,
10911 .@"usingnamespace",
10912 .test_decl,10764 .test_decl,
10913 .switch_case,10765 .switch_case,
10914 .switch_case_inline,10766 .switch_case_inline,
...@@ -11047,12 +10899,8 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {...@@ -11047,12 +10899,8 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
11047 .switch_comma,10899 .switch_comma,
11048 .call_one,10900 .call_one,
11049 .call_one_comma,10901 .call_one_comma,
11050 .async_call_one,
11051 .async_call_one_comma,
11052 .call,10902 .call,
11053 .call_comma,10903 .call_comma,
11054 .async_call,
11055 .async_call_comma,
11056 .block_two,10904 .block_two,
11057 .block_two_semicolon,10905 .block_two_semicolon,
11058 .block,10906 .block,
...@@ -11079,7 +10927,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {...@@ -11079,7 +10927,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
1107910927
11080 // Forward the question to the LHS sub-expression.10928 // Forward the question to the LHS sub-expression.
11081 .@"try",10929 .@"try",
11082 .@"await",
11083 .@"comptime",10930 .@"comptime",
11084 .@"nosuspend",10931 .@"nosuspend",
11085 => node = tree.nodeData(node).node,10932 => node = tree.nodeData(node).node,
...@@ -13586,7 +13433,7 @@ fn scanContainer(...@@ -13586,7 +13433,7 @@ fn scanContainer(
13586 break :blk .{ .decl, ident };13433 break :blk .{ .decl, ident };
13587 },13434 },
1358813435
13589 .@"comptime", .@"usingnamespace" => {13436 .@"comptime" => {
13590 decl_count += 1;13437 decl_count += 1;
13591 continue;13438 continue;
13592 },13439 },
...@@ -13964,7 +13811,6 @@ const DeclarationName = union(enum) {...@@ -13964,7 +13811,6 @@ const DeclarationName = union(enum) {
13964 decltest: Ast.TokenIndex,13811 decltest: Ast.TokenIndex,
13965 unnamed_test,13812 unnamed_test,
13966 @"comptime",13813 @"comptime",
13967 @"usingnamespace",
13968};13814};
1396913815
13970fn addFailedDeclaration(13816fn addFailedDeclaration(
...@@ -14054,7 +13900,6 @@ fn setDeclaration(...@@ -14054,7 +13900,6 @@ fn setDeclaration(
14054 .@"test" => .@"test",13900 .@"test" => .@"test",
14055 .decltest => .decltest,13901 .decltest => .decltest,
14056 .@"comptime" => .@"comptime",13902 .@"comptime" => .@"comptime",
14057 .@"usingnamespace" => if (args.is_pub) .pub_usingnamespace else .@"usingnamespace",
14058 .@"const" => switch (args.linkage) {13903 .@"const" => switch (args.linkage) {
14059 .normal => if (args.is_pub) id: {13904 .normal => if (args.is_pub) id: {
14060 if (has_special_body) break :id .pub_const;13905 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...@@ -165,10 +165,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
165 }165 }
166 return false;166 return false;
167 },167 },
168 .@"usingnamespace" => {
169 _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only);
170 return false;
171 },
172 .test_decl => {168 .test_decl => {
173 _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none);169 _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none);
174 return false;170 return false;
...@@ -334,12 +330,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI...@@ -334,12 +330,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
334330
335 .call_one,331 .call_one,
336 .call_one_comma,332 .call_one_comma,
337 .async_call_one,
338 .async_call_one_comma,
339 .call,333 .call,
340 .call_comma,334 .call_comma,
341 .async_call,
342 .async_call_comma,
343 => {335 => {
344 var buf: [1]Ast.Node.Index = undefined;336 var buf: [1]Ast.Node.Index = undefined;
345 const full = tree.fullCall(&buf, node).?;337 const full = tree.fullCall(&buf, node).?;
...@@ -353,11 +345,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI...@@ -353,11 +345,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
353 .call,345 .call,
354 .call_comma,346 .call_comma,
355 => false, // TODO: once function calls are passed result locations this will change347 => 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
361 else => unreachable,348 else => unreachable,
362 };349 };
363 },350 },
...@@ -503,7 +490,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI...@@ -503,7 +490,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
503 return false;490 return false;
504 },491 },
505 .@"try",492 .@"try",
506 .@"await",
507 .@"nosuspend",493 .@"nosuspend",
508 => return astrl.expr(tree.nodeData(node).node, block, ri),494 => return astrl.expr(tree.nodeData(node).node, block, ri),
509 .grouped_expression,495 .grouped_expression,
...@@ -948,7 +934,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast....@@ -948,7 +934,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
948 .tag_name,934 .tag_name,
949 .type_name,935 .type_name,
950 .Frame,936 .Frame,
951 .frame_size,
952 .int_from_float,937 .int_from_float,
953 .float_from_int,938 .float_from_int,
954 .ptr_from_int,939 .ptr_from_int,
...@@ -1079,13 +1064,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast....@@ -1079,13 +1064,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
1079 _ = try astrl.expr(args[3], block, ResultInfo.none);1064 _ = try astrl.expr(args[3], block, ResultInfo.none);
1080 return false;1065 return false;
1081 },1066 },
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 },
1089 .Vector => {1067 .Vector => {
1090 _ = try astrl.expr(args[0], block, ResultInfo.type_only);1068 _ = try astrl.expr(args[0], block, ResultInfo.type_only);
1091 _ = try astrl.expr(args[1], block, ResultInfo.type_only);1069 _ = try astrl.expr(args[1], block, ResultInfo.type_only);
lib/std/zig/BuiltinFn.zig-16
...@@ -4,7 +4,6 @@ pub const Tag = enum {...@@ -4,7 +4,6 @@ pub const Tag = enum {
4 align_cast,4 align_cast,
5 align_of,5 align_of,
6 as,6 as,
7 async_call,
8 atomic_load,7 atomic_load,
9 atomic_rmw,8 atomic_rmw,
10 atomic_store,9 atomic_store,
...@@ -55,7 +54,6 @@ pub const Tag = enum {...@@ -55,7 +54,6 @@ pub const Tag = enum {
55 frame,54 frame,
56 Frame,55 Frame,
57 frame_address,56 frame_address,
58 frame_size,
59 has_decl,57 has_decl,
60 has_field,58 has_field,
61 import,59 import,
...@@ -184,13 +182,6 @@ pub const list = list: {...@@ -184,13 +182,6 @@ pub const list = list: {
184 .param_count = 2,182 .param_count = 2,
185 },183 },
186 },184 },
187 .{
188 "@asyncCall",
189 .{
190 .tag = .async_call,
191 .param_count = 4,
192 },
193 },
194 .{185 .{
195 "@atomicLoad",186 "@atomicLoad",
196 .{187 .{
...@@ -550,13 +541,6 @@ pub const list = list: {...@@ -550,13 +541,6 @@ pub const list = list: {
550 .illegal_outside_function = true,541 .illegal_outside_function = true,
551 },542 },
552 },543 },
553 .{
554 "@frameSize",
555 .{
556 .tag = .frame_size,
557 .param_count = 1,
558 },
559 },
560 .{544 .{
561 "@hasDecl",545 "@hasDecl",
562 .{546 .{
lib/std/zig/Parse.zig+2-90
...@@ -359,16 +359,6 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {...@@ -359,16 +359,6 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members {
359 }359 }
360 trailing = p.tokenTag(p.tok_i - 1) == .semicolon;360 trailing = p.tokenTag(p.tok_i - 1) == .semicolon;
361 },361 },
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 },
372 .keyword_const,362 .keyword_const,
373 .keyword_var,363 .keyword_var,
374 .keyword_threadlocal,364 .keyword_threadlocal,
...@@ -496,7 +486,6 @@ fn findNextContainerMember(p: *Parse) void {...@@ -496,7 +486,6 @@ fn findNextContainerMember(p: *Parse) void {
496 .keyword_extern,486 .keyword_extern,
497 .keyword_inline,487 .keyword_inline,
498 .keyword_noinline,488 .keyword_noinline,
499 .keyword_usingnamespace,
500 .keyword_threadlocal,489 .keyword_threadlocal,
501 .keyword_const,490 .keyword_const,
502 .keyword_var,491 .keyword_var,
...@@ -601,7 +590,6 @@ fn expectTestDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {...@@ -601,7 +590,6 @@ fn expectTestDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
601/// Decl590/// Decl
602/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)591/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)
603/// / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl592/// / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
604/// / KEYWORD_usingnamespace Expr SEMICOLON
605fn expectTopLevelDecl(p: *Parse) !?Node.Index {593fn expectTopLevelDecl(p: *Parse) !?Node.Index {
606 const extern_export_inline_token = p.nextToken();594 const extern_export_inline_token = p.nextToken();
607 var is_extern: bool = false;595 var is_extern: bool = false;
...@@ -664,10 +652,7 @@ fn expectTopLevelDecl(p: *Parse) !?Node.Index {...@@ -664,10 +652,7 @@ fn expectTopLevelDecl(p: *Parse) !?Node.Index {
664 if (expect_var_or_fn) {652 if (expect_var_or_fn) {
665 return p.fail(.expected_var_decl_or_fn);653 return p.fail(.expected_var_decl_or_fn);
666 }654 }
667 if (p.tokenTag(p.tok_i) != .keyword_usingnamespace) {655 return p.fail(.expected_pub_item);
668 return p.fail(.expected_pub_item);
669 }
670 return try p.expectUsingNamespace();
671}656}
672657
673fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {658fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
...@@ -680,27 +665,6 @@ fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {...@@ -680,27 +665,6 @@ fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index {
680 };665 };
681}666}
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
704/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr668/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
705fn parseFnProto(p: *Parse) !?Node.Index {669fn parseFnProto(p: *Parse) !?Node.Index {
706 const fn_token = p.eatToken(.keyword_fn) orelse return null;670 const fn_token = p.eatToken(.keyword_fn) orelse return null;
...@@ -1688,7 +1652,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {...@@ -1688,7 +1652,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
1688/// / MINUSPERCENT1652/// / MINUSPERCENT
1689/// / AMPERSAND1653/// / AMPERSAND
1690/// / KEYWORD_try1654/// / KEYWORD_try
1691/// / KEYWORD_await
1692fn parsePrefixExpr(p: *Parse) Error!?Node.Index {1655fn parsePrefixExpr(p: *Parse) Error!?Node.Index {
1693 const tag: Node.Tag = switch (p.tokenTag(p.tok_i)) {1656 const tag: Node.Tag = switch (p.tokenTag(p.tok_i)) {
1694 .bang => .bool_not,1657 .bang => .bool_not,
...@@ -1697,7 +1660,6 @@ fn parsePrefixExpr(p: *Parse) Error!?Node.Index {...@@ -1697,7 +1660,6 @@ fn parsePrefixExpr(p: *Parse) Error!?Node.Index {
1697 .minus_percent => .negation_wrap,1660 .minus_percent => .negation_wrap,
1698 .ampersand => .address_of,1661 .ampersand => .address_of,
1699 .keyword_try => .@"try",1662 .keyword_try => .@"try",
1700 .keyword_await => .@"await",
1701 else => return p.parsePrimaryExpr(),1663 else => return p.parsePrimaryExpr(),
1702 };1664 };
1703 return try p.addNode(.{1665 return try p.addNode(.{
...@@ -2385,62 +2347,12 @@ fn parseErrorUnionExpr(p: *Parse) !?Node.Index {...@@ -2385,62 +2347,12 @@ fn parseErrorUnionExpr(p: *Parse) !?Node.Index {
2385}2347}
23862348
2387/// SuffixExpr2349/// SuffixExpr
2388/// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments2350/// <- PrimaryTypeExpr (SuffixOp / FnCallArguments)*
2389/// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
2390///2351///
2391/// FnCallArguments <- LPAREN ExprList RPAREN2352/// FnCallArguments <- LPAREN ExprList RPAREN
2392///2353///
2393/// ExprList <- (Expr COMMA)* Expr?2354/// ExprList <- (Expr COMMA)* Expr?
2394fn parseSuffixExpr(p: *Parse) !?Node.Index {2355fn 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
2444 var res = try p.parsePrimaryTypeExpr() orelse return null;2356 var res = try p.parsePrimaryTypeExpr() orelse return null;
2445 while (true) {2357 while (true) {
2446 const opt_suffix_op = try p.parseSuffixOp(res);2358 const opt_suffix_op = try p.parseSuffixOp(res);
lib/std/zig/Zir.zig+4-43
...@@ -899,8 +899,6 @@ pub const Inst = struct {...@@ -899,8 +899,6 @@ pub const Inst = struct {
899 type_name,899 type_name,
900 /// Implement builtin `@Frame`. Uses `un_node`.900 /// Implement builtin `@Frame`. Uses `un_node`.
901 frame_type,901 frame_type,
902 /// Implement builtin `@frameSize`. Uses `un_node`.
903 frame_size,
904902
905 /// Implements the `@intFromFloat` builtin.903 /// Implements the `@intFromFloat` builtin.
906 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.904 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
...@@ -1044,7 +1042,6 @@ pub const Inst = struct {...@@ -1044,7 +1042,6 @@ pub const Inst = struct {
10441042
1045 /// Implements `resume` syntax. Uses `un_node` field.1043 /// Implements `resume` syntax. Uses `un_node` field.
1046 @"resume",1044 @"resume",
1047 @"await",
10481045
1049 /// A defer statement.1046 /// A defer statement.
1050 /// Uses the `defer` union field.1047 /// Uses the `defer` union field.
...@@ -1241,7 +1238,6 @@ pub const Inst = struct {...@@ -1241,7 +1238,6 @@ pub const Inst = struct {
1241 .tag_name,1238 .tag_name,
1242 .type_name,1239 .type_name,
1243 .frame_type,1240 .frame_type,
1244 .frame_size,
1245 .int_from_float,1241 .int_from_float,
1246 .float_from_int,1242 .float_from_int,
1247 .ptr_from_int,1243 .ptr_from_int,
...@@ -1279,7 +1275,6 @@ pub const Inst = struct {...@@ -1279,7 +1275,6 @@ pub const Inst = struct {
1279 .min,1275 .min,
1280 .c_import,1276 .c_import,
1281 .@"resume",1277 .@"resume",
1282 .@"await",
1283 .ret_err_value_code,1278 .ret_err_value_code,
1284 .extended,1279 .extended,
1285 .ret_ptr,1280 .ret_ptr,
...@@ -1526,7 +1521,6 @@ pub const Inst = struct {...@@ -1526,7 +1521,6 @@ pub const Inst = struct {
1526 .tag_name,1521 .tag_name,
1527 .type_name,1522 .type_name,
1528 .frame_type,1523 .frame_type,
1529 .frame_size,
1530 .int_from_float,1524 .int_from_float,
1531 .float_from_int,1525 .float_from_int,
1532 .ptr_from_int,1526 .ptr_from_int,
...@@ -1560,7 +1554,6 @@ pub const Inst = struct {...@@ -1560,7 +1554,6 @@ pub const Inst = struct {
1560 .min,1554 .min,
1561 .c_import,1555 .c_import,
1562 .@"resume",1556 .@"resume",
1563 .@"await",
1564 .ret_err_value_code,1557 .ret_err_value_code,
1565 .@"break",1558 .@"break",
1566 .break_inline,1559 .break_inline,
...@@ -1791,7 +1784,6 @@ pub const Inst = struct {...@@ -1791,7 +1784,6 @@ pub const Inst = struct {
1791 .tag_name = .un_node,1784 .tag_name = .un_node,
1792 .type_name = .un_node,1785 .type_name = .un_node,
1793 .frame_type = .un_node,1786 .frame_type = .un_node,
1794 .frame_size = .un_node,
17951787
1796 .int_from_float = .pl_node,1788 .int_from_float = .pl_node,
1797 .float_from_int = .pl_node,1789 .float_from_int = .pl_node,
...@@ -1852,7 +1844,6 @@ pub const Inst = struct {...@@ -1852,7 +1844,6 @@ pub const Inst = struct {
1852 .make_ptr_const = .un_node,1844 .make_ptr_const = .un_node,
18531845
1854 .@"resume" = .un_node,1846 .@"resume" = .un_node,
1855 .@"await" = .un_node,
18561847
1857 .@"defer" = .@"defer",1848 .@"defer" = .@"defer",
1858 .defer_err_code = .defer_err_code,1849 .defer_err_code = .defer_err_code,
...@@ -2016,8 +2007,6 @@ pub const Inst = struct {...@@ -2016,8 +2007,6 @@ pub const Inst = struct {
2016 /// Implements the `@errorCast` builtin.2007 /// Implements the `@errorCast` builtin.
2017 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.2008 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
2018 error_cast,2009 error_cast,
2019 /// `operand` is payload index to `UnNode`.
2020 await_nosuspend,
2021 /// Implements `@breakpoint`.2010 /// Implements `@breakpoint`.
2022 /// `operand` is `src_node: Ast.Node.Offset`.2011 /// `operand` is `src_node: Ast.Node.Offset`.
2023 breakpoint,2012 breakpoint,
...@@ -2038,9 +2027,6 @@ pub const Inst = struct {...@@ -2038,9 +2027,6 @@ pub const Inst = struct {
2038 /// `operand` is payload index to `Reify`.2027 /// `operand` is payload index to `Reify`.
2039 /// `small` contains `NameStrategy`.2028 /// `small` contains `NameStrategy`.
2040 reify,2029 reify,
2041 /// Implements the `@asyncCall` builtin.
2042 /// `operand` is payload index to `AsyncCall`.
2043 builtin_async_call,
2044 /// Implements the `@cmpxchgStrong` and `@cmpxchgWeak` builtins.2030 /// Implements the `@cmpxchgStrong` and `@cmpxchgWeak` builtins.
2045 /// `small` 0=>weak 1=>strong2031 /// `small` 0=>weak 1=>strong
2046 /// `operand` is payload index to `Cmpxchg`.2032 /// `operand` is payload index to `Cmpxchg`.
...@@ -2689,7 +2675,6 @@ pub const Inst = struct {...@@ -2689,7 +2675,6 @@ pub const Inst = struct {
2689 @"test",2675 @"test",
2690 decltest,2676 decltest,
2691 @"comptime",2677 @"comptime",
2692 @"usingnamespace",
2693 @"const",2678 @"const",
2694 @"var",2679 @"var",
2695 };2680 };
...@@ -2706,7 +2691,7 @@ pub const Inst = struct {...@@ -2706,7 +2691,7 @@ pub const Inst = struct {
2706 src_column: u32,2691 src_column: u32,
27072692
2708 kind: Kind,2693 kind: Kind,
2709 /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"`, `.@"usingnamespace"`.2694 /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"`
2710 name: NullTerminatedString,2695 name: NullTerminatedString,
2711 /// Always `false` for `kind` of `unnamed_test`, `.@"test"`, `.decltest`, `.@"comptime"`.2696 /// Always `false` for `kind` of `unnamed_test`, `.@"test"`, `.decltest`, `.@"comptime"`.
2712 is_pub: bool,2697 is_pub: bool,
...@@ -2737,9 +2722,6 @@ pub const Inst = struct {...@@ -2737,9 +2722,6 @@ pub const Inst = struct {
2737 decltest,2722 decltest,
2738 @"comptime",2723 @"comptime",
27392724
2740 @"usingnamespace",
2741 pub_usingnamespace,
2742
2743 const_simple,2725 const_simple,
2744 const_typed,2726 const_typed,
2745 @"const",2727 @"const",
...@@ -2776,8 +2758,6 @@ pub const Inst = struct {...@@ -2776,8 +2758,6 @@ pub const Inst = struct {
2776 return switch (id) {2758 return switch (id) {
2777 .unnamed_test,2759 .unnamed_test,
2778 .@"comptime",2760 .@"comptime",
2779 .@"usingnamespace",
2780 .pub_usingnamespace,
2781 => false,2761 => false,
2782 else => true,2762 else => true,
2783 };2763 };
...@@ -2802,8 +2782,6 @@ pub const Inst = struct {...@@ -2802,8 +2782,6 @@ pub const Inst = struct {
2802 .@"test",2782 .@"test",
2803 .decltest,2783 .decltest,
2804 .@"comptime",2784 .@"comptime",
2805 .@"usingnamespace",
2806 .pub_usingnamespace,
2807 => false, // these constructs are untyped2785 => false, // these constructs are untyped
2808 .const_simple,2786 .const_simple,
2809 .pub_const_simple,2787 .pub_const_simple,
...@@ -2835,8 +2813,6 @@ pub const Inst = struct {...@@ -2835,8 +2813,6 @@ pub const Inst = struct {
2835 .@"test",2813 .@"test",
2836 .decltest,2814 .decltest,
2837 .@"comptime",2815 .@"comptime",
2838 .@"usingnamespace",
2839 .pub_usingnamespace,
2840 => false, // these constructs are untyped2816 => false, // these constructs are untyped
2841 .const_simple,2817 .const_simple,
2842 .const_typed,2818 .const_typed,
...@@ -2879,7 +2855,6 @@ pub const Inst = struct {...@@ -2879,7 +2855,6 @@ pub const Inst = struct {
2879 .@"test" => .@"test",2855 .@"test" => .@"test",
2880 .decltest => .decltest,2856 .decltest => .decltest,
2881 .@"comptime" => .@"comptime",2857 .@"comptime" => .@"comptime",
2882 .@"usingnamespace", .pub_usingnamespace => .@"usingnamespace",
2883 .const_simple,2858 .const_simple,
2884 .const_typed,2859 .const_typed,
2885 .@"const",2860 .@"const",
...@@ -2913,7 +2888,6 @@ pub const Inst = struct {...@@ -2913,7 +2888,6 @@ pub const Inst = struct {
29132888
2914 pub fn isPub(id: Id) bool {2889 pub fn isPub(id: Id) bool {
2915 return switch (id) {2890 return switch (id) {
2916 .pub_usingnamespace,
2917 .pub_const_simple,2891 .pub_const_simple,
2918 .pub_const_typed,2892 .pub_const_typed,
2919 .pub_const,2893 .pub_const,
...@@ -2949,8 +2923,7 @@ pub const Inst = struct {...@@ -2949,8 +2923,7 @@ pub const Inst = struct {
29492923
2950 pub const Name = enum(u32) {2924 pub const Name = enum(u32) {
2951 @"comptime" = std.math.maxInt(u32),2925 @"comptime" = std.math.maxInt(u32),
2952 @"usingnamespace" = std.math.maxInt(u32) - 1,2926 unnamed_test = std.math.maxInt(u32) - 1,
2953 unnamed_test = std.math.maxInt(u32) - 2,
2954 /// Other values are `NullTerminatedString` values, i.e. index into2927 /// Other values are `NullTerminatedString` values, i.e. index into
2955 /// `string_bytes`. If the byte referenced is 0, the decl is a named2928 /// `string_bytes`. If the byte referenced is 0, the decl is a named
2956 /// test, and the actual name begins at the following byte.2929 /// test, and the actual name begins at the following byte.
...@@ -2958,13 +2931,13 @@ pub const Inst = struct {...@@ -2958,13 +2931,13 @@ pub const Inst = struct {
29582931
2959 pub fn isNamedTest(name: Name, zir: Zir) bool {2932 pub fn isNamedTest(name: Name, zir: Zir) bool {
2960 return switch (name) {2933 return switch (name) {
2961 .@"comptime", .@"usingnamespace", .unnamed_test => false,2934 .@"comptime", .unnamed_test => false,
2962 _ => zir.string_bytes[@intFromEnum(name)] == 0,2935 _ => zir.string_bytes[@intFromEnum(name)] == 0,
2963 };2936 };
2964 }2937 }
2965 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {2938 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {
2966 switch (name) {2939 switch (name) {
2967 .@"comptime", .@"usingnamespace", .unnamed_test => return null,2940 .@"comptime", .unnamed_test => return null,
2968 _ => {},2941 _ => {},
2969 }2942 }
2970 const idx: u32 = @intFromEnum(name);2943 const idx: u32 = @intFromEnum(name);
...@@ -3771,14 +3744,6 @@ pub const Inst = struct {...@@ -3771,14 +3744,6 @@ pub const Inst = struct {
3771 b: Ref,3744 b: Ref,
3772 };3745 };
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
3782 /// Trailing: inst: Index // for every body_len3747 /// Trailing: inst: Index // for every body_len
3783 pub const Param = struct {3748 pub const Param = struct {
3784 /// Null-terminated string index.3749 /// Null-terminated string index.
...@@ -4297,7 +4262,6 @@ fn findTrackableInner(...@@ -4297,7 +4262,6 @@ fn findTrackableInner(
4297 .tag_name,4262 .tag_name,
4298 .type_name,4263 .type_name,
4299 .frame_type,4264 .frame_type,
4300 .frame_size,
4301 .int_from_float,4265 .int_from_float,
4302 .float_from_int,4266 .float_from_int,
4303 .ptr_from_int,4267 .ptr_from_int,
...@@ -4337,7 +4301,6 @@ fn findTrackableInner(...@@ -4337,7 +4301,6 @@ fn findTrackableInner(
4337 .resolve_inferred_alloc,4301 .resolve_inferred_alloc,
4338 .make_ptr_const,4302 .make_ptr_const,
4339 .@"resume",4303 .@"resume",
4340 .@"await",
4341 .save_err_ret_index,4304 .save_err_ret_index,
4342 .restore_err_ret_index_unconditional,4305 .restore_err_ret_index_unconditional,
4343 .restore_err_ret_index_fn_entry,4306 .restore_err_ret_index_fn_entry,
...@@ -4380,14 +4343,12 @@ fn findTrackableInner(...@@ -4380,14 +4343,12 @@ fn findTrackableInner(
4380 .prefetch,4343 .prefetch,
4381 .set_float_mode,4344 .set_float_mode,
4382 .error_cast,4345 .error_cast,
4383 .await_nosuspend,
4384 .breakpoint,4346 .breakpoint,
4385 .disable_instrumentation,4347 .disable_instrumentation,
4386 .disable_intrinsics,4348 .disable_intrinsics,
4387 .select,4349 .select,
4388 .int_from_error,4350 .int_from_error,
4389 .error_from_int,4351 .error_from_int,
4390 .builtin_async_call,
4391 .cmpxchg,4352 .cmpxchg,
4392 .c_va_arg,4353 .c_va_arg,
4393 .c_va_copy,4354 .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...@@ -100,7 +100,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
100100
101 switch (tree.nodeTag(node)) {101 switch (tree.nodeTag(node)) {
102 .root => unreachable,102 .root => unreachable,
103 .@"usingnamespace" => unreachable,
104 .test_decl => unreachable,103 .test_decl => unreachable,
105 .container_field_init => unreachable,104 .container_field_init => unreachable,
106 .container_field_align => unreachable,105 .container_field_align => unreachable,
...@@ -204,12 +203,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator...@@ -204,12 +203,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
204203
205 .call_one,204 .call_one,
206 .call_one_comma,205 .call_one_comma,
207 .async_call_one,
208 .async_call_one_comma,
209 .call,206 .call,
210 .call_comma,207 .call_comma,
211 .async_call,
212 .async_call_comma,
213 .@"return",208 .@"return",
214 .if_simple,209 .if_simple,
215 .@"if",210 .@"if",
...@@ -226,7 +221,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator...@@ -226,7 +221,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
226 .switch_comma,221 .switch_comma,
227 .@"nosuspend",222 .@"nosuspend",
228 .@"suspend",223 .@"suspend",
229 .@"await",
230 .@"resume",224 .@"resume",
231 .@"try",225 .@"try",
232 .unreachable_literal,226 .unreachable_literal,
lib/std/zig/llvm/Builder.zig+2-2
...@@ -1521,9 +1521,9 @@ pub const Attribute = union(Kind) {...@@ -1521,9 +1521,9 @@ pub const Attribute = union(Kind) {
1521 pub const UwTable = enum(u32) {1521 pub const UwTable = enum(u32) {
1522 none,1522 none,
1523 sync,1523 sync,
1524 @"async",1524 async,
15251525
1526 pub const default = UwTable.@"async";1526 pub const default = UwTable.async;
1527 };1527 };
15281528
1529 pub const VScaleRange = packed struct(u32) {1529 pub const VScaleRange = packed struct(u32) {
lib/std/zig/parser_test.zig-139
...@@ -341,15 +341,6 @@ test "zig fmt: nosuspend block" {...@@ -341,15 +341,6 @@ test "zig fmt: nosuspend block" {
341 );341 );
342}342}
343343
344test "zig fmt: nosuspend await" {
345 try testCanonical(
346 \\fn foo() void {
347 \\ x = nosuspend await y;
348 \\}
349 \\
350 );
351}
352
353test "zig fmt: container declaration, single line" {344test "zig fmt: container declaration, single line" {
354 try testCanonical(345 try testCanonical(
355 \\const X = struct { foo: i32 };346 \\const X = struct { foo: i32 };
...@@ -1093,18 +1084,6 @@ test "zig fmt: block in slice expression" {...@@ -1093,18 +1084,6 @@ test "zig fmt: block in slice expression" {
1093 );1084 );
1094}1085}
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
1108test "zig fmt: whitespace fixes" {1087test "zig fmt: whitespace fixes" {
1109 try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n",1088 try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n",
1110 \\test "" {1089 \\test "" {
...@@ -1549,17 +1528,6 @@ test "zig fmt: spaces around slice operator" {...@@ -1549,17 +1528,6 @@ test "zig fmt: spaces around slice operator" {
1549 );1528 );
1550}1529}
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
1563test "zig fmt: 2nd arg multiline string" {1531test "zig fmt: 2nd arg multiline string" {
1564 try testCanonical(1532 try testCanonical(
1565 \\comptime {1533 \\comptime {
...@@ -3946,27 +3914,6 @@ test "zig fmt: inline asm" {...@@ -3946,27 +3914,6 @@ test "zig fmt: inline asm" {
3946 );3914 );
3947}3915}
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
3970test "zig fmt: nosuspend" {3917test "zig fmt: nosuspend" {
3971 try testCanonical(3918 try testCanonical(
3972 \\const a = nosuspend foo();3919 \\const a = nosuspend foo();
...@@ -3989,14 +3936,6 @@ test "zig fmt: Block after if" {...@@ -3989,14 +3936,6 @@ test "zig fmt: Block after if" {
3989 );3936 );
3990}3937}
39913938
3992test "zig fmt: usingnamespace" {
3993 try testCanonical(
3994 \\usingnamespace @import("std");
3995 \\pub usingnamespace @import("std");
3996 \\
3997 );
3998}
3999
4000test "zig fmt: string identifier" {3939test "zig fmt: string identifier" {
4001 try testCanonical(3940 try testCanonical(
4002 \\const @"a b" = @"c d".@"e f";3941 \\const @"a b" = @"c d".@"e f";
...@@ -5140,17 +5079,6 @@ test "zig fmt: line comment after multiline single expr if statement with multil...@@ -5140,17 +5079,6 @@ test "zig fmt: line comment after multiline single expr if statement with multil
5140 );5079 );
5141}5080}
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
5154test "zig fmt: respect extra newline between switch items" {5082test "zig fmt: respect extra newline between switch items" {
5155 try testCanonical(5083 try testCanonical(
5156 \\const a = switch (b) {5084 \\const a = switch (b) {
...@@ -5719,34 +5647,6 @@ test "zig fmt: canonicalize symbols (primitive types)" {...@@ -5719,34 +5647,6 @@ test "zig fmt: canonicalize symbols (primitive types)" {
5719 );5647 );
5720}5648}
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
5750test "zig fmt: no space before newline before multiline string" {5650test "zig fmt: no space before newline before multiline string" {
5751 try testCanonical(5651 try testCanonical(
5752 \\const S = struct {5652 \\const S = struct {
...@@ -6181,29 +6081,6 @@ test "recovery: missing return type" {...@@ -6181,29 +6081,6 @@ test "recovery: missing return type" {
6181 });6081 });
6182}6082}
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
6207test "recovery: invalid extern/inline" {6084test "recovery: invalid extern/inline" {
6208 try testError(6085 try testError(
6209 \\inline test "" { a & b; }6086 \\inline test "" { a & b; }
...@@ -6232,22 +6109,6 @@ test "recovery: missing semicolon" {...@@ -6232,22 +6109,6 @@ test "recovery: missing semicolon" {
6232 });6109 });
6233}6110}
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
6251// TODO after https://github.com/ziglang/zig/issues/35 is implemented,6112// TODO after https://github.com/ziglang/zig/issues/35 is implemented,
6252// we should be able to recover from this *at any indentation level*,6113// we should be able to recover from this *at any indentation level*,
6253// reporting a parse error and yet also parsing all the decls even6114// reporting a parse error and yet also parsing all the decls even
lib/std/zig/render.zig-20
...@@ -262,17 +262,6 @@ fn renderMember(...@@ -262,17 +262,6 @@ fn renderMember(
262 return renderToken(r, tree.lastToken(decl) + 1, space); // semicolon262 return renderToken(r, tree.lastToken(decl) + 1, space); // semicolon
263 },263 },
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
276 .global_var_decl,265 .global_var_decl,
277 .local_var_decl,266 .local_var_decl,
278 .simple_var_decl,267 .simple_var_decl,
...@@ -591,7 +580,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -591,7 +580,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
591580
592 .@"try",581 .@"try",
593 .@"resume",582 .@"resume",
594 .@"await",
595 => {583 => {
596 try renderToken(r, tree.nodeMainToken(node), .space);584 try renderToken(r, tree.nodeMainToken(node), .space);
597 return renderExpression(r, tree.nodeData(node).node, space);585 return renderExpression(r, tree.nodeData(node).node, space);
...@@ -635,12 +623,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -635,12 +623,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
635623
636 .call_one,624 .call_one,
637 .call_one_comma,625 .call_one_comma,
638 .async_call_one,
639 .async_call_one_comma,
640 .call,626 .call,
641 .call_comma,627 .call_comma,
642 .async_call,
643 .async_call_comma,
644 => {628 => {
645 var buf: [1]Ast.Node.Index = undefined;629 var buf: [1]Ast.Node.Index = undefined;
646 return renderCall(r, tree.fullCall(&buf, node).?, space);630 return renderCall(r, tree.fullCall(&buf, node).?, space);
...@@ -882,7 +866,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -882,7 +866,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
882 .local_var_decl => unreachable,866 .local_var_decl => unreachable,
883 .simple_var_decl => unreachable,867 .simple_var_decl => unreachable,
884 .aligned_var_decl => unreachable,868 .aligned_var_decl => unreachable,
885 .@"usingnamespace" => unreachable,
886 .test_decl => unreachable,869 .test_decl => unreachable,
887 .asm_output => unreachable,870 .asm_output => unreachable,
888 .asm_input => unreachable,871 .asm_input => unreachable,
...@@ -2551,9 +2534,6 @@ fn renderCall(...@@ -2551,9 +2534,6 @@ fn renderCall(
2551 call: Ast.full.Call,2534 call: Ast.full.Call,
2552 space: Space,2535 space: Space,
2553) Error!void {2536) Error!void {
2554 if (call.async_token) |async_token| {
2555 try renderToken(r, async_token, .space);
2556 }
2557 try renderExpression(r, call.ast.fn_expr, .none);2537 try renderExpression(r, call.ast.fn_expr, .none);
2558 try renderParamList(r, call.ast.lparen, call.ast.params, space);2538 try renderParamList(r, call.ast.lparen, call.ast.params, space);
2559}2539}
lib/std/zig/tokenizer.zig-9
...@@ -17,8 +17,6 @@ pub const Token = struct {...@@ -17,8 +17,6 @@ pub const Token = struct {
17 .{ "anyframe", .keyword_anyframe },17 .{ "anyframe", .keyword_anyframe },
18 .{ "anytype", .keyword_anytype },18 .{ "anytype", .keyword_anytype },
19 .{ "asm", .keyword_asm },19 .{ "asm", .keyword_asm },
20 .{ "async", .keyword_async },
21 .{ "await", .keyword_await },
22 .{ "break", .keyword_break },20 .{ "break", .keyword_break },
23 .{ "callconv", .keyword_callconv },21 .{ "callconv", .keyword_callconv },
24 .{ "catch", .keyword_catch },22 .{ "catch", .keyword_catch },
...@@ -55,7 +53,6 @@ pub const Token = struct {...@@ -55,7 +53,6 @@ pub const Token = struct {
55 .{ "try", .keyword_try },53 .{ "try", .keyword_try },
56 .{ "union", .keyword_union },54 .{ "union", .keyword_union },
57 .{ "unreachable", .keyword_unreachable },55 .{ "unreachable", .keyword_unreachable },
58 .{ "usingnamespace", .keyword_usingnamespace },
59 .{ "var", .keyword_var },56 .{ "var", .keyword_var },
60 .{ "volatile", .keyword_volatile },57 .{ "volatile", .keyword_volatile },
61 .{ "while", .keyword_while },58 .{ "while", .keyword_while },
...@@ -146,8 +143,6 @@ pub const Token = struct {...@@ -146,8 +143,6 @@ pub const Token = struct {
146 keyword_anyframe,143 keyword_anyframe,
147 keyword_anytype,144 keyword_anytype,
148 keyword_asm,145 keyword_asm,
149 keyword_async,
150 keyword_await,
151 keyword_break,146 keyword_break,
152 keyword_callconv,147 keyword_callconv,
153 keyword_catch,148 keyword_catch,
...@@ -184,7 +179,6 @@ pub const Token = struct {...@@ -184,7 +179,6 @@ pub const Token = struct {
184 keyword_try,179 keyword_try,
185 keyword_union,180 keyword_union,
186 keyword_unreachable,181 keyword_unreachable,
187 keyword_usingnamespace,
188 keyword_var,182 keyword_var,
189 keyword_volatile,183 keyword_volatile,
190 keyword_while,184 keyword_while,
...@@ -273,8 +267,6 @@ pub const Token = struct {...@@ -273,8 +267,6 @@ pub const Token = struct {
273 .keyword_anyframe => "anyframe",267 .keyword_anyframe => "anyframe",
274 .keyword_anytype => "anytype",268 .keyword_anytype => "anytype",
275 .keyword_asm => "asm",269 .keyword_asm => "asm",
276 .keyword_async => "async",
277 .keyword_await => "await",
278 .keyword_break => "break",270 .keyword_break => "break",
279 .keyword_callconv => "callconv",271 .keyword_callconv => "callconv",
280 .keyword_catch => "catch",272 .keyword_catch => "catch",
...@@ -311,7 +303,6 @@ pub const Token = struct {...@@ -311,7 +303,6 @@ pub const Token = struct {
311 .keyword_try => "try",303 .keyword_try => "try",
312 .keyword_union => "union",304 .keyword_union => "union",
313 .keyword_unreachable => "unreachable",305 .keyword_unreachable => "unreachable",
314 .keyword_usingnamespace => "usingnamespace",
315 .keyword_var => "var",306 .keyword_var => "var",
316 .keyword_volatile => "volatile",307 .keyword_volatile => "volatile",
317 .keyword_while => "while",308 .keyword_while => "while",
src/Compilation.zig+1-1
...@@ -6466,7 +6466,7 @@ pub fn addCCArgs(...@@ -6466,7 +6466,7 @@ pub fn addCCArgs(
6466 try argv.append("-fno-asynchronous-unwind-tables");6466 try argv.append("-fno-asynchronous-unwind-tables");
6467 try argv.append("-funwind-tables");6467 try argv.append("-funwind-tables");
6468 },6468 },
6469 .@"async" => try argv.append("-fasynchronous-unwind-tables"),6469 .async => try argv.append("-fasynchronous-unwind-tables"),
6470 }6470 }
64716471
6472 try argv.append("-nostdinc");6472 try argv.append("-nostdinc");
src/InternPool.zig+1-13
...@@ -518,8 +518,6 @@ pub const Nav = struct {...@@ -518,8 +518,6 @@ pub const Nav = struct {
518 namespace: NamespaceIndex,518 namespace: NamespaceIndex,
519 zir_index: TrackedInst.Index,519 zir_index: TrackedInst.Index,
520 },520 },
521 /// TODO: this is a hack! If #20663 isn't accepted, let's figure out something a bit better.
522 is_usingnamespace: bool,
523 status: union(enum) {521 status: union(enum) {
524 /// This `Nav` is pending semantic analysis.522 /// This `Nav` is pending semantic analysis.
525 unresolved,523 unresolved,
...@@ -735,7 +733,7 @@ pub const Nav = struct {...@@ -735,7 +733,7 @@ pub const Nav = struct {
735 @"addrspace": std.builtin.AddressSpace,733 @"addrspace": std.builtin.AddressSpace,
736 /// Populated only if `bits.status == .type_resolved`.734 /// Populated only if `bits.status == .type_resolved`.
737 is_threadlocal: bool,735 is_threadlocal: bool,
738 is_usingnamespace: bool,736 _: u1 = 0,
739 };737 };
740738
741 fn unpack(repr: Repr) Nav {739 fn unpack(repr: Repr) Nav {
...@@ -749,7 +747,6 @@ pub const Nav = struct {...@@ -749,7 +747,6 @@ pub const Nav = struct {
749 assert(repr.analysis_zir_index == .none);747 assert(repr.analysis_zir_index == .none);
750 break :a null;748 break :a null;
751 },749 },
752 .is_usingnamespace = repr.bits.is_usingnamespace,
753 .status = switch (repr.bits.status) {750 .status = switch (repr.bits.status) {
754 .unresolved => .unresolved,751 .unresolved => .unresolved,
755 .type_resolved, .type_resolved_extern_decl => .{ .type_resolved = .{752 .type_resolved, .type_resolved_extern_decl => .{ .type_resolved = .{
...@@ -797,7 +794,6 @@ pub const Nav = struct {...@@ -797,7 +794,6 @@ pub const Nav = struct {
797 .is_const = false,794 .is_const = false,
798 .alignment = .none,795 .alignment = .none,
799 .@"addrspace" = .generic,796 .@"addrspace" = .generic,
800 .is_usingnamespace = nav.is_usingnamespace,
801 .is_threadlocal = false,797 .is_threadlocal = false,
802 },798 },
803 .type_resolved => |r| .{799 .type_resolved => |r| .{
...@@ -805,7 +801,6 @@ pub const Nav = struct {...@@ -805,7 +801,6 @@ pub const Nav = struct {
805 .is_const = r.is_const,801 .is_const = r.is_const,
806 .alignment = r.alignment,802 .alignment = r.alignment,
807 .@"addrspace" = r.@"addrspace",803 .@"addrspace" = r.@"addrspace",
808 .is_usingnamespace = nav.is_usingnamespace,
809 .is_threadlocal = r.is_threadlocal,804 .is_threadlocal = r.is_threadlocal,
810 },805 },
811 .fully_resolved => |r| .{806 .fully_resolved => |r| .{
...@@ -813,7 +808,6 @@ pub const Nav = struct {...@@ -813,7 +808,6 @@ pub const Nav = struct {
813 .is_const = r.is_const,808 .is_const = r.is_const,
814 .alignment = r.alignment,809 .alignment = r.alignment,
815 .@"addrspace" = r.@"addrspace",810 .@"addrspace" = r.@"addrspace",
816 .is_usingnamespace = nav.is_usingnamespace,
817 .is_threadlocal = false,811 .is_threadlocal = false,
818 },812 },
819 },813 },
...@@ -6865,8 +6859,6 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {...@@ -6865,8 +6859,6 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {
6865 {6859 {
6866 namespace.pub_decls.deinit(gpa);6860 namespace.pub_decls.deinit(gpa);
6867 namespace.priv_decls.deinit(gpa);6861 namespace.priv_decls.deinit(gpa);
6868 namespace.pub_usingnamespace.deinit(gpa);
6869 namespace.priv_usingnamespace.deinit(gpa);
6870 namespace.comptime_decls.deinit(gpa);6862 namespace.comptime_decls.deinit(gpa);
6871 namespace.test_decls.deinit(gpa);6863 namespace.test_decls.deinit(gpa);
6872 }6864 }
...@@ -11503,7 +11495,6 @@ pub fn createNav(...@@ -11503,7 +11495,6 @@ pub fn createNav(
11503 .@"linksection" = opts.@"linksection",11495 .@"linksection" = opts.@"linksection",
11504 .@"addrspace" = opts.@"addrspace",11496 .@"addrspace" = opts.@"addrspace",
11505 } },11497 } },
11506 .is_usingnamespace = false,
11507 }));11498 }));
11508 return index_unwrapped.wrap(ip);11499 return index_unwrapped.wrap(ip);
11509}11500}
...@@ -11518,8 +11509,6 @@ pub fn createDeclNav(...@@ -11518,8 +11509,6 @@ pub fn createDeclNav(
11518 fqn: NullTerminatedString,11509 fqn: NullTerminatedString,
11519 zir_index: TrackedInst.Index,11510 zir_index: TrackedInst.Index,
11520 namespace: NamespaceIndex,11511 namespace: NamespaceIndex,
11521 /// TODO: this is hacky! See `Nav.is_usingnamespace`.
11522 is_usingnamespace: bool,
11523) Allocator.Error!Nav.Index {11512) Allocator.Error!Nav.Index {
11524 const navs = ip.getLocal(tid).getMutableNavs(gpa);11513 const navs = ip.getLocal(tid).getMutableNavs(gpa);
1152511514
...@@ -11538,7 +11527,6 @@ pub fn createDeclNav(...@@ -11538,7 +11527,6 @@ pub fn createDeclNav(
11538 .zir_index = zir_index,11527 .zir_index = zir_index,
11539 },11528 },
11540 .status = .unresolved,11529 .status = .unresolved,
11541 .is_usingnamespace = is_usingnamespace,
11542 }));11530 }));
1154311531
11544 return nav;11532 return nav;
src/Sema.zig+19-155
...@@ -1280,7 +1280,6 @@ fn analyzeBodyInner(...@@ -1280,7 +1280,6 @@ fn analyzeBodyInner(
1280 .tag_name => try sema.zirTagName(block, inst),1280 .tag_name => try sema.zirTagName(block, inst),
1281 .type_name => try sema.zirTypeName(block, inst),1281 .type_name => try sema.zirTypeName(block, inst),
1282 .frame_type => try sema.zirFrameType(block, inst),1282 .frame_type => try sema.zirFrameType(block, inst),
1283 .frame_size => try sema.zirFrameSize(block, inst),
1284 .int_from_float => try sema.zirIntFromFloat(block, inst),1283 .int_from_float => try sema.zirIntFromFloat(block, inst),
1285 .float_from_int => try sema.zirFloatFromInt(block, inst),1284 .float_from_int => try sema.zirFloatFromInt(block, inst),
1286 .ptr_from_int => try sema.zirPtrFromInt(block, inst),1285 .ptr_from_int => try sema.zirPtrFromInt(block, inst),
...@@ -1302,7 +1301,6 @@ fn analyzeBodyInner(...@@ -1302,7 +1301,6 @@ fn analyzeBodyInner(
1302 .mul_add => try sema.zirMulAdd(block, inst),1301 .mul_add => try sema.zirMulAdd(block, inst),
1303 .builtin_call => try sema.zirBuiltinCall(block, inst),1302 .builtin_call => try sema.zirBuiltinCall(block, inst),
1304 .@"resume" => try sema.zirResume(block, inst),1303 .@"resume" => try sema.zirResume(block, inst),
1305 .@"await" => try sema.zirAwait(block, inst),
1306 .for_len => try sema.zirForLen(block, inst),1304 .for_len => try sema.zirForLen(block, inst),
1307 .validate_array_init_ref_ty => try sema.zirValidateArrayInitRefTy(block, inst),1305 .validate_array_init_ref_ty => try sema.zirValidateArrayInitRefTy(block, inst),
1308 .opt_eu_base_ptr_init => try sema.zirOptEuBasePtrInit(block, inst),1306 .opt_eu_base_ptr_init => try sema.zirOptEuBasePtrInit(block, inst),
...@@ -1410,12 +1408,10 @@ fn analyzeBodyInner(...@@ -1410,12 +1408,10 @@ fn analyzeBodyInner(
1410 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),1408 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),
1411 .prefetch => try sema.zirPrefetch( block, extended),1409 .prefetch => try sema.zirPrefetch( block, extended),
1412 .error_cast => try sema.zirErrorCast( block, extended),1410 .error_cast => try sema.zirErrorCast( block, extended),
1413 .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),
1414 .select => try sema.zirSelect( block, extended),1411 .select => try sema.zirSelect( block, extended),
1415 .int_from_error => try sema.zirIntFromError( block, extended),1412 .int_from_error => try sema.zirIntFromError( block, extended),
1416 .error_from_int => try sema.zirErrorFromInt( block, extended),1413 .error_from_int => try sema.zirErrorFromInt( block, extended),
1417 .reify => try sema.zirReify( block, extended, inst),1414 .reify => try sema.zirReify( block, extended, inst),
1418 .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended),
1419 .cmpxchg => try sema.zirCmpxchg( block, extended),1415 .cmpxchg => try sema.zirCmpxchg( block, extended),
1420 .c_va_arg => try sema.zirCVaArg( block, extended),1416 .c_va_arg => try sema.zirCVaArg( block, extended),
1421 .c_va_copy => try sema.zirCVaCopy( block, extended),1417 .c_va_copy => try sema.zirCVaCopy( block, extended),
...@@ -2864,7 +2860,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2864,7 +2860,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2864 sema.code.nullTerminatedString(str),2860 sema.code.nullTerminatedString(str),
2865 .no_embedded_nulls,2861 .no_embedded_nulls,
2866 );2862 );
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);
2868 break :capture InternPool.CaptureValue.wrap(.{ .nav_val = nav });2864 break :capture InternPool.CaptureValue.wrap(.{ .nav_val = nav });
2869 },2865 },
2870 .decl_ref => |str| capture: {2866 .decl_ref => |str| capture: {
...@@ -2874,7 +2870,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2874,7 +2870,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2874 sema.code.nullTerminatedString(str),2870 sema.code.nullTerminatedString(str),
2875 .no_embedded_nulls,2871 .no_embedded_nulls,
2876 );2872 );
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);
2878 break :capture InternPool.CaptureValue.wrap(.{ .nav_ref = nav });2874 break :capture InternPool.CaptureValue.wrap(.{ .nav_ref = nav });
2879 },2875 },
2880 };2876 };
...@@ -6929,7 +6925,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6929,7 +6925,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
6929 inst_data.get(sema.code),6925 inst_data.get(sema.code),
6930 .no_embedded_nulls,6926 .no_embedded_nulls,
6931 );6927 );
6932 const nav_index = try sema.lookupIdentifier(block, src, decl_name);6928 const nav_index = try sema.lookupIdentifier(block, decl_name);
6933 return sema.analyzeNavRef(block, src, nav_index);6929 return sema.analyzeNavRef(block, src, nav_index);
6934}6930}
69356931
...@@ -6944,16 +6940,16 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6944,16 +6940,16 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
6944 inst_data.get(sema.code),6940 inst_data.get(sema.code),
6945 .no_embedded_nulls,6941 .no_embedded_nulls,
6946 );6942 );
6947 const nav = try sema.lookupIdentifier(block, src, decl_name);6943 const nav = try sema.lookupIdentifier(block, decl_name);
6948 return sema.analyzeNavVal(block, src, nav);6944 return sema.analyzeNavVal(block, src, nav);
6949}6945}
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 {
6952 const pt = sema.pt;6948 const pt = sema.pt;
6953 const zcu = pt.zcu;6949 const zcu = pt.zcu;
6954 var namespace = block.namespace;6950 var namespace = block.namespace;
6955 while (true) {6951 while (true) {
6956 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| {6952 if (try sema.lookupInNamespace(block, namespace, name)) |lookup| {
6957 assert(lookup.accessible);6953 assert(lookup.accessible);
6958 return lookup.nav;6954 return lookup.nav;
6959 }6955 }
...@@ -6962,15 +6958,12 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo...@@ -6962,15 +6958,12 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo
6962 unreachable; // AstGen detects use of undeclared identifiers.6958 unreachable; // AstGen detects use of undeclared identifiers.
6963}6959}
69646960
6965/// This looks up a member of a specific namespace. It is affected by `usingnamespace` but6961/// This looks up a member of a specific namespace.
6966/// only for ones in the specified namespace.
6967fn lookupInNamespace(6962fn lookupInNamespace(
6968 sema: *Sema,6963 sema: *Sema,
6969 block: *Block,6964 block: *Block,
6970 src: LazySrcLoc,
6971 namespace_index: InternPool.NamespaceIndex,6965 namespace_index: InternPool.NamespaceIndex,
6972 ident_name: InternPool.NullTerminatedString,6966 ident_name: InternPool.NullTerminatedString,
6973 observe_usingnamespace: bool,
6974) CompileError!?struct {6967) CompileError!?struct {
6975 nav: InternPool.Nav.Index,6968 nav: InternPool.Nav.Index,
6976 /// If `false`, the declaration is in a different file and is not `pub`.6969 /// If `false`, the declaration is in a different file and is not `pub`.
...@@ -6979,7 +6972,6 @@ fn lookupInNamespace(...@@ -6979,7 +6972,6 @@ fn lookupInNamespace(
6979} {6972} {
6980 const pt = sema.pt;6973 const pt = sema.pt;
6981 const zcu = pt.zcu;6974 const zcu = pt.zcu;
6982 const ip = &zcu.intern_pool;
69836975
6984 try pt.ensureNamespaceUpToDate(namespace_index);6976 try pt.ensureNamespaceUpToDate(namespace_index);
69856977
...@@ -6996,75 +6988,7 @@ fn lookupInNamespace(...@@ -6996,75 +6988,7 @@ fn lookupInNamespace(
6996 } });6988 } });
6997 }6989 }
69986990
6999 if (observe_usingnamespace and (namespace.pub_usingnamespace.items.len != 0 or namespace.priv_usingnamespace.items.len != 0)) {6991 if (namespace.pub_decls.getKeyAdapted(ident_name, adapter)) |nav_index| {
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| {
7068 return .{6992 return .{
7069 .nav = nav_index,6993 .nav = nav_index,
7070 .accessible = true,6994 .accessible = true,
...@@ -7653,10 +7577,6 @@ fn analyzeCall(...@@ -7653,10 +7577,6 @@ fn analyzeCall(
7653 const ip = &zcu.intern_pool;7577 const ip = &zcu.intern_pool;
7654 const arena = sema.arena;7578 const arena = sema.arena;
76557579
7656 if (modifier == .async_kw) {
7657 return sema.failWithUseOfAsync(block, call_src);
7658 }
7659
7660 const maybe_func_inst = try sema.funcDeclSrcInst(callee);7580 const maybe_func_inst = try sema.funcDeclSrcInst(callee);
7661 const func_ret_ty_src: LazySrcLoc = if (maybe_func_inst) |fn_decl_inst| .{7581 const func_ret_ty_src: LazySrcLoc = if (maybe_func_inst) |fn_decl_inst| .{
7662 .base_node_inst = fn_decl_inst,7582 .base_node_inst = fn_decl_inst,
...@@ -8048,14 +7968,13 @@ fn analyzeCall(...@@ -8048,14 +7968,13 @@ fn analyzeCall(
8048 }7968 }
80497969
8050 const call_tag: Air.Inst.Tag = switch (modifier) {7970 const call_tag: Air.Inst.Tag = switch (modifier) {
8051 .auto, .no_async => .call,7971 .auto, .no_suspend => .call,
8052 .never_tail => .call_never_tail,7972 .never_tail => .call_never_tail,
8053 .never_inline => .call_never_inline,7973 .never_inline => .call_never_inline,
8054 .always_tail => .call_always_tail,7974 .always_tail => .call_always_tail,
80557975
8056 .always_inline,7976 .always_inline,
8057 .compile_time,7977 .compile_time,
8058 .async_kw,
8059 => unreachable,7978 => unreachable,
8060 };7979 };
80617980
...@@ -13955,7 +13874,6 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13955,7 +13874,6 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13955 const zcu = pt.zcu;13874 const zcu = pt.zcu;
13956 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13875 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13957 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13876 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13958 const src = block.nodeOffset(inst_data.src_node);
13959 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);13877 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13960 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);13878 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
13961 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);13879 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...@@ -13964,7 +13882,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13964 try sema.checkNamespaceType(block, lhs_src, container_type);13882 try sema.checkNamespaceType(block, lhs_src, container_type);
1396513883
13966 const namespace = container_type.getNamespace(zcu).unwrap() orelse return .bool_false;13884 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| {
13968 if (lookup.accessible) {13886 if (lookup.accessible) {
13969 return .bool_true;13887 return .bool_true;
13970 }13888 }
...@@ -17745,7 +17663,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17745,7 +17663,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17745 } });17663 } });
17746 };17664 };
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
17750 const type_enum_ty = try sema.getBuiltinType(src, .@"Type.Enum");17668 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...@@ -17858,7 +17776,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17858 } });17776 } });
17859 };17777 };
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
17863 const enum_tag_ty_val = try pt.intern(.{ .opt = .{17781 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
17864 .ty = (try pt.optionalType(.type_type)).toIntern(),17782 .ty = (try pt.optionalType(.type_type)).toIntern(),
...@@ -18053,7 +17971,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18053,7 +17971,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18053 } });17971 } });
18054 };17972 };
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
18058 const backing_integer_val = try pt.intern(.{ .opt = .{17976 const backing_integer_val = try pt.intern(.{ .opt = .{
18059 .ty = (try pt.optionalType(.type_type)).toIntern(),17977 .ty = (try pt.optionalType(.type_type)).toIntern(),
...@@ -18092,7 +18010,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18092,7 +18010,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18092 const type_opaque_ty = try sema.getBuiltinType(src, .@"Type.Opaque");18010 const type_opaque_ty = try sema.getBuiltinType(src, .@"Type.Opaque");
1809318011
18094 try ty.resolveFields(pt);18012 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
18097 const field_values = .{18015 const field_values = .{
18098 // decls: []const Declaration,18016 // decls: []const Declaration,
...@@ -18114,7 +18032,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18114,7 +18032,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1811418032
18115fn typeInfoDecls(18033fn typeInfoDecls(
18116 sema: *Sema,18034 sema: *Sema,
18117 block: *Block,
18118 src: LazySrcLoc,18035 src: LazySrcLoc,
18119 opt_namespace: InternPool.OptionalNamespaceIndex,18036 opt_namespace: InternPool.OptionalNamespaceIndex,
18120) CompileError!InternPool.Index {18037) CompileError!InternPool.Index {
...@@ -18130,7 +18047,7 @@ fn typeInfoDecls(...@@ -18130,7 +18047,7 @@ fn typeInfoDecls(
18130 var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa);18047 var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa);
18131 defer seen_namespaces.deinit();18048 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
18135 const array_decl_ty = try pt.arrayType(.{18052 const array_decl_ty = try pt.arrayType(.{
18136 .len = decl_vals.items.len,18053 .len = decl_vals.items.len,
...@@ -18164,8 +18081,6 @@ fn typeInfoDecls(...@@ -18164,8 +18081,6 @@ fn typeInfoDecls(
1816418081
18165fn typeInfoNamespaceDecls(18082fn typeInfoNamespaceDecls(
18166 sema: *Sema,18083 sema: *Sema,
18167 block: *Block,
18168 src: LazySrcLoc,
18169 opt_namespace_index: InternPool.OptionalNamespaceIndex,18084 opt_namespace_index: InternPool.OptionalNamespaceIndex,
18170 declaration_ty: Type,18085 declaration_ty: Type,
18171 decl_vals: *std.ArrayList(InternPool.Index),18086 decl_vals: *std.ArrayList(InternPool.Index),
...@@ -18221,15 +18136,6 @@ fn typeInfoNamespaceDecls(...@@ -18221,15 +18136,6 @@ fn typeInfoNamespaceDecls(
18221 .storage = .{ .elems = &fields },18136 .storage = .{ .elems = &fields },
18222 } }));18137 } }));
18223 }18138 }
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 }
18233}18139}
1823418140
18235fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {18141fn 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...@@ -22133,12 +22039,6 @@ fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
22133 return sema.failWithUseOfAsync(block, src);22039 return sema.failWithUseOfAsync(block, src);
22134}22040}
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
22142fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22042fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22143 const pt = sema.pt;22043 const pt = sema.pt;
22144 const zcu = pt.zcu;22044 const zcu = pt.zcu;
...@@ -24776,14 +24676,14 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -24776,14 +24676,14 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
24776 var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier);24676 var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier);
24777 switch (modifier) {24677 switch (modifier) {
24778 // These can be upgraded to comptime or nosuspend calls.24678 // These can be upgraded to comptime or nosuspend calls.
24779 .auto, .never_tail, .no_async => {24679 .auto, .never_tail, .no_suspend => {
24780 if (block.isComptime()) {24680 if (block.isComptime()) {
24781 if (modifier == .never_tail) {24681 if (modifier == .never_tail) {
24782 return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{});24682 return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{});
24783 }24683 }
24784 modifier = .compile_time;24684 modifier = .compile_time;
24785 } else if (extra.flags.is_nosuspend) {24685 } else if (extra.flags.is_nosuspend) {
24786 modifier = .no_async;24686 modifier = .no_suspend;
24787 }24687 }
24788 },24688 },
24789 // These can be upgraded to comptime. nosuspend bit can be safely ignored.24689 // 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...@@ -24801,14 +24701,6 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
24801 modifier = .compile_time;24701 modifier = .compile_time;
24802 }24702 }
24803 },24703 },
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 },
24812 .never_inline => {24704 .never_inline => {
24813 if (block.isComptime()) {24705 if (block.isComptime()) {
24814 return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{});24706 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...@@ -25797,40 +25689,12 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25797 });25689 });
25798}25690}
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
25806fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {25692fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
25807 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;25693 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
25808 const src = block.nodeOffset(inst_data.src_node);25694 const src = block.nodeOffset(inst_data.src_node);
25809 return sema.failWithUseOfAsync(block, src);25695 return sema.failWithUseOfAsync(block, src);
25810}25696}
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
25834fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {25698fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
25835 const tracy = trace(@src());25699 const tracy = trace(@src());
25836 defer tracy.end();25700 defer tracy.end();
...@@ -26738,7 +26602,7 @@ fn explainWhyTypeIsNotExtern(...@@ -26738,7 +26602,7 @@ fn explainWhyTypeIsNotExtern(
26738 }26602 }
26739 switch (ty.fnCallingConvention(zcu)) {26603 switch (ty.fnCallingConvention(zcu)) {
26740 .auto => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),26604 .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", .{}),
26742 .@"inline" => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),26606 .@"inline" => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
26743 else => return,26607 else => return,
26744 }26608 }
...@@ -27760,7 +27624,7 @@ fn namespaceLookup(...@@ -27760,7 +27624,7 @@ fn namespaceLookup(
27760 const pt = sema.pt;27624 const pt = sema.pt;
27761 const zcu = pt.zcu;27625 const zcu = pt.zcu;
27762 const gpa = sema.gpa;27626 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| {
27764 if (!lookup.accessible) {27628 if (!lookup.accessible) {
27765 return sema.failWithOwnedErrorMsg(block, msg: {27629 return sema.failWithOwnedErrorMsg(block, msg: {
27766 const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{27630 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...@@ -382,7 +382,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
382 }382 }
383 }383 }
384 switch (fn_info.cc) {384 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))}),
386 else => try writer.print("callconv({any}) ", .{fn_info.cc}),386 else => try writer.print("callconv({any}) ", .{fn_info.cc}),
387 }387 }
388 }388 }
src/Zcu.zig+1-34
...@@ -792,10 +792,6 @@ pub const Namespace = struct {...@@ -792,10 +792,6 @@ pub const Namespace = struct {
792 pub_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty,792 pub_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty,
793 /// Members of the namespace which are *not* marked `pub`.793 /// Members of the namespace which are *not* marked `pub`.
794 priv_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty,794 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,
799 /// All `comptime` declarations in this namespace. We store these purely so that incremental795 /// All `comptime` declarations in this namespace. We store these purely so that incremental
800 /// compilation can re-use the existing `ComptimeUnit`s when a namespace changes.796 /// compilation can re-use the existing `ComptimeUnit`s when a namespace changes.
801 comptime_decls: std.ArrayListUnmanaged(InternPool.ComptimeUnit.Id) = .empty,797 comptime_decls: std.ArrayListUnmanaged(InternPool.ComptimeUnit.Id) = .empty,
...@@ -1303,9 +1299,6 @@ pub const SrcLoc = struct {...@@ -1303,9 +1299,6 @@ pub const SrcLoc = struct {
1303 .simple_var_decl,1299 .simple_var_decl,
1304 .aligned_var_decl,1300 .aligned_var_decl,
1305 => tree.fullVarDecl(node).?,1301 => tree.fullVarDecl(node).?,
1306 .@"usingnamespace" => {
1307 return tree.nodeToSpan(tree.nodeData(node).node);
1308 },
1309 else => unreachable,1302 else => unreachable,
1310 };1303 };
1311 if (full.ast.type_node.unwrap()) |type_node| {1304 if (full.ast.type_node.unwrap()) |type_node| {
...@@ -1443,12 +1436,8 @@ pub const SrcLoc = struct {...@@ -1443,12 +1436,8 @@ pub const SrcLoc = struct {
1443 .field_access => tree.nodeData(node).node_and_token[1],1436 .field_access => tree.nodeData(node).node_and_token[1],
1444 .call_one,1437 .call_one,
1445 .call_one_comma,1438 .call_one_comma,
1446 .async_call_one,
1447 .async_call_one_comma,
1448 .call,1439 .call,
1449 .call_comma,1440 .call_comma,
1450 .async_call,
1451 .async_call_comma,
1452 => blk: {1441 => blk: {
1453 const full = tree.fullCall(&buf, node).?;1442 const full = tree.fullCall(&buf, node).?;
1454 break :blk tree.lastToken(full.ast.fn_expr);1443 break :blk tree.lastToken(full.ast.fn_expr);
...@@ -3395,9 +3384,6 @@ pub fn mapOldZirToNew(...@@ -3395,9 +3384,6 @@ pub fn mapOldZirToNew(
3395 // All comptime declarations, in order, for a best-effort match.3384 // All comptime declarations, in order, for a best-effort match.
3396 var comptime_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;3385 var comptime_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;
3397 defer comptime_decls.deinit(gpa);3386 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
3402 {3388 {
3403 var old_decl_it = old_zir.declIterator(match_item.old_inst);3389 var old_decl_it = old_zir.declIterator(match_item.old_inst);
...@@ -3405,7 +3391,6 @@ pub fn mapOldZirToNew(...@@ -3405,7 +3391,6 @@ pub fn mapOldZirToNew(
3405 const old_decl = old_zir.getDeclaration(old_decl_inst);3391 const old_decl = old_zir.getDeclaration(old_decl_inst);
3406 switch (old_decl.kind) {3392 switch (old_decl.kind) {
3407 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),3393 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),
3408 .@"usingnamespace" => try usingnamespace_decls.append(gpa, old_decl_inst),
3409 .unnamed_test => try unnamed_tests.append(gpa, old_decl_inst),3394 .unnamed_test => try unnamed_tests.append(gpa, old_decl_inst),
3410 .@"test" => try named_tests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),3395 .@"test" => try named_tests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),
3411 .decltest => try named_decltests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),3396 .decltest => try named_decltests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst),
...@@ -3416,7 +3401,6 @@ pub fn mapOldZirToNew(...@@ -3416,7 +3401,6 @@ pub fn mapOldZirToNew(
34163401
3417 var unnamed_test_idx: u32 = 0;3402 var unnamed_test_idx: u32 = 0;
3418 var comptime_decl_idx: u32 = 0;3403 var comptime_decl_idx: u32 = 0;
3419 var usingnamespace_decl_idx: u32 = 0;
34203404
3421 var new_decl_it = new_zir.declIterator(match_item.new_inst);3405 var new_decl_it = new_zir.declIterator(match_item.new_inst);
3422 while (new_decl_it.next()) |new_decl_inst| {3406 while (new_decl_it.next()) |new_decl_inst| {
...@@ -3426,7 +3410,6 @@ pub fn mapOldZirToNew(...@@ -3426,7 +3410,6 @@ pub fn mapOldZirToNew(
3426 // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name.3410 // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name.
3427 // * For unnamed tests, we match based on order.3411 // * For unnamed tests, we match based on order.
3428 // * For comptime blocks, we match based on order.3412 // * For comptime blocks, we match based on order.
3429 // * For usingnamespace decls, we match based on order.
3430 // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`.3413 // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`.
3431 const old_decl_inst = switch (new_decl.kind) {3414 const old_decl_inst = switch (new_decl.kind) {
3432 .@"comptime" => inst: {3415 .@"comptime" => inst: {
...@@ -3434,11 +3417,6 @@ pub fn mapOldZirToNew(...@@ -3434,11 +3417,6 @@ pub fn mapOldZirToNew(
3434 defer comptime_decl_idx += 1;3417 defer comptime_decl_idx += 1;
3435 break :inst comptime_decls.items[comptime_decl_idx];3418 break :inst comptime_decls.items[comptime_decl_idx];
3436 },3419 },
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 },
3442 .unnamed_test => inst: {3420 .unnamed_test => inst: {
3443 if (unnamed_test_idx == unnamed_tests.items.len) continue;3421 if (unnamed_test_idx == unnamed_tests.items.len) continue;
3444 defer unnamed_test_idx += 1;3422 defer unnamed_test_idx += 1;
...@@ -4147,7 +4125,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4147,7 +4125,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4147 if (!comp.config.is_test or file.mod != zcu.main_mod) continue;4125 if (!comp.config.is_test or file.mod != zcu.main_mod) continue;
41484126
4149 const want_analysis = switch (decl.kind) {4127 const want_analysis = switch (decl.kind) {
4150 .@"usingnamespace" => unreachable,
4151 .@"const", .@"var" => unreachable,4128 .@"const", .@"var" => unreachable,
4152 .@"comptime" => unreachable,4129 .@"comptime" => unreachable,
4153 .unnamed_test => true,4130 .unnamed_test => true,
...@@ -4205,16 +4182,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4205,16 +4182,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4205 }4182 }
4206 }4183 }
4207 }4184 }
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 }
4218 continue;4185 continue;
4219 }4186 }
4220 if (unit_queue.pop()) |kv| {4187 if (unit_queue.pop()) |kv| {
...@@ -4457,7 +4424,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu...@@ -4457,7 +4424,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
4457 const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm);4424 const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm);
4458 switch (cc) {4425 switch (cc) {
4459 .auto, .@"inline" => return .ok,4426 .auto, .@"inline" => return .ok,
4460 .@"async" => return .{ .bad_backend = backend }, // nothing supports async currently4427 .async => return .{ .bad_backend = backend }, // nothing supports async currently
4461 .naked => {}, // depends only on backend4428 .naked => {}, // depends only on backend
4462 else => for (cc.archs()) |allowed_arch| {4429 else => for (cc.archs()) |allowed_arch| {
4463 if (allowed_arch == target.cpu.arch) break;4430 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...@@ -1111,7 +1111,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
1111 defer block.instructions.deinit(gpa);1111 defer block.instructions.deinit(gpa);
11121112
1113 const zir_decl = zir.getDeclaration(inst_resolved.inst);1113 const zir_decl = zir.getDeclaration(inst_resolved.inst);
1114 assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace"));
11151114
1116 const ty_src = block.src(.{ .node_offset_var_decl_ty = .zero });1115 const ty_src = block.src(.{ .node_offset_var_decl_ty = .zero });
1117 const init_src = block.src(.{ .node_offset_var_decl_init = .zero });1116 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...@@ -1160,7 +1159,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
1160 assert(nav_ty.zigTypeTag(zcu) == .@"fn");1159 assert(nav_ty.zigTypeTag(zcu) == .@"fn");
1161 break :is_const true;1160 break :is_const true;
1162 },1161 },
1163 .@"usingnamespace", .@"const" => true,1162 .@"const" => true,
1164 .@"var" => {1163 .@"var" => {
1165 try sema.validateVarType(1164 try sema.validateVarType(
1166 &block,1165 &block,
...@@ -1240,26 +1239,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr...@@ -1240,26 +1239,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr
1240 // this resolves the type `type` (which needs no resolution), not the struct itself.1239 // this resolves the type `type` (which needs no resolution), not the struct itself.
1241 try nav_ty.resolveLayout(pt);1240 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
1263 const queue_linker_work, const is_owned_fn = switch (ip.indexToKey(nav_val.toIntern())) {1242 const queue_linker_work, const is_owned_fn = switch (ip.indexToKey(nav_val.toIntern())) {
1264 .func => |f| .{ true, f.owner_nav == nav_id }, // note that this lets function aliases reach codegen1243 .func => |f| .{ true, f.owner_nav == nav_id }, // note that this lets function aliases reach codegen
1265 .variable => |v| .{ v.owner_nav == nav_id, false },1244 .variable => |v| .{ v.owner_nav == nav_id, false },
...@@ -1464,7 +1443,6 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr...@@ -1464,7 +1443,6 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr
1464 defer _ = zcu.analysis_in_progress.swapRemove(anal_unit);1443 defer _ = zcu.analysis_in_progress.swapRemove(anal_unit);
14651444
1466 const zir_decl = zir.getDeclaration(inst_resolved.inst);1445 const zir_decl = zir.getDeclaration(inst_resolved.inst);
1467 assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace"));
1468 const type_body = zir_decl.type_body.?;1446 const type_body = zir_decl.type_body.?;
14691447
1470 var analysis_arena: std.heap.ArenaAllocator = .init(gpa);1448 var analysis_arena: std.heap.ArenaAllocator = .init(gpa);
...@@ -1527,7 +1505,7 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr...@@ -1527,7 +1505,7 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr
15271505
1528 const is_const = switch (zir_decl.kind) {1506 const is_const = switch (zir_decl.kind) {
1529 .@"comptime" => unreachable,1507 .@"comptime" => unreachable,
1530 .unnamed_test, .@"test", .decltest, .@"usingnamespace", .@"const" => true,1508 .unnamed_test, .@"test", .decltest, .@"const" => true,
1531 .@"var" => false,1509 .@"var" => false,
1532 };1510 };
15331511
...@@ -2541,7 +2519,6 @@ pub fn scanNamespace(...@@ -2541,7 +2519,6 @@ pub fn scanNamespace(
25412519
2542 try existing_by_inst.ensureTotalCapacity(gpa, @intCast(2520 try existing_by_inst.ensureTotalCapacity(gpa, @intCast(
2543 namespace.pub_decls.count() + namespace.priv_decls.count() +2521 namespace.pub_decls.count() + namespace.priv_decls.count() +
2544 namespace.pub_usingnamespace.items.len + namespace.priv_usingnamespace.items.len +
2545 namespace.comptime_decls.items.len +2522 namespace.comptime_decls.items.len +
2546 namespace.test_decls.items.len,2523 namespace.test_decls.items.len,
2547 ));2524 ));
...@@ -2554,14 +2531,6 @@ pub fn scanNamespace(...@@ -2554,14 +2531,6 @@ pub fn scanNamespace(
2554 const zir_index = ip.getNav(nav).analysis.?.zir_index;2531 const zir_index = ip.getNav(nav).analysis.?.zir_index;
2555 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .nav_val = nav }));2532 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .nav_val = nav }));
2556 }2533 }
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 }
2565 for (namespace.comptime_decls.items) |cu| {2534 for (namespace.comptime_decls.items) |cu| {
2566 const zir_index = ip.getComptimeUnit(cu).zir_index;2535 const zir_index = ip.getComptimeUnit(cu).zir_index;
2567 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .@"comptime" = cu }));2536 existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .@"comptime" = cu }));
...@@ -2578,8 +2547,6 @@ pub fn scanNamespace(...@@ -2578,8 +2547,6 @@ pub fn scanNamespace(
25782547
2579 namespace.pub_decls.clearRetainingCapacity();2548 namespace.pub_decls.clearRetainingCapacity();
2580 namespace.priv_decls.clearRetainingCapacity();2549 namespace.priv_decls.clearRetainingCapacity();
2581 namespace.pub_usingnamespace.clearRetainingCapacity();
2582 namespace.priv_usingnamespace.clearRetainingCapacity();
2583 namespace.comptime_decls.clearRetainingCapacity();2550 namespace.comptime_decls.clearRetainingCapacity();
2584 namespace.test_decls.clearRetainingCapacity();2551 namespace.test_decls.clearRetainingCapacity();
25852552
...@@ -2607,7 +2574,6 @@ const ScanDeclIter = struct {...@@ -2607,7 +2574,6 @@ const ScanDeclIter = struct {
2607 /// Decl scanning is run in two passes, so that we can detect when a generated2574 /// Decl scanning is run in two passes, so that we can detect when a generated
2608 /// name would clash with an explicit name and use a different one.2575 /// name would clash with an explicit name and use a different one.
2609 pass: enum { named, unnamed },2576 pass: enum { named, unnamed },
2610 usingnamespace_index: usize = 0,
2611 unnamed_test_index: usize = 0,2577 unnamed_test_index: usize = 0,
26122578
2613 fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString {2579 fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString {
...@@ -2646,12 +2612,6 @@ const ScanDeclIter = struct {...@@ -2646,12 +2612,6 @@ const ScanDeclIter = struct {
2646 if (iter.pass != .unnamed) return;2612 if (iter.pass != .unnamed) return;
2647 break :name .none;2613 break :name .none;
2648 },2614 },
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 },
2655 .unnamed_test => name: {2615 .unnamed_test => name: {
2656 if (iter.pass != .unnamed) return;2616 if (iter.pass != .unnamed) return;
2657 const i = iter.unnamed_test_index;2617 const i = iter.unnamed_test_index;
...@@ -2710,7 +2670,7 @@ const ScanDeclIter = struct {...@@ -2710,7 +2670,7 @@ const ScanDeclIter = struct {
2710 const name = maybe_name.unwrap().?;2670 const name = maybe_name.unwrap().?;
2711 const fqn = try namespace.internFullyQualifiedName(ip, gpa, pt.tid, name);2671 const fqn = try namespace.internFullyQualifiedName(ip, gpa, pt.tid, name);
2712 const nav = if (existing_unit) |eu| eu.unwrap().nav_val else nav: {2672 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);
2714 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newNav(zcu, nav);2674 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newNav(zcu, nav);
2715 break :nav nav;2675 break :nav nav;
2716 };2676 };
...@@ -2722,17 +2682,6 @@ const ScanDeclIter = struct {...@@ -2722,17 +2682,6 @@ const ScanDeclIter = struct {
27222682
2723 const want_analysis = switch (decl.kind) {2683 const want_analysis = switch (decl.kind) {
2724 .@"comptime" => unreachable,2684 .@"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 },
2736 .unnamed_test, .@"test", .decltest => a: {2685 .unnamed_test, .@"test", .decltest => a: {
2737 const is_named = decl.kind != .unnamed_test;2686 const is_named = decl.kind != .unnamed_test;
2738 try namespace.test_decls.append(gpa, nav);2687 try namespace.test_decls.append(gpa, nav);
src/codegen/llvm.zig+7-7
...@@ -2758,7 +2758,7 @@ pub const Object = struct {...@@ -2758,7 +2758,7 @@ pub const Object = struct {
2758 llvm_arg_i += 1;2758 llvm_arg_i += 1;
2759 }2759 }
27602760
2761 if (fn_info.cc == .@"async") {2761 if (fn_info.cc == .async) {
2762 @panic("TODO: LLVM backend lower async function");2762 @panic("TODO: LLVM backend lower async function");
2763 }2763 }
27642764
...@@ -2910,7 +2910,7 @@ pub const Object = struct {...@@ -2910,7 +2910,7 @@ pub const Object = struct {
2910 try attributes.addFnAttr(.nounwind, &o.builder);2910 try attributes.addFnAttr(.nounwind, &o.builder);
2911 if (owner_mod.unwind_tables != .none) {2911 if (owner_mod.unwind_tables != .none) {
2912 try attributes.addFnAttr(2912 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 },
2914 &o.builder,2914 &o.builder,
2915 );2915 );
2916 }2916 }
...@@ -5273,7 +5273,7 @@ pub const FuncGen = struct {...@@ -5273,7 +5273,7 @@ pub const FuncGen = struct {
5273 switch (modifier) {5273 switch (modifier) {
5274 .auto, .always_tail => {},5274 .auto, .always_tail => {},
5275 .never_tail, .never_inline => try attributes.addFnAttr(.@"noinline", &o.builder),5275 .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,
5277 }5277 }
52785278
5279 const ret_ptr = if (!sret) null else blk: {5279 const ret_ptr = if (!sret) null else blk: {
...@@ -5488,7 +5488,7 @@ pub const FuncGen = struct {...@@ -5488,7 +5488,7 @@ pub const FuncGen = struct {
5488 .auto, .never_inline => .normal,5488 .auto, .never_inline => .normal,
5489 .never_tail => .notail,5489 .never_tail => .notail,
5490 .always_tail => .musttail,5490 .always_tail => .musttail,
5491 .async_kw, .no_async, .always_inline, .compile_time => unreachable,5491 .no_suspend, .always_inline, .compile_time => unreachable,
5492 },5492 },
5493 toLlvmCallConvTag(fn_info.cc, target).?,5493 toLlvmCallConvTag(fn_info.cc, target).?,
5494 try attributes.finish(&o.builder),5494 try attributes.finish(&o.builder),
...@@ -11861,7 +11861,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s...@@ -11861,7 +11861,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
11861 }11861 }
11862 return switch (cc_tag) {11862 return switch (cc_tag) {
11863 .@"inline" => unreachable,11863 .@"inline" => unreachable,
11864 .auto, .@"async" => .fastcc,11864 .auto, .async => .fastcc,
11865 .naked => .ccc,11865 .naked => .ccc,
11866 .x86_64_sysv => .x86_64_sysvcc,11866 .x86_64_sysv => .x86_64_sysvcc,
11867 .x86_64_win => .win64cc,11867 .x86_64_win => .win64cc,
...@@ -12369,7 +12369,7 @@ const ParamTypeIterator = struct {...@@ -12369,7 +12369,7 @@ const ParamTypeIterator = struct {
12369 return .byval;12369 return .byval;
12370 }12370 }
12371 },12371 },
12372 .@"async" => {12372 .async => {
12373 @panic("TODO implement async function lowering in the LLVM backend");12373 @panic("TODO implement async function lowering in the LLVM backend");
12374 },12374 },
12375 .x86_64_sysv => return it.nextSystemV(ty),12375 .x86_64_sysv => return it.nextSystemV(ty),
...@@ -12624,7 +12624,7 @@ fn ccAbiPromoteInt(...@@ -12624,7 +12624,7 @@ fn ccAbiPromoteInt(
12624) ?std.builtin.Signedness {12624) ?std.builtin.Signedness {
12625 const target = zcu.getTarget();12625 const target = zcu.getTarget();
12626 switch (cc) {12626 switch (cc) {
12627 .auto, .@"inline", .@"async" => return null,12627 .auto, .@"inline", .async => return null,
12628 else => {},12628 else => {},
12629 }12629 }
12630 const int_info = switch (ty.zigTypeTag(zcu)) {12630 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...@@ -325,7 +325,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
325 // See the `-fno-exceptions` logic for WASI.325 // See the `-fno-exceptions` logic for WASI.
326 // The old 32-bit x86 variant of SEH doesn't use tables.326 // The old 32-bit x86 variant of SEH doesn't use tables.
327 const unwind_tables: std.builtin.UnwindTables =327 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
330 const config = Compilation.Config.resolve(.{330 const config = Compilation.Config.resolve(.{
331 .output_mode = output_mode,331 .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...@@ -48,7 +48,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
48 const optimize_mode = comp.compilerRtOptMode();48 const optimize_mode = comp.compilerRtOptMode();
49 const strip = comp.compilerRtStrip();49 const strip = comp.compilerRtStrip();
50 const unwind_tables: std.builtin.UnwindTables =50 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;
52 const link_libcpp = target.os.tag.isDarwin();52 const link_libcpp = target.os.tag.isDarwin();
5353
54 const config = Compilation.Config.resolve(.{54 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...@@ -29,7 +29,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
29 const output_mode = .Lib;29 const output_mode = .Lib;
30 const target = &comp.root_mod.resolved_target.result;30 const target = &comp.root_mod.resolved_target.result;
31 const unwind_tables: std.builtin.UnwindTables =31 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;
33 const config = Compilation.Config.resolve(.{33 const config = Compilation.Config.resolve(.{
34 .output_mode = output_mode,34 .output_mode = output_mode,
35 .resolved_target = comp.root_mod.resolved_target,35 .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...@@ -29,7 +29,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
29 const target = comp.getTarget();29 const target = comp.getTarget();
3030
31 // The old 32-bit x86 variant of SEH doesn't use tables.31 // 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
34 switch (crt_file) {34 switch (crt_file) {
35 .crt2_o => {35 .crt2_o => {
src/link/Dwarf.zig+3-3
...@@ -2489,7 +2489,7 @@ fn initWipNavInner(...@@ -2489,7 +2489,7 @@ fn initWipNavInner(
2489 const addr: Loc = .{ .addr_reloc = sym_index };2489 const addr: Loc = .{ .addr_reloc = sym_index };
2490 const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr;2490 const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr;
2491 switch (decl.kind) {2491 switch (decl.kind) {
2492 .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable,2492 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
2493 .@"const" => {2493 .@"const" => {
2494 const const_ty_reloc_index = try wip_nav.refForward();2494 const const_ty_reloc_index = try wip_nav.refForward();
2495 try wip_nav.infoExprLoc(loc);2495 try wip_nav.infoExprLoc(loc);
...@@ -2775,7 +2775,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -2775,7 +2775,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
27752775
2776 const is_test = switch (decl.kind) {2776 const is_test = switch (decl.kind) {
2777 .unnamed_test, .@"test", .decltest => true,2777 .unnamed_test, .@"test", .decltest => true,
2778 .@"comptime", .@"usingnamespace", .@"const", .@"var" => false,2778 .@"comptime", .@"const", .@"var" => false,
2779 };2779 };
2780 if (is_test) {2780 if (is_test) {
2781 // This isn't actually a comptime Nav! It's a test, so it'll definitely never be referenced at comptime.2781 // 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(...@@ -3596,7 +3596,7 @@ fn updateLazyType(
3596 // For better or worse, we try to match what Clang emits.3596 // For better or worse, we try to match what Clang emits.
3597 break :cc switch (func_type.cc) {3597 break :cc switch (func_type.cc) {
3598 .@"inline" => .nocall,3598 .@"inline" => .nocall,
3599 .@"async", .auto, .naked => .normal,3599 .async, .auto, .naked => .normal,
3600 .x86_64_sysv => .LLVM_X86_64SysV,3600 .x86_64_sysv => .LLVM_X86_64SysV,
3601 .x86_64_win => .LLVM_Win64,3601 .x86_64_win => .LLVM_Win64,
3602 .x86_64_regcall_v3_sysv => .LLVM_X86RegCall,3602 .x86_64_regcall_v3_sysv => .LLVM_X86RegCall,
src/main.zig+6-6
...@@ -1416,7 +1416,7 @@ fn buildOutputType(...@@ -1416,7 +1416,7 @@ fn buildOutputType(
1416 } else if (mem.eql(u8, arg, "-funwind-tables")) {1416 } else if (mem.eql(u8, arg, "-funwind-tables")) {
1417 mod_opts.unwind_tables = .sync;1417 mod_opts.unwind_tables = .sync;
1418 } else if (mem.eql(u8, arg, "-fasync-unwind-tables")) {1418 } else if (mem.eql(u8, arg, "-fasync-unwind-tables")) {
1419 mod_opts.unwind_tables = .@"async";1419 mod_opts.unwind_tables = .async;
1420 } else if (mem.eql(u8, arg, "-fno-unwind-tables")) {1420 } else if (mem.eql(u8, arg, "-fno-unwind-tables")) {
1421 mod_opts.unwind_tables = .none;1421 mod_opts.unwind_tables = .none;
1422 } else if (mem.eql(u8, arg, "-fstack-check")) {1422 } else if (mem.eql(u8, arg, "-fstack-check")) {
...@@ -2035,15 +2035,15 @@ fn buildOutputType(...@@ -2035,15 +2035,15 @@ fn buildOutputType(
2035 .none => {2035 .none => {
2036 mod_opts.unwind_tables = .sync;2036 mod_opts.unwind_tables = .sync;
2037 },2037 },
2038 .sync, .@"async" => {},2038 .sync, .async => {},
2039 } else {2039 } else {
2040 mod_opts.unwind_tables = .sync;2040 mod_opts.unwind_tables = .sync;
2041 },2041 },
2042 .no_unwind_tables => mod_opts.unwind_tables = .none,2042 .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,
2044 .no_asynchronous_unwind_tables => if (mod_opts.unwind_tables) |uwt| switch (uwt) {2044 .no_asynchronous_unwind_tables => if (mod_opts.unwind_tables) |uwt| switch (uwt) {
2045 .none, .sync => {},2045 .none, .sync => {},
2046 .@"async" => {2046 .async => {
2047 mod_opts.unwind_tables = .sync;2047 mod_opts.unwind_tables = .sync;
2048 },2048 },
2049 } else {2049 } else {
...@@ -2951,7 +2951,7 @@ fn buildOutputType(...@@ -2951,7 +2951,7 @@ fn buildOutputType(
2951 create_module.opts.any_fuzz = true;2951 create_module.opts.any_fuzz = true;
2952 if (mod_opts.unwind_tables) |uwt| switch (uwt) {2952 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
2953 .none => {},2953 .none => {},
2954 .sync, .@"async" => create_module.opts.any_unwind_tables = true,2954 .sync, .async => create_module.opts.any_unwind_tables = true,
2955 };2955 };
2956 if (mod_opts.strip == false)2956 if (mod_opts.strip == false)
2957 create_module.opts.any_non_stripped = true;2957 create_module.opts.any_non_stripped = true;
...@@ -7413,7 +7413,7 @@ fn handleModArg(...@@ -7413,7 +7413,7 @@ fn handleModArg(
7413 create_module.opts.any_fuzz = true;7413 create_module.opts.any_fuzz = true;
7414 if (mod_opts.unwind_tables) |uwt| switch (uwt) {7414 if (mod_opts.unwind_tables) |uwt| switch (uwt) {
7415 .none => {},7415 .none => {},
7416 .sync, .@"async" => create_module.opts.any_unwind_tables = true,7416 .sync, .async => create_module.opts.any_unwind_tables = true,
7417 };7417 };
7418 if (mod_opts.strip == false)7418 if (mod_opts.strip == false)
7419 create_module.opts.any_non_stripped = true;7419 create_module.opts.any_non_stripped = true;
src/print_zir.zig-18
...@@ -261,14 +261,12 @@ const Writer = struct {...@@ -261,14 +261,12 @@ const Writer = struct {
261 .tag_name,261 .tag_name,
262 .type_name,262 .type_name,
263 .frame_type,263 .frame_type,
264 .frame_size,
265 .clz,264 .clz,
266 .ctz,265 .ctz,
267 .pop_count,266 .pop_count,
268 .byte_swap,267 .byte_swap,
269 .bit_reverse,268 .bit_reverse,
270 .@"resume",269 .@"resume",
271 .@"await",
272 .make_ptr_const,270 .make_ptr_const,
273 .validate_deref,271 .validate_deref,
274 .validate_const,272 .validate_const,
...@@ -565,7 +563,6 @@ const Writer = struct {...@@ -565,7 +563,6 @@ const Writer = struct {
565563
566 .tuple_decl => try self.writeTupleDecl(stream, extended),564 .tuple_decl => try self.writeTupleDecl(stream, extended),
567565
568 .await_nosuspend,
569 .c_undef,566 .c_undef,
570 .c_include,567 .c_include,
571 .set_float_mode,568 .set_float_mode,
...@@ -611,7 +608,6 @@ const Writer = struct {...@@ -611,7 +608,6 @@ const Writer = struct {
611 try self.writeSrcNode(stream, inst_data.node);608 try self.writeSrcNode(stream, inst_data.node);
612 },609 },
613610
614 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
615 .cmpxchg => try self.writeCmpxchg(stream, extended),611 .cmpxchg => try self.writeCmpxchg(stream, extended),
616 .ptr_cast_full => try self.writePtrCastFull(stream, extended),612 .ptr_cast_full => try self.writePtrCastFull(stream, extended),
617 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),613 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),
...@@ -932,19 +928,6 @@ const Writer = struct {...@@ -932,19 +928,6 @@ const Writer = struct {
932 try self.writeSrcNode(stream, extra.src_node);928 try self.writeSrcNode(stream, extra.src_node);
933 }929 }
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
948 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {931 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
949 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;932 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
950 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);933 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
...@@ -2605,7 +2588,6 @@ const Writer = struct {...@@ -2605,7 +2588,6 @@ const Writer = struct {
2605 }2588 }
2606 switch (decl.kind) {2589 switch (decl.kind) {
2607 .@"comptime" => try stream.writeAll("comptime"),2590 .@"comptime" => try stream.writeAll("comptime"),
2608 .@"usingnamespace" => try stream.writeAll("usingnamespace"),
2609 .unnamed_test => try stream.writeAll("test"),2591 .unnamed_test => try stream.writeAll("test"),
2610 .@"test", .decltest, .@"const", .@"var" => {2592 .@"test", .decltest, .@"const", .@"var" => {
2611 try stream.print("{s} '{s}'", .{ @tagName(decl.kind), self.code.nullTerminatedString(decl.name) });2593 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 {...@@ -483,12 +483,12 @@ pub fn clangSupportsNoImplicitFloatArg(target: *const std.Target) bool {
483pub fn defaultUnwindTables(target: *const std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables {483pub fn defaultUnwindTables(target: *const std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables {
484 if (target.os.tag == .windows) {484 if (target.os.tag == .windows) {
485 // The old 32-bit x86 variant of SEH doesn't use tables.485 // 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;
487 }487 }
488 if (target.os.tag.isDarwin()) return .@"async";488 if (target.os.tag.isDarwin()) return .async;
489 if (libunwind) return .@"async";489 if (libunwind) return .async;
490 if (libtsan) return .@"async";490 if (libtsan) return .async;
491 if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .@"async";491 if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .async;
492 return .none;492 return .none;
493}493}
494494
...@@ -815,7 +815,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {...@@ -815,7 +815,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {
815815
816pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {816pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
817 return switch (cc) {817 return switch (cc) {
818 .auto, .@"async", .@"inline" => true,818 .auto, .async, .@"inline" => true,
819 // For now we want to authorize PTX kernel to use zig objects, even if819 // For now we want to authorize PTX kernel to use zig objects, even if
820 // we end up exposing the ABI. The goal is to experiment with more820 // we end up exposing the ABI. The goal is to experiment with more
821 // integrated CPU/GPU code.821 // 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 {...@@ -5,9 +5,7 @@ test {
5 _ = @import("behavior/align.zig");5 _ = @import("behavior/align.zig");
6 _ = @import("behavior/alignof.zig");6 _ = @import("behavior/alignof.zig");
7 _ = @import("behavior/array.zig");7 _ = @import("behavior/array.zig");
8 _ = @import("behavior/async_fn.zig");
9 _ = @import("behavior/atomics.zig");8 _ = @import("behavior/atomics.zig");
10 _ = @import("behavior/await_struct.zig");
11 _ = @import("behavior/basic.zig");9 _ = @import("behavior/basic.zig");
12 _ = @import("behavior/bit_shifting.zig");10 _ = @import("behavior/bit_shifting.zig");
13 _ = @import("behavior/bitcast.zig");11 _ = @import("behavior/bitcast.zig");
...@@ -103,7 +101,6 @@ test {...@@ -103,7 +101,6 @@ test {
103 _ = @import("behavior/underscore.zig");101 _ = @import("behavior/underscore.zig");
104 _ = @import("behavior/union.zig");102 _ = @import("behavior/union.zig");
105 _ = @import("behavior/union_with_members.zig");103 _ = @import("behavior/union_with_members.zig");
106 _ = @import("behavior/usingnamespace.zig");
107 _ = @import("behavior/var_args.zig");104 _ = @import("behavior/var_args.zig");
108 // https://github.com/llvm/llvm-project/issues/118879105 // https://github.com/llvm/llvm-project/issues/118879
109 // https://github.com/llvm/llvm-project/issues/134659106 // https://github.com/llvm/llvm-project/issues/134659
test/behavior/align.zig-24
...@@ -425,30 +425,6 @@ test "struct field explicit alignment" {...@@ -425,30 +425,6 @@ test "struct field explicit alignment" {
425 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);425 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);
426}426}
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
452test "align(N) on functions" {428test "align(N) on functions" {
453 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO429 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
454 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO430 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" {...@@ -1107,27 +1107,6 @@ test "inline call of function with a switch inside the return statement" {
1107 try expect(S.foo(1) == 1);1107 try expect(S.foo(1) == 1);
1108}1108}
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
1131test "pointer to zero sized global is mutable" {1110test "pointer to zero sized global is mutable" {
1132 const S = struct {1111 const S = struct {
1133 const Thing = struct {};1112 const Thing = struct {};
test/behavior/call.zig+3-26
...@@ -37,7 +37,7 @@ test "basic invocations" {...@@ -37,7 +37,7 @@ test "basic invocations" {
37 comptime {37 comptime {
38 // comptime calls with supported modifiers38 // comptime calls with supported modifiers
39 try expect(@call(.auto, foo, .{2}) == 1234);39 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);
41 try expect(@call(.always_tail, foo, .{4}) == 1234);41 try expect(@call(.always_tail, foo, .{4}) == 1234);
42 try expect(@call(.always_inline, foo, .{5}) == 1234);42 try expect(@call(.always_inline, foo, .{5}) == 1234);
43 }43 }
...@@ -45,7 +45,7 @@ test "basic invocations" {...@@ -45,7 +45,7 @@ test "basic invocations" {
45 const result = @call(.compile_time, foo, .{6}) == 1234;45 const result = @call(.compile_time, foo, .{6}) == 1234;
46 comptime assert(result);46 comptime assert(result);
47 // runtime calls of comptime-known function47 // runtime calls of comptime-known function
48 try expect(@call(.no_async, foo, .{7}) == 1234);48 try expect(@call(.no_suspend, foo, .{7}) == 1234);
49 try expect(@call(.never_tail, foo, .{8}) == 1234);49 try expect(@call(.never_tail, foo, .{8}) == 1234);
50 try expect(@call(.never_inline, foo, .{9}) == 1234);50 try expect(@call(.never_inline, foo, .{9}) == 1234);
51 // CBE does not support attributes on runtime functions51 // CBE does not support attributes on runtime functions
...@@ -53,7 +53,7 @@ test "basic invocations" {...@@ -53,7 +53,7 @@ test "basic invocations" {
53 // runtime calls of non comptime-known function53 // runtime calls of non comptime-known function
54 var alias_foo = &foo;54 var alias_foo = &foo;
55 _ = &alias_foo;55 _ = &alias_foo;
56 try expect(@call(.no_async, alias_foo, .{10}) == 1234);56 try expect(@call(.no_suspend, alias_foo, .{10}) == 1234);
57 try expect(@call(.never_tail, alias_foo, .{11}) == 1234);57 try expect(@call(.never_tail, alias_foo, .{11}) == 1234);
58 try expect(@call(.never_inline, alias_foo, .{12}) == 1234);58 try expect(@call(.never_inline, alias_foo, .{12}) == 1234);
59 }59 }
...@@ -507,29 +507,6 @@ test "call inline fn through pointer" {...@@ -507,29 +507,6 @@ test "call inline fn through pointer" {
507 try f(123);507 try f(123);
508}508}
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
533test "call function in comptime field" {510test "call function in comptime field" {
534 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO511 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" {...@@ -18,16 +18,6 @@ test "importing the same thing gives the same import" {
18 try expect(@import("std") == @import("std"));18 try expect(@import("std") == @import("std"));
19}19}
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
31test "import empty file" {21test "import empty file" {
32 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;22 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;23 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" {...@@ -236,17 +236,6 @@ test "call method with mutable reference to struct with no fields" {
236 try expect(s.do());236 try expect(s.do());
237}237}
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
250test "struct field init with catch" {239test "struct field init with catch" {
251 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
252 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO241 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/type_info.zig-83
...@@ -592,24 +592,6 @@ test "StructField.is_comptime" {...@@ -592,24 +592,6 @@ test "StructField.is_comptime" {
592 try expect(info.fields[1].is_comptime);592 try expect(info.fields[1].is_comptime);
593}593}
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
613test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {595test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
614 comptime {596 comptime {
615 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr;597 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" {...@@ -617,77 +599,12 @@ test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
617 }599 }
618}600}
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
657test "type info of tuple of string literal default value" {602test "type info of tuple of string literal default value" {
658 const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];603 const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];
659 const value = struct_field.defaultValue().?;604 const value = struct_field.defaultValue().?;
660 comptime std.debug.assert(value[0] == 'h');605 comptime std.debug.assert(value[0] == 'h');
661}606}
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
691test "@typeInfo function with generic return type and inferred error set" {608test "@typeInfo function with generic return type and inferred error set" {
692 const S = struct {609 const S = struct {
693 fn testFn(comptime T: type) !T {}610 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 @@...@@ -48,9 +48,6 @@
48 .pkg_import = .{48 .pkg_import = .{
49 .path = "pkg_import",49 .path = "pkg_import",
50 },50 },
51 .use_alias = .{
52 .path = "use_alias",
53 },
54 .install_raw_hex = .{51 .install_raw_hex = .{
55 .path = "install_raw_hex",52 .path = "install_raw_hex",
56 },53 },
test/standalone/stack_iterator/build.zig+3-3
...@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {...@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
29 .root_source_file = b.path("unwind.zig"),29 .root_source_file = b.path("unwind.zig"),
30 .target = target,30 .target = target,
31 .optimize = optimize,31 .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,
33 .omit_frame_pointer = false,33 .omit_frame_pointer = false,
34 }),34 }),
35 });35 });
...@@ -54,7 +54,7 @@ pub fn build(b: *std.Build) void {...@@ -54,7 +54,7 @@ pub fn build(b: *std.Build) void {
54 .root_source_file = b.path("unwind.zig"),54 .root_source_file = b.path("unwind.zig"),
55 .target = target,55 .target = target,
56 .optimize = optimize,56 .optimize = optimize,
57 .unwind_tables = .@"async",57 .unwind_tables = .async,
58 .omit_frame_pointer = true,58 .omit_frame_pointer = true,
59 }),59 }),
60 // self-hosted lacks omit_frame_pointer support60 // self-hosted lacks omit_frame_pointer support
...@@ -101,7 +101,7 @@ pub fn build(b: *std.Build) void {...@@ -101,7 +101,7 @@ pub fn build(b: *std.Build) void {
101 .root_source_file = b.path("shared_lib_unwind.zig"),101 .root_source_file = b.path("shared_lib_unwind.zig"),
102 .target = target,102 .target = target,
103 .optimize = optimize,103 .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,
105 .omit_frame_pointer = true,105 .omit_frame_pointer = true,
106 }),106 }),
107 // zig objcopy doesn't support incremental binaries107 // 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(...@@ -710,8 +710,6 @@ fn tokenizeAndPrintRaw(
710 .keyword_align,710 .keyword_align,
711 .keyword_and,711 .keyword_and,
712 .keyword_asm,712 .keyword_asm,
713 .keyword_async,
714 .keyword_await,
715 .keyword_break,713 .keyword_break,
716 .keyword_catch,714 .keyword_catch,
717 .keyword_comptime,715 .keyword_comptime,
...@@ -748,7 +746,6 @@ fn tokenizeAndPrintRaw(...@@ -748,7 +746,6 @@ fn tokenizeAndPrintRaw(
748 .keyword_try,746 .keyword_try,
749 .keyword_union,747 .keyword_union,
750 .keyword_unreachable,748 .keyword_unreachable,
751 .keyword_usingnamespace,
752 .keyword_var,749 .keyword_var,
753 .keyword_volatile,750 .keyword_volatile,
754 .keyword_allowzero,751 .keyword_allowzero,
tools/doctest.zig-3
...@@ -653,8 +653,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {...@@ -653,8 +653,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
653 .keyword_align,653 .keyword_align,
654 .keyword_and,654 .keyword_and,
655 .keyword_asm,655 .keyword_asm,
656 .keyword_async,
657 .keyword_await,
658 .keyword_break,656 .keyword_break,
659 .keyword_catch,657 .keyword_catch,
660 .keyword_comptime,658 .keyword_comptime,
...@@ -691,7 +689,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {...@@ -691,7 +689,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
691 .keyword_try,689 .keyword_try,
692 .keyword_union,690 .keyword_union,
693 .keyword_unreachable,691 .keyword_unreachable,
694 .keyword_usingnamespace,
695 .keyword_var,692 .keyword_var,
696 .keyword_volatile,693 .keyword_volatile,
697 .keyword_allowzero,694 .keyword_allowzero,
tools/lldb_pretty_printers.py-3
...@@ -50,8 +50,6 @@ zig_keywords = {...@@ -50,8 +50,6 @@ zig_keywords = {
50 'anyframe',50 'anyframe',
51 'anytype',51 'anytype',
52 'asm',52 'asm',
53 'async',
54 'await',
55 'break',53 'break',
56 'callconv',54 'callconv',
57 'catch',55 'catch',
...@@ -88,7 +86,6 @@ zig_keywords = {...@@ -88,7 +86,6 @@ zig_keywords = {
88 'try',86 'try',
89 'union',87 'union',
90 'unreachable',88 'unreachable',
91 'usingnamespace',
92 'var',89 'var',
93 'volatile',90 'volatile',
94 'while',91 'while',