Skip to content

ABI checker: refactor the format of the ABI descriptor JSON to be more extensible. NFC #41359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/swift/APIDigester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ namespace api {
///
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
const uint8_t DIGESTER_JSON_VERSION = 6; // Add initkind for constructors
const uint8_t DIGESTER_JSON_VERSION = 7; // push SDKNodeRoot to lower-level
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.
const StringRef ABIRootKey = "ABIRoot";

class SDKNode;
typedef SDKNode* NodePtr;
Expand Down Expand Up @@ -827,4 +828,13 @@ void nodeSetDifference(ArrayRef<SDKNode*> Left, ArrayRef<SDKNode*> Right,
} // end of ide namespace
} // end of Swift namespace

namespace swift {
namespace json {
template <> struct ObjectTraits<ide::api::SDKNodeRoot> {
static void mapping(Output &out, ide::api::SDKNodeRoot &contents) {
contents.jsonize(out);
}
};
}}

#endif
17 changes: 13 additions & 4 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
NodeVector Children;
NodeVector Conformances;
NodeVector Accessors;
SDKNode *Result = nullptr;

for (auto &Pair : *Node) {
auto keyString = GetScalarString(Pair.getKey());
Expand Down Expand Up @@ -742,14 +743,18 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
break;
}
}
}
else {
} else if (keyString == ABIRootKey) {
Result = constructSDKNode(Ctx,
cast<llvm::yaml::MappingNode>(Pair.getValue()));
} else {
Ctx.diagnose(Pair.getKey(), diag::sdk_node_unrecognized_key,
keyString);
Pair.skip();
}
};
SDKNode *Result = Info.createSDKNode(Kind);
if (Result)
return Result;
Result = Info.createSDKNode(Kind);
for (auto C : Children) {
Result->addChild(C);
}
Expand Down Expand Up @@ -2224,7 +2229,11 @@ void SwiftDeclCollector::serialize(StringRef Filename, SDKNode *Root) {
std::error_code EC;
llvm::raw_fd_ostream fs(Filename, EC, llvm::sys::fs::OF_None);
json::Output yout(fs);
yout << Root;
assert(Root->getKind() == SDKNodeKind::Root);
SDKNodeRoot &root = *static_cast<SDKNodeRoot*>(Root);
yout.beginObject();
yout.mapRequired(ABIRootKey, root);
yout.endObject();
}

// Serialize the content of all roots to a given file using JSON format.
Expand Down
Loading