mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
db93feb180
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.
143 lines
5.0 KiB
TOML
143 lines
5.0 KiB
TOML
includes = ["memory", "optional"]
|
|
|
|
definitions = '''
|
|
struct IncompleteType;
|
|
struct IncompleteTypeContainer {
|
|
IncompleteType *ptrundef;
|
|
// std::unique_ptr<IncompleteType> unundef; // std::unique_ptr requires its template param to have a size
|
|
char __makePad1;
|
|
std::shared_ptr<IncompleteType> shundef;
|
|
char __makePad2;
|
|
std::optional<std::shared_ptr<IncompleteType>> shoptundef;
|
|
char __makePad3;
|
|
std::optional<IncompleteType *> optundef;
|
|
};
|
|
|
|
void incomplete_type_deleter(IncompleteType *ptr) {
|
|
::operator delete(ptr);
|
|
}
|
|
'''
|
|
[cases]
|
|
[cases.raw]
|
|
oil_disable = "oil can't chase raw pointers safely"
|
|
oid_skip = "oid codegen fails on this" # https://github.com/facebookexperimental/object-introspection/issues/17
|
|
param_types = ["IncompleteType*"]
|
|
setup = "return static_cast<IncompleteType*>(::operator new(5));"
|
|
cli_options = ["-fchase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"typeName": "IncompleteType *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.raw_no_follow]
|
|
skip = "oid codegen fails on this" # https://github.com/facebookexperimental/object-introspection/issues/17
|
|
param_types = ["IncompleteType*"]
|
|
setup = "return static_cast<IncompleteType*>(::operator new(5));"
|
|
expect_json = '''[{
|
|
"typeName": "IncompleteType *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.raw_null]
|
|
skip = "oid codegen fails on this" # https://github.com/facebookexperimental/object-introspection/issues/17
|
|
param_types = ["IncompleteType*"]
|
|
setup = "return nullptr;"
|
|
expect_json = '''[{
|
|
"typeName": "IncompleteType *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"pointer": 0,
|
|
"NOT": "members"
|
|
}]'''
|
|
|
|
[cases.unique_ptr]
|
|
param_types = ["const std::unique_ptr<IncompleteType, decltype(&incomplete_type_deleter)>&"]
|
|
setup = '''
|
|
auto raw_ptr = static_cast<IncompleteType*>(::operator new(5));
|
|
return std::unique_ptr<IncompleteType, decltype(&incomplete_type_deleter)>(
|
|
raw_ptr, &incomplete_type_deleter);
|
|
'''
|
|
expect_json = '[{"staticSize":16, "dynamicSize":0, "NOT":"members"}]'
|
|
expect_json_v2 = '[{"staticSize":16, "exclusiveSize":16}]'
|
|
[cases.unique_ptr_null]
|
|
param_types = ["const std::unique_ptr<IncompleteType, decltype(&incomplete_type_deleter)>&"]
|
|
setup = '''
|
|
return std::unique_ptr<IncompleteType, decltype(&incomplete_type_deleter)>(
|
|
nullptr, &incomplete_type_deleter);
|
|
'''
|
|
expect_json = '[{"staticSize":16, "dynamicSize":0, "NOT":"members"}]'
|
|
expect_json_v2 = '[{"staticSize":16, "exclusiveSize":16}]'
|
|
|
|
[cases.shared_ptr]
|
|
param_types = ["const std::shared_ptr<IncompleteType>&"]
|
|
setup = '''
|
|
auto raw_ptr = static_cast<IncompleteType*>(::operator new(5));
|
|
return std::shared_ptr<IncompleteType>(raw_ptr , &incomplete_type_deleter);
|
|
'''
|
|
expect_json = '[{"staticSize":16, "dynamicSize":0, "NOT":"members"}]'
|
|
expect_json_v2 = '[{"staticSize":16, "exclusiveSize":16}]'
|
|
[cases.shared_ptr_null]
|
|
param_types = ["const std::shared_ptr<IncompleteType>"]
|
|
setup = "return nullptr;"
|
|
expect_json = '[{"staticSize":16, "dynamicSize":0, "NOT":"members"}]'
|
|
expect_json_v2 = '[{"staticSize":16, "exclusiveSize":16}]'
|
|
|
|
[cases.containing_struct]
|
|
oil_disable = "oil can't chase raw pointers safely"
|
|
param_types = ["const IncompleteTypeContainer&"]
|
|
setup = "return IncompleteTypeContainer{};"
|
|
cli_options = ["-fchase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize": 88,
|
|
"dynamicSize": 0,
|
|
"members": [
|
|
{ "name": "ptrundef", "staticSize": 8, "dynamicSize": 0 },
|
|
{ "name": "__makePad1", "staticSize": 1, "dynamicSize": 0 },
|
|
{ "name": "shundef", "staticSize": 16, "dynamicSize": 0 },
|
|
{ "name": "__makePad2", "staticSize": 1, "dynamicSize": 0 },
|
|
{ "name": "shoptundef",
|
|
"staticSize": 24,
|
|
"dynamicSize": 0,
|
|
"length": 0,
|
|
"capacity": 1,
|
|
"elementStaticSize": 16
|
|
},
|
|
{ "name": "__makePad3", "staticSize": 1, "dynamicSize": 0 },
|
|
{ "name": "optundef",
|
|
"staticSize": 16,
|
|
"dynamicSize": 0,
|
|
"length": 0,
|
|
"capacity": 1,
|
|
"elementStaticSize": 8
|
|
}
|
|
]
|
|
}]'''
|
|
|
|
[cases.containing_struct_no_follow]
|
|
param_types = ["const IncompleteTypeContainer&"]
|
|
setup = "return IncompleteTypeContainer{};"
|
|
expect_json = '''[{
|
|
"staticSize": 88,
|
|
"members": [
|
|
{ "name": "ptrundef", "staticSize": 8 },
|
|
{ "name": "__makePad1", "staticSize": 1 },
|
|
{ "name": "shundef", "staticSize": 16 },
|
|
{ "name": "__makePad2", "staticSize": 1 },
|
|
{ "name": "shoptundef",
|
|
"staticSize": 24,
|
|
"length": 0,
|
|
"capacity": 1
|
|
},
|
|
{ "name": "__makePad3", "staticSize": 1 },
|
|
{ "name": "optundef",
|
|
"staticSize": 16,
|
|
"length": 0,
|
|
"capacity": 1
|
|
}
|
|
]
|
|
}]'''
|