From 09a9ba47e7b5967451251a357b67cb0f47f252ff Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Fri, 17 May 2024 08:25:16 -0700 Subject: [PATCH] SIL: Ignore AEIC on package declaration inside declarations without effective public access Quoting Slava: "The AST-level access is allowed to be 'more public'. I honestly don't know why, but it's always worked this way and the 'lowered' access levels must always intersect the access levels of the parents but with @uic, @aeic and @inlinable, that means just ignoring those attributes if some enclosing context is not @uic" rdar://128270848 --- lib/SIL/IR/SILDeclRef.cpp | 6 +++++- .../always_emit_into_client_attribute.swift | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 } +}