Skip to content

Fix isorecursive canonicalization #5269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2676,11 +2676,8 @@ bool RecGroupEquator::topLevelEq(HeapType a, HeapType b) const {
}

bool RecGroupEquator::eq(Type a, Type b) const {
if (a == b) {
return true;
}
if (a.isBasic() || b.isBasic()) {
return false;
return a == b;
}
return eq(*getTypeInfo(a), *getTypeInfo(b));
}
Expand All @@ -2699,7 +2696,9 @@ bool RecGroupEquator::eq(HeapType a, HeapType b) const {
}
auto groupA = a.getRecGroup();
auto groupB = b.getRecGroup();
return groupA == groupB || (groupA == newGroup && groupB == otherGroup);
bool selfRefA = groupA == newGroup;
bool selfRefB = groupB == otherGroup;
return (selfRefA && selfRefB) || (!selfRefA && !selfRefB && groupA == groupB);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forgotten how this code works, sorry. Is newGroup a new group being built that is being compared to an existing group otherGroup? How can groupA/B not match those two, why would we be comparing types not from the groups at all, when comparing newGroup/otherGroup?

I couldn't find code comments explaining how the class RecGroupEquator is used - are they somewhere else than on the class itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forgotten how this code works, sorry. Is newGroup a new group being built that is being compared to an existing group otherGroup?

Yes, exactly.

How can groupA/B not match those two, why would we be comparing types not from the groups at all, when comparing newGroup/otherGroup?

Because we might be comparing heap types that are used in newGroup and otherGroup (e.g. because structs defined in those groups contain reference to the heap types), but are defined in some arbitrary different previous groups. We're trying to compare the "shapes" of newGroup and otherGroup, and how they reference other groups is part of that "shape."

I couldn't find code comments explaining how the class RecGroupEquator is used - are they somewhere else than on the class itself?

There are some additional comments on RecGroupStructure and RecGroupStore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

}

bool RecGroupEquator::eq(const TypeInfo& a, const TypeInfo& b) const {
Expand Down
2 changes: 1 addition & 1 deletion test/gtest/type-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ TEST_F(IsorecursiveTest, CanonicalizeUses) {
EXPECT_NE(built[4], built[6]);
}

TEST_F(IsorecursiveTest, DISABLED_CanonicalizeSelfReferences) {
TEST_F(IsorecursiveTest, CanonicalizeSelfReferences) {
TypeBuilder builder(5);
// Single self-reference
builder[0] = makeStruct(builder, {0});
Expand Down