Skip to content

Commit aa0f555

Browse files
committed
No dummy constraint in the public swiftinterface for SPI extensions
rdar://problem/63352700
1 parent 976890d commit aa0f555

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,18 @@ class InheritedProtocolCollector {
345345
/// in \p map.
346346
///
347347
/// \sa recordConditionalConformances
348-
static void collectSkippedConditionalConformances(PerTypeMap &map,
349-
const Decl *D) {
348+
static void collectSkippedConditionalConformances(
349+
PerTypeMap &map,
350+
const Decl *D,
351+
const PrintOptions &printOptions) {
350352
auto *extension = dyn_cast<ExtensionDecl>(D);
351353
if (!extension || !extension->isConstrainedExtension())
352354
return;
353355

356+
// Skip SPI extensions in the public interface.
357+
if (!printOptions.PrintSPIs && extension->isSPI())
358+
return;
359+
354360
const NominalTypeDecl *nominal = extension->getExtendedNominal();
355361
if (!isPublicOrUsableFromInline(nominal))
356362
return;
@@ -497,8 +503,9 @@ bool swift::emitSwiftInterface(raw_ostream &out,
497503

498504
if (!D->shouldPrintInContext(printOptions) ||
499505
!printOptions.shouldPrint(D)) {
506+
500507
InheritedProtocolCollector::collectSkippedConditionalConformances(
501-
inheritedProtocolMap, D);
508+
inheritedProtocolMap, D, printOptions);
502509
continue;
503510
}
504511

test/SPI/private_swiftinterface.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,25 @@ private class PrivateClassLocal {}
8787
// CHECK-PRIVATE: @_spi(LocalSPI) public func extensionSPIMethod()
8888
// CHECK-PUBLIC-NOT: extensionSPIMethod
8989
}
90+
91+
// Test the dummy conformance printed to replace private types used in
92+
// conditional conformances. rdar://problem/63352700
93+
94+
// Conditional conformances using SPI types should appear in full in the
95+
// private swiftinterface.
96+
public struct PublicType<T> {}
97+
@_spi(LocalSPI) public protocol SPIProto {}
98+
private protocol PrivateConstraint {}
99+
@_spi(LocalSPI) public protocol SPIProto2 {}
100+
101+
@_spi(LocalSPI)
102+
extension PublicType: SPIProto2 where T: SPIProto2 {}
103+
// CHECK-PRIVATE: extension PublicType : {{.*}}.SPIProto2 where T : {{.*}}.SPIProto2
104+
// CHECK-PUBLIC-NOT: _ConstraintThatIsNotPartOfTheAPIOfThisLibrary
105+
106+
// The dummy conformance should be only in the private swiftinterface for
107+
// SPI extensions.
108+
@_spi(LocalSPI)
109+
extension PublicType: SPIProto where T: PrivateConstraint {}
110+
// CHECK-PRIVATE: extension {{.*}}.PublicType : {{.*}}.SPIProto where T : _ConstraintThatIsNotPartOfTheAPIOfThisLibrary
111+
// CHECK-PUBLIC-NOT: _ConstraintThatIsNotPartOfTheAPIOfThisLibrary

0 commit comments

Comments
 (0)