wgsl: Deprecate '-> void' on functions

Was removed with:
https://github.com/gpuweb/gpuweb/pull/1460

Bug: tint:677
Change-Id: If08cb450189c6158561051ef6e8f2439c60bc010
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47140
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-04-08 14:39:47 +00:00 committed by Commit Bot service account
parent d15391e802
commit 9328d94572
48 changed files with 645 additions and 600 deletions

View File

@ -2244,7 +2244,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kStoreWO1dRgba32float, ValidTextureOverload::kStoreWO1dRgba32float,
"textureStore(t : texture_storage_1d<rgba32float>,\n" "textureStore(t : texture_storage_1d<rgba32float>,\n"
" coords : i32,\n" " coords : i32,\n"
" value : vec4<T>) -> void", " value : vec4<T>)",
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
type::ImageFormat::kRgba32Float, type::ImageFormat::kRgba32Float,
type::TextureDimension::k1d, type::TextureDimension::k1d,
@ -2260,7 +2260,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kStoreWO2dRgba32float, ValidTextureOverload::kStoreWO2dRgba32float,
"textureStore(t : texture_storage_2d<rgba32float>,\n" "textureStore(t : texture_storage_2d<rgba32float>,\n"
" coords : vec2<i32>,\n" " coords : vec2<i32>,\n"
" value : vec4<T>) -> void", " value : vec4<T>)",
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
type::ImageFormat::kRgba32Float, type::ImageFormat::kRgba32Float,
type::TextureDimension::k2d, type::TextureDimension::k2d,
@ -2277,7 +2277,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
"textureStore(t : texture_storage_2d_array<rgba32float>,\n" "textureStore(t : texture_storage_2d_array<rgba32float>,\n"
" coords : vec2<i32>,\n" " coords : vec2<i32>,\n"
" array_index : i32,\n" " array_index : i32,\n"
" value : vec4<T>) -> void", " value : vec4<T>)",
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
type::ImageFormat::kRgba32Float, type::ImageFormat::kRgba32Float,
type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
@ -2294,7 +2294,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kStoreWO3dRgba32float, ValidTextureOverload::kStoreWO3dRgba32float,
"textureStore(t : texture_storage_3d<rgba32float>,\n" "textureStore(t : texture_storage_3d<rgba32float>,\n"
" coords : vec3<i32>,\n" " coords : vec3<i32>,\n"
" value : vec4<T>) -> void", " value : vec4<T>)",
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
type::ImageFormat::kRgba32Float, type::ImageFormat::kRgba32Float,
type::TextureDimension::k3d, type::TextureDimension::k3d,

View File

@ -98,7 +98,7 @@ fn f1(p0 : f32, p1 : i32) -> f32 {
} }
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
f1(1.0, 2); f1(1.0, 2);
} }
@ -106,7 +106,7 @@ const declaration_order_check_0 : i32 = 1;
type declaration_order_check_1 = f32; type declaration_order_check_1 = f32;
fn declaration_order_check_2() -> void {} fn declaration_order_check_2() {}
type declaration_order_check_2 = f32; type declaration_order_check_2 = f32;

View File

@ -108,6 +108,17 @@ class List {
add(std::move(error)); add(std::move(error));
} }
/// adds the warning message with the given Source to the end of this list.
/// @param warning_msg the warning message
/// @param source the source of the warning diagnostic
void add_warning(const std::string& warning_msg, const Source& source) {
diag::Diagnostic error{};
error.severity = diag::Severity::Warning;
error.source = source;
error.message = warning_msg;
add(std::move(error));
}
/// adds the error message without a source to the end of this list. /// adds the error message without a source to the end of this list.
/// @param err_msg the error message /// @param err_msg the error message
void add_error(std::string err_msg) { void add_error(std::string err_msg) {

View File

@ -211,6 +211,11 @@ ParserImpl::Failure::Errored ParserImpl::add_error(const Source& source,
return Failure::kErrored; return Failure::kErrored;
} }
void ParserImpl::deprecated(const Source& source, const std::string& msg) {
builder_.Diagnostics().add_warning(
"use of deprecated language feature: " + msg, source);
}
Token ParserImpl::next() { Token ParserImpl::next() {
if (!token_queue_.empty()) { if (!token_queue_.empty()) {
auto t = token_queue_.front(); auto t = token_queue_.front();
@ -1207,8 +1212,9 @@ Maybe<type::Type*> ParserImpl::function_type_decl() {
// : FN IDENT PAREN_LEFT param_list PAREN_RIGHT ARROW function_type_decl // : FN IDENT PAREN_LEFT param_list PAREN_RIGHT ARROW function_type_decl
Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() { Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
Source source; Source source;
if (!match(Token::Type::kFn, &source)) if (!match(Token::Type::kFn, &source)) {
return Failure::kNoMatch; return Failure::kNoMatch;
}
const char* use = "function declaration"; const char* use = "function declaration";
bool errored = false; bool errored = false;
@ -1216,37 +1222,56 @@ Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
auto name = expect_ident(use); auto name = expect_ident(use);
if (name.errored) { if (name.errored) {
errored = true; errored = true;
if (!sync_to(Token::Type::kParenLeft, /* consume: */ false)) if (!sync_to(Token::Type::kParenLeft, /* consume: */ false)) {
return Failure::kErrored; return Failure::kErrored;
}
} }
auto params = expect_paren_block(use, [&] { return expect_param_list(); }); auto params = expect_paren_block(use, [&] { return expect_param_list(); });
if (params.errored) { if (params.errored) {
errored = true; errored = true;
if (!synchronized_) if (!synchronized_) {
return Failure::kErrored; return Failure::kErrored;
}
} }
if (!expect(use, Token::Type::kArrow)) type::Type* return_type = nullptr;
return Failure::kErrored; ast::DecorationList return_decorations;
auto decos = decoration_list(); if (match(Token::Type::kArrow)) {
if (decos.errored) { auto decos = decoration_list();
if (decos.errored) {
return Failure::kErrored;
}
return_decorations = decos.value;
auto tok = peek();
auto type = function_type_decl();
if (type.errored) {
errored = true;
} else if (!type.matched) {
return add_error(peek(), "unable to determine function return type");
} else {
return_type = type.value;
}
if (return_type->Is<type::Void>()) {
// crbug.com/tint/677: void has been removed from the language
deprecated(tok.source(),
"omit '-> void' for functions that do not return a value");
}
} else {
return_type = builder_.ty.void_();
}
if (errored) {
return Failure::kErrored; return Failure::kErrored;
} }
auto type = function_type_decl(); return FunctionHeader{source, name.value, std::move(params.value),
if (type.errored) { return_type, std::move(return_decorations)};
errored = true;
} else if (!type.matched) {
return add_error(peek(), "unable to determine function return type");
}
if (errored)
return Failure::kErrored;
return FunctionHeader{source, name.value, std::move(params.value), type.value,
std::move(decos.value)};
} }
// param_list // param_list

View File

@ -320,7 +320,11 @@ class ParserImpl {
/// @return `Failure::Errored::kError` so that you can combine an add_error() /// @return `Failure::Errored::kError` so that you can combine an add_error()
/// call and return on the same line. /// call and return on the same line.
Failure::Errored add_error(const Source& source, const std::string& msg); Failure::Errored add_error(const Source& source, const std::string& msg);
/// Appends a deprecated-language-feature warning at `source` with the message
/// `msg`
/// @param source the source to associate the error with
/// @param msg the warning message
void deprecated(const Source& source, const std::string& msg);
/// Registers a constructed type into the parser /// Registers a constructed type into the parser
/// @param name the constructed name /// @param name the constructed name
/// @param type the constructed type /// @param type the constructed type

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, BodyStmt_Empty) {
} }
TEST_F(ParserImplTest, BodyStmt_InvalidStmt) { TEST_F(ParserImplTest, BodyStmt_InvalidStmt) {
auto p = parser("{fn main() -> void {}}"); auto p = parser("{fn main() {}}");
auto e = p->expect_body_stmt(); auto e = p->expect_body_stmt();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_TRUE(e.errored); ASSERT_TRUE(e.errored);

View File

@ -32,7 +32,7 @@ TEST_F(ParserImplTest, ElseStmt) {
} }
TEST_F(ParserImplTest, ElseStmt_InvalidBody) { TEST_F(ParserImplTest, ElseStmt_InvalidBody) {
auto p = parser("else { fn main() -> void {}}"); auto p = parser("else { fn main() {}}");
auto e = p->else_stmt(); auto e = p->else_stmt();
EXPECT_FALSE(e.matched); EXPECT_FALSE(e.matched);
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);

View File

@ -53,7 +53,7 @@ TEST_F(ParserImplTest, ElseIfStmt_Multiple) {
} }
TEST_F(ParserImplTest, ElseIfStmt_InvalidBody) { TEST_F(ParserImplTest, ElseIfStmt_InvalidBody) {
auto p = parser("elseif (true) { fn main() -> void {}}"); auto p = parser("elseif (true) { fn main() {}}");
auto e = p->elseif_stmt(); auto e = p->elseif_stmt();
EXPECT_FALSE(e.matched); EXPECT_FALSE(e.matched);
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);

View File

@ -38,179 +38,179 @@ class ParserImplErrorTest : public ParserImplTest {};
} while (false) } while (false)
TEST_F(ParserImplErrorTest, AdditiveInvalidExpr) { TEST_F(ParserImplErrorTest, AdditiveInvalidExpr) {
EXPECT("fn f() -> void { return 1.0 + <; }", EXPECT("fn f() { return 1.0 + <; }",
"test.wgsl:1:31 error: unable to parse right side of + expression\n" "test.wgsl:1:23 error: unable to parse right side of + expression\n"
"fn f() -> void { return 1.0 + <; }\n" "fn f() { return 1.0 + <; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, AndInvalidExpr) { TEST_F(ParserImplErrorTest, AndInvalidExpr) {
EXPECT("fn f() -> void { return 1 & >; }", EXPECT("fn f() { return 1 & >; }",
"test.wgsl:1:29 error: unable to parse right side of & expression\n" "test.wgsl:1:21 error: unable to parse right side of & expression\n"
"fn f() -> void { return 1 & >; }\n" "fn f() { return 1 & >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ArrayIndexExprInvalidExpr) { TEST_F(ParserImplErrorTest, ArrayIndexExprInvalidExpr) {
EXPECT("fn f() -> void { x = y[^]; }", EXPECT("fn f() { x = y[^]; }",
"test.wgsl:1:24 error: unable to parse expression inside []\n" "test.wgsl:1:16 error: unable to parse expression inside []\n"
"fn f() -> void { x = y[^]; }\n" "fn f() { x = y[^]; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ArrayIndexExprMissingRBracket) { TEST_F(ParserImplErrorTest, ArrayIndexExprMissingRBracket) {
EXPECT("fn f() -> void { x = y[1; }", EXPECT("fn f() { x = y[1; }",
"test.wgsl:1:25 error: expected ']' for array accessor\n" "test.wgsl:1:17 error: expected ']' for array accessor\n"
"fn f() -> void { x = y[1; }\n" "fn f() { x = y[1; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment) { TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment) {
EXPECT("fn f() -> void { a; }", EXPECT("fn f() { a; }",
"test.wgsl:1:19 error: expected '=' for assignment\n" "test.wgsl:1:11 error: expected '=' for assignment\n"
"fn f() -> void { a; }\n" "fn f() { a; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment2) { TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment2) {
EXPECT("fn f() -> void { a : i32; }", EXPECT("fn f() { a : i32; }",
"test.wgsl:1:18 error: expected 'var' for variable declaration\n" "test.wgsl:1:10 error: expected 'var' for variable declaration\n"
"fn f() -> void { a : i32; }\n" "fn f() { a : i32; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, AssignmentStmtMissingSemicolon) { TEST_F(ParserImplErrorTest, AssignmentStmtMissingSemicolon) {
EXPECT("fn f() -> void { a = 1 }", EXPECT("fn f() { a = 1 }",
"test.wgsl:1:24 error: expected ';' for assignment statement\n" "test.wgsl:1:16 error: expected ';' for assignment statement\n"
"fn f() -> void { a = 1 }\n" "fn f() { a = 1 }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, AssignmentStmtInvalidRHS) { TEST_F(ParserImplErrorTest, AssignmentStmtInvalidRHS) {
EXPECT("fn f() -> void { a = >; }", EXPECT("fn f() { a = >; }",
"test.wgsl:1:22 error: unable to parse right side of assignment\n" "test.wgsl:1:14 error: unable to parse right side of assignment\n"
"fn f() -> void { a = >; }\n" "fn f() { a = >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, BitcastExprMissingLessThan) { TEST_F(ParserImplErrorTest, BitcastExprMissingLessThan) {
EXPECT("fn f() -> void { x = bitcast(y); }", EXPECT("fn f() { x = bitcast(y); }",
"test.wgsl:1:29 error: expected '<' for bitcast expression\n" "test.wgsl:1:21 error: expected '<' for bitcast expression\n"
"fn f() -> void { x = bitcast(y); }\n" "fn f() { x = bitcast(y); }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, BitcastExprMissingGreaterThan) { TEST_F(ParserImplErrorTest, BitcastExprMissingGreaterThan) {
EXPECT("fn f() -> void { x = bitcast<u32(y); }", EXPECT("fn f() { x = bitcast<u32(y); }",
"test.wgsl:1:33 error: expected '>' for bitcast expression\n" "test.wgsl:1:25 error: expected '>' for bitcast expression\n"
"fn f() -> void { x = bitcast<u32(y); }\n" "fn f() { x = bitcast<u32(y); }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, BitcastExprMissingType) { TEST_F(ParserImplErrorTest, BitcastExprMissingType) {
EXPECT("fn f() -> void { x = bitcast<>(y); }", EXPECT("fn f() { x = bitcast<>(y); }",
"test.wgsl:1:30 error: invalid type for bitcast expression\n" "test.wgsl:1:22 error: invalid type for bitcast expression\n"
"fn f() -> void { x = bitcast<>(y); }\n" "fn f() { x = bitcast<>(y); }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, BreakStmtMissingSemicolon) {
EXPECT("fn f() -> void { loop { break } }",
"test.wgsl:1:31 error: expected ';' for break statement\n"
"fn f() -> void { loop { break } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, CallExprMissingRParen) {
EXPECT("fn f() -> void { x = f(1.; }",
"test.wgsl:1:26 error: expected ')' for call expression\n"
"fn f() -> void { x = f(1.; }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, CallStmtMissingRParen) {
EXPECT("fn f() -> void { f(1.; }",
"test.wgsl:1:22 error: expected ')' for call statement\n"
"fn f() -> void { f(1.; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, BreakStmtMissingSemicolon) {
EXPECT("fn f() { loop { break } }",
"test.wgsl:1:23 error: expected ';' for break statement\n"
"fn f() { loop { break } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, CallExprMissingRParen) {
EXPECT("fn f() { x = f(1.; }",
"test.wgsl:1:18 error: expected ')' for call expression\n"
"fn f() { x = f(1.; }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, CallStmtMissingRParen) {
EXPECT("fn f() { f(1.; }",
"test.wgsl:1:14 error: expected ')' for call statement\n"
"fn f() { f(1.; }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, CallStmtInvalidArgument0) { TEST_F(ParserImplErrorTest, CallStmtInvalidArgument0) {
EXPECT("fn f() -> void { f(<); }", EXPECT("fn f() { f(<); }",
"test.wgsl:1:20 error: unable to parse argument expression\n" "test.wgsl:1:12 error: unable to parse argument expression\n"
"fn f() -> void { f(<); }\n" "fn f() { f(<); }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, CallStmtInvalidArgument1) { TEST_F(ParserImplErrorTest, CallStmtInvalidArgument1) {
EXPECT( EXPECT(
"fn f() -> void { f(1.0, <); }", "fn f() { f(1.0, <); }",
"test.wgsl:1:25 error: unable to parse argument expression after comma\n" "test.wgsl:1:17 error: unable to parse argument expression after comma\n"
"fn f() -> void { f(1.0, <); }\n" "fn f() { f(1.0, <); }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, CallStmtMissingSemicolon) { TEST_F(ParserImplErrorTest, CallStmtMissingSemicolon) {
EXPECT("fn f() -> void { f() }", EXPECT("fn f() { f() }",
"test.wgsl:1:22 error: expected ';' for function call\n" "test.wgsl:1:14 error: expected ';' for function call\n"
"fn f() -> void { f() }\n" "fn f() { f() }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ConstructorExprMissingLParen) { TEST_F(ParserImplErrorTest, ConstructorExprMissingLParen) {
EXPECT("fn f() -> void { x = vec2<u32>1,2); }", EXPECT("fn f() { x = vec2<u32>1,2); }",
"test.wgsl:1:31 error: expected '(' for type constructor\n" "test.wgsl:1:23 error: expected '(' for type constructor\n"
"fn f() -> void { x = vec2<u32>1,2); }\n" "fn f() { x = vec2<u32>1,2); }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ConstructorExprMissingRParen) { TEST_F(ParserImplErrorTest, ConstructorExprMissingRParen) {
EXPECT("fn f() -> void { x = vec2<u32>(1,2; }", EXPECT("fn f() { x = vec2<u32>(1,2; }",
"test.wgsl:1:35 error: expected ')' for type constructor\n" "test.wgsl:1:27 error: expected ')' for type constructor\n"
"fn f() -> void { x = vec2<u32>(1,2; }\n" "fn f() { x = vec2<u32>(1,2; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ConstVarStmtInvalid) { TEST_F(ParserImplErrorTest, ConstVarStmtInvalid) {
EXPECT("fn f() -> void { const >; }", EXPECT("fn f() { const >; }",
"test.wgsl:1:24 error: expected identifier for constant declaration\n" "test.wgsl:1:16 error: expected identifier for constant declaration\n"
"fn f() -> void { const >; }\n" "fn f() { const >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ConstVarStmtMissingAssignment) { TEST_F(ParserImplErrorTest, ConstVarStmtMissingAssignment) {
EXPECT("fn f() -> void { const a : i32; }", EXPECT("fn f() { const a : i32; }",
"test.wgsl:1:31 error: expected '=' for constant declaration\n" "test.wgsl:1:23 error: expected '=' for constant declaration\n"
"fn f() -> void { const a : i32; }\n" "fn f() { const a : i32; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ConstVarStmtMissingConstructor) { TEST_F(ParserImplErrorTest, ConstVarStmtMissingConstructor) {
EXPECT("fn f() -> void { const a : i32 = >; }", EXPECT("fn f() { const a : i32 = >; }",
"test.wgsl:1:34 error: missing constructor for const declaration\n" "test.wgsl:1:26 error: missing constructor for const declaration\n"
"fn f() -> void { const a : i32 = >; }\n" "fn f() { const a : i32 = >; }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, ContinueStmtMissingSemicolon) {
EXPECT("fn f() -> void { loop { continue } }",
"test.wgsl:1:34 error: expected ';' for continue statement\n"
"fn f() -> void { loop { continue } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, DiscardStmtMissingSemicolon) {
EXPECT("fn f() -> void { discard }",
"test.wgsl:1:26 error: expected ';' for discard statement\n"
"fn f() -> void { discard }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ContinueStmtMissingSemicolon) {
EXPECT("fn f() { loop { continue } }",
"test.wgsl:1:26 error: expected ';' for continue statement\n"
"fn f() { loop { continue } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, DiscardStmtMissingSemicolon) {
EXPECT("fn f() { discard }",
"test.wgsl:1:18 error: expected ';' for discard statement\n"
"fn f() { discard }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, EqualityInvalidExpr) { TEST_F(ParserImplErrorTest, EqualityInvalidExpr) {
EXPECT("fn f() -> void { return 1 == >; }", EXPECT("fn f() { return 1 == >; }",
"test.wgsl:1:30 error: unable to parse right side of == expression\n" "test.wgsl:1:22 error: unable to parse right side of == expression\n"
"fn f() -> void { return 1 == >; }\n" "fn f() { return 1 == >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FloatLiteralSuffixedWithF) { TEST_F(ParserImplErrorTest, FloatLiteralSuffixedWithF) {
@ -221,52 +221,52 @@ TEST_F(ParserImplErrorTest, FloatLiteralSuffixedWithF) {
} }
TEST_F(ParserImplErrorTest, ForLoopInitializerMissingSemicolon) { TEST_F(ParserImplErrorTest, ForLoopInitializerMissingSemicolon) {
EXPECT("fn f() -> void { for (var i : i32 = 0 i < 8; i=i+1) {} }", EXPECT("fn f() { for (var i : i32 = 0 i < 8; i=i+1) {} }",
"test.wgsl:1:39 error: expected ';' for initializer in for loop\n" "test.wgsl:1:31 error: expected ';' for initializer in for loop\n"
"fn f() -> void { for (var i : i32 = 0 i < 8; i=i+1) {} }\n" "fn f() { for (var i : i32 = 0 i < 8; i=i+1) {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopInitializerMissingVar) { TEST_F(ParserImplErrorTest, ForLoopInitializerMissingVar) {
EXPECT("fn f() -> void { for (i : i32 = 0; i < 8; i=i+1) {} }", EXPECT("fn f() { for (i : i32 = 0; i < 8; i=i+1) {} }",
"test.wgsl:1:23 error: expected 'var' for variable declaration\n" "test.wgsl:1:15 error: expected 'var' for variable declaration\n"
"fn f() -> void { for (i : i32 = 0; i < 8; i=i+1) {} }\n" "fn f() { for (i : i32 = 0; i < 8; i=i+1) {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopConditionMissingSemicolon) { TEST_F(ParserImplErrorTest, ForLoopConditionMissingSemicolon) {
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8 i=i+1) {} }", EXPECT("fn f() { for (var i : i32 = 0; i < 8 i=i+1) {} }",
"test.wgsl:1:46 error: expected ';' for condition in for loop\n" "test.wgsl:1:38 error: expected ';' for condition in for loop\n"
"fn f() -> void { for (var i : i32 = 0; i < 8 i=i+1) {} }\n" "fn f() { for (var i : i32 = 0; i < 8 i=i+1) {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopMissingLParen) { TEST_F(ParserImplErrorTest, ForLoopMissingLParen) {
EXPECT("fn f() -> void { for var i : i32 = 0; i < 8; i=i+1) {} }", EXPECT("fn f() { for var i : i32 = 0; i < 8; i=i+1) {} }",
"test.wgsl:1:22 error: expected '(' for for loop\n" "test.wgsl:1:14 error: expected '(' for for loop\n"
"fn f() -> void { for var i : i32 = 0; i < 8; i=i+1) {} }\n" "fn f() { for var i : i32 = 0; i < 8; i=i+1) {} }\n"
" ^^^\n"); " ^^^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopMissingRParen) { TEST_F(ParserImplErrorTest, ForLoopMissingRParen) {
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1 {} }", EXPECT("fn f() { for (var i : i32 = 0; i < 8; i=i+1 {} }",
"test.wgsl:1:53 error: expected ')' for for loop\n" "test.wgsl:1:45 error: expected ')' for for loop\n"
"fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1 {} }\n" "fn f() { for (var i : i32 = 0; i < 8; i=i+1 {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopMissingLBrace) { TEST_F(ParserImplErrorTest, ForLoopMissingLBrace) {
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) }", EXPECT("fn f() { for (var i : i32 = 0; i < 8; i=i+1) }",
"test.wgsl:1:54 error: expected '{' for for loop\n" "test.wgsl:1:46 error: expected '{' for for loop\n"
"fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) }\n" "fn f() { for (var i : i32 = 0; i < 8; i=i+1) }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ForLoopMissingRBrace) { TEST_F(ParserImplErrorTest, ForLoopMissingRBrace) {
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) {", EXPECT("fn f() { for (var i : i32 = 0; i < 8; i=i+1) {",
"test.wgsl:1:55 error: expected '}' for for loop\n" "test.wgsl:1:47 error: expected '}' for for loop\n"
"fn f() -> void { for (var i : i32 = 0; i < 8; i=i+1) {\n" "fn f() { for (var i : i32 = 0; i < 8; i=i+1) {\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclInvalid) {
@ -277,150 +277,150 @@ TEST_F(ParserImplErrorTest, FunctionDeclInvalid) {
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoMissingEnd) { TEST_F(ParserImplErrorTest, FunctionDeclDecoMissingEnd) {
EXPECT("[[stage(vertex) fn f() -> void {}", EXPECT("[[stage(vertex) fn f() {}",
"test.wgsl:1:17 error: expected ']]' for decoration list\n" "test.wgsl:1:17 error: expected ']]' for decoration list\n"
"[[stage(vertex) fn f() -> void {}\n" "[[stage(vertex) fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoStageMissingLParen) { TEST_F(ParserImplErrorTest, FunctionDeclDecoStageMissingLParen) {
EXPECT("[[stage vertex]] fn f() -> void {}", EXPECT("[[stage vertex]] fn f() {}",
"test.wgsl:1:9 error: expected '(' for stage decoration\n" "test.wgsl:1:9 error: expected '(' for stage decoration\n"
"[[stage vertex]] fn f() -> void {}\n" "[[stage vertex]] fn f() {}\n"
" ^^^^^^\n"); " ^^^^^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoStageMissingRParen) { TEST_F(ParserImplErrorTest, FunctionDeclDecoStageMissingRParen) {
EXPECT("[[stage(vertex]] fn f() -> void {}", EXPECT("[[stage(vertex]] fn f() {}",
"test.wgsl:1:15 error: expected ')' for stage decoration\n" "test.wgsl:1:15 error: expected ')' for stage decoration\n"
"[[stage(vertex]] fn f() -> void {}\n" "[[stage(vertex]] fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoStageInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclDecoStageInvalid) {
EXPECT("[[stage(x)]] fn f() -> void {}", EXPECT("[[stage(x)]] fn f() {}",
"test.wgsl:1:9 error: invalid value for stage decoration\n" "test.wgsl:1:9 error: invalid value for stage decoration\n"
"[[stage(x)]] fn f() -> void {}\n" "[[stage(x)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoStageTypeInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclDecoStageTypeInvalid) {
EXPECT("[[shader(vertex)]] fn main() -> void {}", EXPECT("[[shader(vertex)]] fn main() {}",
"test.wgsl:1:3 error: expected decoration\n" "test.wgsl:1:3 error: expected decoration\n"
"[[shader(vertex)]] fn main() -> void {}\n" "[[shader(vertex)]] fn main() {}\n"
" ^^^^^^\n"); " ^^^^^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeMissingLParen) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeMissingLParen) {
EXPECT("[[workgroup_size 1]] fn f() -> void {}", EXPECT("[[workgroup_size 1]] fn f() {}",
"test.wgsl:1:18 error: expected '(' for workgroup_size decoration\n" "test.wgsl:1:18 error: expected '(' for workgroup_size decoration\n"
"[[workgroup_size 1]] fn f() -> void {}\n" "[[workgroup_size 1]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeMissingRParen) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeMissingRParen) {
EXPECT("[[workgroup_size(1]] fn f() -> void {}", EXPECT("[[workgroup_size(1]] fn f() {}",
"test.wgsl:1:19 error: expected ')' for workgroup_size decoration\n" "test.wgsl:1:19 error: expected ')' for workgroup_size decoration\n"
"[[workgroup_size(1]] fn f() -> void {}\n" "[[workgroup_size(1]] fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXInvalid) {
EXPECT("[[workgroup_size(x)]] fn f() -> void {}", EXPECT("[[workgroup_size(x)]] fn f() {}",
"test.wgsl:1:18 error: expected signed integer literal for " "test.wgsl:1:18 error: expected signed integer literal for "
"workgroup_size x parameter\n" "workgroup_size x parameter\n"
"[[workgroup_size(x)]] fn f() -> void {}\n" "[[workgroup_size(x)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXNegative) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXNegative) {
EXPECT("[[workgroup_size(-1)]] fn f() -> void {}", EXPECT("[[workgroup_size(-1)]] fn f() {}",
"test.wgsl:1:18 error: workgroup_size x parameter must be greater " "test.wgsl:1:18 error: workgroup_size x parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(-1)]] fn f() -> void {}\n" "[[workgroup_size(-1)]] fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXZero) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeXZero) {
EXPECT("[[workgroup_size(0)]] fn f() -> void {}", EXPECT("[[workgroup_size(0)]] fn f() {}",
"test.wgsl:1:18 error: workgroup_size x parameter must be greater " "test.wgsl:1:18 error: workgroup_size x parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(0)]] fn f() -> void {}\n" "[[workgroup_size(0)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYInvalid) {
EXPECT("[[workgroup_size(1, x)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, x)]] fn f() {}",
"test.wgsl:1:21 error: expected signed integer literal for " "test.wgsl:1:21 error: expected signed integer literal for "
"workgroup_size y parameter\n" "workgroup_size y parameter\n"
"[[workgroup_size(1, x)]] fn f() -> void {}\n" "[[workgroup_size(1, x)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYNegative) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYNegative) {
EXPECT("[[workgroup_size(1, -1)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, -1)]] fn f() {}",
"test.wgsl:1:21 error: workgroup_size y parameter must be greater " "test.wgsl:1:21 error: workgroup_size y parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(1, -1)]] fn f() -> void {}\n" "[[workgroup_size(1, -1)]] fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYZero) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeYZero) {
EXPECT("[[workgroup_size(1, 0)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, 0)]] fn f() {}",
"test.wgsl:1:21 error: workgroup_size y parameter must be greater " "test.wgsl:1:21 error: workgroup_size y parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(1, 0)]] fn f() -> void {}\n" "[[workgroup_size(1, 0)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZInvalid) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZInvalid) {
EXPECT("[[workgroup_size(1, 2, x)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, 2, x)]] fn f() {}",
"test.wgsl:1:24 error: expected signed integer literal for " "test.wgsl:1:24 error: expected signed integer literal for "
"workgroup_size z parameter\n" "workgroup_size z parameter\n"
"[[workgroup_size(1, 2, x)]] fn f() -> void {}\n" "[[workgroup_size(1, 2, x)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZNegative) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZNegative) {
EXPECT("[[workgroup_size(1, 2, -1)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, 2, -1)]] fn f() {}",
"test.wgsl:1:24 error: workgroup_size z parameter must be greater " "test.wgsl:1:24 error: workgroup_size z parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(1, 2, -1)]] fn f() -> void {}\n" "[[workgroup_size(1, 2, -1)]] fn f() {}\n"
" ^^\n"); " ^^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZZero) { TEST_F(ParserImplErrorTest, FunctionDeclDecoWorkgroupSizeZZero) {
EXPECT("[[workgroup_size(1, 2, 0)]] fn f() -> void {}", EXPECT("[[workgroup_size(1, 2, 0)]] fn f() {}",
"test.wgsl:1:24 error: workgroup_size z parameter must be greater " "test.wgsl:1:24 error: workgroup_size z parameter must be greater "
"than 0\n" "than 0\n"
"[[workgroup_size(1, 2, 0)]] fn f() -> void {}\n" "[[workgroup_size(1, 2, 0)]] fn f() {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingIdentifier) { TEST_F(ParserImplErrorTest, FunctionDeclMissingIdentifier) {
EXPECT("fn () -> void {}", EXPECT("fn () {}",
"test.wgsl:1:4 error: expected identifier for function declaration\n" "test.wgsl:1:4 error: expected identifier for function declaration\n"
"fn () -> void {}\n" "fn () {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingLParen) { TEST_F(ParserImplErrorTest, FunctionDeclMissingLParen) {
EXPECT("fn f) -> void {}", EXPECT("fn f) {}",
"test.wgsl:1:5 error: expected '(' for function declaration\n" "test.wgsl:1:5 error: expected '(' for function declaration\n"
"fn f) -> void {}\n" "fn f) {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingRParen) { TEST_F(ParserImplErrorTest, FunctionDeclMissingRParen) {
EXPECT("fn f( -> void {}", EXPECT("fn f( {}",
"test.wgsl:1:7 error: expected ')' for function declaration\n" "test.wgsl:1:7 error: expected ')' for function declaration\n"
"fn f( -> void {}\n" "fn f( {}\n"
" ^^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingArrow) { TEST_F(ParserImplErrorTest, FunctionDeclMissingArrow) {
EXPECT("fn f() void {}", EXPECT("fn f() void {}",
"test.wgsl:1:8 error: expected '->' for function declaration\n" "test.wgsl:1:8 error: expected '{'\n"
"fn f() void {}\n" "fn f() void {}\n"
" ^^^^\n"); " ^^^^\n");
} }
@ -433,38 +433,38 @@ TEST_F(ParserImplErrorTest, FunctionDeclInvalidReturnType) {
} }
TEST_F(ParserImplErrorTest, FunctionDeclParamMissingColon) { TEST_F(ParserImplErrorTest, FunctionDeclParamMissingColon) {
EXPECT("fn f(x) -> void {}", EXPECT("fn f(x) {}",
"test.wgsl:1:7 error: expected ':' for parameter\n" "test.wgsl:1:7 error: expected ':' for parameter\n"
"fn f(x) -> void {}\n" "fn f(x) {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclParamInvalidType) { TEST_F(ParserImplErrorTest, FunctionDeclParamInvalidType) {
EXPECT("fn f(x : 1) -> void {}", EXPECT("fn f(x : 1) {}",
"test.wgsl:1:10 error: invalid type for parameter\n" "test.wgsl:1:10 error: invalid type for parameter\n"
"fn f(x : 1) -> void {}\n" "fn f(x : 1) {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclParamMissing) { TEST_F(ParserImplErrorTest, FunctionDeclParamMissing) {
EXPECT("fn f(x : i32, ) -> void {}", EXPECT("fn f(x : i32, ) {}",
"test.wgsl:1:15 error: expected identifier for parameter\n" "test.wgsl:1:15 error: expected identifier for parameter\n"
"fn f(x : i32, ) -> void {}\n" "fn f(x : i32, ) {}\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingLBrace) { TEST_F(ParserImplErrorTest, FunctionDeclMissingLBrace) {
EXPECT("fn f() -> void }", EXPECT("fn f() }",
"test.wgsl:1:16 error: expected '{'\n" "test.wgsl:1:8 error: expected '{'\n"
"fn f() -> void }\n" "fn f() }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionDeclMissingRBrace) { TEST_F(ParserImplErrorTest, FunctionDeclMissingRBrace) {
EXPECT("fn f() -> void {", EXPECT("fn f() {",
"test.wgsl:1:17 error: expected '}'\n" "test.wgsl:1:9 error: expected '}'\n"
"fn f() -> void {\n" "fn f() {\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, FunctionMissingOpenLine) { TEST_F(ParserImplErrorTest, FunctionMissingOpenLine) {
@ -1127,52 +1127,52 @@ TEST_F(ParserImplErrorTest, GlobalDeclTextureExplicitStorageClass) {
} }
TEST_F(ParserImplErrorTest, IfStmtMissingLParen) { TEST_F(ParserImplErrorTest, IfStmtMissingLParen) {
EXPECT("fn f() -> void { if true) {} }", EXPECT("fn f() { if true) {} }",
"test.wgsl:1:21 error: expected '('\n" "test.wgsl:1:13 error: expected '('\n"
"fn f() -> void { if true) {} }\n" "fn f() { if true) {} }\n"
" ^^^^\n"); " ^^^^\n");
} }
TEST_F(ParserImplErrorTest, IfStmtMissingRParen) { TEST_F(ParserImplErrorTest, IfStmtMissingRParen) {
EXPECT("fn f() -> void { if (true {} }", EXPECT("fn f() { if (true {} }",
"test.wgsl:1:27 error: expected ')'\n" "test.wgsl:1:19 error: expected ')'\n"
"fn f() -> void { if (true {} }\n" "fn f() { if (true {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, IfStmtInvalidCond) { TEST_F(ParserImplErrorTest, IfStmtInvalidCond) {
EXPECT("fn f() -> void { if (>) {} }", EXPECT("fn f() { if (>) {} }",
"test.wgsl:1:22 error: unable to parse expression\n" "test.wgsl:1:14 error: unable to parse expression\n"
"fn f() -> void { if (>) {} }\n" "fn f() { if (>) {} }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, LogicalAndInvalidExpr) { TEST_F(ParserImplErrorTest, LogicalAndInvalidExpr) {
EXPECT("fn f() -> void { return 1 && >; }", EXPECT("fn f() { return 1 && >; }",
"test.wgsl:1:30 error: unable to parse right side of && expression\n" "test.wgsl:1:22 error: unable to parse right side of && expression\n"
"fn f() -> void { return 1 && >; }\n" "fn f() { return 1 && >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, LogicalOrInvalidExpr) { TEST_F(ParserImplErrorTest, LogicalOrInvalidExpr) {
EXPECT("fn f() -> void { return 1 || >; }", EXPECT("fn f() { return 1 || >; }",
"test.wgsl:1:30 error: unable to parse right side of || expression\n" "test.wgsl:1:22 error: unable to parse right side of || expression\n"
"fn f() -> void { return 1 || >; }\n" "fn f() { return 1 || >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, LoopMissingLBrace) { TEST_F(ParserImplErrorTest, LoopMissingLBrace) {
EXPECT("fn f() -> void { loop }", EXPECT("fn f() { loop }",
"test.wgsl:1:23 error: expected '{' for loop\n" "test.wgsl:1:15 error: expected '{' for loop\n"
"fn f() -> void { loop }\n" "fn f() { loop }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, LoopMissingRBrace) { TEST_F(ParserImplErrorTest, LoopMissingRBrace) {
EXPECT("fn f() -> void { loop {", EXPECT("fn f() { loop {",
"test.wgsl:1:24 error: expected '}' for loop\n" "test.wgsl:1:16 error: expected '}' for loop\n"
"fn f() -> void { loop {\n" "fn f() { loop {\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, MaxErrorsReached) { TEST_F(ParserImplErrorTest, MaxErrorsReached) {
@ -1196,123 +1196,123 @@ TEST_F(ParserImplErrorTest, MaxErrorsReached) {
} }
TEST_F(ParserImplErrorTest, MemberExprMissingIdentifier) { TEST_F(ParserImplErrorTest, MemberExprMissingIdentifier) {
EXPECT("fn f() -> void { x = a.; }", EXPECT("fn f() { x = a.; }",
"test.wgsl:1:24 error: expected identifier for member accessor\n" "test.wgsl:1:16 error: expected identifier for member accessor\n"
"fn f() -> void { x = a.; }\n" "fn f() { x = a.; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, MultiplicativeInvalidExpr) { TEST_F(ParserImplErrorTest, MultiplicativeInvalidExpr) {
EXPECT("fn f() -> void { return 1.0 * <; }", EXPECT("fn f() { return 1.0 * <; }",
"test.wgsl:1:31 error: unable to parse right side of * expression\n" "test.wgsl:1:23 error: unable to parse right side of * expression\n"
"fn f() -> void { return 1.0 * <; }\n" "fn f() { return 1.0 * <; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, OrInvalidExpr) { TEST_F(ParserImplErrorTest, OrInvalidExpr) {
EXPECT("fn f() -> void { return 1 | >; }", EXPECT("fn f() { return 1 | >; }",
"test.wgsl:1:29 error: unable to parse right side of | expression\n" "test.wgsl:1:21 error: unable to parse right side of | expression\n"
"fn f() -> void { return 1 | >; }\n" "fn f() { return 1 | >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, RelationalInvalidExpr) { TEST_F(ParserImplErrorTest, RelationalInvalidExpr) {
EXPECT("fn f() -> void { return 1 < >; }", EXPECT("fn f() { return 1 < >; }",
"test.wgsl:1:29 error: unable to parse right side of < expression\n" "test.wgsl:1:21 error: unable to parse right side of < expression\n"
"fn f() -> void { return 1 < >; }\n" "fn f() { return 1 < >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ReturnStmtMissingSemicolon) { TEST_F(ParserImplErrorTest, ReturnStmtMissingSemicolon) {
EXPECT("fn f() -> void { return }", EXPECT("fn f() { return }",
"test.wgsl:1:25 error: expected ';' for return statement\n" "test.wgsl:1:17 error: expected ';' for return statement\n"
"fn f() -> void { return }\n" "fn f() { return }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, ShiftInvalidExpr) { TEST_F(ParserImplErrorTest, ShiftInvalidExpr) {
EXPECT("fn f() -> void { return 1 << >; }", EXPECT("fn f() { return 1 << >; }",
"test.wgsl:1:30 error: unable to parse right side of << expression\n" "test.wgsl:1:22 error: unable to parse right side of << expression\n"
"fn f() -> void { return 1 << >; }\n" "fn f() { return 1 << >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtMissingLBrace) { TEST_F(ParserImplErrorTest, SwitchStmtMissingLBrace) {
EXPECT("fn f() -> void { switch(1) }", EXPECT("fn f() { switch(1) }",
"test.wgsl:1:28 error: expected '{' for switch statement\n" "test.wgsl:1:20 error: expected '{' for switch statement\n"
"fn f() -> void { switch(1) }\n" "fn f() { switch(1) }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtMissingRBrace) { TEST_F(ParserImplErrorTest, SwitchStmtMissingRBrace) {
EXPECT("fn f() -> void { switch(1) {", EXPECT("fn f() { switch(1) {",
"test.wgsl:1:29 error: expected '}' for switch statement\n" "test.wgsl:1:21 error: expected '}' for switch statement\n"
"fn f() -> void { switch(1) {\n" "fn f() { switch(1) {\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtInvalidCase) { TEST_F(ParserImplErrorTest, SwitchStmtInvalidCase) {
EXPECT("fn f() -> void { switch(1) { case ^: } }", EXPECT("fn f() { switch(1) { case ^: } }",
"test.wgsl:1:35 error: unable to parse case selectors\n" "test.wgsl:1:27 error: unable to parse case selectors\n"
"fn f() -> void { switch(1) { case ^: } }\n" "fn f() { switch(1) { case ^: } }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtInvalidCase2) { TEST_F(ParserImplErrorTest, SwitchStmtInvalidCase2) {
EXPECT( EXPECT(
"fn f() -> void { switch(1) { case false: } }", "fn f() { switch(1) { case false: } }",
"test.wgsl:1:35 error: invalid case selector must be an integer value\n" "test.wgsl:1:27 error: invalid case selector must be an integer value\n"
"fn f() -> void { switch(1) { case false: } }\n" "fn f() { switch(1) { case false: } }\n"
" ^^^^^\n"); " ^^^^^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingColon) { TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingColon) {
EXPECT("fn f() -> void { switch(1) { case 1 {} } }", EXPECT("fn f() { switch(1) { case 1 {} } }",
"test.wgsl:1:37 error: expected ':' for case statement\n" "test.wgsl:1:29 error: expected ':' for case statement\n"
"fn f() -> void { switch(1) { case 1 {} } }\n" "fn f() { switch(1) { case 1 {} } }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingLBrace) { TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingLBrace) {
EXPECT("fn f() -> void { switch(1) { case 1: } }", EXPECT("fn f() { switch(1) { case 1: } }",
"test.wgsl:1:38 error: expected '{' for case statement\n" "test.wgsl:1:30 error: expected '{' for case statement\n"
"fn f() -> void { switch(1) { case 1: } }\n" "fn f() { switch(1) { case 1: } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingRBrace) {
EXPECT("fn f() -> void { switch(1) { case 1: {",
"test.wgsl:1:39 error: expected '}' for case statement\n"
"fn f() -> void { switch(1) { case 1: {\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, SwitchStmtCaseFallthroughMissingSemicolon) {
EXPECT("fn f() -> void { switch(1) { case 1: { fallthrough } case 2: {} } }",
"test.wgsl:1:52 error: expected ';' for fallthrough statement\n"
"fn f() -> void { switch(1) { case 1: { fallthrough } case 2: {} } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, VarStmtMissingSemicolon) {
EXPECT("fn f() -> void { var a : u32 }",
"test.wgsl:1:30 error: expected ';' for variable declaration\n"
"fn f() -> void { var a : u32 }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, SwitchStmtCaseMissingRBrace) {
EXPECT("fn f() { switch(1) { case 1: {",
"test.wgsl:1:31 error: expected '}' for case statement\n"
"fn f() { switch(1) { case 1: {\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, SwitchStmtCaseFallthroughMissingSemicolon) {
EXPECT("fn f() { switch(1) { case 1: { fallthrough } case 2: {} } }",
"test.wgsl:1:44 error: expected ';' for fallthrough statement\n"
"fn f() { switch(1) { case 1: { fallthrough } case 2: {} } }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, VarStmtMissingSemicolon) {
EXPECT("fn f() { var a : u32 }",
"test.wgsl:1:22 error: expected ';' for variable declaration\n"
"fn f() { var a : u32 }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, VarStmtInvalidAssignment) { TEST_F(ParserImplErrorTest, VarStmtInvalidAssignment) {
EXPECT("fn f() -> void { var a : u32 = >; }", EXPECT("fn f() { var a : u32 = >; }",
"test.wgsl:1:32 error: missing constructor for variable declaration\n" "test.wgsl:1:24 error: missing constructor for variable declaration\n"
"fn f() -> void { var a : u32 = >; }\n" "fn f() { var a : u32 = >; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, UnaryInvalidExpr) { TEST_F(ParserImplErrorTest, UnaryInvalidExpr) {
EXPECT("fn f() -> void { return !<; }", EXPECT("fn f() { return !<; }",
"test.wgsl:1:26 error: unable to parse right side of ! expression\n" "test.wgsl:1:18 error: unable to parse right side of ! expression\n"
"fn f() -> void { return !<; }\n" "fn f() { return !<; }\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, UnexpectedToken) { TEST_F(ParserImplErrorTest, UnexpectedToken) {
@ -1323,10 +1323,10 @@ TEST_F(ParserImplErrorTest, UnexpectedToken) {
} }
TEST_F(ParserImplErrorTest, XorInvalidExpr) { TEST_F(ParserImplErrorTest, XorInvalidExpr) {
EXPECT("fn f() -> void { return 1 ^ >; }", EXPECT("fn f() { return 1 ^ >; }",
"test.wgsl:1:29 error: unable to parse right side of ^ expression\n" "test.wgsl:1:21 error: unable to parse right side of ^ expression\n"
"fn f() -> void { return 1 ^ >; }\n" "fn f() { return 1 ^ >; }\n"
" ^\n"); " ^\n");
} }
} // namespace } // namespace

View File

@ -39,9 +39,9 @@ class ParserImplErrorResyncTest : public ParserImplTest {};
TEST_F(ParserImplErrorResyncTest, BadFunctionDecls) { TEST_F(ParserImplErrorResyncTest, BadFunctionDecls) {
EXPECT(R"( EXPECT(R"(
fn .() -> . {} fn .() -> . {}
fn x(.) . {} fn x(.) {}
[[.,.]] fn -> {} [[.,.]] fn -> {}
fn good() -> void {} fn good() {}
)", )",
"test.wgsl:2:4 error: expected identifier for function declaration\n" "test.wgsl:2:4 error: expected identifier for function declaration\n"
"fn .() -> . {}\n" "fn .() -> . {}\n"
@ -52,13 +52,9 @@ fn good() -> void {}
" ^\n" " ^\n"
"\n" "\n"
"test.wgsl:3:6 error: expected ')' for function declaration\n" "test.wgsl:3:6 error: expected ')' for function declaration\n"
"fn x(.) . {}\n" "fn x(.) {}\n"
" ^\n" " ^\n"
"\n" "\n"
"test.wgsl:3:9 error: expected '->' for function declaration\n"
"fn x(.) . {}\n"
" ^\n"
"\n"
"test.wgsl:4:3 error: expected decoration\n" "test.wgsl:4:3 error: expected decoration\n"
"[[.,.]] fn -> {}\n" "[[.,.]] fn -> {}\n"
" ^\n" " ^\n"
@ -74,7 +70,7 @@ fn good() -> void {}
TEST_F(ParserImplErrorResyncTest, AssignmentStatement) { TEST_F(ParserImplErrorResyncTest, AssignmentStatement) {
EXPECT(R"( EXPECT(R"(
fn f() -> void { fn f() {
blah blah blah blah; blah blah blah blah;
good = 1; good = 1;
blah blah blah blah; blah blah blah blah;
@ -97,7 +93,7 @@ fn f() -> void {
TEST_F(ParserImplErrorResyncTest, DiscardStatement) { TEST_F(ParserImplErrorResyncTest, DiscardStatement) {
EXPECT(R"( EXPECT(R"(
fn f() -> void { fn f() {
discard blah blah blah; discard blah blah blah;
a = 1; a = 1;
discard blah blah blah; discard blah blah blah;
@ -142,7 +138,7 @@ struct S {
// scope. // scope.
TEST_F(ParserImplErrorResyncTest, NestedSyncPoints) { TEST_F(ParserImplErrorResyncTest, NestedSyncPoints) {
EXPECT(R"( EXPECT(R"(
fn f() -> void { fn f() {
x = 1; x = 1;
discard discard
} }
@ -160,7 +156,7 @@ struct S { blah };
TEST_F(ParserImplErrorResyncTest, BracketCounting) { TEST_F(ParserImplErrorResyncTest, BracketCounting) {
EXPECT(R"( EXPECT(R"(
[[woof[[[[]]]]]] [[woof[[[[]]]]]]
fn f(x(((())))) -> void { fn f(x(((())))) {
meow = {{{}}} meow = {{{}}}
} }
struct S { blah }; struct S { blah };
@ -170,7 +166,7 @@ struct S { blah };
" ^^^^\n" " ^^^^\n"
"\n" "\n"
"test.wgsl:3:7 error: expected ':' for parameter\n" "test.wgsl:3:7 error: expected ':' for parameter\n"
"fn f(x(((())))) -> void {\n" "fn f(x(((())))) {\n"
" ^\n" " ^\n"
"\n" "\n"
"test.wgsl:4:10 error: unable to parse right side of assignment\n" "test.wgsl:4:10 error: unable to parse right side of assignment\n"

View File

@ -274,7 +274,7 @@ TEST_F(ForStmtErrorTest, InvalidBody) {
// Test a for loop with a body not matching statements // Test a for loop with a body not matching statements
TEST_F(ForStmtErrorTest, InvalidBodyMatch) { TEST_F(ForStmtErrorTest, InvalidBodyMatch) {
std::string for_str = "for (;;) { fn main() -> void {} }"; std::string for_str = "for (;;) { fn main() {} }";
std::string error_str = "1:12: expected '}' for for loop"; std::string error_str = "1:12: expected '}' for for loop";
TestForWithError(for_str, error_str); TestForWithError(for_str, error_str);

View File

@ -21,7 +21,7 @@ namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, FunctionDecl) { TEST_F(ParserImplTest, FunctionDecl) {
auto p = parser("fn main(a : i32, b : f32) -> void { return; }"); auto p = parser("fn main(a : i32, b : f32) { return; }");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decos.errored); ASSERT_FALSE(decos.errored);
@ -49,7 +49,7 @@ TEST_F(ParserImplTest, FunctionDecl) {
} }
TEST_F(ParserImplTest, FunctionDecl_DecorationList) { TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
auto p = parser("[[workgroup_size(2, 3, 4)]] fn main() -> void { return; }"); auto p = parser("[[workgroup_size(2, 3, 4)]] fn main() { return; }");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decos.errored); ASSERT_FALSE(decos.errored);
@ -87,7 +87,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleEntries) { TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleEntries) {
auto p = parser(R"( auto p = parser(R"(
[[workgroup_size(2, 3, 4), workgroup_size(5, 6, 7)]] [[workgroup_size(2, 3, 4), workgroup_size(5, 6, 7)]]
fn main() -> void { return; })"); fn main() { return; })");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decos.errored); ASSERT_FALSE(decos.errored);
@ -132,7 +132,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleLists) {
auto p = parser(R"( auto p = parser(R"(
[[workgroup_size(2, 3, 4)]] [[workgroup_size(2, 3, 4)]]
[[workgroup_size(5, 6, 7)]] [[workgroup_size(5, 6, 7)]]
fn main() -> void { return; })"); fn main() { return; })");
auto decorations = p->decoration_list(); auto decorations = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decorations.errored); ASSERT_FALSE(decorations.errored);
@ -219,7 +219,7 @@ TEST_F(ParserImplTest, FunctionDecl_InvalidHeader) {
} }
TEST_F(ParserImplTest, FunctionDecl_InvalidBody) { TEST_F(ParserImplTest, FunctionDecl_InvalidBody) {
auto p = parser("fn main() -> void { return }"); auto p = parser("fn main() { return }");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decos.errored); ASSERT_FALSE(decos.errored);
@ -229,11 +229,11 @@ TEST_F(ParserImplTest, FunctionDecl_InvalidBody) {
EXPECT_FALSE(f.matched); EXPECT_FALSE(f.matched);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(f.value, nullptr); EXPECT_EQ(f.value, nullptr);
EXPECT_EQ(p->error(), "1:28: expected ';' for return statement"); EXPECT_EQ(p->error(), "1:20: expected ';' for return statement");
} }
TEST_F(ParserImplTest, FunctionDecl_MissingLeftBrace) { TEST_F(ParserImplTest, FunctionDecl_MissingLeftBrace) {
auto p = parser("fn main() -> void return; }"); auto p = parser("fn main() return; }");
auto decos = p->decoration_list(); auto decos = p->decoration_list();
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(decos.errored); ASSERT_FALSE(decos.errored);
@ -243,7 +243,7 @@ TEST_F(ParserImplTest, FunctionDecl_MissingLeftBrace) {
EXPECT_FALSE(f.matched); EXPECT_FALSE(f.matched);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(f.value, nullptr); EXPECT_EQ(f.value, nullptr);
EXPECT_EQ(p->error(), "1:19: expected '{'"); EXPECT_EQ(p->error(), "1:11: expected '{'");
} }
} // namespace } // namespace

View File

@ -20,7 +20,7 @@ namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, FunctionHeader) { TEST_F(ParserImplTest, FunctionHeader) {
auto p = parser("fn main(a : i32, b: f32) -> void"); auto p = parser("fn main(a : i32, b: f32)");
auto f = p->function_header(); auto f = p->function_header();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(f.matched); EXPECT_TRUE(f.matched);
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType) {
} }
TEST_F(ParserImplTest, FunctionHeader_MissingIdent) { TEST_F(ParserImplTest, FunctionHeader_MissingIdent) {
auto p = parser("fn () -> void"); auto p = parser("fn ()");
auto f = p->function_header(); auto f = p->function_header();
EXPECT_FALSE(f.matched); EXPECT_FALSE(f.matched);
EXPECT_TRUE(f.errored); EXPECT_TRUE(f.errored);
@ -94,15 +94,6 @@ TEST_F(ParserImplTest, FunctionHeader_MissingParenRight) {
EXPECT_EQ(p->error(), "1:10: expected ')' for function declaration"); EXPECT_EQ(p->error(), "1:10: expected ')' for function declaration");
} }
TEST_F(ParserImplTest, FunctionHeader_MissingArrow) {
auto p = parser("fn main() i32");
auto f = p->function_header();
EXPECT_FALSE(f.matched);
EXPECT_TRUE(f.errored);
EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:11: expected '->' for function declaration");
}
TEST_F(ParserImplTest, FunctionHeader_InvalidReturnType) { TEST_F(ParserImplTest, FunctionHeader_InvalidReturnType) {
auto p = parser("fn main() -> invalid"); auto p = parser("fn main() -> invalid");
auto f = p->function_header(); auto f = p->function_header();
@ -121,6 +112,19 @@ TEST_F(ParserImplTest, FunctionHeader_MissingReturnType) {
EXPECT_EQ(p->error(), "1:13: unable to determine function return type"); EXPECT_EQ(p->error(), "1:13: unable to determine function return type");
} }
TEST_F(ParserImplTest, FunctionHeader_ArrowVoid) {
auto p = parser("fn main() -> void");
auto f = p->function_header();
EXPECT_TRUE(f.matched);
EXPECT_FALSE(f.errored);
EXPECT_EQ(
p->builder().Diagnostics().str(),
R"(test.wgsl:1:14 warning: use of deprecated language feature: omit '-> void' for functions that do not return a value
fn main() -> void
^^^^
)");
}
} // namespace } // namespace
} // namespace wgsl } // namespace wgsl
} // namespace reader } // namespace reader

View File

@ -127,7 +127,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) {
} }
TEST_F(ParserImplTest, GlobalDecl_Function) { TEST_F(ParserImplTest, GlobalDecl_Function) {
auto p = parser("fn main() -> void { return; }"); auto p = parser("fn main() { return; }");
p->expect_global_decl(); p->expect_global_decl();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
@ -138,7 +138,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
} }
TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) { TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
auto p = parser("[[workgroup_size(2)]] fn main() -> void { return; }"); auto p = parser("[[workgroup_size(2)]] fn main() { return; }");
p->expect_global_decl(); p->expect_global_decl();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();

View File

@ -78,7 +78,7 @@ TEST_F(ParserImplTest, IfStmt_MissingCondition) {
} }
TEST_F(ParserImplTest, IfStmt_InvalidBody) { TEST_F(ParserImplTest, IfStmt_InvalidBody) {
auto p = parser("if (a) { fn main() -> void {}}"); auto p = parser("if (a) { fn main() {}}");
auto e = p->if_stmt(); auto e = p->if_stmt();
EXPECT_FALSE(e.matched); EXPECT_FALSE(e.matched);
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);

View File

@ -93,7 +93,7 @@ TEST_F(ParserImplTest, SwitchBody_Case_MissingBracketRight) {
} }
TEST_F(ParserImplTest, SwitchBody_Case_InvalidCaseBody) { TEST_F(ParserImplTest, SwitchBody_Case_InvalidCaseBody) {
auto p = parser("case 1: { fn main() -> void {} }"); auto p = parser("case 1: { fn main() {} }");
auto e = p->switch_body(); auto e = p->switch_body();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
@ -201,7 +201,7 @@ TEST_F(ParserImplTest, SwitchBody_Default_MissingBracketRight) {
} }
TEST_F(ParserImplTest, SwitchBody_Default_InvalidCaseBody) { TEST_F(ParserImplTest, SwitchBody_Default_InvalidCaseBody) {
auto p = parser("default: { fn main() -> void {} }"); auto p = parser("default: { fn main() {} }");
auto e = p->switch_body(); auto e = p->switch_body();
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);

View File

@ -29,7 +29,7 @@ TEST_F(ParserImplTest, Parses) {
[[location(0)]] var<out> gl_FragColor : vec4<f32>; [[location(0)]] var<out> gl_FragColor : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
gl_FragColor = vec4<f32>(.4, .2, .3, 1); gl_FragColor = vec4<f32>(.4, .2, .3, 1);
} }
)"); )");

View File

@ -37,7 +37,7 @@ TEST_F(ParserTest, Parses) {
[[location(0)]] var<out> gl_FragColor : vec4<f32>; [[location(0)]] var<out> gl_FragColor : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
gl_FragColor = vec4<f32>(.4, .2, .3, 1.); gl_FragColor = vec4<f32>(.4, .2, .3, 1.);
} }
)"); )");

View File

@ -48,7 +48,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
TEST_F(ResolverFunctionValidationTest, TEST_F(ResolverFunctionValidationTest,
VoidFunctionEndWithoutReturnStatement_Pass) { VoidFunctionEndWithoutReturnStatement_Pass) {
// [[stage(vertex)]] // [[stage(vertex)]]
// fn func -> void { var a:i32 = 2; } // fn func { var a:i32 = 2; }
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
@ -83,7 +83,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
TEST_F(ResolverFunctionValidationTest, TEST_F(ResolverFunctionValidationTest,
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) { VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
// [[stage(vertex)]] // [[stage(vertex)]]
// fn func -> void {} // fn func {}
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(), ast::StatementList{}, ty.void_(), ast::StatementList{},
@ -110,7 +110,7 @@ TEST_F(ResolverFunctionValidationTest,
TEST_F(ResolverFunctionValidationTest, TEST_F(ResolverFunctionValidationTest,
FunctionTypeMustMatchReturnStatementType_Pass) { FunctionTypeMustMatchReturnStatementType_Pass) {
// [[stage(vertex)]] // [[stage(vertex)]]
// fn func -> void { return; } // fn func { return; }
Func("func", ast::VariableList{}, ty.void_(), Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
@ -125,7 +125,7 @@ TEST_F(ResolverFunctionValidationTest,
TEST_F(ResolverFunctionValidationTest, TEST_F(ResolverFunctionValidationTest,
FunctionTypeMustMatchReturnStatementType_fail) { FunctionTypeMustMatchReturnStatementType_fail) {
// fn func -> void { return 2; } // fn func { return 2; }
Func("func", ast::VariableList{}, ty.void_(), Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
@ -216,7 +216,7 @@ TEST_F(ResolverFunctionValidationTest,
TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) { TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
// [[stage(fragment)]] // [[stage(fragment)]]
// [[stage(vertex)]] // [[stage(vertex)]]
// fn main() -> void { return; } // fn main() { return; }
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
ty.void_(), ty.void_(),
ast::StatementList{ ast::StatementList{
@ -244,7 +244,7 @@ TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
} }
TEST_F(ResolverFunctionValidationTest, FunctionVarInitWithParam) { TEST_F(ResolverFunctionValidationTest, FunctionVarInitWithParam) {
// fn foo(bar : f32) -> void{ // fn foo(bar : f32){
// var baz : f32 = bar; // var baz : f32 = bar;
// } // }
@ -258,7 +258,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionVarInitWithParam) {
} }
TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) { TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) {
// fn foo(bar : f32) -> void{ // fn foo(bar : f32){
// const baz : f32 = bar; // const baz : f32 = bar;
// } // }

View File

@ -285,7 +285,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) {
} }
TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) { TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
// fn func_i32() -> void { // fn func_i32() {
// { // {
// var foo : i32 = 2; // var foo : i32 = 2;
// var bar : i32 = foo; // var bar : i32 = foo;
@ -345,11 +345,11 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
} }
TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) { TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
// fn func_i32() -> void { // fn func_i32() {
// var foo : i32 = 2; // var foo : i32 = 2;
// } // }
// var foo : f32 = 2.0; // var foo : f32 = 2.0;
// fn func_f32() -> void { // fn func_f32() {
// var bar : f32 = foo; // var bar : f32 = foo;
// } // }

View File

@ -154,7 +154,7 @@ TEST_P(InferTypeTest_FromCallExpression, All) {
// return vec3<f32>(0.0, 0.0, 0.0); // return vec3<f32>(0.0, 0.0, 0.0);
// } // }
// //
// fn bar() -> void // fn bar()
// { // {
// var a = foo(); // var a = foo();
// } // }

View File

@ -111,7 +111,7 @@ TEST_F(ResolverTypeValidationTest, GlobalVariableNotUnique_Fail) {
TEST_F(ResolverTypeValidationTest, TEST_F(ResolverTypeValidationTest,
GlobalVariableFunctionVariableNotUnique_Pass) { GlobalVariableFunctionVariableNotUnique_Pass) {
// fn my_func -> void { // fn my_func() {
// var a: f32 = 2.0; // var a: f32 = 2.0;
// } // }
// var a: f32 = 2.1; // var a: f32 = 2.1;
@ -130,7 +130,7 @@ TEST_F(ResolverTypeValidationTest,
TEST_F(ResolverTypeValidationTest, TEST_F(ResolverTypeValidationTest,
GlobalVariableFunctionVariableNotUnique_Fail) { GlobalVariableFunctionVariableNotUnique_Fail) {
// var a: f32 = 2.1; // var a: f32 = 2.1;
// fn my_func -> void { // fn my_func() {
// var a: f32 = 2.0; // var a: f32 = 2.0;
// return 0; // return 0;
// } // }
@ -150,7 +150,7 @@ TEST_F(ResolverTypeValidationTest,
} }
TEST_F(ResolverTypeValidationTest, RedeclaredIdentifier_Fail) { TEST_F(ResolverTypeValidationTest, RedeclaredIdentifier_Fail) {
// fn my_func() -> void { // fn my_func()() {
// var a :i32 = 2; // var a :i32 = 2;
// var a :f21 = 2.0; // var a :f21 = 2.0;
// } // }
@ -293,7 +293,7 @@ TEST_F(ResolverTypeValidationTest,
TEST_F(ResolverTypeValidationTest, RuntimeArrayInFunction_Fail) { TEST_F(ResolverTypeValidationTest, RuntimeArrayInFunction_Fail) {
/// [[stage(vertex)]] /// [[stage(vertex)]]
// fn func -> void { var a : array<i32>; } // fn func() { var a : array<i32>; }
auto* var = auto* var =
Var(Source{{12, 34}}, "a", ty.array<i32>(), ast::StorageClass::kNone); Var(Source{{12, 34}}, "a", ty.array<i32>(), ast::StorageClass::kNone);

View File

@ -83,8 +83,8 @@ TEST_F(ResolverValidationTest, Stmt_Error_Unknown) {
} }
TEST_F(ResolverValidationTest, Stmt_Call_undeclared) { TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
// fn main() -> void {func(); return; } // fn main() {func(); return; }
// fn func() -> void { return; } // fn func() { return; }
SetSource(Source::Location{12, 34}); SetSource(Source::Location{12, 34});
auto* call_expr = Call("func"); auto* call_expr = Call("func");
@ -110,7 +110,7 @@ TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
} }
TEST_F(ResolverValidationTest, Stmt_Call_recursive) { TEST_F(ResolverValidationTest, Stmt_Call_recursive) {
// fn main() -> void {main(); } // fn main() {main(); }
SetSource(Source::Location{12, 34}); SetSource(Source::Location{12, 34});
auto* call_expr = Call("main"); auto* call_expr = Call("main");
@ -241,7 +241,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInBlockStatement_Fail) {
} }
TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) { TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
// fn my_func() -> void { // fn my_func() {
// global_var = 3.14f; // global_var = 3.14f;
// } // }
// var global_var: f32 = 2.1; // var global_var: f32 = 2.1;
@ -266,7 +266,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariable_Pass) { TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariable_Pass) {
// var global_var: f32 = 2.1; // var global_var: f32 = 2.1;
// fn my_func() -> void { // fn my_func() {
// global_var = 3.14; // global_var = 3.14;
// return; // return;
// } // }

View File

@ -35,7 +35,7 @@ struct S {
[[group(3), binding(2)]] var<storage> b : S; [[group(3), binding(2)]] var<storage> b : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -60,7 +60,7 @@ struct S {
[[group(3), binding(2)]] var<storage> b : S; [[group(3), binding(2)]] var<storage> b : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -74,7 +74,7 @@ struct S {
[[group(3), binding(2)]] var<storage> b : S; [[group(3), binding(2)]] var<storage> b : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -106,7 +106,7 @@ S;
[[group(4), binding(3)]] var<storage> c : S; [[group(4), binding(3)]] var<storage> c : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -125,7 +125,7 @@ S;
S; S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -165,7 +165,7 @@ type A = S;
[[group(4), binding(3)]] var<storage> c : A; [[group(4), binding(3)]] var<storage> c : A;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -190,7 +190,7 @@ S;
[[group(4), binding(3)]] var<storage> c : [[access(write)]] S; [[group(4), binding(3)]] var<storage> c : [[access(write)]] S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -219,7 +219,7 @@ S;
[[group(3), binding(2)]] var<storage> b : S; [[group(3), binding(2)]] var<storage> b : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -235,7 +235,7 @@ S;
S; S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void { fn f() {
} }
)"; )";
@ -264,7 +264,7 @@ struct S {
[[group(3), binding(2)]] var<storage> b : S; [[group(3), binding(2)]] var<storage> b : S;
[[stage(compute)]] [[stage(compute)]]
fn f() -> void {} fn f() {}
)"; )";
auto* expect = "error: BindingRemapper did not find the remapping data"; auto* expect = "error: BindingRemapper did not find the remapping data";

View File

@ -28,7 +28,7 @@ var<storage> a : array<f32, 3>;
const c : u32 = 1u; const c : u32 = 1u;
fn f() -> void { fn f() {
const b : ptr<storage, f32> = a[c]; const b : ptr<storage, f32> = a[c];
} }
)"; )";
@ -38,7 +38,7 @@ var<storage> a : array<f32, 3>;
const c : u32 = 1u; const c : u32 = 1u;
fn f() -> void { fn f() {
const b : ptr<storage, f32> = a[min(u32(c), 2u)]; const b : ptr<storage, f32> = a[min(u32(c), 2u)];
} }
)"; )";
@ -56,7 +56,7 @@ var<in> b : array<f32, 5>;
var<in> i : u32; var<in> i : u32;
fn f() -> void { fn f() {
var c : f32 = a[ b[i] ]; var c : f32 = a[ b[i] ];
} }
)"; )";
@ -68,7 +68,7 @@ var<in> b : array<f32, 5>;
var<in> i : u32; var<in> i : u32;
fn f() -> void { fn f() {
var c : f32 = a[min(u32(b[min(u32(i), 4u)]), 2u)]; var c : f32 = a[min(u32(b[min(u32(i), 4u)]), 2u)];
} }
)"; )";
@ -82,7 +82,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
auto* src = R"( auto* src = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[1]; var b : f32 = a[1];
} }
)"; )";
@ -90,7 +90,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[1]; var b : f32 = a[1];
} }
)"; )";
@ -106,7 +106,7 @@ var<in> a : array<f32, 3>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[c + 2 - 3]; var b : f32 = a[c + 2 - 3];
} }
)"; )";
@ -116,7 +116,7 @@ var<in> a : array<f32, 3>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)]; var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
} }
)"; )";
@ -130,7 +130,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
auto* src = R"( auto* src = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[-1]; var b : f32 = a[-1];
} }
)"; )";
@ -138,7 +138,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[0]; var b : f32 = a[0];
} }
)"; )";
@ -152,7 +152,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
auto* src = R"( auto* src = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[3]; var b : f32 = a[3];
} }
)"; )";
@ -160,7 +160,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : array<f32, 3>; var<in> a : array<f32, 3>;
fn f() -> void { fn f() {
var b : f32 = a[2]; var b : f32 = a[2];
} }
)"; )";
@ -174,7 +174,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
auto* src = R"( auto* src = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[1]; var b : f32 = a[1];
} }
)"; )";
@ -182,7 +182,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[1]; var b : f32 = a[1];
} }
)"; )";
@ -198,7 +198,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[c + 2 - 3]; var b : f32 = a[c + 2 - 3];
} }
)"; )";
@ -208,7 +208,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)]; var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
} }
)"; )";
@ -222,7 +222,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Scalar) {
auto* src = R"( auto* src = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a.xy[2]; var b : f32 = a.xy[2];
} }
)"; )";
@ -230,7 +230,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a.xy[1]; var b : f32 = a.xy[1];
} }
)"; )";
@ -246,7 +246,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a.xy[c]; var b : f32 = a.xy[c];
} }
)"; )";
@ -256,7 +256,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a.xy[min(u32(c), 1u)]; var b : f32 = a.xy[min(u32(c), 1u)];
} }
)"; )";
@ -271,7 +271,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a.xy[c + 2 - 3]; var b : f32 = a.xy[c + 2 - 3];
} }
)"; )";
@ -281,7 +281,7 @@ var<in> a : vec3<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)]; var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)];
} }
)"; )";
@ -295,7 +295,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
auto* src = R"( auto* src = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[-1]; var b : f32 = a[-1];
} }
)"; )";
@ -303,7 +303,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[0]; var b : f32 = a[0];
} }
)"; )";
@ -317,7 +317,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
auto* src = R"( auto* src = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[3]; var b : f32 = a[3];
} }
)"; )";
@ -325,7 +325,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : vec3<f32>; var<in> a : vec3<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2]; var b : f32 = a[2];
} }
)"; )";
@ -339,7 +339,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
auto* src = R"( auto* src = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][1]; var b : f32 = a[2][1];
} }
)"; )";
@ -347,7 +347,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][1]; var b : f32 = a[2][1];
} }
)"; )";
@ -363,7 +363,7 @@ var<in> a : mat3x2<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[c + 2 - 3][1]; var b : f32 = a[c + 2 - 3][1];
} }
)"; )";
@ -373,7 +373,7 @@ var<in> a : mat3x2<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)][1]; var b : f32 = a[min(u32(((c + 2) - 3)), 2u)][1];
} }
)"; )";
@ -389,7 +389,7 @@ var<in> a : mat3x2<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[1][c + 2 - 3]; var b : f32 = a[1][c + 2 - 3];
} }
)"; )";
@ -399,7 +399,7 @@ var<in> a : mat3x2<f32>;
var<in> c : i32; var<in> c : i32;
fn f() -> void { fn f() {
var b : f32 = a[1][min(u32(((c + 2) - 3)), 1u)]; var b : f32 = a[1][min(u32(((c + 2) - 3)), 1u)];
} }
)"; )";
@ -413,7 +413,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
auto* src = R"( auto* src = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[-1][1]; var b : f32 = a[-1][1];
} }
)"; )";
@ -421,7 +421,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[0][1]; var b : f32 = a[0][1];
} }
)"; )";
@ -435,7 +435,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
auto* src = R"( auto* src = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][-1]; var b : f32 = a[2][-1];
} }
)"; )";
@ -443,7 +443,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][0]; var b : f32 = a[2][0];
} }
)"; )";
@ -457,7 +457,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
auto* src = R"( auto* src = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[5][1]; var b : f32 = a[5][1];
} }
)"; )";
@ -465,7 +465,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][1]; var b : f32 = a[2][1];
} }
)"; )";
@ -479,7 +479,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
auto* src = R"( auto* src = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][5]; var b : f32 = a[2][5];
} }
)"; )";
@ -487,7 +487,7 @@ fn f() -> void {
auto* expect = R"( auto* expect = R"(
var<in> a : mat3x2<f32>; var<in> a : mat3x2<f32>;
fn f() -> void { fn f() {
var b : f32 = a[2][1]; var b : f32 = a[2][1];
} }
)"; )";
@ -542,7 +542,7 @@ struct S {
}; };
var<in> s : S; var<in> s : S;
fn f() -> void { fn f() {
var d : f32 = s.b[25]; var d : f32 = s.b[25];
} }
)"; )";
@ -556,7 +556,7 @@ struct S {
var<in> s : S; var<in> s : S;
fn f() -> void { fn f() {
var d : f32 = s.b[min(u32(25), (arrayLength(s.b) - 1u))]; var d : f32 = s.b[min(u32(25), (arrayLength(s.b) - 1u))];
} }
)"; )";

View File

@ -27,7 +27,7 @@ TEST_F(CanonicalizeEntryPointIOTest, Parameters) {
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>,
[[location(1)]] loc1 : f32, [[location(1)]] loc1 : f32,
[[location(2)]] loc2 : vec4<u32>) -> void { [[location(2)]] loc2 : vec4<u32>) {
var col : f32 = (coord.x * loc1); var col : f32 = (coord.x * loc1);
} }
)"; )";
@ -43,7 +43,7 @@ struct tint_symbol_5 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(tint_symbol_1 : tint_symbol_5) -> void { fn frag_main(tint_symbol_1 : tint_symbol_5) {
const coord : vec4<f32> = tint_symbol_1.coord; const coord : vec4<f32> = tint_symbol_1.coord;
const loc1 : f32 = tint_symbol_1.loc1; const loc1 : f32 = tint_symbol_1.loc1;
const loc2 : vec4<u32> = tint_symbol_1.loc2; const loc2 : vec4<u32> = tint_symbol_1.loc2;
@ -61,7 +61,7 @@ TEST_F(CanonicalizeEntryPointIOTest, Parameter_TypeAlias) {
type myf32 = f32; type myf32 = f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main([[location(1)]] loc1 : myf32) -> void { fn frag_main([[location(1)]] loc1 : myf32) {
var x : myf32 = loc1; var x : myf32 = loc1;
} }
)"; )";
@ -75,7 +75,7 @@ struct tint_symbol_4 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(tint_symbol_1 : tint_symbol_4) -> void { fn frag_main(tint_symbol_1 : tint_symbol_4) {
const loc1 : myf32 = tint_symbol_1.loc1; const loc1 : myf32 = tint_symbol_1.loc1;
var x : myf32 = loc1; var x : myf32 = loc1;
} }
@ -91,7 +91,7 @@ TEST_F(CanonicalizeEntryPointIOTest, Parameters_EmptyBody) {
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>,
[[location(1)]] loc1 : f32, [[location(1)]] loc1 : f32,
[[location(2)]] loc2 : vec4<u32>) -> void { [[location(2)]] loc2 : vec4<u32>) {
} }
)"; )";
@ -106,7 +106,7 @@ struct tint_symbol_5 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(tint_symbol_1 : tint_symbol_5) -> void { fn frag_main(tint_symbol_1 : tint_symbol_5) {
} }
)"; )";
@ -128,7 +128,7 @@ struct FragLocations {
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(builtins : FragBuiltins, fn frag_main(builtins : FragBuiltins,
locations : FragLocations, locations : FragLocations,
[[location(0)]] loc0 : f32) -> void { [[location(0)]] loc0 : f32) {
var col : f32 = ((builtins.coord.x * locations.loc1) + loc0); var col : f32 = ((builtins.coord.x * locations.loc1) + loc0);
} }
)"; )";
@ -155,7 +155,7 @@ struct tint_symbol_10 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(tint_symbol_6 : tint_symbol_10) -> void { fn frag_main(tint_symbol_6 : tint_symbol_10) {
const builtins : FragBuiltins = FragBuiltins(tint_symbol_6.coord); const builtins : FragBuiltins = FragBuiltins(tint_symbol_6.coord);
const locations : FragLocations = FragLocations(tint_symbol_6.loc1, tint_symbol_6.loc2); const locations : FragLocations = FragLocations(tint_symbol_6.loc1, tint_symbol_6.loc2);
const loc0 : f32 = tint_symbol_6.loc0; const loc0 : f32 = tint_symbol_6.loc0;
@ -254,12 +254,12 @@ fn foo(x : FragmentInput) -> f32 {
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main1(inputs : FragmentInput) -> void { fn frag_main1(inputs : FragmentInput) {
var x : f32 = foo(inputs); var x : f32 = foo(inputs);
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main2(inputs : FragmentInput) -> void { fn frag_main2(inputs : FragmentInput) {
var x : f32 = foo(inputs); var x : f32 = foo(inputs);
} }
)"; )";
@ -282,7 +282,7 @@ struct tint_symbol_6 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main1(tint_symbol_4 : tint_symbol_6) -> void { fn frag_main1(tint_symbol_4 : tint_symbol_6) {
const inputs : FragmentInput = FragmentInput(tint_symbol_4.value, tint_symbol_4.mul); const inputs : FragmentInput = FragmentInput(tint_symbol_4.value, tint_symbol_4.mul);
var x : f32 = foo(inputs); var x : f32 = foo(inputs);
} }
@ -295,7 +295,7 @@ struct tint_symbol_11 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main2(tint_symbol_10 : tint_symbol_11) -> void { fn frag_main2(tint_symbol_10 : tint_symbol_11) {
const inputs : FragmentInput = FragmentInput(tint_symbol_10.value, tint_symbol_10.mul); const inputs : FragmentInput = FragmentInput(tint_symbol_10.value, tint_symbol_10.mul);
var x : f32 = foo(inputs); var x : f32 = foo(inputs);
} }
@ -324,7 +324,7 @@ fn bar() -> f32 {
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main1(inputs : FragmentInput) -> void { fn frag_main1(inputs : FragmentInput) {
global_inputs = inputs; global_inputs = inputs;
var r : f32 = foo(); var r : f32 = foo();
var g : f32 = bar(); var g : f32 = bar();
@ -355,7 +355,7 @@ struct tint_symbol_6 {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main1(tint_symbol_4 : tint_symbol_6) -> void { fn frag_main1(tint_symbol_4 : tint_symbol_6) {
const inputs : FragmentInput = FragmentInput(tint_symbol_4.col1, tint_symbol_4.col2); const inputs : FragmentInput = FragmentInput(tint_symbol_4.col1, tint_symbol_4.col2);
global_inputs = inputs; global_inputs = inputs;
var r : f32 = foo(); var r : f32 = foo();

View File

@ -24,31 +24,31 @@ using EmitVertexPointSizeTest = TransformTest;
TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
auto* src = R"( auto* src = R"(
fn non_entry_a() -> void { fn non_entry_a() {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
var builtin_assignments_should_happen_before_this : f32; var builtin_assignments_should_happen_before_this : f32;
} }
fn non_entry_b() -> void { fn non_entry_b() {
} }
)"; )";
auto* expect = R"( auto* expect = R"(
[[builtin(pointsize)]] var<out> tint_pointsize : f32; [[builtin(pointsize)]] var<out> tint_pointsize : f32;
fn non_entry_a() -> void { fn non_entry_a() {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
tint_pointsize = 1.0; tint_pointsize = 1.0;
var builtin_assignments_should_happen_before_this : f32; var builtin_assignments_should_happen_before_this : f32;
} }
fn non_entry_b() -> void { fn non_entry_b() {
} }
)"; )";
@ -59,29 +59,29 @@ fn non_entry_b() -> void {
TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
auto* src = R"( auto* src = R"(
fn non_entry_a() -> void { fn non_entry_a() {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
} }
fn non_entry_b() -> void { fn non_entry_b() {
} }
)"; )";
auto* expect = R"( auto* expect = R"(
[[builtin(pointsize)]] var<out> tint_pointsize : f32; [[builtin(pointsize)]] var<out> tint_pointsize : f32;
fn non_entry_a() -> void { fn non_entry_a() {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
tint_pointsize = 1.0; tint_pointsize = 1.0;
} }
fn non_entry_b() -> void { fn non_entry_b() {
} }
)"; )";
@ -93,21 +93,21 @@ fn non_entry_b() -> void {
TEST_F(EmitVertexPointSizeTest, NonVertexStage) { TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
auto* src = R"( auto* src = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn fragment_entry() -> void { fn fragment_entry() {
} }
[[stage(compute)]] [[stage(compute)]]
fn compute_entry() -> void { fn compute_entry() {
} }
)"; )";
auto* expect = R"( auto* expect = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn fragment_entry() -> void { fn fragment_entry() {
} }
[[stage(compute)]] [[stage(compute)]]
fn compute_entry() -> void { fn compute_entry() {
} }
)"; )";

View File

@ -35,7 +35,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -86,7 +86,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -107,7 +107,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -134,7 +134,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -155,7 +155,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -183,7 +183,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -208,7 +208,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -239,7 +239,7 @@ fn func2() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
func2(); func2();
} }
)"; )";
@ -264,7 +264,7 @@ fn func2() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
func2(); func2();
} }
)"; )";

View File

@ -25,7 +25,7 @@ using HlslTest = TransformTest;
TEST_F(HlslTest, PromoteArrayInitializerToConstVar_Basic) { TEST_F(HlslTest, PromoteArrayInitializerToConstVar_Basic) {
auto* src = R"( auto* src = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var f0 : f32 = 1.0; var f0 : f32 = 1.0;
var f1 : f32 = 2.0; var f1 : f32 = 2.0;
var f2 : f32 = 3.0; var f2 : f32 = 3.0;
@ -36,7 +36,7 @@ fn main() -> void {
auto* expect = R"( auto* expect = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var f0 : f32 = 1.0; var f0 : f32 = 1.0;
var f1 : f32 = 2.0; var f1 : f32 = 2.0;
var f2 : f32 = 3.0; var f2 : f32 = 3.0;
@ -60,7 +60,7 @@ struct S {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var x : f32 = S(1, 2.0, vec3<f32>()).b; var x : f32 = S(1, 2.0, vec3<f32>()).b;
} }
)"; )";
@ -73,7 +73,7 @@ struct S {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const tint_symbol_1 : S = S(1, 2.0, vec3<f32>()); const tint_symbol_1 : S = S(1, 2.0, vec3<f32>());
var x : f32 = tint_symbol_1.b; var x : f32 = tint_symbol_1.b;
} }
@ -87,14 +87,14 @@ fn main() -> void {
TEST_F(HlslTest, PromoteArrayInitializerToConstVar_ArrayInArray) { TEST_F(HlslTest, PromoteArrayInitializerToConstVar_ArrayInArray) {
auto* src = R"( auto* src = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var i : f32 = array<array<f32, 2>, 2>(array<f32, 2>(1.0, 2.0), array<f32, 2>(3.0, 4.0))[0][1]; var i : f32 = array<array<f32, 2>, 2>(array<f32, 2>(1.0, 2.0), array<f32, 2>(3.0, 4.0))[0][1];
} }
)"; )";
auto* expect = R"( auto* expect = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const tint_symbol_1 : array<f32, 2> = array<f32, 2>(1.0, 2.0); const tint_symbol_1 : array<f32, 2> = array<f32, 2>(1.0, 2.0);
const tint_symbol_2 : array<f32, 2> = array<f32, 2>(3.0, 4.0); const tint_symbol_2 : array<f32, 2> = array<f32, 2>(3.0, 4.0);
const tint_symbol_3 : array<array<f32, 2>, 2> = array<array<f32, 2>, 2>(tint_symbol_1, tint_symbol_2); const tint_symbol_3 : array<array<f32, 2>, 2> = array<array<f32, 2>, 2>(tint_symbol_1, tint_symbol_2);
@ -124,7 +124,7 @@ struct S3 {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var x : i32 = S3(S2(1, S1(2), 3)).a.b.a; var x : i32 = S3(S2(1, S1(2), 3)).a.b.a;
} }
)"; )";
@ -145,7 +145,7 @@ struct S3 {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const tint_symbol_1 : S1 = S1(2); const tint_symbol_1 : S1 = S1(2);
const tint_symbol_4 : S2 = S2(1, tint_symbol_1, 3); const tint_symbol_4 : S2 = S2(1, tint_symbol_1, 3);
const tint_symbol_8 : S3 = S3(tint_symbol_4); const tint_symbol_8 : S3 = S3(tint_symbol_4);
@ -169,7 +169,7 @@ struct S2 {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var x : i32 = S2(array<S1, 3>(S1(1), S1(2), S1(3))).a[1].a; var x : i32 = S2(array<S1, 3>(S1(1), S1(2), S1(3))).a[1].a;
} }
)"; )";
@ -184,7 +184,7 @@ struct S2 {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const tint_symbol_1 : S1 = S1(1); const tint_symbol_1 : S1 = S1(1);
const tint_symbol_4 : S1 = S1(2); const tint_symbol_4 : S1 = S1(2);
const tint_symbol_5 : S1 = S1(3); const tint_symbol_5 : S1 = S1(3);
@ -208,7 +208,7 @@ struct S {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
var local_arr : array<f32, 4> = array<f32, 4>(0.0, 1.0, 2.0, 3.0); var local_arr : array<f32, 4> = array<f32, 4>(0.0, 1.0, 2.0, 3.0);
var local_str : S = S(1, 2.0, 3); var local_str : S = S(1, 2.0, 3);
} }
@ -240,7 +240,7 @@ struct Uniforms {
[[builtin(position)]] var<out> position : vec4<f32>; [[builtin(position)]] var<out> position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const transform : mat2x2<f32> = ubo.transform; const transform : mat2x2<f32> = ubo.transform;
var coord : vec2<f32> = array<vec2<f32>, 3>( var coord : vec2<f32> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, 1.0), vec2<f32>(-1.0, 1.0),
@ -264,7 +264,7 @@ struct Uniforms {
[[builtin(position)]] var<out> position : vec4<f32>; [[builtin(position)]] var<out> position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
const transform : mat2x2<f32> = ubo.transform; const transform : mat2x2<f32> = ubo.transform;
const tint_symbol_1 : array<vec2<f32>, 3> = array<vec2<f32>, 3>(vec2<f32>(-1.0, 1.0), vec2<f32>(1.0, 1.0), vec2<f32>(-1.0, -1.0)); const tint_symbol_1 : array<vec2<f32>, 3> = array<vec2<f32>, 3>(vec2<f32>(-1.0, 1.0), vec2<f32>(1.0, 1.0), vec2<f32>(-1.0, -1.0));
var coord : vec2<f32> = tint_symbol_1[vertex_index]; var coord : vec2<f32> = tint_symbol_1[vertex_index];
@ -282,7 +282,7 @@ TEST_F(HlslTest, AddEmptyEntryPoint) {
auto* expect = R"( auto* expect = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn _tint_unused_entry_point() -> void { fn _tint_unused_entry_point() {
} }
)"; )";

View File

@ -31,7 +31,7 @@ struct class {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
var foo : i32; var foo : i32;
var half : f32; var half : f32;
var half1 : f32; var half1 : f32;
@ -46,7 +46,7 @@ struct _tint_class {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn _tint_main() -> void { fn _tint_main() {
var foo : i32; var foo : i32;
var _tint_half : f32; var _tint_half : f32;
var half1 : f32; var half1 : f32;
@ -65,7 +65,7 @@ TEST_P(MslReservedKeywordTest, Keywords) {
auto src = R"( auto src = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
var )" + keyword + var )" + keyword +
R"( : i32; R"( : i32;
} }
@ -73,7 +73,7 @@ fn main() -> void {
auto expect = R"( auto expect = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn _tint_main() -> void { fn _tint_main() {
var _tint_)" + keyword + var _tint_)" + keyword +
R"( : i32; R"( : i32;
} }

View File

@ -47,7 +47,7 @@ fn test() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn entry() -> void { fn entry() {
test(); test();
} }
)"; )";
@ -60,7 +60,7 @@ fn _tint_2() -> u32 {
} }
[[stage(vertex)]] [[stage(vertex)]]
fn _tint_3() -> void { fn _tint_3() {
_tint_2(); _tint_2();
} }
)"; )";

View File

@ -94,13 +94,13 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
// [[builtin(frag_depth)]] var<out> depth: f32; // [[builtin(frag_depth)]] var<out> depth: f32;
// [[builtin(sample_mask_out)]] var<out> mask_out : u32; // [[builtin(sample_mask_out)]] var<out> mask_out : u32;
// //
// fn frag_main_ret(retval : FragmentOutput) -> void { // fn frag_main_ret(retval : FragmentOutput) {
// depth = reval.depth; // depth = reval.depth;
// mask_out = retval.mask_out; // mask_out = retval.mask_out;
// } // }
// //
// [[stage(fragment)]] // [[stage(fragment)]]
// fn frag_main() -> void { // fn frag_main() {
// const samples : FragmentInput(sample_index, sample_mask_in); // const samples : FragmentInput(sample_index, sample_mask_in);
// var output : FragmentOutput = FragmentOutput(1.0, // var output : FragmentOutput = FragmentOutput(1.0,
// samples.sample_mask_in); // samples.sample_mask_in);
@ -194,14 +194,14 @@ void Spirv::HandleSampleMaskBuiltins(CloneContext& ctx) const {
// Before: // Before:
// ``` // ```
// [[builtin(sample_mask_out)]] var<out> mask_out : u32; // [[builtin(sample_mask_out)]] var<out> mask_out : u32;
// fn main() -> void { // fn main() {
// mask_out = 1u; // mask_out = 1u;
// } // }
// ``` // ```
// After: // After:
// ``` // ```
// [[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>; // [[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>;
// fn main() -> void { // fn main() {
// mask_out[0] = 1u; // mask_out[0] = 1u;
// } // }
// ``` // ```

View File

@ -26,13 +26,13 @@ TEST_F(SpirvTest, HandleEntryPointIOTypes_Parameters) {
auto* src = R"( auto* src = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>,
[[location(1)]] loc1 : f32) -> void { [[location(1)]] loc1 : f32) {
var col : f32 = (coord.x * loc1); var col : f32 = (coord.x * loc1);
} }
[[stage(compute)]] [[stage(compute)]]
fn compute_main([[builtin(local_invocation_id)]] local_id : vec3<u32>, fn compute_main([[builtin(local_invocation_id)]] local_id : vec3<u32>,
[[builtin(local_invocation_index)]] local_index : u32) -> void { [[builtin(local_invocation_index)]] local_index : u32) {
var id_x : u32 = local_id.x; var id_x : u32 = local_id.x;
} }
)"; )";
@ -43,7 +43,7 @@ fn compute_main([[builtin(local_invocation_id)]] local_id : vec3<u32>,
[[location(1)]] var<in> tint_symbol_2 : f32; [[location(1)]] var<in> tint_symbol_2 : f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
var col : f32 = (tint_symbol_1.x * tint_symbol_2); var col : f32 = (tint_symbol_1.x * tint_symbol_2);
} }
@ -52,7 +52,7 @@ fn frag_main() -> void {
[[builtin(local_invocation_index)]] var<in> tint_symbol_7 : u32; [[builtin(local_invocation_index)]] var<in> tint_symbol_7 : u32;
[[stage(compute)]] [[stage(compute)]]
fn compute_main() -> void { fn compute_main() {
var id_x : u32 = tint_symbol_6.x; var id_x : u32 = tint_symbol_6.x;
} }
)"; )";
@ -67,7 +67,7 @@ TEST_F(SpirvTest, HandleEntryPointIOTypes_Parameter_TypeAlias) {
type myf32 = f32; type myf32 = f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main([[location(1)]] loc1 : myf32) -> void { fn frag_main([[location(1)]] loc1 : myf32) {
} }
)"; )";
@ -77,7 +77,7 @@ type myf32 = f32;
[[location(1)]] var<in> tint_symbol_2 : myf32; [[location(1)]] var<in> tint_symbol_2 : myf32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
} }
)"; )";
@ -97,12 +97,12 @@ fn vert_main() -> [[builtin(position)]] vec4<f32> {
auto* expect = R"( auto* expect = R"(
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>; [[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
fn tint_symbol_2(tint_symbol_3 : vec4<f32>) -> void { fn tint_symbol_2(tint_symbol_3 : vec4<f32>) {
tint_symbol_1 = tint_symbol_3; tint_symbol_1 = tint_symbol_3;
} }
[[stage(vertex)]] [[stage(vertex)]]
fn vert_main() -> void { fn vert_main() {
tint_symbol_2(vec4<f32>(1.0, 2.0, 3.0, 0.0)); tint_symbol_2(vec4<f32>(1.0, 2.0, 3.0, 0.0));
return; return;
} }
@ -129,12 +129,12 @@ fn frag_main([[location(0)]] loc_in : u32) -> [[location(0)]] f32 {
[[location(0)]] var<out> tint_symbol_2 : f32; [[location(0)]] var<out> tint_symbol_2 : f32;
fn tint_symbol_3(tint_symbol_4 : f32) -> void { fn tint_symbol_3(tint_symbol_4 : f32) {
tint_symbol_2 = tint_symbol_4; tint_symbol_2 = tint_symbol_4;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
if ((tint_symbol_1 > 10u)) { if ((tint_symbol_1 > 10u)) {
tint_symbol_3(0.5); tint_symbol_3(0.5);
return; return;
@ -169,12 +169,12 @@ type myf32 = f32;
[[location(0)]] var<out> tint_symbol_3 : myf32; [[location(0)]] var<out> tint_symbol_3 : myf32;
fn tint_symbol_4(tint_symbol_5 : myf32) -> void { fn tint_symbol_4(tint_symbol_5 : myf32) {
tint_symbol_3 = tint_symbol_5; tint_symbol_3 = tint_symbol_5;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
if ((tint_symbol_2 > 10u)) { if ((tint_symbol_2 > 10u)) {
tint_symbol_4(0.5); tint_symbol_4(0.5);
return; return;
@ -197,7 +197,7 @@ struct FragmentInput {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(inputs : FragmentInput) -> void { fn frag_main(inputs : FragmentInput) {
var col : f32 = inputs.coord.x * inputs.value; var col : f32 = inputs.coord.x * inputs.value;
} }
)"; )";
@ -213,7 +213,7 @@ struct FragmentInput {
[[location(1)]] var<in> tint_symbol_5 : f32; [[location(1)]] var<in> tint_symbol_5 : f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
const tint_symbol_7 : FragmentInput = FragmentInput(tint_symbol_4, tint_symbol_5); const tint_symbol_7 : FragmentInput = FragmentInput(tint_symbol_4, tint_symbol_5);
var col : f32 = (tint_symbol_7.coord.x * tint_symbol_7.value); var col : f32 = (tint_symbol_7.coord.x * tint_symbol_7.value);
} }
@ -231,7 +231,7 @@ struct FragmentInput {
}; };
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(inputs : FragmentInput) -> void { fn frag_main(inputs : FragmentInput) {
} }
)"; )";
@ -243,7 +243,7 @@ struct FragmentInput {
[[location(1)]] var<in> tint_symbol_3 : f32; [[location(1)]] var<in> tint_symbol_3 : f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
} }
)"; )";
@ -279,13 +279,13 @@ struct VertexOutput {
[[location(1)]] var<out> tint_symbol_5 : f32; [[location(1)]] var<out> tint_symbol_5 : f32;
fn tint_symbol_6(tint_symbol_7 : VertexOutput) -> void { fn tint_symbol_6(tint_symbol_7 : VertexOutput) {
tint_symbol_4 = tint_symbol_7.pos; tint_symbol_4 = tint_symbol_7.pos;
tint_symbol_5 = tint_symbol_7.value; tint_symbol_5 = tint_symbol_7.value;
} }
[[stage(vertex)]] [[stage(vertex)]]
fn vert_main() -> void { fn vert_main() {
if (false) { if (false) {
tint_symbol_6(VertexOutput()); tint_symbol_6(VertexOutput());
return; return;
@ -322,12 +322,12 @@ struct Interface {
[[location(1)]] var<out> tint_symbol_4 : f32; [[location(1)]] var<out> tint_symbol_4 : f32;
fn tint_symbol_5(tint_symbol_6 : Interface) -> void { fn tint_symbol_5(tint_symbol_6 : Interface) {
tint_symbol_4 = tint_symbol_6.value; tint_symbol_4 = tint_symbol_6.value;
} }
[[stage(vertex)]] [[stage(vertex)]]
fn vert_main() -> void { fn vert_main() {
const tint_symbol_8 : Interface = Interface(tint_symbol_3); const tint_symbol_8 : Interface = Interface(tint_symbol_3);
tint_symbol_5(tint_symbol_8); tint_symbol_5(tint_symbol_8);
return; return;
@ -351,7 +351,7 @@ fn vert_main() -> Interface {
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main(inputs : Interface) -> void { fn frag_main(inputs : Interface) {
var x : f32 = inputs.value; var x : f32 = inputs.value;
} }
)"; )";
@ -363,12 +363,12 @@ struct Interface {
[[location(1)]] var<out> tint_symbol_3 : f32; [[location(1)]] var<out> tint_symbol_3 : f32;
fn tint_symbol_4(tint_symbol_5 : Interface) -> void { fn tint_symbol_4(tint_symbol_5 : Interface) {
tint_symbol_3 = tint_symbol_5.value; tint_symbol_3 = tint_symbol_5.value;
} }
[[stage(vertex)]] [[stage(vertex)]]
fn vert_main() -> void { fn vert_main() {
tint_symbol_4(Interface(42.0)); tint_symbol_4(Interface(42.0));
return; return;
} }
@ -376,7 +376,7 @@ fn vert_main() -> void {
[[location(1)]] var<in> tint_symbol_7 : f32; [[location(1)]] var<in> tint_symbol_7 : f32;
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
const tint_symbol_9 : Interface = Interface(tint_symbol_7); const tint_symbol_9 : Interface = Interface(tint_symbol_7);
var x : f32 = tint_symbol_9.value; var x : f32 = tint_symbol_9.value;
} }
@ -425,12 +425,12 @@ struct FragmentOutput {
[[location(1)]] var<out> tint_symbol_7 : f32; [[location(1)]] var<out> tint_symbol_7 : f32;
fn tint_symbol_8(tint_symbol_9 : FragmentOutput) -> void { fn tint_symbol_8(tint_symbol_9 : FragmentOutput) {
tint_symbol_7 = tint_symbol_9.value; tint_symbol_7 = tint_symbol_9.value;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn frag_main() -> void { fn frag_main() {
const tint_symbol_11 : FragmentInput = FragmentInput(tint_symbol_5, tint_symbol_6); const tint_symbol_11 : FragmentInput = FragmentInput(tint_symbol_5, tint_symbol_6);
tint_symbol_8(FragmentOutput((tint_symbol_11.coord.x * tint_symbol_11.value))); tint_symbol_8(FragmentOutput((tint_symbol_11.coord.x * tint_symbol_11.value)));
return; return;
@ -467,12 +467,12 @@ struct VertexOutput {
[[builtin(position)]] var<out> tint_symbol_4 : vec4<f32>; [[builtin(position)]] var<out> tint_symbol_4 : vec4<f32>;
fn tint_symbol_5(tint_symbol_6 : VertexOutput) -> void { fn tint_symbol_5(tint_symbol_6 : VertexOutput) {
tint_symbol_4 = tint_symbol_6.Position; tint_symbol_4 = tint_symbol_6.Position;
} }
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
tint_symbol_5(VertexOutput(vec4<f32>())); tint_symbol_5(VertexOutput(vec4<f32>()));
return; return;
} }
@ -492,7 +492,7 @@ TEST_F(SpirvTest, HandleSampleMaskBuiltins_Basic) {
[[builtin(sample_mask_out)]] var<out> mask_out : u32; [[builtin(sample_mask_out)]] var<out> mask_out : u32;
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
mask_out = mask_in; mask_out = mask_in;
} }
)"; )";
@ -505,7 +505,7 @@ fn main() -> void {
[[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>; [[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>;
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
mask_out[0] = mask_in[0]; mask_out[0] = mask_in[0];
} }
)"; )";
@ -525,12 +525,12 @@ fn filter(mask: u32) -> u32 {
return (mask & 3u); return (mask & 3u);
} }
fn set_mask(input : u32) -> void { fn set_mask(input : u32) {
mask_out = input; mask_out = input;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
set_mask(filter(mask_in)); set_mask(filter(mask_in));
} }
)"; )";
@ -544,12 +544,12 @@ fn filter(mask : u32) -> u32 {
return (mask & 3u); return (mask & 3u);
} }
fn set_mask(input : u32) -> void { fn set_mask(input : u32) {
mask_out[0] = input; mask_out[0] = input;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
set_mask(filter(mask_in[0])); set_mask(filter(mask_in[0]));
} }
)"; )";
@ -564,7 +564,7 @@ TEST_F(SpirvTest, AddEmptyEntryPoint) {
auto* expect = R"( auto* expect = R"(
[[stage(compute)]] [[stage(compute)]]
fn _tint_unused_entry_point() -> void { fn _tint_unused_entry_point() {
} }
)"; )";
@ -591,12 +591,12 @@ fn main([[builtin(sample_index)]] sample_index : u32,
[[builtin(sample_mask_out)]] var<out> tint_symbol_2 : array<u32, 1>; [[builtin(sample_mask_out)]] var<out> tint_symbol_2 : array<u32, 1>;
fn tint_symbol_4(tint_symbol_5 : u32) -> void { fn tint_symbol_4(tint_symbol_5 : u32) {
tint_symbol_2[0] = tint_symbol_5; tint_symbol_2[0] = tint_symbol_5;
} }
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void { fn main() {
tint_symbol_4(tint_symbol_1[0]); tint_symbol_4(tint_symbol_1[0]);
return; return;
} }

View File

@ -41,7 +41,7 @@ TEST_F(VertexPullingTest, Error_NoEntryPoint) {
TEST_F(VertexPullingTest, Error_InvalidEntryPoint) { TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
auto* src = R"( auto* src = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = "error: Vertex stage entry point not found"; auto* expect = "error: Vertex stage entry point not found";
@ -59,7 +59,7 @@ fn main() -> void {}
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) { TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
auto* src = R"( auto* src = R"(
[[stage(fragment)]] [[stage(fragment)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = "error: Vertex stage entry point not found"; auto* expect = "error: Vertex stage entry point not found";
@ -77,7 +77,7 @@ fn main() -> void {}
TEST_F(VertexPullingTest, BasicModule) { TEST_F(VertexPullingTest, BasicModule) {
auto* src = R"( auto* src = R"(
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -87,7 +87,7 @@ struct TintVertexData {
}; };
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
} }
@ -109,7 +109,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
[[location(0)]] var<in> var_a : f32; [[location(0)]] var<in> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -125,7 +125,7 @@ struct TintVertexData {
var<private> var_a : f32; var<private> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u); _tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u);
@ -151,7 +151,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
[[location(0)]] var<in> var_a : f32; [[location(0)]] var<in> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -167,7 +167,7 @@ struct TintVertexData {
var<private> var_a : f32; var<private> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((_tint_pulling_instance_index * 4u) + 0u); _tint_pulling_pos = ((_tint_pulling_instance_index * 4u) + 0u);
@ -193,7 +193,7 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
[[location(0)]] var<in> var_a : f32; [[location(0)]] var<in> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -209,7 +209,7 @@ struct TintVertexData {
var<private> var_a : f32; var<private> var_a : f32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u); _tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u);
@ -240,7 +240,7 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
[[builtin(instance_index)]] var<in> custom_instance_index : u32; [[builtin(instance_index)]] var<in> custom_instance_index : u32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -262,7 +262,7 @@ var<private> var_b : f32;
[[builtin(instance_index)]] var<in> custom_instance_index : u32; [[builtin(instance_index)]] var<in> custom_instance_index : u32;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((custom_vertex_index * 4u) + 0u); _tint_pulling_pos = ((custom_vertex_index * 4u) + 0u);
@ -301,7 +301,7 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
[[location(1)]] var<in> var_b : vec4<f32>; [[location(1)]] var<in> var_b : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -319,7 +319,7 @@ var<private> var_a : f32;
var<private> var_b : vec4<f32>; var<private> var_b : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((_tint_pulling_vertex_index * 16u) + 0u); _tint_pulling_pos = ((_tint_pulling_vertex_index * 16u) + 0u);
@ -351,7 +351,7 @@ TEST_F(VertexPullingTest, FloatVectorAttributes) {
[[location(2)]] var<in> var_c : vec4<f32>; [[location(2)]] var<in> var_c : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void {} fn main() {}
)"; )";
auto* expect = R"( auto* expect = R"(
@ -375,7 +375,7 @@ var<private> var_b : vec3<f32>;
var<private> var_c : vec4<f32>; var<private> var_c : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]]
fn main() -> void { fn main() {
{ {
var _tint_pulling_pos : u32; var _tint_pulling_pos : u32;
_tint_pulling_pos = ((_tint_pulling_vertex_index * 8u) + 0u); _tint_pulling_pos = ((_tint_pulling_vertex_index * 8u) + 0u);

View File

@ -185,7 +185,7 @@ TEST_F(HlslGeneratorImplTest_Function,
// fn vert_main() -> Interface { // fn vert_main() -> Interface {
// return Interface(0.4, 0.6); // return Interface(0.4, 0.6);
// } // }
// fn frag_main(colors : Interface) -> void { // fn frag_main(colors : Interface) {
// const r = colors.col1; // const r = colors.col1;
// const g = colors.col2; // const g = colors.col2;
// } // }
@ -961,12 +961,12 @@ TEST_F(HlslGeneratorImplTest_Function,
// [[binding(0), group(0)]] var<storage> data : Data; // [[binding(0), group(0)]] var<storage> data : Data;
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn a() -> void { // fn a() {
// return; // return;
// } // }
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn b() -> void { // fn b() {
// return; // return;
// } // }

View File

@ -166,7 +166,7 @@ TEST_F(MslGeneratorImplTest,
// fn vert_main() -> Interface { // fn vert_main() -> Interface {
// return Interface(0.4, 0.6); // return Interface(0.4, 0.6);
// } // }
// fn frag_main(colors : Interface) -> void { // fn frag_main(colors : Interface) {
// const r = colors.col1; // const r = colors.col1;
// const g = colors.col2; // const g = colors.col2;
// } // }
@ -790,12 +790,12 @@ TEST_F(MslGeneratorImplTest,
// [[binding(0), group(0)]] var<storage> data : Data; // [[binding(0), group(0)]] var<storage> data : Data;
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn a() -> void { // fn a() {
// return; // return;
// } // }
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn b() -> void { // fn b() {
// return; // return;
// } // }

View File

@ -39,7 +39,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, EntryPoint_Parameters) { TEST_F(BuilderTest, EntryPoint_Parameters) {
// [[stage(fragment)]] // [[stage(fragment)]]
// fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, // fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>,
// [[location(1)]] loc1 : f32) -> void { // [[location(1)]] loc1 : f32) {
// var col : f32 = (coord.x * loc1); // var col : f32 = (coord.x * loc1);
// } // }
auto* f32 = ty.f32(); auto* f32 = ty.f32();

View File

@ -196,12 +196,12 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
// [[binding(0), group(0)]] var<storage> data : Data; // [[binding(0), group(0)]] var<storage> data : Data;
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn a() -> void { // fn a() {
// return; // return;
// } // }
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn b() -> void { // fn b() {
// return; // return;
// } // }

View File

@ -612,7 +612,7 @@ TEST_F(BuilderTest, SampleMask) {
// [[builtin(sample_mask_in)]] var<in> mask_in : u32; // [[builtin(sample_mask_in)]] var<in> mask_in : u32;
// [[builtin(sample_mask_out)]] var<out> mask_out : u32; // [[builtin(sample_mask_out)]] var<out> mask_out : u32;
// [[stage(fragment)]] // [[stage(fragment)]]
// fn main() -> void { // fn main() {
// mask_out = mask_in; // mask_out = mask_in;
// } // }
@ -620,7 +620,7 @@ TEST_F(BuilderTest, SampleMask) {
// [[builtin(sample_mask_in)]] var<in> mask_in : array<u32, 1>; // [[builtin(sample_mask_in)]] var<in> mask_in : array<u32, 1>;
// [[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>; // [[builtin(sample_mask_out)]] var<out> mask_out : array<u32, 1>;
// [[stage(fragment)]] // [[stage(fragment)]]
// fn main() -> void { // fn main() {
// mask_out[0] = mask_in[0]; // mask_out[0] = mask_in[0];
// } // }

View File

@ -330,17 +330,22 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
} }
} }
out_ << ") -> "; out_ << ")";
if (!func->return_type_decorations().empty()) { if (!func->return_type()->Is<type::Void>() ||
if (!EmitDecorations(func->return_type_decorations())) { !func->return_type_decorations().empty()) {
out_ << " -> ";
if (!func->return_type_decorations().empty()) {
if (!EmitDecorations(func->return_type_decorations())) {
return false;
}
out_ << " ";
}
if (!EmitType(func->return_type())) {
return false; return false;
} }
out_ << " ";
}
if (!EmitType(func->return_type())) {
return false;
} }
if (func->body()) { if (func->body()) {

View File

@ -48,11 +48,11 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedFunction) {
ASSERT_TRUE( ASSERT_TRUE(
gen.GenerateEntryPoint(tint::ast::PipelineStage::kCompute, "main")) gen.GenerateEntryPoint(tint::ast::PipelineStage::kCompute, "main"))
<< gen.error(); << gen.error();
EXPECT_EQ(gen.result(), R"( fn func_used() -> void { EXPECT_EQ(gen.result(), R"( fn func_used() {
} }
[[stage(compute)]] [[stage(compute)]]
fn main() -> void { fn main() {
func_used(); func_used();
} }
)"); )");
@ -85,7 +85,7 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedVariable) {
EXPECT_EQ(gen.result(), R"( var<in> global_used : f32; EXPECT_EQ(gen.result(), R"( var<in> global_used : f32;
[[stage(compute)]] [[stage(compute)]]
fn main() -> void { fn main() {
global_used = 1.0; global_used = 1.0;
} }
)"); )");
@ -152,7 +152,7 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_GlobalsInterleaved) {
}; };
[[stage(compute)]] [[stage(compute)]]
fn main() -> void { fn main() {
var s0 : S0; var s0 : S0;
var s1 : S1; var s1 : S1;
a1 = func(); a1 = func();

View File

@ -39,7 +39,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( fn my_func() -> void { EXPECT_EQ(gen.result(), R"( fn my_func() {
discard; discard;
return; return;
} }
@ -63,7 +63,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( fn my_func(a : f32, b : i32) -> void { EXPECT_EQ(gen.result(), R"( fn my_func(a : f32, b : i32) {
discard; discard;
return; return;
} }
@ -86,7 +86,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( [[workgroup_size(2, 4, 6)]] EXPECT_EQ(gen.result(), R"( [[workgroup_size(2, 4, 6)]]
fn my_func() -> void { fn my_func() {
discard; discard;
return; return;
} }
@ -110,7 +110,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( [[stage(fragment)]] EXPECT_EQ(gen.result(), R"( [[stage(fragment)]]
fn my_func() -> void { fn my_func() {
discard; discard;
return; return;
} }
@ -136,7 +136,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( [[stage(fragment)]] EXPECT_EQ(gen.result(), R"( [[stage(fragment)]]
[[workgroup_size(2, 4, 6)]] [[workgroup_size(2, 4, 6)]]
fn my_func() -> void { fn my_func() {
discard; discard;
return; return;
} }
@ -162,7 +162,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
ASSERT_TRUE(gen.EmitFunction(func)); ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( [[stage(fragment)]] EXPECT_EQ(gen.result(), R"( [[stage(fragment)]]
fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, [[location(1)]] loc1 : f32) -> void { fn frag_main([[builtin(frag_coord)]] coord : vec4<f32>, [[location(1)]] loc1 : f32) {
} }
)"); )");
} }
@ -201,12 +201,12 @@ TEST_F(WgslGeneratorImplTest,
// [[binding(0), group(0)]] var<storage> data : Data; // [[binding(0), group(0)]] var<storage> data : Data;
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn a() -> void { // fn a() {
// return; // return;
// } // }
// //
// [[stage(compute)]] // [[stage(compute)]]
// fn b() -> void { // fn b() {
// return; // return;
// } // }
@ -263,13 +263,13 @@ struct Data {
Data; Data;
[[stage(compute)]] [[stage(compute)]]
fn a() -> void { fn a() {
var v : f32 = data.d; var v : f32 = data.d;
return; return;
} }
[[stage(compute)]] [[stage(compute)]]
fn b() -> void { fn b() {
var v : f32 = data.d; var v : f32 = data.d;
return; return;
} }

View File

@ -36,7 +36,7 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalDeclAfterFunction) {
ASSERT_TRUE(gen.Generate(nullptr)) << gen.error(); ASSERT_TRUE(gen.Generate(nullptr)) << gen.error();
EXPECT_EQ(gen.result(), R"( [[stage(compute)]] EXPECT_EQ(gen.result(), R"( [[stage(compute)]]
fn test_function() -> void { fn test_function() {
var a : f32; var a : f32;
} }
@ -103,7 +103,7 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
}; };
[[stage(compute)]] [[stage(compute)]]
fn main() -> void { fn main() {
var s0 : S0; var s0 : S0;
var s1 : S1; var s1 : S1;
a1 = func(); a1 = func();

View File

@ -29,7 +29,7 @@ TEST_F(WgslGeneratorImplTest, Generate) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(nullptr)) << gen.error(); ASSERT_TRUE(gen.Generate(nullptr)) << gen.error();
EXPECT_EQ(gen.result(), R"(fn my_func() -> void { EXPECT_EQ(gen.result(), R"(fn my_func() {
} }
)"); )");
} }

View File

@ -60,7 +60,7 @@ fn frag_main() -> [[location(0)]] vec4<f32> {
// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
[[stage(compute)]] [[stage(compute)]]
fn comp_main( fn comp_main(
[[builtin(global_invocation_id)]] gl_GlobalInvocationID : vec3<u32>) -> void { [[builtin(global_invocation_id)]] gl_GlobalInvocationID : vec3<u32>) {
var index : u32 = gl_GlobalInvocationID.x; var index : u32 = gl_GlobalInvocationID.x;
if (index >= 5u) { if (index >= 5u) {
return; return;

View File

@ -18,5 +18,5 @@ fn main() -> f32 {
[[stage(compute)]] [[stage(compute)]]
[[workgroup_size(2)]] [[workgroup_size(2)]]
fn ep() -> void { fn ep() {
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
fn bar() -> void { fn bar() {
} }
[[stage(fragment)]] [[stage(fragment)]]

View File

@ -199,7 +199,7 @@ type example struct {
func tryCompile(compiler, wd string, e example) error { func tryCompile(compiler, wd string, e example) error {
code := e.code code := e.code
if e.functionScope { if e.functionScope {
code = "\n[[stage(vertex)]] fn main() -> void {\n" + code + "}\n" code = "\n[[stage(vertex)]] fn main() {\n" + code + "}\n"
} }
addedStubFunction := false addedStubFunction := false
@ -212,7 +212,7 @@ func tryCompile(compiler, wd string, e example) error {
if !addedStubFunction && strings.Contains(err.Error(), "error v-0003") { if !addedStubFunction && strings.Contains(err.Error(), "error v-0003") {
// error v-0003: At least one of vertex, fragment or compute shader // error v-0003: At least one of vertex, fragment or compute shader
// must be present. Add a stub entry point to satisfy the compiler. // must be present. Add a stub entry point to satisfy the compiler.
code += "\n[[stage(vertex)]] fn main() -> void {}\n" code += "\n[[stage(vertex)]] fn main() {}\n"
addedStubFunction = true addedStubFunction = true
continue continue
} }