Skip to content

Commit cb59366

Browse files
committed
SourceKit: do not print implementation-only imports
Implementation-only imports are unnecessary in generated module interfaces, since they aren't exported to the module's dependencies, and the module's public API cannot refer to symbols imported as implementation-only.
1 parent f7f658c commit cb59366

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ void swift::ide::printModuleInterface(
607607
}
608608

609609
auto ShouldPrintImport = [&](ImportDecl *ImportD) -> bool {
610+
if (ImportD->getAttrs().hasAttribute<ImplementationOnlyAttr>())
611+
return false;
612+
610613
if (!TargetClangMod)
611614
return true;
612615
if (ImportD->getModule() == TargetMod)

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ void ModuleFile::getImportDecls(SmallVectorImpl<Decl *> &Results) {
499499
if (Dep.isExported())
500500
ID->getAttrs().add(
501501
new (Ctx) ExportedAttr(/*IsImplicit=*/false));
502+
if (Dep.isImplementationOnly())
503+
ID->getAttrs().add(
504+
new (Ctx) ImplementationOnlyAttr(/*IsImplicit=*/false));
505+
502506
ImportDecls.push_back(ID);
503507
}
504508
Bits.ComputedImportDecls = true;

test/Serialization/Recovery/implementation-only-override.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %FileCheck %s < %t/Library.txt
55

66
// CHECK: import FooKit
7-
// CHECK: import FooKit_SECRET
7+
// CHECK-NOT: import FooKit_SECRET
88

99
import FooKit
1010
@_implementationOnly import FooKit_SECRET

0 commit comments

Comments
 (0)