OICodeGen: Respect ContainerInfo::requiredFeatures

CodeGen v1 and CodeGen v2 must be in sync in order for CodeGen v2 and
TreeBuilder v1 to be compatible. This change updates CodeGen v1 to use
the same set of containers as CodeGen v2.

This specifically fixes "-ftype-graph -Ftree-builder-v2 -Fcapture-thrift-isset"
for Thrift types.

The integration test "thrift_isset_no_capture" covers this, but this bug
was missed as the Thrift tests do not run in CI.
This commit is contained in:
Alastair Robertson 2023-11-16 07:21:05 -08:00 committed by Jake Hillion
parent b117150f83
commit 8e8db376d8
3 changed files with 21 additions and 0 deletions

View File

@ -126,6 +126,20 @@ const char* containerTypeEnumToStr(ContainerTypeEnum ty) {
});
}
oi::detail::FeatureSet requiredFeatures;
if (toml::array* arr = (*info)["required_features"].as_array()) {
arr->for_each([&](auto&& el) {
if constexpr (toml::is_string<decltype(el)>) {
oi::detail::Feature f = oi::detail::featureFromStr(*el);
if (f == oi::detail::Feature::UnknownFeature) {
LOG(WARNING) << "unknown feature in container config: " << el;
return;
}
requiredFeatures[f] = true;
}
});
}
std::optional<size_t> allocatorIndex =
(*info)["allocatorIndex"].value<size_t>();
std::optional<size_t> underlyingContainerIndex =
@ -166,6 +180,7 @@ const char* containerTypeEnumToStr(ContainerTypeEnum ty) {
allocatorIndex,
underlyingContainerIndex,
{},
requiredFeatures,
{
std::move(decl),
std::move(func),

View File

@ -58,6 +58,7 @@ struct ContainerInfo {
std::optional<size_t> allocatorIndex_,
std::optional<size_t> underlyingContainerIndex_,
std::vector<size_t> stubTemplateParams_,
oi::detail::FeatureSet requiredFeatures,
ContainerInfo::Codegen codegen_)
: typeName(std::move(typeName_)),
matcher(std::move(matcher_)),
@ -69,6 +70,7 @@ struct ContainerInfo {
allocatorIndex(allocatorIndex_),
underlyingContainerIndex(underlyingContainerIndex_),
stubTemplateParams(std::move(stubTemplateParams_)),
requiredFeatures(requiredFeatures),
codegen(std::move(codegen_)) {
}

View File

@ -85,6 +85,10 @@ bool OICodeGen::registerContainer(const fs::path& path) {
if (!info) {
return false;
}
if (info->requiredFeatures != (config.features & info->requiredFeatures)) {
VLOG(1) << "Skipping container (feature conflict): " << info->typeName;
return true;
}
VLOG(1) << "registered container, type: " << info->typeName;
containerInfoList.emplace_back(std::move(info));