Skip to content

Commit 6f451b9

Browse files
authored
Merge pull request #68551 from nkcsgexi/module-name-in-baseline
2 parents bb5b77e + 95d7317 commit 6f451b9

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ class SDKNodeRoot: public SDKNode {
438438
uint8_t JsonFormatVer;
439439
public:
440440
SDKNodeRoot(SDKNodeInitInfo Info);
441-
static SDKNode *getInstance(SDKContext &Ctx);
441+
static SDKNode *getInstance(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules);
442442
static bool classof(const SDKNode *N);
443443
void registerDescendant(SDKNode *D);
444444
virtual void jsonize(json::Output &Out) override;
@@ -777,8 +777,7 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
777777
void visitAllRoots(SDKNodeVisitor &Visitor) {
778778
SDKNode::preorderVisit(RootNode, Visitor);
779779
}
780-
SwiftDeclCollector(SDKContext &Ctx) : Ctx(Ctx),
781-
RootNode(SDKNodeRoot::getInstance(Ctx)) {}
780+
SwiftDeclCollector(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules = {});
782781

783782
// Construct all roots vector from a given file where a forest was
784783
// previously dumped.
@@ -818,8 +817,6 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
818817
void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
819818
DynamicLookupInfo dynamicLookupInfo = {}) override;
820819
void processDecl(Decl *D);
821-
public:
822-
void lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules);
823820
};
824821

825822
void detectRename(SDKNode *L, SDKNode *R);

lib/APIDigester/ModuleAnalyzerNodes.cpp

+23-9
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,17 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
428428
llvm_unreachable("Unhandled SDKNodeKind in switch");
429429
}
430430

431-
SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx) {
431+
SDKNode *SDKNodeRoot::getInstance(SDKContext &Ctx, ArrayRef<ModuleDecl*> modules) {
432432
SDKNodeInitInfo Info(Ctx);
433-
Info.Name = Ctx.buffer("TopLevel");
434-
Info.PrintedName = Ctx.buffer("TopLevel");
433+
StringRef name = Ctx.buffer("NO_MODULE");
434+
if (modules.size() == 1) {
435+
// use the module name
436+
name = Ctx.buffer(modules[0]->getName().str());
437+
} else if (!modules.empty()) {
438+
name = Ctx.buffer("MULTI_MODULES");
439+
}
440+
Info.Name = name;
441+
Info.PrintedName = name;
435442
llvm::transform(Ctx.getOpts().ToolArgs, std::back_inserter(Info.ToolArgs),
436443
[&](std::string s) { return Ctx.buffer(s); });
437444
Info.JsonFormatVer = DIGESTER_JSON_VERSION;
@@ -1976,8 +1983,13 @@ void SwiftDeclCollector::printTopLevelNames() {
19761983
llvm::outs() << Node->getKind() << ": " << Node->getName() << '\n';
19771984
}
19781985
}
1979-
1980-
void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1986+
SwiftDeclCollector::SwiftDeclCollector(SDKContext &Ctx,
1987+
ArrayRef<ModuleDecl*> Modules) : Ctx(Ctx),
1988+
RootNode(SDKNodeRoot::getInstance(Ctx, Modules)) {
1989+
if (Modules.empty()) {
1990+
return;
1991+
}
1992+
assert(!Modules.empty());
19811993
for (auto M: Modules) {
19821994
llvm::SmallVector<Decl*, 512> Decls;
19831995
swift::getTopLevelDeclsForDisplay(M, Decls);
@@ -2544,8 +2556,7 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
25442556
if (Opts.Verbose)
25452557
llvm::errs() << "Scanning symbols...\n";
25462558

2547-
SwiftDeclCollector Collector(SDKCtx);
2548-
Collector.lookupVisibleDecls(Modules);
2559+
SwiftDeclCollector Collector(SDKCtx, Modules);
25492560
return Collector.getSDKRoot();
25502561
}
25512562

@@ -2603,7 +2614,11 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
26032614
opts.SkipRemoveDeprecatedCheck = false;
26042615
opts.Verbose = false;
26052616
SDKContext ctx(opts);
2606-
SwiftDeclCollector collector(ctx);
2617+
llvm::SmallVector<ModuleDecl*, 4> modules;
2618+
if (!Empty) {
2619+
modules.push_back(MD);
2620+
}
2621+
SwiftDeclCollector collector(ctx, modules);
26072622
ConstExtractor extractor(ctx, MD->getASTContext());
26082623
PayLoad payload;
26092624
SWIFT_DEFER {
@@ -2613,7 +2628,6 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
26132628
if (Empty) {
26142629
return;
26152630
}
2616-
collector.lookupVisibleDecls({MD});
26172631
extractor.extract(MD);
26182632
}
26192633

test/ModuleInterface/emit-abi-descriptor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
// RUN: %FileCheck %s < %t/Foo-c.json
2727

2828
// CHECK: "kind": "Root"
29-
// CHECK-NEXT: "name": "TopLevel"
30-
// CHECK-NEXT: "printedName": "TopLevel"
29+
// CHECK-NEXT: "name":
30+
// CHECK-NEXT: "printedName":
3131
// CHECK: "kind": "Function"

test/api-digester/Outputs/cake-abi.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"ABIRoot": {
33
"kind": "Root",
4-
"name": "TopLevel",
5-
"printedName": "TopLevel",
4+
"name": "cake",
5+
"printedName": "cake",
66
"children": [
77
{
88
"kind": "Import",

test/api-digester/Outputs/cake.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"ABIRoot": {
33
"kind": "Root",
4-
"name": "TopLevel",
5-
"printedName": "TopLevel",
4+
"name": "cake",
5+
"printedName": "cake",
66
"children": [
77
{
88
"kind": "Import",
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"ABIRoot": {
33
"kind": "Root",
4-
"name": "TopLevel",
5-
"printedName": "TopLevel",
4+
"name": "NO_MODULE",
5+
"printedName": "NO_MODULE",
66
"json_format_version": 8
77
}
88
}

0 commit comments

Comments
 (0)