From 592e182e0ffd150b4fa9625c733f2029f2d48c75 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Wed, 15 Nov 2023 11:28:21 -0800 Subject: [PATCH] tbv2: replace DB template param with Ctx (#409) Summary: tbv2: replace DB template param with Ctx TreeBuilder v2 adds a DB template parameter to every function. This is used as part of the static type to decide what type of DataBuffer is being used: currently `BackInserterDataBuffer>` for OIL and it would be `DataSegmentDataBuffer` for OID. This change replaces the `DB` template parameter with a more general `Ctx`. Due to issues with dependent naming it also adds a `using DB` to each `TypeHandler` which has the same function as before. This allows us to add more "static context" (typedefs and constants) to functions without changing this signature again, because changing the signature of everything is a massive pain. Currently this change achieves nothing because Ctx contains only DB in a static wrapper. In the next change I'm going to pass a reference of type Ctx around to add a "dynamic context" to invocations which will contain the pointer array. In future we'll then be able to add either static or dynamic context without any signature adjustments. Test Plan: - CI --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebookexperimental/object-introspection/pull/409). * https://github.com/facebookexperimental/object-introspection/issues/410 * __->__ https://github.com/facebookexperimental/object-introspection/issues/409 Reviewed By: ajor Differential Revision: D51352092 Pulled By: JakeHillion --- oi/CodeGen.cpp | 59 ++++++++++++++------------ oi/FuncGen.cpp | 47 +++++++++++--------- types/array_type.toml | 6 +-- types/cxx11_list_type.toml | 8 ++-- types/cxx11_string_type.toml | 5 ++- types/f14_fast_map.toml | 14 +++--- types/f14_fast_set.toml | 6 +-- types/f14_node_map.toml | 14 +++--- types/f14_node_set.toml | 6 +-- types/f14_value_map.toml | 14 +++--- types/f14_value_set.toml | 6 +-- types/f14_vector_map.toml | 14 +++--- types/f14_vector_set.toml | 6 +-- types/list_type.toml | 8 ++-- types/map_seq_type.toml | 24 +++++------ types/multi_map_type.toml | 14 +++--- types/multi_set_type.toml | 6 +-- types/optional_type.toml | 8 ++-- types/pair_type.toml | 10 ++--- types/seq_type.toml | 6 +-- types/set_type.toml | 6 +-- types/shrd_ptr_type.toml | 8 ++-- types/small_vec_type.toml | 8 ++-- types/sorted_vec_set_type.toml | 6 +-- types/std_map_type.toml | 24 +++++------ types/std_unordered_map_type.toml | 24 +++++------ types/std_unordered_multimap_type.toml | 10 ++--- types/uniq_ptr_type.toml | 8 ++-- types/unordered_multiset_type.toml | 6 +-- types/unordered_set_type.toml | 6 +-- 30 files changed, 200 insertions(+), 187 deletions(-) diff --git a/oi/CodeGen.cpp b/oi/CodeGen.cpp index 73725e4..cfa87e7 100644 --- a/oi/CodeGen.cpp +++ b/oi/CodeGen.cpp @@ -651,7 +651,7 @@ void CodeGen::genClassTraversalFunction(const Class& c, std::string& code) { code += funcName; code += "(\n const "; code += c.name(); - code += "& t,\n typename TypeHandler::type, // Pair::type, // TypeHandler::type @@ -734,7 +734,7 @@ void CodeGen::genClassStaticType(const Class& c, std::string& code) { } code += - (boost::format("typename TypeHandler::type") % + (boost::format("typename TypeHandler::type") % c.name() % member.name) .str(); @@ -787,8 +787,8 @@ void CodeGen::genClassTreeBuilderInstructions(const Class& c, code += " inst::Field{sizeof(" + fullName + "), " + std::to_string(calculateExclusiveSize(m.type())) + ",\"" + m.inputName + "\", member_" + std::to_string(index) + - "_type_names, TypeHandler::fields, TypeHandler::fields, TypeHandler::processors},\n"; } code += " };\n"; @@ -820,10 +820,11 @@ void CodeGen::genClassTypeHandler(const Class& c, std::string& code) { .str(); } - code += "template \n"; - code += "class TypeHandler& used, containerWithTypes = "OICaptureKeys<" + containerWithTypes + ">"; } - code += "template & used, } } code += ">\n"; - code += "struct TypeHandler& used, code += " const "; code += containerWithTypes; code += "& container,\n"; - code += " typename TypeHandler& used, void addCaptureKeySupport(std::string& code) { code += R"( - template + template class CaptureKeyHandler { + using DB = typename Ctx::DataBuffer; public: using type = types::st::Sum, types::st::VarInt>; @@ -975,24 +978,24 @@ void addCaptureKeySupport(std::string& code) { } }; - template + template auto maybeCaptureKey(const T& key, auto returnArg) { if constexpr (CaptureKeys) { return returnArg.delegate([&key](auto ret) { - return CaptureKeyHandler::captureKey(key, ret); + return CaptureKeyHandler::captureKey(key, ret); }); } else { return returnArg; } } - template + template static constexpr inst::ProcessorInst CaptureKeysProcessor{ - CaptureKeyHandler::type::describe, + CaptureKeyHandler::type::describe, [](result::Element& el, std::function stack_ins, ParsedData d) { if constexpr (std::is_same_v< - typename CaptureKeyHandler::type, - types::st::List>>) { + typename CaptureKeyHandler::type, + types::st::List>>) { // String auto& str = el.data.emplace(); auto list = std::get(d.val); @@ -1013,11 +1016,11 @@ void addCaptureKeySupport(std::string& code) { } }; - template + template static constexpr auto maybeCaptureKeysProcessor() { if constexpr (CaptureKeys) { return std::array{ - CaptureKeysProcessor, + CaptureKeysProcessor, }; } else { @@ -1034,28 +1037,28 @@ void addStandardTypeHandlers(TypeGraph& typeGraph, addCaptureKeySupport(code); // Provide a wrapper function, getSizeType, to infer T instead of having to - // explicitly specify it with TypeHandler::getSizeType every time. + // explicitly specify it with TypeHandler::getSizeType every time. code += R"( - template - types::st::Unit - getSizeType(const T &t, typename TypeHandler::type returnArg) { + template + types::st::Unit + getSizeType(const T &t, typename TypeHandler::type returnArg) { JLOG("obj @"); JLOGPTR(&t); - return TypeHandler::getSizeType(t, returnArg); + return TypeHandler::getSizeType(t, returnArg); } )"; if (features[Feature::TreeBuilderV2]) { code += R"( -template +template constexpr inst::Field make_field(std::string_view name) { return inst::Field{ sizeof(T), ExclusiveSizeProvider::size, name, NameProvider::names, - TypeHandler::fields, - TypeHandler::processors, + TypeHandler::fields, + TypeHandler::processors, }; } )"; diff --git a/oi/FuncGen.cpp b/oi/FuncGen.cpp index 14eeb61..7cc2868 100644 --- a/oi/FuncGen.cpp +++ b/oi/FuncGen.cpp @@ -268,11 +268,13 @@ void __attribute__((used, retain)) introspect_%2$016x( v.clear(); v.reserve(4096); - using DataBufferType = DataBuffer::BackInserter>; - using ContentType = OIInternal::TypeHandler::type; + struct Context { + using DataBuffer = DataBuffer::BackInserter>; + }; + using ContentType = OIInternal::TypeHandler::type; - ContentType ret{DataBufferType{v}}; - OIInternal::getSizeType(t, ret); + ContentType ret{Context::DataBuffer{v}}; + OIInternal::getSizeType(t, ret); } )"; @@ -368,6 +370,9 @@ void FuncGen::DefineTreeBuilderInstructions( #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-attributes" namespace { +struct FakeContext { + using DataBuffer = int; +}; const std::array::fields, " - "OIInternal::TypeHandler::processors};\n"; + ", OIInternal::TypeHandler::fields, " + "OIInternal::TypeHandler::processors};\n"; code += "} // namespace\n"; code += "extern const exporters::inst::Inst __attribute__((used, retain)) " @@ -603,14 +610,15 @@ class BackInserter { */ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { code += R"( - template + template struct TypeHandler { + using DB = typename Ctx::DataBuffer; private: static auto choose_type() { if constexpr(std::is_pointer_v) { return std::type_identity, - types::st::Sum, typename TypeHandler>::type> + types::st::Sum, typename TypeHandler>::type> >>(); } else { return std::type_identity>(); @@ -631,8 +639,8 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { sizeof(T), "*", names, - TypeHandler::fields, - TypeHandler::processors, + TypeHandler::fields, + TypeHandler::processors, }; const ParsedData::Sum& sum = std::get(d.val); @@ -657,7 +665,7 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { if constexpr(std::is_pointer_v) { return std::array{ {types::st::VarInt::describe, &process_pointer}, - {types::st::Sum, typename TypeHandler>::type>::describe, &process_pointer_content}, + {types::st::Sum, typename TypeHandler>::type>::describe, &process_pointer_content}, }; } else { return std::array{}; @@ -671,7 +679,7 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { code += R"( static types::st::Unit getSizeType( const T& t, - typename TypeHandler::type returnArg) { + typename TypeHandler::type returnArg) { if constexpr(std::is_pointer_v) { JLOG("ptr val @"); JLOGPTR(t); @@ -679,7 +687,7 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { if (t && pointers.add((uintptr_t)t)) { return r0.template delegate<1>([&t](auto ret) { if constexpr (!std::is_void>::value) { - return TypeHandler>::getSizeType(*t, ret); + return TypeHandler>::getSizeType(*t, ret); } else { return ret; } @@ -695,8 +703,9 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) { )"; code += R"( - template - class TypeHandler { + template + class TypeHandler { + using DB = typename Ctx::DataBuffer; public: using type = types::st::Unit; )"; @@ -719,21 +728,21 @@ ContainerInfo FuncGen::GetOiArrayContainerInfo() { auto tail = returnArg.write(N0); for (size_t i=0; i::getSizeType(container.vals[i], ret); + return TypeHandler::getSizeType(container.vals[i], ret); }); } return tail.finish(); )"; oiArray.codegen.processors.emplace_back(ContainerInfo::Processor{ - .type = "types::st::List::type>", + .type = "types::st::List::type>", .func = R"( static constexpr std::array names{"TODO"}; static constexpr auto childField = inst::Field{ sizeof(T0), "[]", names, - TypeHandler::fields, - TypeHandler::processors, + TypeHandler::fields, + TypeHandler::processors, }; el.exclusive_size = 0; diff --git a/types/array_type.toml b/types/array_type.toml index 6d73322..126af6a 100644 --- a/types/array_type.toml +++ b/types/array_type.toml @@ -34,7 +34,7 @@ traversal_func = """ for (auto & it: container) { tail = tail.delegate([&it](auto ret) { - return TypeHandler::getSizeType(it, ret); + return TypeHandler::getSizeType(it, ret); }); } @@ -42,9 +42,9 @@ traversal_func = """ """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); size_t size = std::get(d.val).length; el.exclusive_size = N0 == 0 ? 1 : 0; diff --git a/types/cxx11_list_type.toml b/types/cxx11_list_type.toml index fb54d22..f838eee 100644 --- a/types/cxx11_list_type.toml +++ b/types/cxx11_list_type.toml @@ -39,7 +39,7 @@ auto tail = returnArg.write((uintptr_t)&container) for (auto&& it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -53,7 +53,7 @@ el.pointer = std::get(d.val).value; """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ static constexpr size_t element_size = sizeof(std::_List_node); @@ -62,7 +62,7 @@ static_assert(false && "No known element_size for list. See types/cxx11_list_typ #endif static constexpr std::array child_field{ - make_field("*"), + make_field("*"), }; static constexpr inst::Field element{ element_size, @@ -72,7 +72,7 @@ static constexpr inst::Field element{ child_field, std::array{}, }; -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats{ diff --git a/types/cxx11_string_type.toml b/types/cxx11_string_type.toml index 94e7183..c88debd 100644 --- a/types/cxx11_string_type.toml +++ b/types/cxx11_string_type.toml @@ -37,8 +37,9 @@ void getSizeType(const %1% &container, size_t& returnArg) """ extra = """ -template -class CaptureKeyHandler> { +template +class CaptureKeyHandler> { + using DB = typename Ctx::DataBuffer; public: // List of characters using type = types::st::List>; diff --git a/types/f14_fast_map.toml b/types/f14_fast_map.toml index c8c84f2..faf2e9d 100644 --- a/types/f14_fast_map.toml +++ b/types/f14_fast_map.toml @@ -44,10 +44,10 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto next = ret.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto next = ret.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -69,8 +69,8 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ static constexpr size_t element_size = sizeof(typename container_type::value_type); @@ -84,8 +84,8 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * element_size; static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr inst::Field element{ diff --git a/types/f14_fast_set.toml b/types/f14_fast_set.toml index 8516f8c..b66284b 100644 --- a/types/f14_fast_set.toml +++ b/types/f14_fast_set.toml @@ -43,7 +43,7 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&entry](auto ret) { - return OIInternal::getSizeType(entry, ret); + return OIInternal::getSizeType(entry, ret); }); } @@ -64,7 +64,7 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ -types::st::List::type> +types::st::List::type> """ func = """ auto allocationSize = el.pointer.value(); @@ -75,7 +75,7 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * sizeof(T0); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/f14_node_map.toml b/types/f14_node_map.toml index 93b53e9..a53c3e6 100644 --- a/types/f14_node_map.toml +++ b/types/f14_node_map.toml @@ -44,10 +44,10 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto next = ret.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto next = ret.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -69,8 +69,8 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ static constexpr size_t element_size = sizeof(typename container_type::value_type); @@ -84,8 +84,8 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * element_size; static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr inst::Field element{ diff --git a/types/f14_node_set.toml b/types/f14_node_set.toml index 511c2f8..3ed0b5d 100644 --- a/types/f14_node_set.toml +++ b/types/f14_node_set.toml @@ -43,7 +43,7 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&entry](auto ret) { - return OIInternal::getSizeType(entry, ret); + return OIInternal::getSizeType(entry, ret); }); } @@ -64,7 +64,7 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ -types::st::List::type> +types::st::List::type> """ func = """ auto allocationSize = el.pointer.value(); @@ -75,7 +75,7 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * sizeof(T0); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/f14_value_map.toml b/types/f14_value_map.toml index ec4f187..8072abf 100644 --- a/types/f14_value_map.toml +++ b/types/f14_value_map.toml @@ -44,10 +44,10 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto next = ret.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto next = ret.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -69,8 +69,8 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ static constexpr size_t element_size = sizeof(typename container_type::value_type); @@ -84,8 +84,8 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * element_size; static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr inst::Field element{ diff --git a/types/f14_value_set.toml b/types/f14_value_set.toml index 20aae30..dd4070d 100644 --- a/types/f14_value_set.toml +++ b/types/f14_value_set.toml @@ -43,7 +43,7 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&entry](auto ret) { - return OIInternal::getSizeType(entry, ret); + return OIInternal::getSizeType(entry, ret); }); } @@ -64,7 +64,7 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ -types::st::List::type> +types::st::List::type> """ func = """ auto allocationSize = el.pointer.value(); @@ -75,7 +75,7 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * sizeof(T0); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/f14_vector_map.toml b/types/f14_vector_map.toml index 5e29d82..ec7ac93 100644 --- a/types/f14_vector_map.toml +++ b/types/f14_vector_map.toml @@ -44,10 +44,10 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto next = ret.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto next = ret.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -69,8 +69,8 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ static constexpr size_t element_size = sizeof(typename container_type::value_type); @@ -84,8 +84,8 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * element_size; static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr inst::Field element{ diff --git a/types/f14_vector_set.toml b/types/f14_vector_set.toml index 1aed210..e98b6d8 100644 --- a/types/f14_vector_set.toml +++ b/types/f14_vector_set.toml @@ -43,7 +43,7 @@ auto tail = returnArg for (auto &&entry: container) { tail = tail.delegate([&entry](auto ret) { - return OIInternal::getSizeType(entry, ret); + return OIInternal::getSizeType(entry, ret); }); } @@ -64,7 +64,7 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ -types::st::List::type> +types::st::List::type> """ func = """ auto allocationSize = el.pointer.value(); @@ -75,7 +75,7 @@ el.container_stats->length = list.length; el.exclusive_size += allocationSize - list.length * sizeof(T0); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/list_type.toml b/types/list_type.toml index 9ea8ef7..86d457e 100644 --- a/types/list_type.toml +++ b/types/list_type.toml @@ -39,7 +39,7 @@ auto tail = returnArg.write((uintptr_t)&container) for (auto&& it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -53,7 +53,7 @@ el.pointer = std::get(d.val).value; """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ static constexpr size_t element_size = sizeof(std::_List_node); @@ -62,7 +62,7 @@ static_assert(false && "No known element_size for list. See types/cxx11_list_typ #endif static constexpr std::array child_field{ - make_field("*"), + make_field("*"), }; static constexpr inst::Field element{ element_size, @@ -72,7 +72,7 @@ static constexpr inst::Field element{ child_field, std::array{}, }; -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats{ diff --git a/types/map_seq_type.toml b/types/map_seq_type.toml index 90d424d..887df6a 100644 --- a/types/map_seq_type.toml +++ b/types/map_seq_type.toml @@ -43,11 +43,11 @@ traversal_func = ''' for (const auto& kv : container) { tail = tail.delegate([&kv](auto ret) { - auto start = maybeCaptureKey(kv.first, ret); - auto next = start.delegate([&kv](typename TypeHandler::type ret) { - return OIInternal::getSizeType(kv.first, ret); + auto start = maybeCaptureKey(kv.first, ret); + auto next = start.delegate([&kv](typename TypeHandler::type ret) { + return OIInternal::getSizeType(kv.first, ret); }); - return OIInternal::getSizeType(kv.second, next); + return OIInternal::getSizeType(kv.second, next); }); } @@ -68,22 +68,22 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get type = ''' std::conditional_t::type, + typename CaptureKeyHandler::type, types::st::Pair::type, - typename TypeHandler::type>>>, + typename TypeHandler::type, + typename TypeHandler::type>>>, types::st::List::type, - typename TypeHandler::type>>> + typename TypeHandler::type, + typename TypeHandler::type>>> ''' func = ''' using element_type = std::pair; static constexpr std::array entryFields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; -static constexpr auto processors = maybeCaptureKeysProcessor(); +static constexpr auto processors = maybeCaptureKeysProcessor(); static constexpr auto entry = inst::Field { sizeof(element_type), sizeof(element_type) - sizeof(T0) - sizeof(T1), diff --git a/types/multi_map_type.toml b/types/multi_map_type.toml index 7b1e622..e05a1e3 100644 --- a/types/multi_map_type.toml +++ b/types/multi_map_type.toml @@ -40,10 +40,10 @@ auto tail = returnArg for (const auto &entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto next = ret.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto next = ret.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -57,8 +57,8 @@ func = "el.pointer = std::get(d.val).value;" [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ #ifdef __GLIBCXX__ @@ -108,8 +108,8 @@ static_assert(false && "No known element_size for sets. See types/multi_map_type #endif static constexpr std::array elementFields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr auto element = inst::Field { element_size, diff --git a/types/multi_set_type.toml b/types/multi_set_type.toml index 34163e8..00f8239 100644 --- a/types/multi_set_type.toml +++ b/types/multi_set_type.toml @@ -43,7 +43,7 @@ auto tail = returnArg.write((uintptr_t)&container) // vector for (auto&& it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -57,7 +57,7 @@ el.pointer = std::get(d.val).value; """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ /* We don't have access to the _Rb_tree_node struct, so we manually re-create it @@ -103,7 +103,7 @@ static constexpr size_t element_size = sizeof(OI__tree_node); static_assert(false && "No known element_size for multisets. See types/multi_set_type.toml"); #endif -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats { diff --git a/types/optional_type.toml b/types/optional_type.toml index 2178743..3bd9cff 100644 --- a/types/optional_type.toml +++ b/types/optional_type.toml @@ -31,7 +31,7 @@ void getSizeType(const %1%& container, size_t& returnArg) { traversal_func = """ if (container.has_value()) { return returnArg.template delegate<1>([&container](auto ret) { - return OIInternal::getSizeType(*container, ret); + return OIInternal::getSizeType(*container, ret); }); } else { return returnArg.template delegate<0>(std::identity()); @@ -39,15 +39,15 @@ if (container.has_value()) { """ [[codegen.processor]] -type = "types::st::Sum, typename TypeHandler::type>" +type = "types::st::Sum, typename TypeHandler::type>" func = """ static constexpr std::array names{"TODO"}; static constexpr auto elementField = inst::Field{ sizeof(T0), "el", names, - TypeHandler::fields, - TypeHandler::processors, + TypeHandler::fields, + TypeHandler::processors, }; auto sum = std::get(d.val); diff --git a/types/pair_type.toml b/types/pair_type.toml index 570d289..ba5bc38 100644 --- a/types/pair_type.toml +++ b/types/pair_type.toml @@ -27,19 +27,19 @@ void getSizeType(const %1% &container, size_t& returnArg) """ traversal_func = """ - return OIInternal::getSizeType( + return OIInternal::getSizeType( container.second, returnArg.delegate([&container](auto ret) { - return OIInternal::getSizeType(container.first, ret); + return OIInternal::getSizeType(container.first, ret); }) ); """ [[codegen.processor]] -type = "types::st::Pair::type, typename TypeHandler::type>" +type = "types::st::Pair::type, typename TypeHandler::type>" func = """ -static constexpr auto firstField = make_field("first"); -static constexpr auto secondField = make_field("second"); +static constexpr auto firstField = make_field("first"); +static constexpr auto secondField = make_field("second"); el.exclusive_size = sizeof(std::pair) - sizeof(T0) - sizeof(T1); stack_ins(secondField); diff --git a/types/seq_type.toml b/types/seq_type.toml index 0ccfee8..88ddd1d 100644 --- a/types/seq_type.toml +++ b/types/seq_type.toml @@ -44,7 +44,7 @@ auto tail = returnArg.write((uintptr_t)&container) // vector for (auto&& it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -64,9 +64,9 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats->length = list.length; diff --git a/types/set_type.toml b/types/set_type.toml index 43206f6..e29611e 100644 --- a/types/set_type.toml +++ b/types/set_type.toml @@ -44,7 +44,7 @@ auto tail = returnArg.write((uintptr_t)&container) // vector for (auto&& it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -58,7 +58,7 @@ el.pointer = std::get(d.val).value; """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ /* We don't have access to the _Rb_tree_node struct, so we manually re-create it @@ -104,7 +104,7 @@ static constexpr size_t element_size = sizeof(OI__tree_node); static_assert(false && "No known element_size for sets. See types/set_type.toml"); #endif -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats.emplace(result::Element::ContainerStats { diff --git a/types/shrd_ptr_type.toml b/types/shrd_ptr_type.toml index 693f871..125fd71 100644 --- a/types/shrd_ptr_type.toml +++ b/types/shrd_ptr_type.toml @@ -45,7 +45,7 @@ if constexpr (std::is_void::value) { return tail.template delegate<0>(std::identity()); return tail.template delegate<1>([&container](auto ret) { - return OIInternal::getSizeType(*container, ret); + return OIInternal::getSizeType(*container, ret); }); } """ @@ -60,7 +60,7 @@ el.pointer = std::get(d.val).value; type = """ types::st::Sum, - typename TypeHandler::type> + typename TypeHandler::type> """ func = """ #ifdef __GLIBCXX__ @@ -84,10 +84,10 @@ el.container_stats.emplace(result::Element::ContainerStats { .length = sum.index, // 0 for empty containers/void, 1 otherwise }); -// Must be in a `if constexpr` or the compiler will complain about make_field +// Must be in a `if constexpr` or the compiler will complain about make_field if constexpr (!std::is_void::value) { if (sum.index == 1) { - static constexpr auto element = make_field("ptr_val"); + static constexpr auto element = make_field("ptr_val"); stack_ins(element); } } diff --git a/types/small_vec_type.toml b/types/small_vec_type.toml index aca3e79..d129285 100644 --- a/types/small_vec_type.toml +++ b/types/small_vec_type.toml @@ -56,8 +56,8 @@ auto tail = returnArg .write(container.size()); for (auto &&it: container) { - tail = tail.delegate([&it](typename TypeHandler::type ret) { - return OIInternal::getSizeType(it, ret); + tail = tail.delegate([&it](typename TypeHandler::type ret) { + return OIInternal::getSizeType(it, ret); }); } @@ -81,7 +81,7 @@ el.container_stats.emplace(result::Element::ContainerStats { """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ // Reading the `uses_intern_storage` boolean that was stored in `pointer` by the processor above. bool uses_intern_storage = std::exchange(el.pointer.value(), (uintptr_t)0); @@ -97,7 +97,7 @@ if (uses_intern_storage) { el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0); } -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/sorted_vec_set_type.toml b/types/sorted_vec_set_type.toml index f17a0f7..e8b9483 100644 --- a/types/sorted_vec_set_type.toml +++ b/types/sorted_vec_set_type.toml @@ -38,7 +38,7 @@ auto tail = returnArg.write((uintptr_t)&container) for (const auto& el : container) { tail = tail.delegate([&el](auto ret) { - return OIInternal::getSizeType(el, ret); + return OIInternal::getSizeType(el, ret); }); } @@ -56,9 +56,9 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get ''' [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); el.container_stats->length = list.length; diff --git a/types/std_map_type.toml b/types/std_map_type.toml index 61be6be..df06cc7 100644 --- a/types/std_map_type.toml +++ b/types/std_map_type.toml @@ -44,11 +44,11 @@ auto tail = returnArg for (const auto &entry: container) { tail = tail.delegate([&key = entry.first, &value = entry.second](auto ret) { - auto start = maybeCaptureKey(key, ret); - auto next = start.delegate([&key](typename TypeHandler::type ret) { - return OIInternal::getSizeType(key, ret); + auto start = maybeCaptureKey(key, ret); + auto next = start.delegate([&key](typename TypeHandler::type ret) { + return OIInternal::getSizeType(key, ret); }); - return OIInternal::getSizeType(value, next); + return OIInternal::getSizeType(value, next); }); } @@ -64,14 +64,14 @@ type = """ std::conditional_t::type, + typename CaptureKeyHandler::type, types::st::Pair::type, - typename TypeHandler::type>>>, + typename TypeHandler::type, + typename TypeHandler::type>>>, types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> > """ func = """ @@ -122,11 +122,11 @@ static_assert(false && "No known element_size for sets. See types/std_map_type.t #endif static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; -static constexpr auto processors = maybeCaptureKeysProcessor(); +static constexpr auto processors = maybeCaptureKeysProcessor(); static constexpr inst::Field element{ element_size, diff --git a/types/std_unordered_map_type.toml b/types/std_unordered_map_type.toml index 541576d..27142a1 100644 --- a/types/std_unordered_map_type.toml +++ b/types/std_unordered_map_type.toml @@ -47,11 +47,11 @@ auto tail = returnArg for (const auto& kv : container) { tail = tail.delegate([&kv](auto ret) { - auto start = maybeCaptureKey(kv.first, ret); - auto next = start.delegate([&kv](typename TypeHandler::type ret) { - return OIInternal::getSizeType(kv.first, ret); + auto start = maybeCaptureKey(kv.first, ret); + auto next = start.delegate([&kv](typename TypeHandler::type ret) { + return OIInternal::getSizeType(kv.first, ret); }); - return OIInternal::getSizeType(kv.second, next); + return OIInternal::getSizeType(kv.second, next); }); } @@ -79,13 +79,13 @@ type = """ std::conditional_t::type, + typename CaptureKeyHandler::type, types::st::Pair::type, - typename TypeHandler::type>>>, + typename TypeHandler::type, + typename TypeHandler::type>>>, types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> > """ func = """ @@ -122,11 +122,11 @@ el.container_stats.emplace(result::Element::ContainerStats { }); static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; -static constexpr auto processors = maybeCaptureKeysProcessor(); +static constexpr auto processors = maybeCaptureKeysProcessor(); static constexpr auto element = inst::Field{ element_size, diff --git a/types/std_unordered_multimap_type.toml b/types/std_unordered_multimap_type.toml index a548623..261a0be 100644 --- a/types/std_unordered_multimap_type.toml +++ b/types/std_unordered_multimap_type.toml @@ -47,7 +47,7 @@ auto tail = returnArg for (const auto &it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -73,8 +73,8 @@ el.container_stats.emplace(result::Element::ContainerStats { [[codegen.processor]] type = """ types::st::List::type, - typename TypeHandler::type>> + typename TypeHandler::type, + typename TypeHandler::type>> """ func = """ #ifdef __GLIBCXX__ @@ -110,8 +110,8 @@ el.container_stats.emplace(result::Element::ContainerStats { }); static constexpr std::array element_fields{ - make_field("key"), - make_field("value"), + make_field("key"), + make_field("value"), }; static constexpr auto element = inst::Field{ diff --git a/types/uniq_ptr_type.toml b/types/uniq_ptr_type.toml index 35155f9..58364cf 100644 --- a/types/uniq_ptr_type.toml +++ b/types/uniq_ptr_type.toml @@ -46,7 +46,7 @@ if constexpr (std::is_void::value) { return tail.template delegate<0>(std::identity()); return tail.template delegate<1>([&container](auto ret) { - return OIInternal::getSizeType(*container, ret); + return OIInternal::getSizeType(*container, ret); }); } """ @@ -61,7 +61,7 @@ el.pointer = std::get(d.val).value; type = """ types::st::Sum, - typename TypeHandler::type> + typename TypeHandler::type> """ func = """ auto sum = std::get(d.val); @@ -70,10 +70,10 @@ el.container_stats.emplace(result::Element::ContainerStats { .length = sum.index, // 0 for empty containers/void, 1 otherwise }); -// Must be in a `if constexpr` or the compiler will complain about make_field +// Must be in a `if constexpr` or the compiler will complain about make_field if constexpr (!std::is_void::value) { if (sum.index == 1) { - static constexpr auto element = make_field("ptr_val"); + static constexpr auto element = make_field("ptr_val"); stack_ins(element); } } diff --git a/types/unordered_multiset_type.toml b/types/unordered_multiset_type.toml index 9d1449a..5c2e96b 100644 --- a/types/unordered_multiset_type.toml +++ b/types/unordered_multiset_type.toml @@ -45,7 +45,7 @@ auto tail = returnArg for (const auto &it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -69,7 +69,7 @@ el.container_stats.emplace(result::Element::ContainerStats { """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ /* Use libstdc++ implementation __details to compute the size of Nodes and Buckets. @@ -100,7 +100,7 @@ el.container_stats.emplace(result::Element::ContainerStats { .length = list.length, }); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """ diff --git a/types/unordered_set_type.toml b/types/unordered_set_type.toml index 62e0190..f8d26c9 100644 --- a/types/unordered_set_type.toml +++ b/types/unordered_set_type.toml @@ -45,7 +45,7 @@ auto tail = returnArg for (const auto &it : container) { tail = tail.delegate([&it](auto ret) { - return OIInternal::getSizeType(it, ret); + return OIInternal::getSizeType(it, ret); }); } @@ -69,7 +69,7 @@ el.container_stats.emplace(result::Element::ContainerStats { """ [[codegen.processor]] -type = "types::st::List::type>" +type = "types::st::List::type>" func = """ #ifdef __GLIBCXX__ /* Use libstdc++ implementation __details to compute the size of Nodes and Buckets. @@ -100,7 +100,7 @@ el.container_stats.emplace(result::Element::ContainerStats { .length = list.length, }); -static constexpr auto childField = make_field("[]"); +static constexpr auto childField = make_field("[]"); for (size_t i = 0; i < list.length; i++) stack_ins(childField); """