Move array to type/

This CL moves array to the type/ folder. Namespaces are updated as
needed. A FriendlyName method was added to ArrayCount so the sem::
ArrayCount entries do not need to be referenced inside type/.

Bug: tint:1718
Change-Id: I16a8f32b3fab1131b284a6981a5c386081138b08
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113427
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-12-08 22:21:24 +00:00
committed by Dan Sinclair
parent f53b2b5b2e
commit 946858ad56
55 changed files with 260 additions and 226 deletions

View File

@@ -23,12 +23,12 @@
#include <utility>
#include "src/tint/program_builder.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/constant.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/bool.h"
#include "src/tint/type/f16.h"
#include "src/tint/type/f32.h"
@@ -486,7 +486,7 @@ const ImplConstant* ZeroValue(ProgramBuilder& builder, const type::Type* type) {
auto* zero_el = ZeroValue(builder, m->ColumnType());
return builder.create<Splat>(type, zero_el, m->columns());
},
[&](const sem::Array* a) -> const ImplConstant* {
[&](const type::Array* a) -> const ImplConstant* {
if (auto n = a->ConstantCount()) {
if (auto* zero_el = ZeroValue(builder, a->ElemType())) {
return builder.create<Splat>(type, zero_el, n.value());
@@ -547,7 +547,7 @@ bool Equal(const sem::Constant* a, const sem::Constant* b) {
}
return true;
},
[&](const sem::Array* arr) {
[&](const type::Array* arr) {
if (auto count = arr->ConstantCount()) {
for (size_t i = 0; i < count; i++) {
if (!Equal(a->Index(i), b->Index(i))) {

View File

@@ -1318,7 +1318,7 @@ TEST_F(ResolverConstEvalTest, Array_i32_Zero) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::I32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1355,7 +1355,7 @@ TEST_F(ResolverConstEvalTest, Array_f32_Zero) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::F32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1392,7 +1392,7 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Zero) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::Vector>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1443,7 +1443,7 @@ TEST_F(ResolverConstEvalTest, Array_Struct_f32_Zero) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1480,7 +1480,7 @@ TEST_F(ResolverConstEvalTest, Array_i32_Elements) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::I32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1517,7 +1517,7 @@ TEST_F(ResolverConstEvalTest, Array_f32_Elements) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::F32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1555,7 +1555,7 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Elements) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::Vector>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -1584,7 +1584,7 @@ TEST_F(ResolverConstEvalTest, Array_Struct_f32_Elements) {
auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>();
auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@@ -2087,14 +2087,14 @@ TEST_F(ResolverConstEvalTest, Struct_Array_Construct) {
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllEqual());
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
EXPECT_TRUE(sem->ConstantValue()->Index(0)->Type()->Is<sem::Array>());
EXPECT_TRUE(sem->ConstantValue()->Index(0)->Type()->Is<type::Array>());
EXPECT_EQ(sem->ConstantValue()->Index(0)->Index(0)->As<i32>(), 1_i);
EXPECT_EQ(sem->ConstantValue()->Index(0)->Index(1)->As<u32>(), 2_i);
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllEqual());
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
EXPECT_TRUE(sem->ConstantValue()->Index(1)->Type()->Is<sem::Array>());
EXPECT_TRUE(sem->ConstantValue()->Index(1)->Type()->Is<type::Array>());
EXPECT_EQ(sem->ConstantValue()->Index(1)->Index(0)->As<i32>(), 1_f);
EXPECT_EQ(sem->ConstantValue()->Index(1)->Index(1)->As<u32>(), 2_f);
EXPECT_EQ(sem->ConstantValue()->Index(1)->Index(2)->As<f32>(), 3_f);

View File

@@ -135,7 +135,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest, ResolverInferredTypeParamTest, testing::V
TEST_F(ResolverInferredTypeTest, InferArray_Pass) {
auto* type = ty.array(ty.u32(), 10_u);
auto* expected_type = create<sem::Array>(
auto* expected_type = create<type::Array>(
create<type::U32>(), create<type::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u);
auto* ctor_expr = Construct(type);

View File

@@ -522,7 +522,7 @@ bool match_array(MatchState&, const type::Type* ty, const type::Type*& T) {
return true;
}
if (auto* a = ty->As<sem::Array>()) {
if (auto* a = ty->As<type::Array>()) {
if (a->Count()->Is<type::RuntimeArrayCount>()) {
T = a->ElemType();
return true;
@@ -531,8 +531,8 @@ bool match_array(MatchState&, const type::Type* ty, const type::Type*& T) {
return false;
}
const sem::Array* build_array(MatchState& state, const type::Type* el) {
return state.builder.create<sem::Array>(
const type::Array* build_array(MatchState& state, const type::Type* el) {
return state.builder.create<type::Array>(
el,
/* count */ state.builder.create<type::RuntimeArrayCount>(),
/* align */ 0u,

View File

@@ -253,7 +253,7 @@ TEST_F(IntrinsicTableTest, MismatchPointer) {
TEST_F(IntrinsicTableTest, MatchArray) {
auto* arr =
create<sem::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<type::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
auto* arr_ptr =
create<type::Pointer>(arr, ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto result = table->Lookup(BuiltinType::kArrayLength, utils::Vector{arr_ptr},
@@ -265,7 +265,7 @@ TEST_F(IntrinsicTableTest, MatchArray) {
ASSERT_EQ(result.sem->Parameters().Length(), 1u);
auto* param_type = result.sem->Parameters()[0]->Type();
ASSERT_TRUE(param_type->Is<type::Pointer>());
EXPECT_TRUE(param_type->As<type::Pointer>()->StoreType()->Is<sem::Array>());
EXPECT_TRUE(param_type->As<type::Pointer>()->StoreType()->Is<type::Array>());
}
TEST_F(IntrinsicTableTest, MismatchArray) {
@@ -958,7 +958,7 @@ TEST_F(IntrinsicTableTest, MatchTypeConversion) {
TEST_F(IntrinsicTableTest, MismatchTypeConversion) {
auto* arr =
create<sem::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<type::Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
auto* f32 = create<type::F32>();
auto result = table->Lookup(InitConvIntrinsic::kVec3, f32, utils::Vector{arr},
sem::EvaluationStage::kConstant, Source{{12, 34}});

View File

@@ -106,14 +106,14 @@ TEST_F(ResolverIsHostShareable, Atomic) {
}
TEST_F(ResolverIsHostShareable, ArraySizedOfHostShareable) {
auto* arr = create<sem::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
auto* arr = create<type::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(r()->IsHostShareable(arr));
}
TEST_F(ResolverIsHostShareable, ArrayUnsizedOfHostShareable) {
auto* arr =
create<sem::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<type::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(r()->IsHostShareable(arr));
}

View File

@@ -89,14 +89,14 @@ TEST_F(ResolverIsStorableTest, Atomic) {
}
TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
auto* arr = create<type::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(r()->IsStorable(arr));
}
TEST_F(ResolverIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr =
create<sem::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<type::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(r()->IsStorable(arr));
}

View File

@@ -117,7 +117,7 @@ class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {
}
}
},
[&](const sem::Array* a) {
[&](const type::Array* a) {
auto count = a->ConstantCount();
ASSERT_NE(count, 0u);
for (uint32_t i = 0; i < count; i++) {

View File

@@ -259,7 +259,7 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize_Alias) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
{
auto* r = Sem().TransitivelyReferencedOverrides(Sem().Get<sem::Array>(arr_ty->type));
auto* r = Sem().TransitivelyReferencedOverrides(Sem().Get<type::Array>(arr_ty->type));
ASSERT_NE(r, nullptr);
auto& refs = *r;
ASSERT_EQ(refs.Length(), 2u);

View File

@@ -52,7 +52,6 @@
#include "src/tint/ast/while_statement.h"
#include "src/tint/ast/workgroup_attribute.h"
#include "src/tint/resolver/uniformity.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/break_if_statement.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/for_loop_statement.h"
@@ -72,6 +71,7 @@
#include "src/tint/sem/while_statement.h"
#include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h"
@@ -927,7 +927,7 @@ sem::GlobalVariable* Resolver::GlobalVariable(const ast::Variable* v) {
for (auto* var : transitively_referenced_overrides) {
builder_->Sem().AddTransitivelyReferencedOverride(sem, var);
}
if (auto* arr = sem->Type()->UnwrapRef()->As<sem::Array>()) {
if (auto* arr = sem->Type()->UnwrapRef()->As<type::Array>()) {
auto* refs = builder_->Sem().TransitivelyReferencedOverrides(arr);
if (refs) {
for (auto* var : *refs) {
@@ -1742,9 +1742,9 @@ const type::Type* Resolver::ConcreteType(const type::Type* ty,
return target_ty ? target_ty : f32m(m->columns(), m->rows());
});
},
[&](const sem::Array* a) -> const type::Type* {
[&](const type::Array* a) -> const type::Type* {
const type::Type* target_el_ty = nullptr;
if (auto* target_arr_ty = As<sem::Array>(target_ty)) {
if (auto* target_arr_ty = As<type::Array>(target_ty)) {
target_el_ty = target_arr_ty->ElemType();
}
if (auto* el_ty = ConcreteType(a->ElemType(), target_el_ty, source)) {
@@ -1869,7 +1869,7 @@ sem::Expression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* exp
auto* obj_ty = obj_raw_ty->UnwrapRef();
auto* ty = Switch(
obj_ty, //
[&](const sem::Array* arr) { return arr->ElemType(); },
[&](const type::Array* arr) { return arr->ElemType(); },
[&](const type::Vector* vec) { return vec->type(); },
[&](const type::Matrix* mat) {
return builder_->create<type::Vector>(mat->type(), mat->rows());
@@ -2045,7 +2045,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
[&](const type::F16*) { return ct_init_or_conv(InitConvIntrinsic::kF16, nullptr); },
[&](const type::F32*) { return ct_init_or_conv(InitConvIntrinsic::kF32, nullptr); },
[&](const type::Bool*) { return ct_init_or_conv(InitConvIntrinsic::kBool, nullptr); },
[&](const sem::Array* arr) -> sem::Call* {
[&](const type::Array* arr) -> sem::Call* {
auto* call_target = array_inits_.GetOrCreate(
ArrayInitializerSig{{arr, args.Length(), args_stage}},
[&]() -> sem::TypeInitializer* {
@@ -2925,7 +2925,7 @@ type::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) {
return result;
}
sem::Array* Resolver::Array(const ast::Array* arr) {
type::Array* Resolver::Array(const ast::Array* arr) {
if (!arr->type) {
AddError("missing array element type", arr->source.End());
return nullptr;
@@ -3053,11 +3053,11 @@ bool Resolver::ArrayAttributes(utils::VectorRef<const ast::Attribute*> attribute
return true;
}
sem::Array* Resolver::Array(const Source& el_source,
const Source& count_source,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride) {
type::Array* Resolver::Array(const Source& el_source,
const Source& count_source,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride) {
uint32_t el_align = el_ty->Align();
uint32_t el_size = el_ty->Size();
uint64_t implicit_stride = el_size ? utils::RoundUp<uint64_t>(el_align, el_size) : 0;
@@ -3076,9 +3076,9 @@ sem::Array* Resolver::Array(const Source& el_source,
} else if (el_count->Is<type::RuntimeArrayCount>()) {
size = stride;
}
auto* out = builder_->create<sem::Array>(el_ty, el_count, el_align, static_cast<uint32_t>(size),
static_cast<uint32_t>(stride),
static_cast<uint32_t>(implicit_stride));
auto* out = builder_->create<type::Array>(
el_ty, el_count, el_align, static_cast<uint32_t>(size), static_cast<uint32_t>(stride),
static_cast<uint32_t>(implicit_stride));
if (!validator_.Array(out, el_source)) {
return nullptr;
@@ -3642,7 +3642,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
return true;
}
if (auto* arr = ty->As<sem::Array>()) {
if (auto* arr = ty->As<type::Array>()) {
if (address_space != ast::AddressSpace::kStorage) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
AddError("runtime-sized arrays can only be used in the <storage> address space",

View File

@@ -272,7 +272,7 @@ class Resolver {
/// to the AST node.
/// @returns the semantic Array information, or nullptr if an error is raised.
/// @param arr the Array to get semantic information for
sem::Array* Array(const ast::Array* arr);
type::Array* Array(const ast::Array* arr);
/// Resolves and validates the expression used as the count parameter of an array.
/// @param count_expr the expression used as the second template parameter to an array<>.
@@ -297,11 +297,11 @@ class Resolver {
/// @param el_ty the Array element type
/// @param el_count the number of elements in the array.
/// @param explicit_stride the explicit byte stride of the array. Zero means implicit stride.
sem::Array* Array(const Source& el_source,
const Source& count_source,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride);
type::Array* Array(const Source& el_source,
const Source& count_source,
const type::Type* el_ty,
const type::ArrayCount* el_count,
uint32_t explicit_stride);
/// Builds and returns the semantic information for the alias `alias`.
/// This method does not mark the ast::Alias node, nor attach the generated
@@ -426,7 +426,7 @@ class Resolver {
// ArrayInitializerSig represents a unique array initializer signature.
// It is a tuple of the array type, number of arguments provided and earliest evaluation stage.
using ArrayInitializerSig =
utils::UnorderedKeyWrapper<std::tuple<const sem::Array*, size_t, sem::EvaluationStage>>;
utils::UnorderedKeyWrapper<std::tuple<const type::Array*, size_t, sem::EvaluationStage>>;
// StructInitializerSig represents a unique structure initializer signature.
// It is a tuple of the structure type, number of arguments provided and earliest evaluation

View File

@@ -439,7 +439,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedLiteral) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
@@ -452,7 +452,7 @@ TEST_F(ResolverTest, ArraySize_SignedLiteral) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
@@ -467,7 +467,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedConst) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
@@ -482,7 +482,7 @@ TEST_F(ResolverTest, ArraySize_SignedConst) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
}
@@ -497,7 +497,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::NamedOverrideArrayCount>(sem_override));
@@ -516,12 +516,12 @@ TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref_a = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref_a, nullptr);
auto* ary_a = ref_a->StoreType()->As<sem::Array>();
auto* ary_a = ref_a->StoreType()->As<type::Array>();
ASSERT_NE(TypeOf(b), nullptr);
auto* ref_b = TypeOf(b)->As<type::Reference>();
ASSERT_NE(ref_b, nullptr);
auto* ary_b = ref_b->StoreType()->As<sem::Array>();
auto* ary_b = ref_b->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr);
@@ -542,7 +542,7 @@ TEST_F(ResolverTest, ArraySize_UnnamedOverride) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<sem::Array>();
auto* ary = ref->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::UnnamedOverrideArrayCount>(Sem().Get(cnt)));
@@ -563,12 +563,12 @@ TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {
ASSERT_NE(TypeOf(a), nullptr);
auto* ref_a = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref_a, nullptr);
auto* ary_a = ref_a->StoreType()->As<sem::Array>();
auto* ary_a = ref_a->StoreType()->As<type::Array>();
ASSERT_NE(TypeOf(b), nullptr);
auto* ref_b = TypeOf(b)->As<type::Reference>();
ASSERT_NE(ref_b, nullptr);
auto* ary_b = ref_b->StoreType()->As<sem::Array>();
auto* ary_b = ref_b->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr);

View File

@@ -667,7 +667,7 @@ struct DataType<array<N, T>> {
} else {
count = b.create<type::ConstantArrayCount>(N);
}
return b.create<sem::Array>(
return b.create<type::Array>(
/* element */ el,
/* count */ count,
/* align */ el->Align(),

View File

@@ -494,7 +494,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_ZeroValue_Pass) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -510,7 +510,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_U32U32U32) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -529,7 +529,7 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArray_U32U32U32) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -548,7 +548,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_U32AIU32) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -567,7 +567,7 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArray_U32AIU32) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -586,7 +586,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayU32_AIAIAI) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -605,7 +605,7 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArray_AIAIAI) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -626,7 +626,7 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArrayU32_VecI32_VecAI) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());
@@ -648,7 +648,7 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArrayU32_VecAI_VecF32) {
auto* call = Sem().Get<sem::Call>(tc);
ASSERT_NE(call, nullptr);
EXPECT_TRUE(call->Type()->Is<sem::Array>());
EXPECT_TRUE(call->Type()->Is<type::Array>());
auto* ctor = call->Target()->As<sem::TypeInitializer>();
ASSERT_NE(ctor, nullptr);
EXPECT_EQ(call->Type(), ctor->ReturnType());

View File

@@ -47,7 +47,6 @@
#include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/vector.h"
#include "src/tint/ast/workgroup_attribute.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/break_if_statement.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/for_loop_statement.h"
@@ -64,6 +63,7 @@
#include "src/tint/sem/variable.h"
#include "src/tint/sem/while_statement.h"
#include "src/tint/type/abstract_numeric.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h"
@@ -183,7 +183,7 @@ void Validator::AddNote(const std::string& msg, const Source& source) const {
// https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section
bool Validator::IsPlain(const type::Type* type) const {
return type->is_scalar() ||
type->IsAnyOf<type::Atomic, type::Vector, type::Matrix, sem::Array, sem::Struct>();
type->IsAnyOf<type::Atomic, type::Vector, type::Matrix, type::Array, sem::Struct>();
}
// https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types
@@ -193,7 +193,7 @@ bool Validator::IsFixedFootprint(const type::Type* type) const {
[&](const type::Vector*) { return true; }, //
[&](const type::Matrix*) { return true; }, //
[&](const type::Atomic*) { return true; },
[&](const sem::Array* arr) {
[&](const type::Array* arr) {
return !arr->Count()->Is<type::RuntimeArrayCount>() &&
IsFixedFootprint(arr->ElemType());
},
@@ -217,7 +217,7 @@ bool Validator::IsHostShareable(const type::Type* type) const {
type, //
[&](const type::Vector* vec) { return IsHostShareable(vec->type()); },
[&](const type::Matrix* mat) { return IsHostShareable(mat->type()); },
[&](const sem::Array* arr) { return IsHostShareable(arr->ElemType()); },
[&](const type::Array* arr) { return IsHostShareable(arr->ElemType()); },
[&](const sem::Struct* str) {
for (auto* member : str->Members()) {
if (!IsHostShareable(member->Type())) {
@@ -398,7 +398,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
auto is_uniform_struct_or_array = [address_space](const type::Type* ty) {
return address_space == ast::AddressSpace::kUniform &&
ty->IsAnyOf<sem::Array, sem::Struct>();
ty->IsAnyOf<type::Array, sem::Struct>();
};
auto is_uniform_struct = [address_space](const type::Type* ty) {
@@ -504,7 +504,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
}
// For uniform buffer array members, validate that array elements are aligned to 16 bytes
if (auto* arr = store_ty->As<sem::Array>()) {
if (auto* arr = store_ty->As<type::Array>()) {
// Recurse into the element type.
// TODO(crbug.com/tint/1388): Ideally we'd pass the source for nested element type here, but
// we can't easily get that from the semantic node. We should consider recursing through the
@@ -1744,7 +1744,7 @@ bool Validator::StructureInitializer(const ast::CallExpression* ctor,
}
bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
const sem::Array* array_type) const {
const type::Array* array_type) const {
auto& values = ctor->args;
auto* elem_ty = array_type->ElemType();
for (auto* value : values) {
@@ -1968,7 +1968,7 @@ bool Validator::PushConstants(utils::VectorRef<sem::Function*> entry_points) con
return true;
}
bool Validator::Array(const sem::Array* arr, const Source& el_source) const {
bool Validator::Array(const type::Array* arr, const Source& el_source) const {
auto* el_ty = arr->ElemType();
if (!IsPlain(el_ty)) {
@@ -2021,7 +2021,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 (auto* r = member->Type()->As<type::Array>()) {
if (r->Count()->Is<type::RuntimeArrayCount>()) {
if (member != str->Members().Back()) {
AddError("runtime arrays may only appear as the last member of a struct",
@@ -2393,7 +2393,7 @@ bool Validator::IsValidationEnabled(utils::VectorRef<const ast::Attribute*> attr
}
bool Validator::IsArrayWithOverrideCount(const type::Type* ty) const {
if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) {
if (auto* arr = ty->UnwrapRef()->As<type::Array>()) {
if (arr->Count()->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
return true;
}
@@ -2474,7 +2474,7 @@ bool Validator::CheckTypeAccessAddressSpace(
return true;
},
[&](const sem::Struct*) { return check_sub_atomics(); }, //
[&](const sem::Array*) { return check_sub_atomics(); }, //
[&](const type::Array*) { return check_sub_atomics(); }, //
[&](Default) { return true; });
}

View File

@@ -154,7 +154,7 @@ class Validator {
/// @param el_source the source of the array element, or the array if the array does not have a
/// locally-declared element AST node.
/// @returns true on success, false otherwise.
bool Array(const sem::Array* arr, const Source& el_source) const;
bool Array(const type::Array* arr, const Source& el_source) const;
/// Validates an array stride attribute
/// @param attr the stride attribute to validate
@@ -432,7 +432,7 @@ class Validator {
/// @param ctor the call expresion to validate
/// @param arr_type the type of the array
/// @returns true on success, false otherwise
bool ArrayInitializer(const ast::CallExpression* ctor, const sem::Array* arr_type) const;
bool ArrayInitializer(const ast::CallExpression* ctor, const type::Array* arr_type) const;
/// Validates a texture builtin function
/// @param call the builtin call to validate

View File

@@ -89,14 +89,14 @@ TEST_F(ValidatorIsStorableTest, Atomic) {
}
TEST_F(ValidatorIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
auto* arr = create<type::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u);
EXPECT_TRUE(v()->IsStorable(arr));
}
TEST_F(ValidatorIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr =
create<sem::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
create<type::Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 4u, 4u, 4u, 4u);
EXPECT_TRUE(v()->IsStorable(arr));
}