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...@@ -802,8 +802,8 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
802 .Keyword_inline,802 .Keyword_inline,
803 .Keyword_nakedcc,803 .Keyword_nakedcc,
804 .Keyword_noalias,804 .Keyword_noalias,
805 .Keyword_noasync,
806 .Keyword_noinline,805 .Keyword_noinline,
806 .Keyword_nosuspend,
807 .Keyword_or,807 .Keyword_or,
808 .Keyword_orelse,808 .Keyword_orelse,
809 .Keyword_packed,809 .Keyword_packed,
lib/std/zig/ast.zig+11-11
...@@ -438,7 +438,7 @@ pub const Node = struct {...@@ -438,7 +438,7 @@ pub const Node = struct {
438 ContainerDecl,438 ContainerDecl,
439 Asm,439 Asm,
440 Comptime,440 Comptime,
441 Noasync,441 Nosuspend,
442 Block,442 Block,
443443
444 // Misc444 // Misc
...@@ -569,9 +569,9 @@ pub const Node = struct {...@@ -569,9 +569,9 @@ pub const Node = struct {
569569
570 return true;570 return true;
571 },571 },
572 .Noasync => {572 .Nosuspend => {
573 const noasync_node = @fieldParentPtr(Noasync, "base", n);573 const nosuspend_node = @fieldParentPtr(Nosuspend, "base", n);
574 return noasync_node.expr.id != .Block;574 return nosuspend_node.expr.id != .Block;
575 },575 },
576 else => return true,576 else => return true,
577 }577 }
...@@ -1084,12 +1084,12 @@ pub const Node = struct {...@@ -1084,12 +1084,12 @@ pub const Node = struct {
1084 }1084 }
1085 };1085 };
10861086
1087 pub const Noasync = struct {1087 pub const Nosuspend = struct {
1088 base: Node = Node{ .id = .Noasync },1088 base: Node = Node{ .id = .Nosuspend },
1089 noasync_token: TokenIndex,1089 nosuspend_token: TokenIndex,
1090 expr: *Node,1090 expr: *Node,
10911091
1092 pub fn iterate(self: *Noasync, index: usize) ?*Node {1092 pub fn iterate(self: *Nosuspend, index: usize) ?*Node {
1093 var i = index;1093 var i = index;
10941094
1095 if (i < 1) return self.expr;1095 if (i < 1) return self.expr;
...@@ -1098,11 +1098,11 @@ pub const Node = struct {...@@ -1098,11 +1098,11 @@ pub const Node = struct {
1098 return null;1098 return null;
1099 }1099 }
11001100
1101 pub fn firstToken(self: *const Noasync) TokenIndex {1101 pub fn firstToken(self: *const Nosuspend) TokenIndex {
1102 return self.noasync_token;1102 return self.nosuspend_token;
1103 }1103 }
11041104
1105 pub fn lastToken(self: *const Noasync) TokenIndex {1105 pub fn lastToken(self: *const Nosuspend) TokenIndex {
1106 return self.expr.lastToken();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,7 +495,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
495/// Statement495/// Statement
496/// <- KEYWORD_comptime? VarDecl496/// <- KEYWORD_comptime? VarDecl
497/// / KEYWORD_comptime BlockExprStatement497/// / KEYWORD_comptime BlockExprStatement
498/// / KEYWORD_noasync BlockExprStatement498/// / KEYWORD_nosuspend BlockExprStatement
499/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)499/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
500/// / KEYWORD_defer BlockExprStatement500/// / KEYWORD_defer BlockExprStatement
501/// / KEYWORD_errdefer Payload? BlockExprStatement501/// / KEYWORD_errdefer Payload? BlockExprStatement
...@@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No...@@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
527 return &node.base;527 return &node.base;
528 }528 }
529529
530 if (eatToken(it, .Keyword_noasync)) |noasync_token| {530 if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| {
531 const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{531 const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{
532 .ExpectedBlockOrAssignment = .{ .token = it.index },532 .ExpectedBlockOrAssignment = .{ .token = it.index },
533 });533 });
534534
535 const node = try arena.create(Node.Noasync);535 const node = try arena.create(Node.Nosuspend);
536 node.* = .{536 node.* = .{
537 .noasync_token = noasync_token,537 .nosuspend_token = nosuspend_token,
538 .expr = block_expr,538 .expr = block_expr,
539 };539 };
540 return &node.base;540 return &node.base;
...@@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {...@@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
908/// / IfExpr908/// / IfExpr
909/// / KEYWORD_break BreakLabel? Expr?909/// / KEYWORD_break BreakLabel? Expr?
910/// / KEYWORD_comptime Expr910/// / KEYWORD_comptime Expr
911/// / KEYWORD_noasync Expr911/// / KEYWORD_nosuspend Expr
912/// / KEYWORD_continue BreakLabel?912/// / KEYWORD_continue BreakLabel?
913/// / KEYWORD_resume Expr913/// / KEYWORD_resume Expr
914/// / KEYWORD_return Expr?914/// / KEYWORD_return Expr?
...@@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
944 return &node.base;944 return &node.base;
945 }945 }
946946
947 if (eatToken(it, .Keyword_noasync)) |token| {947 if (eatToken(it, .Keyword_nosuspend)) |token| {
948 const expr_node = try expectNode(arena, it, tree, parseExpr, .{948 const expr_node = try expectNode(arena, it, tree, parseExpr, .{
949 .ExpectedExpr = .{ .token = it.index },949 .ExpectedExpr = .{ .token = it.index },
950 });950 });
951 const node = try arena.create(Node.Noasync);951 const node = try arena.create(Node.Nosuspend);
952 node.* = .{952 node.* = .{
953 .noasync_token = token,953 .nosuspend_token = token,
954 .expr = expr_node,954 .expr = expr_node,
955 };955 };
956 return &node.base;956 return &node.base;
...@@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {...@@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1288/// / IfTypeExpr1288/// / IfTypeExpr
1289/// / INTEGER1289/// / INTEGER
1290/// / KEYWORD_comptime TypeExpr1290/// / KEYWORD_comptime TypeExpr
1291/// / KEYWORD_noasync TypeExpr1291/// / KEYWORD_nosuspend TypeExpr
1292/// / KEYWORD_error DOT IDENTIFIER1292/// / KEYWORD_error DOT IDENTIFIER
1293/// / KEYWORD_false1293/// / KEYWORD_false
1294/// / KEYWORD_null1294/// / KEYWORD_null
...@@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N...@@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N
1327 };1327 };
1328 return &node.base;1328 return &node.base;
1329 }1329 }
1330 if (eatToken(it, .Keyword_noasync)) |token| {1330 if (eatToken(it, .Keyword_nosuspend)) |token| {
1331 const expr = (try parseTypeExpr(arena, it, tree)) orelse return null;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 node.* = .{1333 node.* = .{
1334 .noasync_token = token,1334 .nosuspend_token = token,
1335 .expr = expr,1335 .expr = expr,
1336 };1336 };
1337 return &node.base;1337 return &node.base;
lib/std/zig/parser_test.zig+20-6
...@@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" {...@@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" {
35 );35 );
36}36}
3737
38test "zig fmt: noasync block" {38test "zig fmt: nosuspend block" {
39 try testCanonical(39 try testCanonical(
40 \\pub fn main() anyerror!void {40 \\pub fn main() anyerror!void {
41 \\ noasync {41 \\ nosuspend {
42 \\ var foo: Foo = .{ .bar = 42 };42 \\ var foo: Foo = .{ .bar = 42 };
43 \\ }43 \\ }
44 \\}44 \\}
...@@ -46,10 +46,10 @@ test "zig fmt: noasync block" {...@@ -46,10 +46,10 @@ test "zig fmt: noasync block" {
46 );46 );
47}47}
4848
49test "zig fmt: noasync await" {49test "zig fmt: nosuspend await" {
50 try testCanonical(50 try testCanonical(
51 \\fn foo() void {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,9 +2519,9 @@ test "zig fmt: async functions" {
2519 );2519 );
2520}2520}
25212521
2522test "zig fmt: noasync" {2522test "zig fmt: nosuspend" {
2523 try testCanonical(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,6 +2926,20 @@ test "zig fmt: hexadeciaml float literals with underscore separators" {
2926 );2926 );
2927}2927}
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
2929const std = @import("std");2943const std = @import("std");
2930const mem = std.mem;2944const mem = std.mem;
2931const warn = std.debug.warn;2945const warn = std.debug.warn;
lib/std/zig/render.zig+9-5
...@@ -391,11 +391,15 @@ fn renderExpression(...@@ -391,11 +391,15 @@ fn renderExpression(
391 try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space);391 try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space);
392 return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space);392 return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space);
393 },393 },
394 .Noasync => {394 .Nosuspend => {
395 const noasync_node = @fieldParentPtr(ast.Node.Noasync, "base", base);395 const nosuspend_node = @fieldParentPtr(ast.Node.Nosuspend, "base", base);
396396 if (mem.eql(u8, tree.tokenSlice(nosuspend_node.nosuspend_token), "noasync")) {
397 try renderToken(tree, stream, noasync_node.noasync_token, indent, start_col, Space.Space);397 // TODO: remove this
398 return renderExpression(allocator, stream, tree, indent, start_col, noasync_node.expr, space);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 },
400404
401 .Suspend => {405 .Suspend => {
lib/std/zig/tokenizer.zig+4-3
...@@ -49,8 +49,9 @@ pub const Token = struct {...@@ -49,8 +49,9 @@ pub const Token = struct {
49 Keyword.init("inline", .Keyword_inline),49 Keyword.init("inline", .Keyword_inline),
50 Keyword.init("nakedcc", .Keyword_nakedcc),50 Keyword.init("nakedcc", .Keyword_nakedcc),
51 Keyword.init("noalias", .Keyword_noalias),51 Keyword.init("noalias", .Keyword_noalias),
52 Keyword.init("noasync", .Keyword_noasync),52 Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this
53 Keyword.init("noinline", .Keyword_noinline),53 Keyword.init("noinline", .Keyword_noinline),
54 Keyword.init("nosuspend", .Keyword_nosuspend),
54 Keyword.init("null", .Keyword_null),55 Keyword.init("null", .Keyword_null),
55 Keyword.init("or", .Keyword_or),56 Keyword.init("or", .Keyword_or),
56 Keyword.init("orelse", .Keyword_orelse),57 Keyword.init("orelse", .Keyword_orelse),
...@@ -182,8 +183,8 @@ pub const Token = struct {...@@ -182,8 +183,8 @@ pub const Token = struct {
182 Keyword_inline,183 Keyword_inline,
183 Keyword_nakedcc,184 Keyword_nakedcc,
184 Keyword_noalias,185 Keyword_noalias,
185 Keyword_noasync,
186 Keyword_noinline,186 Keyword_noinline,
187 Keyword_nosuspend,
187 Keyword_null,188 Keyword_null,
188 Keyword_or,189 Keyword_or,
189 Keyword_orelse,190 Keyword_orelse,
...@@ -307,8 +308,8 @@ pub const Token = struct {...@@ -307,8 +308,8 @@ pub const Token = struct {
307 .Keyword_inline => "inline",308 .Keyword_inline => "inline",
308 .Keyword_nakedcc => "nakedcc",309 .Keyword_nakedcc => "nakedcc",
309 .Keyword_noalias => "noalias",310 .Keyword_noalias => "noalias",
310 .Keyword_noasync => "noasync",
311 .Keyword_noinline => "noinline",311 .Keyword_noinline => "noinline",
312 .Keyword_nosuspend => "nosuspend",
312 .Keyword_null => "null",313 .Keyword_null => "null",
313 .Keyword_or => "or",314 .Keyword_or => "or",
314 .Keyword_orelse => "orelse",315 .Keyword_orelse => "orelse",