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 <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2022-07-29 14:32:51 +00:00 committed by Dawn LUCI CQ
parent 8e0368e554
commit 6fb5d379c2
5 changed files with 12 additions and 11 deletions

View File

@ -361,7 +361,7 @@ const Constant* ZeroValue(ProgramBuilder& builder, const sem::Type* type) {
return nullptr; return nullptr;
}, },
[&](const sem::Struct* s) -> const Constant* { [&](const sem::Struct* s) -> const Constant* {
std::unordered_map<sem::Type*, const Constant*> zero_by_type; std::unordered_map<const sem::Type*, const Constant*> zero_by_type;
utils::Vector<const sem::Constant*, 4> zeros; utils::Vector<const sem::Constant*, 4> zeros;
zeros.Reserve(s->Members().size()); zeros.Reserve(s->Members().size());
for (auto* member : s->Members()) { for (auto* member : s->Members()) {

View File

@ -2803,7 +2803,7 @@ bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc,
str->AddUsage(sc); str->AddUsage(sc);
for (auto* member : str->Members()) { for (auto* member : str->Members()) {
if (!ApplyStorageClassUsageToType(sc, member->Type(), usage)) { if (!ApplyStorageClassUsageToType(sc, const_cast<sem::Type*>(member->Type()), usage)) {
std::stringstream err; std::stringstream err;
err << "while analysing structure member " << sem_.TypeNameOf(str) << "." err << "while analysing structure member " << sem_.TypeNameOf(str) << "."
<< builder_->Symbols().NameFor(member->Declaration()->symbol); << builder_->Symbols().NameFor(member->Declaration()->symbol);

View File

@ -157,7 +157,7 @@ bool Struct::IsConstructible() const {
StructMember::StructMember(const ast::StructMember* declaration, StructMember::StructMember(const ast::StructMember* declaration,
Symbol name, Symbol name,
sem::Type* type, const sem::Type* type,
uint32_t index, uint32_t index,
uint32_t offset, uint32_t offset,
uint32_t align, uint32_t align,

View File

@ -182,7 +182,7 @@ class StructMember final : public Castable<StructMember, Node> {
/// @param size the byte size of the member /// @param size the byte size of the member
StructMember(const ast::StructMember* declaration, StructMember(const ast::StructMember* declaration,
Symbol name, Symbol name,
sem::Type* type, const sem::Type* type,
uint32_t index, uint32_t index,
uint32_t offset, uint32_t offset,
uint32_t align, uint32_t align,
@ -205,7 +205,7 @@ class StructMember final : public Castable<StructMember, Node> {
const sem::Struct* Struct() const { return struct_; } const sem::Struct* Struct() const { return struct_; }
/// @returns the type of the member /// @returns the type of the member
sem::Type* Type() const { return type_; } const sem::Type* Type() const { return type_; }
/// @returns the member index /// @returns the member index
uint32_t Index() const { return index_; } uint32_t Index() const { return index_; }
@ -223,7 +223,7 @@ class StructMember final : public Castable<StructMember, Node> {
const ast::StructMember* const declaration_; const ast::StructMember* const declaration_;
const Symbol name_; const Symbol name_;
const sem::Struct* struct_; const sem::Struct* struct_;
sem::Type* const type_; const sem::Type* type_;
const uint32_t index_; const uint32_t index_;
const uint32_t offset_; const uint32_t offset_;
const uint32_t align_; const uint32_t align_;

View File

@ -105,7 +105,8 @@ DecomposeStridedMatrix::~DecomposeStridedMatrix() = default;
bool DecomposeStridedMatrix::ShouldRun(const Program* program, const DataMap&) const { bool DecomposeStridedMatrix::ShouldRun(const Program* program, const DataMap&) const {
bool should_run = false; bool should_run = false;
GatherCustomStrideMatrixMembers(program, [&](const sem::StructMember*, sem::Matrix*, uint32_t) { GatherCustomStrideMatrixMembers(program,
[&](const sem::StructMember*, const sem::Matrix*, uint32_t) {
should_run = true; should_run = true;
return GatherResult::kStop; return GatherResult::kStop;
}); });
@ -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. // and populate the `decomposed` map with the members that have been replaced.
std::unordered_map<const ast::StructMember*, MatrixInfo> decomposed; std::unordered_map<const ast::StructMember*, MatrixInfo> decomposed;
GatherCustomStrideMatrixMembers( 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 // We've got ourselves a struct member of a matrix type with a custom
// stride. Replace this with an array of column vectors. // stride. Replace this with an array of column vectors.
MatrixInfo info{stride, matrix}; MatrixInfo info{stride, matrix};