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>
This commit is contained in:
dan sinclair
2022-12-02 02:59:44 +00:00
committed by Dawn LUCI CQ
parent a5d3d16b1d
commit 15e7f94b76
14 changed files with 24 additions and 37 deletions

View File

@@ -523,7 +523,7 @@ bool match_array(MatchState&, const sem::Type* ty, const sem::Type*& T) {
}
if (auto* a = ty->As<sem::Array>()) {
if (a->IsRuntimeSized()) {
if (a->Count()->Is<sem::RuntimeArrayCount>()) {
T = a->ElemType();
return true;
}

View File

@@ -3639,7 +3639,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
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;

View File

@@ -194,7 +194,7 @@ bool Validator::IsFixedFootprint(const sem::Type* type) const {
[&](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 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
}
}
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 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
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 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
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::IsValidationEnabled(utils::VectorRef<const ast::Attribute*> attr
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;
}
}