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>
diff --git a/src/program_builder.h b/src/program_builder.h
index fd3e685..d78c077 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -1643,11 +1643,11 @@
   const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); }
 
   /// @param expr the expression to ignore
-  /// @returns a `ast::CallStatement` that calls the `ignore` intrinsic which is
-  /// passed the single `expr` argument
+  /// @returns a `ast::AssignmentStatement` that assigns 'expr' to the phony
+  /// (underscore) variable.
   template <typename EXPR>
-  const ast::CallStatement* Ignore(EXPR&& expr) {
-    return create<ast::CallStatement>(Call("ignore", Expr(expr)));
+  const ast::AssignmentStatement* Ignore(EXPR&& expr) {
+    return create<ast::AssignmentStatement>(Phony(), Expr(expr));
   }
 
   /// @param lhs the left hand argument to the addition operation
diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc
index d96ac67..7cbf492 100644
--- a/src/writer/msl/generator_impl_loop_test.cc
+++ b/src/writer/msl/generator_impl_loop_test.cc
@@ -190,28 +190,33 @@
 }
 
 TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
+  // fn f(i : i32) {}
+  //
   // var<workgroup> a : atomic<i32>;
-  // for({ignore(1); ignore(2);}; ; ) {
+  // for({f(1); f(2);}; ; ) {
   //   return;
   // }
 
+  Func("f", {Param("i", ty.i32())}, ty.void_(), {});
+  auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
+
   Func("a_statement", {}, ty.void_(), {});
 
   Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
-  auto* multi_stmt = Block(Ignore(1), Ignore(2));
-  auto* f =
+  auto* multi_stmt = Block(f(1), f(2));
+  auto* loop =
       For(multi_stmt, nullptr, nullptr, Block(CallStmt(Call("a_statement"))));
-  WrapInFunction(f);
+  WrapInFunction(loop);
 
   GeneratorImpl& gen = Build();
 
   gen.increment_indent();
 
-  ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
+  ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  {
     {
-      (void) 1;
-      (void) 2;
+      f(1);
+      f(2);
     }
     for(; ; ) {
       a_statement();
@@ -267,29 +272,34 @@
 }
 
 TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
+  // fn f(i : i32) {}
+  //
   // var<workgroup> a : atomic<i32>;
-  // for(; ; { ignore(1); ignore(2); }) {
+  // for(; ; { f(1); f(2); }) {
   //   return;
   // }
 
+  Func("f", {Param("i", ty.i32())}, ty.void_(), {});
+  auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
+
   Func("a_statement", {}, ty.void_(), {});
 
   Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
-  auto* multi_stmt = Block(Ignore(1), Ignore(2));
-  auto* f =
+  auto* multi_stmt = Block(f(1), f(2));
+  auto* loop =
       For(nullptr, nullptr, multi_stmt, Block(CallStmt(Call("a_statement"))));
-  WrapInFunction(f);
+  WrapInFunction(loop);
 
   GeneratorImpl& gen = Build();
 
   gen.increment_indent();
 
-  ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
+  ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  while (true) {
     a_statement();
     {
-      (void) 1;
-      (void) 2;
+      f(1);
+      f(2);
     }
   }
 )");
@@ -320,36 +330,41 @@
 }
 
 TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
+  // fn f(i : 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;
   // }
 
+  Func("f", {Param("i", ty.i32())}, ty.void_(), {});
+  auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
+
   Func("a_statement", {}, ty.void_(), {});
 
   Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
-  auto* multi_stmt_a = Block(Ignore(1), Ignore(2));
-  auto* multi_stmt_b = Block(Ignore(3), Ignore(4));
-  auto* f = For(multi_stmt_a, Expr(true), multi_stmt_b,
-                Block(CallStmt(Call("a_statement"))));
-  WrapInFunction(f);
+  auto* multi_stmt_a = Block(f(1), f(2));
+  auto* multi_stmt_b = Block(f(3), f(4));
+  auto* loop = For(multi_stmt_a, Expr(true), multi_stmt_b,
+                   Block(CallStmt(Call("a_statement"))));
+  WrapInFunction(loop);
 
   GeneratorImpl& gen = Build();
 
   gen.increment_indent();
 
-  ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
+  ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  {
     {
-      (void) 1;
-      (void) 2;
+      f(1);
+      f(2);
     }
     while (true) {
       if (!(true)) { break; }
       a_statement();
       {
-        (void) 3;
-        (void) 4;
+        f(3);
+        f(4);
       }
     }
   }
diff --git a/src/writer/wgsl/generator_impl_loop_test.cc b/src/writer/wgsl/generator_impl_loop_test.cc
index be5651f..d0b2e75 100644
--- a/src/writer/wgsl/generator_impl_loop_test.cc
+++ b/src/writer/wgsl/generator_impl_loop_test.cc
@@ -79,8 +79,8 @@
 
   ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  for({
-    ignore(1);
-    ignore(2);
+    _ = 1;
+    _ = 2;
   }; ; ) {
     return;
   }
@@ -143,8 +143,8 @@
 
   ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  for(; ; {
-    ignore(1);
-    ignore(2);
+    _ = 1;
+    _ = 2;
   }) {
     return;
   }
@@ -188,11 +188,11 @@
 
   ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
   EXPECT_EQ(gen.result(), R"(  for({
-    ignore(1);
-    ignore(2);
+    _ = 1;
+    _ = 2;
   }; true; {
-    ignore(3);
-    ignore(4);
+    _ = 3;
+    _ = 4;
   }) {
     return;
   }