mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
tbv2: add is_primitive to output
C++ has a concept of Primitive which holds in the type graph. However we don't currently expose this information to the end user. Expose this from the OIL iterator to allow future features like primitive rollups. This affects containers like maps which have a fake `[]` element with no type. They use this to group together the key/value in a map and to account for any per element storage overhead. Currently the decision is to make the fake `[]` element a primitive if all of its children are primitives. This allows for more effective primitive rollups if that is implemented. This implementation detail may be changed in future. Test Plan: - CI - Updated simple tests.
This commit is contained in:
parent
16fcba20bc
commit
4c047b5f91
@ -98,8 +98,8 @@ inline void Json::printStringField(std::string_view name,
|
|||||||
inline void Json::printBoolField(std::string_view name,
|
inline void Json::printBoolField(std::string_view name,
|
||||||
bool value,
|
bool value,
|
||||||
std::string_view indent) {
|
std::string_view indent) {
|
||||||
out_ << tab() << '"' << name << "\":" << space() << value << ',' << endl()
|
out_ << tab() << '"' << name << "\":" << space() << (value ? "true" : "false")
|
||||||
<< indent;
|
<< ',' << endl() << indent;
|
||||||
}
|
}
|
||||||
inline void Json::printUnsignedField(std::string_view name,
|
inline void Json::printUnsignedField(std::string_view name,
|
||||||
uint64_t value,
|
uint64_t value,
|
||||||
@ -159,6 +159,7 @@ inline void Json::printFields(const result::Element& el,
|
|||||||
}
|
}
|
||||||
if (el.is_set_stats.has_value())
|
if (el.is_set_stats.has_value())
|
||||||
printUnsignedField("is_set", el.is_set_stats->is_set, indent);
|
printUnsignedField("is_set", el.is_set_stats->is_set, indent);
|
||||||
|
printBoolField("is_primitive", el.is_primitive, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename It>
|
template <typename It>
|
||||||
|
@ -58,19 +58,22 @@ struct Field {
|
|||||||
std::string_view name_,
|
std::string_view name_,
|
||||||
const std::array<std::string_view, N0>& type_names_,
|
const std::array<std::string_view, N0>& type_names_,
|
||||||
const std::array<Field, N1>& fields_,
|
const std::array<Field, N1>& fields_,
|
||||||
const std::array<ProcessorInst, N2>& processors_);
|
const std::array<ProcessorInst, N2>& processors_,
|
||||||
|
bool is_primitive_);
|
||||||
template <size_t N0, size_t N1, size_t N2>
|
template <size_t N0, size_t N1, size_t N2>
|
||||||
constexpr Field(size_t static_size_,
|
constexpr Field(size_t static_size_,
|
||||||
std::string_view name_,
|
std::string_view name_,
|
||||||
const std::array<std::string_view, N0>& type_names_,
|
const std::array<std::string_view, N0>& type_names_,
|
||||||
const std::array<Field, N1>& fields_,
|
const std::array<Field, N1>& fields_,
|
||||||
const std::array<ProcessorInst, N2>& processors_)
|
const std::array<ProcessorInst, N2>& processors_,
|
||||||
|
bool is_primitive_)
|
||||||
: Field(static_size_,
|
: Field(static_size_,
|
||||||
static_size_,
|
static_size_,
|
||||||
name_,
|
name_,
|
||||||
type_names_,
|
type_names_,
|
||||||
fields_,
|
fields_,
|
||||||
processors_) {
|
processors_,
|
||||||
|
is_primitive_) {
|
||||||
}
|
}
|
||||||
constexpr Field(const Field&) = default; // no idea why this is needed
|
constexpr Field(const Field&) = default; // no idea why this is needed
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ struct Field {
|
|||||||
std::span<const std::string_view> type_names;
|
std::span<const std::string_view> type_names;
|
||||||
std::span<const Field> fields;
|
std::span<const Field> fields;
|
||||||
std::span<const ProcessorInst> processors;
|
std::span<const ProcessorInst> processors;
|
||||||
|
bool is_primitive;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t N0, size_t N1, size_t N2>
|
template <size_t N0, size_t N1, size_t N2>
|
||||||
@ -88,13 +92,15 @@ constexpr Field::Field(size_t static_size_,
|
|||||||
std::string_view name_,
|
std::string_view name_,
|
||||||
const std::array<std::string_view, N0>& type_names_,
|
const std::array<std::string_view, N0>& type_names_,
|
||||||
const std::array<Field, N1>& fields_,
|
const std::array<Field, N1>& fields_,
|
||||||
const std::array<ProcessorInst, N2>& processors_)
|
const std::array<ProcessorInst, N2>& processors_,
|
||||||
|
bool is_primitive_)
|
||||||
: static_size(static_size_),
|
: static_size(static_size_),
|
||||||
exclusive_size(exclusive_size_),
|
exclusive_size(exclusive_size_),
|
||||||
name(name_),
|
name(name_),
|
||||||
type_names(type_names_),
|
type_names(type_names_),
|
||||||
fields(fields_),
|
fields(fields_),
|
||||||
processors(processors_) {
|
processors(processors_),
|
||||||
|
is_primitive(is_primitive_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace oi::exporters::inst
|
} // namespace oi::exporters::inst
|
||||||
|
@ -52,6 +52,7 @@ struct Element {
|
|||||||
std::nullopt};
|
std::nullopt};
|
||||||
std::optional<ContainerStats> container_stats;
|
std::optional<ContainerStats> container_stats;
|
||||||
std::optional<IsSetStats> is_set_stats;
|
std::optional<IsSetStats> is_set_stats;
|
||||||
|
bool is_primitive;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace oi::result
|
} // namespace oi::result
|
||||||
|
@ -798,12 +798,15 @@ void CodeGen::genClassTreeBuilderInstructions(const Class& c,
|
|||||||
if (m.name.starts_with(AddPadding::MemberPrefix))
|
if (m.name.starts_with(AddPadding::MemberPrefix))
|
||||||
continue;
|
continue;
|
||||||
std::string fullName = c.name() + "::" + m.name;
|
std::string fullName = c.name() + "::" + m.name;
|
||||||
|
bool isPrimitive = dynamic_cast<const Primitive*>(&m.type());
|
||||||
code += " inst::Field{sizeof(" + fullName + "), " +
|
code += " inst::Field{sizeof(" + fullName + "), " +
|
||||||
std::to_string(calculateExclusiveSize(m.type())) + ",\"" +
|
std::to_string(calculateExclusiveSize(m.type())) + ",\"" +
|
||||||
m.inputName + "\", member_" + std::to_string(index) +
|
m.inputName + "\", member_" + std::to_string(index) +
|
||||||
"_type_names, TypeHandler<Ctx, decltype(" + fullName +
|
"_type_names, TypeHandler<Ctx, decltype(" + fullName +
|
||||||
")>::fields, TypeHandler<Ctx, decltype(" + fullName +
|
")>::fields, TypeHandler<Ctx, decltype(" + fullName +
|
||||||
")>::processors},\n";
|
")>::processors, ";
|
||||||
|
code += isPrimitive ? "true" : "false";
|
||||||
|
code += "},\n";
|
||||||
}
|
}
|
||||||
code += " };\n";
|
code += " };\n";
|
||||||
code +=
|
code +=
|
||||||
@ -1074,6 +1077,7 @@ constexpr inst::Field make_field(std::string_view name) {
|
|||||||
NameProvider<T>::names,
|
NameProvider<T>::names,
|
||||||
TypeHandler<Ctx, T>::fields,
|
TypeHandler<Ctx, T>::fields,
|
||||||
TypeHandler<Ctx, T>::processors,
|
TypeHandler<Ctx, T>::processors,
|
||||||
|
std::is_fundamental_v<T>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
@ -399,7 +399,8 @@ const std::array<std::string_view, )";
|
|||||||
", OIInternal::TypeHandler<FakeContext, "
|
", OIInternal::TypeHandler<FakeContext, "
|
||||||
"OIInternal::__ROOT_TYPE__>::fields, "
|
"OIInternal::__ROOT_TYPE__>::fields, "
|
||||||
"OIInternal::TypeHandler<FakeContext, "
|
"OIInternal::TypeHandler<FakeContext, "
|
||||||
"OIInternal::__ROOT_TYPE__>::processors};\n";
|
"OIInternal::__ROOT_TYPE__>::processors, "
|
||||||
|
"std::is_fundamental_v<OIInternal::__ROOT_TYPE__>};\n";
|
||||||
code += "} // namespace\n";
|
code += "} // namespace\n";
|
||||||
code +=
|
code +=
|
||||||
"extern const exporters::inst::Inst __attribute__((used, retain)) "
|
"extern const exporters::inst::Inst __attribute__((used, retain)) "
|
||||||
@ -640,13 +641,7 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) {
|
|||||||
}
|
}
|
||||||
static void process_pointer_content(result::Element& el, std::function<void(inst::Inst)> stack_ins, ParsedData d) {
|
static void process_pointer_content(result::Element& el, std::function<void(inst::Inst)> stack_ins, ParsedData d) {
|
||||||
static constexpr std::array<std::string_view, 1> names{"TODO"};
|
static constexpr std::array<std::string_view, 1> names{"TODO"};
|
||||||
static constexpr auto childField = inst::Field{
|
static constexpr auto childField = make_field<Ctx, T>("*");
|
||||||
sizeof(T),
|
|
||||||
"*",
|
|
||||||
names,
|
|
||||||
TypeHandler<Ctx, T>::fields,
|
|
||||||
TypeHandler<Ctx, T>::processors,
|
|
||||||
};
|
|
||||||
|
|
||||||
const ParsedData::Sum& sum = std::get<ParsedData::Sum>(d.val);
|
const ParsedData::Sum& sum = std::get<ParsedData::Sum>(d.val);
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ IntrospectionResult::const_iterator::operator++() {
|
|||||||
.exclusive_size = ty.exclusive_size,
|
.exclusive_size = ty.exclusive_size,
|
||||||
.container_stats = std::nullopt,
|
.container_stats = std::nullopt,
|
||||||
.is_set_stats = std::nullopt,
|
.is_set_stats = std::nullopt,
|
||||||
|
.is_primitive = ty.is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto& [dy, handler] : ty.processors) {
|
for (const auto& [dy, handler] : ty.processors) {
|
||||||
|
@ -24,12 +24,21 @@ definitions = '''
|
|||||||
"staticSize":16,
|
"staticSize":16,
|
||||||
"dynamicSize":0,
|
"dynamicSize":0,
|
||||||
"exclusiveSize": 3,
|
"exclusiveSize": 3,
|
||||||
"size": 16,
|
|
||||||
"members":[
|
"members":[
|
||||||
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize": 4, "size": 4},
|
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize": 4, "size": 4},
|
||||||
{"name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize": 1, "size": 1},
|
{"name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize": 1, "size": 1},
|
||||||
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize": 8, "size": 8}
|
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize": 8, "size": 8}
|
||||||
]}]'''
|
]}]'''
|
||||||
|
expect_json_v2 = '''[{
|
||||||
|
"staticSize":16,
|
||||||
|
"exclusiveSize": 3,
|
||||||
|
"size": 16,
|
||||||
|
"is_primitive": false,
|
||||||
|
"members":[
|
||||||
|
{"name":"a", "staticSize":4, "exclusiveSize": 4, "size": 4, "is_primitive": true},
|
||||||
|
{"name":"b", "staticSize":1, "exclusiveSize": 1, "size": 1, "is_primitive": true},
|
||||||
|
{"name":"c", "staticSize":8, "exclusiveSize": 8, "size": 8, "is_primitive": true}
|
||||||
|
]}]'''
|
||||||
[cases.class]
|
[cases.class]
|
||||||
param_types = ["const SimpleClass&"]
|
param_types = ["const SimpleClass&"]
|
||||||
setup = "return {};"
|
setup = "return {};"
|
||||||
@ -37,18 +46,32 @@ definitions = '''
|
|||||||
"staticSize":16,
|
"staticSize":16,
|
||||||
"dynamicSize":0,
|
"dynamicSize":0,
|
||||||
"exclusiveSize": 3,
|
"exclusiveSize": 3,
|
||||||
"size": 16,
|
|
||||||
"members":[
|
"members":[
|
||||||
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize": 4, "size": 4},
|
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize": 4, "size": 4},
|
||||||
{"name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize": 1, "size": 1},
|
{"name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize": 1, "size": 1},
|
||||||
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize": 8, "size": 8}
|
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize": 8, "size": 8}
|
||||||
]}]'''
|
]}]'''
|
||||||
|
expect_json_v2 = '''[{
|
||||||
|
"staticSize":16,
|
||||||
|
"exclusiveSize": 3,
|
||||||
|
"size": 16,
|
||||||
|
"is_primitive": false,
|
||||||
|
"members":[
|
||||||
|
{"name":"a", "staticSize":4, "exclusiveSize": 4, "size": 4, "is_primitive": true},
|
||||||
|
{"name":"b", "staticSize":1, "exclusiveSize": 1, "size": 1, "is_primitive": true},
|
||||||
|
{"name":"c", "staticSize":8, "exclusiveSize": 8, "size": 8, "is_primitive": true}
|
||||||
|
]}]'''
|
||||||
[cases.union]
|
[cases.union]
|
||||||
param_types = ["const SimpleUnion&"]
|
param_types = ["const SimpleUnion&"]
|
||||||
setup = "return {};"
|
setup = "return {};"
|
||||||
expect_json = '''[{
|
expect_json = '''[{
|
||||||
"staticSize":8,
|
"staticSize":8,
|
||||||
"dynamicSize":0,
|
"dynamicSize":0,
|
||||||
"exclusiveSize":8,
|
"exclusiveSize":8
|
||||||
"size":8
|
}]'''
|
||||||
|
expect_json_v2 = '''[{
|
||||||
|
"staticSize":8,
|
||||||
|
"exclusiveSize":8,
|
||||||
|
"size":8,
|
||||||
|
"is_primitive":false
|
||||||
}]'''
|
}]'''
|
||||||
|
@ -95,6 +95,7 @@ static constexpr inst::Field element{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
@ -95,6 +95,7 @@ static constexpr inst::Field element{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
@ -95,6 +95,7 @@ static constexpr inst::Field element{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
@ -95,6 +95,7 @@ static constexpr inst::Field element{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
@ -91,6 +91,7 @@ static constexpr auto entry = inst::Field {
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
entryFields,
|
entryFields,
|
||||||
processors,
|
processors,
|
||||||
|
entryFields[0].is_primitive && entryFields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto list = std::get<ParsedData::List>(d.val);
|
auto list = std::get<ParsedData::List>(d.val);
|
||||||
|
@ -118,6 +118,7 @@ static constexpr auto element = inst::Field {
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
elementFields,
|
elementFields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
elementFields[0].is_primitive && elementFields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto list = std::get<ParsedData::List>(d.val);
|
auto list = std::get<ParsedData::List>(d.val);
|
||||||
|
@ -135,6 +135,7 @@ static constexpr inst::Field element{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
processors,
|
processors,
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto list = std::get<ParsedData::List>(d.val);
|
auto list = std::get<ParsedData::List>(d.val);
|
||||||
|
@ -135,6 +135,7 @@ static constexpr auto element = inst::Field{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
processors,
|
processors,
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
@ -121,6 +121,7 @@ static constexpr auto element = inst::Field{
|
|||||||
std::array<std::string_view, 0>{},
|
std::array<std::string_view, 0>{},
|
||||||
element_fields,
|
element_fields,
|
||||||
std::array<inst::ProcessorInst, 0>{},
|
std::array<inst::ProcessorInst, 0>{},
|
||||||
|
element_fields[0].is_primitive && element_fields[1].is_primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < list.length; i++)
|
for (size_t i = 0; i < list.length; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user