object-introspection/types/shrd_ptr_type.toml
Jake Hillion db93feb180 incomplete: name type in compiler errors
Summary:

We have a good type representation in the Type Graph of an incomplete type and
the underlying type that represents. However, this incomplete type still ends
up in the generated code as `void` which loses information. For example, a
container that can't contain void may fail to compile because it was
initialised with `void` but really its because the type it was supposed to be
initialised with (say, `Foo`) had incomplete debug information.

This change identifies that a type is incomplete in the output by generating it
as an incomplete type `struct Incomplete<struct Foo>`. This allows us to name
the type correctly in the TreeBuilder output and filter for incomplete types,
as well as getting appropriate compiler errors if it mustn't be incomplete.

Test Plan:
- CI
- Added a unit test to namegen.
- Enabled and added an extra pointers_incomplete test.

This change is tricky to test because it isn't really user visible. The types
still use their `inputName` which is unchanged in any successful output - this
change is used so the compiler fails with a more detailed error.
2024-01-09 15:08:25 +00:00

95 lines
2.4 KiB
TOML

[info]
type_name = "std::shared_ptr"
ctype = "SHRD_PTR_TYPE"
header = "memory"
# Old:
typeName = "std::shared_ptr"
ns = ["namespace std"]
numTemplateParams = 1
replaceTemplateParamIndex = []
[codegen]
decl = """
template<typename T>
void getSizeType(const %1%<T> &s_ptr, size_t& returnArg);
"""
func = """
template<typename T>
void getSizeType(const %1%<T> &s_ptr, size_t& returnArg)
{
SAVE_SIZE(sizeof(%1%<T>));
if constexpr (oi_is_complete<T>) {
SAVE_DATA((uintptr_t)(s_ptr.get()));
if (s_ptr && ctx.pointers.add((uintptr_t)(s_ptr.get()))) {
SAVE_DATA(1);
getSizeType(*(s_ptr.get()), returnArg);
} else {
SAVE_DATA(0);
}
}
}
"""
traversal_func = """
auto tail = returnArg.write((uintptr_t)container.get());
if constexpr (!oi_is_complete<T0>) {
return tail.template delegate<0>(std::identity());
} else {
bool do_visit = container && ctx.pointers.add((uintptr_t)container.get());
if (!do_visit)
return tail.template delegate<0>(std::identity());
return tail.template delegate<1>([&ctx, &container](auto ret) {
return OIInternal::getSizeType<Ctx>(ctx, *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<Ctx, 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<Ctx, void>
if constexpr (oi_is_complete<T0>) {
if (sum.index == 1) {
static constexpr auto element = make_field<Ctx, T0>("ptr_val");
stack_ins(element);
}
}
"""