Commit 8d5636ebe4
Changed files (6)
doc/docgen.zig
@@ -802,8 +802,8 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
.Keyword_inline,
.Keyword_nakedcc,
.Keyword_noalias,
- .Keyword_noasync,
.Keyword_noinline,
+ .Keyword_nosuspend,
.Keyword_or,
.Keyword_orelse,
.Keyword_packed,
lib/std/zig/ast.zig
@@ -438,7 +438,7 @@ pub const Node = struct {
ContainerDecl,
Asm,
Comptime,
- Noasync,
+ Nosuspend,
Block,
// Misc
@@ -569,9 +569,9 @@ pub const Node = struct {
return true;
},
- .Noasync => {
- const noasync_node = @fieldParentPtr(Noasync, "base", n);
- return noasync_node.expr.id != .Block;
+ .Nosuspend => {
+ const nosuspend_node = @fieldParentPtr(Nosuspend, "base", n);
+ return nosuspend_node.expr.id != .Block;
},
else => return true,
}
@@ -1084,12 +1084,12 @@ pub const Node = struct {
}
};
- pub const Noasync = struct {
- base: Node = Node{ .id = .Noasync },
- noasync_token: TokenIndex,
+ pub const Nosuspend = struct {
+ base: Node = Node{ .id = .Nosuspend },
+ nosuspend_token: TokenIndex,
expr: *Node,
- pub fn iterate(self: *Noasync, index: usize) ?*Node {
+ pub fn iterate(self: *Nosuspend, index: usize) ?*Node {
var i = index;
if (i < 1) return self.expr;
@@ -1098,11 +1098,11 @@ pub const Node = struct {
return null;
}
- pub fn firstToken(self: *const Noasync) TokenIndex {
- return self.noasync_token;
+ pub fn firstToken(self: *const Nosuspend) TokenIndex {
+ return self.nosuspend_token;
}
- pub fn lastToken(self: *const Noasync) TokenIndex {
+ pub fn lastToken(self: *const Nosuspend) TokenIndex {
return self.expr.lastToken();
}
};
lib/std/zig/parse.zig
@@ -495,7 +495,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
/// Statement
/// <- KEYWORD_comptime? VarDecl
/// / KEYWORD_comptime BlockExprStatement
-/// / KEYWORD_noasync BlockExprStatement
+/// / KEYWORD_nosuspend BlockExprStatement
/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
/// / KEYWORD_defer BlockExprStatement
/// / KEYWORD_errdefer Payload? BlockExprStatement
@@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |noasync_token| {
+ if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| {
const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{
.ExpectedBlockOrAssignment = .{ .token = it.index },
});
- const node = try arena.create(Node.Noasync);
+ const node = try arena.create(Node.Nosuspend);
node.* = .{
- .noasync_token = noasync_token,
+ .nosuspend_token = nosuspend_token,
.expr = block_expr,
};
return &node.base;
@@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
/// / IfExpr
/// / KEYWORD_break BreakLabel? Expr?
/// / KEYWORD_comptime Expr
-/// / KEYWORD_noasync Expr
+/// / KEYWORD_nosuspend Expr
/// / KEYWORD_continue BreakLabel?
/// / KEYWORD_resume Expr
/// / KEYWORD_return Expr?
@@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |token| {
+ if (eatToken(it, .Keyword_nosuspend)) |token| {
const expr_node = try expectNode(arena, it, tree, parseExpr, .{
.ExpectedExpr = .{ .token = it.index },
});
- const node = try arena.create(Node.Noasync);
+ const node = try arena.create(Node.Nosuspend);
node.* = .{
- .noasync_token = token,
+ .nosuspend_token = token,
.expr = expr_node,
};
return &node.base;
@@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
/// / IfTypeExpr
/// / INTEGER
/// / KEYWORD_comptime TypeExpr
-/// / KEYWORD_noasync TypeExpr
+/// / KEYWORD_nosuspend TypeExpr
/// / KEYWORD_error DOT IDENTIFIER
/// / KEYWORD_false
/// / KEYWORD_null
@@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N
};
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |token| {
+ if (eatToken(it, .Keyword_nosuspend)) |token| {
const expr = (try parseTypeExpr(arena, it, tree)) orelse return null;
- const node = try arena.create(Node.Noasync);
+ const node = try arena.create(Node.Nosuspend);
node.* = .{
- .noasync_token = token,
+ .nosuspend_token = token,
.expr = expr,
};
return &node.base;
lib/std/zig/parser_test.zig
@@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" {
);
}
-test "zig fmt: noasync block" {
+test "zig fmt: nosuspend block" {
try testCanonical(
\\pub fn main() anyerror!void {
- \\ noasync {
+ \\ nosuspend {
\\ var foo: Foo = .{ .bar = 42 };
\\ }
\\}
@@ -46,10 +46,10 @@ test "zig fmt: noasync block" {
);
}
-test "zig fmt: noasync await" {
+test "zig fmt: nosuspend await" {
try testCanonical(
\\fn foo() void {
- \\ x = noasync await y;
+ \\ x = nosuspend await y;
\\}
\\
);
@@ -2519,9 +2519,9 @@ test "zig fmt: async functions" {
);
}
-test "zig fmt: noasync" {
+test "zig fmt: nosuspend" {
try testCanonical(
- \\const a = noasync foo();
+ \\const a = nosuspend foo();
\\
);
}
@@ -2926,6 +2926,20 @@ test "zig fmt: hexadeciaml float literals with underscore separators" {
);
}
+test "zig fmt: noasync to nosuspend" {
+ // TODO: remove this
+ try testTransform(
+ \\pub fn main() void {
+ \\ noasync call();
+ \\}
+ ,
+ \\pub fn main() void {
+ \\ nosuspend call();
+ \\}
+ \\
+ );
+}
+
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
lib/std/zig/render.zig
@@ -391,11 +391,15 @@ fn renderExpression(
try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space);
return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space);
},
- .Noasync => {
- const noasync_node = @fieldParentPtr(ast.Node.Noasync, "base", base);
-
- try renderToken(tree, stream, noasync_node.noasync_token, indent, start_col, Space.Space);
- return renderExpression(allocator, stream, tree, indent, start_col, noasync_node.expr, space);
+ .Nosuspend => {
+ const nosuspend_node = @fieldParentPtr(ast.Node.Nosuspend, "base", base);
+ if (mem.eql(u8, tree.tokenSlice(nosuspend_node.nosuspend_token), "noasync")) {
+ // TODO: remove this
+ try stream.writeAll("nosuspend ");
+ } else {
+ try renderToken(tree, stream, nosuspend_node.nosuspend_token, indent, start_col, Space.Space);
+ }
+ return renderExpression(allocator, stream, tree, indent, start_col, nosuspend_node.expr, space);
},
.Suspend => {
lib/std/zig/tokenizer.zig
@@ -49,8 +49,9 @@ pub const Token = struct {
Keyword.init("inline", .Keyword_inline),
Keyword.init("nakedcc", .Keyword_nakedcc),
Keyword.init("noalias", .Keyword_noalias),
- Keyword.init("noasync", .Keyword_noasync),
+ Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this
Keyword.init("noinline", .Keyword_noinline),
+ Keyword.init("nosuspend", .Keyword_nosuspend),
Keyword.init("null", .Keyword_null),
Keyword.init("or", .Keyword_or),
Keyword.init("orelse", .Keyword_orelse),
@@ -182,8 +183,8 @@ pub const Token = struct {
Keyword_inline,
Keyword_nakedcc,
Keyword_noalias,
- Keyword_noasync,
Keyword_noinline,
+ Keyword_nosuspend,
Keyword_null,
Keyword_or,
Keyword_orelse,
@@ -307,8 +308,8 @@ pub const Token = struct {
.Keyword_inline => "inline",
.Keyword_nakedcc => "nakedcc",
.Keyword_noalias => "noalias",
- .Keyword_noasync => "noasync",
.Keyword_noinline => "noinline",
+ .Keyword_nosuspend => "nosuspend",
.Keyword_null => "null",
.Keyword_or => "or",
.Keyword_orelse => "orelse",