Skip to content

No dummy constraint in the public swiftinterface for SPI extensions #31896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/Frontend/ModuleInterfaceSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,18 @@ class InheritedProtocolCollector {
/// in \p map.
///
/// \sa recordConditionalConformances
static void collectSkippedConditionalConformances(PerTypeMap &map,
const Decl *D) {
static void collectSkippedConditionalConformances(
PerTypeMap &map,
const Decl *D,
const PrintOptions &printOptions) {
auto *extension = dyn_cast<ExtensionDecl>(D);
if (!extension || !extension->isConstrainedExtension())
return;

// Skip SPI extensions in the public interface.
if (!printOptions.PrintSPIs && extension->isSPI())
return;

const NominalTypeDecl *nominal = extension->getExtendedNominal();
if (!isPublicOrUsableFromInline(nominal))
return;
Expand Down Expand Up @@ -497,8 +503,9 @@ bool swift::emitSwiftInterface(raw_ostream &out,

if (!D->shouldPrintInContext(printOptions) ||
!printOptions.shouldPrint(D)) {

InheritedProtocolCollector::collectSkippedConditionalConformances(
inheritedProtocolMap, D);
inheritedProtocolMap, D, printOptions);
continue;
}

Expand Down
22 changes: 22 additions & 0 deletions test/SPI/private_swiftinterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,25 @@ private class PrivateClassLocal {}
// CHECK-PRIVATE: @_spi(LocalSPI) public func extensionSPIMethod()
// CHECK-PUBLIC-NOT: extensionSPIMethod
}

// Test the dummy conformance printed to replace private types used in
// conditional conformances. rdar://problem/63352700

// Conditional conformances using SPI types should appear in full in the
// private swiftinterface.
public struct PublicType<T> {}
@_spi(LocalSPI) public protocol SPIProto {}
private protocol PrivateConstraint {}
@_spi(LocalSPI) public protocol SPIProto2 {}

@_spi(LocalSPI)
extension PublicType: SPIProto2 where T: SPIProto2 {}
// CHECK-PRIVATE: extension PublicType : {{.*}}.SPIProto2 where T : {{.*}}.SPIProto2
// CHECK-PUBLIC-NOT: _ConstraintThatIsNotPartOfTheAPIOfThisLibrary

// The dummy conformance should be only in the private swiftinterface for
// SPI extensions.
@_spi(LocalSPI)
extension PublicType: SPIProto where T: PrivateConstraint {}
// CHECK-PRIVATE: extension {{.*}}.PublicType : {{.*}}.SPIProto where T : _ConstraintThatIsNotPartOfTheAPIOfThisLibrary
// CHECK-PUBLIC-NOT: _ConstraintThatIsNotPartOfTheAPIOfThisLibrary