Skip to content

Commit ea27698

Browse files
authored
Merge pull request #61023 from xymus/spi-only-and-apis
[Sema] Integrate `@_spiOnly` imports logic with recent API checks
2 parents d20e00e + ebc2162 commit ea27698

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
132132
TAD->getName(), definingModule->getNameStr(), D->getNameStr(),
133133
static_cast<unsigned>(*reason), definingModule->getName(),
134134
static_cast<unsigned>(originKind))
135-
.warnUntilSwiftVersion(6);
135+
.warnUntilSwiftVersionIf(originKind != DisallowedOriginKind::SPIOnly,
136+
6);
136137
} else {
137138
ctx.Diags
138139
.diagnose(loc,
139140
diag::inlinable_typealias_desugars_to_type_from_hidden_module,
140141
TAD->getName(), definingModule->getNameStr(), D->getNameStr(),
141142
fragileKind.getSelector(), definingModule->getName(),
142143
static_cast<unsigned>(originKind))
143-
.warnUntilSwiftVersion(6);
144+
.warnUntilSwiftVersionIf(originKind != DisallowedOriginKind::SPIOnly,
145+
6);
144146
}
145147
D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
146148

@@ -253,7 +255,8 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
253255
M->getName(),
254256
static_cast<unsigned>(originKind))
255257
.warnUntilSwiftVersionIf((useConformanceAvailabilityErrorsOption &&
256-
!ctx.LangOpts.EnableConformanceAvailabilityErrors) ||
258+
!ctx.LangOpts.EnableConformanceAvailabilityErrors &&
259+
originKind != DisallowedOriginKind::SPIOnly) ||
257260
originKind == DisallowedOriginKind::ImplicitlyImported,
258261
6);
259262

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
18811881
auto importer = ID->getModuleContext();
18821882
if (target &&
18831883
!ID->getAttrs().hasAttribute<ImplementationOnlyAttr>() &&
1884+
!ID->getAttrs().hasAttribute<SPIOnlyAttr>() &&
18841885
target->getLibraryLevel() == LibraryLevel::SPI) {
18851886

18861887
auto &diags = ID->getASTContext().Diags;

test/SPI/spi-only-import-exportability.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public func publicInlinableUser() {
118118

119119
let p: PublicType = PublicType()
120120
p.spiOnlyExtensionMethod() // expected-error {{instance method 'spiOnlyExtensionMethod()' cannot be used in an '@inlinable' function because 'SPIOnlyImportedLib' was imported for SPI only}}
121+
conformanceUse(p) // expected-error{{cannot use conformance of 'PublicType' to 'PublicProtocol' here; 'SPIOnlyImportedLib' was imported for SPI only}}
121122
}
122123
#endif
123124

@@ -131,6 +132,7 @@ public func spiInlinableUser() {
131132

132133
let p: PublicType = PublicType()
133134
p.spiOnlyExtensionMethod()
135+
conformanceUse(p)
134136
}
135137

136138
public func implementationDetailsUser() {
@@ -142,6 +144,7 @@ public func implementationDetailsUser() {
142144

143145
let p: PublicType = PublicType()
144146
p.spiOnlyExtensionMethod()
147+
conformanceUse(p)
145148
}
146149

147150
public struct ClientStruct {

test/Sema/implementation-only-import-suggestion.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ import LocalClang // expected-error{{private module 'LocalClang' is imported pub
5454
@_implementationOnly import FullyPrivateClang
5555
@_implementationOnly import LocalClang
5656

57+
/// Expect no errors with spi-only imports.
58+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
59+
// RUN: -experimental-spi-only-imports \
60+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
61+
// RUN: -library-level api -D SPI_ONLY_IMPORTS
62+
#elseif SPI_ONLY_IMPORTS
63+
64+
@_spiOnly import PrivateSwift
65+
@_spiOnly import PublicClang_Private
66+
@_spiOnly import FullyPrivateClang
67+
@_spiOnly import LocalClang
68+
5769
#endif
5870

5971
/// Test error message on an unknown library level name.

test/Sema/implicit-import-typealias.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -I %t
1111
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesImplementationOnlyImport.swift -I %t
12+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesSPIOnlyImport.swift -I %t -experimental-spi-only-imports
1213
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesWithImport.swift -I %t
1314

1415
/// The swiftinterface is broken by the missing import without the workaround.
@@ -101,6 +102,20 @@ import Aliases
101102
public func takesGeneric<T: ProtoAlias>(_ t: T) {}
102103

103104

105+
//--- UsesAliasesSPIOnlyImport.swift
106+
107+
import Aliases
108+
@_spiOnly import Original
109+
110+
@inlinable public func inlinableFunc() {
111+
// expected-error@+1 {{'StructAlias' aliases 'Original.Struct' and cannot be used in an '@inlinable' function because 'Original' was imported for SPI only}}
112+
_ = StructAlias.self
113+
}
114+
115+
// expected-error@+1 {{'ProtoAlias' aliases 'Original.Proto' and cannot be used here because 'Original' was imported for SPI only}}
116+
public func takesGeneric<T: ProtoAlias>(_ t: T) {}
117+
118+
104119
//--- UsesAliasesWithImport.swift
105120

106121
import Aliases

0 commit comments

Comments
 (0)