Skip to content

Commit 20d8192

Browse files
committed
[ModuleInterface] Only skip extensions without public members
Additional restriction to keep printing some extensions to implementation-only imported types. This will be accepted only if the extension is marked SPI.
1 parent e6ebd14 commit 20d8192

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,22 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
169169
if (!shouldPrint(ED->getExtendedNominal(), options))
170170
return false;
171171

172-
// Skip extensions to implementation-only imported types.
172+
// Skip extensions to implementation-only imported types that have
173+
// no public members.
173174
auto localModule = ED->getParentModule();
174175
auto nominalModule = ED->getExtendedNominal()->getParentModule();
175176
if (localModule != nominalModule &&
176-
localModule->isImportedImplementationOnly(nominalModule))
177-
return false;
177+
localModule->isImportedImplementationOnly(nominalModule)) {
178+
179+
bool shouldPrintMembers = llvm::any_of(
180+
ED->getMembers(),
181+
[&](const Decl *member) -> bool {
182+
return shouldPrint(member, options);
183+
});
184+
185+
if (!shouldPrintMembers)
186+
return false;
187+
}
178188

179189
for (const Requirement &req : ED->getGenericRequirements()) {
180190
if (!isPublicOrUsableFromInline(req.getFirstType()))

test/SPI/experimental_spi_imports_swiftinterface.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/// Generate 3 empty modules.
66
// RUN: touch %t/empty.swift
7-
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name ExperimentalImported -emit-module-path %t/ExperimentalImported.swiftmodule -swift-version 5 -enable-library-evolution
7+
// RUN: %target-swift-frontend -emit-module %S/Inputs/ioi_helper.swift -module-name ExperimentalImported -emit-module-path %t/ExperimentalImported.swiftmodule -swift-version 5 -enable-library-evolution
88
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name IOIImported -emit-module-path %t/IOIImported.swiftmodule -swift-version 5 -enable-library-evolution
99
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name SPIImported -emit-module-path %t/SPIImported.swiftmodule -swift-version 5 -enable-library-evolution
1010

@@ -24,3 +24,10 @@
2424
@_spi(dummy) import SPIImported
2525
// CHECK-PUBLIC: {{^}}import SPIImported
2626
// CHECK-PRIVATE: @_spi{{.*}} import SPIImported
27+
28+
@_spi(X)
29+
extension IOIPublicStruct {
30+
public func foo() {}
31+
}
32+
// CHECK-PUBLIC-NOT: IOIPublicStruct
33+
// CHECK-PRIVATE: @_spi{{.*}} extension IOIPublicStruct

0 commit comments

Comments
 (0)