Skip to content

Commit 3bec622

Browse files
re-exported synthesized extensions need to go under the base module
rdar://93928003
1 parent 0bf6fc3 commit 3bec622

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
6868
return &MainGraph;
6969
}
7070

71-
if (isFromExportedImportedModule(D)) {
71+
if (isExportedImportedModule(M)) {
7272
return &MainGraph;
7373
}
7474

@@ -231,9 +231,12 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
231231
}
232232

233233
bool SymbolGraphASTWalker::isFromExportedImportedModule(const Decl* D) const {
234-
auto *M = D->getModuleContext();
235-
236-
return llvm::any_of(ExportedImportedModules, [&M](const auto *MD) {
237-
return areModulesEqual(M, MD->getModuleContext());
238-
});
234+
auto *M = D->getModuleContext();
235+
return isExportedImportedModule(M);
236+
}
237+
238+
bool SymbolGraphASTWalker::isExportedImportedModule(const ModuleDecl *M) const {
239+
return llvm::any_of(ExportedImportedModules, [&M](const auto *MD) {
240+
return areModulesEqual(M, MD->getModuleContext());
241+
});
239242
}

lib/SymbolGraphGen/SymbolGraphASTWalker.h

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ struct SymbolGraphASTWalker : public SourceEntityWalker {
9696

9797
/// Returns whether the given declaration comes from an `@_exported import` module.
9898
virtual bool isFromExportedImportedModule(const Decl *D) const;
99+
100+
/// Returns whether the given module is an `@_exported import` module.
101+
virtual bool isExportedImportedModule(const ModuleDecl *M) const;
99102
};
100103

101104
} // end namespace symbolgraphgen
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public struct SomeStruct {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import A
2+
3+
public extension SomeStruct {
4+
struct InnerStruct: Equatable {}
5+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/ThirdOrder/A.swift -module-name A -emit-module -emit-module-path %t/A.swiftmodule
3+
// RUN: %target-swift-frontend %S/Inputs/ThirdOrder/B.swift -module-name B -emit-module -emit-module-path %t/B.swiftmodule -I %t
4+
// RUN: %target-swift-frontend %s -module-name ThirdOrder -emit-module -emit-module-path %t/ThirdOrder.swiftmodule -I %t -emit-symbol-graph -emit-symbol-graph-dir %t
5+
// RUN: %FileCheck %s --input-file %t/ThirdOrder.symbols.json --check-prefix BASE
6+
// RUN: %FileCheck %s --input-file %t/ThirdOrder@A.symbols.json --check-prefix EXT
7+
8+
// Module B extends a symbol from module A that includes a synthesized symbol.
9+
// To ensure that we track source modules correctly, we need to make sure that
10+
// the synthesized equality operators don't appear in the ThirdOrder symbol graph.
11+
12+
@_exported import B
13+
14+
// BASE-NOT: "s:SQsE2neoiySbx_xtFZ::SYNTHESIZED::s:1A10SomeStructV1BE05InnerB0V"
15+
// EXT: "s:SQsE2neoiySbx_xtFZ::SYNTHESIZED::s:1A10SomeStructV1BE05InnerB0V"

0 commit comments

Comments
 (0)