Skip to content

Commit 9be9b6f

Browse files
committed
Inherit access control in @abi
ABI-only declarations now inherit access control modifiers like `public` or `private(set)`, as well as `@usableFromInline` and `@_spi`, from their API counterpart. This means these attributes and modifiers don’t need to be specified in an `@abi` attribute. Very few tests because we aren’t yet enforcing the absence of these attributes.
1 parent 1bb2186 commit 9be9b6f

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

lib/AST/AccessRequests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ AccessLevel
4343
AccessLevelRequest::evaluate(Evaluator &evaluator, ValueDecl *D) const {
4444
assert(!D->hasAccess());
4545

46+
// ABI decls share the access level of their API decl.
47+
auto abiRole = ABIRoleInfo(D);
48+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
49+
return abiRole.getCounterpart()->getFormalAccess();
50+
4651
// Check if the decl has an explicit access control attribute.
4752
if (auto *AA = D->getAttrs().getAttribute<AccessControlAttr>())
4853
return AA->getAccess();
@@ -201,6 +206,12 @@ AccessLevel
201206
SetterAccessLevelRequest::evaluate(Evaluator &evaluator,
202207
AbstractStorageDecl *ASD) const {
203208
assert(!ASD->Accessors.getInt().hasValue());
209+
210+
// ABI decls share the access level of their API decl.
211+
auto abiRole = ABIRoleInfo(ASD);
212+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
213+
return abiRole.getCounterpart()->getSetterFormalAccess();
214+
204215
if (auto *SAA = ASD->getAttrs().getAttribute<SetterAccessAttr>())
205216
return SAA->getAccess();
206217

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4719,6 +4719,11 @@ SourceLoc Decl::getAttributeInsertionLoc(bool forModifier) const {
47194719
bool ValueDecl::isUsableFromInline() const {
47204720
assert(getFormalAccess() < AccessLevel::Public);
47214721

4722+
// ABI decls share the access level of their API decl.
4723+
auto abiRole = ABIRoleInfo(this);
4724+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
4725+
return abiRole.getCounterpart()->isUsableFromInline();
4726+
47224727
if (getAttrs().hasAttribute<UsableFromInlineAttr>() ||
47234728
getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>() ||
47244729
getAttrs().hasAttribute<InlinableAttr>())

lib/AST/Module.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,11 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
31653165
assert (isa<ValueDecl>(decl) ||
31663166
isa<ExtensionDecl>(decl));
31673167

3168+
// ABI decls share the SPI groups of their API decl.
3169+
auto abiRole = ABIRoleInfo(decl);
3170+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
3171+
return abiRole.getCounterpart()->getSPIGroups();
3172+
31683173
// First, look for local attributes.
31693174
llvm::SetVector<Identifier> spiGroups;
31703175
for (auto attr : decl->getAttrs().getAttributes<SPIAccessControlAttr>())

test/IRGen/asmname.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ extension X {
8888
// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s7asmname21abi_ABIAttrPublic_vars5Int64Vvs"
8989
// CHECK: define hidden swiftcc i64 @"$s7asmname23abi_ABIAttrInternal_vars5Int64Vvg"
9090
// CHECK: define hidden swiftcc void @"$s7asmname23abi_ABIAttrInternal_vars5Int64Vvs"
91-
// CHECK: define internal swiftcc i64 @"$s7asmname22abi_ABIAttrPrivate_vars5Int64Vvg"
92-
// CHECK: define internal swiftcc void @"$s7asmname22abi_ABIAttrPrivate_vars5Int64Vvs"
91+
// CHECK: define internal swiftcc i64 @"$s7asmname22abi_ABIAttrPrivate_var33_{{[0-9A-F]+}}LLs5Int64Vvg"
92+
// CHECK: define internal swiftcc void @"$s7asmname22abi_ABIAttrPrivate_var33_{{[0-9A-F]+}}LLs5Int64Vvs"
9393

9494
@abi(func abi_ABIAttrGenericNonSendableToSendable<T>(_ value: T) -> T)
9595
public func api_ABIAttrGenericNonSendableToSendable<T: Sendable>(_ value: T) -> T { return value }

0 commit comments

Comments
 (0)