Skip to content

Commit 7f25ca3

Browse files
committed
Sema: Allow SPI references from implicitly public layouts
1 parent 8e04430 commit 7f25ca3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ bool ExportContext::canReferenceOrigin(DisallowedOriginKind originKind) const {
240240
if (originKind == DisallowedOriginKind::None)
241241
return true;
242242

243-
// Implicitly always emit into client code in embedded mode can still
244-
// access many restricted origins as more dependencies are loaded
245-
// in non-library-evolution mode and there isn't an enforced separation of
246-
// public vs SPI.
243+
// Exportability checks for non-library-evolution mode have less restrictions
244+
// than the library-evolution ones. Implicitly always emit into client code
245+
// in embedded mode and implicitly exported layouts in non-library-evolution
246+
// mode can reference SPIs and non-public dependencies.
247247
if (getFragileFunctionKind().kind ==
248-
FragileFunctionKind::EmbeddedAlwaysEmitIntoClient) {
248+
FragileFunctionKind::EmbeddedAlwaysEmitIntoClient ||
249+
*getExportabilityReason() ==
250+
ExportabilityReason::ImplicitlyPublicVarDecl) {
249251
switch (originKind) {
250252
case DisallowedOriginKind::None:
251253
case DisallowedOriginKind::NonPublicImport:

test/Sema/hidden-memory-layout.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ public struct ExposedLayoutPublicUser: ProtocolFromDirect {
413413
// expected-embedded-opt-in-error @-1 {{struct 'HiddenLayout' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenLayout' is marked '@_implementationOnly'}}
414414
private func privateFuncClass(h: HiddenClass) {}
415415
// expected-embedded-opt-in-error @-1 {{class 'HiddenClass' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenClass' is marked '@_implementationOnly'}}
416+
417+
@_spi(S) public var s: SPIStruct
416418
}
417419

418420
internal struct ExposedLayoutInternalUser: ProtocolFromDirect {
@@ -448,6 +450,8 @@ internal struct ExposedLayoutInternalUser: ProtocolFromDirect {
448450
// expected-embedded-opt-in-error @-1 {{struct 'HiddenLayout' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenLayout' is marked '@_implementationOnly'}}
449451
private func privateFuncClass(h: HiddenClass) {}
450452
// expected-embedded-opt-in-error @-1 {{class 'HiddenClass' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenClass' is marked '@_implementationOnly'}}
453+
454+
@_spi(S) public var s: SPIStruct
451455
}
452456

453457
private struct ExposedLayoutPrivateUser: ProtocolFromDirect {
@@ -483,6 +487,8 @@ private struct ExposedLayoutPrivateUser: ProtocolFromDirect {
483487
// expected-embedded-opt-in-error @-1 {{struct 'HiddenLayout' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenLayout' is marked '@_implementationOnly'}}
484488
private func privateFuncClass(h: HiddenClass) {}
485489
// expected-embedded-opt-in-error @-1 {{class 'HiddenClass' cannot be used in an embedded function not marked '@export(interface)' because 'HiddenClass' is marked '@_implementationOnly'}}
490+
491+
@_spi(S) public var s: SPIStruct
486492
}
487493

488494
#if UseImplementationOnly

0 commit comments

Comments
 (0)