object-introspection/types/f14_vector_map.toml
Jake Hillion b117150f83 tbv2: add dynamic context passed through all functions (#410)
Summary:
tbv2: add dynamic context passed through all functions

Previously for we had some shared state between all requests, noticeably the
pointers set. This change adds a by reference value to all requests which can
hold additional mutable state. The pointers set is moved into this mutable
state for OIL, which means each concurrent request will have its own pointer
set. Doing things this way allows more features to be added in the future
without such a big code modification.

Closes https://github.com/facebookexperimental/object-introspection/issues/404

Pull Request resolved: https://github.com/facebookexperimental/object-introspection/pull/410

Test Plan: - CI

Differential Revision: D51394035

Pulled By: JakeHillion

fbshipit-source-id: 55d2ba9b5e056148a29dc821020cfc3d94e5175a
2023-11-16 08:03:32 -08:00

103 lines
2.8 KiB
TOML

[info]
type_name = "folly::F14VectorMap"
stub_template_params = [2,3,4]
ctype = "F14_MAP"
header = "folly/container/F14Map.h"
# Old:
typeName = "folly::F14VectorMap<"
ns = ["folly::F14VectorMap"]
numTemplateParams = 2
replaceTemplateParamIndex = [2, 3]
allocatorIndex = 4
[codegen]
decl = """
template <typename Key, typename Mapped, typename Hasher, typename KeyEqual, typename Alloc>
void getSizeType(const %1%<Key, Mapped, Hasher, KeyEqual, Alloc> &container, size_t& dataSegOffset);
"""
func = """
template <typename Key, typename Mapped, typename Hasher, typename KeyEqual, typename Alloc>
void getSizeType(const %1%<Key, Mapped, Hasher, KeyEqual, Alloc> &container, size_t& returnArg)
{
size_t memorySize = container.getAllocatedMemorySize();
SAVE_SIZE(sizeof(%1%<Key, Mapped, Hasher, KeyEqual>) + memorySize);
SAVE_DATA(memorySize);
SAVE_DATA(container.bucket_count());
SAVE_DATA(container.size());
// The double ampersand is needed otherwise this loop doesn't work with vector<bool>
for (auto&& it: container) {
getSizeType(it.first, returnArg);
getSizeType(it.second, returnArg);
}
}
"""
traversal_func = """
auto tail = returnArg
.write((uintptr_t)container.getAllocatedMemorySize())
.write((uintptr_t)container.bucket_count())
.write(container.size());
for (auto &&entry: container) {
tail = tail.delegate([&ctx, &key = entry.first, &value = entry.second](auto ret) {
auto next = ret.delegate([&ctx, &key](typename TypeHandler<Ctx, T0>::type ret) {
return OIInternal::getSizeType<Ctx>(ctx, key, ret);
});
return OIInternal::getSizeType<Ctx>(ctx, value, 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 = """
el.container_stats.emplace(result::Element::ContainerStats {
.capacity = std::get<ParsedData::VarInt>(d.val).value,
});
"""
[[codegen.processor]]
type = """
types::st::List<DB, types::st::Pair<DB,
typename TypeHandler<Ctx, T0>::type,
typename TypeHandler<Ctx, T1>::type>>
"""
func = """
static constexpr size_t element_size = sizeof(typename container_type::value_type);
auto allocationSize = el.pointer.value();
el.pointer.reset();
auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;
el.exclusive_size += allocationSize - list.length * element_size;
static constexpr std::array<inst::Field, 2> element_fields{
make_field<Ctx, T0>("key"),
make_field<Ctx, T1>("value"),
};
static constexpr inst::Field element{
element_size,
element_size - sizeof(T0) - sizeof(T1),
"[]",
std::array<std::string_view, 0>{},
element_fields,
std::array<inst::ProcessorInst, 0>{},
};
for (size_t i = 0; i < list.length; i++)
stack_ins(element);
"""