Implement Container V2 for std::shared_ptr

This commit is contained in:
Thierry Treyer 2023-08-31 08:25:53 -07:00 committed by Thierry Treyer
parent 344023239b
commit a5284549da
2 changed files with 110 additions and 6 deletions

View File

@ -158,7 +158,6 @@ definitions = '''
] ]
''' '''
[cases.shared_ptr_uint64_empty] [cases.shared_ptr_uint64_empty]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<std::uint64_t>&"] param_types = ["std::shared_ptr<std::uint64_t>&"]
setup = "return {nullptr};" setup = "return {nullptr};"
expect_json = ''' expect_json = '''
@ -172,8 +171,17 @@ definitions = '''
} }
] ]
''' '''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 0,
"capacity": 1
}
]
'''
[cases.shared_ptr_uint64_present] [cases.shared_ptr_uint64_present]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<std::uint64_t>&"] param_types = ["std::shared_ptr<std::uint64_t>&"]
setup = "return std::make_shared<std::uint64_t>(64);" setup = "return std::make_shared<std::uint64_t>(64);"
expect_json = ''' expect_json = '''
@ -187,8 +195,20 @@ definitions = '''
} }
] ]
''' '''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 1,
"capacity": 1,
"members": [
{ "staticSize": 8, "exclusiveSize": 8 }
]
}
]
'''
[cases.shared_ptr_vector_empty] [cases.shared_ptr_vector_empty]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<std::vector<std::uint64_t>>&"] param_types = ["std::shared_ptr<std::vector<std::uint64_t>>&"]
setup = "return {nullptr};" setup = "return {nullptr};"
expect_json = ''' expect_json = '''
@ -202,8 +222,17 @@ definitions = '''
} }
] ]
''' '''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 0,
"capacity": 1
}
]
'''
[cases.shared_ptr_vector_present] [cases.shared_ptr_vector_present]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<std::vector<std::uint64_t>>&"] param_types = ["std::shared_ptr<std::vector<std::uint64_t>>&"]
setup = "return std::make_shared<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}));" setup = "return std::make_shared<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}));"
expect_json = ''' expect_json = '''
@ -223,8 +252,25 @@ definitions = '''
} }
] ]
''' '''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 1,
"capacity": 1,
"members": [
{
"staticSize": 24,
"exclusiveSize": 24,
"length": 5,
"capacity": 5
}
]
}
]
'''
[cases.shared_ptr_void_empty] [cases.shared_ptr_void_empty]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<void>&"] param_types = ["std::shared_ptr<void>&"]
setup = "return {nullptr};" setup = "return {nullptr};"
expect_json = ''' expect_json = '''
@ -237,7 +283,6 @@ definitions = '''
] ]
''' '''
[cases.shared_ptr_void_present] [cases.shared_ptr_void_present]
oil_skip = "std::shared_ptr is not implemented for treebuilder v2" # https://github.com/facebookexperimental/object-introspection/issues/300
param_types = ["std::shared_ptr<void>&"] param_types = ["std::shared_ptr<void>&"]
setup = "return {std::shared_ptr<void>(new int)};" setup = "return {std::shared_ptr<void>(new int)};"
expect_json = ''' expect_json = '''

View File

@ -65,3 +65,62 @@ struct TypeHandler<DB, %1%<T0>> {
} }
}; };
""" """
traversal_func = """
auto tail = returnArg.write((uintptr_t)container.get());
if constexpr (std::is_void<T0>::value) {
return tail.template delegate<0>(std::identity());
} else {
bool do_visit = container && pointers.add((uintptr_t)container.get());
if (!do_visit)
return tail.template delegate<0>(std::identity());
return tail.template delegate<1>([&container](auto ret) {
return OIInternal::getSizeType<DB>(*container, ret);
});
}
"""
[[codegen.processor]]
type = "types::st::VarInt<DB>"
func = """
el.pointer = std::get<ParsedData::VarInt>(d.val).value;
"""
[[codegen.processor]]
type = """
types::st::Sum<DB,
types::st::Unit<DB>,
typename TypeHandler<DB, T0>::type>
"""
func = """
#ifdef __GLIBCXX__
// TODO: Accurately report the control block overhead
// accounting for both in-place and non-in-place
// _Sp_counted_base (_Atomic_word, _Atomic_word)
// _Sp_counted_ptr : _Sp_counted_base (_Ptr)
// _Sp_counted_ptr_inplace : _Sp_counted_base (_Tp)
// _Sp_counted_deleter : _Sp_counted_base (_Ptr)
// _Sp_counted_array : _Sp_counted_base (_Ptr)
#elif _LIBCPP_VERSION
static_assert(false && "libc++ is currently not supported");
#else
static_assert(false && "No known element_size for sets. See types/set_type.toml");
#endif
auto sum = std::get<ParsedData::Sum>(d.val);
el.container_stats.emplace(result::Element::ContainerStats {
.capacity = 1,
.length = sum.index, // 0 for empty containers/void, 1 otherwise
});
// Must be in a `if constexpr` or the compiler will complain about make_field<DB, void>
if constexpr (!std::is_void<T0>::value) {
if (sum.index == 1) {
static constexpr auto element = make_field<DB, T0>("ptr_val");
ins.emplace(element);
}
}
"""