@@ -80,14 +80,22 @@ class PossibleContentsTest : public testing::Test {
8080 PossibleContents::literal (Literal::makeNull(HeapType::i31));
8181
8282 PossibleContents i32Global1 =
83- PossibleContents::global (" i32Global1" , Type::i32 );
83+ PossibleContents::global (" i32Global1" , ExternalKind::Global, Type::i32 );
8484 PossibleContents i32Global2 =
85- PossibleContents::global (" i32Global2" , Type::i32 );
86- PossibleContents f64Global = PossibleContents::global(" f64Global" , Type::f64 );
87- PossibleContents anyGlobal = PossibleContents::global(" anyGlobal" , anyref);
88- PossibleContents funcGlobal = PossibleContents::global(" funcGlobal" , funcref);
89- PossibleContents nonNullFuncGlobal =
90- PossibleContents::global (" funcGlobal" , Type(HeapType::func, NonNullable));
85+ PossibleContents::global (" i32Global2" , ExternalKind::Global, Type::i32 );
86+ PossibleContents f64Global =
87+ PossibleContents::global (" f64Global" , ExternalKind::Global, Type::f64 );
88+ PossibleContents anyGlobal =
89+ PossibleContents::global (" anyGlobal" , ExternalKind::Global, anyref);
90+ PossibleContents funcGlobal =
91+ PossibleContents::global (" funcGlobal" , ExternalKind::Global, funcref);
92+ PossibleContents nonNullFuncGlobal = PossibleContents::global(
93+ " funcGlobal" , ExternalKind::Global, Type(HeapType::func, NonNullable));
94+
95+ PossibleContents importedFunc1 = PossibleContents::global(
96+ " impfunc1" , ExternalKind::Function, Type(HeapType::func, NonNullable));
97+ PossibleContents importedFunc2 = PossibleContents::global(
98+ " impfunc2" , ExternalKind::Function, Type(HeapType::func, NonNullable));
9199
92100 PossibleContents nonNullFunc = PossibleContents::literal(
93101 Literal::makeFunc (" func" , Signature(Type::none, Type::none)));
@@ -114,6 +122,8 @@ class PossibleContentsTest : public testing::Test {
114122 PossibleContents coneAnyref = PossibleContents::coneType(anyref);
115123 PossibleContents coneFuncref = PossibleContents::coneType(funcref);
116124 PossibleContents coneFuncref1 = PossibleContents::coneType(funcref, 1 );
125+ PossibleContents coneNonNullFuncref =
126+ PossibleContents::coneType (Type(HeapType::func, NonNullable));
117127};
118128
119129TEST_F (PossibleContentsTest, TestComparisons) {
@@ -135,6 +145,9 @@ TEST_F(PossibleContentsTest, TestComparisons) {
135145 assertNotEqualSymmetric (i32Global1, exactI32);
136146 assertNotEqualSymmetric (i32Global1, many);
137147
148+ assertEqualSymmetric (importedFunc1, importedFunc1);
149+ assertNotEqualSymmetric (importedFunc1, importedFunc2);
150+
138151 assertEqualSymmetric (exactI32, exactI32);
139152 assertNotEqualSymmetric (exactI32, exactAnyref);
140153 assertNotEqualSymmetric (exactI32, many);
@@ -151,6 +164,23 @@ TEST_F(PossibleContentsTest, TestComparisons) {
151164 assertNotEqualSymmetric (exactNonNullAnyref, exactAnyref);
152165}
153166
167+ TEST_F (PossibleContentsTest, TestComparisonsGlobals) {
168+ // Check if two PossibleContents::global, one a wasm Global and one a wasm
169+ // Function, and equal in their names and types, are still understood to be
170+ // non-equal: the |kind| field differentiates them.
171+
172+ PossibleContents wasmGlobal = PossibleContents::global (
173+ " foo" , ExternalKind::Global, Type (HeapType::func, NonNullable));
174+ PossibleContents wasmFunction = PossibleContents::global (
175+ " foo" , ExternalKind::Function, Type (HeapType::func, NonNullable));
176+
177+ assertNotEqualSymmetric (wasmGlobal, wasmFunction);
178+
179+ // But they are equal to themselves, of course.
180+ assertEqualSymmetric (wasmGlobal, wasmGlobal);
181+ assertEqualSymmetric (wasmFunction, wasmFunction);
182+ }
183+
154184TEST_F (PossibleContentsTest, TestHash) {
155185 // Hashes should be deterministic.
156186 EXPECT_EQ (none.hash (), none.hash ());
@@ -257,6 +287,10 @@ TEST_F(PossibleContentsTest, TestCombinations) {
257287
258288 assertCombination (anyGlobal, anyNull, coneAnyref);
259289 assertCombination (anyGlobal, i31Null, coneAnyref);
290+
291+ // Imported functions.
292+ assertCombination (importedFunc1, importedFunc1, importedFunc1);
293+ assertCombination (importedFunc1, importedFunc2, coneNonNullFuncref);
260294}
261295
262296static PassOptions options;
@@ -338,6 +372,13 @@ TEST_F(PossibleContentsTest, TestIntersection) {
338372
339373 // Separate hierarchies.
340374 assertLackIntersection (funcGlobal, anyGlobal);
375+
376+ // Imported functions.
377+ assertHaveIntersection (importedFunc1, importedFunc1);
378+ assertHaveIntersection (importedFunc1, exactFuncSignatureType);
379+ assertHaveIntersection (importedFunc1, exactNonNullFuncSignatureType);
380+ assertHaveIntersection (importedFunc1, importedFunc2);
381+ assertHaveIntersection (importedFunc1, funcGlobal);
341382}
342383
343384TEST_F (PossibleContentsTest, TestIntersectWithCombinations) {
@@ -484,6 +525,8 @@ TEST_F(PossibleContentsTest, TestIntersectWithCombinations) {
484525 funcGlobal,
485526 nonNullFuncGlobal,
486527 nonNullFunc,
528+ importedFunc1,
529+ importedFunc2,
487530 exactI32,
488531 exactAnyref,
489532 exactFuncref,
@@ -785,9 +828,10 @@ TEST_F(PossibleContentsTest, TestStructCones) {
785828 nonNullFunc, PossibleContents::coneType (signature), nonNullFunc);
786829
787830 // Filter a global to a more specific type.
788- assertIntersection (funcGlobal,
789- PossibleContents::coneType (signature),
790- PossibleContents::global (" funcGlobal" , signature));
831+ assertIntersection (
832+ funcGlobal,
833+ PossibleContents::coneType (signature),
834+ PossibleContents::global (" funcGlobal" , ExternalKind::Global, signature));
791835
792836 // Filter a global's nullability only.
793837 auto nonNullFuncRef = Type (HeapType::func, NonNullable);
@@ -814,6 +858,13 @@ TEST_F(PossibleContentsTest, TestStructCones) {
814858 assertIntersection (funcGlobal, none, none);
815859 assertIntersection (PossibleContents::coneType (signature), none, none);
816860
861+ // Imported functions. TODO: These are not yet supported, and assert instead.
862+ // assertIntersection(
863+ // importedFunc1, importedFunc1, importedFunc1);
864+ // assertIntersection(
865+ // importedFunc1, PossibleContents::coneType(nonNullFuncRef),
866+ // importedFunc1);
867+
817868 // Subcontents. This API only supports the case where one of the inputs is a
818869 // full cone type.
819870 // First, compare exact types to such a cone.
0 commit comments