authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-05 05:08:46-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-05-05 05:17:33-06:00
log8d5636ebe4b1d70db14e28c67f7986fb2a1ce3cf
treeec2bb66b5e5b180bf55e891b09220e7eeac85ea3
parent9b788b765c1557a414710872fa9c11fce1f8c504
signaturelock-open Commit is signed but in an unrecognized format.

Rename noasync to nosuspend in self-hosted, add rewriter


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
802802 .Keyword_inline,
803803 .Keyword_nakedcc,
804804 .Keyword_noalias,
805 .Keyword_noasync,
806805 .Keyword_noinline,
806 .Keyword_nosuspend,
807807 .Keyword_or,
808808 .Keyword_orelse,
809809 .Keyword_packed,
lib/std/zig/ast.zig+11-11
......@@ -438,7 +438,7 @@ pub const Node = struct {
438438 ContainerDecl,
439439 Asm,
440440 Comptime,
441 Noasync,
441 Nosuspend,
442442 Block,
443443
444444 // Misc
......@@ -569,9 +569,9 @@ pub const Node = struct {
569569
570570 return true;
571571 },
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;
575575 },
576576 else => return true,
577577 }
......@@ -1084,12 +1084,12 @@ pub const Node = struct {
10841084 }
10851085 };
10861086
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,
10901090 expr: *Node,
10911091
1092 pub fn iterate(self: *Noasync, index: usize) ?*Node {
1092 pub fn iterate(self: *Nosuspend, index: usize) ?*Node {
10931093 var i = index;
10941094
10951095 if (i < 1) return self.expr;
......@@ -1098,11 +1098,11 @@ pub const Node = struct {
10981098 return null;
10991099 }
11001100
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;
11031103 }
11041104
1105 pub fn lastToken(self: *const Noasync) TokenIndex {
1105 pub fn lastToken(self: *const Nosuspend) TokenIndex {
11061106 return self.expr.lastToken();
11071107 }
11081108 };
lib/std/zig/parse.zig+12-12
......@@ -495,7 +495,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
495495/// Statement
496496/// <- KEYWORD_comptime? VarDecl
497497/// / KEYWORD_comptime BlockExprStatement
498/// / KEYWORD_noasync BlockExprStatement
498/// / KEYWORD_nosuspend BlockExprStatement
499499/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
500500/// / KEYWORD_defer BlockExprStatement
501501/// / KEYWORD_errdefer Payload? BlockExprStatement
......@@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
527527 return &node.base;
528528 }
529529
530 if (eatToken(it, .Keyword_noasync)) |noasync_token| {
530 if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| {
531531 const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{
532532 .ExpectedBlockOrAssignment = .{ .token = it.index },
533533 });
534534
535 const node = try arena.create(Node.Noasync);
535 const node = try arena.create(Node.Nosuspend);
536536 node.* = .{
537 .noasync_token = noasync_token,
537 .nosuspend_token = nosuspend_token,
538538 .expr = block_expr,
539539 };
540540 return &node.base;
......@@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
908908/// / IfExpr
909909/// / KEYWORD_break BreakLabel? Expr?
910910/// / KEYWORD_comptime Expr
911/// / KEYWORD_noasync Expr
911/// / KEYWORD_nosuspend Expr
912912/// / KEYWORD_continue BreakLabel?
913913/// / KEYWORD_resume Expr
914914/// / KEYWORD_return Expr?
......@@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
944944 return &node.base;
945945 }
946946
947 if (eatToken(it, .Keyword_noasync)) |token| {
947 if (eatToken(it, .Keyword_nosuspend)) |token| {
948948 const expr_node = try expectNode(arena, it, tree, parseExpr, .{
949949 .ExpectedExpr = .{ .token = it.index },
950950 });
951 const node = try arena.create(Node.Noasync);
951 const node = try arena.create(Node.Nosuspend);
952952 node.* = .{
953 .noasync_token = token,
953 .nosuspend_token = token,
954954 .expr = expr_node,
955955 };
956956 return &node.base;
......@@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
12881288/// / IfTypeExpr
12891289/// / INTEGER
12901290/// / KEYWORD_comptime TypeExpr
1291/// / KEYWORD_noasync TypeExpr
1291/// / KEYWORD_nosuspend TypeExpr
12921292/// / KEYWORD_error DOT IDENTIFIER
12931293/// / KEYWORD_false
12941294/// / KEYWORD_null
......@@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N
13271327 };
13281328 return &node.base;
13291329 }
1330 if (eatToken(it, .Keyword_noasync)) |token| {
1330 if (eatToken(it, .Keyword_nosuspend)) |token| {
13311331 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);
13331333 node.* = .{
1334 .noasync_token = token,
1334 .nosuspend_token = token,
13351335 .expr = expr,
13361336 };
13371337 return &node.base;
lib/std/zig/parser_test.zig+20-6
......@@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" {
3535 );
3636}
3737
38test "zig fmt: noasync block" {
38test "zig fmt: nosuspend block" {
3939 try testCanonical(
4040 \\pub fn main() anyerror!void {
41 \\ noasync {
41 \\ nosuspend {
4242 \\ var foo: Foo = .{ .bar = 42 };
4343 \\ }
4444 \\}
......@@ -46,10 +46,10 @@ test "zig fmt: noasync block" {
4646 );
4747}
4848
49test "zig fmt: noasync await" {
49test "zig fmt: nosuspend await" {
5050 try testCanonical(
5151 \\fn foo() void {
52 \\ x = noasync await y;
52 \\ x = nosuspend await y;
5353 \\}
5454 \\
5555 );
......@@ -2519,9 +2519,9 @@ test "zig fmt: async functions" {
25192519 );
25202520}
25212521
2522test "zig fmt: noasync" {
2522test "zig fmt: nosuspend" {
25232523 try testCanonical(
2524 \\const a = noasync foo();
2524 \\const a = nosuspend foo();
25252525 \\
25262526 );
25272527}
......@@ -2926,6 +2926,20 @@ test "zig fmt: hexadeciaml float literals with underscore separators" {
29262926 );
29272927}
29282928
2929test "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
29292943const std = @import("std");
29302944const mem = std.mem;
29312945const warn = std.debug.warn;
lib/std/zig/render.zig+9-5
......@@ -391,11 +391,15 @@ fn renderExpression(
391391 try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space);
392392 return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space);
393393 },
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);
399403 },
400404
401405 .Suspend => {
lib/std/zig/tokenizer.zig+4-3
......@@ -49,8 +49,9 @@ pub const Token = struct {
4949 Keyword.init("inline", .Keyword_inline),
5050 Keyword.init("nakedcc", .Keyword_nakedcc),
5151 Keyword.init("noalias", .Keyword_noalias),
52 Keyword.init("noasync", .Keyword_noasync),
52 Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this
5353 Keyword.init("noinline", .Keyword_noinline),
54 Keyword.init("nosuspend", .Keyword_nosuspend),
5455 Keyword.init("null", .Keyword_null),
5556 Keyword.init("or", .Keyword_or),
5657 Keyword.init("orelse", .Keyword_orelse),
......@@ -182,8 +183,8 @@ pub const Token = struct {
182183 Keyword_inline,
183184 Keyword_nakedcc,
184185 Keyword_noalias,
185 Keyword_noasync,
186186 Keyword_noinline,
187 Keyword_nosuspend,
187188 Keyword_null,
188189 Keyword_or,
189190 Keyword_orelse,
......@@ -307,8 +308,8 @@ pub const Token = struct {
307308 .Keyword_inline => "inline",
308309 .Keyword_nakedcc => "nakedcc",
309310 .Keyword_noalias => "noalias",
310 .Keyword_noasync => "noasync",
311311 .Keyword_noinline => "noinline",
312 .Keyword_nosuspend => "nosuspend",
312313 .Keyword_null => "null",
313314 .Keyword_or => "or",
314315 .Keyword_orelse => "orelse",