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:
parent
a5d3d16b1d
commit
15e7f94b76
|
@ -523,7 +523,7 @@ bool match_array(MatchState&, const sem::Type* ty, const sem::Type*& T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto* a = ty->As<sem::Array>()) {
|
if (auto* a = ty->As<sem::Array>()) {
|
||||||
if (a->IsRuntimeSized()) {
|
if (a->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
T = a->ElemType();
|
T = a->ElemType();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3639,7 +3639,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
|
||||||
|
|
||||||
if (auto* arr = ty->As<sem::Array>()) {
|
if (auto* arr = ty->As<sem::Array>()) {
|
||||||
if (address_space != ast::AddressSpace::kStorage) {
|
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",
|
AddError("runtime-sized arrays can only be used in the <storage> address space",
|
||||||
usage);
|
usage);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -194,7 +194,7 @@ bool Validator::IsFixedFootprint(const sem::Type* type) const {
|
||||||
[&](const sem::Matrix*) { return true; }, //
|
[&](const sem::Matrix*) { return true; }, //
|
||||||
[&](const sem::Atomic*) { return true; },
|
[&](const sem::Atomic*) { return true; },
|
||||||
[&](const sem::Array* arr) {
|
[&](const sem::Array* arr) {
|
||||||
return !arr->IsRuntimeSized() && IsFixedFootprint(arr->ElemType());
|
return !arr->Count()->Is<sem::RuntimeArrayCount>() && IsFixedFootprint(arr->ElemType());
|
||||||
},
|
},
|
||||||
[&](const sem::Struct* str) {
|
[&](const sem::Struct* str) {
|
||||||
for (auto* member : str->Members()) {
|
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);
|
AddError("cannot construct a runtime-sized array", ctor->source);
|
||||||
return false;
|
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);
|
AddError("cannot construct an array that has an override-expression count", ctor->source);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1778,12 +1779,12 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_type->IsConstantSized()) {
|
if (!c->Is<sem::ConstantArrayCount>()) {
|
||||||
TINT_ICE(Resolver, diagnostics_) << "Invalid ArrayCount found";
|
TINT_ICE(Resolver, diagnostics_) << "Invalid ArrayCount found";
|
||||||
return false;
|
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)) {
|
if (!values.IsEmpty() && (values.Length() != count)) {
|
||||||
std::string fm = values.Length() < count ? "few" : "many";
|
std::string fm = values.Length() < count ? "few" : "many";
|
||||||
AddError("array initializer has too " + fm + " elements: expected " +
|
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;
|
utils::Hashset<uint32_t, 8> locations;
|
||||||
for (auto* member : str->Members()) {
|
for (auto* member : str->Members()) {
|
||||||
if (auto* r = member->Type()->As<sem::Array>()) {
|
if (auto* r = member->Type()->As<sem::Array>()) {
|
||||||
if (r->IsRuntimeSized()) {
|
if (r->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
if (member != str->Members().back()) {
|
if (member != str->Members().back()) {
|
||||||
AddError("runtime arrays may only appear as the last member of a struct",
|
AddError("runtime arrays may only appear as the last member of a struct",
|
||||||
member->Source());
|
member->Source());
|
||||||
|
@ -2398,7 +2399,7 @@ bool Validator::IsValidationEnabled(utils::VectorRef<const ast::Attribute*> attr
|
||||||
|
|
||||||
bool Validator::IsArrayWithOverrideCount(const sem::Type* ty) const {
|
bool Validator::IsArrayWithOverrideCount(const sem::Type* ty) const {
|
||||||
if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) {
|
if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) {
|
||||||
if (arr->IsOverrideSized()) {
|
if (arr->Count()->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,21 +103,6 @@ class Array final : public Castable<Array, Type> {
|
||||||
/// natural stride
|
/// natural stride
|
||||||
bool IsStrideImplicit() const { return stride_ == implicit_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
|
/// @param symbols the program's symbol table
|
||||||
/// @returns the name for this type that closely resembles how it would be
|
/// @returns the name for this type that closely resembles how it would be
|
||||||
/// declared in WGSL.
|
/// declared in WGSL.
|
||||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(ArrayTest, CreateSizedArray) {
|
||||||
EXPECT_EQ(a->Stride(), 32u);
|
EXPECT_EQ(a->Stride(), 32u);
|
||||||
EXPECT_EQ(a->ImplicitStride(), 16u);
|
EXPECT_EQ(a->ImplicitStride(), 16u);
|
||||||
EXPECT_FALSE(a->IsStrideImplicit());
|
EXPECT_FALSE(a->IsStrideImplicit());
|
||||||
EXPECT_FALSE(a->IsRuntimeSized());
|
EXPECT_FALSE(a->Count()->Is<RuntimeArrayCount>());
|
||||||
|
|
||||||
EXPECT_EQ(a, b);
|
EXPECT_EQ(a, b);
|
||||||
EXPECT_NE(a, c);
|
EXPECT_NE(a, c);
|
||||||
|
@ -61,7 +61,7 @@ TEST_F(ArrayTest, CreateRuntimeArray) {
|
||||||
EXPECT_EQ(a->Stride(), 32u);
|
EXPECT_EQ(a->Stride(), 32u);
|
||||||
EXPECT_EQ(a->ImplicitStride(), 32u);
|
EXPECT_EQ(a->ImplicitStride(), 32u);
|
||||||
EXPECT_TRUE(a->IsStrideImplicit());
|
EXPECT_TRUE(a->IsStrideImplicit());
|
||||||
EXPECT_TRUE(a->IsRuntimeSized());
|
EXPECT_TRUE(a->Count()->Is<RuntimeArrayCount>());
|
||||||
|
|
||||||
EXPECT_EQ(a, b);
|
EXPECT_EQ(a, b);
|
||||||
EXPECT_NE(a, c);
|
EXPECT_NE(a, c);
|
||||||
|
|
|
@ -146,7 +146,8 @@ struct ModuleScopeVarToEntryPointParam::State {
|
||||||
attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace));
|
attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace));
|
||||||
|
|
||||||
auto* param_type = store_type();
|
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
|
// 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
|
// them. Ideally we'd just emit the array itself as a pointer, but this is not
|
||||||
// representable in Tint's AST.
|
// representable in Tint's AST.
|
||||||
|
|
|
@ -84,7 +84,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat
|
||||||
// std140 structs should be padded out to 16 bytes.
|
// std140 structs should be padded out to 16 bytes.
|
||||||
size = utils::RoundUp(16u, size);
|
size = utils::RoundUp(16u, size);
|
||||||
} else if (auto* array_ty = ty->As<sem::Array>()) {
|
} 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;
|
has_runtime_sized_array = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ struct Robustness::State {
|
||||||
},
|
},
|
||||||
[&](const sem::Array* arr) -> const ast::Expression* {
|
[&](const sem::Array* arr) -> const ast::Expression* {
|
||||||
const ast::Expression* max = nullptr;
|
const ast::Expression* max = nullptr;
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
// Size is unknown until runtime.
|
// Size is unknown until runtime.
|
||||||
// Must clamp, even if the index is constant.
|
// Must clamp, even if the index is constant.
|
||||||
auto* arr_ptr = b.AddressOf(ctx.Clone(expr->object));
|
auto* arr_ptr = b.AddressOf(ctx.Clone(expr->object));
|
||||||
|
|
|
@ -202,7 +202,7 @@ struct SpirvAtomic::State {
|
||||||
[&](const sem::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
|
[&](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::Struct* str) { return b.ty.type_name(Fork(str->Declaration()).name); },
|
||||||
[&](const sem::Array* arr) -> const ast::Type* {
|
[&](const sem::Array* arr) -> const ast::Type* {
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
return b.ty.array(AtomicTypeFor(arr->ElemType()));
|
return b.ty.array(AtomicTypeFor(arr->ElemType()));
|
||||||
}
|
}
|
||||||
auto count = arr->ConstantCount();
|
auto count = arr->ConstantCount();
|
||||||
|
|
|
@ -106,7 +106,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const sem::Type*
|
||||||
if (!a->IsStrideImplicit()) {
|
if (!a->IsStrideImplicit()) {
|
||||||
attrs.Push(ctx.dst->create<ast::StrideAttribute>(a->Stride()));
|
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));
|
return ctx.dst->ty.array(el, nullptr, std::move(attrs));
|
||||||
}
|
}
|
||||||
if (auto* override = a->Count()->As<sem::NamedOverrideArrayCount>()) {
|
if (auto* override = a->Count()->As<sem::NamedOverrideArrayCount>()) {
|
||||||
|
|
|
@ -292,7 +292,7 @@ bool GeneratorImpl::Generate() {
|
||||||
auto* sem = builder_.Sem().Get(str);
|
auto* sem = builder_.Sem().Get(str);
|
||||||
bool has_rt_arr = false;
|
bool has_rt_arr = false;
|
||||||
if (auto* arr = sem->Members().back()->Type()->As<sem::Array>()) {
|
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 =
|
bool is_block =
|
||||||
ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(str->attributes);
|
ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(str->attributes);
|
||||||
|
@ -2834,7 +2834,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
const sem::Type* base_type = ary;
|
const sem::Type* base_type = ary;
|
||||||
std::vector<uint32_t> sizes;
|
std::vector<uint32_t> sizes;
|
||||||
while (auto* arr = base_type->As<sem::Array>()) {
|
while (auto* arr = base_type->As<sem::Array>()) {
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
sizes.push_back(0);
|
sizes.push_back(0);
|
||||||
} else {
|
} else {
|
||||||
auto count = arr->ConstantCount();
|
auto count = arr->ConstantCount();
|
||||||
|
|
|
@ -3924,7 +3924,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
const sem::Type* base_type = ary;
|
const sem::Type* base_type = ary;
|
||||||
std::vector<uint32_t> sizes;
|
std::vector<uint32_t> sizes;
|
||||||
while (auto* arr = base_type->As<sem::Array>()) {
|
while (auto* arr = base_type->As<sem::Array>()) {
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
TINT_ICE(Writer, diagnostics_)
|
TINT_ICE(Writer, diagnostics_)
|
||||||
<< "runtime arrays may only exist in storage buffers, which should have "
|
<< "runtime arrays may only exist in storage buffers, which should have "
|
||||||
"been transformed into a ByteAddressBuffer";
|
"been transformed into a ByteAddressBuffer";
|
||||||
|
|
|
@ -2537,7 +2537,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out << ", ";
|
out << ", ";
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
out << "1";
|
out << "1";
|
||||||
} else {
|
} else {
|
||||||
auto count = arr->ConstantCount();
|
auto count = arr->ConstantCount();
|
||||||
|
@ -3165,7 +3165,7 @@ GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(const sem::
|
||||||
<< "arrays with explicit strides should not exist past the SPIR-V reader";
|
<< "arrays with explicit strides should not exist past the SPIR-V reader";
|
||||||
return SizeAndAlign{};
|
return SizeAndAlign{};
|
||||||
}
|
}
|
||||||
if (arr->IsRuntimeSized()) {
|
if (arr->Count()->Is<sem::RuntimeArrayCount>()) {
|
||||||
return SizeAndAlign{arr->Stride(), arr->Align()};
|
return SizeAndAlign{arr->Stride(), arr->Align()};
|
||||||
}
|
}
|
||||||
if (auto count = arr->ConstantCount()) {
|
if (auto count = arr->ConstantCount()) {
|
||||||
|
|
|
@ -3839,7 +3839,7 @@ bool Builder::GenerateArrayType(const sem::Array* arr, const Operand& result) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result_id = std::get<uint32_t>(result);
|
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)});
|
push_type(spv::Op::OpTypeRuntimeArray, {result, Operand(elem_type)});
|
||||||
} else {
|
} else {
|
||||||
auto count = arr->ConstantCount();
|
auto count = arr->ConstantCount();
|
||||||
|
|
Loading…
Reference in New Issue