| author | |
| committer | |
| log | fc2c1883b36a6ba8c7303d12b57147656dc7dd70 |
| tree | 8b68413d10d994377456b9a6a71473caa8e564d0 |
| parent | 9e49652757da1946abd57a1a3af15a7bbcf8491c |
| parent | 4ba0e7d424a7c0af55c8085c659e9205560d3095 |
| signature |
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 | 460 | .skip_linux = skip_linux, |
| 461 | 461 | .skip_llvm = skip_llvm, |
| 462 | 462 | .skip_libc = skip_libc, |
| 463 | // 2923515904 was observed on an x86_64-linux-gnu host. | |
| 464 | .max_rss = 3100000000, | |
| 463 | // 3888779264 was observed on an x86_64-linux-gnu host. | |
| 464 | .max_rss = 4000000000, | |
| 465 | 465 | })); |
| 466 | 466 | |
| 467 | 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 | 3842 | {#header_close#} |
| 3843 | 3843 | {#header_close#} |
| 3844 | 3844 | |
| 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#} | |
| 3859 | pub 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 | 3845 | {#header_open|comptime#} |
| 3877 | 3846 | <p> |
| 3878 | 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 | 4248 | {#header_close#} |
| 4280 | 4249 | |
| 4281 | 4250 | {#header_open|Async Functions#} |
| 4282 | <p>Async functions regressed with the release of 0.11.0. Their future in | |
| 4283 | the Zig language is unclear due to multiple unsolved problems:</p> | |
| 4284 | <ul> | |
| 4285 | <li>LLVM's lack of ability to optimize them.</li> | |
| 4286 | <li>Third-party debuggers' lack of ability to debug them.</li> | |
| 4287 | <li><a href="https://github.com/ziglang/zig/issues/5913">The cancellation problem</a>.</li> | |
| 4288 | <li>Async function pointers preventing the stack size from being known.</li> | |
| 4289 | </ul> | |
| 4290 | <p>These problems are surmountable, but it will take time. The Zig team | |
| 4291 | is currently focused on other priorities.</p> | |
| 4251 | <p>Async functions regressed with the release of 0.11.0. The current plan is to | |
| 4252 | reintroduce them as a lower level primitive that powers I/O implementations.</p> | |
| 4253 | <p>Tracking issue: <a href="https://github.com/ziglang/zig/issues/23446">Proposal: stackless coroutines as low-level primitives</a></p> | |
| 4292 | 4254 | {#header_close#} |
| 4293 | 4255 | |
| 4294 | 4256 | {#header_open|Builtin Functions|2col#} |
| ... | ... | @@ -6552,7 +6514,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 6552 | 6514 | </p> |
| 6553 | 6515 | <ul> |
| 6554 | 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 | 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 | 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 | 6520 | </ul> |
| ... | ... | @@ -7372,29 +7334,6 @@ fn readU32Be() u32 {} |
| 7372 | 7334 | </ul> |
| 7373 | 7335 | </td> |
| 7374 | 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 | 7337 | <tr> |
| 7399 | 7338 | <th scope="row"> |
| 7400 | 7339 | <pre>{#syntax#}break{#endsyntax#}</pre> |
| ... | ... | @@ -7812,18 +7751,6 @@ fn readU32Be() u32 {} |
| 7812 | 7751 | </ul> |
| 7813 | 7752 | </td> |
| 7814 | 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 | 7754 | <tr> |
| 7828 | 7755 | <th scope="row"> |
| 7829 | 7756 | <pre>{#syntax#}var{#endsyntax#}</pre> |
| ... | ... | @@ -7893,7 +7820,6 @@ ComptimeDecl <- KEYWORD_comptime Block |
| 7893 | 7820 | Decl |
| 7894 | 7821 | <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block) |
| 7895 | 7822 | / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? GlobalVarDecl |
| 7896 | / KEYWORD_usingnamespace Expr SEMICOLON | |
| 7897 | 7823 | |
| 7898 | 7824 | FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr |
| 7899 | 7825 | |
| ... | ... | @@ -8006,8 +7932,7 @@ TypeExpr <- PrefixTypeOp* ErrorUnionExpr |
| 8006 | 7932 | ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)? |
| 8007 | 7933 | |
| 8008 | 7934 | SuffixExpr |
| 8009 | <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments | |
| 8010 | / PrimaryTypeExpr (SuffixOp / FnCallArguments)* | |
| 7935 | <- PrimaryTypeExpr (SuffixOp / FnCallArguments)* | |
| 8011 | 7936 | |
| 8012 | 7937 | PrimaryTypeExpr |
| 8013 | 7938 | <- BUILTINIDENTIFIER FnCallArguments |
| ... | ... | @@ -8183,7 +8108,6 @@ PrefixOp |
| 8183 | 8108 | / MINUSPERCENT |
| 8184 | 8109 | / AMPERSAND |
| 8185 | 8110 | / KEYWORD_try |
| 8186 | / KEYWORD_await | |
| 8187 | 8111 | |
| 8188 | 8112 | PrefixTypeOp |
| 8189 | 8113 | <- QUESTIONMARK |
| ... | ... | @@ -8404,8 +8328,6 @@ KEYWORD_and <- 'and' end_of_word |
| 8404 | 8328 | KEYWORD_anyframe <- 'anyframe' end_of_word |
| 8405 | 8329 | KEYWORD_anytype <- 'anytype' end_of_word |
| 8406 | 8330 | KEYWORD_asm <- 'asm' end_of_word |
| 8407 | KEYWORD_async <- 'async' end_of_word | |
| 8408 | KEYWORD_await <- 'await' end_of_word | |
| 8409 | 8331 | KEYWORD_break <- 'break' end_of_word |
| 8410 | 8332 | KEYWORD_callconv <- 'callconv' end_of_word |
| 8411 | 8333 | KEYWORD_catch <- 'catch' end_of_word |
| ... | ... | @@ -8442,14 +8364,13 @@ KEYWORD_threadlocal <- 'threadlocal' end_of_word |
| 8442 | 8364 | KEYWORD_try <- 'try' end_of_word |
| 8443 | 8365 | KEYWORD_union <- 'union' end_of_word |
| 8444 | 8366 | KEYWORD_unreachable <- 'unreachable' end_of_word |
| 8445 | KEYWORD_usingnamespace <- 'usingnamespace' end_of_word | |
| 8446 | 8367 | KEYWORD_var <- 'var' end_of_word |
| 8447 | 8368 | KEYWORD_volatile <- 'volatile' end_of_word |
| 8448 | 8369 | KEYWORD_while <- 'while' end_of_word |
| 8449 | 8370 | |
| 8450 | 8371 | keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and |
| 8451 | / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm / KEYWORD_async | |
| 8452 | / KEYWORD_await / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch | |
| 8372 | / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm | |
| 8373 | / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch | |
| 8453 | 8374 | / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer |
| 8454 | 8375 | / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export |
| 8455 | 8376 | / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if |
| ... | ... | @@ -8458,7 +8379,7 @@ keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and |
| 8458 | 8379 | / KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection |
| 8459 | 8380 | / KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test |
| 8460 | 8381 | / KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable |
| 8461 | / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while | |
| 8382 | / KEYWORD_var / KEYWORD_volatile / KEYWORD_while | |
| 8462 | 8383 | {#end_syntax_block#} |
| 8463 | 8384 | {#header_close#} |
| 8464 | 8385 | {#header_open|Zen#} |
doc/langref/test_usingnamespace.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | test "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 | 160 | try walkExpression(w, decl); |
| 161 | 161 | }, |
| 162 | 162 | |
| 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 | 163 | .global_var_decl, |
| 170 | 164 | .local_var_decl, |
| 171 | 165 | .simple_var_decl, |
| ... | ... | @@ -335,7 +329,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { |
| 335 | 329 | .address_of, |
| 336 | 330 | .@"try", |
| 337 | 331 | .@"resume", |
| 338 | .@"await", | |
| 339 | 332 | .deref, |
| 340 | 333 | => { |
| 341 | 334 | return walkExpression(w, ast.nodeData(node).node); |
| ... | ... | @@ -379,12 +372,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { |
| 379 | 372 | |
| 380 | 373 | .call_one, |
| 381 | 374 | .call_one_comma, |
| 382 | .async_call_one, | |
| 383 | .async_call_one_comma, | |
| 384 | 375 | .call, |
| 385 | 376 | .call_comma, |
| 386 | .async_call, | |
| 387 | .async_call_comma, | |
| 388 | 377 | => { |
| 389 | 378 | var buf: [1]Ast.Node.Index = undefined; |
| 390 | 379 | return walkCall(w, ast.fullCall(&buf, node).?); |
| ... | ... | @@ -525,7 +514,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { |
| 525 | 514 | .local_var_decl => unreachable, |
| 526 | 515 | .simple_var_decl => unreachable, |
| 527 | 516 | .aligned_var_decl => unreachable, |
| 528 | .@"usingnamespace" => unreachable, | |
| 529 | 517 | .test_decl => unreachable, |
| 530 | 518 | .asm_output => unreachable, |
| 531 | 519 | .asm_input => unreachable, |
lib/docs/wasm/Walk.zig-11| ... | ... | @@ -238,12 +238,8 @@ pub const File = struct { |
| 238 | 238 | |
| 239 | 239 | .call_one, |
| 240 | 240 | .call_one_comma, |
| 241 | .async_call_one, | |
| 242 | .async_call_one_comma, | |
| 243 | 241 | .call, |
| 244 | 242 | .call_comma, |
| 245 | .async_call, | |
| 246 | .async_call_comma, | |
| 247 | 243 | => { |
| 248 | 244 | var buf: [1]Ast.Node.Index = undefined; |
| 249 | 245 | return categorize_call(file_index, node, ast.fullCall(&buf, node).?); |
| ... | ... | @@ -571,7 +567,6 @@ fn struct_decl( |
| 571 | 567 | }, |
| 572 | 568 | |
| 573 | 569 | .@"comptime", |
| 574 | .@"usingnamespace", | |
| 575 | 570 | => try w.expr(&namespace.base, parent_decl, ast.nodeData(member).node), |
| 576 | 571 | |
| 577 | 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 | 638 | const ast = w.file.get_ast(); |
| 644 | 639 | switch (ast.nodeTag(node)) { |
| 645 | 640 | .root => unreachable, // Top-level declaration. |
| 646 | .@"usingnamespace" => unreachable, // Top-level declaration. | |
| 647 | 641 | .test_decl => unreachable, // Top-level declaration. |
| 648 | 642 | .container_field_init => unreachable, // Top-level declaration. |
| 649 | 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 | 737 | .@"comptime", |
| 744 | 738 | .@"nosuspend", |
| 745 | 739 | .@"suspend", |
| 746 | .@"await", | |
| 747 | 740 | .@"resume", |
| 748 | 741 | .@"try", |
| 749 | 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 | 799 | |
| 807 | 800 | .call_one, |
| 808 | 801 | .call_one_comma, |
| 809 | .async_call_one, | |
| 810 | .async_call_one_comma, | |
| 811 | 802 | .call, |
| 812 | 803 | .call_comma, |
| 813 | .async_call, | |
| 814 | .async_call_comma, | |
| 815 | 804 | => { |
| 816 | 805 | var buf: [1]Ast.Node.Index = undefined; |
| 817 | 806 | const full = ast.fullCall(&buf, node).?; |
lib/docs/wasm/html_render.zig-3| ... | ... | @@ -101,8 +101,6 @@ pub fn fileSourceHtml( |
| 101 | 101 | .keyword_align, |
| 102 | 102 | .keyword_and, |
| 103 | 103 | .keyword_asm, |
| 104 | .keyword_async, | |
| 105 | .keyword_await, | |
| 106 | 104 | .keyword_break, |
| 107 | 105 | .keyword_catch, |
| 108 | 106 | .keyword_comptime, |
| ... | ... | @@ -139,7 +137,6 @@ pub fn fileSourceHtml( |
| 139 | 137 | .keyword_try, |
| 140 | 138 | .keyword_union, |
| 141 | 139 | .keyword_unreachable, |
| 142 | .keyword_usingnamespace, | |
| 143 | 140 | .keyword_var, |
| 144 | 141 | .keyword_volatile, |
| 145 | 142 | .keyword_allowzero, |
lib/std/Build/Module.zig+1-1| ... | ... | @@ -572,7 +572,7 @@ pub fn appendZigProcessFlags( |
| 572 | 572 | try zig_args.append(switch (unwind_tables) { |
| 573 | 573 | .none => "-fno-unwind-tables", |
| 574 | 574 | .sync => "-funwind-tables", |
| 575 | .@"async" => "-fasync-unwind-tables", | |
| 575 | .async => "-fasync-unwind-tables", | |
| 576 | 576 | }); |
| 577 | 577 | } |
| 578 | 578 |
lib/std/Target.zig+1-1| ... | ... | @@ -1691,7 +1691,7 @@ pub const Cpu = struct { |
| 1691 | 1691 | pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch { |
| 1692 | 1692 | return switch (cc) { |
| 1693 | 1693 | .auto, |
| 1694 | .@"async", | |
| 1694 | .async, | |
| 1695 | 1695 | .naked, |
| 1696 | 1696 | .@"inline", |
| 1697 | 1697 | => unreachable, |
lib/std/builtin.zig+3-14| ... | ... | @@ -199,8 +199,6 @@ pub const CallingConvention = union(enum(u8)) { |
| 199 | 199 | pub const C: CallingConvention = .c; |
| 200 | 200 | /// Deprecated; use `.naked`. |
| 201 | 201 | pub const Naked: CallingConvention = .naked; |
| 202 | /// Deprecated; use `.@"async"`. | |
| 203 | pub const Async: CallingConvention = .@"async"; | |
| 204 | 202 | /// Deprecated; use `.@"inline"`. |
| 205 | 203 | pub const Inline: CallingConvention = .@"inline"; |
| 206 | 204 | /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`. |
| ... | ... | @@ -248,7 +246,7 @@ pub const CallingConvention = union(enum(u8)) { |
| 248 | 246 | /// The calling convention of a function that can be called with `async` syntax. An `async` call |
| 249 | 247 | /// of a runtime-known function must target a function with this calling convention. |
| 250 | 248 | /// Comptime-known functions with other calling conventions may be coerced to this one. |
| 251 | @"async", | |
| 249 | async, | |
| 252 | 250 | |
| 253 | 251 | /// Functions with this calling convention have no prologue or epilogue, making the function |
| 254 | 252 | /// uncallable in regular Zig code. This can be useful when integrating with assembly. |
| ... | ... | @@ -851,7 +849,7 @@ pub const LinkMode = enum { |
| 851 | 849 | pub const UnwindTables = enum { |
| 852 | 850 | none, |
| 853 | 851 | sync, |
| 854 | @"async", | |
| 852 | async, | |
| 855 | 853 | }; |
| 856 | 854 | |
| 857 | 855 | /// This data structure is used by the Zig language code generation and |
| ... | ... | @@ -866,32 +864,23 @@ pub const WasiExecModel = enum { |
| 866 | 864 | pub const CallModifier = enum { |
| 867 | 865 | /// Equivalent to function call syntax. |
| 868 | 866 | auto, |
| 869 | ||
| 870 | /// Equivalent to async keyword used with function call syntax. | |
| 871 | async_kw, | |
| 872 | ||
| 873 | 867 | /// Prevents tail call optimization. This guarantees that the return |
| 874 | 868 | /// address will point to the callsite, as opposed to the callsite's |
| 875 | 869 | /// callsite. If the call is otherwise required to be tail-called |
| 876 | 870 | /// or inlined, a compile error is emitted instead. |
| 877 | 871 | never_tail, |
| 878 | ||
| 879 | 872 | /// Guarantees that the call will not be inlined. If the call is |
| 880 | 873 | /// otherwise required to be inlined, a compile error is emitted instead. |
| 881 | 874 | never_inline, |
| 882 | ||
| 883 | 875 | /// Asserts that the function call will not suspend. This allows a |
| 884 | 876 | /// non-async function to call an async function. |
| 885 | no_async, | |
| 886 | ||
| 877 | no_suspend, | |
| 887 | 878 | /// Guarantees that the call will be generated with tail call optimization. |
| 888 | 879 | /// If this is not possible, a compile error is emitted instead. |
| 889 | 880 | always_tail, |
| 890 | ||
| 891 | 881 | /// Guarantees that the call will be inlined at the callsite. |
| 892 | 882 | /// If this is not possible, a compile error is emitted instead. |
| 893 | 883 | always_inline, |
| 894 | ||
| 895 | 884 | /// Evaluates the call at compile-time. If the call cannot be completed at |
| 896 | 885 | /// compile-time, a compile error is emitted instead. |
| 897 | 886 | compile_time, |
lib/std/zig/Ast.zig+7-78| ... | ... | @@ -606,7 +606,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 606 | 606 | .negation_wrap, |
| 607 | 607 | .address_of, |
| 608 | 608 | .@"try", |
| 609 | .@"await", | |
| 610 | 609 | .optional_type, |
| 611 | 610 | .@"switch", |
| 612 | 611 | .switch_comma, |
| ... | ... | @@ -756,27 +755,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 756 | 755 | return i - end_offset; |
| 757 | 756 | }, |
| 758 | 757 | |
| 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 | 758 | .container_field_init, |
| 781 | 759 | .container_field_align, |
| 782 | 760 | .container_field, |
| ... | ... | @@ -896,14 +874,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 896 | 874 | while (true) switch (tree.nodeTag(n)) { |
| 897 | 875 | .root => return @intCast(tree.tokens.len - 1), |
| 898 | 876 | |
| 899 | .@"usingnamespace", | |
| 900 | 877 | .bool_not, |
| 901 | 878 | .negation, |
| 902 | 879 | .bit_not, |
| 903 | 880 | .negation_wrap, |
| 904 | 881 | .address_of, |
| 905 | 882 | .@"try", |
| 906 | .@"await", | |
| 907 | 883 | .optional_type, |
| 908 | 884 | .@"suspend", |
| 909 | 885 | .@"resume", |
| ... | ... | @@ -1022,7 +998,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1022 | 998 | }; |
| 1023 | 999 | }, |
| 1024 | 1000 | |
| 1025 | .call, .async_call => { | |
| 1001 | .call => { | |
| 1026 | 1002 | _, const extra_index = tree.nodeData(n).node_and_extra; |
| 1027 | 1003 | const params = tree.extraData(extra_index, Node.SubRange); |
| 1028 | 1004 | assert(params.start != params.end); |
| ... | ... | @@ -1041,7 +1017,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1041 | 1017 | } |
| 1042 | 1018 | }, |
| 1043 | 1019 | .call_comma, |
| 1044 | .async_call_comma, | |
| 1045 | 1020 | .tagged_union_enum_tag_trailing, |
| 1046 | 1021 | => { |
| 1047 | 1022 | _, const extra_index = tree.nodeData(n).node_and_extra; |
| ... | ... | @@ -1122,7 +1097,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1122 | 1097 | n = @enumFromInt(tree.extra_data[@intFromEnum(range.end) - 1]); // last member |
| 1123 | 1098 | }, |
| 1124 | 1099 | .call_one, |
| 1125 | .async_call_one, | |
| 1126 | 1100 | => { |
| 1127 | 1101 | _, const first_param = tree.nodeData(n).node_and_opt_node; |
| 1128 | 1102 | end_offset += 1; // for the rparen |
| ... | ... | @@ -1271,7 +1245,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1271 | 1245 | n = first_element; |
| 1272 | 1246 | }, |
| 1273 | 1247 | .call_one_comma, |
| 1274 | .async_call_one_comma, | |
| 1275 | 1248 | .struct_init_one_comma, |
| 1276 | 1249 | => { |
| 1277 | 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 | 1961 | pub fn callOne(tree: Ast, buffer: *[1]Node.Index, node: Node.Index) full.Call { |
| 1989 | 1962 | const fn_expr, const first_param = tree.nodeData(node).node_and_opt_node; |
| 1990 | 1963 | const params = loadOptionalNodesIntoBuffer(1, buffer, .{first_param}); |
| 1991 | return tree.fullCallComponents(.{ | |
| 1964 | return .{ .ast = .{ | |
| 1992 | 1965 | .lparen = tree.nodeMainToken(node), |
| 1993 | 1966 | .fn_expr = fn_expr, |
| 1994 | 1967 | .params = params, |
| 1995 | }); | |
| 1968 | } }; | |
| 1996 | 1969 | } |
| 1997 | 1970 | |
| 1998 | 1971 | pub fn callFull(tree: Ast, node: Node.Index) full.Call { |
| 1999 | 1972 | const fn_expr, const extra_index = tree.nodeData(node).node_and_extra; |
| 2000 | 1973 | const params = tree.extraDataSlice(tree.extraData(extra_index, Node.SubRange), Node.Index); |
| 2001 | return tree.fullCallComponents(.{ | |
| 1974 | return .{ .ast = .{ | |
| 2002 | 1975 | .lparen = tree.nodeMainToken(node), |
| 2003 | 1976 | .fn_expr = fn_expr, |
| 2004 | 1977 | .params = params, |
| 2005 | }); | |
| 1978 | } }; | |
| 2006 | 1979 | } |
| 2007 | 1980 | |
| 2008 | 1981 | fn fullVarDeclComponents(tree: Ast, info: full.VarDecl.Components) full.VarDecl { |
| ... | ... | @@ -2336,18 +2309,6 @@ fn fullForComponents(tree: Ast, info: full.For.Components) full.For { |
| 2336 | 2309 | return result; |
| 2337 | 2310 | } |
| 2338 | 2311 | |
| 2339 | fn 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 | ||
| 2351 | 2312 | pub fn fullVarDecl(tree: Ast, node: Node.Index) ?full.VarDecl { |
| 2352 | 2313 | return switch (tree.nodeTag(node)) { |
| 2353 | 2314 | .global_var_decl => tree.globalVarDecl(node), |
| ... | ... | @@ -2488,8 +2449,8 @@ pub fn fullAsm(tree: Ast, node: Node.Index) ?full.Asm { |
| 2488 | 2449 | |
| 2489 | 2450 | pub fn fullCall(tree: Ast, buffer: *[1]Ast.Node.Index, node: Node.Index) ?full.Call { |
| 2490 | 2451 | return switch (tree.nodeTag(node)) { |
| 2491 | .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node), | |
| 2492 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(buffer, node), | |
| 2452 | .call, .call_comma => tree.callFull(node), | |
| 2453 | .call_one, .call_one_comma => tree.callOne(buffer, node), | |
| 2493 | 2454 | else => null, |
| 2494 | 2455 | }; |
| 2495 | 2456 | } |
| ... | ... | @@ -2882,7 +2843,6 @@ pub const full = struct { |
| 2882 | 2843 | |
| 2883 | 2844 | pub const Call = struct { |
| 2884 | 2845 | ast: Components, |
| 2885 | async_token: ?TokenIndex, | |
| 2886 | 2846 | |
| 2887 | 2847 | pub const Components = struct { |
| 2888 | 2848 | lparen: TokenIndex, |
| ... | ... | @@ -3065,12 +3025,6 @@ pub const Node = struct { |
| 3065 | 3025 | /// |
| 3066 | 3026 | /// The `main_token` field is the first token for the source file. |
| 3067 | 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 | 3028 | /// `test {}`, |
| 3075 | 3029 | /// `test "name" {}`, |
| 3076 | 3030 | /// `test identifier {}`. |
| ... | ... | @@ -3301,8 +3255,6 @@ pub const Node = struct { |
| 3301 | 3255 | address_of, |
| 3302 | 3256 | /// `try expr`. The `main_token` field is the `try` token. |
| 3303 | 3257 | @"try", |
| 3304 | /// `await expr`. The `main_token` field is the `await` token. | |
| 3305 | @"await", | |
| 3306 | 3258 | /// `?expr`. The `main_token` field is the `?` token. |
| 3307 | 3259 | optional_type, |
| 3308 | 3260 | /// `[lhs]rhs`. The `main_token` field is the `[` token. |
| ... | ... | @@ -3498,17 +3450,6 @@ pub const Node = struct { |
| 3498 | 3450 | /// Same as `call_one` except there is known to be a trailing comma |
| 3499 | 3451 | /// before the final rparen. |
| 3500 | 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 | 3453 | /// `a(b, c, d)`. |
| 3513 | 3454 | /// |
| 3514 | 3455 | /// The `data` field is a `.node_and_extra`: |
| ... | ... | @@ -3521,18 +3462,6 @@ pub const Node = struct { |
| 3521 | 3462 | /// Same as `call` except there is known to be a trailing comma before |
| 3522 | 3463 | /// the final rparen. |
| 3523 | 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 | 3465 | /// `switch(a) {}`. |
| 3537 | 3466 | /// |
| 3538 | 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 | 442 | const tree = astgen.tree; |
| 443 | 443 | switch (tree.nodeTag(node)) { |
| 444 | 444 | .root => unreachable, |
| 445 | .@"usingnamespace" => unreachable, | |
| 446 | 445 | .test_decl => unreachable, |
| 447 | 446 | .global_var_decl => unreachable, |
| 448 | 447 | .local_var_decl => unreachable, |
| ... | ... | @@ -510,12 +509,8 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins |
| 510 | 509 | .number_literal, |
| 511 | 510 | .call, |
| 512 | 511 | .call_comma, |
| 513 | .async_call, | |
| 514 | .async_call_comma, | |
| 515 | 512 | .call_one, |
| 516 | 513 | .call_one_comma, |
| 517 | .async_call_one, | |
| 518 | .async_call_one_comma, | |
| 519 | 514 | .unreachable_literal, |
| 520 | 515 | .@"return", |
| 521 | 516 | .@"if", |
| ... | ... | @@ -547,7 +542,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins |
| 547 | 542 | .merge_error_sets, |
| 548 | 543 | .switch_range, |
| 549 | 544 | .for_range, |
| 550 | .@"await", | |
| 551 | 545 | .bit_not, |
| 552 | 546 | .negation, |
| 553 | 547 | .negation_wrap, |
| ... | ... | @@ -642,7 +636,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 642 | 636 | |
| 643 | 637 | switch (tree.nodeTag(node)) { |
| 644 | 638 | .root => unreachable, // Top-level declaration. |
| 645 | .@"usingnamespace" => unreachable, // Top-level declaration. | |
| 646 | 639 | .test_decl => unreachable, // Top-level declaration. |
| 647 | 640 | .container_field_init => unreachable, // Top-level declaration. |
| 648 | 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 | 829 | |
| 837 | 830 | .call_one, |
| 838 | 831 | .call_one_comma, |
| 839 | .async_call_one, | |
| 840 | .async_call_one_comma, | |
| 841 | 832 | .call, |
| 842 | 833 | .call_comma, |
| 843 | .async_call, | |
| 844 | .async_call_comma, | |
| 845 | 834 | => { |
| 846 | 835 | var buf: [1]Ast.Node.Index = undefined; |
| 847 | 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 | 1103 | |
| 1115 | 1104 | .@"nosuspend" => return nosuspendExpr(gz, scope, ri, node), |
| 1116 | 1105 | .@"suspend" => return suspendExpr(gz, scope, node), |
| 1117 | .@"await" => return awaitExpr(gz, scope, ri, node), | |
| 1118 | 1106 | .@"resume" => return resumeExpr(gz, scope, ri, node), |
| 1119 | 1107 | |
| 1120 | 1108 | .@"try" => return tryExpr(gz, scope, ri, node, tree.nodeData(node).node), |
| ... | ... | @@ -1259,33 +1247,6 @@ fn suspendExpr( |
| 1259 | 1247 | return suspend_inst.toRef(); |
| 1260 | 1248 | } |
| 1261 | 1249 | |
| 1262 | fn 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 | ||
| 1289 | 1250 | fn resumeExpr( |
| 1290 | 1251 | gz: *GenZir, |
| 1291 | 1252 | scope: *Scope, |
| ... | ... | @@ -2853,7 +2814,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2853 | 2814 | .tag_name, |
| 2854 | 2815 | .type_name, |
| 2855 | 2816 | .frame_type, |
| 2856 | .frame_size, | |
| 2857 | 2817 | .int_from_float, |
| 2858 | 2818 | .float_from_int, |
| 2859 | 2819 | .ptr_from_int, |
| ... | ... | @@ -2887,7 +2847,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2887 | 2847 | .min, |
| 2888 | 2848 | .c_import, |
| 2889 | 2849 | .@"resume", |
| 2890 | .@"await", | |
| 2891 | 2850 | .ret_err_value_code, |
| 2892 | 2851 | .ret_ptr, |
| 2893 | 2852 | .ret_type, |
| ... | ... | @@ -4739,69 +4698,6 @@ fn comptimeDecl( |
| 4739 | 4698 | }); |
| 4740 | 4699 | } |
| 4741 | 4700 | |
| 4742 | fn 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 | ||
| 4805 | 4701 | fn testDecl( |
| 4806 | 4702 | astgen: *AstGen, |
| 4807 | 4703 | gz: *GenZir, |
| ... | ... | @@ -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 | 5870 | .test_decl => { |
| 5992 | 5871 | const prev_decl_index = wip_members.decl_index; |
| 5993 | 5872 | // We need to have *some* decl here so that the decl count matches what's expected. |
| ... | ... | @@ -9501,7 +9380,6 @@ fn builtinCall( |
| 9501 | 9380 | .tag_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .tag_name), |
| 9502 | 9381 | .type_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .type_name), |
| 9503 | 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), | |
| 9505 | 9383 | |
| 9506 | 9384 | .int_from_float => return typeCast(gz, scope, ri, node, params[0], .int_from_float, builtin_name), |
| 9507 | 9385 | .float_from_int => return typeCast(gz, scope, ri, node, params[0], .float_from_int, builtin_name), |
| ... | ... | @@ -9767,16 +9645,6 @@ fn builtinCall( |
| 9767 | 9645 | }); |
| 9768 | 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 | 9648 | .Vector => { |
| 9781 | 9649 | const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{ |
| 9782 | 9650 | .lhs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .type), |
| ... | ... | @@ -10175,11 +10043,8 @@ fn callExpr( |
| 10175 | 10043 | |
| 10176 | 10044 | const callee = try calleeExpr(gz, scope, ri.rl, override_decl_literal_type, call.ast.fn_expr); |
| 10177 | 10045 | const modifier: std.builtin.CallModifier = blk: { |
| 10178 | if (call.async_token != null) { | |
| 10179 | break :blk .async_kw; | |
| 10180 | } | |
| 10181 | 10046 | if (gz.nosuspend_node != .none) { |
| 10182 | break :blk .no_async; | |
| 10047 | break :blk .no_suspend; | |
| 10183 | 10048 | } |
| 10184 | 10049 | break :blk .auto; |
| 10185 | 10050 | }; |
| ... | ... | @@ -10451,7 +10316,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10451 | 10316 | while (true) { |
| 10452 | 10317 | switch (tree.nodeTag(node)) { |
| 10453 | 10318 | .root, |
| 10454 | .@"usingnamespace", | |
| 10455 | 10319 | .test_decl, |
| 10456 | 10320 | .switch_case, |
| 10457 | 10321 | .switch_case_inline, |
| ... | ... | @@ -10483,12 +10347,8 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10483 | 10347 | .switch_comma, |
| 10484 | 10348 | .call_one, |
| 10485 | 10349 | .call_one_comma, |
| 10486 | .async_call_one, | |
| 10487 | .async_call_one_comma, | |
| 10488 | 10350 | .call, |
| 10489 | 10351 | .call_comma, |
| 10490 | .async_call, | |
| 10491 | .async_call_comma, | |
| 10492 | 10352 | => return .maybe, |
| 10493 | 10353 | |
| 10494 | 10354 | .@"return", |
| ... | ... | @@ -10613,7 +10473,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10613 | 10473 | |
| 10614 | 10474 | // Forward the question to the LHS sub-expression. |
| 10615 | 10475 | .@"try", |
| 10616 | .@"await", | |
| 10617 | 10476 | .@"comptime", |
| 10618 | 10477 | .@"nosuspend", |
| 10619 | 10478 | => node = tree.nodeData(node).node, |
| ... | ... | @@ -10664,7 +10523,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10664 | 10523 | while (true) { |
| 10665 | 10524 | switch (tree.nodeTag(node)) { |
| 10666 | 10525 | .root, |
| 10667 | .@"usingnamespace", | |
| 10668 | 10526 | .test_decl, |
| 10669 | 10527 | .switch_case, |
| 10670 | 10528 | .switch_case_inline, |
| ... | ... | @@ -10803,12 +10661,8 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10803 | 10661 | .switch_comma, |
| 10804 | 10662 | .call_one, |
| 10805 | 10663 | .call_one_comma, |
| 10806 | .async_call_one, | |
| 10807 | .async_call_one_comma, | |
| 10808 | 10664 | .call, |
| 10809 | 10665 | .call_comma, |
| 10810 | .async_call, | |
| 10811 | .async_call_comma, | |
| 10812 | 10666 | .block_two, |
| 10813 | 10667 | .block_two_semicolon, |
| 10814 | 10668 | .block, |
| ... | ... | @@ -10826,7 +10680,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 10826 | 10680 | |
| 10827 | 10681 | // Forward the question to the LHS sub-expression. |
| 10828 | 10682 | .@"try", |
| 10829 | .@"await", | |
| 10830 | 10683 | .@"comptime", |
| 10831 | 10684 | .@"nosuspend", |
| 10832 | 10685 | => node = tree.nodeData(node).node, |
| ... | ... | @@ -10908,7 +10761,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 10908 | 10761 | while (true) { |
| 10909 | 10762 | switch (tree.nodeTag(node)) { |
| 10910 | 10763 | .root, |
| 10911 | .@"usingnamespace", | |
| 10912 | 10764 | .test_decl, |
| 10913 | 10765 | .switch_case, |
| 10914 | 10766 | .switch_case_inline, |
| ... | ... | @@ -11047,12 +10899,8 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 11047 | 10899 | .switch_comma, |
| 11048 | 10900 | .call_one, |
| 11049 | 10901 | .call_one_comma, |
| 11050 | .async_call_one, | |
| 11051 | .async_call_one_comma, | |
| 11052 | 10902 | .call, |
| 11053 | 10903 | .call_comma, |
| 11054 | .async_call, | |
| 11055 | .async_call_comma, | |
| 11056 | 10904 | .block_two, |
| 11057 | 10905 | .block_two_semicolon, |
| 11058 | 10906 | .block, |
| ... | ... | @@ -11079,7 +10927,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 11079 | 10927 | |
| 11080 | 10928 | // Forward the question to the LHS sub-expression. |
| 11081 | 10929 | .@"try", |
| 11082 | .@"await", | |
| 11083 | 10930 | .@"comptime", |
| 11084 | 10931 | .@"nosuspend", |
| 11085 | 10932 | => node = tree.nodeData(node).node, |
| ... | ... | @@ -13586,7 +13433,7 @@ fn scanContainer( |
| 13586 | 13433 | break :blk .{ .decl, ident }; |
| 13587 | 13434 | }, |
| 13588 | 13435 | |
| 13589 | .@"comptime", .@"usingnamespace" => { | |
| 13436 | .@"comptime" => { | |
| 13590 | 13437 | decl_count += 1; |
| 13591 | 13438 | continue; |
| 13592 | 13439 | }, |
| ... | ... | @@ -13964,7 +13811,6 @@ const DeclarationName = union(enum) { |
| 13964 | 13811 | decltest: Ast.TokenIndex, |
| 13965 | 13812 | unnamed_test, |
| 13966 | 13813 | @"comptime", |
| 13967 | @"usingnamespace", | |
| 13968 | 13814 | }; |
| 13969 | 13815 | |
| 13970 | 13816 | fn addFailedDeclaration( |
| ... | ... | @@ -14054,7 +13900,6 @@ fn setDeclaration( |
| 14054 | 13900 | .@"test" => .@"test", |
| 14055 | 13901 | .decltest => .decltest, |
| 14056 | 13902 | .@"comptime" => .@"comptime", |
| 14057 | .@"usingnamespace" => if (args.is_pub) .pub_usingnamespace else .@"usingnamespace", | |
| 14058 | 13903 | .@"const" => switch (args.linkage) { |
| 14059 | 13904 | .normal => if (args.is_pub) id: { |
| 14060 | 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 | 165 | } |
| 166 | 166 | return false; |
| 167 | 167 | }, |
| 168 | .@"usingnamespace" => { | |
| 169 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only); | |
| 170 | return false; | |
| 171 | }, | |
| 172 | 168 | .test_decl => { |
| 173 | 169 | _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none); |
| 174 | 170 | return false; |
| ... | ... | @@ -334,12 +330,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 334 | 330 | |
| 335 | 331 | .call_one, |
| 336 | 332 | .call_one_comma, |
| 337 | .async_call_one, | |
| 338 | .async_call_one_comma, | |
| 339 | 333 | .call, |
| 340 | 334 | .call_comma, |
| 341 | .async_call, | |
| 342 | .async_call_comma, | |
| 343 | 335 | => { |
| 344 | 336 | var buf: [1]Ast.Node.Index = undefined; |
| 345 | 337 | const full = tree.fullCall(&buf, node).?; |
| ... | ... | @@ -353,11 +345,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 353 | 345 | .call, |
| 354 | 346 | .call_comma, |
| 355 | 347 | => 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 | 348 | else => unreachable, |
| 362 | 349 | }; |
| 363 | 350 | }, |
| ... | ... | @@ -503,7 +490,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 503 | 490 | return false; |
| 504 | 491 | }, |
| 505 | 492 | .@"try", |
| 506 | .@"await", | |
| 507 | 493 | .@"nosuspend", |
| 508 | 494 | => return astrl.expr(tree.nodeData(node).node, block, ri), |
| 509 | 495 | .grouped_expression, |
| ... | ... | @@ -948,7 +934,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast. |
| 948 | 934 | .tag_name, |
| 949 | 935 | .type_name, |
| 950 | 936 | .Frame, |
| 951 | .frame_size, | |
| 952 | 937 | .int_from_float, |
| 953 | 938 | .float_from_int, |
| 954 | 939 | .ptr_from_int, |
| ... | ... | @@ -1079,13 +1064,6 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast. |
| 1079 | 1064 | _ = try astrl.expr(args[3], block, ResultInfo.none); |
| 1080 | 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 | 1067 | .Vector => { |
| 1090 | 1068 | _ = try astrl.expr(args[0], block, ResultInfo.type_only); |
| 1091 | 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 | 4 | align_cast, |
| 5 | 5 | align_of, |
| 6 | 6 | as, |
| 7 | async_call, | |
| 8 | 7 | atomic_load, |
| 9 | 8 | atomic_rmw, |
| 10 | 9 | atomic_store, |
| ... | ... | @@ -55,7 +54,6 @@ pub const Tag = enum { |
| 55 | 54 | frame, |
| 56 | 55 | Frame, |
| 57 | 56 | frame_address, |
| 58 | frame_size, | |
| 59 | 57 | has_decl, |
| 60 | 58 | has_field, |
| 61 | 59 | import, |
| ... | ... | @@ -184,13 +182,6 @@ pub const list = list: { |
| 184 | 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 | 186 | "@atomicLoad", |
| 196 | 187 | .{ |
| ... | ... | @@ -550,13 +541,6 @@ pub const list = list: { |
| 550 | 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 | 545 | "@hasDecl", |
| 562 | 546 | .{ |
lib/std/zig/Parse.zig+2-90| ... | ... | @@ -359,16 +359,6 @@ fn parseContainerMembers(p: *Parse) Allocator.Error!Members { |
| 359 | 359 | } |
| 360 | 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 | 362 | .keyword_const, |
| 373 | 363 | .keyword_var, |
| 374 | 364 | .keyword_threadlocal, |
| ... | ... | @@ -496,7 +486,6 @@ fn findNextContainerMember(p: *Parse) void { |
| 496 | 486 | .keyword_extern, |
| 497 | 487 | .keyword_inline, |
| 498 | 488 | .keyword_noinline, |
| 499 | .keyword_usingnamespace, | |
| 500 | 489 | .keyword_threadlocal, |
| 501 | 490 | .keyword_const, |
| 502 | 491 | .keyword_var, |
| ... | ... | @@ -601,7 +590,6 @@ fn expectTestDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index { |
| 601 | 590 | /// Decl |
| 602 | 591 | /// <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block) |
| 603 | 592 | /// / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl |
| 604 | /// / KEYWORD_usingnamespace Expr SEMICOLON | |
| 605 | 593 | fn expectTopLevelDecl(p: *Parse) !?Node.Index { |
| 606 | 594 | const extern_export_inline_token = p.nextToken(); |
| 607 | 595 | var is_extern: bool = false; |
| ... | ... | @@ -664,10 +652,7 @@ fn expectTopLevelDecl(p: *Parse) !?Node.Index { |
| 664 | 652 | if (expect_var_or_fn) { |
| 665 | 653 | return p.fail(.expected_var_decl_or_fn); |
| 666 | 654 | } |
| 667 | if (p.tokenTag(p.tok_i) != .keyword_usingnamespace) { | |
| 668 | return p.fail(.expected_pub_item); | |
| 669 | } | |
| 670 | return try p.expectUsingNamespace(); | |
| 655 | return p.fail(.expected_pub_item); | |
| 671 | 656 | } |
| 672 | 657 | |
| 673 | 658 | fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index { |
| ... | ... | @@ -680,27 +665,6 @@ fn expectTopLevelDeclRecoverable(p: *Parse) error{OutOfMemory}!?Node.Index { |
| 680 | 665 | }; |
| 681 | 666 | } |
| 682 | 667 | |
| 683 | fn 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 | ||
| 694 | fn 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 | 668 | /// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr |
| 705 | 669 | fn parseFnProto(p: *Parse) !?Node.Index { |
| 706 | 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 | 1652 | /// / MINUSPERCENT |
| 1689 | 1653 | /// / AMPERSAND |
| 1690 | 1654 | /// / KEYWORD_try |
| 1691 | /// / KEYWORD_await | |
| 1692 | 1655 | fn parsePrefixExpr(p: *Parse) Error!?Node.Index { |
| 1693 | 1656 | const tag: Node.Tag = switch (p.tokenTag(p.tok_i)) { |
| 1694 | 1657 | .bang => .bool_not, |
| ... | ... | @@ -1697,7 +1660,6 @@ fn parsePrefixExpr(p: *Parse) Error!?Node.Index { |
| 1697 | 1660 | .minus_percent => .negation_wrap, |
| 1698 | 1661 | .ampersand => .address_of, |
| 1699 | 1662 | .keyword_try => .@"try", |
| 1700 | .keyword_await => .@"await", | |
| 1701 | 1663 | else => return p.parsePrimaryExpr(), |
| 1702 | 1664 | }; |
| 1703 | 1665 | return try p.addNode(.{ |
| ... | ... | @@ -2385,62 +2347,12 @@ fn parseErrorUnionExpr(p: *Parse) !?Node.Index { |
| 2385 | 2347 | } |
| 2386 | 2348 | |
| 2387 | 2349 | /// SuffixExpr |
| 2388 | /// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments | |
| 2389 | /// / PrimaryTypeExpr (SuffixOp / FnCallArguments)* | |
| 2350 | /// <- PrimaryTypeExpr (SuffixOp / FnCallArguments)* | |
| 2390 | 2351 | /// |
| 2391 | 2352 | /// FnCallArguments <- LPAREN ExprList RPAREN |
| 2392 | 2353 | /// |
| 2393 | 2354 | /// ExprList <- (Expr COMMA)* Expr? |
| 2394 | 2355 | fn 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 | 2356 | var res = try p.parsePrimaryTypeExpr() orelse return null; |
| 2445 | 2357 | while (true) { |
| 2446 | 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 | 899 | type_name, |
| 900 | 900 | /// Implement builtin `@Frame`. Uses `un_node`. |
| 901 | 901 | frame_type, |
| 902 | /// Implement builtin `@frameSize`. Uses `un_node`. | |
| 903 | frame_size, | |
| 904 | 902 | |
| 905 | 903 | /// Implements the `@intFromFloat` builtin. |
| 906 | 904 | /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. |
| ... | ... | @@ -1044,7 +1042,6 @@ pub const Inst = struct { |
| 1044 | 1042 | |
| 1045 | 1043 | /// Implements `resume` syntax. Uses `un_node` field. |
| 1046 | 1044 | @"resume", |
| 1047 | @"await", | |
| 1048 | 1045 | |
| 1049 | 1046 | /// A defer statement. |
| 1050 | 1047 | /// Uses the `defer` union field. |
| ... | ... | @@ -1241,7 +1238,6 @@ pub const Inst = struct { |
| 1241 | 1238 | .tag_name, |
| 1242 | 1239 | .type_name, |
| 1243 | 1240 | .frame_type, |
| 1244 | .frame_size, | |
| 1245 | 1241 | .int_from_float, |
| 1246 | 1242 | .float_from_int, |
| 1247 | 1243 | .ptr_from_int, |
| ... | ... | @@ -1279,7 +1275,6 @@ pub const Inst = struct { |
| 1279 | 1275 | .min, |
| 1280 | 1276 | .c_import, |
| 1281 | 1277 | .@"resume", |
| 1282 | .@"await", | |
| 1283 | 1278 | .ret_err_value_code, |
| 1284 | 1279 | .extended, |
| 1285 | 1280 | .ret_ptr, |
| ... | ... | @@ -1526,7 +1521,6 @@ pub const Inst = struct { |
| 1526 | 1521 | .tag_name, |
| 1527 | 1522 | .type_name, |
| 1528 | 1523 | .frame_type, |
| 1529 | .frame_size, | |
| 1530 | 1524 | .int_from_float, |
| 1531 | 1525 | .float_from_int, |
| 1532 | 1526 | .ptr_from_int, |
| ... | ... | @@ -1560,7 +1554,6 @@ pub const Inst = struct { |
| 1560 | 1554 | .min, |
| 1561 | 1555 | .c_import, |
| 1562 | 1556 | .@"resume", |
| 1563 | .@"await", | |
| 1564 | 1557 | .ret_err_value_code, |
| 1565 | 1558 | .@"break", |
| 1566 | 1559 | .break_inline, |
| ... | ... | @@ -1791,7 +1784,6 @@ pub const Inst = struct { |
| 1791 | 1784 | .tag_name = .un_node, |
| 1792 | 1785 | .type_name = .un_node, |
| 1793 | 1786 | .frame_type = .un_node, |
| 1794 | .frame_size = .un_node, | |
| 1795 | 1787 | |
| 1796 | 1788 | .int_from_float = .pl_node, |
| 1797 | 1789 | .float_from_int = .pl_node, |
| ... | ... | @@ -1852,7 +1844,6 @@ pub const Inst = struct { |
| 1852 | 1844 | .make_ptr_const = .un_node, |
| 1853 | 1845 | |
| 1854 | 1846 | .@"resume" = .un_node, |
| 1855 | .@"await" = .un_node, | |
| 1856 | 1847 | |
| 1857 | 1848 | .@"defer" = .@"defer", |
| 1858 | 1849 | .defer_err_code = .defer_err_code, |
| ... | ... | @@ -2016,8 +2007,6 @@ pub const Inst = struct { |
| 2016 | 2007 | /// Implements the `@errorCast` builtin. |
| 2017 | 2008 | /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand. |
| 2018 | 2009 | error_cast, |
| 2019 | /// `operand` is payload index to `UnNode`. | |
| 2020 | await_nosuspend, | |
| 2021 | 2010 | /// Implements `@breakpoint`. |
| 2022 | 2011 | /// `operand` is `src_node: Ast.Node.Offset`. |
| 2023 | 2012 | breakpoint, |
| ... | ... | @@ -2038,9 +2027,6 @@ pub const Inst = struct { |
| 2038 | 2027 | /// `operand` is payload index to `Reify`. |
| 2039 | 2028 | /// `small` contains `NameStrategy`. |
| 2040 | 2029 | reify, |
| 2041 | /// Implements the `@asyncCall` builtin. | |
| 2042 | /// `operand` is payload index to `AsyncCall`. | |
| 2043 | builtin_async_call, | |
| 2044 | 2030 | /// Implements the `@cmpxchgStrong` and `@cmpxchgWeak` builtins. |
| 2045 | 2031 | /// `small` 0=>weak 1=>strong |
| 2046 | 2032 | /// `operand` is payload index to `Cmpxchg`. |
| ... | ... | @@ -2689,7 +2675,6 @@ pub const Inst = struct { |
| 2689 | 2675 | @"test", |
| 2690 | 2676 | decltest, |
| 2691 | 2677 | @"comptime", |
| 2692 | @"usingnamespace", | |
| 2693 | 2678 | @"const", |
| 2694 | 2679 | @"var", |
| 2695 | 2680 | }; |
| ... | ... | @@ -2706,7 +2691,7 @@ pub const Inst = struct { |
| 2706 | 2691 | src_column: u32, |
| 2707 | 2692 | |
| 2708 | 2693 | kind: Kind, |
| 2709 | /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"`, `.@"usingnamespace"`. | |
| 2694 | /// Always `.empty` for `kind` of `unnamed_test`, `.@"comptime"` | |
| 2710 | 2695 | name: NullTerminatedString, |
| 2711 | 2696 | /// Always `false` for `kind` of `unnamed_test`, `.@"test"`, `.decltest`, `.@"comptime"`. |
| 2712 | 2697 | is_pub: bool, |
| ... | ... | @@ -2737,9 +2722,6 @@ pub const Inst = struct { |
| 2737 | 2722 | decltest, |
| 2738 | 2723 | @"comptime", |
| 2739 | 2724 | |
| 2740 | @"usingnamespace", | |
| 2741 | pub_usingnamespace, | |
| 2742 | ||
| 2743 | 2725 | const_simple, |
| 2744 | 2726 | const_typed, |
| 2745 | 2727 | @"const", |
| ... | ... | @@ -2776,8 +2758,6 @@ pub const Inst = struct { |
| 2776 | 2758 | return switch (id) { |
| 2777 | 2759 | .unnamed_test, |
| 2778 | 2760 | .@"comptime", |
| 2779 | .@"usingnamespace", | |
| 2780 | .pub_usingnamespace, | |
| 2781 | 2761 | => false, |
| 2782 | 2762 | else => true, |
| 2783 | 2763 | }; |
| ... | ... | @@ -2802,8 +2782,6 @@ pub const Inst = struct { |
| 2802 | 2782 | .@"test", |
| 2803 | 2783 | .decltest, |
| 2804 | 2784 | .@"comptime", |
| 2805 | .@"usingnamespace", | |
| 2806 | .pub_usingnamespace, | |
| 2807 | 2785 | => false, // these constructs are untyped |
| 2808 | 2786 | .const_simple, |
| 2809 | 2787 | .pub_const_simple, |
| ... | ... | @@ -2835,8 +2813,6 @@ pub const Inst = struct { |
| 2835 | 2813 | .@"test", |
| 2836 | 2814 | .decltest, |
| 2837 | 2815 | .@"comptime", |
| 2838 | .@"usingnamespace", | |
| 2839 | .pub_usingnamespace, | |
| 2840 | 2816 | => false, // these constructs are untyped |
| 2841 | 2817 | .const_simple, |
| 2842 | 2818 | .const_typed, |
| ... | ... | @@ -2879,7 +2855,6 @@ pub const Inst = struct { |
| 2879 | 2855 | .@"test" => .@"test", |
| 2880 | 2856 | .decltest => .decltest, |
| 2881 | 2857 | .@"comptime" => .@"comptime", |
| 2882 | .@"usingnamespace", .pub_usingnamespace => .@"usingnamespace", | |
| 2883 | 2858 | .const_simple, |
| 2884 | 2859 | .const_typed, |
| 2885 | 2860 | .@"const", |
| ... | ... | @@ -2913,7 +2888,6 @@ pub const Inst = struct { |
| 2913 | 2888 | |
| 2914 | 2889 | pub fn isPub(id: Id) bool { |
| 2915 | 2890 | return switch (id) { |
| 2916 | .pub_usingnamespace, | |
| 2917 | 2891 | .pub_const_simple, |
| 2918 | 2892 | .pub_const_typed, |
| 2919 | 2893 | .pub_const, |
| ... | ... | @@ -2949,8 +2923,7 @@ pub const Inst = struct { |
| 2949 | 2923 | |
| 2950 | 2924 | pub const Name = enum(u32) { |
| 2951 | 2925 | @"comptime" = std.math.maxInt(u32), |
| 2952 | @"usingnamespace" = std.math.maxInt(u32) - 1, | |
| 2953 | unnamed_test = std.math.maxInt(u32) - 2, | |
| 2926 | unnamed_test = std.math.maxInt(u32) - 1, | |
| 2954 | 2927 | /// Other values are `NullTerminatedString` values, i.e. index into |
| 2955 | 2928 | /// `string_bytes`. If the byte referenced is 0, the decl is a named |
| 2956 | 2929 | /// test, and the actual name begins at the following byte. |
| ... | ... | @@ -2958,13 +2931,13 @@ pub const Inst = struct { |
| 2958 | 2931 | |
| 2959 | 2932 | pub fn isNamedTest(name: Name, zir: Zir) bool { |
| 2960 | 2933 | return switch (name) { |
| 2961 | .@"comptime", .@"usingnamespace", .unnamed_test => false, | |
| 2934 | .@"comptime", .unnamed_test => false, | |
| 2962 | 2935 | _ => zir.string_bytes[@intFromEnum(name)] == 0, |
| 2963 | 2936 | }; |
| 2964 | 2937 | } |
| 2965 | 2938 | pub fn toString(name: Name, zir: Zir) ?NullTerminatedString { |
| 2966 | 2939 | switch (name) { |
| 2967 | .@"comptime", .@"usingnamespace", .unnamed_test => return null, | |
| 2940 | .@"comptime", .unnamed_test => return null, | |
| 2968 | 2941 | _ => {}, |
| 2969 | 2942 | } |
| 2970 | 2943 | const idx: u32 = @intFromEnum(name); |
| ... | ... | @@ -3771,14 +3744,6 @@ pub const Inst = struct { |
| 3771 | 3744 | b: Ref, |
| 3772 | 3745 | }; |
| 3773 | 3746 | |
| 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 | 3747 | /// Trailing: inst: Index // for every body_len |
| 3783 | 3748 | pub const Param = struct { |
| 3784 | 3749 | /// Null-terminated string index. |
| ... | ... | @@ -4297,7 +4262,6 @@ fn findTrackableInner( |
| 4297 | 4262 | .tag_name, |
| 4298 | 4263 | .type_name, |
| 4299 | 4264 | .frame_type, |
| 4300 | .frame_size, | |
| 4301 | 4265 | .int_from_float, |
| 4302 | 4266 | .float_from_int, |
| 4303 | 4267 | .ptr_from_int, |
| ... | ... | @@ -4337,7 +4301,6 @@ fn findTrackableInner( |
| 4337 | 4301 | .resolve_inferred_alloc, |
| 4338 | 4302 | .make_ptr_const, |
| 4339 | 4303 | .@"resume", |
| 4340 | .@"await", | |
| 4341 | 4304 | .save_err_ret_index, |
| 4342 | 4305 | .restore_err_ret_index_unconditional, |
| 4343 | 4306 | .restore_err_ret_index_fn_entry, |
| ... | ... | @@ -4380,14 +4343,12 @@ fn findTrackableInner( |
| 4380 | 4343 | .prefetch, |
| 4381 | 4344 | .set_float_mode, |
| 4382 | 4345 | .error_cast, |
| 4383 | .await_nosuspend, | |
| 4384 | 4346 | .breakpoint, |
| 4385 | 4347 | .disable_instrumentation, |
| 4386 | 4348 | .disable_intrinsics, |
| 4387 | 4349 | .select, |
| 4388 | 4350 | .int_from_error, |
| 4389 | 4351 | .error_from_int, |
| 4390 | .builtin_async_call, | |
| 4391 | 4352 | .cmpxchg, |
| 4392 | 4353 | .c_va_arg, |
| 4393 | 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 | 100 | |
| 101 | 101 | switch (tree.nodeTag(node)) { |
| 102 | 102 | .root => unreachable, |
| 103 | .@"usingnamespace" => unreachable, | |
| 104 | 103 | .test_decl => unreachable, |
| 105 | 104 | .container_field_init => unreachable, |
| 106 | 105 | .container_field_align => unreachable, |
| ... | ... | @@ -204,12 +203,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 204 | 203 | |
| 205 | 204 | .call_one, |
| 206 | 205 | .call_one_comma, |
| 207 | .async_call_one, | |
| 208 | .async_call_one_comma, | |
| 209 | 206 | .call, |
| 210 | 207 | .call_comma, |
| 211 | .async_call, | |
| 212 | .async_call_comma, | |
| 213 | 208 | .@"return", |
| 214 | 209 | .if_simple, |
| 215 | 210 | .@"if", |
| ... | ... | @@ -226,7 +221,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 226 | 221 | .switch_comma, |
| 227 | 222 | .@"nosuspend", |
| 228 | 223 | .@"suspend", |
| 229 | .@"await", | |
| 230 | 224 | .@"resume", |
| 231 | 225 | .@"try", |
| 232 | 226 | .unreachable_literal, |
lib/std/zig/llvm/Builder.zig+2-2| ... | ... | @@ -1521,9 +1521,9 @@ pub const Attribute = union(Kind) { |
| 1521 | 1521 | pub const UwTable = enum(u32) { |
| 1522 | 1522 | none, |
| 1523 | 1523 | sync, |
| 1524 | @"async", | |
| 1524 | async, | |
| 1525 | 1525 | |
| 1526 | pub const default = UwTable.@"async"; | |
| 1526 | pub const default = UwTable.async; | |
| 1527 | 1527 | }; |
| 1528 | 1528 | |
| 1529 | 1529 | pub const VScaleRange = packed struct(u32) { |
lib/std/zig/parser_test.zig-139| ... | ... | @@ -341,15 +341,6 @@ test "zig fmt: nosuspend block" { |
| 341 | 341 | ); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | test "zig fmt: nosuspend await" { | |
| 345 | try testCanonical( | |
| 346 | \\fn foo() void { | |
| 347 | \\ x = nosuspend await y; | |
| 348 | \\} | |
| 349 | \\ | |
| 350 | ); | |
| 351 | } | |
| 352 | ||
| 353 | 344 | test "zig fmt: container declaration, single line" { |
| 354 | 345 | try testCanonical( |
| 355 | 346 | \\const X = struct { foo: i32 }; |
| ... | ... | @@ -1093,18 +1084,6 @@ test "zig fmt: block in slice expression" { |
| 1093 | 1084 | ); |
| 1094 | 1085 | } |
| 1095 | 1086 | |
| 1096 | test "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 | ||
| 1108 | 1087 | test "zig fmt: whitespace fixes" { |
| 1109 | 1088 | try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n", |
| 1110 | 1089 | \\test "" { |
| ... | ... | @@ -1549,17 +1528,6 @@ test "zig fmt: spaces around slice operator" { |
| 1549 | 1528 | ); |
| 1550 | 1529 | } |
| 1551 | 1530 | |
| 1552 | test "zig fmt: async call in if condition" { | |
| 1553 | try testCanonical( | |
| 1554 | \\comptime { | |
| 1555 | \\ if (async b()) { | |
| 1556 | \\ a(); | |
| 1557 | \\ } | |
| 1558 | \\} | |
| 1559 | \\ | |
| 1560 | ); | |
| 1561 | } | |
| 1562 | ||
| 1563 | 1531 | test "zig fmt: 2nd arg multiline string" { |
| 1564 | 1532 | try testCanonical( |
| 1565 | 1533 | \\comptime { |
| ... | ... | @@ -3946,27 +3914,6 @@ test "zig fmt: inline asm" { |
| 3946 | 3914 | ); |
| 3947 | 3915 | } |
| 3948 | 3916 | |
| 3949 | test "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 | ||
| 3970 | 3917 | test "zig fmt: nosuspend" { |
| 3971 | 3918 | try testCanonical( |
| 3972 | 3919 | \\const a = nosuspend foo(); |
| ... | ... | @@ -3989,14 +3936,6 @@ test "zig fmt: Block after if" { |
| 3989 | 3936 | ); |
| 3990 | 3937 | } |
| 3991 | 3938 | |
| 3992 | test "zig fmt: usingnamespace" { | |
| 3993 | try testCanonical( | |
| 3994 | \\usingnamespace @import("std"); | |
| 3995 | \\pub usingnamespace @import("std"); | |
| 3996 | \\ | |
| 3997 | ); | |
| 3998 | } | |
| 3999 | ||
| 4000 | 3939 | test "zig fmt: string identifier" { |
| 4001 | 3940 | try testCanonical( |
| 4002 | 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 | 5079 | ); |
| 5141 | 5080 | } |
| 5142 | 5081 | |
| 5143 | test "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 | ||
| 5154 | 5082 | test "zig fmt: respect extra newline between switch items" { |
| 5155 | 5083 | try testCanonical( |
| 5156 | 5084 | \\const a = switch (b) { |
| ... | ... | @@ -5719,34 +5647,6 @@ test "zig fmt: canonicalize symbols (primitive types)" { |
| 5719 | 5647 | ); |
| 5720 | 5648 | } |
| 5721 | 5649 | |
| 5722 | // Never unescape names spelled like keywords. | |
| 5723 | test "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 | ||
| 5750 | 5650 | test "zig fmt: no space before newline before multiline string" { |
| 5751 | 5651 | try testCanonical( |
| 5752 | 5652 | \\const S = struct { |
| ... | ... | @@ -6181,29 +6081,6 @@ test "recovery: missing return type" { |
| 6181 | 6081 | }); |
| 6182 | 6082 | } |
| 6183 | 6083 | |
| 6184 | test "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 | ||
| 6207 | 6084 | test "recovery: invalid extern/inline" { |
| 6208 | 6085 | try testError( |
| 6209 | 6086 | \\inline test "" { a & b; } |
| ... | ... | @@ -6232,22 +6109,6 @@ test "recovery: missing semicolon" { |
| 6232 | 6109 | }); |
| 6233 | 6110 | } |
| 6234 | 6111 | |
| 6235 | test "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 | 6112 | // TODO after https://github.com/ziglang/zig/issues/35 is implemented, |
| 6252 | 6113 | // we should be able to recover from this *at any indentation level*, |
| 6253 | 6114 | // 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 | 262 | return renderToken(r, tree.lastToken(decl) + 1, space); // semicolon |
| 263 | 263 | }, |
| 264 | 264 | |
| 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 | 265 | .global_var_decl, |
| 277 | 266 | .local_var_decl, |
| 278 | 267 | .simple_var_decl, |
| ... | ... | @@ -591,7 +580,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 591 | 580 | |
| 592 | 581 | .@"try", |
| 593 | 582 | .@"resume", |
| 594 | .@"await", | |
| 595 | 583 | => { |
| 596 | 584 | try renderToken(r, tree.nodeMainToken(node), .space); |
| 597 | 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 | 623 | |
| 636 | 624 | .call_one, |
| 637 | 625 | .call_one_comma, |
| 638 | .async_call_one, | |
| 639 | .async_call_one_comma, | |
| 640 | 626 | .call, |
| 641 | 627 | .call_comma, |
| 642 | .async_call, | |
| 643 | .async_call_comma, | |
| 644 | 628 | => { |
| 645 | 629 | var buf: [1]Ast.Node.Index = undefined; |
| 646 | 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 | 866 | .local_var_decl => unreachable, |
| 883 | 867 | .simple_var_decl => unreachable, |
| 884 | 868 | .aligned_var_decl => unreachable, |
| 885 | .@"usingnamespace" => unreachable, | |
| 886 | 869 | .test_decl => unreachable, |
| 887 | 870 | .asm_output => unreachable, |
| 888 | 871 | .asm_input => unreachable, |
| ... | ... | @@ -2551,9 +2534,6 @@ fn renderCall( |
| 2551 | 2534 | call: Ast.full.Call, |
| 2552 | 2535 | space: Space, |
| 2553 | 2536 | ) Error!void { |
| 2554 | if (call.async_token) |async_token| { | |
| 2555 | try renderToken(r, async_token, .space); | |
| 2556 | } | |
| 2557 | 2537 | try renderExpression(r, call.ast.fn_expr, .none); |
| 2558 | 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 | 17 | .{ "anyframe", .keyword_anyframe }, |
| 18 | 18 | .{ "anytype", .keyword_anytype }, |
| 19 | 19 | .{ "asm", .keyword_asm }, |
| 20 | .{ "async", .keyword_async }, | |
| 21 | .{ "await", .keyword_await }, | |
| 22 | 20 | .{ "break", .keyword_break }, |
| 23 | 21 | .{ "callconv", .keyword_callconv }, |
| 24 | 22 | .{ "catch", .keyword_catch }, |
| ... | ... | @@ -55,7 +53,6 @@ pub const Token = struct { |
| 55 | 53 | .{ "try", .keyword_try }, |
| 56 | 54 | .{ "union", .keyword_union }, |
| 57 | 55 | .{ "unreachable", .keyword_unreachable }, |
| 58 | .{ "usingnamespace", .keyword_usingnamespace }, | |
| 59 | 56 | .{ "var", .keyword_var }, |
| 60 | 57 | .{ "volatile", .keyword_volatile }, |
| 61 | 58 | .{ "while", .keyword_while }, |
| ... | ... | @@ -146,8 +143,6 @@ pub const Token = struct { |
| 146 | 143 | keyword_anyframe, |
| 147 | 144 | keyword_anytype, |
| 148 | 145 | keyword_asm, |
| 149 | keyword_async, | |
| 150 | keyword_await, | |
| 151 | 146 | keyword_break, |
| 152 | 147 | keyword_callconv, |
| 153 | 148 | keyword_catch, |
| ... | ... | @@ -184,7 +179,6 @@ pub const Token = struct { |
| 184 | 179 | keyword_try, |
| 185 | 180 | keyword_union, |
| 186 | 181 | keyword_unreachable, |
| 187 | keyword_usingnamespace, | |
| 188 | 182 | keyword_var, |
| 189 | 183 | keyword_volatile, |
| 190 | 184 | keyword_while, |
| ... | ... | @@ -273,8 +267,6 @@ pub const Token = struct { |
| 273 | 267 | .keyword_anyframe => "anyframe", |
| 274 | 268 | .keyword_anytype => "anytype", |
| 275 | 269 | .keyword_asm => "asm", |
| 276 | .keyword_async => "async", | |
| 277 | .keyword_await => "await", | |
| 278 | 270 | .keyword_break => "break", |
| 279 | 271 | .keyword_callconv => "callconv", |
| 280 | 272 | .keyword_catch => "catch", |
| ... | ... | @@ -311,7 +303,6 @@ pub const Token = struct { |
| 311 | 303 | .keyword_try => "try", |
| 312 | 304 | .keyword_union => "union", |
| 313 | 305 | .keyword_unreachable => "unreachable", |
| 314 | .keyword_usingnamespace => "usingnamespace", | |
| 315 | 306 | .keyword_var => "var", |
| 316 | 307 | .keyword_volatile => "volatile", |
| 317 | 308 | .keyword_while => "while", |
src/Compilation.zig+1-1| ... | ... | @@ -6466,7 +6466,7 @@ pub fn addCCArgs( |
| 6466 | 6466 | try argv.append("-fno-asynchronous-unwind-tables"); |
| 6467 | 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 | } |
| 6471 | 6471 | |
| 6472 | 6472 | try argv.append("-nostdinc"); |
src/InternPool.zig+1-13| ... | ... | @@ -518,8 +518,6 @@ pub const Nav = struct { |
| 518 | 518 | namespace: NamespaceIndex, |
| 519 | 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 | 521 | status: union(enum) { |
| 524 | 522 | /// This `Nav` is pending semantic analysis. |
| 525 | 523 | unresolved, |
| ... | ... | @@ -735,7 +733,7 @@ pub const Nav = struct { |
| 735 | 733 | @"addrspace": std.builtin.AddressSpace, |
| 736 | 734 | /// Populated only if `bits.status == .type_resolved`. |
| 737 | 735 | is_threadlocal: bool, |
| 738 | is_usingnamespace: bool, | |
| 736 | _: u1 = 0, | |
| 739 | 737 | }; |
| 740 | 738 | |
| 741 | 739 | fn unpack(repr: Repr) Nav { |
| ... | ... | @@ -749,7 +747,6 @@ pub const Nav = struct { |
| 749 | 747 | assert(repr.analysis_zir_index == .none); |
| 750 | 748 | break :a null; |
| 751 | 749 | }, |
| 752 | .is_usingnamespace = repr.bits.is_usingnamespace, | |
| 753 | 750 | .status = switch (repr.bits.status) { |
| 754 | 751 | .unresolved => .unresolved, |
| 755 | 752 | .type_resolved, .type_resolved_extern_decl => .{ .type_resolved = .{ |
| ... | ... | @@ -797,7 +794,6 @@ pub const Nav = struct { |
| 797 | 794 | .is_const = false, |
| 798 | 795 | .alignment = .none, |
| 799 | 796 | .@"addrspace" = .generic, |
| 800 | .is_usingnamespace = nav.is_usingnamespace, | |
| 801 | 797 | .is_threadlocal = false, |
| 802 | 798 | }, |
| 803 | 799 | .type_resolved => |r| .{ |
| ... | ... | @@ -805,7 +801,6 @@ pub const Nav = struct { |
| 805 | 801 | .is_const = r.is_const, |
| 806 | 802 | .alignment = r.alignment, |
| 807 | 803 | .@"addrspace" = r.@"addrspace", |
| 808 | .is_usingnamespace = nav.is_usingnamespace, | |
| 809 | 804 | .is_threadlocal = r.is_threadlocal, |
| 810 | 805 | }, |
| 811 | 806 | .fully_resolved => |r| .{ |
| ... | ... | @@ -813,7 +808,6 @@ pub const Nav = struct { |
| 813 | 808 | .is_const = r.is_const, |
| 814 | 809 | .alignment = r.alignment, |
| 815 | 810 | .@"addrspace" = r.@"addrspace", |
| 816 | .is_usingnamespace = nav.is_usingnamespace, | |
| 817 | 811 | .is_threadlocal = false, |
| 818 | 812 | }, |
| 819 | 813 | }, |
| ... | ... | @@ -6865,8 +6859,6 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void { |
| 6865 | 6859 | { |
| 6866 | 6860 | namespace.pub_decls.deinit(gpa); |
| 6867 | 6861 | namespace.priv_decls.deinit(gpa); |
| 6868 | namespace.pub_usingnamespace.deinit(gpa); | |
| 6869 | namespace.priv_usingnamespace.deinit(gpa); | |
| 6870 | 6862 | namespace.comptime_decls.deinit(gpa); |
| 6871 | 6863 | namespace.test_decls.deinit(gpa); |
| 6872 | 6864 | } |
| ... | ... | @@ -11503,7 +11495,6 @@ pub fn createNav( |
| 11503 | 11495 | .@"linksection" = opts.@"linksection", |
| 11504 | 11496 | .@"addrspace" = opts.@"addrspace", |
| 11505 | 11497 | } }, |
| 11506 | .is_usingnamespace = false, | |
| 11507 | 11498 | })); |
| 11508 | 11499 | return index_unwrapped.wrap(ip); |
| 11509 | 11500 | } |
| ... | ... | @@ -11518,8 +11509,6 @@ pub fn createDeclNav( |
| 11518 | 11509 | fqn: NullTerminatedString, |
| 11519 | 11510 | zir_index: TrackedInst.Index, |
| 11520 | 11511 | namespace: NamespaceIndex, |
| 11521 | /// TODO: this is hacky! See `Nav.is_usingnamespace`. | |
| 11522 | is_usingnamespace: bool, | |
| 11523 | 11512 | ) Allocator.Error!Nav.Index { |
| 11524 | 11513 | const navs = ip.getLocal(tid).getMutableNavs(gpa); |
| 11525 | 11514 | |
| ... | ... | @@ -11538,7 +11527,6 @@ pub fn createDeclNav( |
| 11538 | 11527 | .zir_index = zir_index, |
| 11539 | 11528 | }, |
| 11540 | 11529 | .status = .unresolved, |
| 11541 | .is_usingnamespace = is_usingnamespace, | |
| 11542 | 11530 | })); |
| 11543 | 11531 | |
| 11544 | 11532 | return nav; |
src/Sema.zig+19-155| ... | ... | @@ -1280,7 +1280,6 @@ fn analyzeBodyInner( |
| 1280 | 1280 | .tag_name => try sema.zirTagName(block, inst), |
| 1281 | 1281 | .type_name => try sema.zirTypeName(block, inst), |
| 1282 | 1282 | .frame_type => try sema.zirFrameType(block, inst), |
| 1283 | .frame_size => try sema.zirFrameSize(block, inst), | |
| 1284 | 1283 | .int_from_float => try sema.zirIntFromFloat(block, inst), |
| 1285 | 1284 | .float_from_int => try sema.zirFloatFromInt(block, inst), |
| 1286 | 1285 | .ptr_from_int => try sema.zirPtrFromInt(block, inst), |
| ... | ... | @@ -1302,7 +1301,6 @@ fn analyzeBodyInner( |
| 1302 | 1301 | .mul_add => try sema.zirMulAdd(block, inst), |
| 1303 | 1302 | .builtin_call => try sema.zirBuiltinCall(block, inst), |
| 1304 | 1303 | .@"resume" => try sema.zirResume(block, inst), |
| 1305 | .@"await" => try sema.zirAwait(block, inst), | |
| 1306 | 1304 | .for_len => try sema.zirForLen(block, inst), |
| 1307 | 1305 | .validate_array_init_ref_ty => try sema.zirValidateArrayInitRefTy(block, inst), |
| 1308 | 1306 | .opt_eu_base_ptr_init => try sema.zirOptEuBasePtrInit(block, inst), |
| ... | ... | @@ -1410,12 +1408,10 @@ fn analyzeBodyInner( |
| 1410 | 1408 | .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended), |
| 1411 | 1409 | .prefetch => try sema.zirPrefetch( block, extended), |
| 1412 | 1410 | .error_cast => try sema.zirErrorCast( block, extended), |
| 1413 | .await_nosuspend => try sema.zirAwaitNosuspend( block, extended), | |
| 1414 | 1411 | .select => try sema.zirSelect( block, extended), |
| 1415 | 1412 | .int_from_error => try sema.zirIntFromError( block, extended), |
| 1416 | 1413 | .error_from_int => try sema.zirErrorFromInt( block, extended), |
| 1417 | 1414 | .reify => try sema.zirReify( block, extended, inst), |
| 1418 | .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended), | |
| 1419 | 1415 | .cmpxchg => try sema.zirCmpxchg( block, extended), |
| 1420 | 1416 | .c_va_arg => try sema.zirCVaArg( block, extended), |
| 1421 | 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 | 2860 | sema.code.nullTerminatedString(str), |
| 2865 | 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 | 2864 | break :capture InternPool.CaptureValue.wrap(.{ .nav_val = nav }); |
| 2869 | 2865 | }, |
| 2870 | 2866 | .decl_ref => |str| capture: { |
| ... | ... | @@ -2874,7 +2870,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2874 | 2870 | sema.code.nullTerminatedString(str), |
| 2875 | 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 | 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 | 6925 | inst_data.get(sema.code), |
| 6930 | 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 | 6929 | return sema.analyzeNavRef(block, src, nav_index); |
| 6934 | 6930 | } |
| 6935 | 6931 | |
| ... | ... | @@ -6944,16 +6940,16 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6944 | 6940 | inst_data.get(sema.code), |
| 6945 | 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 | 6944 | return sema.analyzeNavVal(block, src, nav); |
| 6949 | 6945 | } |
| 6950 | 6946 | |
| 6951 | fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.Nav.Index { | |
| 6947 | fn lookupIdentifier(sema: *Sema, block: *Block, name: InternPool.NullTerminatedString) !InternPool.Nav.Index { | |
| 6952 | 6948 | const pt = sema.pt; |
| 6953 | 6949 | const zcu = pt.zcu; |
| 6954 | 6950 | var namespace = block.namespace; |
| 6955 | 6951 | while (true) { |
| 6956 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| { | |
| 6952 | if (try sema.lookupInNamespace(block, namespace, name)) |lookup| { | |
| 6957 | 6953 | assert(lookup.accessible); |
| 6958 | 6954 | return lookup.nav; |
| 6959 | 6955 | } |
| ... | ... | @@ -6962,15 +6958,12 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo |
| 6962 | 6958 | unreachable; // AstGen detects use of undeclared identifiers. |
| 6963 | 6959 | } |
| 6964 | 6960 | |
| 6965 | /// This looks up a member of a specific namespace. It is affected by `usingnamespace` but | |
| 6966 | /// only for ones in the specified namespace. | |
| 6961 | /// This looks up a member of a specific namespace. | |
| 6967 | 6962 | fn lookupInNamespace( |
| 6968 | 6963 | sema: *Sema, |
| 6969 | 6964 | block: *Block, |
| 6970 | src: LazySrcLoc, | |
| 6971 | 6965 | namespace_index: InternPool.NamespaceIndex, |
| 6972 | 6966 | ident_name: InternPool.NullTerminatedString, |
| 6973 | observe_usingnamespace: bool, | |
| 6974 | 6967 | ) CompileError!?struct { |
| 6975 | 6968 | nav: InternPool.Nav.Index, |
| 6976 | 6969 | /// If `false`, the declaration is in a different file and is not `pub`. |
| ... | ... | @@ -6979,7 +6972,6 @@ fn lookupInNamespace( |
| 6979 | 6972 | } { |
| 6980 | 6973 | const pt = sema.pt; |
| 6981 | 6974 | const zcu = pt.zcu; |
| 6982 | const ip = &zcu.intern_pool; | |
| 6983 | 6975 | |
| 6984 | 6976 | try pt.ensureNamespaceUpToDate(namespace_index); |
| 6985 | 6977 | |
| ... | ... | @@ -6996,75 +6988,7 @@ fn lookupInNamespace( |
| 6996 | 6988 | } }); |
| 6997 | 6989 | } |
| 6998 | 6990 | |
| 6999 | if (observe_usingnamespace and (namespace.pub_usingnamespace.items.len != 0 or namespace.priv_usingnamespace.items.len != 0)) { | |
| 7000 | const gpa = sema.gpa; | |
| 7001 | var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .empty; | |
| 7002 | defer checked_namespaces.deinit(gpa); | |
| 7003 | ||
| 7004 | // Keep track of name conflicts for error notes. | |
| 7005 | var candidates: std.ArrayListUnmanaged(InternPool.Nav.Index) = .empty; | |
| 7006 | defer candidates.deinit(gpa); | |
| 7007 | ||
| 7008 | try checked_namespaces.put(gpa, namespace, {}); | |
| 7009 | var check_i: usize = 0; | |
| 7010 | ||
| 7011 | while (check_i < checked_namespaces.count()) : (check_i += 1) { | |
| 7012 | const check_ns = checked_namespaces.keys()[check_i]; | |
| 7013 | const Pass = enum { @"pub", priv }; | |
| 7014 | for ([2]Pass{ .@"pub", .priv }) |pass| { | |
| 7015 | if (pass == .priv and src_file != check_ns.file_scope) { | |
| 7016 | continue; | |
| 7017 | } | |
| 7018 | ||
| 7019 | const decls, const usingnamespaces = switch (pass) { | |
| 7020 | .@"pub" => .{ &check_ns.pub_decls, &check_ns.pub_usingnamespace }, | |
| 7021 | .priv => .{ &check_ns.priv_decls, &check_ns.priv_usingnamespace }, | |
| 7022 | }; | |
| 7023 | ||
| 7024 | if (decls.getKeyAdapted(ident_name, adapter)) |nav_index| { | |
| 7025 | try candidates.append(gpa, nav_index); | |
| 7026 | } | |
| 7027 | ||
| 7028 | for (usingnamespaces.items) |sub_ns_nav| { | |
| 7029 | try sema.ensureNavResolved(block, src, sub_ns_nav, .fully); | |
| 7030 | const sub_ns_ty: Type = .fromInterned(ip.getNav(sub_ns_nav).status.fully_resolved.val); | |
| 7031 | const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu)); | |
| 7032 | try checked_namespaces.put(gpa, sub_ns, {}); | |
| 7033 | } | |
| 7034 | } | |
| 7035 | } | |
| 7036 | ||
| 7037 | ignore_self: { | |
| 7038 | const skip_nav = switch (sema.owner.unwrap()) { | |
| 7039 | .@"comptime", .type, .func, .memoized_state => break :ignore_self, | |
| 7040 | .nav_ty, .nav_val => |nav| nav, | |
| 7041 | }; | |
| 7042 | var i: usize = 0; | |
| 7043 | while (i < candidates.items.len) { | |
| 7044 | if (candidates.items[i] == skip_nav) { | |
| 7045 | _ = candidates.orderedRemove(i); | |
| 7046 | } else { | |
| 7047 | i += 1; | |
| 7048 | } | |
| 7049 | } | |
| 7050 | } | |
| 7051 | ||
| 7052 | switch (candidates.items.len) { | |
| 7053 | 0 => {}, | |
| 7054 | 1 => return .{ | |
| 7055 | .nav = candidates.items[0], | |
| 7056 | .accessible = true, | |
| 7057 | }, | |
| 7058 | else => return sema.failWithOwnedErrorMsg(block, msg: { | |
| 7059 | const msg = try sema.errMsg(src, "ambiguous reference", .{}); | |
| 7060 | errdefer msg.destroy(gpa); | |
| 7061 | for (candidates.items) |candidate| { | |
| 7062 | try sema.errNote(zcu.navSrcLoc(candidate), msg, "declared here", .{}); | |
| 7063 | } | |
| 7064 | break :msg msg; | |
| 7065 | }), | |
| 7066 | } | |
| 7067 | } else if (namespace.pub_decls.getKeyAdapted(ident_name, adapter)) |nav_index| { | |
| 6991 | if (namespace.pub_decls.getKeyAdapted(ident_name, adapter)) |nav_index| { | |
| 7068 | 6992 | return .{ |
| 7069 | 6993 | .nav = nav_index, |
| 7070 | 6994 | .accessible = true, |
| ... | ... | @@ -7653,10 +7577,6 @@ fn analyzeCall( |
| 7653 | 7577 | const ip = &zcu.intern_pool; |
| 7654 | 7578 | const arena = sema.arena; |
| 7655 | 7579 | |
| 7656 | if (modifier == .async_kw) { | |
| 7657 | return sema.failWithUseOfAsync(block, call_src); | |
| 7658 | } | |
| 7659 | ||
| 7660 | 7580 | const maybe_func_inst = try sema.funcDeclSrcInst(callee); |
| 7661 | 7581 | const func_ret_ty_src: LazySrcLoc = if (maybe_func_inst) |fn_decl_inst| .{ |
| 7662 | 7582 | .base_node_inst = fn_decl_inst, |
| ... | ... | @@ -8048,14 +7968,13 @@ fn analyzeCall( |
| 8048 | 7968 | } |
| 8049 | 7969 | |
| 8050 | 7970 | const call_tag: Air.Inst.Tag = switch (modifier) { |
| 8051 | .auto, .no_async => .call, | |
| 7971 | .auto, .no_suspend => .call, | |
| 8052 | 7972 | .never_tail => .call_never_tail, |
| 8053 | 7973 | .never_inline => .call_never_inline, |
| 8054 | 7974 | .always_tail => .call_always_tail, |
| 8055 | 7975 | |
| 8056 | 7976 | .always_inline, |
| 8057 | 7977 | .compile_time, |
| 8058 | .async_kw, | |
| 8059 | 7978 | => unreachable, |
| 8060 | 7979 | }; |
| 8061 | 7980 | |
| ... | ... | @@ -13955,7 +13874,6 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13955 | 13874 | const zcu = pt.zcu; |
| 13956 | 13875 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13957 | 13876 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13958 | const src = block.nodeOffset(inst_data.src_node); | |
| 13959 | 13877 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13960 | 13878 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13961 | 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 | 13882 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 13965 | 13883 | |
| 13966 | 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 | 13886 | if (lookup.accessible) { |
| 13969 | 13887 | return .bool_true; |
| 13970 | 13888 | } |
| ... | ... | @@ -17745,7 +17663,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17745 | 17663 | } }); |
| 17746 | 17664 | }; |
| 17747 | 17665 | |
| 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()); | |
| 17749 | 17667 | |
| 17750 | 17668 | const type_enum_ty = try sema.getBuiltinType(src, .@"Type.Enum"); |
| 17751 | 17669 | |
| ... | ... | @@ -17858,7 +17776,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17858 | 17776 | } }); |
| 17859 | 17777 | }; |
| 17860 | 17778 | |
| 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()); | |
| 17862 | 17780 | |
| 17863 | 17781 | const enum_tag_ty_val = try pt.intern(.{ .opt = .{ |
| 17864 | 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 | 17971 | } }); |
| 18054 | 17972 | }; |
| 18055 | 17973 | |
| 18056 | const decls_val = try sema.typeInfoDecls(block, src, ty.getNamespace(zcu)); | |
| 17974 | const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu)); | |
| 18057 | 17975 | |
| 18058 | 17976 | const backing_integer_val = try pt.intern(.{ .opt = .{ |
| 18059 | 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 | 18010 | const type_opaque_ty = try sema.getBuiltinType(src, .@"Type.Opaque"); |
| 18093 | 18011 | |
| 18094 | 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)); | |
| 18096 | 18014 | |
| 18097 | 18015 | const field_values = .{ |
| 18098 | 18016 | // decls: []const Declaration, |
| ... | ... | @@ -18114,7 +18032,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18114 | 18032 | |
| 18115 | 18033 | fn typeInfoDecls( |
| 18116 | 18034 | sema: *Sema, |
| 18117 | block: *Block, | |
| 18118 | 18035 | src: LazySrcLoc, |
| 18119 | 18036 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 18120 | 18037 | ) CompileError!InternPool.Index { |
| ... | ... | @@ -18130,7 +18047,7 @@ fn typeInfoDecls( |
| 18130 | 18047 | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa); |
| 18131 | 18048 | defer seen_namespaces.deinit(); |
| 18132 | 18049 | |
| 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); | |
| 18134 | 18051 | |
| 18135 | 18052 | const array_decl_ty = try pt.arrayType(.{ |
| 18136 | 18053 | .len = decl_vals.items.len, |
| ... | ... | @@ -18164,8 +18081,6 @@ fn typeInfoDecls( |
| 18164 | 18081 | |
| 18165 | 18082 | fn typeInfoNamespaceDecls( |
| 18166 | 18083 | sema: *Sema, |
| 18167 | block: *Block, | |
| 18168 | src: LazySrcLoc, | |
| 18169 | 18084 | opt_namespace_index: InternPool.OptionalNamespaceIndex, |
| 18170 | 18085 | declaration_ty: Type, |
| 18171 | 18086 | decl_vals: *std.ArrayList(InternPool.Index), |
| ... | ... | @@ -18221,15 +18136,6 @@ fn typeInfoNamespaceDecls( |
| 18221 | 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 | } |
| 18234 | 18140 | |
| 18235 | 18141 | fn 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 | 22039 | return sema.failWithUseOfAsync(block, src); |
| 22134 | 22040 | } |
| 22135 | 22041 | |
| 22136 | fn 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 | ||
| 22142 | 22042 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22143 | 22043 | const pt = sema.pt; |
| 22144 | 22044 | const zcu = pt.zcu; |
| ... | ... | @@ -24776,14 +24676,14 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24776 | 24676 | var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier); |
| 24777 | 24677 | switch (modifier) { |
| 24778 | 24678 | // These can be upgraded to comptime or nosuspend calls. |
| 24779 | .auto, .never_tail, .no_async => { | |
| 24679 | .auto, .never_tail, .no_suspend => { | |
| 24780 | 24680 | if (block.isComptime()) { |
| 24781 | 24681 | if (modifier == .never_tail) { |
| 24782 | 24682 | return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{}); |
| 24783 | 24683 | } |
| 24784 | 24684 | modifier = .compile_time; |
| 24785 | 24685 | } else if (extra.flags.is_nosuspend) { |
| 24786 | modifier = .no_async; | |
| 24686 | modifier = .no_suspend; | |
| 24787 | 24687 | } |
| 24788 | 24688 | }, |
| 24789 | 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 | 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 | 24704 | .never_inline => { |
| 24813 | 24705 | if (block.isComptime()) { |
| 24814 | 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 | 25689 | }); |
| 25798 | 25690 | } |
| 25799 | 25691 | |
| 25800 | fn 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 | ||
| 25806 | 25692 | fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 25807 | 25693 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 25808 | 25694 | const src = block.nodeOffset(inst_data.src_node); |
| 25809 | 25695 | return sema.failWithUseOfAsync(block, src); |
| 25810 | 25696 | } |
| 25811 | 25697 | |
| 25812 | fn 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 | ||
| 25823 | fn 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 | ||
| 25834 | 25698 | fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 25835 | 25699 | const tracy = trace(@src()); |
| 25836 | 25700 | defer tracy.end(); |
| ... | ... | @@ -26738,7 +26602,7 @@ fn explainWhyTypeIsNotExtern( |
| 26738 | 26602 | } |
| 26739 | 26603 | switch (ty.fnCallingConvention(zcu)) { |
| 26740 | 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 | 26606 | .@"inline" => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}), |
| 26743 | 26607 | else => return, |
| 26744 | 26608 | } |
| ... | ... | @@ -27760,7 +27624,7 @@ fn namespaceLookup( |
| 27760 | 27624 | const pt = sema.pt; |
| 27761 | 27625 | const zcu = pt.zcu; |
| 27762 | 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 | 27628 | if (!lookup.accessible) { |
| 27765 | 27629 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 27766 | 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 | 382 | } |
| 383 | 383 | } |
| 384 | 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 | 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 | 792 | pub_decls: std.ArrayHashMapUnmanaged(InternPool.Nav.Index, void, NavNameContext, true) = .empty, |
| 793 | 793 | /// Members of the namespace which are *not* marked `pub`. |
| 794 | 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 | 795 | /// All `comptime` declarations in this namespace. We store these purely so that incremental |
| 800 | 796 | /// compilation can re-use the existing `ComptimeUnit`s when a namespace changes. |
| 801 | 797 | comptime_decls: std.ArrayListUnmanaged(InternPool.ComptimeUnit.Id) = .empty, |
| ... | ... | @@ -1303,9 +1299,6 @@ pub const SrcLoc = struct { |
| 1303 | 1299 | .simple_var_decl, |
| 1304 | 1300 | .aligned_var_decl, |
| 1305 | 1301 | => tree.fullVarDecl(node).?, |
| 1306 | .@"usingnamespace" => { | |
| 1307 | return tree.nodeToSpan(tree.nodeData(node).node); | |
| 1308 | }, | |
| 1309 | 1302 | else => unreachable, |
| 1310 | 1303 | }; |
| 1311 | 1304 | if (full.ast.type_node.unwrap()) |type_node| { |
| ... | ... | @@ -1443,12 +1436,8 @@ pub const SrcLoc = struct { |
| 1443 | 1436 | .field_access => tree.nodeData(node).node_and_token[1], |
| 1444 | 1437 | .call_one, |
| 1445 | 1438 | .call_one_comma, |
| 1446 | .async_call_one, | |
| 1447 | .async_call_one_comma, | |
| 1448 | 1439 | .call, |
| 1449 | 1440 | .call_comma, |
| 1450 | .async_call, | |
| 1451 | .async_call_comma, | |
| 1452 | 1441 | => blk: { |
| 1453 | 1442 | const full = tree.fullCall(&buf, node).?; |
| 1454 | 1443 | break :blk tree.lastToken(full.ast.fn_expr); |
| ... | ... | @@ -3395,9 +3384,6 @@ pub fn mapOldZirToNew( |
| 3395 | 3384 | // All comptime declarations, in order, for a best-effort match. |
| 3396 | 3385 | var comptime_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty; |
| 3397 | 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); | |
| 3401 | 3387 | |
| 3402 | 3388 | { |
| 3403 | 3389 | var old_decl_it = old_zir.declIterator(match_item.old_inst); |
| ... | ... | @@ -3405,7 +3391,6 @@ pub fn mapOldZirToNew( |
| 3405 | 3391 | const old_decl = old_zir.getDeclaration(old_decl_inst); |
| 3406 | 3392 | switch (old_decl.kind) { |
| 3407 | 3393 | .@"comptime" => try comptime_decls.append(gpa, old_decl_inst), |
| 3408 | .@"usingnamespace" => try usingnamespace_decls.append(gpa, old_decl_inst), | |
| 3409 | 3394 | .unnamed_test => try unnamed_tests.append(gpa, old_decl_inst), |
| 3410 | 3395 | .@"test" => try named_tests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst), |
| 3411 | 3396 | .decltest => try named_decltests.put(gpa, old_zir.nullTerminatedString(old_decl.name), old_decl_inst), |
| ... | ... | @@ -3416,7 +3401,6 @@ pub fn mapOldZirToNew( |
| 3416 | 3401 | |
| 3417 | 3402 | var unnamed_test_idx: u32 = 0; |
| 3418 | 3403 | var comptime_decl_idx: u32 = 0; |
| 3419 | var usingnamespace_decl_idx: u32 = 0; | |
| 3420 | 3404 | |
| 3421 | 3405 | var new_decl_it = new_zir.declIterator(match_item.new_inst); |
| 3422 | 3406 | while (new_decl_it.next()) |new_decl_inst| { |
| ... | ... | @@ -3426,7 +3410,6 @@ pub fn mapOldZirToNew( |
| 3426 | 3410 | // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name. |
| 3427 | 3411 | // * For unnamed tests, we match based on order. |
| 3428 | 3412 | // * For comptime blocks, we match based on order. |
| 3429 | // * For usingnamespace decls, we match based on order. | |
| 3430 | 3413 | // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`. |
| 3431 | 3414 | const old_decl_inst = switch (new_decl.kind) { |
| 3432 | 3415 | .@"comptime" => inst: { |
| ... | ... | @@ -3434,11 +3417,6 @@ pub fn mapOldZirToNew( |
| 3434 | 3417 | defer comptime_decl_idx += 1; |
| 3435 | 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 | 3420 | .unnamed_test => inst: { |
| 3443 | 3421 | if (unnamed_test_idx == unnamed_tests.items.len) continue; |
| 3444 | 3422 | defer unnamed_test_idx += 1; |
| ... | ... | @@ -4147,7 +4125,6 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv |
| 4147 | 4125 | if (!comp.config.is_test or file.mod != zcu.main_mod) continue; |
| 4148 | 4126 | |
| 4149 | 4127 | const want_analysis = switch (decl.kind) { |
| 4150 | .@"usingnamespace" => unreachable, | |
| 4151 | 4128 | .@"const", .@"var" => unreachable, |
| 4152 | 4129 | .@"comptime" => unreachable, |
| 4153 | 4130 | .unnamed_test => true, |
| ... | ... | @@ -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 | 4185 | continue; |
| 4219 | 4186 | } |
| 4220 | 4187 | if (unit_queue.pop()) |kv| { |
| ... | ... | @@ -4457,7 +4424,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu |
| 4457 | 4424 | const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm); |
| 4458 | 4425 | switch (cc) { |
| 4459 | 4426 | .auto, .@"inline" => return .ok, |
| 4460 | .@"async" => return .{ .bad_backend = backend }, // nothing supports async currently | |
| 4427 | .async => return .{ .bad_backend = backend }, // nothing supports async currently | |
| 4461 | 4428 | .naked => {}, // depends only on backend |
| 4462 | 4429 | else => for (cc.archs()) |allowed_arch| { |
| 4463 | 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 | 1111 | defer block.instructions.deinit(gpa); |
| 1112 | 1112 | |
| 1113 | 1113 | const zir_decl = zir.getDeclaration(inst_resolved.inst); |
| 1114 | assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace")); | |
| 1115 | 1114 | |
| 1116 | 1115 | const ty_src = block.src(.{ .node_offset_var_decl_ty = .zero }); |
| 1117 | 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 | 1159 | assert(nav_ty.zigTypeTag(zcu) == .@"fn"); |
| 1161 | 1160 | break :is_const true; |
| 1162 | 1161 | }, |
| 1163 | .@"usingnamespace", .@"const" => true, | |
| 1162 | .@"const" => true, | |
| 1164 | 1163 | .@"var" => { |
| 1165 | 1164 | try sema.validateVarType( |
| 1166 | 1165 | &block, |
| ... | ... | @@ -1240,26 +1239,6 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr |
| 1240 | 1239 | // this resolves the type `type` (which needs no resolution), not the struct itself. |
| 1241 | 1240 | try nav_ty.resolveLayout(pt); |
| 1242 | 1241 | |
| 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 | 1242 | const queue_linker_work, const is_owned_fn = switch (ip.indexToKey(nav_val.toIntern())) { |
| 1264 | 1243 | .func => |f| .{ true, f.owner_nav == nav_id }, // note that this lets function aliases reach codegen |
| 1265 | 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 | 1443 | defer _ = zcu.analysis_in_progress.swapRemove(anal_unit); |
| 1465 | 1444 | |
| 1466 | 1445 | const zir_decl = zir.getDeclaration(inst_resolved.inst); |
| 1467 | assert(old_nav.is_usingnamespace == (zir_decl.kind == .@"usingnamespace")); | |
| 1468 | 1446 | const type_body = zir_decl.type_body.?; |
| 1469 | 1447 | |
| 1470 | 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 | 1505 | |
| 1528 | 1506 | const is_const = switch (zir_decl.kind) { |
| 1529 | 1507 | .@"comptime" => unreachable, |
| 1530 | .unnamed_test, .@"test", .decltest, .@"usingnamespace", .@"const" => true, | |
| 1508 | .unnamed_test, .@"test", .decltest, .@"const" => true, | |
| 1531 | 1509 | .@"var" => false, |
| 1532 | 1510 | }; |
| 1533 | 1511 | |
| ... | ... | @@ -2541,7 +2519,6 @@ pub fn scanNamespace( |
| 2541 | 2519 | |
| 2542 | 2520 | try existing_by_inst.ensureTotalCapacity(gpa, @intCast( |
| 2543 | 2521 | namespace.pub_decls.count() + namespace.priv_decls.count() + |
| 2544 | namespace.pub_usingnamespace.items.len + namespace.priv_usingnamespace.items.len + | |
| 2545 | 2522 | namespace.comptime_decls.items.len + |
| 2546 | 2523 | namespace.test_decls.items.len, |
| 2547 | 2524 | )); |
| ... | ... | @@ -2554,14 +2531,6 @@ pub fn scanNamespace( |
| 2554 | 2531 | const zir_index = ip.getNav(nav).analysis.?.zir_index; |
| 2555 | 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 | 2534 | for (namespace.comptime_decls.items) |cu| { |
| 2566 | 2535 | const zir_index = ip.getComptimeUnit(cu).zir_index; |
| 2567 | 2536 | existing_by_inst.putAssumeCapacityNoClobber(zir_index, .wrap(.{ .@"comptime" = cu })); |
| ... | ... | @@ -2578,8 +2547,6 @@ pub fn scanNamespace( |
| 2578 | 2547 | |
| 2579 | 2548 | namespace.pub_decls.clearRetainingCapacity(); |
| 2580 | 2549 | namespace.priv_decls.clearRetainingCapacity(); |
| 2581 | namespace.pub_usingnamespace.clearRetainingCapacity(); | |
| 2582 | namespace.priv_usingnamespace.clearRetainingCapacity(); | |
| 2583 | 2550 | namespace.comptime_decls.clearRetainingCapacity(); |
| 2584 | 2551 | namespace.test_decls.clearRetainingCapacity(); |
| 2585 | 2552 | |
| ... | ... | @@ -2607,7 +2574,6 @@ const ScanDeclIter = struct { |
| 2607 | 2574 | /// Decl scanning is run in two passes, so that we can detect when a generated |
| 2608 | 2575 | /// name would clash with an explicit name and use a different one. |
| 2609 | 2576 | pass: enum { named, unnamed }, |
| 2610 | usingnamespace_index: usize = 0, | |
| 2611 | 2577 | unnamed_test_index: usize = 0, |
| 2612 | 2578 | |
| 2613 | 2579 | fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString { |
| ... | ... | @@ -2646,12 +2612,6 @@ const ScanDeclIter = struct { |
| 2646 | 2612 | if (iter.pass != .unnamed) return; |
| 2647 | 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 | 2615 | .unnamed_test => name: { |
| 2656 | 2616 | if (iter.pass != .unnamed) return; |
| 2657 | 2617 | const i = iter.unnamed_test_index; |
| ... | ... | @@ -2710,7 +2670,7 @@ const ScanDeclIter = struct { |
| 2710 | 2670 | const name = maybe_name.unwrap().?; |
| 2711 | 2671 | const fqn = try namespace.internFullyQualifiedName(ip, gpa, pt.tid, name); |
| 2712 | 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 | 2674 | if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newNav(zcu, nav); |
| 2715 | 2675 | break :nav nav; |
| 2716 | 2676 | }; |
| ... | ... | @@ -2722,17 +2682,6 @@ const ScanDeclIter = struct { |
| 2722 | 2682 | |
| 2723 | 2683 | const want_analysis = switch (decl.kind) { |
| 2724 | 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 | 2685 | .unnamed_test, .@"test", .decltest => a: { |
| 2737 | 2686 | const is_named = decl.kind != .unnamed_test; |
| 2738 | 2687 | try namespace.test_decls.append(gpa, nav); |
src/codegen/llvm.zig+7-7| ... | ... | @@ -2758,7 +2758,7 @@ pub const Object = struct { |
| 2758 | 2758 | llvm_arg_i += 1; |
| 2759 | 2759 | } |
| 2760 | 2760 | |
| 2761 | if (fn_info.cc == .@"async") { | |
| 2761 | if (fn_info.cc == .async) { | |
| 2762 | 2762 | @panic("TODO: LLVM backend lower async function"); |
| 2763 | 2763 | } |
| 2764 | 2764 | |
| ... | ... | @@ -2910,7 +2910,7 @@ pub const Object = struct { |
| 2910 | 2910 | try attributes.addFnAttr(.nounwind, &o.builder); |
| 2911 | 2911 | if (owner_mod.unwind_tables != .none) { |
| 2912 | 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 | 2914 | &o.builder, |
| 2915 | 2915 | ); |
| 2916 | 2916 | } |
| ... | ... | @@ -5273,7 +5273,7 @@ pub const FuncGen = struct { |
| 5273 | 5273 | switch (modifier) { |
| 5274 | 5274 | .auto, .always_tail => {}, |
| 5275 | 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 | } |
| 5278 | 5278 | |
| 5279 | 5279 | const ret_ptr = if (!sret) null else blk: { |
| ... | ... | @@ -5488,7 +5488,7 @@ pub const FuncGen = struct { |
| 5488 | 5488 | .auto, .never_inline => .normal, |
| 5489 | 5489 | .never_tail => .notail, |
| 5490 | 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 | 5493 | toLlvmCallConvTag(fn_info.cc, target).?, |
| 5494 | 5494 | try attributes.finish(&o.builder), |
| ... | ... | @@ -11861,7 +11861,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s |
| 11861 | 11861 | } |
| 11862 | 11862 | return switch (cc_tag) { |
| 11863 | 11863 | .@"inline" => unreachable, |
| 11864 | .auto, .@"async" => .fastcc, | |
| 11864 | .auto, .async => .fastcc, | |
| 11865 | 11865 | .naked => .ccc, |
| 11866 | 11866 | .x86_64_sysv => .x86_64_sysvcc, |
| 11867 | 11867 | .x86_64_win => .win64cc, |
| ... | ... | @@ -12369,7 +12369,7 @@ const ParamTypeIterator = struct { |
| 12369 | 12369 | return .byval; |
| 12370 | 12370 | } |
| 12371 | 12371 | }, |
| 12372 | .@"async" => { | |
| 12372 | .async => { | |
| 12373 | 12373 | @panic("TODO implement async function lowering in the LLVM backend"); |
| 12374 | 12374 | }, |
| 12375 | 12375 | .x86_64_sysv => return it.nextSystemV(ty), |
| ... | ... | @@ -12624,7 +12624,7 @@ fn ccAbiPromoteInt( |
| 12624 | 12624 | ) ?std.builtin.Signedness { |
| 12625 | 12625 | const target = zcu.getTarget(); |
| 12626 | 12626 | switch (cc) { |
| 12627 | .auto, .@"inline", .@"async" => return null, | |
| 12627 | .auto, .@"inline", .async => return null, | |
| 12628 | 12628 | else => {}, |
| 12629 | 12629 | } |
| 12630 | 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 | 325 | // See the `-fno-exceptions` logic for WASI. |
| 326 | 326 | // The old 32-bit x86 variant of SEH doesn't use tables. |
| 327 | 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; | |
| 329 | 329 | |
| 330 | 330 | const config = Compilation.Config.resolve(.{ |
| 331 | 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 | 48 | const optimize_mode = comp.compilerRtOptMode(); |
| 49 | 49 | const strip = comp.compilerRtStrip(); |
| 50 | 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 | 52 | const link_libcpp = target.os.tag.isDarwin(); |
| 53 | 53 | |
| 54 | 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 | 29 | const output_mode = .Lib; |
| 30 | 30 | const target = &comp.root_mod.resolved_target.result; |
| 31 | 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 | 33 | const config = Compilation.Config.resolve(.{ |
| 34 | 34 | .output_mode = output_mode, |
| 35 | 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 | 29 | const target = comp.getTarget(); |
| 30 | 30 | |
| 31 | 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; | |
| 33 | 33 | |
| 34 | 34 | switch (crt_file) { |
| 35 | 35 | .crt2_o => { |
src/link/Dwarf.zig+3-3| ... | ... | @@ -2489,7 +2489,7 @@ fn initWipNavInner( |
| 2489 | 2489 | const addr: Loc = .{ .addr_reloc = sym_index }; |
| 2490 | 2490 | const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr; |
| 2491 | 2491 | switch (decl.kind) { |
| 2492 | .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable, | |
| 2492 | .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable, | |
| 2493 | 2493 | .@"const" => { |
| 2494 | 2494 | const const_ty_reloc_index = try wip_nav.refForward(); |
| 2495 | 2495 | try wip_nav.infoExprLoc(loc); |
| ... | ... | @@ -2775,7 +2775,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2775 | 2775 | |
| 2776 | 2776 | const is_test = switch (decl.kind) { |
| 2777 | 2777 | .unnamed_test, .@"test", .decltest => true, |
| 2778 | .@"comptime", .@"usingnamespace", .@"const", .@"var" => false, | |
| 2778 | .@"comptime", .@"const", .@"var" => false, | |
| 2779 | 2779 | }; |
| 2780 | 2780 | if (is_test) { |
| 2781 | 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 | 3596 | // For better or worse, we try to match what Clang emits. |
| 3597 | 3597 | break :cc switch (func_type.cc) { |
| 3598 | 3598 | .@"inline" => .nocall, |
| 3599 | .@"async", .auto, .naked => .normal, | |
| 3599 | .async, .auto, .naked => .normal, | |
| 3600 | 3600 | .x86_64_sysv => .LLVM_X86_64SysV, |
| 3601 | 3601 | .x86_64_win => .LLVM_Win64, |
| 3602 | 3602 | .x86_64_regcall_v3_sysv => .LLVM_X86RegCall, |
src/main.zig+6-6| ... | ... | @@ -1416,7 +1416,7 @@ fn buildOutputType( |
| 1416 | 1416 | } else if (mem.eql(u8, arg, "-funwind-tables")) { |
| 1417 | 1417 | mod_opts.unwind_tables = .sync; |
| 1418 | 1418 | } else if (mem.eql(u8, arg, "-fasync-unwind-tables")) { |
| 1419 | mod_opts.unwind_tables = .@"async"; | |
| 1419 | mod_opts.unwind_tables = .async; | |
| 1420 | 1420 | } else if (mem.eql(u8, arg, "-fno-unwind-tables")) { |
| 1421 | 1421 | mod_opts.unwind_tables = .none; |
| 1422 | 1422 | } else if (mem.eql(u8, arg, "-fstack-check")) { |
| ... | ... | @@ -2035,15 +2035,15 @@ fn buildOutputType( |
| 2035 | 2035 | .none => { |
| 2036 | 2036 | mod_opts.unwind_tables = .sync; |
| 2037 | 2037 | }, |
| 2038 | .sync, .@"async" => {}, | |
| 2038 | .sync, .async => {}, | |
| 2039 | 2039 | } else { |
| 2040 | 2040 | mod_opts.unwind_tables = .sync; |
| 2041 | 2041 | }, |
| 2042 | 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 | 2044 | .no_asynchronous_unwind_tables => if (mod_opts.unwind_tables) |uwt| switch (uwt) { |
| 2045 | 2045 | .none, .sync => {}, |
| 2046 | .@"async" => { | |
| 2046 | .async => { | |
| 2047 | 2047 | mod_opts.unwind_tables = .sync; |
| 2048 | 2048 | }, |
| 2049 | 2049 | } else { |
| ... | ... | @@ -2951,7 +2951,7 @@ fn buildOutputType( |
| 2951 | 2951 | create_module.opts.any_fuzz = true; |
| 2952 | 2952 | if (mod_opts.unwind_tables) |uwt| switch (uwt) { |
| 2953 | 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 | 2956 | if (mod_opts.strip == false) |
| 2957 | 2957 | create_module.opts.any_non_stripped = true; |
| ... | ... | @@ -7413,7 +7413,7 @@ fn handleModArg( |
| 7413 | 7413 | create_module.opts.any_fuzz = true; |
| 7414 | 7414 | if (mod_opts.unwind_tables) |uwt| switch (uwt) { |
| 7415 | 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 | 7418 | if (mod_opts.strip == false) |
| 7419 | 7419 | create_module.opts.any_non_stripped = true; |
src/print_zir.zig-18| ... | ... | @@ -261,14 +261,12 @@ const Writer = struct { |
| 261 | 261 | .tag_name, |
| 262 | 262 | .type_name, |
| 263 | 263 | .frame_type, |
| 264 | .frame_size, | |
| 265 | 264 | .clz, |
| 266 | 265 | .ctz, |
| 267 | 266 | .pop_count, |
| 268 | 267 | .byte_swap, |
| 269 | 268 | .bit_reverse, |
| 270 | 269 | .@"resume", |
| 271 | .@"await", | |
| 272 | 270 | .make_ptr_const, |
| 273 | 271 | .validate_deref, |
| 274 | 272 | .validate_const, |
| ... | ... | @@ -565,7 +563,6 @@ const Writer = struct { |
| 565 | 563 | |
| 566 | 564 | .tuple_decl => try self.writeTupleDecl(stream, extended), |
| 567 | 565 | |
| 568 | .await_nosuspend, | |
| 569 | 566 | .c_undef, |
| 570 | 567 | .c_include, |
| 571 | 568 | .set_float_mode, |
| ... | ... | @@ -611,7 +608,6 @@ const Writer = struct { |
| 611 | 608 | try self.writeSrcNode(stream, inst_data.node); |
| 612 | 609 | }, |
| 613 | 610 | |
| 614 | .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended), | |
| 615 | 611 | .cmpxchg => try self.writeCmpxchg(stream, extended), |
| 616 | 612 | .ptr_cast_full => try self.writePtrCastFull(stream, extended), |
| 617 | 613 | .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended), |
| ... | ... | @@ -932,19 +928,6 @@ const Writer = struct { |
| 932 | 928 | try self.writeSrcNode(stream, extra.src_node); |
| 933 | 929 | } |
| 934 | 930 | |
| 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 | 931 | fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 949 | 932 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; |
| 950 | 933 | const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| ... | ... | @@ -2605,7 +2588,6 @@ const Writer = struct { |
| 2605 | 2588 | } |
| 2606 | 2589 | switch (decl.kind) { |
| 2607 | 2590 | .@"comptime" => try stream.writeAll("comptime"), |
| 2608 | .@"usingnamespace" => try stream.writeAll("usingnamespace"), | |
| 2609 | 2591 | .unnamed_test => try stream.writeAll("test"), |
| 2610 | 2592 | .@"test", .decltest, .@"const", .@"var" => { |
| 2611 | 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 | 483 | pub fn defaultUnwindTables(target: *const std.Target, libunwind: bool, libtsan: bool) std.builtin.UnwindTables { |
| 484 | 484 | if (target.os.tag == .windows) { |
| 485 | 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"; | |
| 489 | if (libunwind) return .@"async"; | |
| 490 | if (libtsan) return .@"async"; | |
| 491 | if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .@"async"; | |
| 488 | if (target.os.tag.isDarwin()) return .async; | |
| 489 | if (libunwind) return .async; | |
| 490 | if (libtsan) return .async; | |
| 491 | if (std.debug.Dwarf.abi.supportsUnwinding(target)) return .async; | |
| 492 | 492 | return .none; |
| 493 | 493 | } |
| 494 | 494 | |
| ... | ... | @@ -815,7 +815,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 { |
| 815 | 815 | |
| 816 | 816 | pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool { |
| 817 | 817 | return switch (cc) { |
| 818 | .auto, .@"async", .@"inline" => true, | |
| 818 | .auto, .async, .@"inline" => true, | |
| 819 | 819 | // For now we want to authorize PTX kernel to use zig objects, even if |
| 820 | 820 | // we end up exposing the ABI. The goal is to experiment with more |
| 821 | 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 | 5 | _ = @import("behavior/align.zig"); |
| 6 | 6 | _ = @import("behavior/alignof.zig"); |
| 7 | 7 | _ = @import("behavior/array.zig"); |
| 8 | _ = @import("behavior/async_fn.zig"); | |
| 9 | 8 | _ = @import("behavior/atomics.zig"); |
| 10 | _ = @import("behavior/await_struct.zig"); | |
| 11 | 9 | _ = @import("behavior/basic.zig"); |
| 12 | 10 | _ = @import("behavior/bit_shifting.zig"); |
| 13 | 11 | _ = @import("behavior/bitcast.zig"); |
| ... | ... | @@ -103,7 +101,6 @@ test { |
| 103 | 101 | _ = @import("behavior/underscore.zig"); |
| 104 | 102 | _ = @import("behavior/union.zig"); |
| 105 | 103 | _ = @import("behavior/union_with_members.zig"); |
| 106 | _ = @import("behavior/usingnamespace.zig"); | |
| 107 | 104 | _ = @import("behavior/var_args.zig"); |
| 108 | 105 | // https://github.com/llvm/llvm-project/issues/118879 |
| 109 | 106 | // https://github.com/llvm/llvm-project/issues/134659 |
test/behavior/align.zig-24| ... | ... | @@ -425,30 +425,6 @@ test "struct field explicit alignment" { |
| 425 | 425 | try expect(@intFromPtr(&node.massive_byte) % 64 == 0); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | test "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 | ||
| 452 | 428 | test "align(N) on functions" { |
| 453 | 429 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 454 | 430 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
test/behavior/async_fn.zig deleted-1911| ... | ... | @@ -1,1911 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const assert = std.debug.assert; | |
| 4 | const expect = std.testing.expect; | |
| 5 | const expectEqual = std.testing.expectEqual; | |
| 6 | const expectEqualStrings = std.testing.expectEqualStrings; | |
| 7 | const expectError = std.testing.expectError; | |
| 8 | ||
| 9 | var global_x: i32 = 1; | |
| 10 | ||
| 11 | test "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 | } | |
| 24 | fn simpleAsyncFn() void { | |
| 25 | global_x += 1; | |
| 26 | suspend {} | |
| 27 | global_x += 1; | |
| 28 | suspend {} | |
| 29 | global_x += 1; | |
| 30 | } | |
| 31 | ||
| 32 | var global_y: i32 = 1; | |
| 33 | ||
| 34 | test "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 | } | |
| 43 | fn simpleAsyncFnWithArg(delta: i32) void { | |
| 44 | global_y += delta; | |
| 45 | suspend {} | |
| 46 | global_y += delta; | |
| 47 | } | |
| 48 | ||
| 49 | test "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 | ||
| 71 | test "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 | ||
| 103 | test "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 | ||
| 130 | test "@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 | ||
| 166 | test "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 | ||
| 210 | test "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 | ||
| 221 | var a_promise: anyframe = undefined; | |
| 222 | var global_result = false; | |
| 223 | fn 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 | ||
| 236 | var await_a_promise: anyframe = undefined; | |
| 237 | var await_final_result: i32 = 0; | |
| 238 | ||
| 239 | test "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 | } | |
| 252 | fn 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 | } | |
| 259 | fn 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 | ||
| 269 | var await_points = [_]u8{0} ** "abcdefghi".len; | |
| 270 | var await_seq_index: usize = 0; | |
| 271 | ||
| 272 | fn await_seq(c: u8) void { | |
| 273 | await_points[await_seq_index] = c; | |
| 274 | await_seq_index += 1; | |
| 275 | } | |
| 276 | ||
| 277 | var early_final_result: i32 = 0; | |
| 278 | ||
| 279 | test "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 | } | |
| 290 | fn 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 | } | |
| 297 | fn early_another() callconv(.@"async") i32 { | |
| 298 | early_seq('c'); | |
| 299 | return 1234; | |
| 300 | } | |
| 301 | ||
| 302 | var early_points = [_]u8{0} ** "abcdef".len; | |
| 303 | var early_seq_index: usize = 0; | |
| 304 | ||
| 305 | fn early_seq(c: u8) void { | |
| 306 | early_points[early_seq_index] = c; | |
| 307 | early_seq_index += 1; | |
| 308 | } | |
| 309 | ||
| 310 | test "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 | ||
| 326 | test "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 | ||
| 346 | fn doTheAwait(f: anyframe->void) void { | |
| 347 | await f; | |
| 348 | } | |
| 349 | fn simpleAsyncFn2(y: *i32) callconv(.@"async") void { | |
| 350 | defer y.* += 2; | |
| 351 | y.* += 1; | |
| 352 | suspend {} | |
| 353 | } | |
| 354 | ||
| 355 | test "@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 | ||
| 383 | test "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 | ||
| 417 | test "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 | ||
| 427 | test "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 | ||
| 437 | fn 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 | } | |
| 444 | fn suspendThenFail() callconv(.@"async") anyerror!void { | |
| 445 | suspend {} | |
| 446 | return error.Fail; | |
| 447 | } | |
| 448 | fn 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 | ||
| 460 | test "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 | } | |
| 469 | fn 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 | ||
| 478 | test "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 | ||
| 505 | test "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 | ||
| 549 | test "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 | ||
| 578 | test "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 | ||
| 614 | test "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 | ||
| 638 | test "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 | ||
| 664 | test "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 | ||
| 697 | test "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 | ||
| 731 | test "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 | ||
| 746 | fn 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 | ||
| 829 | test "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 | ||
| 844 | test "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 | } | |
| 850 | fn simpleNothing() void { | |
| 851 | var x: i32 = 1234; | |
| 852 | _ = &x; | |
| 853 | } | |
| 854 | ||
| 855 | test "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 | ||
| 878 | test "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 | ||
| 895 | test "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 | ||
| 943 | test "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 | ||
| 974 | test "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 | ||
| 1004 | test "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 | ||
| 1017 | test "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 | ||
| 1025 | fn 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 | ||
| 1082 | test "@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 | ||
| 1114 | test "@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 | ||
| 1131 | test "@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 | ||
| 1162 | test "@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 | ||
| 1176 | test "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 | ||
| 1204 | test "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 | ||
| 1243 | test "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 | ||
| 1262 | test "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 | ||
| 1281 | test "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 | ||
| 1302 | test "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 | ||
| 1322 | test "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 | ||
| 1351 | test "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 | ||
| 1391 | test "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 | ||
| 1417 | test "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 | ||
| 1451 | test "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 | ||
| 1490 | test "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 | ||
| 1515 | test "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 | ||
| 1539 | test "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 | ||
| 1565 | test "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 | ||
| 1590 | test "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 | ||
| 1617 | test "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 | ||
| 1645 | test "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 | ||
| 1688 | test "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 | ||
| 1720 | test "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 | ||
| 1744 | test "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 | ||
| 1763 | test "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 | ||
| 1807 | test "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 | ||
| 1832 | test "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 | ||
| 1851 | test "@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 | ||
| 1888 | test "@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 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const expect = std.testing.expect; | |
| 4 | ||
| 5 | const Foo = struct { | |
| 6 | x: i32, | |
| 7 | }; | |
| 8 | ||
| 9 | var await_a_promise: anyframe = undefined; | |
| 10 | var await_final_result = Foo{ .x = 0 }; | |
| 11 | ||
| 12 | test "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 | } | |
| 24 | fn 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 | } | |
| 31 | fn 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 | ||
| 41 | var await_points = [_]u8{0} ** "abcdefghi".len; | |
| 42 | var await_seq_index: usize = 0; | |
| 43 | ||
| 44 | fn 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 | 1107 | try expect(S.foo(1) == 1); |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | test "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 | ||
| 1131 | 1110 | test "pointer to zero sized global is mutable" { |
| 1132 | 1111 | const S = struct { |
| 1133 | 1112 | const Thing = struct {}; |
test/behavior/call.zig+3-26| ... | ... | @@ -37,7 +37,7 @@ test "basic invocations" { |
| 37 | 37 | comptime { |
| 38 | 38 | // comptime calls with supported modifiers |
| 39 | 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 | 41 | try expect(@call(.always_tail, foo, .{4}) == 1234); |
| 42 | 42 | try expect(@call(.always_inline, foo, .{5}) == 1234); |
| 43 | 43 | } |
| ... | ... | @@ -45,7 +45,7 @@ test "basic invocations" { |
| 45 | 45 | const result = @call(.compile_time, foo, .{6}) == 1234; |
| 46 | 46 | comptime assert(result); |
| 47 | 47 | // 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 | 49 | try expect(@call(.never_tail, foo, .{8}) == 1234); |
| 50 | 50 | try expect(@call(.never_inline, foo, .{9}) == 1234); |
| 51 | 51 | // CBE does not support attributes on runtime functions |
| ... | ... | @@ -53,7 +53,7 @@ test "basic invocations" { |
| 53 | 53 | // runtime calls of non comptime-known function |
| 54 | 54 | var alias_foo = &foo; |
| 55 | 55 | _ = &alias_foo; |
| 56 | try expect(@call(.no_async, alias_foo, .{10}) == 1234); | |
| 56 | try expect(@call(.no_suspend, alias_foo, .{10}) == 1234); | |
| 57 | 57 | try expect(@call(.never_tail, alias_foo, .{11}) == 1234); |
| 58 | 58 | try expect(@call(.never_inline, alias_foo, .{12}) == 1234); |
| 59 | 59 | } |
| ... | ... | @@ -507,29 +507,6 @@ test "call inline fn through pointer" { |
| 507 | 507 | try f(123); |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | test "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 | ||
| 533 | 510 | test "call function in comptime field" { |
| 534 | 511 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 535 | 512 |
test/behavior/import.zig-10| ... | ... | @@ -18,16 +18,6 @@ test "importing the same thing gives the same import" { |
| 18 | 18 | try expect(@import("std") == @import("std")); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | test "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 | ||
| 31 | 21 | test "import empty file" { |
| 32 | 22 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 33 | 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 | 236 | try expect(s.do()); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | test "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 | ||
| 250 | 239 | test "struct field init with catch" { |
| 251 | 240 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 252 | 241 | 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 | 592 | try expect(info.fields[1].is_comptime); |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | test "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 | ||
| 613 | 595 | test "value from struct @typeInfo default_value_ptr can be loaded at comptime" { |
| 614 | 596 | comptime { |
| 615 | 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 | 599 | } |
| 618 | 600 | } |
| 619 | 601 | |
| 620 | test "@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 | ||
| 644 | test "@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 | ||
| 657 | 602 | test "type info of tuple of string literal default value" { |
| 658 | 603 | const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0]; |
| 659 | 604 | const value = struct_field.defaultValue().?; |
| 660 | 605 | comptime std.debug.assert(value[0] == 'h'); |
| 661 | 606 | } |
| 662 | 607 | |
| 663 | test "@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 | ||
| 691 | 608 | test "@typeInfo function with generic return type and inferred error set" { |
| 692 | 609 | const S = struct { |
| 693 | 610 | fn testFn(comptime T: type) !T {} |
test/behavior/usingnamespace.zig deleted-125| ... | ... | @@ -1,125 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const expect = std.testing.expect; | |
| 4 | ||
| 5 | const A = struct { | |
| 6 | pub const B = bool; | |
| 7 | }; | |
| 8 | ||
| 9 | const C = struct { | |
| 10 | usingnamespace A; | |
| 11 | }; | |
| 12 | ||
| 13 | test "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 | ||
| 20 | fn Foo(comptime T: type) type { | |
| 21 | return struct { | |
| 22 | usingnamespace T; | |
| 23 | }; | |
| 24 | } | |
| 25 | ||
| 26 | test "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 | ||
| 36 | usingnamespace struct { | |
| 37 | pub const foo = 42; | |
| 38 | }; | |
| 39 | ||
| 40 | test "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 | ||
| 47 | usingnamespace @import("usingnamespace/foo.zig"); | |
| 48 | test "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 | } | |
| 57 | fn privateFunction() bool { | |
| 58 | return true; | |
| 59 | } | |
| 60 | ||
| 61 | test { | |
| 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 | ||
| 68 | usingnamespace @import("usingnamespace/a.zig"); | |
| 69 | test "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 | ||
| 78 | test { | |
| 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 | ||
| 100 | const Bar = struct { | |
| 101 | usingnamespace Mixin; | |
| 102 | }; | |
| 103 | ||
| 104 | const Mixin = struct { | |
| 105 | pub fn two(self: Bar) void { | |
| 106 | _ = self; | |
| 107 | } | |
| 108 | }; | |
| 109 | ||
| 110 | test "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 | ||
| 118 | usingnamespace opaque {}; | |
| 119 | ||
| 120 | usingnamespace @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 @@ |
| 1 | usingnamespace @import("b.zig"); | |
| 2 | ||
| 3 | pub const a_text = "OK\n"; | |
| 4 | ||
| 5 | pub 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 @@ |
| 1 | usingnamespace @import("a.zig"); | |
| 2 | ||
| 3 | pub const b_text = @This().a_text; |
test/behavior/usingnamespace/bar.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | usingnamespace @import("other.zig"); | |
| 2 | ||
| 3 | pub var saw_bar_function = false; | |
| 4 | pub 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 | |
| 3 | fn privateFunction() bool { | |
| 4 | return false; | |
| 5 | } | |
| 6 | ||
| 7 | pub fn printText() bool { | |
| 8 | return privateFunction(); | |
| 9 | } | |
| 10 | ||
| 11 | pub var saw_foo_function = false; | |
| 12 | pub fn foo_function() void { | |
| 13 | saw_foo_function = true; | |
| 14 | } |
test/behavior/usingnamespace/import_segregation.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | usingnamespace @import("foo.zig"); | |
| 5 | usingnamespace @import("bar.zig"); | |
| 6 | ||
| 7 | test "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 @@ |
| 1 | pub 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.@"async") void { | |
| 5 | other(); | |
| 6 | } | |
| 7 | fn 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 @@ |
| 1 | export fn a() void { | |
| 2 | const f = async func(); | |
| 3 | resume f; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | const f = async func(); | |
| 7 | var x: anyframe = &f; | |
| 8 | _ = &x; | |
| 9 | } | |
| 10 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(); | |
| 3 | } | |
| 4 | fn foo() void { | |
| 5 | bar(); | |
| 6 | } | |
| 7 | fn 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 @@ |
| 1 | var frame: ?anyframe = null; | |
| 2 | ||
| 3 | export fn a() void { | |
| 4 | _ = async rangeSum(10); | |
| 5 | while (frame) |f| resume f; | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 | ||
| 19 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame = async func(); | |
| 3 | var result = await frame; | |
| 4 | _ = &result; | |
| 5 | } | |
| 6 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() void { | |
| 5 | var ptr = afunc; | |
| 6 | _ = ptr(); | |
| 7 | _ = &ptr; | |
| 8 | } | |
| 9 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr = afunc; | |
| 3 | _ = async ptr(); | |
| 4 | _ = &ptr; | |
| 5 | } | |
| 6 | ||
| 7 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame: @Frame(foo) = undefined; | |
| 3 | frame = async bar(); | |
| 4 | } | |
| 5 | fn foo() void { | |
| 6 | suspend {} | |
| 7 | } | |
| 8 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() i32 { | |
| 5 | var frame: @Frame(foo) = undefined; | |
| 6 | return await @asyncCall(&frame, false, foo, .{}); | |
| 7 | } | |
| 8 | fn 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 | ||
| 8 | const S = struct { | |
| 9 | ok: u32, | |
| 10 | bad: @typeInfo(T), | |
| 11 | }; | |
| 12 | ||
| 13 | const T = struct { | |
| 14 | pub usingnamespace @compileError("usingnamespace analyzed"); | |
| 15 | }; | |
| 16 | ||
| 17 | comptime { | |
| 18 | const a: S = .{ .ok = 123, .bad = undefined }; | |
| 19 | _ = a; | |
| 20 | @compileError("should not be reached"); | |
| 21 | } | |
| 22 | ||
| 23 | comptime { | |
| 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 @@ |
| 1 | export fn entry() void { | |
| 2 | nosuspend { | |
| 3 | const bar = async foo(); | |
| 4 | suspend {} | |
| 5 | resume bar; | |
| 6 | } | |
| 7 | } | |
| 8 | fn 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 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async foo(); | |
| 3 | } | |
| 4 | fn 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 @@ |
| 1 | usingnamespace 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 5 | _ = message; | |
| 6 | _ = stack_trace; | |
| 7 | std.process.exit(0); | |
| 8 | } | |
| 9 | pub 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 | } | |
| 21 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | var frame: anyframe = undefined; | |
| 9 | ||
| 10 | pub fn main() !void { | |
| 11 | _ = async amain(); | |
| 12 | resume frame; | |
| 13 | return error.TestFailed; | |
| 14 | } | |
| 15 | ||
| 16 | fn amain() void { | |
| 17 | var f = async func(); | |
| 18 | await f; | |
| 19 | await f; | |
| 20 | } | |
| 21 | ||
| 22 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | ||
| 9 | var failing_frame: @Frame(failing) = undefined; | |
| 10 | ||
| 11 | pub fn main() !void { | |
| 12 | const p = nonFailing(); | |
| 13 | resume p; | |
| 14 | const p2 = async printTrace(p); | |
| 15 | _ = p2; | |
| 16 | return error.TestFailed; | |
| 17 | } | |
| 18 | ||
| 19 | fn nonFailing() anyframe->anyerror!void { | |
| 20 | failing_frame = async failing(); | |
| 21 | return &failing_frame; | |
| 22 | } | |
| 23 | ||
| 24 | fn failing() anyerror!void { | |
| 25 | suspend {} | |
| 26 | return second(); | |
| 27 | } | |
| 28 | ||
| 29 | fn second() callconv(.@"async") anyerror!void { | |
| 30 | return error.Fail; | |
| 31 | } | |
| 32 | ||
| 33 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | pub fn main() !void { | |
| 9 | var p = async suspendOnce(); | |
| 10 | resume p; //ok | |
| 11 | resume p; //bad | |
| 12 | return error.TestFailed; | |
| 13 | } | |
| 14 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | pub fn main() !void { | |
| 9 | var frame = async first(); | |
| 10 | resume frame; | |
| 11 | return error.TestFailed; | |
| 12 | } | |
| 13 | fn first() void { | |
| 14 | other(); | |
| 15 | } | |
| 16 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | pub fn main() !void { | |
| 9 | var frame = async first(); | |
| 10 | resume frame; | |
| 11 | return error.TestFailed; | |
| 12 | } | |
| 13 | fn first() void { | |
| 14 | var frame = async other(); | |
| 15 | await frame; | |
| 16 | } | |
| 17 | fn 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | fn foo() void { | |
| 9 | suspend { | |
| 10 | global_frame = @frame(); | |
| 11 | } | |
| 12 | var f = async bar(@frame()); | |
| 13 | _ = &f; | |
| 14 | std.process.exit(1); | |
| 15 | } | |
| 16 | ||
| 17 | fn bar(frame: anyframe) void { | |
| 18 | suspend { | |
| 19 | resume frame; | |
| 20 | } | |
| 21 | std.process.exit(1); | |
| 22 | } | |
| 23 | ||
| 24 | var global_frame: anyframe = undefined; | |
| 25 | pub 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 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | |
| 4 | _ = message; | |
| 5 | _ = stack_trace; | |
| 6 | std.process.exit(0); | |
| 7 | } | |
| 8 | fn foo() void { | |
| 9 | var f = async bar(@frame()); | |
| 10 | _ = &f; | |
| 11 | std.process.exit(1); | |
| 12 | } | |
| 13 | ||
| 14 | fn bar(frame: anyframe) void { | |
| 15 | suspend { | |
| 16 | resume frame; | |
| 17 | } | |
| 18 | std.process.exit(1); | |
| 19 | } | |
| 20 | ||
| 21 | pub 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 | 48 | .pkg_import = .{ |
| 49 | 49 | .path = "pkg_import", |
| 50 | 50 | }, |
| 51 | .use_alias = .{ | |
| 52 | .path = "use_alias", | |
| 53 | }, | |
| 54 | 51 | .install_raw_hex = .{ |
| 55 | 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 | 29 | .root_source_file = b.path("unwind.zig"), |
| 30 | 30 | .target = target, |
| 31 | 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 | 33 | .omit_frame_pointer = false, |
| 34 | 34 | }), |
| 35 | 35 | }); |
| ... | ... | @@ -54,7 +54,7 @@ pub fn build(b: *std.Build) void { |
| 54 | 54 | .root_source_file = b.path("unwind.zig"), |
| 55 | 55 | .target = target, |
| 56 | 56 | .optimize = optimize, |
| 57 | .unwind_tables = .@"async", | |
| 57 | .unwind_tables = .async, | |
| 58 | 58 | .omit_frame_pointer = true, |
| 59 | 59 | }), |
| 60 | 60 | // self-hosted lacks omit_frame_pointer support |
| ... | ... | @@ -101,7 +101,7 @@ pub fn build(b: *std.Build) void { |
| 101 | 101 | .root_source_file = b.path("shared_lib_unwind.zig"), |
| 102 | 102 | .target = target, |
| 103 | 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 | 105 | .omit_frame_pointer = true, |
| 106 | 106 | }), |
| 107 | 107 | // zig objcopy doesn't support incremental binaries |
test/standalone/use_alias/build.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub 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 @@ |
| 1 | pub usingnamespace @cImport(@cInclude("foo.h")); |
test/standalone/use_alias/foo.h deleted-4| ... | ... | @@ -1,4 +0,0 @@ |
| 1 | struct Foo { | |
| 2 | int a; | |
| 3 | int b; | |
| 4 | }; |
test/standalone/use_alias/main.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | const c = @import("c.zig"); | |
| 2 | const expect = @import("std").testing.expect; | |
| 3 | ||
| 4 | test "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 | 710 | .keyword_align, |
| 711 | 711 | .keyword_and, |
| 712 | 712 | .keyword_asm, |
| 713 | .keyword_async, | |
| 714 | .keyword_await, | |
| 715 | 713 | .keyword_break, |
| 716 | 714 | .keyword_catch, |
| 717 | 715 | .keyword_comptime, |
| ... | ... | @@ -748,7 +746,6 @@ fn tokenizeAndPrintRaw( |
| 748 | 746 | .keyword_try, |
| 749 | 747 | .keyword_union, |
| 750 | 748 | .keyword_unreachable, |
| 751 | .keyword_usingnamespace, | |
| 752 | 749 | .keyword_var, |
| 753 | 750 | .keyword_volatile, |
| 754 | 751 | .keyword_allowzero, |
tools/doctest.zig-3| ... | ... | @@ -653,8 +653,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void { |
| 653 | 653 | .keyword_align, |
| 654 | 654 | .keyword_and, |
| 655 | 655 | .keyword_asm, |
| 656 | .keyword_async, | |
| 657 | .keyword_await, | |
| 658 | 656 | .keyword_break, |
| 659 | 657 | .keyword_catch, |
| 660 | 658 | .keyword_comptime, |
| ... | ... | @@ -691,7 +689,6 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void { |
| 691 | 689 | .keyword_try, |
| 692 | 690 | .keyword_union, |
| 693 | 691 | .keyword_unreachable, |
| 694 | .keyword_usingnamespace, | |
| 695 | 692 | .keyword_var, |
| 696 | 693 | .keyword_volatile, |
| 697 | 694 | .keyword_allowzero, |
tools/lldb_pretty_printers.py-3| ... | ... | @@ -50,8 +50,6 @@ zig_keywords = { |
| 50 | 50 | 'anyframe', |
| 51 | 51 | 'anytype', |
| 52 | 52 | 'asm', |
| 53 | 'async', | |
| 54 | 'await', | |
| 55 | 53 | 'break', |
| 56 | 54 | 'callconv', |
| 57 | 55 | 'catch', |
| ... | ... | @@ -88,7 +86,6 @@ zig_keywords = { |
| 88 | 86 | 'try', |
| 89 | 87 | 'union', |
| 90 | 88 | 'unreachable', |
| 91 | 'usingnamespace', | |
| 92 | 89 | 'var', |
| 93 | 90 | 'volatile', |
| 94 | 91 | 'while', |