tbv2: use std::decay_t with smart pointers

CodeGen v2 permits template parameters to be qualified. This means that if we
call `make_field` with a template parameter it will be qualified. However, we
don't qualify the types when generating meta functions such as `NameProvider`
and `TypeHandler`. This means these qualified types don't match up with the
expected type.

Use `std::decay_t` when forwarding the type to `NameProvider` and `TypeHandler`
so they're always the base type that they were generated with. Most of this is
covered by `make_field`, but there are direct references to `TypeHandler<Ctx,
T>` in a lot of `TypeHandler::type` fields. Fix the problematic types manually
for now, there may need to be a better solution with meta functions for this in
the future.

Test Plan:
- CI
- Added a test for `std::unique_ptr<const uint64_t>` to exercise this. Failed
  before, passes after.
- Added a test for `std::unique_ptr<const std::
This commit is contained in:
Jake Hillion 2023-12-22 16:12:36 +00:00
parent beb404e41c
commit 8ab3041df9
4 changed files with 103 additions and 6 deletions

View File

@ -1060,7 +1060,7 @@ void addStandardTypeHandlers(TypeGraph& typeGraph,
getSizeType(Ctx& ctx, const T &t, typename TypeHandler<Ctx, T>::type returnArg) {
JLOG("obj @");
JLOGPTR(&t);
return TypeHandler<Ctx, T>::getSizeType(ctx, t, returnArg);
return TypeHandler<Ctx, std::decay_t<T>>::getSizeType(ctx, t, returnArg);
}
)";
@ -1072,9 +1072,9 @@ constexpr inst::Field make_field(std::string_view name) {
sizeof(T),
ExclusiveSizeProvider<T>::size,
name,
NameProvider<T>::names,
TypeHandler<Ctx, T>::fields,
TypeHandler<Ctx, T>::processors,
NameProvider<std::decay_t<T>>::names,
TypeHandler<Ctx, std::decay_t<T>>::fields,
TypeHandler<Ctx, std::decay_t<T>>::processors,
};
}
)";

View File

@ -31,6 +31,31 @@ definitions = '''
}
]
'''
[cases.unique_ptr_const_uint64_empty]
param_types = ["std::unique_ptr<const std::uint64_t>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 8,
"dynamicSize": 0,
"exclusiveSize": 8,
"length": 0,
"capacity": 1,
"elementStaticSize": 8
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 8,
"exclusiveSize": 8,
"length": 0,
"capacity": 1
}
]
'''
[cases.unique_ptr_uint64_present]
param_types = ["std::unique_ptr<std::uint64_t>&"]
setup = "return {std::make_unique<std::uint64_t>(64)};"
@ -79,6 +104,30 @@ definitions = '''
}
]
'''
[cases.unique_ptr_const_vector_empty]
param_types = ["std::unique_ptr<const std::vector<std::uint64_t>>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 8,
"dynamicSize": 0,
"length": 0,
"capacity": 1,
"elementStaticSize": 24
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 8,
"exclusiveSize": 8,
"length": 0,
"capacity": 1
}
]
'''
[cases.unique_ptr_vector_present]
param_types = ["std::unique_ptr<std::vector<std::uint64_t>>&"]
setup = "return {std::make_unique<std::vector<std::uint64_t>>(std::initializer_list<std::uint64_t>({1,2,3,4,5}))};"
@ -181,6 +230,30 @@ definitions = '''
}
]
'''
[cases.shared_ptr_const_uint64_empty]
param_types = ["std::shared_ptr<const std::uint64_t>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 16,
"dynamicSize": 0,
"length": 0,
"capacity": 1,
"elementStaticSize": 8
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 0,
"capacity": 1
}
]
'''
[cases.shared_ptr_uint64_present]
param_types = ["std::shared_ptr<std::uint64_t>&"]
setup = "return std::make_shared<std::uint64_t>(64);"
@ -232,6 +305,30 @@ definitions = '''
}
]
'''
[cases.shared_ptr_const_vector_empty]
param_types = ["std::shared_ptr<const std::vector<std::uint64_t>>&"]
setup = "return {nullptr};"
expect_json = '''
[
{
"staticSize": 16,
"dynamicSize": 0,
"length": 0,
"capacity": 1,
"elementStaticSize": 24
}
]
'''
expect_json_v2 = '''
[
{
"staticSize": 16,
"exclusiveSize": 16,
"length": 0,
"capacity": 1
}
]
'''
[cases.shared_ptr_vector_present]
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}));"

View File

@ -60,7 +60,7 @@ el.pointer = std::get<ParsedData::VarInt>(d.val).value;
type = """
types::st::Sum<DB,
types::st::Unit<DB>,
typename TypeHandler<Ctx, T0>::type>
typename TypeHandler<Ctx, std::decay_t<T0>>::type>
"""
func = """
#ifdef __GLIBCXX__

View File

@ -61,7 +61,7 @@ el.pointer = std::get<ParsedData::VarInt>(d.val).value;
type = """
types::st::Sum<DB,
types::st::Unit<DB>,
typename TypeHandler<Ctx, T0>::type>
typename TypeHandler<Ctx, std::decay_t<T0>>::type>
"""
func = """
auto sum = std::get<ParsedData::Sum>(d.val);