From 6fb5d379c2fd5f7415e793056b22d09a9626870a Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 29 Jul 2022 14:32:51 +0000 Subject: [PATCH] tint/sem: Add const to StructMember 'type'. This should be immutable once the sem tree is built. Add a hacky const_cast in Resolver for now, as this is preferable to having some things non-const in sem. Bug: tint:745 Change-Id: I67ebce76730347c9543875ab8e1c21a47d71fd56 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97584 Reviewed-by: Dan Sinclair Commit-Queue: Ben Clayton Kokoro: Kokoro --- src/tint/resolver/const_eval.cc | 2 +- src/tint/resolver/resolver.cc | 2 +- src/tint/sem/struct.cc | 2 +- src/tint/sem/struct.h | 6 +++--- src/tint/transform/decompose_strided_matrix.cc | 11 ++++++----- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index 3b5af60e6d..ba70b33068 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -361,7 +361,7 @@ const Constant* ZeroValue(ProgramBuilder& builder, const sem::Type* type) { return nullptr; }, [&](const sem::Struct* s) -> const Constant* { - std::unordered_map zero_by_type; + std::unordered_map zero_by_type; utils::Vector zeros; zeros.Reserve(s->Members().size()); for (auto* member : s->Members()) { diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index fa278dae79..b1961c3129 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -2803,7 +2803,7 @@ bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc, str->AddUsage(sc); for (auto* member : str->Members()) { - if (!ApplyStorageClassUsageToType(sc, member->Type(), usage)) { + if (!ApplyStorageClassUsageToType(sc, const_cast(member->Type()), usage)) { std::stringstream err; err << "while analysing structure member " << sem_.TypeNameOf(str) << "." << builder_->Symbols().NameFor(member->Declaration()->symbol); diff --git a/src/tint/sem/struct.cc b/src/tint/sem/struct.cc index eb0583b03b..0ace9db55f 100644 --- a/src/tint/sem/struct.cc +++ b/src/tint/sem/struct.cc @@ -157,7 +157,7 @@ bool Struct::IsConstructible() const { StructMember::StructMember(const ast::StructMember* declaration, Symbol name, - sem::Type* type, + const sem::Type* type, uint32_t index, uint32_t offset, uint32_t align, diff --git a/src/tint/sem/struct.h b/src/tint/sem/struct.h index 5ee93e5491..62b1008ce3 100644 --- a/src/tint/sem/struct.h +++ b/src/tint/sem/struct.h @@ -182,7 +182,7 @@ class StructMember final : public Castable { /// @param size the byte size of the member StructMember(const ast::StructMember* declaration, Symbol name, - sem::Type* type, + const sem::Type* type, uint32_t index, uint32_t offset, uint32_t align, @@ -205,7 +205,7 @@ class StructMember final : public Castable { const sem::Struct* Struct() const { return struct_; } /// @returns the type of the member - sem::Type* Type() const { return type_; } + const sem::Type* Type() const { return type_; } /// @returns the member index uint32_t Index() const { return index_; } @@ -223,7 +223,7 @@ class StructMember final : public Castable { const ast::StructMember* const declaration_; const Symbol name_; const sem::Struct* struct_; - sem::Type* const type_; + const sem::Type* type_; const uint32_t index_; const uint32_t offset_; const uint32_t align_; diff --git a/src/tint/transform/decompose_strided_matrix.cc b/src/tint/transform/decompose_strided_matrix.cc index 4f9d6c8db9..3d474ed110 100644 --- a/src/tint/transform/decompose_strided_matrix.cc +++ b/src/tint/transform/decompose_strided_matrix.cc @@ -105,10 +105,11 @@ DecomposeStridedMatrix::~DecomposeStridedMatrix() = default; bool DecomposeStridedMatrix::ShouldRun(const Program* program, const DataMap&) const { bool should_run = false; - GatherCustomStrideMatrixMembers(program, [&](const sem::StructMember*, sem::Matrix*, uint32_t) { - should_run = true; - return GatherResult::kStop; - }); + GatherCustomStrideMatrixMembers(program, + [&](const sem::StructMember*, const sem::Matrix*, uint32_t) { + should_run = true; + return GatherResult::kStop; + }); return should_run; } @@ -118,7 +119,7 @@ void DecomposeStridedMatrix::Run(CloneContext& ctx, const DataMap&, DataMap&) co // and populate the `decomposed` map with the members that have been replaced. std::unordered_map decomposed; GatherCustomStrideMatrixMembers( - ctx.src, [&](const sem::StructMember* member, sem::Matrix* matrix, uint32_t stride) { + ctx.src, [&](const sem::StructMember* member, const sem::Matrix* matrix, uint32_t stride) { // We've got ourselves a struct member of a matrix type with a custom // stride. Replace this with an array of column vectors. MatrixInfo info{stride, matrix};