tint/resolver: Fix const-eval Equal()

It was not considering structures, and the default clause was happily assuming two std::monostates (no-value) were equal.
This lead to non-deterministic behaviour as the Hash() would sometimes match and sometimes not.

Change-Id: Idf01a9e0e4ac09d5eaf683b62fcadd1714dc5849
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113981
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-12-13 14:56:25 +00:00 committed by Dawn LUCI CQ
parent 61dbeb5b72
commit e3f3de773a
1 changed files with 16 additions and 1 deletions

View File

@ -560,7 +560,22 @@ bool Equal(const constant::Constant* a, const constant::Constant* b) {
return false; return false;
}, },
[&](Default) { return a->Value() == b->Value(); }); [&](const type::Struct* str) {
auto count = str->Members().Length();
for (size_t i = 0; i < count; i++) {
if (!Equal(a->Index(i), b->Index(i))) {
return false;
}
}
return true;
},
[&](Default) {
auto va = a->Value();
auto vb = b->Value();
TINT_ASSERT(Resolver, !std::holds_alternative<std::monostate>(va));
TINT_ASSERT(Resolver, !std::holds_alternative<std::monostate>(vb));
return va == vb;
});
} }
/// CreateComposite is used to construct a constant of a vector, matrix or array type. /// CreateComposite is used to construct a constant of a vector, matrix or array type.