diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index ff235622d3..81495f70d6 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -497,7 +497,7 @@ class ProgramBuilder { /// @returns the de-aliased array count pointer template traits::EnableIf || - traits::IsTypeOrDerived, + traits::IsTypeOrDerived, T>* create(ARGS&&... args) { AssertNotMoved(); diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index 8b020e2e98..da73215ae2 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -416,7 +416,7 @@ struct Composite : ImplConstant { utils::Vector conv_els; conv_els.Reserve(elements.Length()); std::function target_el_ty; - if (auto* str = target_ty->As()) { + if (auto* str = target_ty->As()) { if (str->Members().Length() != elements.Length()) { TINT_ICE(Resolver, builder.Diagnostics()) << "const-eval conversion of structure has mismatched element counts"; @@ -494,7 +494,7 @@ const ImplConstant* ZeroValue(ProgramBuilder& builder, const type::Type* type) { } return nullptr; }, - [&](const type::StructBase* s) -> const ImplConstant* { + [&](const type::Struct* s) -> const ImplConstant* { utils::Hashmap zero_by_type; utils::Vector zeros; zeros.Reserve(s->Members().Length()); @@ -1449,7 +1449,7 @@ ConstEval::Result ConstEval::Index(const sem::Expression* obj_expr, } ConstEval::Result ConstEval::MemberAccess(const sem::Expression* obj_expr, - const type::StructMemberBase* member) { + const type::StructMember* member) { auto obj_val = obj_expr->ConstantValue(); if (!obj_val) { return nullptr; diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h index f3d51b6465..fa5c0eef2d 100644 --- a/src/tint/resolver/const_eval.h +++ b/src/tint/resolver/const_eval.h @@ -35,7 +35,7 @@ class Constant; class Expression; } // namespace tint::sem namespace tint::type { -class StructMemberBase; +class StructMember; } // namespace tint::type namespace tint::resolver { @@ -94,7 +94,7 @@ class ConstEval { /// @param obj the object being accessed /// @param member the member /// @return the result of the member access, or null if the value cannot be calculated - Result MemberAccess(const sem::Expression* obj, const type::StructMemberBase* member); + Result MemberAccess(const sem::Expression* obj, const type::StructMember* member); /// @param ty the result type /// @param vector the vector being swizzled diff --git a/src/tint/sem/struct.h b/src/tint/sem/struct.h index ac535ece30..a05a96afd5 100644 --- a/src/tint/sem/struct.h +++ b/src/tint/sem/struct.h @@ -32,13 +32,13 @@ namespace tint::sem { class StructMember; } // namespace tint::sem namespace tint::type { -class StructMemberBase; +class StructMember; } // namespace tint::type namespace tint::sem { /// Struct holds the semantic information for structures. -class Struct final : public Castable { +class Struct final : public Castable { public: /// Constructor /// @param declaration the AST structure declaration @@ -73,7 +73,7 @@ class Struct final : public Castable { }; /// StructMember holds the semantic information for structure members. -class StructMember final : public Castable { +class StructMember final : public Castable { public: /// Constructor /// @param declaration the AST declaration node diff --git a/src/tint/transform/promote_initializers_to_let.cc b/src/tint/transform/promote_initializers_to_let.cc index 3b1ea7fdf7..391a7f2bc6 100644 --- a/src/tint/transform/promote_initializers_to_let.cc +++ b/src/tint/transform/promote_initializers_to_let.cc @@ -42,7 +42,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src, // Returns true if the expression should be hoisted to a new let statement before the // expression's statement. auto should_hoist = [&](const sem::Expression* expr) { - if (!expr->Type()->IsAnyOf()) { + if (!expr->Type()->IsAnyOf()) { // We only care about array and struct initializers return false; } diff --git a/src/tint/type/manager.h b/src/tint/type/manager.h index 2e587c332a..0515b1432a 100644 --- a/src/tint/type/manager.h +++ b/src/tint/type/manager.h @@ -91,7 +91,7 @@ class Manager final { /// pointer is returned. template || - traits::IsTypeOrDerived>, + traits::IsTypeOrDerived>, typename... ARGS> TYPE* GetNode(ARGS&&... args) { return nodes_.Get(std::forward(args)...); @@ -119,8 +119,8 @@ struct hash { size_t operator()(const tint::type::Node& type) const { if (const auto* ac = type.As()) { return ac->Hash(); - } else if (type.Is()) { - return tint::TypeInfo::Of().full_hashcode; + } else if (type.Is()) { + return tint::TypeInfo::Of().full_hashcode; } TINT_ASSERT(Type, false && "Unreachable"); return 0; @@ -139,7 +139,7 @@ struct equal_to { return ac->Equals(*bc); } return false; - } else if (a.Is()) { + } else if (a.Is()) { return &a == &b; } TINT_ASSERT(Type, false && "Unreachable"); diff --git a/src/tint/type/struct.cc b/src/tint/type/struct.cc index a72aa0f4c7..e7b220d523 100644 --- a/src/tint/type/struct.cc +++ b/src/tint/type/struct.cc @@ -22,13 +22,13 @@ #include "src/tint/symbol_table.h" #include "src/tint/utils/hash.h" -TINT_INSTANTIATE_TYPEINFO(tint::type::StructBase); -TINT_INSTANTIATE_TYPEINFO(tint::type::StructMemberBase); +TINT_INSTANTIATE_TYPEINFO(tint::type::Struct); +TINT_INSTANTIATE_TYPEINFO(tint::type::StructMember); namespace tint::type { namespace { -TypeFlags FlagsFrom(utils::VectorRef members) { +TypeFlags FlagsFrom(utils::VectorRef members) { TypeFlags flags{ TypeFlag::kConstructable, TypeFlag::kCreationFixedFootprint, @@ -50,12 +50,12 @@ TypeFlags FlagsFrom(utils::VectorRef members) { } // namespace -StructBase::StructBase(tint::Source source, - Symbol name, - utils::VectorRef members, - uint32_t align, - uint32_t size, - uint32_t size_no_padding) +Struct::Struct(tint::Source source, + Symbol name, + utils::VectorRef members, + uint32_t align, + uint32_t size, + uint32_t size_no_padding) : Base(FlagsFrom(members)), source_(source), name_(name), @@ -64,20 +64,20 @@ StructBase::StructBase(tint::Source source, size_(size), size_no_padding_(size_no_padding) {} -StructBase::~StructBase() = default; +Struct::~Struct() = default; -size_t StructBase::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, name_); +size_t Struct::Hash() const { + return utils::Hash(TypeInfo::Of().full_hashcode, name_); } -bool StructBase::Equals(const Type& other) const { - if (auto* o = other.As()) { +bool Struct::Equals(const Type& other) const { + if (auto* o = other.As()) { return o->name_ == name_; } return false; } -const StructMemberBase* StructBase::FindMember(Symbol name) const { +const StructMember* Struct::FindMember(Symbol name) const { for (auto* member : members_) { if (member->Name() == name) { return member; @@ -86,22 +86,22 @@ const StructMemberBase* StructBase::FindMember(Symbol name) const { return nullptr; } -uint32_t StructBase::Align() const { +uint32_t Struct::Align() const { return align_; } -uint32_t StructBase::Size() const { +uint32_t Struct::Size() const { return size_; } -std::string StructBase::FriendlyName(const SymbolTable& symbols) const { +std::string Struct::FriendlyName(const SymbolTable& symbols) const { return symbols.NameFor(name_); } -std::string StructBase::Layout(const tint::SymbolTable& symbols) const { +std::string Struct::Layout(const tint::SymbolTable& symbols) const { std::stringstream ss; - auto member_name_of = [&](const StructMemberBase* sm) { return symbols.NameFor(sm->Name()); }; + auto member_name_of = [&](const StructMember* sm) { return symbols.NameFor(sm->Name()); }; if (Members().IsEmpty()) { return {}; @@ -164,14 +164,14 @@ std::string StructBase::Layout(const tint::SymbolTable& symbols) const { return ss.str(); } -StructMemberBase::StructMemberBase(tint::Source source, - Symbol name, - const type::Type* type, - uint32_t index, - uint32_t offset, - uint32_t align, - uint32_t size, - std::optional location) +StructMember::StructMember(tint::Source source, + Symbol name, + const type::Type* type, + uint32_t index, + uint32_t offset, + uint32_t align, + uint32_t size, + std::optional location) : source_(source), name_(name), type_(type), @@ -181,6 +181,6 @@ StructMemberBase::StructMemberBase(tint::Source source, size_(size), location_(location) {} -StructMemberBase::~StructMemberBase() = default; +StructMember::~StructMember() = default; } // namespace tint::type diff --git a/src/tint/type/struct.h b/src/tint/type/struct.h index b9daec9a0c..89467141d5 100644 --- a/src/tint/type/struct.h +++ b/src/tint/type/struct.h @@ -29,7 +29,7 @@ // Forward declarations namespace tint::type { -class StructMemberBase; +class StructMember; } // namespace tint::type namespace tint::type { @@ -44,8 +44,8 @@ enum class PipelineStageUsage { kComputeOutput, }; -/// StructBase holds the Type information for structures. -class StructBase : public Castable { +/// Struct holds the Type information for structures. +class Struct : public Castable { public: /// Constructor /// @param source the source of the structure @@ -55,15 +55,15 @@ class StructBase : public Castable { /// @param size the byte size of the structure /// @param size_no_padding size of the members without the end of structure /// alignment padding - StructBase(tint::Source source, - Symbol name, - utils::VectorRef members, - uint32_t align, - uint32_t size, - uint32_t size_no_padding); + Struct(tint::Source source, + Symbol name, + utils::VectorRef members, + uint32_t align, + uint32_t size, + uint32_t size_no_padding); /// Destructor - ~StructBase() override; + ~Struct() override; /// @returns a hash of the type. size_t Hash() const override; @@ -79,11 +79,11 @@ class StructBase : public Castable { Symbol Name() const { return name_; } /// @returns the members of the structure - utils::VectorRef Members() const { return members_; } + utils::VectorRef Members() const { return members_; } /// @param name the member name to look for /// @returns the member with the given name, or nullptr if it was not found. - const StructMemberBase* FindMember(Symbol name) const; + const StructMember* FindMember(Symbol name) const; /// @returns the byte alignment of the structure /// @note this may differ from the alignment of a structure member of this @@ -145,29 +145,27 @@ class StructBase : public Castable { std::string Layout(const tint::SymbolTable& symbols) const; /// @param concrete the conversion-rank ordered concrete versions of this abstract structure. - void SetConcreteTypes(utils::VectorRef concrete) { - concrete_types_ = concrete; - } + void SetConcreteTypes(utils::VectorRef concrete) { concrete_types_ = concrete; } /// @returns the conversion-rank ordered concrete versions of this abstract structure, or an /// empty vector if this structure is not abstract. /// @note only structures returned by builtins may be abstract (e.g. modf, frexp) - utils::VectorRef ConcreteTypes() const { return concrete_types_; } + utils::VectorRef ConcreteTypes() const { return concrete_types_; } private: const tint::Source source_; const Symbol name_; - const utils::Vector members_; + const utils::Vector members_; const uint32_t align_; const uint32_t size_; const uint32_t size_no_padding_; std::unordered_set address_space_usage_; std::unordered_set pipeline_stage_uses_; - utils::Vector concrete_types_; + utils::Vector concrete_types_; }; -/// StructMemberBase holds the type information for structure members. -class StructMemberBase : public Castable { +/// StructMember holds the type information for structure members. +class StructMember : public Castable { public: /// Constructor /// @param source the source of the struct member @@ -178,17 +176,17 @@ class StructMemberBase : public Castable { /// @param align the byte alignment of the member /// @param size the byte size of the member /// @param location the location attribute, if present - StructMemberBase(tint::Source source, - Symbol name, - const type::Type* type, - uint32_t index, - uint32_t offset, - uint32_t align, - uint32_t size, - std::optional location); + StructMember(tint::Source source, + Symbol name, + const type::Type* type, + uint32_t index, + uint32_t offset, + uint32_t align, + uint32_t size, + std::optional location); /// Destructor - ~StructMemberBase() override; + ~StructMember() override; /// @returns the source the struct member const tint::Source& Source() const { return source_; } @@ -198,10 +196,10 @@ class StructMemberBase : public Castable { /// Sets the owning structure to `s` /// @param s the new structure owner - void SetStruct(const StructBase* s) { struct_ = s; } + void SetStruct(const Struct* s) { struct_ = s; } /// @returns the structure that owns this member - const StructBase* Struct() const { return struct_; } + const type::Struct* Struct() const { return struct_; } /// @returns the type of the member const type::Type* Type() const { return type_; } @@ -224,7 +222,7 @@ class StructMemberBase : public Castable { private: const tint::Source source_; const Symbol name_; - const StructBase* struct_; + const type::Struct* struct_; const type::Type* type_; const uint32_t index_; const uint32_t offset_; diff --git a/src/tint/type/struct_test.cc b/src/tint/type/struct_test.cc index 55e1517c1a..ae9a249594 100644 --- a/src/tint/type/struct_test.cc +++ b/src/tint/type/struct_test.cc @@ -24,27 +24,27 @@ using TypeStructTest = TestHelper; TEST_F(TypeStructTest, Creation) { auto name = Sym("S"); - auto* s = create(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */, - 16u /* size_no_padding */); + auto* s = create(Source{}, name, utils::Empty, 4u /* align */, 8u /* size */, + 16u /* size_no_padding */); EXPECT_EQ(s->Align(), 4u); EXPECT_EQ(s->Size(), 8u); EXPECT_EQ(s->SizeNoPadding(), 16u); } TEST_F(TypeStructTest, Hash) { - auto* a = create(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */, - 4u /* size_no_padding */); - auto* b = create(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */, - 4u /* size_no_padding */); + auto* a = create(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */, + 4u /* size_no_padding */); + auto* b = create(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */, + 4u /* size_no_padding */); EXPECT_NE(a->Hash(), b->Hash()); } TEST_F(TypeStructTest, Equals) { - auto* a = create(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */, - 4u /* size_no_padding */); - auto* b = create(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */, - 4u /* size_no_padding */); + auto* a = create(Source{}, Sym("a"), utils::Empty, 4u /* align */, 4u /* size */, + 4u /* size_no_padding */); + auto* b = create(Source{}, Sym("b"), utils::Empty, 4u /* align */, 4u /* size */, + 4u /* size_no_padding */); EXPECT_TRUE(a->Equals(*a)); EXPECT_FALSE(a->Equals(*b)); @@ -53,8 +53,8 @@ TEST_F(TypeStructTest, Equals) { TEST_F(TypeStructTest, FriendlyName) { auto name = Sym("my_struct"); - auto* s = create(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */, - 4u /* size_no_padding */); + auto* s = create(Source{}, name, utils::Empty, 4u /* align */, 4u /* size */, + 4u /* size_no_padding */); EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct"); } diff --git a/src/tint/type/type.cc b/src/tint/type/type.cc index 1eead356f5..7241782493 100644 --- a/src/tint/type/type.cc +++ b/src/tint/type/type.cc @@ -180,7 +180,7 @@ bool Type::HoldsAbstract() const { [&](const Vector* v) { return v->type()->HoldsAbstract(); }, [&](const Matrix* m) { return m->type()->HoldsAbstract(); }, [&](const Array* a) { return a->ElemType()->HoldsAbstract(); }, - [&](const StructBase* s) { + [&](const Struct* s) { for (auto* m : s->Members()) { if (m->Type()->HoldsAbstract()) { return true; @@ -238,7 +238,7 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) { } return kNoConversion; }, - [&](const StructBase* from_str) { + [&](const Struct* from_str) { auto concrete_tys = from_str->ConcreteTypes(); for (size_t i = 0; i < concrete_tys.Length(); i++) { if (concrete_tys[i] == to) { diff --git a/src/tint/type/type_test.cc b/src/tint/type/type_test.cc index 133f52129f..48b44dd7c0 100644 --- a/src/tint/type/type_test.cc +++ b/src/tint/type/type_test.cc @@ -45,54 +45,54 @@ struct TypeTest : public TestHelper { const Matrix* mat4x3_af = create(vec3_af, 4u); const Reference* ref_u32 = create(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite); - const StructBase* str_f32 = create(Source{}, - Sym("str_f32"), - utils::Vector{ - create( - /* source */ Source{}, - /* name */ Sym("x"), - /* type */ f32, - /* index */ 0u, - /* offset */ 0u, - /* align */ 4u, - /* size */ 4u, - /* location */ std::nullopt), - }, - /* align*/ 4u, - /* size*/ 4u, - /* size_no_padding*/ 4u); - const StructBase* str_f16 = create(Source{}, - Sym("str_f16"), - utils::Vector{ - create( - /* source */ Source{}, - /* name */ Sym("x"), - /* type */ f16, - /* index */ 0u, - /* offset */ 0u, - /* align */ 4u, - /* size */ 4u, - /* location */ std::nullopt), - }, - /* align*/ 4u, - /* size*/ 4u, - /* size_no_padding*/ 4u); - StructBase* str_af = create(Source{}, - Sym("str_af"), - utils::Vector{ - create( - /* source */ Source{}, - /* name */ Sym("x"), - /* type */ af, - /* index */ 0u, - /* offset */ 0u, - /* align */ 4u, - /* size */ 4u, - /* location */ std::nullopt), - }, - /* align*/ 4u, - /* size*/ 4u, - /* size_no_padding*/ 4u); + const Struct* str_f32 = create(Source{}, + Sym("str_f32"), + utils::Vector{ + create( + /* source */ Source{}, + /* name */ Sym("x"), + /* type */ f32, + /* index */ 0u, + /* offset */ 0u, + /* align */ 4u, + /* size */ 4u, + /* location */ std::nullopt), + }, + /* align*/ 4u, + /* size*/ 4u, + /* size_no_padding*/ 4u); + const Struct* str_f16 = create(Source{}, + Sym("str_f16"), + utils::Vector{ + create( + /* source */ Source{}, + /* name */ Sym("x"), + /* type */ f16, + /* index */ 0u, + /* offset */ 0u, + /* align */ 4u, + /* size */ 4u, + /* location */ std::nullopt), + }, + /* align*/ 4u, + /* size*/ 4u, + /* size_no_padding*/ 4u); + Struct* str_af = create(Source{}, + Sym("str_af"), + utils::Vector{ + create( + /* source */ Source{}, + /* name */ Sym("x"), + /* type */ af, + /* index */ 0u, + /* offset */ 0u, + /* align */ 4u, + /* size */ 4u, + /* location */ std::nullopt), + }, + /* align*/ 4u, + /* size*/ 4u, + /* size_no_padding*/ 4u); const Array* arr_i32 = create( /* element */ i32, /* count */ create(5u),