| author | |
| committer | |
| log | 8d5636ebe4b1d70db14e28c67f7986fb2a1ce3cf |
| tree | ec2bb66b5e5b180bf55e891b09220e7eeac85ea3 |
| parent | 9b788b765c1557a414710872fa9c11fce1f8c504 |
| signature |
6 files changed, 57 insertions(+), 38 deletions(-)
doc/docgen.zig+1-1| ... | ... | @@ -802,8 +802,8 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 802 | 802 | .Keyword_inline, |
| 803 | 803 | .Keyword_nakedcc, |
| 804 | 804 | .Keyword_noalias, |
| 805 | .Keyword_noasync, | |
| 806 | 805 | .Keyword_noinline, |
| 806 | .Keyword_nosuspend, | |
| 807 | 807 | .Keyword_or, |
| 808 | 808 | .Keyword_orelse, |
| 809 | 809 | .Keyword_packed, |
lib/std/zig/ast.zig+11-11| ... | ... | @@ -438,7 +438,7 @@ pub const Node = struct { |
| 438 | 438 | ContainerDecl, |
| 439 | 439 | Asm, |
| 440 | 440 | Comptime, |
| 441 | Noasync, | |
| 441 | Nosuspend, | |
| 442 | 442 | Block, |
| 443 | 443 | |
| 444 | 444 | // Misc |
| ... | ... | @@ -569,9 +569,9 @@ pub const Node = struct { |
| 569 | 569 | |
| 570 | 570 | return true; |
| 571 | 571 | }, |
| 572 | .Noasync => { | |
| 573 | const noasync_node = @fieldParentPtr(Noasync, "base", n); | |
| 574 | return noasync_node.expr.id != .Block; | |
| 572 | .Nosuspend => { | |
| 573 | const nosuspend_node = @fieldParentPtr(Nosuspend, "base", n); | |
| 574 | return nosuspend_node.expr.id != .Block; | |
| 575 | 575 | }, |
| 576 | 576 | else => return true, |
| 577 | 577 | } |
| ... | ... | @@ -1084,12 +1084,12 @@ pub const Node = struct { |
| 1084 | 1084 | } |
| 1085 | 1085 | }; |
| 1086 | 1086 | |
| 1087 | pub const Noasync = struct { | |
| 1088 | base: Node = Node{ .id = .Noasync }, | |
| 1089 | noasync_token: TokenIndex, | |
| 1087 | pub const Nosuspend = struct { | |
| 1088 | base: Node = Node{ .id = .Nosuspend }, | |
| 1089 | nosuspend_token: TokenIndex, | |
| 1090 | 1090 | expr: *Node, |
| 1091 | 1091 | |
| 1092 | pub fn iterate(self: *Noasync, index: usize) ?*Node { | |
| 1092 | pub fn iterate(self: *Nosuspend, index: usize) ?*Node { | |
| 1093 | 1093 | var i = index; |
| 1094 | 1094 | |
| 1095 | 1095 | if (i < 1) return self.expr; |
| ... | ... | @@ -1098,11 +1098,11 @@ pub const Node = struct { |
| 1098 | 1098 | return null; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | pub fn firstToken(self: *const Noasync) TokenIndex { | |
| 1102 | return self.noasync_token; | |
| 1101 | pub fn firstToken(self: *const Nosuspend) TokenIndex { | |
| 1102 | return self.nosuspend_token; | |
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | pub fn lastToken(self: *const Noasync) TokenIndex { | |
| 1105 | pub fn lastToken(self: *const Nosuspend) TokenIndex { | |
| 1106 | 1106 | return self.expr.lastToken(); |
| 1107 | 1107 | } |
| 1108 | 1108 | }; |
lib/std/zig/parse.zig+12-12| ... | ... | @@ -495,7 +495,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No |
| 495 | 495 | /// Statement |
| 496 | 496 | /// <- KEYWORD_comptime? VarDecl |
| 497 | 497 | /// / KEYWORD_comptime BlockExprStatement |
| 498 | /// / KEYWORD_noasync BlockExprStatement | |
| 498 | /// / KEYWORD_nosuspend BlockExprStatement | |
| 499 | 499 | /// / KEYWORD_suspend (SEMICOLON / BlockExprStatement) |
| 500 | 500 | /// / KEYWORD_defer BlockExprStatement |
| 501 | 501 | /// / KEYWORD_errdefer Payload? BlockExprStatement |
| ... | ... | @@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No |
| 527 | 527 | return &node.base; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | if (eatToken(it, .Keyword_noasync)) |noasync_token| { | |
| 530 | if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| { | |
| 531 | 531 | const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{ |
| 532 | 532 | .ExpectedBlockOrAssignment = .{ .token = it.index }, |
| 533 | 533 | }); |
| 534 | 534 | |
| 535 | const node = try arena.create(Node.Noasync); | |
| 535 | const node = try arena.create(Node.Nosuspend); | |
| 536 | 536 | node.* = .{ |
| 537 | .noasync_token = noasync_token, | |
| 537 | .nosuspend_token = nosuspend_token, | |
| 538 | 538 | .expr = block_expr, |
| 539 | 539 | }; |
| 540 | 540 | return &node.base; |
| ... | ... | @@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 908 | 908 | /// / IfExpr |
| 909 | 909 | /// / KEYWORD_break BreakLabel? Expr? |
| 910 | 910 | /// / KEYWORD_comptime Expr |
| 911 | /// / KEYWORD_noasync Expr | |
| 911 | /// / KEYWORD_nosuspend Expr | |
| 912 | 912 | /// / KEYWORD_continue BreakLabel? |
| 913 | 913 | /// / KEYWORD_resume Expr |
| 914 | 914 | /// / KEYWORD_return Expr? |
| ... | ... | @@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node |
| 944 | 944 | return &node.base; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | if (eatToken(it, .Keyword_noasync)) |token| { | |
| 947 | if (eatToken(it, .Keyword_nosuspend)) |token| { | |
| 948 | 948 | const expr_node = try expectNode(arena, it, tree, parseExpr, .{ |
| 949 | 949 | .ExpectedExpr = .{ .token = it.index }, |
| 950 | 950 | }); |
| 951 | const node = try arena.create(Node.Noasync); | |
| 951 | const node = try arena.create(Node.Nosuspend); | |
| 952 | 952 | node.* = .{ |
| 953 | .noasync_token = token, | |
| 953 | .nosuspend_token = token, | |
| 954 | 954 | .expr = expr_node, |
| 955 | 955 | }; |
| 956 | 956 | return &node.base; |
| ... | ... | @@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { |
| 1288 | 1288 | /// / IfTypeExpr |
| 1289 | 1289 | /// / INTEGER |
| 1290 | 1290 | /// / KEYWORD_comptime TypeExpr |
| 1291 | /// / KEYWORD_noasync TypeExpr | |
| 1291 | /// / KEYWORD_nosuspend TypeExpr | |
| 1292 | 1292 | /// / KEYWORD_error DOT IDENTIFIER |
| 1293 | 1293 | /// / KEYWORD_false |
| 1294 | 1294 | /// / KEYWORD_null |
| ... | ... | @@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N |
| 1327 | 1327 | }; |
| 1328 | 1328 | return &node.base; |
| 1329 | 1329 | } |
| 1330 | if (eatToken(it, .Keyword_noasync)) |token| { | |
| 1330 | if (eatToken(it, .Keyword_nosuspend)) |token| { | |
| 1331 | 1331 | const expr = (try parseTypeExpr(arena, it, tree)) orelse return null; |
| 1332 | const node = try arena.create(Node.Noasync); | |
| 1332 | const node = try arena.create(Node.Nosuspend); | |
| 1333 | 1333 | node.* = .{ |
| 1334 | .noasync_token = token, | |
| 1334 | .nosuspend_token = token, | |
| 1335 | 1335 | .expr = expr, |
| 1336 | 1336 | }; |
| 1337 | 1337 | return &node.base; |
lib/std/zig/parser_test.zig+20-6| ... | ... | @@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" { |
| 35 | 35 | ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | test "zig fmt: noasync block" { | |
| 38 | test "zig fmt: nosuspend block" { | |
| 39 | 39 | try testCanonical( |
| 40 | 40 | \\pub fn main() anyerror!void { |
| 41 | \\ noasync { | |
| 41 | \\ nosuspend { | |
| 42 | 42 | \\ var foo: Foo = .{ .bar = 42 }; |
| 43 | 43 | \\ } |
| 44 | 44 | \\} |
| ... | ... | @@ -46,10 +46,10 @@ test "zig fmt: noasync block" { |
| 46 | 46 | ); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | test "zig fmt: noasync await" { | |
| 49 | test "zig fmt: nosuspend await" { | |
| 50 | 50 | try testCanonical( |
| 51 | 51 | \\fn foo() void { |
| 52 | \\ x = noasync await y; | |
| 52 | \\ x = nosuspend await y; | |
| 53 | 53 | \\} |
| 54 | 54 | \\ |
| 55 | 55 | ); |
| ... | ... | @@ -2519,9 +2519,9 @@ test "zig fmt: async functions" { |
| 2519 | 2519 | ); |
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | test "zig fmt: noasync" { | |
| 2522 | test "zig fmt: nosuspend" { | |
| 2523 | 2523 | try testCanonical( |
| 2524 | \\const a = noasync foo(); | |
| 2524 | \\const a = nosuspend foo(); | |
| 2525 | 2525 | \\ |
| 2526 | 2526 | ); |
| 2527 | 2527 | } |
| ... | ... | @@ -2926,6 +2926,20 @@ test "zig fmt: hexadeciaml float literals with underscore separators" { |
| 2926 | 2926 | ); |
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | test "zig fmt: noasync to nosuspend" { | |
| 2930 | // TODO: remove this | |
| 2931 | try testTransform( | |
| 2932 | \\pub fn main() void { | |
| 2933 | \\ noasync call(); | |
| 2934 | \\} | |
| 2935 | , | |
| 2936 | \\pub fn main() void { | |
| 2937 | \\ nosuspend call(); | |
| 2938 | \\} | |
| 2939 | \\ | |
| 2940 | ); | |
| 2941 | } | |
| 2942 | ||
| 2929 | 2943 | const std = @import("std"); |
| 2930 | 2944 | const mem = std.mem; |
| 2931 | 2945 | const warn = std.debug.warn; |
lib/std/zig/render.zig+9-5| ... | ... | @@ -391,11 +391,15 @@ fn renderExpression( |
| 391 | 391 | try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space); |
| 392 | 392 | return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space); |
| 393 | 393 | }, |
| 394 | .Noasync => { | |
| 395 | const noasync_node = @fieldParentPtr(ast.Node.Noasync, "base", base); | |
| 396 | ||
| 397 | try renderToken(tree, stream, noasync_node.noasync_token, indent, start_col, Space.Space); | |
| 398 | return renderExpression(allocator, stream, tree, indent, start_col, noasync_node.expr, space); | |
| 394 | .Nosuspend => { | |
| 395 | const nosuspend_node = @fieldParentPtr(ast.Node.Nosuspend, "base", base); | |
| 396 | if (mem.eql(u8, tree.tokenSlice(nosuspend_node.nosuspend_token), "noasync")) { | |
| 397 | // TODO: remove this | |
| 398 | try stream.writeAll("nosuspend "); | |
| 399 | } else { | |
| 400 | try renderToken(tree, stream, nosuspend_node.nosuspend_token, indent, start_col, Space.Space); | |
| 401 | } | |
| 402 | return renderExpression(allocator, stream, tree, indent, start_col, nosuspend_node.expr, space); | |
| 399 | 403 | }, |
| 400 | 404 | |
| 401 | 405 | .Suspend => { |
lib/std/zig/tokenizer.zig+4-3| ... | ... | @@ -49,8 +49,9 @@ pub const Token = struct { |
| 49 | 49 | Keyword.init("inline", .Keyword_inline), |
| 50 | 50 | Keyword.init("nakedcc", .Keyword_nakedcc), |
| 51 | 51 | Keyword.init("noalias", .Keyword_noalias), |
| 52 | Keyword.init("noasync", .Keyword_noasync), | |
| 52 | Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this | |
| 53 | 53 | Keyword.init("noinline", .Keyword_noinline), |
| 54 | Keyword.init("nosuspend", .Keyword_nosuspend), | |
| 54 | 55 | Keyword.init("null", .Keyword_null), |
| 55 | 56 | Keyword.init("or", .Keyword_or), |
| 56 | 57 | Keyword.init("orelse", .Keyword_orelse), |
| ... | ... | @@ -182,8 +183,8 @@ pub const Token = struct { |
| 182 | 183 | Keyword_inline, |
| 183 | 184 | Keyword_nakedcc, |
| 184 | 185 | Keyword_noalias, |
| 185 | Keyword_noasync, | |
| 186 | 186 | Keyword_noinline, |
| 187 | Keyword_nosuspend, | |
| 187 | 188 | Keyword_null, |
| 188 | 189 | Keyword_or, |
| 189 | 190 | Keyword_orelse, |
| ... | ... | @@ -307,8 +308,8 @@ pub const Token = struct { |
| 307 | 308 | .Keyword_inline => "inline", |
| 308 | 309 | .Keyword_nakedcc => "nakedcc", |
| 309 | 310 | .Keyword_noalias => "noalias", |
| 310 | .Keyword_noasync => "noasync", | |
| 311 | 311 | .Keyword_noinline => "noinline", |
| 312 | .Keyword_nosuspend => "nosuspend", | |
| 312 | 313 | .Keyword_null => "null", |
| 313 | 314 | .Keyword_or => "or", |
| 314 | 315 | .Keyword_orelse => "orelse", |