Skip to content

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

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
Sep 16, 2023
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
7 changes: 2 additions & 5 deletions include/swift/APIDigester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -777,8 +777,7 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
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.
Expand Down Expand Up @@ -818,8 +817,6 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
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);
Expand Down
32 changes: 23 additions & 9 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand All @@ -2613,7 +2628,6 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
if (Empty) {
return;
}
collector.lookupVisibleDecls({MD});
extractor.extract(MD);
}

Expand Down
4 changes: 2 additions & 2 deletions test/ModuleInterface/emit-abi-descriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions test/api-digester/Outputs/cake-abi.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "cake",
"printedName": "cake",
"children": [
{
"kind": "Import",
Expand Down
4 changes: 2 additions & 2 deletions test/api-digester/Outputs/cake.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "cake",
"printedName": "cake",
"children": [
{
"kind": "Import",
Expand Down
4 changes: 2 additions & 2 deletions test/api-digester/Outputs/empty-baseline.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ABIRoot": {
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"name": "NO_MODULE",
"printedName": "NO_MODULE",
"json_format_version": 8
}
}