ProgramBuilder: Generate type pairs for primitives

Emit the new typ::I32, typ::U32, typ::F32, typ::Void, typ::Bool types instead of the just the sem::Types.

Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Ic492e33bc909e0821b581af05242d956631db2e3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48602
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/program_builder.h b/src/program_builder.h
index d8651a9..2c61450 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -21,10 +21,13 @@
 #include "src/ast/array_accessor_expression.h"
 #include "src/ast/assignment_statement.h"
 #include "src/ast/binary_expression.h"
+#include "src/ast/bool.h"
 #include "src/ast/bool_literal.h"
 #include "src/ast/call_expression.h"
 #include "src/ast/case_statement.h"
+#include "src/ast/f32.h"
 #include "src/ast/float_literal.h"
+#include "src/ast/i32.h"
 #include "src/ast/if_statement.h"
 #include "src/ast/loop_statement.h"
 #include "src/ast/member_accessor_expression.h"
@@ -39,8 +42,10 @@
 #include "src/ast/struct_member_size_decoration.h"
 #include "src/ast/switch_statement.h"
 #include "src/ast/type_constructor_expression.h"
+#include "src/ast/u32.h"
 #include "src/ast/uint_literal.h"
 #include "src/ast/variable_decl_statement.h"
+#include "src/ast/void.h"
 #include "src/program.h"
 #include "src/program_id.h"
 #include "src/sem/access_control_type.h"
@@ -55,6 +60,7 @@
 #include "src/sem/u32_type.h"
 #include "src/sem/vector_type.h"
 #include "src/sem/void_type.h"
+#include "src/typepair.h"
 
 namespace tint {
 
@@ -329,19 +335,29 @@
     }
 
     /// @returns a boolean type
-    sem::Bool* bool_() const { return builder->create<sem::Bool>(); }
+    typ::Bool bool_() const {
+      return {builder->create<ast::Bool>(), builder->create<sem::Bool>()};
+    }
 
     /// @returns a f32 type
-    sem::F32* f32() const { return builder->create<sem::F32>(); }
+    typ::F32 f32() const {
+      return {builder->create<ast::F32>(), builder->create<sem::F32>()};
+    }
 
     /// @returns a i32 type
-    sem::I32* i32() const { return builder->create<sem::I32>(); }
+    typ::I32 i32() const {
+      return {builder->create<ast::I32>(), builder->create<sem::I32>()};
+    }
 
     /// @returns a u32 type
-    sem::U32* u32() const { return builder->create<sem::U32>(); }
+    typ::U32 u32() const {
+      return {builder->create<ast::U32>(), builder->create<sem::U32>()};
+    }
 
     /// @returns a void type
-    sem::Void* void_() const { return builder->create<sem::Void>(); }
+    typ::Void void_() const {
+      return {builder->create<ast::Void>(), builder->create<sem::Void>()};
+    }
 
     /// @param type vector subtype
     /// @return the tint AST type for a 2-element vector of `type`.
diff --git a/src/program_builder_test.cc b/src/program_builder_test.cc
index bfa9159..f5a7394 100644
--- a/src/program_builder_test.cc
+++ b/src/program_builder_test.cc
@@ -33,7 +33,7 @@
 TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
   Program inner([] {
     ProgramBuilder builder;
-    auto* ty = builder.ty.f32();
+    auto ty = builder.ty.f32();
     builder.Func("a", {}, ty, {}, {});
     return builder;
   }());
@@ -54,7 +54,7 @@
   EXPECT_FALSE(inner.Symbols().Get("b").IsValid());
   EXPECT_FALSE(outer.Symbols().Get("b").IsValid());
 
-  auto* ty = outer.ty.f32();
+  auto ty = outer.ty.f32();
   outer.Func("b", {}, ty, {}, {});
 
   ASSERT_EQ(inner.AST().Functions().size(), 1u);
diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc
index 68ce72a..f92eb00 100644
--- a/src/reader/wgsl/parser_impl_struct_member_test.cc
+++ b/src/reader/wgsl/parser_impl_struct_member_test.cc
@@ -23,7 +23,7 @@
   auto p = parser("a : i32;");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
@@ -49,7 +49,7 @@
   auto p = parser("[[offset(2)]] a : i32;");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
@@ -79,7 +79,7 @@
   auto p = parser("[[align(2)]] a : i32;");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
@@ -108,7 +108,7 @@
   auto p = parser("[[size(2)]] a : i32;");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
@@ -137,7 +137,7 @@
   auto p = parser("[[size(2)]] a : i32;");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
@@ -167,7 +167,7 @@
 [[align(4)]] a : i32;)");
 
   auto& builder = p->builder();
-  auto* i32 = builder.ty.i32();
+  auto i32 = builder.ty.i32();
 
   auto decos = p->decoration_list();
   EXPECT_FALSE(decos.errored);
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index 24790f1..697c706 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -245,7 +245,8 @@
 
   for (auto* node : builder_->ASTNodes().Objects()) {
     if (marked_.count(node) == 0) {
-      if (node->IsAnyOf<ast::AccessDecoration, ast::StrideDecoration>()) {
+      if (node->IsAnyOf<ast::AccessDecoration, ast::StrideDecoration,
+                        ast::Type>()) {
         // TODO(crbug.com/tint/724) - Remove once tint:724 is complete.
         // ast::AccessDecorations are generated by the WGSL parser, used to
         // build sem::AccessControls and then leaked.
@@ -253,6 +254,7 @@
         // multiple arrays of the same stride, size and element type are
         // currently de-duplicated by the type manager, and we leak these
         // decorations.
+        // ast::Types are being built, but not yet being handled. This is WIP.
         continue;
       }
       TINT_ICE(diagnostics_) << "AST node '" << node->TypeInfo().name
diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc
index 9e77e94..71fc2e2 100644
--- a/src/writer/hlsl/generator_impl_type_test.cc
+++ b/src/writer/hlsl/generator_impl_type_test.cc
@@ -105,7 +105,7 @@
 }
 
 TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
-  auto* bool_ = ty.bool_();
+  auto bool_ = ty.bool_();
 
   GeneratorImpl& gen = Build();
 
@@ -115,7 +115,7 @@
 }
 
 TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
-  auto* f32 = ty.f32();
+  auto f32 = ty.f32();
 
   GeneratorImpl& gen = Build();
 
@@ -125,7 +125,7 @@
 }
 
 TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
 
   GeneratorImpl& gen = Build();
 
@@ -265,7 +265,7 @@
 }
 
 TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
-  auto* u32 = ty.u32();
+  auto u32 = ty.u32();
 
   GeneratorImpl& gen = Build();
 
@@ -285,7 +285,7 @@
 }
 
 TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
-  auto* void_ = ty.void_();
+  auto void_ = ty.void_();
 
   GeneratorImpl& gen = Build();
 
diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc
index 6cb8d72..836b22f 100644
--- a/src/writer/msl/generator_impl_type_test.cc
+++ b/src/writer/msl/generator_impl_type_test.cc
@@ -127,7 +127,7 @@
 }
 
 TEST_F(MslGeneratorImplTest, EmitType_Bool) {
-  auto* bool_ = ty.bool_();
+  auto bool_ = ty.bool_();
 
   GeneratorImpl& gen = Build();
 
@@ -136,7 +136,7 @@
 }
 
 TEST_F(MslGeneratorImplTest, EmitType_F32) {
-  auto* f32 = ty.f32();
+  auto f32 = ty.f32();
 
   GeneratorImpl& gen = Build();
 
@@ -145,7 +145,7 @@
 }
 
 TEST_F(MslGeneratorImplTest, EmitType_I32) {
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
 
   GeneratorImpl& gen = Build();
 
@@ -604,7 +604,7 @@
 }
 
 TEST_F(MslGeneratorImplTest, EmitType_U32) {
-  auto* u32 = ty.u32();
+  auto u32 = ty.u32();
 
   GeneratorImpl& gen = Build();
 
@@ -622,7 +622,7 @@
 }
 
 TEST_F(MslGeneratorImplTest, EmitType_Void) {
-  auto* void_ = ty.void_();
+  auto void_ = ty.void_();
 
   GeneratorImpl& gen = Build();
 
diff --git a/src/writer/spirv/builder_entry_point_test.cc b/src/writer/spirv/builder_entry_point_test.cc
index 555b93c..ecbc205 100644
--- a/src/writer/spirv/builder_entry_point_test.cc
+++ b/src/writer/spirv/builder_entry_point_test.cc
@@ -42,7 +42,7 @@
   //              [[location(1)]] loc1 : f32) {
   //   var col : f32 = (coord.x * loc1);
   // }
-  auto* f32 = ty.f32();
+  auto f32 = ty.f32();
   auto* vec4 = ty.vec4<float>();
   auto* coord = Param(
       "coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
@@ -106,8 +106,8 @@
   //   }
   //   return 1.0;
   // }
-  auto* f32 = ty.f32();
-  auto* u32 = ty.u32();
+  auto f32 = ty.f32();
+  auto u32 = ty.u32();
   auto* loc_in = Param("loc_in", u32, {create<ast::LocationDecoration>(0)});
   auto* cond = create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThan,
                                              Expr("loc_in"), Expr(10u));
diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc
index ed081d8..f445009 100644
--- a/src/writer/spirv/builder_type_test.cc
+++ b/src/writer/spirv/builder_type_test.cc
@@ -41,8 +41,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedAlias) {
-  auto* i32 = ty.i32();
-  auto* f32 = ty.f32();
+  auto i32 = ty.i32();
+  auto f32 = ty.f32();
   auto* alias_type = ty.alias("my_type", f32);
 
   spirv::Builder& b = Build();
@@ -148,7 +148,7 @@
 }
 
 TEST_F(BuilderTest_Type, GenerateBool) {
-  auto* bool_ = ty.bool_();
+  auto bool_ = ty.bool_();
 
   spirv::Builder& b = Build();
 
@@ -162,8 +162,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedBool) {
-  auto* bool_ = ty.bool_();
-  auto* i32 = ty.i32();
+  auto bool_ = ty.bool_();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -176,7 +176,7 @@
 }
 
 TEST_F(BuilderTest_Type, GenerateF32) {
-  auto* f32 = ty.f32();
+  auto f32 = ty.f32();
 
   spirv::Builder& b = Build();
 
@@ -190,8 +190,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedF32) {
-  auto* f32 = ty.f32();
-  auto* i32 = ty.i32();
+  auto f32 = ty.f32();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -204,7 +204,7 @@
 }
 
 TEST_F(BuilderTest_Type, GenerateI32) {
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -218,8 +218,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedI32) {
-  auto* f32 = ty.f32();
-  auto* i32 = ty.i32();
+  auto f32 = ty.f32();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -249,7 +249,7 @@
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedMatrix) {
   auto* mat = ty.mat4x3<i32>();
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -500,7 +500,7 @@
 }
 
 TEST_F(BuilderTest_Type, GenerateU32) {
-  auto* u32 = ty.u32();
+  auto u32 = ty.u32();
 
   spirv::Builder& b = Build();
 
@@ -514,8 +514,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedU32) {
-  auto* u32 = ty.u32();
-  auto* f32 = ty.f32();
+  auto u32 = ty.u32();
+  auto f32 = ty.f32();
 
   spirv::Builder& b = Build();
 
@@ -544,7 +544,7 @@
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedVector) {
   auto* vec = ty.vec3<i32>();
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
@@ -557,7 +557,7 @@
 }
 
 TEST_F(BuilderTest_Type, GenerateVoid) {
-  auto* void_ = ty.void_();
+  auto void_ = ty.void_();
 
   spirv::Builder& b = Build();
 
@@ -571,8 +571,8 @@
 }
 
 TEST_F(BuilderTest_Type, ReturnsGeneratedVoid) {
-  auto* void_ = ty.void_();
-  auto* i32 = ty.i32();
+  auto void_ = ty.void_();
+  auto i32 = ty.i32();
 
   spirv::Builder& b = Build();
 
diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc
index 0ac4460..8f03f60 100644
--- a/src/writer/wgsl/generator_impl_type_test.cc
+++ b/src/writer/wgsl/generator_impl_type_test.cc
@@ -110,7 +110,7 @@
 }
 
 TEST_F(WgslGeneratorImplTest, EmitType_Bool) {
-  auto* bool_ = ty.bool_();
+  auto bool_ = ty.bool_();
   AST().AddConstructedType(ty.alias("make_type_reachable", bool_));
 
   GeneratorImpl& gen = Build();
@@ -120,7 +120,7 @@
 }
 
 TEST_F(WgslGeneratorImplTest, EmitType_F32) {
-  auto* f32 = ty.f32();
+  auto f32 = ty.f32();
   AST().AddConstructedType(ty.alias("make_type_reachable", f32));
 
   GeneratorImpl& gen = Build();
@@ -130,7 +130,7 @@
 }
 
 TEST_F(WgslGeneratorImplTest, EmitType_I32) {
-  auto* i32 = ty.i32();
+  auto i32 = ty.i32();
   AST().AddConstructedType(ty.alias("make_type_reachable", i32));
 
   GeneratorImpl& gen = Build();
@@ -294,7 +294,7 @@
 }
 
 TEST_F(WgslGeneratorImplTest, EmitType_U32) {
-  auto* u32 = ty.u32();
+  auto u32 = ty.u32();
   AST().AddConstructedType(ty.alias("make_type_reachable", u32));
 
   GeneratorImpl& gen = Build();