ABIChecker: include module name explicitly in generated ABI baseline. NFC

This commit is contained in:
Xi Ge
2023-09-15 11:03:43 -07:00
parent 83f8454248
commit 95d73171ae
6 changed files with 33 additions and 22 deletions

View File

@@ -438,7 +438,7 @@ class SDKNodeRoot: public SDKNode {
uint8_t JsonFormatVer;
public:
SDKNodeRoot(SDKNodeInitInfo Info);
static SDKNode *getInstance(SDKContext &Ctx);
static SDKNode *getInstance(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules);
static bool classof(const SDKNode *N);
void registerDescendant(SDKNode *D);
virtual void jsonize(json::Output &Out) override;
@@ -777,8 +777,7 @@ public:
void visitAllRoots(SDKNodeVisitor &Visitor) {
SDKNode::preorderVisit(RootNode, Visitor);
}
SwiftDeclCollector(SDKContext &Ctx) : Ctx(Ctx),
RootNode(SDKNodeRoot::getInstance(Ctx)) {}
SwiftDeclCollector(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules = {});
// Construct all roots vector from a given file where a forest was
// previously dumped.
@@ -818,8 +817,6 @@ public:
void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
DynamicLookupInfo dynamicLookupInfo = {}) override;
void processDecl(Decl *D);
public:
void lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules);
};
void detectRename(SDKNode *L, SDKNode *R);

View File

@@ -428,10 +428,17 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
llvm_unreachable("Unhandled SDKNodeKind in switch");
}
SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx) {
SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules) {
SDKNodeInitInfo Info(Ctx);
Info.Name = Ctx.buffer("TopLevel");
Info.PrintedName = Ctx.buffer("TopLevel");
StringRef name = Ctx.buffer("NO_MODULE");
if (modules.size() == 1) {
// use the module name
name = Ctx.buffer(modules[0]->getName().str());
} else if (!modules.empty()) {
name = Ctx.buffer("MULTI_MODULES");
}
Info.Name = name;
Info.PrintedName = name;
llvm::transform(Ctx.getOpts().ToolArgs, std::back_inserter(Info.ToolArgs),
[&](std::string s) { return Ctx.buffer(s); });
Info.JsonFormatVer = DIGESTER_JSON_VERSION;
@@ -1976,8 +1983,13 @@ void SwiftDeclCollector::printTopLevelNames() {
llvm::outs() << Node->getKind() << ": " << Node->getName() << '\n';
}
}
void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
SwiftDeclCollector::SwiftDeclCollector(SDKContext &Ctx,
ArrayRef<ModuleDecl*> Modules) : Ctx(Ctx),
RootNode(SDKNodeRoot::getInstance(Ctx, Modules)) {
if (Modules.empty()) {
return;
}
assert(!Modules.empty());
for (auto M: Modules) {
llvm::SmallVector<Decl*, 512> Decls;
swift::getTopLevelDeclsForDisplay(M, Decls);
@@ -2544,8 +2556,7 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
if (Opts.Verbose)
llvm::errs() << "Scanning symbols...\n";
SwiftDeclCollector Collector(SDKCtx);
Collector.lookupVisibleDecls(Modules);
SwiftDeclCollector Collector(SDKCtx, Modules);
return Collector.getSDKRoot();
}
@@ -2603,7 +2614,11 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
opts.SkipRemoveDeprecatedCheck = false;
opts.Verbose = false;
SDKContext ctx(opts);
SwiftDeclCollector collector(ctx);
llvm::SmallVector<ModuleDecl*, 4> modules;
if (!Empty) {
modules.push_back(MD);
}
SwiftDeclCollector collector(ctx, modules);
ConstExtractor extractor(ctx, MD->getASTContext());
PayLoad payload;
SWIFT_DEFER {
@@ -2613,7 +2628,6 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
if (Empty) {
return;
}
collector.lookupVisibleDecls({MD});
extractor.extract(MD);
}

View File

@@ -26,6 +26,6 @@
// RUN: %FileCheck %s < %t/Foo-c.json
// CHECK: "kind": "Root"
// CHECK-NEXT: "name": "TopLevel"
// CHECK-NEXT: "printedName": "TopLevel"
// CHECK-NEXT: "name":
// CHECK-NEXT: "printedName":
// CHECK: "kind": "Function"

View File

@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "cake",
"printedName": "cake",
"children": [
{
"kind": "Import",

View File

@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "cake",
"printedName": "cake",
"children": [
{
"kind": "Import",

View File

@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "NO_MODULE",
"printedName": "NO_MODULE",
"json_format_version": 8
}
}