Skip to content

Commit b360d3a

Browse files
include cross-import overlay information in the symbol graph itself
1 parent 3facf1f commit b360d3a

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

lib/SymbolGraphGen/FormatVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
#define SWIFT_SYMBOLGRAPH_FORMAT_MAJOR 0
1717
#define SWIFT_SYMBOLGRAPH_FORMAT_MINOR 5
18-
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 0
18+
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 1
1919

2020
#endif // SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ SymbolGraph::SymbolGraph(SymbolGraphASTWalker &Walker,
3939
M(M),
4040
ExtendedModule(ExtendedModule),
4141
Ctx(Ctx),
42-
ModuleVersion(ModuleVersion) {}
42+
ModuleVersion(ModuleVersion) {
43+
if (auto *DM = M.getDeclaringModuleIfCrossImportOverlay()) {
44+
DeclaringModule = DM;
45+
SmallVector<Identifier, 1> Bystanders;
46+
if (M.getRequiredBystandersIfCrossImportOverlay(DM, Bystanders)) {
47+
BystanderModules = Bystanders;
48+
}
49+
}
50+
}
4351

4452
// MARK: - Utilities
4553

@@ -499,7 +507,17 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
499507
}); // end metadata:
500508

501509
OS.attributeObject("module", [&](){
502-
OS.attribute("name", M.getNameStr());
510+
if (DeclaringModule) {
511+
// A cross-import overlay can be considered part of its declaring module
512+
OS.attribute("name", (*DeclaringModule)->getNameStr());
513+
std::vector<StringRef> B;
514+
for (auto BModule : BystanderModules) {
515+
B.push_back(BModule.str());
516+
}
517+
OS.attribute("bystanders", B);
518+
} else {
519+
OS.attribute("name", M.getNameStr());
520+
}
503521
AttributeRAII Platform("platform", OS);
504522

505523
auto *MainFile = M.getFiles().front();

lib/SymbolGraphGen/SymbolGraph.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ struct SymbolGraph {
4242
The module whose types were extended in `M`.
4343
*/
4444
Optional<ModuleDecl *> ExtendedModule;
45+
46+
/**
47+
The module declaring `M`, if `M` is a cross-import overlay.
48+
*/
49+
Optional<ModuleDecl *> DeclaringModule;
50+
51+
/**
52+
The modules that must be imported alongside `DeclaringModule` for `M` to be imported, if `M` is a cross-import overlay.
53+
*/
54+
SmallVector<Identifier, 1> BystanderModules;
4555

4656
/**
4757
A context for allocations.

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ using namespace symbolgraphgen;
2222
namespace {
2323
int serializeSymbolGraph(SymbolGraph &SG,
2424
const SymbolGraphOptions &Options) {
25-
SmallString<256> FileName(SG.M.getNameStr());
26-
if (SG.ExtendedModule.hasValue()) {
27-
FileName.push_back('@');
28-
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
25+
SmallString<256> FileName;
26+
if (SG.DeclaringModule.hasValue()) {
27+
// Save a cross-import overlay symbol graph as `MainModule@BystandingModule[@BystandingModule...].symbols.json`
28+
FileName.append(SG.DeclaringModule.getValue()->getNameStr());
29+
for (auto BystanderModule : SG.BystanderModules) {
30+
FileName.push_back('@');
31+
FileName.append(BystanderModule.str());
32+
}
33+
} else {
34+
FileName.append(SG.M.getNameStr());
35+
36+
if (SG.ExtendedModule.hasValue()) {
37+
FileName.push_back('@');
38+
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
39+
}
2940
}
3041
FileName.append(".symbols.json");
3142

0 commit comments

Comments
 (0)