From 3d91603c8e93f83b5df166854996165e76c41625 Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Thu, 25 May 2023 09:06:45 -0700 Subject: [PATCH] TypeGraph: Fix std::string container std::basic_string takes three template parameters: 1. CharT 2. Traits 3. Allocator The Traits parameter was causing issues, as it requires a type which exposes certain things, e.g. `Traits::value_type`. We have a few options to resolve this: 1. Remove this parameter, as we do for allocators Cons: removing a template parameter doesn't work if other parameters appear after it 2. Stub this parameter, as we do for hashers/comparators Cons: we need to hardcode an implementation that satisfies the `Traits::value_type` requirements 3. Leave the parameter as-is Cons: will not work if a non-standard Traits is used By using the real implementation of this Traits parameter (normally `std::char_traits`), we get one that we know will work as long as it is defined in a stdlib header. Option 3 is what we use in this patch. Instead of adding more configuration options to the container TOML file format (e.g. `params_to_keep = [1]`), we add `std::char_traits` as a dummy container type. Now, whenever `std::char_traits` appears, it will be left as-is, i.e. not removed, replaced or reverse-engineered. This is the same approach previously used for Thrift's isset_bitset. --- dev.oid.toml | 1 + oi/Common.h | 2 +- oi/TreeBuilder.cpp | 2 +- test/ci.oid.toml | 1 + types/cxx11_string_type.toml | 2 +- types/std_char_traits.toml | 17 +++++++++++++++++ types/string_type.toml | 2 +- types/thrift_isset_type.toml | 2 +- 8 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 types/std_char_traits.toml diff --git a/dev.oid.toml b/dev.oid.toml index 77a05c5..b92ff7e 100644 --- a/dev.oid.toml +++ b/dev.oid.toml @@ -46,4 +46,5 @@ containers = [ "PWD/types/std_variant.toml", "PWD/types/thrift_isset_type.toml", "PWD/types/weak_ptr_type.toml", + "PWD/types/std_char_traits.toml", ] diff --git a/oi/Common.h b/oi/Common.h index c402592..df113f3 100644 --- a/oi/Common.h +++ b/oi/Common.h @@ -65,7 +65,7 @@ constexpr int oidMagicId = 0x01DE8; X(ENUM_MAP_TYPE) \ X(BOOST_BIMAP_TYPE) \ X(STD_VARIANT_TYPE) \ - X(THRIFT_ISSET_TYPE) \ + X(DUMMY_TYPE) \ X(WEAK_PTR_TYPE) enum ContainerTypeEnum { diff --git a/oi/TreeBuilder.cpp b/oi/TreeBuilder.cpp index 23f8fe9..33b97c3 100644 --- a/oi/TreeBuilder.cpp +++ b/oi/TreeBuilder.cpp @@ -830,7 +830,7 @@ void TreeBuilder::processContainer(const Variable& variable, Node& node) { case BY_MULTI_QRT_TYPE: containerStats.length = containerStats.capacity = next(); break; - case THRIFT_ISSET_TYPE: + case DUMMY_TYPE: // Dummy container containerStats.elementStaticSize = 0; break; diff --git a/test/ci.oid.toml b/test/ci.oid.toml index 830ed96..5f5b0e3 100644 --- a/test/ci.oid.toml +++ b/test/ci.oid.toml @@ -42,6 +42,7 @@ containers = [ "../types/std_variant.toml", "../types/thrift_isset_type.toml", "../types/weak_ptr_type.toml", + "../types/std_char_traits.toml", ] [headers] diff --git a/types/cxx11_string_type.toml b/types/cxx11_string_type.toml index 3771ffb..85e3f6c 100644 --- a/types/cxx11_string_type.toml +++ b/types/cxx11_string_type.toml @@ -1,6 +1,6 @@ [info] type_name = "std::__cxx11::basic_string" -stub_template_params = [1,2] +stub_template_params = [2] ctype = "STRING_TYPE" header = "string" diff --git a/types/std_char_traits.toml b/types/std_char_traits.toml new file mode 100644 index 0000000..3eb8e87 --- /dev/null +++ b/types/std_char_traits.toml @@ -0,0 +1,17 @@ +[info] +type_name = "std::char_traits" +ctype = "DUMMY_TYPE" +header = "string" + +# Old: +typeName = "std::char_traits<" +ns = ["namespace std"] +numTemplateParams = 1 + +[codegen] +decl = """ +// DummyDecl %1% +""" +func = """ +// DummyFunc %1% +""" diff --git a/types/string_type.toml b/types/string_type.toml index d838129..007b73e 100644 --- a/types/string_type.toml +++ b/types/string_type.toml @@ -1,6 +1,6 @@ [info] type_name = "std::basic_string" -stub_template_params = [1,2] +stub_template_params = [2] ctype = "STRING_TYPE" header = "string" diff --git a/types/thrift_isset_type.toml b/types/thrift_isset_type.toml index 54eff13..09ca687 100644 --- a/types/thrift_isset_type.toml +++ b/types/thrift_isset_type.toml @@ -1,6 +1,6 @@ [info] type_name = "apache::thrift::detail::isset_bitset" -ctype = "THRIFT_ISSET_TYPE" +ctype = "DUMMY_TYPE" header = "thrift/lib/cpp2/gen/module_types_h.h" # Old: