object-introspection/types/map_seq_type.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
3.2 KiB
TOML

[info]
type_name = "folly::sorted_vector_map"
ctype = "MAP_SEQ_TYPE"
header = "folly/sorted_vector_types.h"
stub_template_params = [2,3]
# Old:
typeName = "folly::sorted_vector_map<"
ns = ["namespace std", "folly::sorted_vector_map"]
numTemplateParams = 2
replaceTemplateParamIndex = []
[codegen]
decl = """
template <class Key, class Value, class Compare, class Allocator, class GrowthPolicy, class Container>
void getSizeType(const %1%<Key, Value, Compare, Allocator, GrowthPolicy, Container> &container, size_t& returnArg);
"""
func = """
template <class Key, class Value, class Compare, class Allocator, class GrowthPolicy, class Container>
void getSizeType(const %1%<Key, Value, Compare, Allocator, GrowthPolicy, Container> &container, size_t& returnArg)
{
SAVE_SIZE(sizeof(%1%<Key,Value,Compare,Allocator,GrowthPolicy,Container>));
SAVE_DATA((uintptr_t)&container);
SAVE_DATA((uintptr_t)container.capacity());
SAVE_DATA((uintptr_t)container.size());
SAVE_SIZE((container.capacity() - container.size()) * (sizeof(Key) + sizeof(Value)));
for (auto const& it : container)
{
getSizeType(it.first, returnArg);
getSizeType(it.second, returnArg);
}
}
"""
traversal_func = '''
auto tail = returnArg.write((uintptr_t)&container)
.write(container.capacity())
.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 = '''
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,
typename CaptureKeyHandler<Ctx, T0>::type,
types::st::Pair<DB,
typename TypeHandler<Ctx, T0>::type,
typename TypeHandler<Ctx, T1>::type>>>,
types::st::List<DB, types::st::Pair<DB,
typename TypeHandler<Ctx, T0>::type,
typename TypeHandler<Ctx, T1>::type>>>
'''
func = '''
using element_type = std::pair<T0, T1>;
static constexpr std::array<inst::Field, 2> entryFields{
make_field<Ctx, T0>("key"),
make_field<Ctx, T1>("value"),
};
static constexpr auto processors = maybeCaptureKeysProcessor<captureKeys, Ctx, T0>();
static constexpr auto entry = inst::Field {
sizeof(element_type),
sizeof(element_type) - sizeof(T0) - sizeof(T1),
"[]",
std::array<std::string_view, 0>{},
entryFields,
processors,
entryFields[0].is_primitive && entryFields[1].is_primitive,
};
auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;
el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(element_type);
for (size_t i = 0; i < list.length; i++)
stack_ins(entry);
'''