Skip to content

Commit deefd5e

Browse files
authored
Merge pull request #31897 from xymus/fix-dummy-constraint-5.3
[5.3] No dummy constraint in the public swiftinterface for SPI extensions
2 parents 43a607c + a0fa529 commit deefd5e

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
@@ -344,12 +344,18 @@ class InheritedProtocolCollector {
344344
/// in \p map.
345345
///
346346
/// \sa recordConditionalConformances
347-
static void collectSkippedConditionalConformances(PerTypeMap &map,
348-
const Decl *D) {
347+
static void collectSkippedConditionalConformances(
348+
PerTypeMap &map,
349+
const Decl *D,
350+
const PrintOptions &printOptions) {
349351
auto *extension = dyn_cast<ExtensionDecl>(D);
350352
if (!extension || !extension->isConstrainedExtension())
351353
return;
352354

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

497503
if (!D->shouldPrintInContext(printOptions) ||
498504
!printOptions.shouldPrint(D)) {
505+
499506
InheritedProtocolCollector::collectSkippedConditionalConformances(
500-
inheritedProtocolMap, D);
507+
inheritedProtocolMap, D, printOptions);
501508
continue;
502509
}
503510

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)