Remove ArrayCount helpers.

This CL removes the helpers in sem::Array to determine the type of
ArrayCount. Instead the `Is` and `As` functions from Castable are used
at the call sites.

Bug: tint:1718
Change-Id: Ie666bfbfca6bb1be8ead613266a7221d88f7a76d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112442
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc
index aed49c3..ebd5043 100644
--- a/src/tint/resolver/intrinsic_table.cc
+++ b/src/tint/resolver/intrinsic_table.cc
@@ -523,7 +523,7 @@
     }
 
     if (auto* a = ty->As<sem::Array>()) {
-        if (a->IsRuntimeSized()) {
+        if (a->Count()->Is<sem::RuntimeArrayCount>()) {
             T = a->ElemType();
             return true;
         }
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index f909bf0..ca66ac2 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -3639,7 +3639,7 @@
 
     if (auto* arr = ty->As<sem::Array>()) {
         if (address_space != ast::AddressSpace::kStorage) {
-            if (arr->IsRuntimeSized()) {
+            if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                 AddError("runtime-sized arrays can only be used in the <storage> address space",
                          usage);
                 return false;
diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc
index 5a7f9d8..e5c7c1a 100644
--- a/src/tint/resolver/validator.cc
+++ b/src/tint/resolver/validator.cc
@@ -194,7 +194,7 @@
         [&](const sem::Matrix*) { return true; },  //
         [&](const sem::Atomic*) { return true; },
         [&](const sem::Array* arr) {
-            return !arr->IsRuntimeSized() && IsFixedFootprint(arr->ElemType());
+            return !arr->Count()->Is<sem::RuntimeArrayCount>() && IsFixedFootprint(arr->ElemType());
         },
         [&](const sem::Struct* str) {
             for (auto* member : str->Members()) {
@@ -1763,12 +1763,13 @@
         }
     }
 
-    if (array_type->IsRuntimeSized()) {
+    auto* c = array_type->Count();
+    if (c->Is<sem::RuntimeArrayCount>()) {
         AddError("cannot construct a runtime-sized array", ctor->source);
         return false;
     }
 
-    if (array_type->IsOverrideSized()) {
+    if (c->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
         AddError("cannot construct an array that has an override-expression count", ctor->source);
         return false;
     }
@@ -1778,12 +1779,12 @@
         return false;
     }
 
-    if (!array_type->IsConstantSized()) {
+    if (!c->Is<sem::ConstantArrayCount>()) {
         TINT_ICE(Resolver, diagnostics_) << "Invalid ArrayCount found";
         return false;
     }
 
-    const auto count = array_type->Count()->As<sem::ConstantArrayCount>()->value;
+    const auto count = c->As<sem::ConstantArrayCount>()->value;
     if (!values.IsEmpty() && (values.Length() != count)) {
         std::string fm = values.Length() < count ? "few" : "many";
         AddError("array initializer has too " + fm + " elements: expected " +
@@ -2026,7 +2027,7 @@
     utils::Hashset<uint32_t, 8> locations;
     for (auto* member : str->Members()) {
         if (auto* r = member->Type()->As<sem::Array>()) {
-            if (r->IsRuntimeSized()) {
+            if (r->Count()->Is<sem::RuntimeArrayCount>()) {
                 if (member != str->Members().back()) {
                     AddError("runtime arrays may only appear as the last member of a struct",
                              member->Source());
@@ -2398,7 +2399,7 @@
 
 bool Validator::IsArrayWithOverrideCount(const sem::Type* ty) const {
     if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) {
-        if (arr->IsOverrideSized()) {
+        if (arr->Count()->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
             return true;
         }
     }
diff --git a/src/tint/sem/array.h b/src/tint/sem/array.h
index c068948..7a484e5 100644
--- a/src/tint/sem/array.h
+++ b/src/tint/sem/array.h
@@ -103,21 +103,6 @@
     /// natural stride
     bool IsStrideImplicit() const { return stride_ == implicit_stride_; }
 
-    /// @returns true if this array is sized using an const-expression
-    bool IsConstantSized() const { return count_->Is<ConstantArrayCount>(); }
-
-    /// @returns true if this array is sized using a named override variable
-    bool IsNamedOverrideSized() const { return count_->Is<NamedOverrideArrayCount>(); }
-
-    /// @returns true if this array is sized using an unnamed override variable
-    bool IsUnnamedOverrideSized() const { return count_->Is<UnnamedOverrideArrayCount>(); }
-
-    /// @returns true if this array is sized using a named or unnamed override variable
-    bool IsOverrideSized() const { return IsNamedOverrideSized() || IsUnnamedOverrideSized(); }
-
-    /// @returns true if this array is runtime sized
-    bool IsRuntimeSized() const { return count_->Is<RuntimeArrayCount>(); }
-
     /// @param symbols the program's symbol table
     /// @returns the name for this type that closely resembles how it would be
     /// declared in WGSL.
diff --git a/src/tint/sem/array_test.cc b/src/tint/sem/array_test.cc
index 44073df..a2bc3d3 100644
--- a/src/tint/sem/array_test.cc
+++ b/src/tint/sem/array_test.cc
@@ -36,7 +36,7 @@
     EXPECT_EQ(a->Stride(), 32u);
     EXPECT_EQ(a->ImplicitStride(), 16u);
     EXPECT_FALSE(a->IsStrideImplicit());
-    EXPECT_FALSE(a->IsRuntimeSized());
+    EXPECT_FALSE(a->Count()->Is<RuntimeArrayCount>());
 
     EXPECT_EQ(a, b);
     EXPECT_NE(a, c);
@@ -61,7 +61,7 @@
     EXPECT_EQ(a->Stride(), 32u);
     EXPECT_EQ(a->ImplicitStride(), 32u);
     EXPECT_TRUE(a->IsStrideImplicit());
-    EXPECT_TRUE(a->IsRuntimeSized());
+    EXPECT_TRUE(a->Count()->Is<RuntimeArrayCount>());
 
     EXPECT_EQ(a, b);
     EXPECT_NE(a, c);
diff --git a/src/tint/transform/module_scope_var_to_entry_point_param.cc b/src/tint/transform/module_scope_var_to_entry_point_param.cc
index 9c9c42f..9156205 100644
--- a/src/tint/transform/module_scope_var_to_entry_point_param.cc
+++ b/src/tint/transform/module_scope_var_to_entry_point_param.cc
@@ -146,7 +146,8 @@
                 attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace));
 
                 auto* param_type = store_type();
-                if (auto* arr = ty->As<sem::Array>(); arr && arr->IsRuntimeSized()) {
+                if (auto* arr = ty->As<sem::Array>();
+                    arr && arr->Count()->Is<sem::RuntimeArrayCount>()) {
                     // Wrap runtime-sized arrays in structures, so that we can declare pointers to
                     // them. Ideally we'd just emit the array itself as a pointer, but this is not
                     // representable in Tint's AST.
diff --git a/src/tint/transform/pad_structs.cc b/src/tint/transform/pad_structs.cc
index 4ceb39d..e8c21a7 100644
--- a/src/tint/transform/pad_structs.cc
+++ b/src/tint/transform/pad_structs.cc
@@ -84,7 +84,7 @@
                 // std140 structs should be padded out to 16 bytes.
                 size = utils::RoundUp(16u, size);
             } else if (auto* array_ty = ty->As<sem::Array>()) {
-                if (array_ty->IsRuntimeSized()) {
+                if (array_ty->Count()->Is<sem::RuntimeArrayCount>()) {
                     has_runtime_sized_array = true;
                 }
             }
diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc
index 75d63f2..c9f6292 100644
--- a/src/tint/transform/robustness.cc
+++ b/src/tint/transform/robustness.cc
@@ -106,7 +106,7 @@
             },
             [&](const sem::Array* arr) -> const ast::Expression* {
                 const ast::Expression* max = nullptr;
-                if (arr->IsRuntimeSized()) {
+                if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                     // Size is unknown until runtime.
                     // Must clamp, even if the index is constant.
                     auto* arr_ptr = b.AddressOf(ctx.Clone(expr->object));
diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc
index 319975a..de3cdab 100644
--- a/src/tint/transform/spirv_atomic.cc
+++ b/src/tint/transform/spirv_atomic.cc
@@ -202,7 +202,7 @@
             [&](const sem::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
             [&](const sem::Struct* str) { return b.ty.type_name(Fork(str->Declaration()).name); },
             [&](const sem::Array* arr) -> const ast::Type* {
-                if (arr->IsRuntimeSized()) {
+                if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                     return b.ty.array(AtomicTypeFor(arr->ElemType()));
                 }
                 auto count = arr->ConstantCount();
diff --git a/src/tint/transform/transform.cc b/src/tint/transform/transform.cc
index d2eea42..cbfb90a 100644
--- a/src/tint/transform/transform.cc
+++ b/src/tint/transform/transform.cc
@@ -106,7 +106,7 @@
         if (!a->IsStrideImplicit()) {
             attrs.Push(ctx.dst->create<ast::StrideAttribute>(a->Stride()));
         }
-        if (a->IsRuntimeSized()) {
+        if (a->Count()->Is<sem::RuntimeArrayCount>()) {
             return ctx.dst->ty.array(el, nullptr, std::move(attrs));
         }
         if (auto* override = a->Count()->As<sem::NamedOverrideArrayCount>()) {
diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc
index f304d82..c9ca429 100644
--- a/src/tint/writer/glsl/generator_impl.cc
+++ b/src/tint/writer/glsl/generator_impl.cc
@@ -292,7 +292,7 @@
             auto* sem = builder_.Sem().Get(str);
             bool has_rt_arr = false;
             if (auto* arr = sem->Members().back()->Type()->As<sem::Array>()) {
-                has_rt_arr = arr->IsRuntimeSized();
+                has_rt_arr = arr->Count()->Is<sem::RuntimeArrayCount>();
             }
             bool is_block =
                 ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(str->attributes);
@@ -2834,7 +2834,7 @@
         const sem::Type* base_type = ary;
         std::vector<uint32_t> sizes;
         while (auto* arr = base_type->As<sem::Array>()) {
-            if (arr->IsRuntimeSized()) {
+            if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                 sizes.push_back(0);
             } else {
                 auto count = arr->ConstantCount();
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index 9d09795..0c3856a 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -3924,7 +3924,7 @@
             const sem::Type* base_type = ary;
             std::vector<uint32_t> sizes;
             while (auto* arr = base_type->As<sem::Array>()) {
-                if (arr->IsRuntimeSized()) {
+                if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                     TINT_ICE(Writer, diagnostics_)
                         << "runtime arrays may only exist in storage buffers, which should have "
                            "been transformed into a ByteAddressBuffer";
diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc
index 9d06439..c7354f0 100644
--- a/src/tint/writer/msl/generator_impl.cc
+++ b/src/tint/writer/msl/generator_impl.cc
@@ -2537,7 +2537,7 @@
                 return false;
             }
             out << ", ";
-            if (arr->IsRuntimeSized()) {
+            if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                 out << "1";
             } else {
                 auto count = arr->ConstantCount();
@@ -3165,7 +3165,7 @@
                     << "arrays with explicit strides should not exist past the SPIR-V reader";
                 return SizeAndAlign{};
             }
-            if (arr->IsRuntimeSized()) {
+            if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
                 return SizeAndAlign{arr->Stride(), arr->Align()};
             }
             if (auto count = arr->ConstantCount()) {
diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc
index f2db430..f2b8f85 100644
--- a/src/tint/writer/spirv/builder.cc
+++ b/src/tint/writer/spirv/builder.cc
@@ -3839,7 +3839,7 @@
     }
 
     auto result_id = std::get<uint32_t>(result);
-    if (arr->IsRuntimeSized()) {
+    if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
         push_type(spv::Op::OpTypeRuntimeArray, {result, Operand(elem_type)});
     } else {
         auto count = arr->ConstantCount();