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

@ -413,7 +413,6 @@ libtint_source_set("libtint_core_all_src") {
"resolver/validator.cc", "resolver/validator.cc",
"resolver/validator.h", "resolver/validator.h",
"scope_stack.h", "scope_stack.h",
"sem/array.h",
"sem/array_count.h", "sem/array_count.h",
"sem/behavior.h", "sem/behavior.h",
"sem/binding_point.h", "sem/binding_point.h",
@ -555,6 +554,7 @@ libtint_source_set("libtint_core_all_src") {
"type/abstract_float.h", "type/abstract_float.h",
"type/abstract_int.h", "type/abstract_int.h",
"type/abstract_numeric.h", "type/abstract_numeric.h",
"type/array.h",
"type/array_count.h", "type/array_count.h",
"type/atomic.h", "type/atomic.h",
"type/bool.h", "type/bool.h",
@ -633,8 +633,6 @@ libtint_source_set("libtint_core_all_src") {
libtint_source_set("libtint_sem_src") { libtint_source_set("libtint_sem_src") {
sources = [ sources = [
"sem/array.cc",
"sem/array.h",
"sem/array_count.cc", "sem/array_count.cc",
"sem/array_count.h", "sem/array_count.h",
"sem/behavior.cc", "sem/behavior.cc",
@ -703,6 +701,8 @@ libtint_source_set("libtint_type_src") {
"type/abstract_int.h", "type/abstract_int.h",
"type/abstract_numeric.cc", "type/abstract_numeric.cc",
"type/abstract_numeric.h", "type/abstract_numeric.h",
"type/array.cc",
"type/array.h",
"type/array_count.cc", "type/array_count.cc",
"type/array_count.h", "type/array_count.h",
"type/atomic.cc", "type/atomic.cc",
@ -1206,7 +1206,6 @@ if (tint_build_unittests) {
tint_unittests_source_set("tint_unittests_sem_src") { tint_unittests_source_set("tint_unittests_sem_src") {
sources = [ sources = [
"sem/array_test.cc",
"sem/builtin_test.cc", "sem/builtin_test.cc",
"sem/expression_test.cc", "sem/expression_test.cc",
"sem/struct_test.cc", "sem/struct_test.cc",
@ -1215,6 +1214,7 @@ if (tint_build_unittests) {
tint_unittests_source_set("tint_unittests_type_src") { tint_unittests_source_set("tint_unittests_type_src") {
sources = [ sources = [
"type/array_test.cc",
"type/atomic_test.cc", "type/atomic_test.cc",
"type/bool_test.cc", "type/bool_test.cc",
"type/depth_multisampled_texture_test.cc", "type/depth_multisampled_texture_test.cc",

View File

@ -291,8 +291,6 @@ list(APPEND TINT_LIB_SRCS
resolver/validator.cc resolver/validator.cc
resolver/validator.h resolver/validator.h
scope_stack.h scope_stack.h
sem/array.cc
sem/array.h
sem/array_count.cc sem/array_count.cc
sem/array_count.h sem/array_count.h
sem/behavior.cc sem/behavior.cc
@ -460,6 +458,8 @@ list(APPEND TINT_LIB_SRCS
type/abstract_int.h type/abstract_int.h
type/abstract_numeric.cc type/abstract_numeric.cc
type/abstract_numeric.h type/abstract_numeric.h
type/array.cc
type/array.h
type/array_count.cc type/array_count.cc
type/array_count.h type/array_count.h
type/atomic.cc type/atomic.cc
@ -923,7 +923,6 @@ if(TINT_BUILD_TESTS)
resolver/variable_test.cc resolver/variable_test.cc
resolver/variable_validation_test.cc resolver/variable_validation_test.cc
scope_stack_test.cc scope_stack_test.cc
sem/array_test.cc
sem/builtin_test.cc sem/builtin_test.cc
sem/expression_test.cc sem/expression_test.cc
sem/struct_test.cc sem/struct_test.cc
@ -934,6 +933,7 @@ if(TINT_BUILD_TESTS)
text/unicode_test.cc text/unicode_test.cc
traits_test.cc traits_test.cc
transform/transform_test.cc transform/transform_test.cc
type/array_test.cc
type/atomic.cc type/atomic.cc
type/bool_test.cc type/bool_test.cc
type/depth_multisampled_texture_test.cc type/depth_multisampled_texture_test.cc

View File

@ -28,13 +28,13 @@
#include "src/tint/ast/module.h" #include "src/tint/ast/module.h"
#include "src/tint/ast/override.h" #include "src/tint/ast/override.h"
#include "src/tint/ast/var.h" #include "src/tint/ast/var.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/function.h" #include "src/tint/sem/function.h"
#include "src/tint/sem/module.h" #include "src/tint/sem/module.h"
#include "src/tint/sem/statement.h" #include "src/tint/sem/statement.h"
#include "src/tint/sem/struct.h" #include "src/tint/sem/struct.h"
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/type/array.h"
#include "src/tint/type/bool.h" #include "src/tint/type/bool.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h" #include "src/tint/type/depth_texture.h"

View File

@ -14,7 +14,7 @@
#include "src/tint/inspector/resource_binding.h" #include "src/tint/inspector/resource_binding.h"
#include "src/tint/sem/array.h" #include "src/tint/type/array.h"
#include "src/tint/type/f32.h" #include "src/tint/type/f32.h"
#include "src/tint/type/i32.h" #include "src/tint/type/i32.h"
#include "src/tint/type/matrix.h" #include "src/tint/type/matrix.h"
@ -50,7 +50,7 @@ ResourceBinding::SampledKind BaseTypeToSampledKind(const type::Type* base_type)
return ResourceBinding::SampledKind::kUnknown; return ResourceBinding::SampledKind::kUnknown;
} }
if (auto* at = base_type->As<sem::Array>()) { if (auto* at = base_type->As<type::Array>()) {
base_type = at->ElemType(); base_type = at->ElemType();
} else if (auto* mt = base_type->As<type::Matrix>()) { } else if (auto* mt = base_type->As<type::Matrix>()) {
base_type = mt->type(); base_type = mt->type();

View File

@ -90,10 +90,10 @@
#include "src/tint/number.h" #include "src/tint/number.h"
#include "src/tint/program.h" #include "src/tint/program.h"
#include "src/tint/program_id.h" #include "src/tint/program_id.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/array_count.h" #include "src/tint/sem/array_count.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
#include "src/tint/sem/struct.h" #include "src/tint/sem/struct.h"
#include "src/tint/type/array.h"
#include "src/tint/type/bool.h" #include "src/tint/type/bool.h"
#include "src/tint/type/depth_texture.h" #include "src/tint/type/depth_texture.h"
#include "src/tint/type/external_texture.h" #include "src/tint/type/external_texture.h"

View File

@ -23,12 +23,12 @@
#include <utility> #include <utility>
#include "src/tint/program_builder.h" #include "src/tint/program_builder.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
#include "src/tint/sem/member_accessor_expression.h" #include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/type_initializer.h" #include "src/tint/sem/type_initializer.h"
#include "src/tint/type/abstract_float.h" #include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h" #include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/bool.h" #include "src/tint/type/bool.h"
#include "src/tint/type/f16.h" #include "src/tint/type/f16.h"
#include "src/tint/type/f32.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()); auto* zero_el = ZeroValue(builder, m->ColumnType());
return builder.create<Splat>(type, zero_el, m->columns()); 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 n = a->ConstantCount()) {
if (auto* zero_el = ZeroValue(builder, a->ElemType())) { if (auto* zero_el = ZeroValue(builder, a->ElemType())) {
return builder.create<Splat>(type, zero_el, n.value()); 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; return true;
}, },
[&](const sem::Array* arr) { [&](const type::Array* arr) {
if (auto count = arr->ConstantCount()) { if (auto count = arr->ConstantCount()) {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (!Equal(a->Index(i), b->Index(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); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::I32>()); EXPECT_TRUE(arr->ElemType()->Is<type::I32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1355,7 +1355,7 @@ TEST_F(ResolverConstEvalTest, Array_f32_Zero) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::F32>()); EXPECT_TRUE(arr->ElemType()->Is<type::F32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1392,7 +1392,7 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Zero) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::Vector>()); EXPECT_TRUE(arr->ElemType()->Is<type::Vector>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1443,7 +1443,7 @@ TEST_F(ResolverConstEvalTest, Array_Struct_f32_Zero) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>()); EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1480,7 +1480,7 @@ TEST_F(ResolverConstEvalTest, Array_i32_Elements) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::I32>()); EXPECT_TRUE(arr->ElemType()->Is<type::I32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1517,7 +1517,7 @@ TEST_F(ResolverConstEvalTest, Array_f32_Elements) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::F32>()); EXPECT_TRUE(arr->ElemType()->Is<type::F32>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1555,7 +1555,7 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Elements) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<type::Vector>()); EXPECT_TRUE(arr->ElemType()->Is<type::Vector>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type());
@ -1584,7 +1584,7 @@ TEST_F(ResolverConstEvalTest, Array_Struct_f32_Elements) {
auto* sem = Sem().Get(expr); auto* sem = Sem().Get(expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
auto* arr = sem->Type()->As<sem::Array>(); auto* arr = sem->Type()->As<type::Array>();
ASSERT_NE(arr, nullptr); ASSERT_NE(arr, nullptr);
EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>()); EXPECT_TRUE(arr->ElemType()->Is<sem::Struct>());
EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); 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)->AllEqual());
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero()); EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero()); 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(0)->As<i32>(), 1_i);
EXPECT_EQ(sem->ConstantValue()->Index(0)->Index(1)->As<u32>(), 2_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)->AllEqual());
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero()); EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero()); 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(0)->As<i32>(), 1_f);
EXPECT_EQ(sem->ConstantValue()->Index(1)->Index(1)->As<u32>(), 2_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); 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) { TEST_F(ResolverInferredTypeTest, InferArray_Pass) {
auto* type = ty.array(ty.u32(), 10_u); 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); create<type::U32>(), create<type::ConstantArrayCount>(10u), 4u, 4u * 10u, 4u, 4u);
auto* ctor_expr = Construct(type); 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; return true;
} }
if (auto* a = ty->As<sem::Array>()) { if (auto* a = ty->As<type::Array>()) {
if (a->Count()->Is<type::RuntimeArrayCount>()) { if (a->Count()->Is<type::RuntimeArrayCount>()) {
T = a->ElemType(); T = a->ElemType();
return true; return true;
@ -531,8 +531,8 @@ bool match_array(MatchState&, const type::Type* ty, const type::Type*& T) {
return false; return false;
} }
const sem::Array* build_array(MatchState& state, const type::Type* el) { const type::Array* build_array(MatchState& state, const type::Type* el) {
return state.builder.create<sem::Array>( return state.builder.create<type::Array>(
el, el,
/* count */ state.builder.create<type::RuntimeArrayCount>(), /* count */ state.builder.create<type::RuntimeArrayCount>(),
/* align */ 0u, /* align */ 0u,

View File

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

View File

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

View File

@ -89,14 +89,14 @@ TEST_F(ResolverIsStorableTest, Atomic) {
} }
TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) { TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) {
auto* arr = create<sem::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u, auto* arr = create<type::Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u,
20u, 4u, 4u); 20u, 4u, 4u);
EXPECT_TRUE(r()->IsStorable(arr)); EXPECT_TRUE(r()->IsStorable(arr));
} }
TEST_F(ResolverIsStorableTest, ArrayUnsizedOfStorable) { TEST_F(ResolverIsStorableTest, ArrayUnsizedOfStorable) {
auto* arr = 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)); 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(); auto count = a->ConstantCount();
ASSERT_NE(count, 0u); ASSERT_NE(count, 0u);
for (uint32_t i = 0; i < count; i++) { 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(); 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); ASSERT_NE(r, nullptr);
auto& refs = *r; auto& refs = *r;
ASSERT_EQ(refs.Length(), 2u); ASSERT_EQ(refs.Length(), 2u);

View File

@ -52,7 +52,6 @@
#include "src/tint/ast/while_statement.h" #include "src/tint/ast/while_statement.h"
#include "src/tint/ast/workgroup_attribute.h" #include "src/tint/ast/workgroup_attribute.h"
#include "src/tint/resolver/uniformity.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/break_if_statement.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/for_loop_statement.h" #include "src/tint/sem/for_loop_statement.h"
@ -72,6 +71,7 @@
#include "src/tint/sem/while_statement.h" #include "src/tint/sem/while_statement.h"
#include "src/tint/type/abstract_float.h" #include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h" #include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_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) { for (auto* var : transitively_referenced_overrides) {
builder_->Sem().AddTransitivelyReferencedOverride(sem, var); 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); auto* refs = builder_->Sem().TransitivelyReferencedOverrides(arr);
if (refs) { if (refs) {
for (auto* var : *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()); 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; 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(); target_el_ty = target_arr_ty->ElemType();
} }
if (auto* el_ty = ConcreteType(a->ElemType(), target_el_ty, source)) { 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* obj_ty = obj_raw_ty->UnwrapRef();
auto* ty = Switch( auto* ty = Switch(
obj_ty, // 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::Vector* vec) { return vec->type(); },
[&](const type::Matrix* mat) { [&](const type::Matrix* mat) {
return builder_->create<type::Vector>(mat->type(), mat->rows()); 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::F16*) { return ct_init_or_conv(InitConvIntrinsic::kF16, nullptr); },
[&](const type::F32*) { return ct_init_or_conv(InitConvIntrinsic::kF32, nullptr); }, [&](const type::F32*) { return ct_init_or_conv(InitConvIntrinsic::kF32, nullptr); },
[&](const type::Bool*) { return ct_init_or_conv(InitConvIntrinsic::kBool, 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( auto* call_target = array_inits_.GetOrCreate(
ArrayInitializerSig{{arr, args.Length(), args_stage}}, ArrayInitializerSig{{arr, args.Length(), args_stage}},
[&]() -> sem::TypeInitializer* { [&]() -> sem::TypeInitializer* {
@ -2925,7 +2925,7 @@ type::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) {
return result; return result;
} }
sem::Array* Resolver::Array(const ast::Array* arr) { type::Array* Resolver::Array(const ast::Array* arr) {
if (!arr->type) { if (!arr->type) {
AddError("missing array element type", arr->source.End()); AddError("missing array element type", arr->source.End());
return nullptr; return nullptr;
@ -3053,7 +3053,7 @@ bool Resolver::ArrayAttributes(utils::VectorRef<const ast::Attribute*> attribute
return true; return true;
} }
sem::Array* Resolver::Array(const Source& el_source, type::Array* Resolver::Array(const Source& el_source,
const Source& count_source, const Source& count_source,
const type::Type* el_ty, const type::Type* el_ty,
const type::ArrayCount* el_count, const type::ArrayCount* el_count,
@ -3076,8 +3076,8 @@ sem::Array* Resolver::Array(const Source& el_source,
} else if (el_count->Is<type::RuntimeArrayCount>()) { } else if (el_count->Is<type::RuntimeArrayCount>()) {
size = stride; size = stride;
} }
auto* out = builder_->create<sem::Array>(el_ty, el_count, el_align, static_cast<uint32_t>(size), auto* out = builder_->create<type::Array>(
static_cast<uint32_t>(stride), el_ty, el_count, el_align, static_cast<uint32_t>(size), static_cast<uint32_t>(stride),
static_cast<uint32_t>(implicit_stride)); static_cast<uint32_t>(implicit_stride));
if (!validator_.Array(out, el_source)) { if (!validator_.Array(out, el_source)) {
@ -3642,7 +3642,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space,
return true; return true;
} }
if (auto* arr = ty->As<sem::Array>()) { if (auto* arr = ty->As<type::Array>()) {
if (address_space != ast::AddressSpace::kStorage) { if (address_space != ast::AddressSpace::kStorage) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::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",

View File

@ -272,7 +272,7 @@ class Resolver {
/// to the AST node. /// to the AST node.
/// @returns the semantic Array information, or nullptr if an error is raised. /// @returns the semantic Array information, or nullptr if an error is raised.
/// @param arr the Array to get semantic information for /// @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. /// 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<>. /// @param count_expr the expression used as the second template parameter to an array<>.
@ -297,7 +297,7 @@ class Resolver {
/// @param el_ty the Array element type /// @param el_ty the Array element type
/// @param el_count the number of elements in the array. /// @param el_count the number of elements in the array.
/// @param explicit_stride the explicit byte stride of the array. Zero means implicit stride. /// @param explicit_stride the explicit byte stride of the array. Zero means implicit stride.
sem::Array* Array(const Source& el_source, type::Array* Array(const Source& el_source,
const Source& count_source, const Source& count_source,
const type::Type* el_ty, const type::Type* el_ty,
const type::ArrayCount* el_count, const type::ArrayCount* el_count,
@ -426,7 +426,7 @@ class Resolver {
// ArrayInitializerSig represents a unique array initializer signature. // ArrayInitializerSig represents a unique array initializer signature.
// It is a tuple of the array type, number of arguments provided and earliest evaluation stage. // It is a tuple of the array type, number of arguments provided and earliest evaluation stage.
using ArrayInitializerSig = 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. // StructInitializerSig represents a unique structure initializer signature.
// It is a tuple of the structure type, number of arguments provided and earliest evaluation // 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); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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)); EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
} }
@ -452,7 +452,7 @@ TEST_F(ResolverTest, ArraySize_SignedLiteral) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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)); EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
} }
@ -467,7 +467,7 @@ TEST_F(ResolverTest, ArraySize_UnsignedConst) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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)); EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
} }
@ -482,7 +482,7 @@ TEST_F(ResolverTest, ArraySize_SignedConst) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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)); EXPECT_EQ(ary->Count(), create<type::ConstantArrayCount>(10u));
} }
@ -497,7 +497,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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); auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr); ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::NamedOverrideArrayCount>(sem_override)); EXPECT_EQ(ary->Count(), create<sem::NamedOverrideArrayCount>(sem_override));
@ -516,12 +516,12 @@ TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref_a = TypeOf(a)->As<type::Reference>(); auto* ref_a = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref_a, nullptr); 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); ASSERT_NE(TypeOf(b), nullptr);
auto* ref_b = TypeOf(b)->As<type::Reference>(); auto* ref_b = TypeOf(b)->As<type::Reference>();
ASSERT_NE(ref_b, nullptr); 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); auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr); ASSERT_NE(sem_override, nullptr);
@ -542,7 +542,7 @@ TEST_F(ResolverTest, ArraySize_UnnamedOverride) {
ASSERT_NE(TypeOf(a), nullptr); ASSERT_NE(TypeOf(a), nullptr);
auto* ref = TypeOf(a)->As<type::Reference>(); auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr); 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); auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr); ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::UnnamedOverrideArrayCount>(Sem().Get(cnt))); 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); ASSERT_NE(TypeOf(a), nullptr);
auto* ref_a = TypeOf(a)->As<type::Reference>(); auto* ref_a = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref_a, nullptr); 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); ASSERT_NE(TypeOf(b), nullptr);
auto* ref_b = TypeOf(b)->As<type::Reference>(); auto* ref_b = TypeOf(b)->As<type::Reference>();
ASSERT_NE(ref_b, nullptr); 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); auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
ASSERT_NE(sem_override, nullptr); ASSERT_NE(sem_override, nullptr);

View File

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

View File

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

View File

@ -47,7 +47,6 @@
#include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/vector.h" #include "src/tint/ast/vector.h"
#include "src/tint/ast/workgroup_attribute.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/break_if_statement.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/for_loop_statement.h" #include "src/tint/sem/for_loop_statement.h"
@ -64,6 +63,7 @@
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/sem/while_statement.h" #include "src/tint/sem/while_statement.h"
#include "src/tint/type/abstract_numeric.h" #include "src/tint/type/abstract_numeric.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_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 // https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section
bool Validator::IsPlain(const type::Type* type) const { bool Validator::IsPlain(const type::Type* type) const {
return type->is_scalar() || 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 // 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::Vector*) { return true; }, //
[&](const type::Matrix*) { return true; }, // [&](const type::Matrix*) { return true; }, //
[&](const type::Atomic*) { return true; }, [&](const type::Atomic*) { return true; },
[&](const sem::Array* arr) { [&](const type::Array* arr) {
return !arr->Count()->Is<type::RuntimeArrayCount>() && return !arr->Count()->Is<type::RuntimeArrayCount>() &&
IsFixedFootprint(arr->ElemType()); IsFixedFootprint(arr->ElemType());
}, },
@ -217,7 +217,7 @@ bool Validator::IsHostShareable(const type::Type* type) const {
type, // type, //
[&](const type::Vector* vec) { return IsHostShareable(vec->type()); }, [&](const type::Vector* vec) { return IsHostShareable(vec->type()); },
[&](const type::Matrix* mat) { return IsHostShareable(mat->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) { [&](const sem::Struct* str) {
for (auto* member : str->Members()) { for (auto* member : str->Members()) {
if (!IsHostShareable(member->Type())) { 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) { auto is_uniform_struct_or_array = [address_space](const type::Type* ty) {
return address_space == ast::AddressSpace::kUniform && 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) { 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 // 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. // Recurse into the element type.
// TODO(crbug.com/tint/1388): Ideally we'd pass the source for nested element type here, but // 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 // 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, bool Validator::ArrayInitializer(const ast::CallExpression* ctor,
const sem::Array* array_type) const { const type::Array* array_type) const {
auto& values = ctor->args; auto& values = ctor->args;
auto* elem_ty = array_type->ElemType(); auto* elem_ty = array_type->ElemType();
for (auto* value : values) { for (auto* value : values) {
@ -1968,7 +1968,7 @@ bool Validator::PushConstants(utils::VectorRef<sem::Function*> entry_points) con
return true; 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(); auto* el_ty = arr->ElemType();
if (!IsPlain(el_ty)) { 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; 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<type::Array>()) {
if (r->Count()->Is<type::RuntimeArrayCount>()) { if (r->Count()->Is<type::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",
@ -2393,7 +2393,7 @@ bool Validator::IsValidationEnabled(utils::VectorRef<const ast::Attribute*> attr
} }
bool Validator::IsArrayWithOverrideCount(const type::Type* ty) const { 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>()) { if (arr->Count()->IsAnyOf<sem::NamedOverrideArrayCount, sem::UnnamedOverrideArrayCount>()) {
return true; return true;
} }
@ -2474,7 +2474,7 @@ bool Validator::CheckTypeAccessAddressSpace(
return true; return true;
}, },
[&](const sem::Struct*) { return check_sub_atomics(); }, // [&](const sem::Struct*) { return check_sub_atomics(); }, //
[&](const sem::Array*) { return check_sub_atomics(); }, // [&](const type::Array*) { return check_sub_atomics(); }, //
[&](Default) { return true; }); [&](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 /// @param el_source the source of the array element, or the array if the array does not have a
/// locally-declared element AST node. /// locally-declared element AST node.
/// @returns true on success, false otherwise. /// @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 /// Validates an array stride attribute
/// @param attr the stride attribute to validate /// @param attr the stride attribute to validate
@ -432,7 +432,7 @@ class Validator {
/// @param ctor the call expresion to validate /// @param ctor the call expresion to validate
/// @param arr_type the type of the array /// @param arr_type the type of the array
/// @returns true on success, false otherwise /// @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 /// Validates a texture builtin function
/// @param call the builtin call to validate /// @param call the builtin call to validate

View File

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

View File

@ -34,6 +34,10 @@ bool NamedOverrideArrayCount::Equals(const ArrayCount& other) const {
return false; return false;
} }
std::string NamedOverrideArrayCount::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(variable->Declaration()->symbol);
}
UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e) : Base(), expr(e) {} UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e) : Base(), expr(e) {}
UnnamedOverrideArrayCount::~UnnamedOverrideArrayCount() = default; UnnamedOverrideArrayCount::~UnnamedOverrideArrayCount() = default;
@ -48,4 +52,8 @@ bool UnnamedOverrideArrayCount::Equals(const ArrayCount& other) const {
return false; return false;
} }
std::string UnnamedOverrideArrayCount::FriendlyName(const SymbolTable&) const {
return "[unnamed override-expression]";
}
} // namespace tint::sem } // namespace tint::sem

View File

@ -15,6 +15,8 @@
#ifndef SRC_TINT_SEM_ARRAY_COUNT_H_ #ifndef SRC_TINT_SEM_ARRAY_COUNT_H_
#define SRC_TINT_SEM_ARRAY_COUNT_H_ #define SRC_TINT_SEM_ARRAY_COUNT_H_
#include <string>
#include "src/tint/sem/expression.h" #include "src/tint/sem/expression.h"
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/type/array_count.h" #include "src/tint/type/array_count.h"
@ -41,6 +43,10 @@ class NamedOverrideArrayCount final : public Castable<NamedOverrideArrayCount, t
/// @returns true if this array count is equal to the given array count /// @returns true if this array count is equal to the given array count
bool Equals(const type::ArrayCount& t) const override; bool Equals(const type::ArrayCount& t) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override;
/// The `override` variable. /// The `override` variable.
const GlobalVariable* variable; const GlobalVariable* variable;
}; };
@ -66,6 +72,10 @@ class UnnamedOverrideArrayCount final
/// @returns true if this array count is equal to the given array count /// @returns true if this array count is equal to the given array count
bool Equals(const type::ArrayCount& t) const override; bool Equals(const type::ArrayCount& t) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override;
/// The unnamed override expression. /// The unnamed override expression.
/// Note: Each AST expression gets a unique semantic expression node, so two equivalent AST /// Note: Each AST expression gets a unique semantic expression node, so two equivalent AST
/// expressions will not result in the same `expr` pointer. This property is important to ensure /// expressions will not result in the same `expr` pointer. This property is important to ensure

View File

@ -36,7 +36,6 @@ class Variable;
class WhileStatement; class WhileStatement;
} // namespace tint::ast } // namespace tint::ast
namespace tint::sem { namespace tint::sem {
class Array;
class Expression; class Expression;
class ForLoopStatement; class ForLoopStatement;
class Function; class Function;
@ -51,6 +50,7 @@ class Variable;
class WhileStatement; class WhileStatement;
} // namespace tint::sem } // namespace tint::sem
namespace tint::type { namespace tint::type {
class Array;
class Type; class Type;
} // namespace tint::type } // namespace tint::type
@ -62,7 +62,7 @@ namespace tint::sem {
/// rules will be used to infer the return type based on the argument type. /// rules will be used to infer the return type based on the argument type.
struct TypeMappings { struct TypeMappings {
//! @cond Doxygen_Suppress //! @cond Doxygen_Suppress
Array* operator()(ast::Array*); type::Array* operator()(ast::Array*);
Expression* operator()(ast::Expression*); Expression* operator()(ast::Expression*);
ForLoopStatement* operator()(ast::ForLoopStatement*); ForLoopStatement* operator()(ast::ForLoopStatement*);
Function* operator()(ast::Function*); Function* operator()(ast::Function*);

View File

@ -141,14 +141,14 @@ struct ArrayLengthFromUniform::State {
// array_stride // array_stride
const ast::Expression* total_size = total_storage_buffer_size; const ast::Expression* total_size = total_storage_buffer_size;
auto* storage_buffer_type = storage_buffer_sem->Type()->UnwrapRef(); auto* storage_buffer_type = storage_buffer_sem->Type()->UnwrapRef();
const sem::Array* array_type = nullptr; const type::Array* array_type = nullptr;
if (auto* str = storage_buffer_type->As<sem::Struct>()) { if (auto* str = storage_buffer_type->As<sem::Struct>()) {
// The variable is a struct, so subtract the byte offset of the array // The variable is a struct, so subtract the byte offset of the array
// member. // member.
auto* array_member_sem = str->Members().Back(); auto* array_member_sem = str->Members().Back();
array_type = array_member_sem->Type()->As<sem::Array>(); array_type = array_member_sem->Type()->As<type::Array>();
total_size = b.Sub(total_storage_buffer_size, u32(array_member_sem->Offset())); total_size = b.Sub(total_storage_buffer_size, u32(array_member_sem->Offset()));
} else if (auto* arr = storage_buffer_type->As<sem::Array>()) { } else if (auto* arr = storage_buffer_type->As<type::Array>()) {
array_type = arr; array_type = arr;
} else { } else {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())

View File

@ -202,16 +202,16 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src,
const ast::Expression* total_size = const ast::Expression* total_size =
b.Expr(buffer_size_result->variable); b.Expr(buffer_size_result->variable);
const sem::Array* array_type = Switch( const type::Array* array_type = Switch(
storage_buffer_type->StoreType(), storage_buffer_type->StoreType(),
[&](const sem::Struct* str) { [&](const sem::Struct* str) {
// The variable is a struct, so subtract the byte offset of // The variable is a struct, so subtract the byte offset of
// the array member. // the array member.
auto* array_member_sem = str->Members().Back(); auto* array_member_sem = str->Members().Back();
total_size = b.Sub(total_size, u32(array_member_sem->Offset())); total_size = b.Sub(total_size, u32(array_member_sem->Offset()));
return array_member_sem->Type()->As<sem::Array>(); return array_member_sem->Type()->As<type::Array>();
}, },
[&](const sem::Array* arr) { return arr; }); [&](const type::Array* arr) { return arr; });
if (!array_type) { if (!array_type) {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())

View File

@ -26,12 +26,12 @@
#include "src/tint/ast/type_name.h" #include "src/tint/ast/type_name.h"
#include "src/tint/ast/unary_op.h" #include "src/tint/ast/unary_op.h"
#include "src/tint/program_builder.h" #include "src/tint/program_builder.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/member_accessor_expression.h" #include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/statement.h" #include "src/tint/sem/statement.h"
#include "src/tint/sem/struct.h" #include "src/tint/sem/struct.h"
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/reference.h" #include "src/tint/type/reference.h"
#include "src/tint/utils/block_allocator.h" #include "src/tint/utils/block_allocator.h"
@ -490,7 +490,7 @@ struct DecomposeMemoryAccess::State {
}, },
utils::Empty); utils::Empty);
b.AST().AddFunction(func); b.AST().AddFunction(func);
} else if (auto* arr_ty = el_ty->As<sem::Array>()) { } else if (auto* arr_ty = el_ty->As<type::Array>()) {
// fn load_func(buffer : buf_ty, offset : u32) -> array<T, N> { // fn load_func(buffer : buf_ty, offset : u32) -> array<T, N> {
// var arr : array<T, N>; // var arr : array<T, N>;
// for (var i = 0u; i < array_count; i = i + 1) { // for (var i = 0u; i < array_count; i = i + 1) {
@ -592,7 +592,7 @@ struct DecomposeMemoryAccess::State {
} else { } else {
auto body = Switch<utils::Vector<const ast::Statement*, 8>>( auto body = Switch<utils::Vector<const ast::Statement*, 8>>(
el_ty, // el_ty, //
[&](const sem::Array* arr_ty) { [&](const type::Array* arr_ty) {
// fn store_func(buffer : buf_ty, offset : u32, value : el_ty) { // fn store_func(buffer : buf_ty, offset : u32, value : el_ty) {
// var array = value; // No dynamic indexing on constant arrays // var array = value; // No dynamic indexing on constant arrays
// for (var i = 0u; i < array_count; i = i + 1) { // for (var i = 0u; i < array_count; i = i + 1) {
@ -928,7 +928,7 @@ Transform::ApplyResult DecomposeMemoryAccess::Apply(const Program* src,
if (auto* accessor = node->As<ast::IndexAccessorExpression>()) { if (auto* accessor = node->As<ast::IndexAccessorExpression>()) {
if (auto access = state.TakeAccess(accessor->object)) { if (auto access = state.TakeAccess(accessor->object)) {
// X[Y] // X[Y]
if (auto* arr = access.type->As<sem::Array>()) { if (auto* arr = access.type->As<type::Array>()) {
auto* offset = state.Mul(arr->Stride(), accessor->index); auto* offset = state.Mul(arr->Stride(), accessor->index);
state.AddAccess(accessor, { state.AddAccess(accessor, {
access.var, access.var,

View File

@ -32,7 +32,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::transform::DecomposeStridedArray);
namespace tint::transform { namespace tint::transform {
namespace { namespace {
using DecomposedArrays = std::unordered_map<const sem::Array*, Symbol>; using DecomposedArrays = std::unordered_map<const type::Array*, Symbol>;
bool ShouldRun(const Program* program) { bool ShouldRun(const Program* program) {
for (auto* node : program->ASTNodes().Objects()) { for (auto* node : program->ASTNodes().Objects()) {
@ -66,7 +66,7 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src,
// Maps an array type in the source program to the name of the struct wrapper // Maps an array type in the source program to the name of the struct wrapper
// type in the target program. // type in the target program.
std::unordered_map<const sem::Array*, Symbol> decomposed; std::unordered_map<const type::Array*, Symbol> decomposed;
// Find and replace all arrays with a @stride attribute with a array that has // Find and replace all arrays with a @stride attribute with a array that has
// the @stride removed. If the source array stride does not match the natural // the @stride removed. If the source array stride does not match the natural
@ -105,7 +105,7 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src,
// Example: `arr[i]` -> `arr[i].el` // Example: `arr[i]` -> `arr[i].el`
ctx.ReplaceAll([&](const ast::IndexAccessorExpression* idx) -> const ast::Expression* { ctx.ReplaceAll([&](const ast::IndexAccessorExpression* idx) -> const ast::Expression* {
if (auto* ty = src->TypeOf(idx->object)) { if (auto* ty = src->TypeOf(idx->object)) {
if (auto* arr = ty->UnwrapRef()->As<sem::Array>()) { if (auto* arr = ty->UnwrapRef()->As<type::Array>()) {
if (!arr->IsStrideImplicit()) { if (!arr->IsStrideImplicit()) {
auto* expr = ctx.CloneWithoutTransform(idx); auto* expr = ctx.CloneWithoutTransform(idx);
return b.MemberAccessor(expr, kMemberName); return b.MemberAccessor(expr, kMemberName);
@ -127,7 +127,7 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src,
if (!expr->args.IsEmpty()) { if (!expr->args.IsEmpty()) {
if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) { if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) {
if (auto* ctor = call->Target()->As<sem::TypeInitializer>()) { if (auto* ctor = call->Target()->As<sem::TypeInitializer>()) {
if (auto* arr = ctor->ReturnType()->As<sem::Array>()) { if (auto* arr = ctor->ReturnType()->As<type::Array>()) {
// Begin by cloning the array initializer type or name // Begin by cloning the array initializer type or name
// If this is an unaliased array, this may add a new entry to // If this is an unaliased array, this may add a new entry to
// decomposed. // decomposed.

View File

@ -157,7 +157,7 @@ struct LocalizeStructArrayAssignment::State {
// Indexing a member access expr? // Indexing a member access expr?
if (auto* ma = ia->object->As<ast::MemberAccessorExpression>()) { if (auto* ma = ia->object->As<ast::MemberAccessorExpression>()) {
// That accesses an array? // That accesses an array?
if (src->TypeOf(ma)->UnwrapRef()->Is<sem::Array>()) { if (src->TypeOf(ma)->UnwrapRef()->Is<type::Array>()) {
result = true; result = true;
return ast::TraverseAction::Stop; return ast::TraverseAction::Stop;
} }

View File

@ -52,7 +52,7 @@ bool ContainsMatrix(const type::Type* type) {
type = type->UnwrapRef(); type = type->UnwrapRef();
if (type->Is<type::Matrix>()) { if (type->Is<type::Matrix>()) {
return true; return true;
} else if (auto* ary = type->As<sem::Array>()) { } else if (auto* ary = type->As<type::Array>()) {
return ContainsMatrix(ary->ElemType()); return ContainsMatrix(ary->ElemType());
} else if (auto* str = type->As<sem::Struct>()) { } else if (auto* str = type->As<sem::Struct>()) {
for (auto* member : str->Members()) { for (auto* member : str->Members()) {
@ -95,7 +95,7 @@ struct ModuleScopeVarToEntryPointParam::State {
auto* ast_str = str->Declaration(); auto* ast_str = str->Declaration();
ctx.dst->AST().AddTypeDecl(ctx.Clone(ast_str)); ctx.dst->AST().AddTypeDecl(ctx.Clone(ast_str));
ctx.Remove(ctx.src->AST().GlobalDeclarations(), ast_str); ctx.Remove(ctx.src->AST().GlobalDeclarations(), ast_str);
} else if (auto* arr = ty->As<sem::Array>()) { } else if (auto* arr = ty->As<type::Array>()) {
CloneStructTypes(arr->ElemType()); CloneStructTypes(arr->ElemType());
} }
} }
@ -146,7 +146,7 @@ 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>(); if (auto* arr = ty->As<type::Array>();
arr && arr->Count()->Is<type::RuntimeArrayCount>()) { arr && arr->Count()->Is<type::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

View File

@ -83,7 +83,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat
if (ty->Is<sem::Struct>() && str->UsedAs(ast::AddressSpace::kUniform)) { if (ty->Is<sem::Struct>() && str->UsedAs(ast::AddressSpace::kUniform)) {
// 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<type::Array>()) {
if (array_ty->Count()->Is<type::RuntimeArrayCount>()) { if (array_ty->Count()->Is<type::RuntimeArrayCount>()) {
has_runtime_sized_array = true; has_runtime_sized_array = true;
} }

View File

@ -132,7 +132,7 @@ struct PreservePadding::State {
return Switch( return Switch(
ty, // ty, //
[&](const sem::Array* arr) { [&](const type::Array* arr) {
// Call a helper function that uses a loop to assigns each element separately. // Call a helper function that uses a loop to assigns each element separately.
return call_helper([&]() { return call_helper([&]() {
utils::Vector<const ast::Statement*, 8> body; utils::Vector<const ast::Statement*, 8> body;
@ -171,7 +171,7 @@ struct PreservePadding::State {
bool HasPadding(const type::Type* ty) { bool HasPadding(const type::Type* ty) {
return Switch( return Switch(
ty, // ty, //
[&](const sem::Array* arr) { [&](const type::Array* arr) {
auto* elem_ty = arr->ElemType(); auto* elem_ty = arr->ElemType();
if (elem_ty->Size() % elem_ty->Align() > 0) { if (elem_ty->Size() % elem_ty->Align() > 0) {
return true; return true;

View File

@ -64,7 +64,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src,
} }
auto* src_ty = expr->Type(); auto* src_ty = expr->Type();
if (!src_ty->IsAnyOf<sem::Array, sem::Struct>()) { if (!src_ty->IsAnyOf<type::Array, sem::Struct>()) {
// We only care about array and struct initializers // We only care about array and struct initializers
return true; return true;
} }

View File

@ -104,7 +104,7 @@ struct Robustness::State {
return b.Call("min", idx(), u32(mat->columns() - 1u)); return b.Call("min", idx(), u32(mat->columns() - 1u));
}, },
[&](const sem::Array* arr) -> const ast::Expression* { [&](const type::Array* arr) -> const ast::Expression* {
const ast::Expression* max = nullptr; const ast::Expression* max = nullptr;
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::RuntimeArrayCount>()) {
// Size is unknown until runtime. // Size is unknown until runtime.
@ -122,7 +122,7 @@ struct Robustness::State {
// Note: Don't be tempted to use the array override variable as an expression // Note: Don't be tempted to use the array override variable as an expression
// here, the name might be shadowed! // here, the name might be shadowed!
b.Diagnostics().add_error(diag::System::Transform, b.Diagnostics().add_error(diag::System::Transform,
sem::Array::kErrExpectedConstantCount); type::Array::kErrExpectedConstantCount);
return nullptr; return nullptr;
} }

View File

@ -70,7 +70,7 @@ Transform::ApplyResult SingleEntryPoint::Apply(const Program* src,
decl, // decl, //
[&](const ast::TypeDecl* ty) { [&](const ast::TypeDecl* ty) {
// Strip aliases that reference unused override declarations. // Strip aliases that reference unused override declarations.
if (auto* arr = sem.Get(ty)->As<sem::Array>()) { if (auto* arr = sem.Get(ty)->As<type::Array>()) {
auto* refs = sem.TransitivelyReferencedOverrides(arr); auto* refs = sem.TransitivelyReferencedOverrides(arr);
if (refs) { if (refs) {
for (auto* o : *refs) { for (auto* o : *refs) {

View File

@ -198,7 +198,7 @@ struct SpirvAtomic::State {
[&](const type::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); }, [&](const type::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const type::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); }, [&](const type::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 type::Array* arr) -> const ast::Type* {
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::RuntimeArrayCount>()) {
return b.ty.array(AtomicTypeFor(arr->ElemType())); return b.ty.array(AtomicTypeFor(arr->ElemType()));
} }

View File

@ -129,7 +129,7 @@ struct Std140::State {
bool ShouldRun() const { bool ShouldRun() const {
// Returns true if the type needs to be forked for std140 usage. // Returns true if the type needs to be forked for std140 usage.
auto needs_fork = [&](const type::Type* ty) { auto needs_fork = [&](const type::Type* ty) {
while (auto* arr = ty->As<sem::Array>()) { while (auto* arr = ty->As<type::Array>()) {
ty = arr->ElemType(); ty = arr->ElemType();
} }
if (auto* mat = ty->As<type::Matrix>()) { if (auto* mat = ty->As<type::Matrix>()) {
@ -426,7 +426,7 @@ struct Std140::State {
} }
return nullptr; return nullptr;
}, },
[&](const sem::Array* arr) -> const ast::Type* { [&](const type::Array* arr) -> const ast::Type* {
if (auto* std140 = Std140Type(arr->ElemType())) { if (auto* std140 = Std140Type(arr->ElemType())) {
utils::Vector<const ast::Attribute*, 1> attrs; utils::Vector<const ast::Attribute*, 1> attrs;
if (!arr->IsStrideImplicit()) { if (!arr->IsStrideImplicit()) {
@ -631,7 +631,7 @@ struct Std140::State {
return Switch( return Switch(
ty, // ty, //
[&](const sem::Struct* str) { return sym.NameFor(str->Name()); }, [&](const sem::Struct* str) { return sym.NameFor(str->Name()); },
[&](const sem::Array* arr) { [&](const type::Array* arr) {
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
// Non-constant counts should not be possible: // Non-constant counts should not be possible:
@ -730,7 +730,7 @@ struct Std140::State {
<< "failed to find std140 matrix info for: " << src->FriendlyName(ty); << "failed to find std140 matrix info for: " << src->FriendlyName(ty);
} }
}, // }, //
[&](const sem::Array* arr) { [&](const type::Array* arr) {
// Converting an array. Create a function var for the converted array, and // Converting an array. Create a function var for the converted array, and
// loop over the input elements, converting each and assigning the result to // loop over the input elements, converting each and assigning the result to
// the local array. // the local array.
@ -1081,7 +1081,7 @@ struct Std140::State {
auto name = "p" + std::to_string(dyn_idx->slot); auto name = "p" + std::to_string(dyn_idx->slot);
return Switch( return Switch(
ty, // ty, //
[&](const sem::Array* arr) -> ExprTypeName { [&](const type::Array* arr) -> ExprTypeName {
auto* idx = dynamic_index(dyn_idx->slot); auto* idx = dynamic_index(dyn_idx->slot);
auto* expr = b.IndexAccessor(lhs, idx); auto* expr = b.IndexAccessor(lhs, idx);
return {expr, arr->ElemType(), name}; return {expr, arr->ElemType(), name};
@ -1134,7 +1134,7 @@ struct Std140::State {
ty = member->Type(); ty = member->Type();
return {expr, ty, member_name}; return {expr, ty, member_name};
}, // }, //
[&](const sem::Array* arr) -> ExprTypeName { [&](const type::Array* arr) -> ExprTypeName {
auto* expr = b.IndexAccessor(lhs, idx); auto* expr = b.IndexAccessor(lhs, idx);
return {expr, arr->ElemType(), std::to_string(idx)}; return {expr, arr->ElemType(), std::to_string(idx)};
}, // }, //

View File

@ -100,7 +100,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
auto* el = CreateASTTypeFor(ctx, v->type()); auto* el = CreateASTTypeFor(ctx, v->type());
return ctx.dst->create<ast::Vector>(el, v->Width()); return ctx.dst->create<ast::Vector>(el, v->Width());
} }
if (auto* a = ty->As<sem::Array>()) { if (auto* a = ty->As<type::Array>()) {
auto* el = CreateASTTypeFor(ctx, a->ElemType()); auto* el = CreateASTTypeFor(ctx, a->ElemType());
utils::Vector<const ast::Attribute*, 1> attrs; utils::Vector<const ast::Attribute*, 1> attrs;
if (!a->IsStrideImplicit()) { if (!a->IsStrideImplicit()) {
@ -133,7 +133,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
if (auto count = a->ConstantCount()) { if (auto count = a->ConstantCount()) {
return ctx.dst->ty.array(el, u32(count.value()), std::move(attrs)); return ctx.dst->ty.array(el, u32(count.value()), std::move(attrs));
} }
TINT_ICE(Transform, ctx.dst->Diagnostics()) << sem::Array::kErrExpectedConstantCount; TINT_ICE(Transform, ctx.dst->Diagnostics()) << type::Array::kErrExpectedConstantCount;
return ctx.dst->ty.array(el, u32(1), std::move(attrs)); return ctx.dst->ty.array(el, u32(1), std::move(attrs));
} }
if (auto* s = ty->As<sem::Struct>()) { if (auto* s = ty->As<sem::Struct>()) {

View File

@ -69,7 +69,7 @@ TEST_F(CreateASTTypeForTest, Vector) {
TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
auto* arr = create([](ProgramBuilder& b) { auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u), return b.create<type::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 32u, 32u); 4u, 4u, 32u, 32u);
}); });
ASSERT_TRUE(arr->Is<ast::Array>()); ASSERT_TRUE(arr->Is<ast::Array>());
@ -83,7 +83,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) {
auto* arr = create([](ProgramBuilder& b) { auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u), return b.create<type::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 64u, 32u); 4u, 4u, 64u, 32u);
}); });
ASSERT_TRUE(arr->Is<ast::Array>()); ASSERT_TRUE(arr->Is<ast::Array>());

View File

@ -47,7 +47,7 @@ Transform::ApplyResult VarForDynamicIndex::Apply(const Program* src,
} }
auto* indexed = sem.Get(object_expr); auto* indexed = sem.Get(object_expr);
if (!indexed->Type()->IsAnyOf<sem::Array, type::Matrix>()) { if (!indexed->Type()->IsAnyOf<type::Array, type::Matrix>()) {
// We only care about array and matrices. // We only care about array and matrices.
return true; return true;
} }

View File

@ -333,7 +333,7 @@ struct ZeroInitWorkgroupMemory::State {
return true; return true;
} }
if (auto* arr = ty->As<sem::Array>()) { if (auto* arr = ty->As<type::Array>()) {
auto get_el = [&](uint32_t num_values) { auto get_el = [&](uint32_t num_values) {
// num_values is the number of values to zero for the element type. // num_values is the number of values to zero for the element type.
// The number of iterations required to zero the array and its elements is: // The number of iterations required to zero the array and its elements is:
@ -343,7 +343,7 @@ struct ZeroInitWorkgroupMemory::State {
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
ctx.dst->Diagnostics().add_error(diag::System::Transform, ctx.dst->Diagnostics().add_error(diag::System::Transform,
sem::Array::kErrExpectedConstantCount); type::Array::kErrExpectedConstantCount);
return Expression{}; // error return Expression{}; // error
} }
auto modulo = num_values * count.value(); auto modulo = num_values * count.value();
@ -449,7 +449,7 @@ struct ZeroInitWorkgroupMemory::State {
} }
} }
} }
if (ty->Is<sem::Array>()) { if (ty->Is<type::Array>()) {
return false; return false;
} }
// True for all other storable types // True for all other storable types

View File

@ -1,4 +1,4 @@
// Copyright 2021 The Tint Authors. // Copyright 2022 The Tint Authors.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -12,19 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/tint/sem/array.h" #include "src/tint/type/array.h"
#include <string> #include <string>
#include "src/tint/ast/variable.h" #include "src/tint/ast/variable.h"
#include "src/tint/debug.h" #include "src/tint/debug.h"
#include "src/tint/sem/variable.h"
#include "src/tint/symbol_table.h" #include "src/tint/symbol_table.h"
#include "src/tint/utils/hash.h" #include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::Array); TINT_INSTANTIATE_TYPEINFO(tint::type::Array);
namespace tint::sem { namespace tint::type {
namespace { namespace {
@ -39,8 +38,7 @@ type::TypeFlags FlagsFrom(const type::Type* element, const type::ArrayCount* cou
flags.Add(type::TypeFlag::kCreationFixedFootprint); flags.Add(type::TypeFlag::kCreationFixedFootprint);
} }
} }
if (count->IsAnyOf<type::ConstantArrayCount, sem::NamedOverrideArrayCount, if (!count->Is<type::RuntimeArrayCount>()) {
sem::UnnamedOverrideArrayCount>()) {
if (element->HasFixedFootprint()) { if (element->HasFixedFootprint()) {
flags.Add(type::TypeFlag::kFixedFootprint); flags.Add(type::TypeFlag::kFixedFootprint);
} }
@ -67,7 +65,7 @@ Array::Array(const type::Type* element,
size_(size), size_(size),
stride_(stride), stride_(stride),
implicit_stride_(implicit_stride) { implicit_stride_(implicit_stride) {
TINT_ASSERT(Semantic, element_); TINT_ASSERT(Type, element_);
} }
size_t Array::Hash() const { size_t Array::Hash() const {
@ -90,13 +88,12 @@ std::string Array::FriendlyName(const SymbolTable& symbols) const {
out << "@stride(" << stride_ << ") "; out << "@stride(" << stride_ << ") ";
} }
out << "array<" << element_->FriendlyName(symbols); out << "array<" << element_->FriendlyName(symbols);
if (auto* const_count = count_->As<type::ConstantArrayCount>()) {
out << ", " << const_count->value; auto count_str = count_->FriendlyName(symbols);
} else if (auto* named_override_count = count_->As<sem::NamedOverrideArrayCount>()) { if (!count_str.empty()) {
out << ", " << symbols.NameFor(named_override_count->variable->Declaration()->symbol); out << ", " << count_str;
} else if (count_->Is<sem::UnnamedOverrideArrayCount>()) {
out << ", [unnamed override-expression]";
} }
out << ">"; out << ">";
return out.str(); return out.str();
} }
@ -109,4 +106,4 @@ uint32_t Array::Size() const {
return size_; return size_;
} }
} // namespace tint::sem } // namespace tint::type

View File

@ -12,29 +12,22 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_TINT_SEM_ARRAY_H_ #ifndef SRC_TINT_TYPE_ARRAY_H_
#define SRC_TINT_SEM_ARRAY_H_ #define SRC_TINT_TYPE_ARRAY_H_
#include <stdint.h> #include <stdint.h>
#include <optional> #include <optional>
#include <string> #include <string>
#include <variant> #include <variant>
#include "src/tint/sem/array_count.h" #include "src/tint/type/array_count.h"
#include "src/tint/sem/node.h"
#include "src/tint/type/type.h" #include "src/tint/type/type.h"
#include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/unique_vector.h" #include "src/tint/utils/unique_vector.h"
// Forward declarations namespace tint::type {
namespace tint::sem {
class Expression;
class GlobalVariable;
} // namespace tint::sem
namespace tint::sem { /// Array holds the type information for Array nodes.
/// Array holds the semantic information for Array nodes.
class Array final : public Castable<Array, type::Type> { class Array final : public Castable<Array, type::Type> {
public: public:
/// An error message string stating that the array count was expected to be a constant /// An error message string stating that the array count was expected to be a constant
@ -117,6 +110,6 @@ class Array final : public Castable<Array, type::Type> {
const uint32_t implicit_stride_; const uint32_t implicit_stride_;
}; };
} // namespace tint::sem } // namespace tint::type
#endif // SRC_TINT_SEM_ARRAY_H_ #endif // SRC_TINT_TYPE_ARRAY_H_

View File

@ -37,6 +37,10 @@ bool ConstantArrayCount::Equals(const ArrayCount& other) const {
return false; return false;
} }
std::string ConstantArrayCount::FriendlyName(const SymbolTable&) const {
return std::to_string(value);
}
RuntimeArrayCount::RuntimeArrayCount() : Base() {} RuntimeArrayCount::RuntimeArrayCount() : Base() {}
RuntimeArrayCount::~RuntimeArrayCount() = default; RuntimeArrayCount::~RuntimeArrayCount() = default;
@ -48,4 +52,8 @@ bool RuntimeArrayCount::Equals(const ArrayCount& other) const {
return other.Is<RuntimeArrayCount>(); return other.Is<RuntimeArrayCount>();
} }
std::string RuntimeArrayCount::FriendlyName(const SymbolTable&) const {
return "";
}
} // namespace tint::type } // namespace tint::type

View File

@ -16,7 +16,9 @@
#define SRC_TINT_TYPE_ARRAY_COUNT_H_ #define SRC_TINT_TYPE_ARRAY_COUNT_H_
#include <functional> #include <functional>
#include <string>
#include "src/tint/symbol_table.h"
#include "src/tint/type/node.h" #include "src/tint/type/node.h"
namespace tint::type { namespace tint::type {
@ -33,6 +35,10 @@ class ArrayCount : public Castable<ArrayCount, Node> {
/// @returns true if this array count is equal to the given array count /// @returns true if this array count is equal to the given array count
virtual bool Equals(const ArrayCount& t) const = 0; virtual bool Equals(const ArrayCount& t) const = 0;
/// @param symbols the symbol table
/// @returns the friendly name for this array count
virtual std::string FriendlyName(const SymbolTable& symbols) const = 0;
protected: protected:
ArrayCount(); ArrayCount();
}; };
@ -57,6 +63,10 @@ class ConstantArrayCount final : public Castable<ConstantArrayCount, ArrayCount>
/// @returns true if this array count is equal to the given array count /// @returns true if this array count is equal to the given array count
bool Equals(const ArrayCount& t) const override; bool Equals(const ArrayCount& t) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override;
/// The array count constant-expression value. /// The array count constant-expression value.
uint32_t value; uint32_t value;
}; };
@ -78,6 +88,10 @@ class RuntimeArrayCount final : public Castable<RuntimeArrayCount, ArrayCount> {
/// @param t other array count /// @param t other array count
/// @returns true if this array count is equal to the given array count /// @returns true if this array count is equal to the given array count
bool Equals(const ArrayCount& t) const override; bool Equals(const ArrayCount& t) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override;
}; };
} // namespace tint::type } // namespace tint::type

View File

@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/tint/sem/test_helper.h" #include "src/tint/sem/array_count.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture.h" #include "src/tint/type/texture.h"
namespace tint::sem { namespace tint::type {
namespace { namespace {
using ArrayTest = TestHelper; using ArrayTest = TestHelper;
@ -205,4 +206,4 @@ TEST_F(ArrayTest, HasFixedFootprint) {
} }
} // namespace } // namespace
} // namespace tint::sem } // namespace tint::type

View File

@ -14,10 +14,9 @@
#include "src/tint/type/type.h" #include "src/tint/type/type.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/struct.h"
#include "src/tint/type/abstract_float.h" #include "src/tint/type/abstract_float.h"
#include "src/tint/type/abstract_int.h" #include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/bool.h" #include "src/tint/type/bool.h"
#include "src/tint/type/f16.h" #include "src/tint/type/f16.h"
#include "src/tint/type/f32.h" #include "src/tint/type/f32.h"
@ -26,6 +25,7 @@
#include "src/tint/type/pointer.h" #include "src/tint/type/pointer.h"
#include "src/tint/type/reference.h" #include "src/tint/type/reference.h"
#include "src/tint/type/sampler.h" #include "src/tint/type/sampler.h"
#include "src/tint/type/struct.h"
#include "src/tint/type/texture.h" #include "src/tint/type/texture.h"
#include "src/tint/type/u32.h" #include "src/tint/type/u32.h"
#include "src/tint/type/vector.h" #include "src/tint/type/vector.h"
@ -181,7 +181,7 @@ bool Type::HoldsAbstract() const {
[&](const type::AbstractNumeric*) { return true; }, [&](const type::AbstractNumeric*) { return true; },
[&](const type::Vector* v) { return v->type()->HoldsAbstract(); }, [&](const type::Vector* v) { return v->type()->HoldsAbstract(); },
[&](const type::Matrix* m) { return m->type()->HoldsAbstract(); }, [&](const type::Matrix* m) { return m->type()->HoldsAbstract(); },
[&](const sem::Array* a) { return a->ElemType()->HoldsAbstract(); }, [&](const type::Array* a) { return a->ElemType()->HoldsAbstract(); },
[&](const type::StructBase* s) { [&](const type::StructBase* s) {
for (auto* m : s->Members()) { for (auto* m : s->Members()) {
if (m->Type()->HoldsAbstract()) { if (m->Type()->HoldsAbstract()) {
@ -232,8 +232,8 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
} }
return kNoConversion; return kNoConversion;
}, },
[&](const sem::Array* from_arr) { [&](const type::Array* from_arr) {
if (auto* to_arr = to->As<sem::Array>()) { if (auto* to_arr = to->As<type::Array>()) {
if (from_arr->Count() == to_arr->Count()) { if (from_arr->Count() == to_arr->Count()) {
return ConversionRank(from_arr->ElemType(), to_arr->ElemType()); return ConversionRank(from_arr->ElemType(), to_arr->ElemType());
} }
@ -273,7 +273,7 @@ const Type* Type::ElementOf(const Type* ty, uint32_t* count /* = nullptr */) {
} }
return m->ColumnType(); return m->ColumnType();
}, },
[&](const sem::Array* a) { [&](const type::Array* a) {
if (count) { if (count) {
if (auto* const_count = a->Count()->As<type::ConstantArrayCount>()) { if (auto* const_count = a->Count()->As<type::ConstantArrayCount>()) {
*count = const_count->value; *count = const_count->value;

View File

@ -20,9 +20,9 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include "src/tint/sem/struct.h"
#include "src/tint/type/array_count.h" #include "src/tint/type/array_count.h"
#include "src/tint/type/node.h" #include "src/tint/type/node.h"
#include "src/tint/type/struct.h"
#include "src/tint/type/type.h" #include "src/tint/type/type.h"
#include "src/tint/utils/unique_allocator.h" #include "src/tint/utils/unique_allocator.h"

View File

@ -93,63 +93,63 @@ struct TypeTest : public TestHelper {
/* align*/ 4u, /* align*/ 4u,
/* size*/ 4u, /* size*/ 4u,
/* size_no_padding*/ 4u); /* size_no_padding*/ 4u);
const sem::Array* arr_i32 = create<sem::Array>( const type::Array* arr_i32 = create<type::Array>(
/* element */ i32, /* element */ i32,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 4u, /* align */ 4u,
/* size */ 5u * 4u, /* size */ 5u * 4u,
/* stride */ 5u * 4u, /* stride */ 5u * 4u,
/* implicit_stride */ 5u * 4u); /* implicit_stride */ 5u * 4u);
const sem::Array* arr_ai = create<sem::Array>( const type::Array* arr_ai = create<type::Array>(
/* element */ ai, /* element */ ai,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 4u, /* align */ 4u,
/* size */ 5u * 4u, /* size */ 5u * 4u,
/* stride */ 5u * 4u, /* stride */ 5u * 4u,
/* implicit_stride */ 5u * 4u); /* implicit_stride */ 5u * 4u);
const sem::Array* arr_vec3_i32 = create<sem::Array>( const type::Array* arr_vec3_i32 = create<type::Array>(
/* element */ vec3_i32, /* element */ vec3_i32,
/* count */ create<ConstantArrayCount>(5u), /* count */ create<ConstantArrayCount>(5u),
/* align */ 16u, /* align */ 16u,
/* size */ 5u * 16u, /* size */ 5u * 16u,
/* stride */ 5u * 16u, /* stride */ 5u * 16u,
/* implicit_stride */ 5u * 16u); /* implicit_stride */ 5u * 16u);
const sem::Array* arr_vec3_ai = create<sem::Array>( const type::Array* arr_vec3_ai = create<type::Array>(
/* element */ vec3_ai, /* element */ vec3_ai,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 16u, /* align */ 16u,
/* size */ 5u * 16u, /* size */ 5u * 16u,
/* stride */ 5u * 16u, /* stride */ 5u * 16u,
/* implicit_stride */ 5u * 16u); /* implicit_stride */ 5u * 16u);
const sem::Array* arr_mat4x3_f16 = create<sem::Array>( const type::Array* arr_mat4x3_f16 = create<type::Array>(
/* element */ mat4x3_f16, /* element */ mat4x3_f16,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 32u, /* align */ 32u,
/* size */ 5u * 32u, /* size */ 5u * 32u,
/* stride */ 5u * 32u, /* stride */ 5u * 32u,
/* implicit_stride */ 5u * 32u); /* implicit_stride */ 5u * 32u);
const sem::Array* arr_mat4x3_f32 = create<sem::Array>( const type::Array* arr_mat4x3_f32 = create<type::Array>(
/* element */ mat4x3_f32, /* element */ mat4x3_f32,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 64u, /* align */ 64u,
/* size */ 5u * 64u, /* size */ 5u * 64u,
/* stride */ 5u * 64u, /* stride */ 5u * 64u,
/* implicit_stride */ 5u * 64u); /* implicit_stride */ 5u * 64u);
const sem::Array* arr_mat4x3_af = create<sem::Array>( const type::Array* arr_mat4x3_af = create<type::Array>(
/* element */ mat4x3_af, /* element */ mat4x3_af,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 64u, /* align */ 64u,
/* size */ 5u * 64u, /* size */ 5u * 64u,
/* stride */ 5u * 64u, /* stride */ 5u * 64u,
/* implicit_stride */ 5u * 64u); /* implicit_stride */ 5u * 64u);
const sem::Array* arr_str_f16 = create<sem::Array>( const type::Array* arr_str_f16 = create<type::Array>(
/* element */ str_f16, /* element */ str_f16,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 4u, /* align */ 4u,
/* size */ 5u * 4u, /* size */ 5u * 4u,
/* stride */ 5u * 4u, /* stride */ 5u * 4u,
/* implicit_stride */ 5u * 4u); /* implicit_stride */ 5u * 4u);
const sem::Array* arr_str_af = create<sem::Array>( const type::Array* arr_str_af = create<type::Array>(
/* element */ str_af, /* element */ str_af,
/* count */ create<type::ConstantArrayCount>(5u), /* count */ create<type::ConstantArrayCount>(5u),
/* align */ 4u, /* align */ 4u,

View File

@ -27,7 +27,6 @@
#include "src/tint/ast/interpolate_attribute.h" #include "src/tint/ast/interpolate_attribute.h"
#include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/debug.h" #include "src/tint/debug.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/block_statement.h" #include "src/tint/sem/block_statement.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
@ -63,6 +62,7 @@
#include "src/tint/transform/std140.h" #include "src/tint/transform/std140.h"
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h" #include "src/tint/type/depth_texture.h"
@ -295,7 +295,7 @@ bool GeneratorImpl::Generate() {
} else if (auto* str = decl->As<ast::Struct>()) { } else if (auto* str = decl->As<ast::Struct>()) {
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<type::Array>()) {
has_rt_arr = arr->Count()->Is<type::RuntimeArrayCount>(); has_rt_arr = arr->Count()->Is<type::RuntimeArrayCount>();
} }
bool is_block = bool is_block =
@ -2355,7 +2355,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
} }
return true; return true;
}, },
[&](const sem::Array* a) { [&](const type::Array* a) {
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) { if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
return false; return false;
} }
@ -2364,7 +2364,8 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
auto count = a->ConstantCount(); auto count = a->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, sem::Array::kErrExpectedConstantCount); diagnostics_.add_error(diag::System::Writer,
type::Array::kErrExpectedConstantCount);
return false; return false;
} }
@ -2486,7 +2487,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
} }
EmitZeroValue(out, member->Type()); EmitZeroValue(out, member->Type());
} }
} else if (auto* arr = type->As<sem::Array>()) { } else if (auto* arr = type->As<type::Array>()) {
if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) { if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
return false; return false;
} }
@ -2494,7 +2495,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, sem::Array::kErrExpectedConstantCount); diagnostics_.add_error(diag::System::Writer, type::Array::kErrExpectedConstantCount);
return false; return false;
} }
@ -2837,17 +2838,17 @@ bool GeneratorImpl::EmitType(std::ostream& out,
break; break;
} }
if (auto* ary = type->As<sem::Array>()) { if (auto* ary = type->As<type::Array>()) {
const type::Type* base_type = ary; const type::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<type::Array>()) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::RuntimeArrayCount>()) {
sizes.push_back(0); sizes.push_back(0);
} else { } else {
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
sem::Array::kErrExpectedConstantCount); type::Array::kErrExpectedConstantCount);
return false; return false;
} }
sizes.push_back(count.value()); sizes.push_back(count.value());

View File

@ -28,7 +28,6 @@
#include "src/tint/ast/interpolate_attribute.h" #include "src/tint/ast/interpolate_attribute.h"
#include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/debug.h" #include "src/tint/debug.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/block_statement.h" #include "src/tint/sem/block_statement.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
@ -63,6 +62,7 @@
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h" #include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h" #include "src/tint/type/depth_texture.h"
@ -1053,7 +1053,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out,
} }
} }
bool brackets = type->IsAnyOf<sem::Array, sem::Struct>(); bool brackets = type->IsAnyOf<type::Array, sem::Struct>();
// For single-value vector initializers, swizzle the scalar to the right // For single-value vector initializers, swizzle the scalar to the right
// vector dimension using .x // vector dimension using .x
@ -2852,7 +2852,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
auto name = builder_.Symbols().NameFor(func->symbol); auto name = builder_.Symbols().NameFor(func->symbol);
// If the function returns an array, then we need to declare a typedef for // If the function returns an array, then we need to declare a typedef for
// this. // this.
if (sem->ReturnType()->Is<sem::Array>()) { if (sem->ReturnType()->Is<type::Array>()) {
auto typedef_name = UniqueIdentifier(name + "_ret"); auto typedef_name = UniqueIdentifier(name + "_ret");
auto pre = line(); auto pre = line();
pre << "typedef "; pre << "typedef ";
@ -3338,7 +3338,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out,
} }
return true; return true;
}, },
[&](const sem::Array* a) { [&](const type::Array* a) {
if (constant->AllZero()) { if (constant->AllZero()) {
out << "("; out << "(";
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) { if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
@ -3353,7 +3353,8 @@ bool GeneratorImpl::EmitConstant(std::ostream& out,
auto count = a->ConstantCount(); auto count = a->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, sem::Array::kErrExpectedConstantCount); diagnostics_.add_error(diag::System::Writer,
type::Array::kErrExpectedConstantCount);
return false; return false;
} }
@ -3514,7 +3515,7 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int val
TINT_DEFER(out << ")" << value); TINT_DEFER(out << ")" << value);
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, ""); return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "");
}, },
[&](const sem::Array*) { [&](const type::Array*) {
out << "("; out << "(";
TINT_DEFER(out << ")" << value); TINT_DEFER(out << ")" << value);
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, ""); return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "");
@ -3920,10 +3921,10 @@ bool GeneratorImpl::EmitType(std::ostream& out,
return Switch( return Switch(
type, type,
[&](const sem::Array* ary) { [&](const type::Array* ary) {
const type::Type* base_type = ary; const type::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<type::Array>()) {
if (arr->Count()->Is<type::RuntimeArrayCount>()) { if (arr->Count()->Is<type::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 "
@ -3933,7 +3934,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
const auto count = arr->ConstantCount(); const auto count = arr->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
sem::Array::kErrExpectedConstantCount); type::Array::kErrExpectedConstantCount);
return false; return false;
} }

View File

@ -31,7 +31,6 @@
#include "src/tint/ast/module.h" #include "src/tint/ast/module.h"
#include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/void.h" #include "src/tint/ast/void.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
#include "src/tint/sem/function.h" #include "src/tint/sem/function.h"
@ -59,6 +58,7 @@
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h" #include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/bool.h" #include "src/tint/type/bool.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
@ -805,7 +805,7 @@ bool GeneratorImpl::EmitTypeInitializer(std::ostream& out,
bool ok = Switch( bool ok = Switch(
type, type,
[&](const sem::Array*) { [&](const type::Array*) {
if (!EmitType(out, type, "")) { if (!EmitType(out, type, "")) {
return false; return false;
} }
@ -1642,7 +1642,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
ScopedParen sp(out); ScopedParen sp(out);
return EmitZeroValue(out, mat->type()); return EmitZeroValue(out, mat->type());
}, },
[&](const sem::Array*) { [&](const type::Array*) {
out << "{}"; out << "{}";
return true; return true;
}, },
@ -1722,7 +1722,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
} }
return true; return true;
}, },
[&](const sem::Array* a) { [&](const type::Array* a) {
if (!EmitType(out, a, "")) { if (!EmitType(out, a, "")) {
return false; return false;
} }
@ -1736,7 +1736,8 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
auto count = a->ConstantCount(); auto count = a->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, sem::Array::kErrExpectedConstantCount); diagnostics_.add_error(diag::System::Writer,
type::Array::kErrExpectedConstantCount);
return false; return false;
} }
@ -2536,7 +2537,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
<< "unhandled atomic type " << atomic->Type()->FriendlyName(builder_.Symbols()); << "unhandled atomic type " << atomic->Type()->FriendlyName(builder_.Symbols());
return false; return false;
}, },
[&](const sem::Array* arr) { [&](const type::Array* arr) {
out << ArrayType() << "<"; out << ArrayType() << "<";
if (!EmitType(out, arr->ElemType(), "")) { if (!EmitType(out, arr->ElemType(), "")) {
return false; return false;
@ -2548,7 +2549,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
sem::Array::kErrExpectedConstantCount); type::Array::kErrExpectedConstantCount);
return false; return false;
} }
@ -3164,7 +3165,7 @@ GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(const type:
return SizeAndAlign{}; return SizeAndAlign{};
}, },
[&](const sem::Array* arr) { [&](const type::Array* arr) {
if (!arr->IsStrideImplicit()) { if (!arr->IsStrideImplicit()) {
TINT_ICE(Writer, diagnostics_) TINT_ICE(Writer, diagnostics_)
<< "arrays with explicit strides should not exist past the SPIR-V reader"; << "arrays with explicit strides should not exist past the SPIR-V reader";
@ -3176,7 +3177,7 @@ GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(const type:
if (auto count = arr->ConstantCount()) { if (auto count = arr->ConstantCount()) {
return SizeAndAlign{arr->Stride() * count.value(), arr->Align()}; return SizeAndAlign{arr->Stride() * count.value(), arr->Align()};
} }
diagnostics_.add_error(diag::System::Writer, sem::Array::kErrExpectedConstantCount); diagnostics_.add_error(diag::System::Writer, type::Array::kErrExpectedConstantCount);
return SizeAndAlign{}; return SizeAndAlign{};
}, },

View File

@ -22,7 +22,6 @@
#include "src/tint/ast/id_attribute.h" #include "src/tint/ast/id_attribute.h"
#include "src/tint/ast/internal_attribute.h" #include "src/tint/ast/internal_attribute.h"
#include "src/tint/ast/traverse_expressions.h" #include "src/tint/ast/traverse_expressions.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/builtin.h" #include "src/tint/sem/builtin.h"
#include "src/tint/sem/call.h" #include "src/tint/sem/call.h"
#include "src/tint/sem/constant.h" #include "src/tint/sem/constant.h"
@ -37,6 +36,7 @@
#include "src/tint/sem/type_initializer.h" #include "src/tint/sem/type_initializer.h"
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/transform/add_block_attribute.h" #include "src/tint/transform/add_block_attribute.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h" #include "src/tint/type/atomic.h"
#include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h" #include "src/tint/type/depth_texture.h"
@ -90,7 +90,7 @@ uint32_t pipeline_stage_to_execution_model(ast::PipelineStage stage) {
/// @param type the given type, which must not be null /// @param type the given type, which must not be null
/// @returns the nested matrix type, or nullptr if none /// @returns the nested matrix type, or nullptr if none
const type::Matrix* GetNestedMatrixType(const type::Type* type) { const type::Matrix* GetNestedMatrixType(const type::Type* type) {
while (auto* arr = type->As<sem::Array>()) { while (auto* arr = type->As<type::Array>()) {
type = arr->ElemType(); type = arr->ElemType();
} }
return type->As<type::Matrix>(); return type->As<type::Matrix>();
@ -1348,7 +1348,7 @@ uint32_t Builder::GenerateTypeInitializerOrConversion(const sem::Call* call,
// If the result is not a vector then we should have validated that the // If the result is not a vector then we should have validated that the
// value type is a correctly sized vector so we can just use it directly. // value type is a correctly sized vector so we can just use it directly.
if (result_type == value_type || result_type->Is<type::Matrix>() || if (result_type == value_type || result_type->Is<type::Matrix>() ||
result_type->Is<sem::Array>() || result_type->Is<sem::Struct>()) { result_type->Is<type::Array>() || result_type->Is<sem::Struct>()) {
ops.push_back(Operand(id)); ops.push_back(Operand(id));
continue; continue;
} }
@ -1702,10 +1702,10 @@ uint32_t Builder::GenerateConstantIfNeeded(const sem::Constant* constant) {
}, },
[&](const type::Vector* v) { return composite(v->Width()); }, [&](const type::Vector* v) { return composite(v->Width()); },
[&](const type::Matrix* m) { return composite(m->columns()); }, [&](const type::Matrix* m) { return composite(m->columns()); },
[&](const sem::Array* a) { [&](const type::Array* a) {
auto count = a->ConstantCount(); auto count = a->ConstantCount();
if (!count) { if (!count) {
error_ = sem::Array::kErrExpectedConstantCount; error_ = type::Array::kErrExpectedConstantCount;
return static_cast<uint32_t>(0); return static_cast<uint32_t>(0);
} }
return composite(count.value()); return composite(count.value());
@ -3673,7 +3673,7 @@ uint32_t Builder::GenerateTypeIfNeeded(const type::Type* type) {
auto id = std::get<uint32_t>(result); auto id = std::get<uint32_t>(result);
bool ok = Switch( bool ok = Switch(
type, type,
[&](const sem::Array* arr) { // [&](const type::Array* arr) { //
return GenerateArrayType(arr, result); return GenerateArrayType(arr, result);
}, },
[&](const type::Bool*) { [&](const type::Bool*) {
@ -3838,7 +3838,7 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r
return true; return true;
} }
bool Builder::GenerateArrayType(const sem::Array* arr, const Operand& result) { bool Builder::GenerateArrayType(const type::Array* arr, const Operand& result) {
auto elem_type = GenerateTypeIfNeeded(arr->ElemType()); auto elem_type = GenerateTypeIfNeeded(arr->ElemType());
if (elem_type == 0) { if (elem_type == 0) {
return false; return false;
@ -3850,7 +3850,7 @@ bool Builder::GenerateArrayType(const sem::Array* arr, const Operand& result) {
} else { } else {
auto count = arr->ConstantCount(); auto count = arr->ConstantCount();
if (!count) { if (!count) {
error_ = sem::Array::kErrExpectedConstantCount; error_ = type::Array::kErrExpectedConstantCount;
return static_cast<uint32_t>(0); return static_cast<uint32_t>(0);
} }

View File

@ -480,7 +480,7 @@ class Builder {
/// @param ary the array to generate /// @param ary the array to generate
/// @param result the result operand /// @param result the result operand
/// @returns true if the array was successfully generated /// @returns true if the array was successfully generated
bool GenerateArrayType(const sem::Array* ary, const Operand& result); bool GenerateArrayType(const type::Array* ary, const Operand& result);
/// Generates a matrix type declaration /// Generates a matrix type declaration
/// @param mat the matrix to generate /// @param mat the matrix to generate
/// @param result the result operand /// @param result the result operand