EnforceCompatibility: Follow OICodeGen's typesToStub list

This commit is contained in:
Alastair Robertson 2023-07-25 09:37:13 -07:00 committed by Alastair Robertson
parent 8b7bfbe4c0
commit e19641efad
4 changed files with 55 additions and 26 deletions

View File

@ -62,32 +62,6 @@ std::unique_ptr<OICodeGen> 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, "*");

View File

@ -69,6 +69,32 @@ class OICodeGen {
std::vector<std::string> 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.

View File

@ -15,12 +15,14 @@
*/
#include "EnforceCompatibility.h"
#include <algorithm>
#include <cassert>
#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());
}

View File

@ -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)
)");
}