diff --git a/lib/SIL/IR/SILDeclRef.cpp b/lib/SIL/IR/SILDeclRef.cpp index e2cc7b35bb4b2..d599056fc284a 100644 --- a/lib/SIL/IR/SILDeclRef.cpp +++ b/lib/SIL/IR/SILDeclRef.cpp @@ -625,7 +625,11 @@ SILLinkage SILDeclRef::getDefinitionLinkage() const { case Limit::None: return SILLinkage::Package; case Limit::AlwaysEmitIntoClient: - return SILLinkage::PackageNonABI; + // Drop the AEIC if the enclosing decl is not effectively public. + // This matches what we do in the `internal` case. + if (isSerialized()) + return SILLinkage::PackageNonABI; + else return SILLinkage::Package; case Limit::OnDemand: return SILLinkage::Shared; case Limit::NeverPublic: diff --git a/test/SILGen/always_emit_into_client_attribute.swift b/test/SILGen/always_emit_into_client_attribute.swift index ca075c1e424ff..1b74cef3bd874 100644 --- a/test/SILGen/always_emit_into_client_attribute.swift +++ b/test/SILGen/always_emit_into_client_attribute.swift @@ -58,3 +58,21 @@ public final class C { @_alwaysEmitIntoClient deinit {} } + + +// We drop AEIC if the containing context does not have effective public +// visibility. +internal struct InternalContext { +// CHECK-LABEL: sil hidden [ossa] @$s33always_emit_into_client_attribute15InternalContextV1vSivgZ + @_alwaysEmitIntoClient + internal static var v : Int { 1 } +} + +// We drop AEIC if the containing context does not have effective public +// visibility. +package struct PackageContext { +// CHECK-LABEL: sil package [ossa] @$s33always_emit_into_client_attribute14PackageContextV1vSivgZ + + @_alwaysEmitIntoClient + package static var v : Int { 1 } +}