object-introspection/types/std_unordered_map_type.toml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 lines
4.1 KiB
TOML
Raw Normal View History

2022-12-19 14:37:51 +00:00
[info]
type_name = "std::unordered_map"
stub_template_params = [2,3,4]
2022-12-19 14:37:51 +00:00
ctype = "STD_UNORDERED_MAP_TYPE"
header = "unordered_map"
# Old:
typeName = "std::unordered_map<"
2022-12-19 14:37:51 +00:00
ns = ["namespace std"]
numTemplateParams = 2
2022-12-19 14:37:51 +00:00
replaceTemplateParamIndex = [2, 3]
allocatorIndex = 4
[codegen]
decl = """
template<class K, class T, class H, class KE, class A>
void getSizeType(const %1%<K, T, H, KE, A> &container, size_t& returnArg);
"""
func = """
template<class K, class T, class H, class KE, class A>
void getSizeType(const %1%<K, T, H, KE, A> &container, size_t& returnArg)
{
constexpr size_t nodeSize = sizeof(typename %1%<K, T, H, KE, A>::node_type);
size_t bucketCount = container.bucket_count();
size_t numElems = container.size();
SAVE_SIZE(sizeof(%1%<K, T, H, KE, A>) + (nodeSize * numElems) + (bucketCount * sizeof(uintptr_t)));
SAVE_DATA((uintptr_t)nodeSize);
SAVE_DATA((uintptr_t)bucketCount);
SAVE_DATA((uintptr_t)numElems);
for (auto const& it : container)
{
getSizeType(it.first, returnArg);
getSizeType(it.second, returnArg);
2022-12-19 14:37:51 +00:00
}
}
"""
traversal_func = """
auto tail = returnArg
.write((uintptr_t)&container)
.write(container.bucket_count())
.write(container.size());
for (const auto& kv : container) {
tail = tail.delegate([&ctx, &kv](auto ret) {
auto start = maybeCaptureKey<captureKeys, Ctx, T0>(ctx, kv.first, ret);
auto next = start.delegate([&ctx, &kv](typename TypeHandler<Ctx, T0>::type ret) {
return OIInternal::getSizeType<Ctx>(ctx, kv.first, ret);
});
return OIInternal::getSizeType<Ctx>(ctx, kv.second, next);
});
}
return tail.finish();
"""
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = """
el.pointer = std::get<ParsedData::VarInt>(d.val).value;
"""
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = """
// Using the container's capacity to temporarily store the number of buckets
// TODO: Is there another way to pass a value across processors?
el.container_stats.emplace(result::Element::ContainerStats {
.capacity = std::get<ParsedData::VarInt>(d.val).value,
});
"""
[[codegen.processor]]
type = """
std::conditional_t<captureKeys,
types::st::List<DB,
types::st::Pair<DB,
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<std::vector<uint8_t>>` 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
2023-11-15 19:28:21 +00:00
typename CaptureKeyHandler<Ctx, T0>::type,
types::st::Pair<DB,
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<std::vector<uint8_t>>` 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
2023-11-15 19:28:21 +00:00
typename TypeHandler<Ctx, T0>::type,
typename TypeHandler<Ctx, T1>::type>>>,
types::st::List<DB, types::st::Pair<DB,
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<std::vector<uint8_t>>` 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
2023-11-15 19:28:21 +00:00
typename TypeHandler<Ctx, T0>::type,
typename TypeHandler<Ctx, T1>::type>>
>
"""
func = """
#ifdef __GLIBCXX__
/* Use libstdc++ implementation __details to compute the size of Nodes and Buckets.
*
* See the source of <bits/hashtable_policy.h>:
* https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00536_source.html
*/
using OI_value_type = std::pair<const T0, T1>;
using OI_Hash_node =
std::__detail::_Hash_node<
OI_value_type,
std::__cache_default<OI_value_type, T2>::value>;
using OI_bucket = std::__detail::_Hash_node_base;
static constexpr size_t element_size = sizeof(OI_Hash_node);
static constexpr size_t bucket_size = sizeof(OI_bucket);
#else
static_assert(false && "No known element_size for sets. See types/set_type.toml");
#endif
auto list = std::get<ParsedData::List>(d.val);
// Reading the bucket count that was stored in `capacity` by the processor above.
size_t bucket_count = el.container_stats->capacity;
el.exclusive_size += bucket_count * bucket_size;
el.exclusive_size += list.length * (element_size - sizeof(T0));
// Overwrite the bucket count stored in `capacity` with the actual container's values.
el.container_stats.emplace(result::Element::ContainerStats {
.capacity = list.length,
.length = list.length,
});
static constexpr std::array<inst::Field, 2> element_fields{
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<std::vector<uint8_t>>` 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
2023-11-15 19:28:21 +00:00
make_field<Ctx, T0>("key"),
make_field<Ctx, T1>("value"),
};
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<std::vector<uint8_t>>` 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
2023-11-15 19:28:21 +00:00
static constexpr auto processors = maybeCaptureKeysProcessor<captureKeys, Ctx, T0>();
static constexpr auto element = inst::Field{
element_size,
element_size - sizeof(T0) - sizeof(T1),
"[]",
std::array<std::string_view, 0>{},
element_fields,
processors,
element_fields[0].is_primitive && element_fields[1].is_primitive,
};
for (size_t i = 0; i < list.length; i++)
stack_ins(element);
"""