mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 19:19:05 +01:00
d71307cb43
Summary: Previously on large types OIL would have problems with corrupting the `std::stack<exporter::inst::Inst>` that is passed to the processors. This change hides the implementation of the stack from the processors by wrapping the call to emplace in a `std::function` written by the non-generated code, which solves the test case I've seen for this crashing. It also allows us to easily change the stack implementation in future - I plan to change it to a `std::stack<T, std::vector<T>>` in a follow up. Reviewed By: tyroguru Differential Revision: D49273116
125 lines
3.8 KiB
TOML
125 lines
3.8 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);
|
|
}
|
|
}
|
|
"""
|
|
handler = """
|
|
template <typename DB, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
|
|
struct TypeHandler<DB, %1%<T0, T1, T2, T3, T4, T5>> {
|
|
using type = types::st::Pair<DB,
|
|
types::st::VarInt<DB>,
|
|
types::st::Pair<DB,
|
|
types::st::VarInt<DB>,
|
|
types::st::List<DB, types::st::Pair<DB,
|
|
typename TypeHandler<DB, T0>::type,
|
|
typename TypeHandler<DB, T1>::type
|
|
>>>>;
|
|
|
|
static types::st::Unit<DB> getSizeType(
|
|
const %1%<T0, T1, T2, T3, T4, T5>& container,
|
|
typename TypeHandler<DB, %1%<T0, T1, T2, T3, T4, T5>>::type returnArg) {
|
|
auto tail = returnArg.write((uintptr_t)&container)
|
|
.write(container.capacity())
|
|
.write(container.size());
|
|
|
|
for (const auto& it : container) {
|
|
tail = tail.delegate([&it](auto ret) {
|
|
return OIInternal::getSizeType<DB>(it.second, ret.delegate([&it](auto ret) {
|
|
return OIInternal::getSizeType<DB>(it.first, ret);
|
|
}));
|
|
});
|
|
}
|
|
|
|
return tail.finish();
|
|
}
|
|
};
|
|
"""
|
|
|
|
traversal_func = '''
|
|
auto tail = returnArg.write((uintptr_t)&container)
|
|
.write(container.capacity())
|
|
.write(container.size());
|
|
|
|
for (const auto& kv : container) {
|
|
tail = tail.delegate([&kv](auto ret) {
|
|
auto next = ret.delegate([&kv](typename TypeHandler<DB, T0>::type ret) {
|
|
return OIInternal::getSizeType<DB>(kv.first, ret);
|
|
});
|
|
return OIInternal::getSizeType<DB>(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 = '''types::st::List<DB, types::st::Pair<DB,
|
|
typename TypeHandler<DB, T0>::type,
|
|
typename TypeHandler<DB, T1>::type
|
|
>>'''
|
|
func = '''
|
|
using element_type = std::pair<T0, T1>;
|
|
|
|
static constexpr std::array<inst::Field, 2> entryFields{
|
|
make_field<DB, T0>("key"),
|
|
make_field<DB, T1>("value"),
|
|
};
|
|
static constexpr auto entry = inst::Field {
|
|
sizeof(element_type),
|
|
sizeof(element_type) - sizeof(T0) - sizeof(T1),
|
|
"[]",
|
|
std::array<std::string_view, 0>{},
|
|
entryFields,
|
|
std::array<inst::ProcessorInst, 0>{},
|
|
};
|
|
|
|
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);
|
|
'''
|