ProgramBuilder: Migrate away from using Ignore()

The `Ignore()` intrinsic is about to be deprecated, so don't use it for testing.

Bug: tint:1213
Change-Id: Ib5d5966da6d566a9f02940970ebd79d520b5e0e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67065
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-10-21 23:28:44 +00:00 committed by Tint LUCI CQ
parent a41694e9a3
commit cc7c4f309b
3 changed files with 52 additions and 37 deletions

View File

@ -1643,11 +1643,11 @@ class ProgramBuilder {
const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); } const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); }
/// @param expr the expression to ignore /// @param expr the expression to ignore
/// @returns a `ast::CallStatement` that calls the `ignore` intrinsic which is /// @returns a `ast::AssignmentStatement` that assigns 'expr' to the phony
/// passed the single `expr` argument /// (underscore) variable.
template <typename EXPR> template <typename EXPR>
const ast::CallStatement* Ignore(EXPR&& expr) { const ast::AssignmentStatement* Ignore(EXPR&& expr) {
return create<ast::CallStatement>(Call("ignore", Expr(expr))); return create<ast::AssignmentStatement>(Phony(), Expr(expr));
} }
/// @param lhs the left hand argument to the addition operation /// @param lhs the left hand argument to the addition operation

View File

@ -190,28 +190,33 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleInit) {
} }
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) { TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
// fn f(i : i32) {}
//
// var<workgroup> a : atomic<i32>; // var<workgroup> a : atomic<i32>;
// for({ignore(1); ignore(2);}; ; ) { // for({f(1); f(2);}; ; ) {
// return; // return;
// } // }
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup); Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
auto* multi_stmt = Block(Ignore(1), Ignore(2)); auto* multi_stmt = Block(f(1), f(2));
auto* f = auto* loop =
For(multi_stmt, nullptr, nullptr, Block(CallStmt(Call("a_statement")))); For(multi_stmt, nullptr, nullptr, Block(CallStmt(Call("a_statement"))));
WrapInFunction(f); WrapInFunction(loop);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
EXPECT_EQ(gen.result(), R"( { EXPECT_EQ(gen.result(), R"( {
{ {
(void) 1; f(1);
(void) 2; f(2);
} }
for(; ; ) { for(; ; ) {
a_statement(); a_statement();
@ -267,29 +272,34 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleCont) {
} }
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) { TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
// fn f(i : i32) {}
//
// var<workgroup> a : atomic<i32>; // var<workgroup> a : atomic<i32>;
// for(; ; { ignore(1); ignore(2); }) { // for(; ; { f(1); f(2); }) {
// return; // return;
// } // }
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup); Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
auto* multi_stmt = Block(Ignore(1), Ignore(2)); auto* multi_stmt = Block(f(1), f(2));
auto* f = auto* loop =
For(nullptr, nullptr, multi_stmt, Block(CallStmt(Call("a_statement")))); For(nullptr, nullptr, multi_stmt, Block(CallStmt(Call("a_statement"))));
WrapInFunction(f); WrapInFunction(loop);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
a_statement(); a_statement();
{ {
(void) 1; f(1);
(void) 2; f(2);
} }
} }
)"); )");
@ -320,36 +330,41 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleInitCondCont) {
} }
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) { TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
// fn f(i : i32) {}
//
// var<workgroup> a : atomic<i32>; // var<workgroup> a : atomic<i32>;
// for({ ignore(1); ignore(2); }; true; { ignore(3); ignore(4); }) { // for({ f(1); f(2); }; true; { f(3); f(4); }) {
// return; // return;
// } // }
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup); Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
auto* multi_stmt_a = Block(Ignore(1), Ignore(2)); auto* multi_stmt_a = Block(f(1), f(2));
auto* multi_stmt_b = Block(Ignore(3), Ignore(4)); auto* multi_stmt_b = Block(f(3), f(4));
auto* f = For(multi_stmt_a, Expr(true), multi_stmt_b, auto* loop = For(multi_stmt_a, Expr(true), multi_stmt_b,
Block(CallStmt(Call("a_statement")))); Block(CallStmt(Call("a_statement"))));
WrapInFunction(f); WrapInFunction(loop);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
EXPECT_EQ(gen.result(), R"( { EXPECT_EQ(gen.result(), R"( {
{ {
(void) 1; f(1);
(void) 2; f(2);
} }
while (true) { while (true) {
if (!(true)) { break; } if (!(true)) { break; }
a_statement(); a_statement();
{ {
(void) 3; f(3);
(void) 4; f(4);
} }
} }
} }

View File

@ -79,8 +79,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
EXPECT_EQ(gen.result(), R"( for({ EXPECT_EQ(gen.result(), R"( for({
ignore(1); _ = 1;
ignore(2); _ = 2;
}; ; ) { }; ; ) {
return; return;
} }
@ -143,8 +143,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
EXPECT_EQ(gen.result(), R"( for(; ; { EXPECT_EQ(gen.result(), R"( for(; ; {
ignore(1); _ = 1;
ignore(2); _ = 2;
}) { }) {
return; return;
} }
@ -188,11 +188,11 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
EXPECT_EQ(gen.result(), R"( for({ EXPECT_EQ(gen.result(), R"( for({
ignore(1); _ = 1;
ignore(2); _ = 2;
}; true; { }; true; {
ignore(3); _ = 3;
ignore(4); _ = 4;
}) { }) {
return; return;
} }