diff --git a/oi/OICodeGen.cpp b/oi/OICodeGen.cpp index c6bad38..d7653b2 100644 --- a/oi/OICodeGen.cpp +++ b/oi/OICodeGen.cpp @@ -62,32 +62,6 @@ std::unique_ptr OICodeGen::buildFromConfig(const Config& c, OICodeGen::OICodeGen(const Config& c, SymbolService& s) : config{c}, symbols{s} { - // TODO: Should folly::Range just be added as a container? - auto typesToStub = std::array{ - "SharedMutex", - "EnumMap", - "function", - "Function", - "ConcurrentHashMap", - "DelayedDestruction", - "McServerSession", - "Range", - "ReadResumableHandle", - "CountedIntrusiveList", - "EventBaseAtomicNotificationQueue", - /* Temporary IOBuf ring used for scattered read/write. - * It's only used for communication and should be empty the rest of the - * time. So we shouldn't loose too much visibility by stubbing it out. - */ - "IOBufIovecBuilder", - /* struct event from libevent - * Its linked lists are not always initialised, leading to SegV in our JIT - * code. We can't stub the linked list themselves, as they're anonymous - * structs. - */ - "event", - }; - membersToStub = config.membersToStub; for (const auto& type : typesToStub) { membersToStub.emplace_back(type, "*"); diff --git a/oi/OICodeGen.h b/oi/OICodeGen.h index d0d9133..01cfcb6 100644 --- a/oi/OICodeGen.h +++ b/oi/OICodeGen.h @@ -69,6 +69,32 @@ class OICodeGen { std::vector toOptions() const; }; + // TODO: Should folly::Range just be added as a container? + static constexpr auto typesToStub = std::array{ + "SharedMutex", + "EnumMap", + "function", + "Function", + "ConcurrentHashMap", + "DelayedDestruction", + "McServerSession", + "Range", + "ReadResumableHandle", + "CountedIntrusiveList", + "EventBaseAtomicNotificationQueue", + /* Temporary IOBuf ring used for scattered read/write. + * It's only used for communication and should be empty the rest of the + * time. So we shouldn't loose too much visibility by stubbing it out. + */ + "IOBufIovecBuilder", + /* struct event from libevent + * Its linked lists are not always initialised, leading to SegV in our JIT + * code. We can't stub the linked list themselves, as they're anonymous + * structs. + */ + "event", + }; + private: // Private constructor. Please use the fallible `OICodeGen::buildFromConfig` // for the expected behaviour. diff --git a/oi/type_graph/EnforceCompatibility.cpp b/oi/type_graph/EnforceCompatibility.cpp index 4a04a40..8e55142 100644 --- a/oi/type_graph/EnforceCompatibility.cpp +++ b/oi/type_graph/EnforceCompatibility.cpp @@ -15,12 +15,14 @@ */ #include "EnforceCompatibility.h" +#include #include #include "AddPadding.h" #include "Flattener.h" #include "TypeGraph.h" #include "TypeIdentifier.h" +#include "oi/OICodeGen.h" namespace type_graph { @@ -42,7 +44,21 @@ void EnforceCompatibility::accept(Type& type) { type.accept(*this); } +namespace { +bool isTypeToStub(const Class& c) { + auto it = std::ranges::find_if(OICodeGen::typesToStub, + [&c](const auto& typeToStub) { + return c.name().starts_with(typeToStub); + }); + return it != OICodeGen::typesToStub.end(); +} +} // namespace + void EnforceCompatibility::visit(Class& c) { + if (isTypeToStub(c)) { + c.members.clear(); + } + for (auto& param : c.templateParams) { accept(param.type()); } diff --git a/test/test_enforce_compatibility.cpp b/test/test_enforce_compatibility.cpp index f398a6c..8ad8975 100644 --- a/test/test_enforce_compatibility.cpp +++ b/test/test_enforce_compatibility.cpp @@ -17,3 +17,16 @@ TEST(EnforceCompatibilityTest, ParentContainers) { [0] Class: MyClass (size: 24) )"); } + +TEST(EnforceCompatibilityTest, TypesToStub) { + test(EnforceCompatibility::createPass(), R"( +[0] Class: EnumMap (size: 8) + Member: a (offset: 0) + Primitive: int32_t + Member: b (offset: 4) + Primitive: int32_t +)", + R"( +[0] Class: EnumMap (size: 8) +)"); +}