ast: Remove helpers from ast::Type

These are legacy methods that were written before the semantic type nodes.

These methods do not consider aliases, and any use of these is likely to be broken for aliases.

Fix up uses of these methods to use the semantic types instead.

Change-Id: Ia66749b279eddff655d3d755fef54a6263643e69
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66601
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/ast/ast_type.cc b/src/ast/ast_type.cc
index 4676d29..d48d66d 100644
--- a/src/ast/ast_type.cc
+++ b/src/ast/ast_type.cc
@@ -38,77 +38,5 @@
 
 Type::~Type() = default;
 
-Type* Type::UnwrapAll() {
-  auto* type = this;
-  while (true) {
-    if (auto* ptr = type->As<Pointer>()) {
-      type = ptr->type();
-    } else {
-      break;
-    }
-  }
-  return type;
-}
-
-bool Type::is_scalar() const {
-  return IsAnyOf<F32, U32, I32, Bool>();
-}
-
-bool Type::is_float_scalar() const {
-  return Is<F32>();
-}
-
-bool Type::is_float_matrix() const {
-  return Is([](const Matrix* m) { return m->type()->is_float_scalar(); });
-}
-
-bool Type::is_float_vector() const {
-  return Is([](const Vector* v) { return v->type()->is_float_scalar(); });
-}
-
-bool Type::is_float_scalar_or_vector() const {
-  return is_float_scalar() || is_float_vector();
-}
-
-bool Type::is_float_scalar_or_vector_or_matrix() const {
-  return is_float_scalar() || is_float_vector() || is_float_matrix();
-}
-
-bool Type::is_integer_scalar() const {
-  return IsAnyOf<U32, I32>();
-}
-
-bool Type::is_unsigned_integer_vector() const {
-  return Is([](const Vector* v) { return v->type()->Is<U32>(); });
-}
-
-bool Type::is_signed_integer_vector() const {
-  return Is([](const Vector* v) { return v->type()->Is<I32>(); });
-}
-
-bool Type::is_unsigned_scalar_or_vector() const {
-  return Is<U32>() || is_unsigned_integer_vector();
-}
-
-bool Type::is_signed_scalar_or_vector() const {
-  return Is<I32>() || is_signed_integer_vector();
-}
-
-bool Type::is_integer_scalar_or_vector() const {
-  return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
-}
-
-bool Type::is_bool_vector() const {
-  return Is([](const Vector* v) { return v->type()->Is<Bool>(); });
-}
-
-bool Type::is_bool_scalar_or_vector() const {
-  return Is<Bool>() || is_bool_vector();
-}
-
-bool Type::is_handle() const {
-  return IsAnyOf<Sampler, Texture>();
-}
-
 }  // namespace ast
 }  // namespace tint
diff --git a/src/ast/type.h b/src/ast/type.h
index 26c9daf..c03a2b5 100644
--- a/src/ast/type.h
+++ b/src/ast/type.h
@@ -40,43 +40,6 @@
   /// declared in WGSL.
   virtual std::string FriendlyName(const SymbolTable& symbols) const = 0;
 
-  /// @returns the type with all aliasing, access control and pointers removed
-  Type* UnwrapAll();
-
-  /// @returns the type with all aliasing, access control and pointers removed
-  const Type* UnwrapAll() const { return const_cast<Type*>(this)->UnwrapAll(); }
-
-  /// @returns true if this type is a scalar
-  bool is_scalar() const;
-  /// @returns true if this type is a float scalar
-  bool is_float_scalar() const;
-  /// @returns true if this type is a float matrix
-  bool is_float_matrix() const;
-  /// @returns true if this type is a float vector
-  bool is_float_vector() const;
-  /// @returns true if this type is a float scalar or vector
-  bool is_float_scalar_or_vector() const;
-  /// @returns true if this type is a float scalar or vector or matrix
-  bool is_float_scalar_or_vector_or_matrix() const;
-  /// @returns true if this type is an integer scalar
-  bool is_integer_scalar() const;
-  /// @returns true if this type is a signed integer vector
-  bool is_signed_integer_vector() const;
-  /// @returns true if this type is an unsigned vector
-  bool is_unsigned_integer_vector() const;
-  /// @returns true if this type is an unsigned scalar or vector
-  bool is_unsigned_scalar_or_vector() const;
-  /// @returns true if this type is a signed scalar or vector
-  bool is_signed_scalar_or_vector() const;
-  /// @returns true if this type is an integer scalar or vector
-  bool is_integer_scalar_or_vector() const;
-  /// @returns true if this type is a boolean vector
-  bool is_bool_vector() const;
-  /// @returns true if this type is boolean scalar or vector
-  bool is_bool_scalar_or_vector() const;
-  /// @returns true if this type is a handle type
-  bool is_handle() const;
-
  protected:
   /// Constructor
   /// @param program_id the identifier of the program that owns this node
diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc
index 6b9f5dc..4c3c266 100644
--- a/src/reader/wgsl/parser_impl_type_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_type_decl_test.cc
@@ -702,7 +702,9 @@
 
   auto* a = t.value->As<ast::Array>();
   ASSERT_TRUE(a->IsRuntimeArray());
-  ASSERT_TRUE(a->type()->is_unsigned_integer_vector());
+  ASSERT_TRUE(a->type()->Is<ast::Vector>());
+  EXPECT_EQ(a->type()->As<ast::Vector>()->size(), 4u);
+  EXPECT_TRUE(a->type()->As<ast::Vector>()->type()->Is<ast::U32>());
   EXPECT_EQ(t.value->source().range, (Source::Range{{1u, 1u}, {1u, 17u}}));
 }
 
diff --git a/src/resolver/intrinsic_test.cc b/src/resolver/intrinsic_test.cc
index 6358f01..5e6526a 100644
--- a/src/resolver/intrinsic_test.cc
+++ b/src/resolver/intrinsic_test.cc
@@ -244,7 +244,7 @@
   void add_call_param(std::string name,
                       const ast::Type* type,
                       ast::ExpressionList* call_params) {
-    if (type->UnwrapAll()->is_handle()) {
+    if (type->IsAnyOf<ast::Texture, ast::Sampler>()) {
       Global(name, type,
              ast::DecorationList{
                  create<ast::BindingDecoration>(0),
diff --git a/src/transform/canonicalize_entry_point_io.cc b/src/transform/canonicalize_entry_point_io.cc
index 4814e12..46f24ae 100644
--- a/src/transform/canonicalize_entry_point_io.cc
+++ b/src/transform/canonicalize_entry_point_io.cc
@@ -155,8 +155,9 @@
   /// @param attributes the attributes to apply to the shader input
   /// @returns an expression which evaluates to the value of the shader input
   ast::Expression* AddInput(std::string name,
-                            ast::Type* type,
+                            sem::Type* type,
                             ast::DecorationList attributes) {
+    auto* ast_type = CreateASTTypeFor(ctx, type);
     if (cfg.shader_style == ShaderStyle::kSpirv) {
       // Vulkan requires that integer user-defined fragment inputs are
       // always decorated with `Flat`.
@@ -178,10 +179,10 @@
       if (HasSampleMask(attributes)) {
         // Vulkan requires the type of a SampleMask builtin to be an array.
         // Declare it as array<u32, 1> and then load the first element.
-        type = ctx.dst->ty.array(type, 1);
+        ast_type = ctx.dst->ty.array(ast_type, 1);
         value = ctx.dst->IndexAccessor(value, 0);
       }
-      ctx.dst->Global(symbol, type, ast::StorageClass::kInput,
+      ctx.dst->Global(symbol, ast_type, ast::StorageClass::kInput,
                       std::move(attributes));
       return value;
     } else if (cfg.shader_style == ShaderStyle::kMsl &&
@@ -192,7 +193,7 @@
                           ? ctx.dst->Symbols().Register(name)
                           : ctx.dst->Symbols().New(name);
       wrapper_ep_parameters.push_back(
-          ctx.dst->Param(symbol, type, std::move(attributes)));
+          ctx.dst->Param(symbol, ast_type, std::move(attributes)));
       return ctx.dst->Expr(symbol);
     } else {
       // Otherwise, move it to the new structure member list.
@@ -200,7 +201,7 @@
                           ? ctx.dst->Symbols().Register(name)
                           : ctx.dst->Symbols().New(name);
       wrapper_struct_param_members.push_back(
-          ctx.dst->Member(symbol, type, std::move(attributes)));
+          ctx.dst->Member(symbol, ast_type, std::move(attributes)));
       return ctx.dst->MemberAccessor(InputStructSymbol(), symbol);
     }
   }
@@ -211,7 +212,7 @@
   /// @param attributes the attributes to apply to the shader output
   /// @param value the value of the shader output
   void AddOutput(std::string name,
-                 ast::Type* type,
+                 sem::Type* type,
                  ast::DecorationList attributes,
                  ast::Expression* value) {
     // Vulkan requires that integer user-defined vertex outputs are
@@ -226,7 +227,7 @@
 
     OutputValue output;
     output.name = name;
-    output.type = type;
+    output.type = CreateASTTypeFor(ctx, type);
     output.attributes = std::move(attributes);
     output.value = value;
     wrapper_output_values.push_back(output);
@@ -249,8 +250,7 @@
     }
 
     auto name = ctx.src->Symbols().NameFor(param->Declaration()->symbol());
-    auto* type = ctx.Clone(param->Declaration()->type());
-    auto* input_expr = AddInput(name, type, std::move(attributes));
+    auto* input_expr = AddInput(name, param->Type(), std::move(attributes));
     inner_call_parameters.push_back(input_expr);
   }
 
@@ -273,9 +273,8 @@
 
       auto* member_ast = member->Declaration();
       auto name = ctx.src->Symbols().NameFor(member_ast->symbol());
-      auto* type = ctx.Clone(member_ast->type());
       auto attributes = CloneShaderIOAttributes(member_ast->decorations());
-      auto* input_expr = AddInput(name, type, std::move(attributes));
+      auto* input_expr = AddInput(name, member->Type(), std::move(attributes));
       inner_struct_values.push_back(input_expr);
     }
 
@@ -300,20 +299,18 @@
 
         auto* member_ast = member->Declaration();
         auto name = ctx.src->Symbols().NameFor(member_ast->symbol());
-        auto* type = ctx.Clone(member_ast->type());
         auto attributes = CloneShaderIOAttributes(member_ast->decorations());
 
         // Extract the original structure member.
-        AddOutput(name, type, std::move(attributes),
+        AddOutput(name, member->Type(), std::move(attributes),
                   ctx.dst->MemberAccessor(original_result, name));
       }
     } else if (!inner_ret_type->Is<sem::Void>()) {
-      auto* type = ctx.Clone(func_ast->return_type());
       auto attributes =
           CloneShaderIOAttributes(func_ast->return_type_decorations());
 
       // Propagate the non-struct return value as is.
-      AddOutput("value", type, std::move(attributes),
+      AddOutput("value", func_sem->ReturnType(), std::move(attributes),
                 ctx.dst->Expr(original_result));
     }
   }
@@ -333,7 +330,7 @@
 
     // No existing sample mask builtin was found, so create a new output value
     // using the fixed sample mask.
-    AddOutput("fixed_sample_mask", ctx.dst->ty.u32(),
+    AddOutput("fixed_sample_mask", ctx.dst->create<sem::U32>(),
               {ctx.dst->Builtin(ast::Builtin::kSampleMask)},
               ctx.dst->Expr(cfg.fixed_sample_mask));
   }
@@ -341,7 +338,7 @@
   /// Add a point size builtin to the wrapper function output.
   void AddVertexPointSize() {
     // Create a new output value and assign it a literal 1.0 value.
-    AddOutput("vertex_point_size", ctx.dst->ty.f32(),
+    AddOutput("vertex_point_size", ctx.dst->create<sem::F32>(),
               {ctx.dst->Builtin(ast::Builtin::kPointSize)}, ctx.dst->Expr(1.f));
   }
 
diff --git a/src/transform/canonicalize_entry_point_io_test.cc b/src/transform/canonicalize_entry_point_io_test.cc
index 084d221..a011e85 100644
--- a/src/transform/canonicalize_entry_point_io_test.cc
+++ b/src/transform/canonicalize_entry_point_io_test.cc
@@ -181,7 +181,7 @@
 
 struct tint_symbol_1 {
   [[location(1)]]
-  loc1 : myf32;
+  loc1 : f32;
 };
 
 fn frag_main_inner(loc1 : myf32) {
@@ -982,16 +982,16 @@
 
 struct tint_symbol_1 {
   [[location(0)]]
-  col1 : myf32;
+  col1 : f32;
   [[location(1)]]
-  col2 : myf32;
+  col2 : f32;
 };
 
 struct tint_symbol_2 {
   [[location(0)]]
-  col1 : myf32;
+  col1 : f32;
   [[location(1)]]
-  col2 : myf32;
+  col2 : f32;
 };
 
 fn frag_main_inner(inputs : MyFragmentInput) -> MyFragmentOutput {
diff --git a/src/transform/module_scope_var_to_entry_point_param.cc b/src/transform/module_scope_var_to_entry_point_param.cc
index c70d7fd..f0a3ee7f 100644
--- a/src/transform/module_scope_var_to_entry_point_param.cc
+++ b/src/transform/module_scope_var_to_entry_point_param.cc
@@ -228,7 +228,7 @@
           // Use a pointer for non-handle types.
           auto* param_type = store_type();
           ast::DecorationList attributes;
-          if (!param_type->is_handle()) {
+          if (!var->Type()->UnwrapRef()->is_handle()) {
             param_type = ctx.dst->ty.pointer(param_type, var->StorageClass());
             is_pointer = true;
 
diff --git a/src/writer/append_vector_test.cc b/src/writer/append_vector_test.cc
index ed271d8..e720c48 100644
--- a/src/writer/append_vector_test.cc
+++ b/src/writer/append_vector_test.cc
@@ -84,7 +84,10 @@
   auto* v2u32_to_v2i32 =
       vec_123->values()[0]->As<ast::TypeConstructorExpression>();
   ASSERT_NE(v2u32_to_v2i32, nullptr);
-  EXPECT_TRUE(v2u32_to_v2i32->type()->is_signed_integer_vector());
+  ASSERT_TRUE(v2u32_to_v2i32->type()->Is<ast::Vector>());
+  EXPECT_EQ(v2u32_to_v2i32->type()->As<ast::Vector>()->size(), 2u);
+  EXPECT_TRUE(
+      v2u32_to_v2i32->type()->As<ast::Vector>()->type()->Is<ast::I32>());
   EXPECT_EQ(v2u32_to_v2i32->values().size(), 1u);
   EXPECT_EQ(v2u32_to_v2i32->values()[0], uvec_12);
 
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index 89e8d06..3ecf89b 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -1622,7 +1622,7 @@
 
       if (type->Is<sem::Struct>()) {
         out << " [[stage_in]]";
-      } else if (var->type()->is_handle()) {
+      } else if (type->is_handle()) {
         auto bp = var->binding_point();
         if (bp.group == nullptr || bp.binding == nullptr) {
           TINT_ICE(Writer, diagnostics_)