Replace TextureType::(Is|As)Depth with Castable

Change-Id: I2f1785cec1880f728fbbf0c75762bc957e34ca0a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34276
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/ast/type/depth_texture_type.cc b/src/ast/type/depth_texture_type.cc
index 79f8e06..95a954f 100644
--- a/src/ast/type/depth_texture_type.cc
+++ b/src/ast/type/depth_texture_type.cc
@@ -41,10 +41,6 @@
 
 DepthTextureType::~DepthTextureType() = default;
 
-bool DepthTextureType::IsDepth() const {
-  return true;
-}
-
 std::string DepthTextureType::type_name() const {
   std::ostringstream out;
   out << "__depth_texture_" << dim();
diff --git a/src/ast/type/depth_texture_type.h b/src/ast/type/depth_texture_type.h
index ee05dc3..4f58fb0 100644
--- a/src/ast/type/depth_texture_type.h
+++ b/src/ast/type/depth_texture_type.h
@@ -33,9 +33,6 @@
   DepthTextureType(DepthTextureType&&);
   ~DepthTextureType() override;
 
-  /// @returns true if the type is a depth texture type
-  bool IsDepth() const override;
-
   /// @returns the name for this type
   std::string type_name() const override;
 };
diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc
index 51c7014..2798b93 100644
--- a/src/ast/type/depth_texture_type_test.cc
+++ b/src/ast/type/depth_texture_type_test.cc
@@ -54,7 +54,7 @@
 
 TEST_F(DepthTextureTypeTest, IsTextureType) {
   DepthTextureType d(TextureDimension::kCube);
-  EXPECT_TRUE(d.IsDepth());
+  EXPECT_TRUE(d.Is<DepthTextureType>());
   EXPECT_FALSE(d.IsSampled());
   EXPECT_FALSE(d.IsStorage());
 }
diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc
index 32756ce..108acb2 100644
--- a/src/ast/type/multisampled_texture_type_test.cc
+++ b/src/ast/type/multisampled_texture_type_test.cc
@@ -18,6 +18,7 @@
 #include "src/ast/type/access_control_type.h"
 #include "src/ast/type/array_type.h"
 #include "src/ast/type/bool_type.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/i32_type.h"
 #include "src/ast/type/matrix_type.h"
@@ -55,10 +56,11 @@
 TEST_F(MultisampledTextureTypeTest, IsTextureType) {
   F32Type f32;
   MultisampledTextureType s(TextureDimension::kCube, &f32);
-  EXPECT_FALSE(s.IsDepth());
-  EXPECT_TRUE(s.IsMultisampled());
-  EXPECT_FALSE(s.IsSampled());
-  EXPECT_FALSE(s.IsStorage());
+  TextureType* ty = &s;
+  EXPECT_FALSE(ty->Is<DepthTextureType>());
+  EXPECT_TRUE(ty->IsMultisampled());
+  EXPECT_FALSE(ty->IsSampled());
+  EXPECT_FALSE(ty->IsStorage());
 }
 
 TEST_F(MultisampledTextureTypeTest, Dim) {
diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc
index 9e68b82..a37b8b7 100644
--- a/src/ast/type/sampled_texture_type_test.cc
+++ b/src/ast/type/sampled_texture_type_test.cc
@@ -18,6 +18,7 @@
 #include "src/ast/type/access_control_type.h"
 #include "src/ast/type/array_type.h"
 #include "src/ast/type/bool_type.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/i32_type.h"
 #include "src/ast/type/matrix_type.h"
@@ -55,9 +56,10 @@
 TEST_F(SampledTextureTypeTest, IsTextureType) {
   F32Type f32;
   SampledTextureType s(TextureDimension::kCube, &f32);
-  EXPECT_FALSE(s.IsDepth());
-  EXPECT_TRUE(s.IsSampled());
-  EXPECT_FALSE(s.IsStorage());
+  TextureType* ty = &s;
+  EXPECT_FALSE(ty->Is<DepthTextureType>());
+  EXPECT_TRUE(ty->IsSampled());
+  EXPECT_FALSE(ty->IsStorage());
 }
 
 TEST_F(SampledTextureTypeTest, Dim) {
diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc
index 4d71c41..cc548c9 100644
--- a/src/ast/type/storage_texture_type_test.cc
+++ b/src/ast/type/storage_texture_type_test.cc
@@ -21,6 +21,7 @@
 #include "src/ast/type/access_control_type.h"
 #include "src/ast/type/array_type.h"
 #include "src/ast/type/bool_type.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/i32_type.h"
 #include "src/ast/type/matrix_type.h"
@@ -59,9 +60,10 @@
 TEST_F(StorageTextureTypeTest, IsTextureType) {
   StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
                        ImageFormat::kRgba32Float);
-  EXPECT_FALSE(s.IsDepth());
-  EXPECT_FALSE(s.IsSampled());
-  EXPECT_TRUE(s.IsStorage());
+  TextureType* ty = &s;
+  EXPECT_FALSE(ty->Is<DepthTextureType>());
+  EXPECT_FALSE(ty->IsSampled());
+  EXPECT_TRUE(ty->IsStorage());
 }
 
 TEST_F(StorageTextureTypeTest, Dim) {
diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc
index c6ff7f1..2e986f4 100644
--- a/src/ast/type/texture_type.cc
+++ b/src/ast/type/texture_type.cc
@@ -16,7 +16,6 @@
 
 #include <cassert>
 
-#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/multisampled_texture_type.h"
 #include "src/ast/type/sampled_texture_type.h"
 #include "src/ast/type/storage_texture_type.h"
@@ -61,9 +60,6 @@
 
 TextureType::~TextureType() = default;
 
-bool TextureType::IsDepth() const {
-  return false;
-}
 bool TextureType::IsMultisampled() const {
   return false;
 }
@@ -74,11 +70,6 @@
   return false;
 }
 
-const DepthTextureType* TextureType::AsDepth() const {
-  assert(IsDepth());
-  return static_cast<const DepthTextureType*>(this);
-}
-
 const MultisampledTextureType* TextureType::AsMultisampled() const {
   assert(IsMultisampled());
   return static_cast<const MultisampledTextureType*>(this);
@@ -94,11 +85,6 @@
   return static_cast<const StorageTextureType*>(this);
 }
 
-DepthTextureType* TextureType::AsDepth() {
-  assert(IsDepth());
-  return static_cast<DepthTextureType*>(this);
-}
-
 MultisampledTextureType* TextureType::AsMultisampled() {
   assert(IsMultisampled());
   return static_cast<MultisampledTextureType*>(this);
diff --git a/src/ast/type/texture_type.h b/src/ast/type/texture_type.h
index 4cb9b23..b2eba82 100644
--- a/src/ast/type/texture_type.h
+++ b/src/ast/type/texture_type.h
@@ -63,8 +63,6 @@
   /// @returns the texture dimension
   TextureDimension dim() const { return dim_; }
 
-  /// @returns true if this is a depth texture
-  virtual bool IsDepth() const;
   /// @returns ture if this is a multisampled texture
   virtual bool IsMultisampled() const;
   /// @returns true if this is a storage texture
@@ -72,8 +70,6 @@
   /// @returns true if this is a sampled texture
   virtual bool IsSampled() const;
 
-  /// @returns the texture as a depth texture
-  const DepthTextureType* AsDepth() const;
   /// @returns the texture as a multisampled texture
   const MultisampledTextureType* AsMultisampled() const;
   /// @returns the texture as a sampled texture
@@ -81,8 +77,6 @@
   /// @returns the texture as a storage texture
   const StorageTextureType* AsStorage() const;
 
-  /// @returns the texture as a depth texture
-  DepthTextureType* AsDepth();
   /// @returns the texture as a multisampled texture
   MultisampledTextureType* AsMultisampled();
   /// @returns the texture as a sampled texture
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index ccff3fd..bc2d5c7 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -53,6 +53,7 @@
 #include "src/ast/storage_class.h"
 #include "src/ast/switch_statement.h"
 #include "src/ast/type/bool_type.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/pointer_type.h"
 #include "src/ast/type/texture_type.h"
@@ -3714,7 +3715,7 @@
             parser_impl_.GetTypeForHandleVar(*image)) {
       if (ast::type::TextureType* texture_type =
               type->type()->As<ast::type::TextureType>()) {
-        if (texture_type->IsDepth()) {
+        if (texture_type->Is<ast::type::DepthTextureType>()) {
           // Convert it to an unsigned integer type.
           lod_operand = ast_module_.create<ast::TypeConstructorExpression>(
               ast_module_.create<ast::type::U32Type>(),
diff --git a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc
index 78783f9..fd1d93b 100644
--- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc
+++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc
@@ -37,7 +37,8 @@
   EXPECT_FALSE(t.errored);
   ASSERT_NE(t.value, nullptr);
   ASSERT_TRUE(t->Is<ast::type::TextureType>());
-  ASSERT_TRUE(t->As<ast::type::TextureType>()->IsDepth());
+  ASSERT_TRUE(
+      t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
   EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
             ast::type::TextureDimension::k2d);
   EXPECT_FALSE(p->has_error());
@@ -50,7 +51,8 @@
   EXPECT_FALSE(t.errored);
   ASSERT_NE(t.value, nullptr);
   ASSERT_TRUE(t->Is<ast::type::TextureType>());
-  ASSERT_TRUE(t->As<ast::type::TextureType>()->IsDepth());
+  ASSERT_TRUE(
+      t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
   EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
             ast::type::TextureDimension::k2dArray);
   EXPECT_FALSE(p->has_error());
@@ -63,7 +65,8 @@
   EXPECT_FALSE(t.errored);
   ASSERT_NE(t.value, nullptr);
   ASSERT_TRUE(t->Is<ast::type::TextureType>());
-  ASSERT_TRUE(t->As<ast::type::TextureType>()->IsDepth());
+  ASSERT_TRUE(
+      t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
   EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
             ast::type::TextureDimension::kCube);
   EXPECT_FALSE(p->has_error());
@@ -76,7 +79,8 @@
   EXPECT_FALSE(t.errored);
   ASSERT_NE(t.value, nullptr);
   ASSERT_TRUE(t->Is<ast::type::TextureType>());
-  ASSERT_TRUE(t->As<ast::type::TextureType>()->IsDepth());
+  ASSERT_TRUE(
+      t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
   EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
             ast::type::TextureDimension::kCubeArray);
   EXPECT_FALSE(p->has_error());
diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc
index d64c5a2..23869a4 100644
--- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc
+++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc
@@ -13,6 +13,7 @@
 // limitations under the License.
 
 #include "gtest/gtest.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/i32_type.h"
 #include "src/ast/type/multisampled_texture_type.h"
@@ -66,7 +67,7 @@
   EXPECT_FALSE(t.errored);
   ASSERT_NE(t.value, nullptr);
   ASSERT_TRUE(t->Is<ast::type::TextureType>());
-  ASSERT_TRUE(t->As<ast::type::TextureType>()->IsDepth());
+  ASSERT_TRUE(t->Is<ast::type::DepthTextureType>());
   EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
             ast::type::TextureDimension::k2d);
 }
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 964a2fb..9d75b84 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -38,6 +38,7 @@
 #include "src/ast/switch_statement.h"
 #include "src/ast/type/array_type.h"
 #include "src/ast/type/bool_type.h"
+#include "src/ast/type/depth_texture_type.h"
 #include "src/ast/type/f32_type.h"
 #include "src/ast/type/i32_type.h"
 #include "src/ast/type/matrix_type.h"
@@ -665,7 +666,7 @@
     ident->set_intrinsic_signature(
         std::make_unique<ast::intrinsic::TextureSignature>(param));
 
-    if (texture->IsDepth()) {
+    if (texture->Is<ast::type::DepthTextureType>()) {
       expr->func()->set_result_type(mod_->create<ast::type::F32Type>());
       return true;
     }
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index 085be03..41795e2 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -1842,7 +1842,7 @@
   } else if (type->Is<ast::type::TextureType>()) {
     auto* tex = type->As<ast::type::TextureType>();
 
-    if (tex->IsDepth()) {
+    if (tex->Is<ast::type::DepthTextureType>()) {
       out_ << "depth";
     } else {
       out_ << "texture";
@@ -1878,7 +1878,7 @@
       out_ << "_ms";
     }
     out_ << "<";
-    if (tex->IsDepth()) {
+    if (tex->Is<ast::type::DepthTextureType>()) {
       out_ << "float, access::sample";
     } else if (tex->IsStorage()) {
       auto* storage = tex->AsStorage();
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 345de30..f7b28a8 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -2521,23 +2521,24 @@
   }
 
   uint32_t depth_literal = 0u;
-  if (texture->IsDepth()) {
+  if (texture->Is<ast::type::DepthTextureType>()) {
     depth_literal = 1u;
   }
 
   uint32_t sampled_literal = 2u;
-  if (texture->IsMultisampled() || texture->IsSampled() || texture->IsDepth()) {
+  if (texture->IsMultisampled() || texture->IsSampled() ||
+      texture->Is<ast::type::DepthTextureType>()) {
     sampled_literal = 1u;
   }
 
   if (dim == ast::type::TextureDimension::kCubeArray) {
-    if (texture->IsSampled() || texture->IsDepth()) {
+    if (texture->IsSampled() || texture->Is<ast::type::DepthTextureType>()) {
       push_capability(SpvCapabilitySampledCubeArray);
     }
   }
 
   uint32_t type_id = 0u;
-  if (texture->IsDepth()) {
+  if (texture->Is<ast::type::DepthTextureType>()) {
     ast::type::F32Type f32;
     type_id = GenerateTypeIfNeeded(&f32);
   } else if (texture->IsSampled()) {
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 91212c9..7e53242 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -470,7 +470,7 @@
     auto* texture = type->As<ast::type::TextureType>();
 
     out_ << "texture_";
-    if (texture->IsDepth()) {
+    if (texture->Is<ast::type::DepthTextureType>()) {
       out_ << "depth_";
     } else if (texture->IsSampled()) {
       /* nothing to emit */