Skip to content

Commit 2c273c4

Browse files
authored
Merge pull request #41359 from nkcsgexi/refactor-abi-desc
2 parents 0e7af7a + 3ef8165 commit 2c273c4

File tree

5 files changed

+3912
-3887
lines changed

5 files changed

+3912
-3887
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ namespace api {
6363
///
6464
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
6565
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
66-
const uint8_t DIGESTER_JSON_VERSION = 6; // Add initkind for constructors
66+
const uint8_t DIGESTER_JSON_VERSION = 7; // push SDKNodeRoot to lower-level
6767
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.
68+
const StringRef ABIRootKey = "ABIRoot";
6869

6970
class SDKNode;
7071
typedef SDKNode* NodePtr;
@@ -827,4 +828,13 @@ void nodeSetDifference(ArrayRef<SDKNode*> Left, ArrayRef<SDKNode*> Right,
827828
} // end of ide namespace
828829
} // end of Swift namespace
829830

831+
namespace swift {
832+
namespace json {
833+
template <> struct ObjectTraits<ide::api::SDKNodeRoot> {
834+
static void mapping(Output &out, ide::api::SDKNodeRoot &contents) {
835+
contents.jsonize(out);
836+
}
837+
};
838+
}}
839+
830840
#endif

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
628628
NodeVector Children;
629629
NodeVector Conformances;
630630
NodeVector Accessors;
631+
SDKNode *Result = nullptr;
631632

632633
for (auto &Pair : *Node) {
633634
auto keyString = GetScalarString(Pair.getKey());
@@ -742,14 +743,18 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
742743
break;
743744
}
744745
}
745-
}
746-
else {
746+
} else if (keyString == ABIRootKey) {
747+
Result = constructSDKNode(Ctx,
748+
cast<llvm::yaml::MappingNode>(Pair.getValue()));
749+
} else {
747750
Ctx.diagnose(Pair.getKey(), diag::sdk_node_unrecognized_key,
748751
keyString);
749752
Pair.skip();
750753
}
751754
};
752-
SDKNode *Result = Info.createSDKNode(Kind);
755+
if (Result)
756+
return Result;
757+
Result = Info.createSDKNode(Kind);
753758
for (auto C : Children) {
754759
Result->addChild(C);
755760
}
@@ -2224,7 +2229,11 @@ void SwiftDeclCollector::serialize(StringRef Filename, SDKNode *Root) {
22242229
std::error_code EC;
22252230
llvm::raw_fd_ostream fs(Filename, EC, llvm::sys::fs::OF_None);
22262231
json::Output yout(fs);
2227-
yout << Root;
2232+
assert(Root->getKind() == SDKNodeKind::Root);
2233+
SDKNodeRoot &root = *static_cast<SDKNodeRoot*>(Root);
2234+
yout.beginObject();
2235+
yout.mapRequired(ABIRootKey, root);
2236+
yout.endObject();
22282237
}
22292238

22302239
// Serialize the content of all roots to a given file using JSON format.

0 commit comments

Comments
 (0)