Skip to content

Commit

Permalink
clang-format: disable bin packing
Browse files Browse the repository at this point in the history
Bin packing often makes code hard to read. Disable it entirely.

Test plan:
- CI
  • Loading branch information
JakeHillion committed Nov 13, 2023
1 parent c207972 commit 393f8aa
Show file tree
Hide file tree
Showing 45 changed files with 668 additions and 358 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false
PointerAlignment: Left
BinPackParameters: false
BinPackArguments: false
15 changes: 11 additions & 4 deletions include/oi/exporters/CSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ class CSV {
static constexpr std::string_view kEscapedQuote = "\\\"";
static constexpr std::string_view kListDelimiter = ";";

static constexpr std::string_view kColumns[] = {
"id", "name", "typePath", "typeNames",
"staticSize", "exclusiveSize", "pointer", "length",
"capacity", "is_set", "parent_id"};
static constexpr std::string_view kColumns[] = {"id",
"name",
"typePath",
"typeNames",
"staticSize",
"exclusiveSize",
"pointer",
"length",
"capacity",
"is_set",
"parent_id"};

size_t id_ = 0;
std::vector<size_t> parentIdStack_ = {0};
Expand Down
32 changes: 19 additions & 13 deletions oi/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ namespace {

size_t calculateExclusiveSize(const Type& t) {
if (const auto* c = dynamic_cast<const Class*>(&t)) {
return std::accumulate(c->members.cbegin(), c->members.cend(), 0,
[](size_t a, const auto& m) {
if (m.name.starts_with(AddPadding::MemberPrefix))
return a + m.type().size();
return a;
});
return std::accumulate(
c->members.cbegin(), c->members.cend(), 0, [](size_t a, const auto& m) {
if (m.name.starts_with(AddPadding::MemberPrefix))
return a + m.type().size();
return a;
});
}
return t.size();
}
Expand Down Expand Up @@ -1087,8 +1087,8 @@ constexpr inst::Field make_field(std::string_view name) {
TemplateParam{typeGraph.makeType<Primitive>(Primitive::Kind::UInt64),
"0"},
};
genContainerTypeHandler(features, used, FuncGen::GetOiArrayContainerInfo(),
arrayParams, code);
genContainerTypeHandler(
features, used, FuncGen::GetOiArrayContainerInfo(), arrayParams, code);
}

} // namespace
Expand All @@ -1098,12 +1098,17 @@ void CodeGen::addTypeHandlers(const TypeGraph& typeGraph, std::string& code) {
if (const auto* c = dynamic_cast<const Class*>(&t)) {
genClassTypeHandler(*c, code);
} else if (const auto* con = dynamic_cast<const Container*>(&t)) {
genContainerTypeHandler(config_.features, definedContainers_,
con->containerInfo_, con->templateParams, code);
genContainerTypeHandler(config_.features,
definedContainers_,
con->containerInfo_,
con->templateParams,
code);
} else if (const auto* cap = dynamic_cast<const CaptureKeys*>(&t)) {
genContainerTypeHandler(config_.features, definedContainers_,
genContainerTypeHandler(config_.features,
definedContainers_,
cap->containerInfo(),
cap->container().templateParams, code);
cap->container().templateParams,
code);
}
}
}
Expand Down Expand Up @@ -1301,7 +1306,8 @@ void CodeGen::generate(
}

if (config_.features[Feature::TreeBuilderV2]) {
FuncGen::DefineTreeBuilderInstructions(code, typeName,
FuncGen::DefineTreeBuilderInstructions(code,
typeName,
calculateExclusiveSize(rootType),
enumerateTypeNames(rootType));
} else if (config_.features[Feature::TreeBuilderTypeChecking]) {
Expand Down
8 changes: 4 additions & 4 deletions oi/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ std::optional<FeatureSet> processConfigFile(
auto* members = (*captureKeys)["members"].as_array();
if (!members) {
generatorConfig.keysToCapture.push_back(
OICodeGen::Config::KeyToCapture{type->value_or(""), "*",
false});
OICodeGen::Config::KeyToCapture{
type->value_or(""), "*", false});
} else {
for (auto&& member : *members) {
generatorConfig.keysToCapture.push_back(
Expand All @@ -226,8 +226,8 @@ std::optional<FeatureSet> processConfigFile(
}
} else if (topLevel) {
generatorConfig.keysToCapture.push_back(
OICodeGen::Config::KeyToCapture{std::nullopt, std::nullopt,
true});
OICodeGen::Config::KeyToCapture{
std::nullopt, std::nullopt, true});
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions oi/ContainerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ ContainerInfo::ContainerInfo(std::string typeName_,
matcher(getMatcher(typeName)),
ctype(ctype_),
header(std::move(header_)),
codegen(Codegen{"// DummyDecl %1%\n", "// DummyFunc %1%\n",
"// DummyHandler %1%\n", "// DummyFunc\n"}) {
codegen(Codegen{"// DummyDecl %1%\n",
"// DummyFunc %1%\n",
"// DummyHandler %1%\n",
"// DummyFunc\n"}) {
}
3 changes: 2 additions & 1 deletion oi/FuncGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ void FuncGen::DefineBasicTypeHandlers(std::string& code, FeatureSet features) {
}

ContainerInfo FuncGen::GetOiArrayContainerInfo() {
ContainerInfo oiArray{"OIArray", UNKNOWN_TYPE,
ContainerInfo oiArray{"OIArray",
UNKNOWN_TYPE,
"cstdint"}; // TODO: remove the need for a dummy header

oiArray.codegen.handler = R"(
Expand Down
7 changes: 5 additions & 2 deletions oi/Metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ void Tracing::stop() {

std::lock_guard<std::mutex> guard{static_.mutex};
// Can't use emplace_back() because of old clang++ on CI
static_.traces.push_back({getNextIndex(), std::move(traceName),
duration.count(), rssBeforeBytes, rssAfterBytes});
static_.traces.push_back({getNextIndex(),
std::move(traceName),
duration.count(),
rssBeforeBytes,
rssAfterBytes});
}

void Tracing::saveTraces(const std::filesystem::path& output) {
Expand Down
93 changes: 58 additions & 35 deletions oi/OICodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ std::string OICodeGen::preProcessUniquePtr(drgn_type* type, std::string name) {
} else if (typeSize == cFunctionDeleterSize) {
name.replace(begin, end - begin + 1, "void(*)(" + typeName + "*)");
} else if (typeSize == stdFunctionDeleterSize) {
name.replace(begin, end - begin + 1,
"std::function<void (" + typeName + "*)>");
name.replace(
begin, end - begin + 1, "std::function<void (" + typeName + "*)>");
} else {
LOG(ERROR) << "Unhandled case, unique_ptr size: " << typeSize;
}
Expand Down Expand Up @@ -540,8 +540,8 @@ bool OICodeGen::buildNameInt(drgn_type* type,
templateParamsStrings.push_back(templateParamName);
}

replaceTemplateParameters(type, templateParams, templateParamsStrings,
nameWithoutTemplate);
replaceTemplateParameters(
type, templateParams, templateParamsStrings, nameWithoutTemplate);

outName = nameWithoutTemplate;
for (size_t i = 0; i < templateParamsStrings.size(); ++i) {
Expand Down Expand Up @@ -765,8 +765,9 @@ bool OICodeGen::enumerateTemplateParamIdxs(drgn_type* type,

auto& templateTypes =
containerTypeMapDrgn
.emplace(type, std::pair(std::ref(containerInfo),
std::vector<drgn_qualified_type>()))
.emplace(type,
std::pair(std::ref(containerInfo),
std::vector<drgn_qualified_type>()))
.first->second.second;

for (auto i : paramIdxs) {
Expand Down Expand Up @@ -1721,8 +1722,8 @@ void OICodeGen::enumerateDescendants(drgn_type* type, drgn_type* baseType) {

// TODO this list may end up containing duplicates
const auto& children = it->second;
descendantClasses[baseType].insert(descendantClasses[baseType].end(),
children.begin(), children.end());
descendantClasses[baseType].insert(
descendantClasses[baseType].end(), children.begin(), children.end());

for (const auto& child : children) {
enumerateDescendants(child, baseType);
Expand Down Expand Up @@ -1878,7 +1879,8 @@ void OICodeGen::memberTransformName(
sortedTypes.push_back(e.first);
}

std::sort(sortedTypes.begin(), sortedTypes.end(),
std::sort(sortedTypes.begin(),
sortedTypes.end(),
[](const std::string& first, const std::string& second) {
return first.size() > second.size();
});
Expand Down Expand Up @@ -2212,8 +2214,13 @@ bool OICodeGen::generateStructDef(drgn_type* e, std::string& code) {

uint64_t offsetBits = 0;
std::unordered_map<std::string, int> memberNames;
if (!generateStructMembers(e, memberNames, generatedMembers, offsetBits,
paddingInfo, violatesAlignmentRequirement, 0)) {
if (!generateStructMembers(e,
memberNames,
generatedMembers,
offsetBits,
paddingInfo,
violatesAlignmentRequirement,
0)) {
return false;
}

Expand Down Expand Up @@ -2471,8 +2478,8 @@ std::optional<uint64_t> OICodeGen::generateMember(
currOffsetBits = 0;
VLOG(1) << "Member size: " << memberSize;
} else {
addSizeComment(feature(Feature::GenPaddingStats), code, currOffsetBits,
memberSize);
addSizeComment(
feature(Feature::GenPaddingStats), code, currOffsetBits, memberSize);
currOffsetBits = currOffsetBits + memberSize;
}

Expand All @@ -2499,8 +2506,12 @@ bool OICodeGen::generateParent(
auto* underlyingType = drgn_utils::underlyingType(p);
uint64_t offsetBits = 0;

if (!generateStructMembers(underlyingType, memberNames, code, offsetBits,
paddingInfo, violatesAlignmentRequirement,
if (!generateStructMembers(underlyingType,
memberNames,
code,
offsetBits,
paddingInfo,
violatesAlignmentRequirement,
offsetToNextMember)) {
return false;
}
Expand Down Expand Up @@ -2657,8 +2668,11 @@ bool OICodeGen::generateStructMembers(
size_t prevOffsetBits = currOffsetBits;

auto newCurrOffsetBits =
generateMember(members[memberIndex], memberNames, currOffsetBits,
code, drgn_type_kind(e) == DRGN_TYPE_UNION);
generateMember(members[memberIndex],
memberNames,
currOffsetBits,
code,
drgn_type_kind(e) == DRGN_TYPE_UNION);

if (!newCurrOffsetBits.has_value()) {
return false;
Expand Down Expand Up @@ -2770,8 +2784,11 @@ bool OICodeGen::generateStructMembers(
}
}

if (!generateParent(parentClasses[e][parentIndex].type, memberNames,
currOffsetBits, code, offsetToNextMember)) {
if (!generateParent(parentClasses[e][parentIndex].type,
memberNames,
currOffsetBits,
code,
offsetToNextMember)) {
return false;
}

Expand Down Expand Up @@ -2869,8 +2886,8 @@ bool OICodeGen::generateStructDefs(std::string& code) {
if (parentClassesCopy.find(e) != parentClassesCopy.end()) {
auto& parents = parentClassesCopy[e];
for (auto& p : parents) {
auto it2 = std::find(structDefTypeCopy.begin(),
structDefTypeCopy.end(), p.type);
auto it2 = std::find(
structDefTypeCopy.begin(), structDefTypeCopy.end(), p.type);
if (it2 != structDefTypeCopy.cend()) {
skip = true;
break;
Expand All @@ -2886,7 +2903,8 @@ bool OICodeGen::generateStructDefs(std::string& code) {

if (underlyingType != e) {
auto it2 = std::find(structDefTypeCopy.begin(),
structDefTypeCopy.end(), underlyingType);
structDefTypeCopy.end(),
underlyingType);
if (it2 != structDefTypeCopy.cend()) {
skip = true;
break;
Expand Down Expand Up @@ -3204,8 +3222,8 @@ bool OICodeGen::generateJitCode(std::string& code) {
std::string functionsCode;
functionsCode.append("namespace OIInternal {\nnamespace {\n");
functionsCode.append("// functions -----\n");
if (!funcGen.DeclareGetSizeFuncs(functionsCode, containerTypesFuncDef,
config.features)) {
if (!funcGen.DeclareGetSizeFuncs(
functionsCode, containerTypesFuncDef, config.features)) {
LOG(ERROR) << "declaring get size for containers failed";
return false;
}
Expand Down Expand Up @@ -3235,8 +3253,8 @@ bool OICodeGen::generateJitCode(std::string& code) {
funcGen.DeclareEncodeData(functionsCode);
funcGen.DeclareEncodeDataSize(functionsCode);

if (!funcGen.DefineGetSizeFuncs(functionsCode, containerTypesFuncDef,
config.features)) {
if (!funcGen.DefineGetSizeFuncs(
functionsCode, containerTypesFuncDef, config.features)) {
LOG(ERROR) << "defining get size for containers failed";
return false;
}
Expand Down Expand Up @@ -3289,8 +3307,8 @@ bool OICodeGen::generateJitCode(std::string& code) {
bool generateOffsetAsserts =
(drgn_type_kind(structType) != DRGN_TYPE_UNION);

if (!addStaticAssertsForType(structType, generateOffsetAsserts,
functionsCode)) {
if (!addStaticAssertsForType(
structType, generateOffsetAsserts, functionsCode)) {
return false;
}
}
Expand Down Expand Up @@ -3328,11 +3346,11 @@ bool OICodeGen::generateJitCode(std::string& code) {
if (rootTypeStr.starts_with("unique_ptr") ||
rootTypeStr.starts_with("LowPtr") ||
rootTypeStr.starts_with("shared_ptr")) {
funcGen.DefineTopLevelGetSizeSmartPtr(functionsCode, rawTypeName,
config.features);
funcGen.DefineTopLevelGetSizeSmartPtr(
functionsCode, rawTypeName, config.features);
} else {
funcGen.DefineTopLevelGetSizeRef(functionsCode, rawTypeName,
config.features);
funcGen.DefineTopLevelGetSizeRef(
functionsCode, rawTypeName, config.features);
}
}

Expand Down Expand Up @@ -3593,7 +3611,9 @@ bool OICodeGen::staticAssertMemberOffsets(
// Operate on the underlying type for typedefs
return staticAssertMemberOffsets(struct_name,
drgn_utils::underlyingType(struct_type),
assert_str, memberNames, base_offset);
assert_str,
memberNames,
base_offset);
}

const auto* tag = drgn_type_tag(struct_type);
Expand All @@ -3606,8 +3626,11 @@ bool OICodeGen::staticAssertMemberOffsets(
// Recurse into parents to find inherited members
for (const auto& parent : parentClasses[struct_type]) {
auto parentOffset = base_offset + parent.bit_offset / CHAR_BIT;
if (!staticAssertMemberOffsets(struct_name, parent.type, assert_str,
memberNames, parentOffset)) {
if (!staticAssertMemberOffsets(struct_name,
parent.type,
assert_str,
memberNames,
parentOffset)) {
return false;
}
}
Expand Down
Loading

0 comments on commit 393f8aa

Please sign in to comment.