object-introspection/types/small_vec_type.toml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.7 KiB
TOML
Raw Normal View History

2022-12-19 14:37:51 +00:00
[info]
type_name = "folly::small_vector"
2022-12-19 14:37:51 +00:00
ctype = "SMALL_VEC_TYPE"
header = "folly/small_vector.h"
stub_template_params = [2]
# Old:
typeName = "folly::small_vector<"
ns = ["folly::small_vector_policy::policy_size_type", "folly::small_vector"]
numTemplateParams = 1
2022-12-19 14:37:51 +00:00
replaceTemplateParamIndex = []
[codegen]
decl = """
template <class V, std::size_t N, class P>
void getSizeType(const %1%<V, N, P> &container, size_t& returnArg);
2022-12-19 14:37:51 +00:00
"""
func = """
template <class V, std::size_t N, class P>
void getSizeType(const %1%<V, N, P> &container, size_t& returnArg)
2022-12-19 14:37:51 +00:00
{
SAVE_SIZE(sizeof(%1%<V, N, P>));
bool dataInlined = isStorageInline(container);
if (dataInlined) {
// Don't double count inlined elements
SAVE_SIZE(-(container.size() * sizeof(V)));
} else {
// Account for wasted space in the buffer
SAVE_SIZE((container.capacity() - container.size()) * sizeof(V));
}
2022-12-19 14:37:51 +00:00
SAVE_DATA((uintptr_t)(N));
SAVE_DATA((uintptr_t)container.capacity());
SAVE_DATA((uintptr_t)container.size());
for (auto & it: container) {
getSizeType(it, returnArg);
}
}
"""
traversal_func = """
bool uses_intern_storage = isStorageInline(container);
auto tail = returnArg
.write((uintptr_t)uses_intern_storage)
.write(container.capacity())
.write(container.size());
for (auto &&it: container) {
tail = tail.delegate([&ctx, &it](typename TypeHandler<Ctx, T0>::type ret) {
return OIInternal::getSizeType<Ctx>(ctx, it, ret);
});
}
return tail.finish();
"""
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = """
// Using the container's pointer to temporarily store the uses_intern_storage boolean.
// TODO: Is there another way to pass a value across processors?
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]]
tbv2: replace DB template param with Ctx (#409) Summary: tbv2: replace DB template param with Ctx TreeBuilder v2 adds a DB template parameter to every function. This is used as part of the static type to decide what type of DataBuffer is being used: currently `BackInserterDataBuffer<std::vector<uint8_t>>` for OIL and it would be `DataSegmentDataBuffer` for OID. This change replaces the `DB` template parameter with a more general `Ctx`. Due to issues with dependent naming it also adds a `using DB` to each `TypeHandler` which has the same function as before. This allows us to add more "static context" (typedefs and constants) to functions without changing this signature again, because changing the signature of everything is a massive pain. Currently this change achieves nothing because Ctx contains only DB in a static wrapper. In the next change I'm going to pass a reference of type Ctx around to add a "dynamic context" to invocations which will contain the pointer array. In future we'll then be able to add either static or dynamic context without any signature adjustments. Test Plan: - CI --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebookexperimental/object-introspection/pull/409). * https://github.com/facebookexperimental/object-introspection/issues/410 * __->__ https://github.com/facebookexperimental/object-introspection/issues/409 Reviewed By: ajor Differential Revision: D51352092 Pulled By: JakeHillion
2023-11-15 19:28:21 +00:00
type = "types::st::List<DB, typename TypeHandler<Ctx, T0>::type>"
func = """
// Reading the `uses_intern_storage` boolean that was stored in `pointer` by the processor above.
bool uses_intern_storage = std::exchange(el.pointer.value(), (uintptr_t)0);
auto list = std::get<ParsedData::List>(d.val);
el.container_stats->length = list.length;
if (uses_intern_storage) {
// The storage is inlined, so don't double count for items using the intern storage.
el.exclusive_size -= list.length * sizeof(T0);
} else {
// The storage is heap allocated, so add any unused capacity.
el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0);
}
tbv2: replace DB template param with Ctx (#409) Summary: tbv2: replace DB template param with Ctx TreeBuilder v2 adds a DB template parameter to every function. This is used as part of the static type to decide what type of DataBuffer is being used: currently `BackInserterDataBuffer<std::vector<uint8_t>>` for OIL and it would be `DataSegmentDataBuffer` for OID. This change replaces the `DB` template parameter with a more general `Ctx`. Due to issues with dependent naming it also adds a `using DB` to each `TypeHandler` which has the same function as before. This allows us to add more "static context" (typedefs and constants) to functions without changing this signature again, because changing the signature of everything is a massive pain. Currently this change achieves nothing because Ctx contains only DB in a static wrapper. In the next change I'm going to pass a reference of type Ctx around to add a "dynamic context" to invocations which will contain the pointer array. In future we'll then be able to add either static or dynamic context without any signature adjustments. Test Plan: - CI --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebookexperimental/object-introspection/pull/409). * https://github.com/facebookexperimental/object-introspection/issues/410 * __->__ https://github.com/facebookexperimental/object-introspection/issues/409 Reviewed By: ajor Differential Revision: D51352092 Pulled By: JakeHillion
2023-11-15 19:28:21 +00:00
static constexpr auto childField = make_field<Ctx, T0>("[]");
for (size_t i = 0; i < list.length; i++)
stack_ins(childField);
"""