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
104 lines
2.8 KiB
TOML
104 lines
2.8 KiB
TOML
[info]
|
|
type_name = "folly::F14VectorSet"
|
|
stub_template_params = [1,2,3]
|
|
ctype = "F14_SET"
|
|
header = "folly/container/F14Set.h"
|
|
|
|
# Old:
|
|
typeName = "folly::F14VectorSet<"
|
|
ns = ["folly::F14VectorSet"]
|
|
numTemplateParams = 1
|
|
replaceTemplateParamIndex = [1, 2]
|
|
allocatorIndex = 3
|
|
|
|
[codegen]
|
|
decl = """
|
|
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
|
|
void getSizeType(const %1%<Key, Hasher, KeyEqual, Alloc> &container, size_t& returnArg);
|
|
"""
|
|
|
|
func = """
|
|
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
|
|
void getSizeType(const %1%<Key, Hasher, KeyEqual, Alloc> &container, size_t& returnArg)
|
|
{
|
|
size_t memorySize = container.getAllocatedMemorySize();
|
|
SAVE_SIZE(sizeof(%1%<Key, Hasher, KeyEqual, Alloc>) + 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, returnArg);
|
|
}
|
|
}
|
|
"""
|
|
|
|
handler = """
|
|
template <typename DB, typename T0, typename T1, typename T2, typename T3>
|
|
struct TypeHandler<DB, %1%<T0, T1, T2, T3>> {
|
|
using type = types::st::Pair<DB,
|
|
types::st::VarInt<DB>,
|
|
types::st::Pair<DB,
|
|
types::st::VarInt<DB>,
|
|
types::st::List<DB,
|
|
typename TypeHandler<DB, T0>::type>>>;
|
|
|
|
static types::st::Unit<DB> getSizeType(
|
|
const %1%<T0, T1, T2, T3>& container,
|
|
typename TypeHandler<DB, %1%<T0, T1, T2, T3>>::type returnArg) {
|
|
size_t memorySize = container.getAllocatedMemorySize();
|
|
auto tail = returnArg
|
|
.write(memorySize)
|
|
.write(container.bucket_count())
|
|
.write(container.size());
|
|
|
|
for (auto &&entry: container) {
|
|
tail = tail.delegate([&entry](auto ret) {
|
|
return OIInternal::getSizeType<DB>(entry, ret);
|
|
});
|
|
}
|
|
|
|
return tail.finish();
|
|
}
|
|
};
|
|
"""
|
|
|
|
traversal_func = """
|
|
// TODO: This implementation enables the traversal of the container,
|
|
// but doesn't report the memory footprint accurately.
|
|
// Revisit this implementation and fix memory footprint reporting.
|
|
auto tail = returnArg
|
|
.write((uintptr_t)&container)
|
|
.write(container.size());
|
|
|
|
for (auto &&entry: container) {
|
|
tail = tail.delegate([&entry](auto ret) {
|
|
return OIInternal::getSizeType<DB>(entry, ret);
|
|
});
|
|
}
|
|
|
|
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::List<DB, typename TypeHandler<DB, T0>::type>
|
|
"""
|
|
func = """
|
|
auto list = std::get<ParsedData::List>(d.val);
|
|
el.container_stats.emplace(result::Element::ContainerStats {
|
|
.capacity = list.length,
|
|
.length = list.length,
|
|
});
|
|
|
|
static constexpr auto childField = make_field<DB, T0>("[]");
|
|
for (size_t i = 0; i < list.length; i++)
|
|
stack_ins(childField);
|
|
"""
|