diff options
author | Alon Zakai <azakai@google.com> | 2022-09-26 13:49:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 20:49:50 +0000 |
commit | b23b47d54a2fb02b048e7eb8de8043358599ec8b (patch) | |
tree | a0df6c52cae239318893b069172674145903598f /test/gtest/possible-contents.cpp | |
parent | b40fa4a885f219d8f317f125880aa0ee9f46b62f (diff) | |
download | binaryen-b23b47d54a2fb02b048e7eb8de8043358599ec8b.tar.gz binaryen-b23b47d54a2fb02b048e7eb8de8043358599ec8b.tar.bz2 binaryen-b23b47d54a2fb02b048e7eb8de8043358599ec8b.zip |
[GUFA] Infer a RefEq value of 0 when possible (#5081)
If the PossibleContents for the two sides have no possible intersection then the
result must be 0.
Diffstat (limited to 'test/gtest/possible-contents.cpp')
-rw-r--r-- | test/gtest/possible-contents.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/gtest/possible-contents.cpp b/test/gtest/possible-contents.cpp index 27ab5b8fb..1e1f0e5c9 100644 --- a/test/gtest/possible-contents.cpp +++ b/test/gtest/possible-contents.cpp @@ -85,6 +85,9 @@ protected: PossibleContents::global("i32Global2", Type::i32); PossibleContents f64Global = PossibleContents::global("f64Global", Type::f64); PossibleContents anyGlobal = PossibleContents::global("anyGlobal", anyref); + PossibleContents funcGlobal = PossibleContents::global("funcGlobal", funcref); + PossibleContents nonNullFuncGlobal = + PossibleContents::global("funcGlobal", Type(HeapType::func, NonNullable)); PossibleContents nonNullFunc = PossibleContents::literal( Literal("func", Signature(Type::none, Type::none))); @@ -242,6 +245,53 @@ TEST_F(PossibleContentsTest, TestOracleMinimal) { Literal(int32_t(42))); } +// Asserts a and b have an intersection (or do not), and checks both orderings. +void assertHaveIntersection(PossibleContents a, PossibleContents b) { + EXPECT_TRUE(PossibleContents::haveIntersection(a, b)); + EXPECT_TRUE(PossibleContents::haveIntersection(b, a)); +} +void assertLackIntersection(PossibleContents a, PossibleContents b) { + EXPECT_FALSE(PossibleContents::haveIntersection(a, b)); + EXPECT_FALSE(PossibleContents::haveIntersection(b, a)); +} + +TEST_F(PossibleContentsTest, TestIntersection) { + // None has no contents, so nothing to intersect. + assertLackIntersection(none, none); + assertLackIntersection(none, i32Zero); + assertLackIntersection(none, many); + + // Many intersects with anything (but none). + assertHaveIntersection(many, many); + assertHaveIntersection(many, i32Zero); + + // Different exact types cannot intersect. + assertLackIntersection(exactI32, exactAnyref); + assertLackIntersection(i32Zero, exactAnyref); + + // But nullable ones can - the null can be the intersection. + assertHaveIntersection(exactFuncSignatureType, exactAnyref); + assertHaveIntersection(exactFuncSignatureType, funcNull); + assertHaveIntersection(anyNull, funcNull); + + // Identical types might. + assertHaveIntersection(exactI32, exactI32); + assertHaveIntersection(i32Zero, i32Zero); + assertHaveIntersection(exactFuncSignatureType, exactFuncSignatureType); + assertHaveIntersection(i32Zero, i32One); // TODO: this could be inferred false + + // Due to subtyping, an intersection might exist. + assertHaveIntersection(funcGlobal, funcGlobal); + assertHaveIntersection(funcGlobal, exactFuncSignatureType); + + // Neither is a subtype of the other, but nulls are possible, so a null can be + // the intersection. + assertHaveIntersection(funcGlobal, anyGlobal); + + // Without null on one side, we cannot intersect. + assertLackIntersection(nonNullFuncGlobal, anyGlobal); +} + TEST_F(PossibleContentsTest, TestOracleManyTypes) { // Test for a node with many possible types. The pass limits how many it // notices to not use excessive memory, so even though 4 are possible here, |