Skip to content

Commit e88b99a

Browse files
committed
Inherit availability in @abi
ABI-only declarations now inherit `@available`, `@backDeployed`, etc. from their ABI counterpart. This will make it unnecessary to specify these attributes in `@abi`. Also some changes to make sure we suggest inserting `@available` in the correct place. No tests because the enforcement is not yet in.
1 parent 9be9b6f commit e88b99a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/AST/Availability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ bool Decl::isAvailableAsSPI() const {
411411

412412
SemanticAvailableAttributes
413413
Decl::getSemanticAvailableAttrs(bool includeInactive) const {
414+
// A decl in an @abi gets its availability from the decl it's attached to.
415+
auto abiRole = ABIRoleInfo(this);
416+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
417+
return abiRole.getCounterpart()->getSemanticAvailableAttrs(includeInactive);
418+
414419
return SemanticAvailableAttributes(getAttrs(), this, includeInactive);
415420
}
416421

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5138,7 +5138,8 @@ void AttributeChecker::checkBackDeployedAttrs(
51385138
}
51395139

51405140
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
5141-
if (!AFD->hasBody()) {
5141+
// Ignore this for ABI-only decls; ABIDeclChecker will diagnose it better.
5142+
if (!AFD->hasBody() && ABIRoleInfo(AFD).providesAPI()) {
51425143
diagnoseAndRemoveAttr(Attr, diag::back_deployed_requires_body, Attr,
51435144
VD);
51445145
continue;

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ static const Decl *relatedDeclForAvailabilityFixit(const Decl *D) {
480480
D = accessor->getStorage();
481481
}
482482

483+
auto abiRole = ABIRoleInfo(D);
484+
if (!abiRole.providesAPI() && abiRole.getCounterpart()) {
485+
// ABI-only decls can't have @available attributes of their own.
486+
D = abiRole.getCounterpart();
487+
}
488+
483489
return D->getAbstractSyntaxDeclForAttributes();
484490
}
485491

@@ -645,7 +651,7 @@ static void fixAvailabilityForDecl(
645651
// syntax to suggest the Fix-It may differ from the declaration to which
646652
// we attach availability attributes in the abstract syntax tree during
647653
// parsing.
648-
const Decl *ConcDecl = D->getConcreteSyntaxDeclForAttributes();
654+
const Decl *ConcDecl = relatedDeclForAvailabilityFixit(D);
649655

650656
// To avoid exposing the pattern binding declaration to the user, get the
651657
// descriptive kind from one of the VarDecls.

0 commit comments

Comments
 (0)