File tree 3 files changed +37
-2
lines changed
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ void setTypeSystem(TypeSystem system);
45
45
46
46
TypeSystem getTypeSystem ();
47
47
48
+ // Dangerous! Frees all types and heap types that have ever been created and
49
+ // resets the type system's internal state. This is only really meant to be used
50
+ // for tests.
51
+ void destroyAllTypesForTestingPurposesOnly ();
52
+
48
53
// The types defined in this file. All of them are small and typically passed by
49
54
// value except for `Tuple` and `Struct`, which may own an unbounded amount of
50
55
// data.
Original file line number Diff line number Diff line change @@ -653,6 +653,11 @@ template<typename Info> struct Store {
653
653
}
654
654
bool hasCanonical (const Info& info, typename Info::type_t & canonical);
655
655
656
+ void clear () {
657
+ typeIDs.clear ();
658
+ constructedTypes.clear ();
659
+ }
660
+
656
661
private:
657
662
template <typename Ref> typename Info::type_t doInsert (Ref& infoRef) {
658
663
const Info& info = [&]() {
@@ -754,12 +759,20 @@ struct SignatureTypeCache {
754
759
std::lock_guard<std::mutex> lock (mutex);
755
760
cache.insert ({type.getSignature (), type});
756
761
}
762
+
763
+ void clear () { cache.clear (); }
757
764
};
758
765
759
766
static SignatureTypeCache nominalSignatureCache;
760
767
761
768
} // anonymous namespace
762
769
770
+ void destroyAllTypesForTestingPurposesOnly () {
771
+ globalTypeStore.clear ();
772
+ globalHeapTypeStore.clear ();
773
+ nominalSignatureCache.clear ();
774
+ }
775
+
763
776
Type::Type (std::initializer_list<Type> types) : Type(Tuple(types)) {}
764
777
765
778
Type::Type (const Tuple& tuple) {
Original file line number Diff line number Diff line change 3
3
4
4
using namespace wasm ;
5
5
6
+ // Helper test fixture for managing the global type system state.
7
+ template <TypeSystem system> class TypeSystemTest : public ::testing::Test {
8
+ TypeSystem originalSystem;
9
+
10
+ protected:
11
+ void SetUp () override {
12
+ originalSystem = getTypeSystem ();
13
+ setTypeSystem (system );
14
+ }
15
+ void TearDown () override {
16
+ destroyAllTypesForTestingPurposesOnly ();
17
+ setTypeSystem (originalSystem);
18
+ }
19
+ };
20
+ using EquirecursiveTest = TypeSystemTest<TypeSystem::Equirecursive>;
21
+ using NominalTest = TypeSystemTest<TypeSystem::Nominal>;
22
+ using IsorecursiveTest = TypeSystemTest<TypeSystem::Isorecursive>;
23
+
6
24
TEST (TypeBuilder, Growth) {
7
25
TypeBuilder builder;
8
26
EXPECT_EQ (builder.size (), size_t {0 });
9
27
builder.grow (3 );
10
28
EXPECT_EQ (builder.size (), size_t {3 });
11
29
}
12
30
13
- TEST (TypeBuilder , Basics) {
31
+ TEST_F (EquirecursiveTest , Basics) {
14
32
// (type $sig (func (param (ref $struct)) (result (ref $array) i32)))
15
33
// (type $struct (struct (field (ref null $array) (mut rtt 0 $array))))
16
34
// (type $array (array (mut externref)))
17
-
18
35
TypeBuilder builder (3 );
19
36
ASSERT_EQ (builder.size (), size_t {3 });
20
37
You can’t perform that action at this time.
0 commit comments