Skip to content

Commit 598a1cd

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 261ddd6 commit 598a1cd

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
@@ -410,6 +410,11 @@ bool Decl::isAvailableAsSPI() const {
410410

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

lib/Sema/TypeCheckAttr.cpp

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

51505150
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
5151-
if (!AFD->hasBody()) {
5151+
// Ignore this for ABI-only decls; ABIDeclChecker will diagnose it better.
5152+
if (!AFD->hasBody() && ABIRoleInfo(AFD).providesAPI()) {
51525153
diagnoseAndRemoveAttr(Attr, diag::back_deployed_requires_body, Attr,
51535154
VD);
51545155
continue;

lib/Sema/TypeCheckAvailability.cpp

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

1810+
auto abiRole = ABIRoleInfo(D);
1811+
if (!abiRole.providesAPI() && abiRole.getCounterpart()) {
1812+
// ABI-only decls can't have @available attributes of their own.
1813+
D = abiRole.getCounterpart();
1814+
}
1815+
18101816
return abstractSyntaxDeclForAvailableAttribute(D);
18111817
}
18121818

@@ -1972,7 +1978,7 @@ static void fixAvailabilityForDecl(
19721978
// syntax to suggest the Fix-It may differ from the declaration to which
19731979
// we attach availability attributes in the abstract syntax tree during
19741980
// parsing.
1975-
const Decl *ConcDecl = concreteSyntaxDeclForAvailableAttribute(D);
1981+
const Decl *ConcDecl = relatedDeclForAvailabilityFixit(D);
19761982

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

0 commit comments

Comments
 (0)