Skip to content

Commit adc1131

Browse files
authored
do not emit extension block symbols for extensions to external types when the extended type is re-exported by the extending module
1 parent 91f7ea1 commit adc1131

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -370,5 +370,8 @@ bool SymbolGraphASTWalker::isOurModule(const ModuleDecl *M) const {
370370
bool SymbolGraphASTWalker::shouldBeRecordedAsExtension(
371371
const ExtensionDecl *ED) const {
372372
return Options.EmitExtensionBlockSymbols &&
373-
!areModulesEqual(ED->getModuleContext(), ED->getExtendedNominal()->getModuleContext());
373+
!areModulesEqual(ED->getModuleContext(),
374+
ED->getExtendedNominal()->getModuleContext()) &&
375+
!isExportedImportedModule(
376+
ED->getExtendedNominal()->getModuleContext());
374377
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/ExportedImportExtensions/A.swift -module-name A -emit-module -emit-module-path %t/A.swiftmodule
3+
// RUN: %target-swift-frontend %S/Inputs/ExportedImportExtensions/B.swift -module-name B -emit-module -emit-module-path %t/B.swiftmodule -I %t
4+
// RUN: %target-swift-frontend %s -module-name ExportedImportExtensions -emit-module -emit-module-path /dev/null -I %t -emit-symbol-graph -emit-symbol-graph-dir %t/ -emit-extension-block-symbols
5+
// RUN: %FileCheck %s --input-file %t/ExportedImportExtensions.symbols.json
6+
// RUN: ls %t | %FileCheck %s --check-prefix FILES
7+
8+
@_exported import A
9+
@_exported import B
10+
11+
public protocol P {
12+
func pRequirement()
13+
}
14+
15+
public extension SymbolFromA {
16+
func extensionFromMain() { }
17+
}
18+
19+
public extension SymbolFromB {
20+
func extensionFromMain() { }
21+
}
22+
23+
extension SymbolFromB: P {
24+
public func pRequirement() { }
25+
}
26+
27+
// CHECK-NOT: "swift.extension"
28+
29+
// the extensions on SymbolFromA ...
30+
// CHECK-DAG: "precise":"s:1A11SymbolFromAV"
31+
// ... made by B
32+
// CHECK-DAG: "precise":"s:1A11SymbolFromAV1BE09extensionB1ByyF"
33+
// CHECK-DAG: {"kind":"memberOf","source":"s:1A11SymbolFromAV1BE09extensionB1ByyF","target":"s:1A11SymbolFromAV","targetFallback":"A.SymbolFromA"}
34+
// ... and by this file
35+
// CHECK-DAG: "precise":"s:1A11SymbolFromAV24ExportedImportExtensionsE09extensionB4MainyyF"
36+
// CHECK-DAG: {"kind":"memberOf","source":"s:1A11SymbolFromAV24ExportedImportExtensionsE09extensionB4MainyyF","target":"s:1A11SymbolFromAV","targetFallback":"A.SymbolFromA"}
37+
38+
// the simple member extension on SymbolFromB (made by this file)
39+
// CHECK-DAG: "precise":"s:1B11SymbolFromBV"
40+
// CHECK-DAG: "precise":"s:1B11SymbolFromBV24ExportedImportExtensionsE09extensionB4MainyyF"
41+
// CHECK-DAG: {"kind":"memberOf","source":"s:1B11SymbolFromBV24ExportedImportExtensionsE09extensionB4MainyyF","target":"s:1B11SymbolFromBV","targetFallback":"B.SymbolFromB"}
42+
43+
// the conformance extension on SymbolFromB (made by this file)
44+
// CHECK-DAG: "precise":"s:1B11SymbolFromBV24ExportedImportExtensionsE12pRequirementyyF"
45+
// CHECK-DAG: {"kind":"memberOf","source":"s:1B11SymbolFromBV24ExportedImportExtensionsE12pRequirementyyF","target":"s:1B11SymbolFromBV","targetFallback":"B.SymbolFromB","sourceOrigin":{"identifier":"s:24ExportedImportExtensions1PP12pRequirementyyF","displayName":"P.pRequirement()"}}
46+
// CHECK-DAG: {"kind":"conformsTo","source":"s:1B11SymbolFromBV","target":"s:24ExportedImportExtensions1PP"}
47+
48+
// FIXME: Symbols from `@_exported import` do not get emitted when using swift-symbolgraph-extract
49+
// This is tracked by https://github.com/apple/swift-docc/issues/179.
50+
51+
// FILES-NOT: [email protected]
52+
// FILES-NOT: [email protected]
53+
// FILES-NOT: [email protected]
54+
// FILES-NOT: [email protected]
55+
// FILES-NOT: A.symbols.json
56+
// FILES-NOT: B.symbols.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public struct SymbolFromA {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import A
2+
3+
public struct SymbolFromB {}
4+
5+
public extension SymbolFromA {
6+
func extensionFromB() {}
7+
}

0 commit comments

Comments
 (0)