Skip to content

Commit 0e7077d

Browse files
committed
Sema: Allow embedded code to reference SPI
Embedded mode use only binary swiftmodules for distribution, SPI will always be visible. We can allow implicitly always-emit-into-client function bodies from the embedded mode to references SPIs. rdar://163519075
1 parent ba54b6d commit 0e7077d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
296296
}
297297
});
298298

299+
auto fragileKind = where.getFragileFunctionKind();
299300
switch (originKind) {
300301
case DisallowedOriginKind::None:
301302
// The decl does not come from a source that needs to be checked for
@@ -327,11 +328,15 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
327328
if (reason && reason == ExportabilityReason::AvailableAttribute &&
328329
ctx.LangOpts.LibraryLevel == LibraryLevel::API)
329330
return false;
330-
break;
331+
LLVM_FALLTHROUGH;
331332

332-
case DisallowedOriginKind::ImplementationOnly:
333333
case DisallowedOriginKind::SPIImported:
334334
case DisallowedOriginKind::SPILocal:
335+
if (fragileKind.kind == FragileFunctionKind::EmbeddedAlwaysEmitIntoClient)
336+
return false;
337+
break;
338+
339+
case DisallowedOriginKind::ImplementationOnly:
335340
case DisallowedOriginKind::FragileCxxAPI:
336341
break;
337342
}
@@ -343,7 +348,6 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
343348
return false;
344349
}
345350

346-
auto fragileKind = where.getFragileFunctionKind();
347351
if (fragileKind.kind == FragileFunctionKind::None) {
348352
DiagnosticBehavior limit = downgradeToWarning == DowngradeToWarning::Yes
349353
? DiagnosticBehavior::Warning

test/Sema/Inputs/implementation-only-imports/indirects.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ public typealias GenericAliasFromIndirect<T> = (StructFromIndirect, T)
66

77
public func globalFunctionFromIndirect() {}
88
public var globalVariableFromIndirect = 0
9+
10+
@_spi(S) public func spiFunctionFromDirect() {}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// RUN: -enable-experimental-feature Embedded
1212

1313
// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unrelated %s -I %t \
14-
// RUN: -swift-version 5 -target arm64-apple-none-macho \
14+
// RUN: -swift-version 6 -target arm64-apple-none-macho \
1515
// RUN: -define-availability "availMacro:macOS 26.0, iOS 26.0" \
1616
// RUN: -enable-experimental-feature Embedded
1717

@@ -20,10 +20,12 @@
2020

2121
@_implementationOnly import directs
2222
// expected-warning @-1 {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
23-
import indirects
23+
@_spi(S) @_spiOnly import indirects
2424

2525
internal func localInternalFunc() {} // expected-note {{global function 'localInternalFunc()' is not '@usableFromInline' or public}}
2626

27+
@_spi(S) public func localSPI() {}
28+
2729
@inlinable
2830
public func explicitlyInlinable(arg: StructFromDirect = StructFromDirect()) {
2931
// expected-error @-1 {{initializer 'init()' cannot be used in a default argument value because 'directs' was imported implementation-only}}
@@ -77,6 +79,9 @@ public func implicitlyInlinablePublic(arg: StructFromDirect = StructFromDirect()
7779
explicitNonInliable()
7880

7981
if #available(availMacro, *) { }
82+
83+
localSPI()
84+
spiFunctionFromDirect()
8085
}
8186

8287
private func implicitlyInlinablePrivate(arg: StructFromDirect = StructFromDirect()) {
@@ -186,6 +191,7 @@ struct Accessors {
186191
}
187192
}
188193

194+
@_spi(S)
189195
public func legalAccessToIndirect(arg: StructFromIndirect = StructFromIndirect()) {
190196
_ = StructFromIndirect()
191197

0 commit comments

Comments
 (0)