object-introspection/types/f14_vector_map.toml
Jake Hillion 4c047b5f91 tbv2: add is_primitive to output
C++ has a concept of Primitive which holds in the type graph. However we don't
currently expose this information to the end user. Expose this from the OIL
iterator to allow future features like primitive rollups.

This affects containers like maps which have a fake `[]` element with no type.
They use this to group together the key/value in a map and to account for any
per element storage overhead. Currently the decision is to make the fake `[]`
element a primitive if all of its children are primitives. This allows for more
effective primitive rollups if that is implemented. This implementation detail
may be changed in future.

Test Plan:
- CI
- Updated simple tests.
2024-01-16 11:14:13 +00:00

104 lines
2.9 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>{},
element_fields[0].is_primitive && element_fields[1].is_primitive,
};
for (size_t i = 0; i < list.length; i++)
stack_ins(element);
"""