Skip to content

Commit d2524a6

Browse files
committed
AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling. rdar://102792909
1 parent df1750d commit d2524a6

20 files changed

+93
-91
lines changed

include/swift/AST/Attr.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,15 +2219,12 @@ class UnavailableFromAsyncAttr : public DeclAttribute {
22192219

22202220
/// The @_backDeploy(...) attribute, used to make function declarations available
22212221
/// for back deployment to older OSes via emission into the client binary.
2222-
class BackDeployAttr: public DeclAttribute {
2222+
class BackDeployedAttr : public DeclAttribute {
22232223
public:
2224-
BackDeployAttr(SourceLoc AtLoc, SourceRange Range,
2225-
PlatformKind Platform,
2226-
const llvm::VersionTuple Version,
2227-
bool Implicit)
2228-
: DeclAttribute(DAK_BackDeploy, AtLoc, Range, Implicit),
2229-
Platform(Platform),
2230-
Version(Version) {}
2224+
BackDeployedAttr(SourceLoc AtLoc, SourceRange Range, PlatformKind Platform,
2225+
const llvm::VersionTuple Version, bool Implicit)
2226+
: DeclAttribute(DAK_BackDeployed, AtLoc, Range, Implicit),
2227+
Platform(Platform), Version(Version) {}
22312228

22322229
/// The platform the symbol is available for back deployment on.
22332230
const PlatformKind Platform;
@@ -2239,7 +2236,7 @@ class BackDeployAttr: public DeclAttribute {
22392236
bool isActivePlatform(const ASTContext &ctx) const;
22402237

22412238
static bool classof(const DeclAttribute *DA) {
2242-
return DA->getKind() == DAK_BackDeploy;
2239+
return DA->getKind() == DAK_BackDeployed;
22432240
}
22442241
};
22452242

@@ -2419,9 +2416,9 @@ class DeclAttributes {
24192416
/// otherwise.
24202417
const AvailableAttr *getNoAsync(const ASTContext &ctx) const;
24212418

2422-
/// Returns the \c @_backDeploy attribute that is active for the current
2419+
/// Returns the `@backDeployed` attribute that is active for the current
24232420
/// platform.
2424-
const BackDeployAttr *getBackDeploy(const ASTContext &ctx) const;
2421+
const BackDeployedAttr *getBackDeployed(const ASTContext &ctx) const;
24252422

24262423
SWIFT_DEBUG_DUMPER(dump(const Decl *D = nullptr));
24272424
void print(ASTPrinter &Printer, const PrintOptions &Options,

include/swift/AST/Decl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,9 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
884884
Optional<llvm::VersionTuple> getIntroducedOSVersion(PlatformKind Kind) const;
885885

886886
/// Returns the OS version in which the decl became ABI as specified by the
887-
/// @_backDeploy attribute.
887+
/// @backDeployed attribute.
888888
Optional<llvm::VersionTuple>
889-
getBackDeployBeforeOSVersion(ASTContext &Ctx) const;
889+
getBackDeployedBeforeOSVersion(ASTContext &Ctx) const;
890890

891891
/// Returns the starting location of the entire declaration.
892892
SourceLoc getStartLoc() const { return getSourceRange().Start; }
@@ -6808,8 +6808,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
68086808
/// \return the synthesized thunk, or null if the base of the call has
68096809
/// diagnosed errors during type checking.
68106810
FuncDecl *getDistributedThunk() const;
6811-
6812-
/// Returns 'true' if the function has (or inherits) the @c @_backDeploy
6811+
6812+
/// Returns 'true' if the function has (or inherits) the `@backDeployed`
68136813
/// attribute.
68146814
bool isBackDeployed() const;
68156815

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,11 +1593,11 @@ ERROR(originally_defined_in_need_nonempty_module_name,none,
15931593

15941594
// backDeploy
15951595
ERROR(attr_back_deploy_expected_before_label,none,
1596-
"expected 'before:' in '@_backDeploy' attribute", ())
1596+
"expected 'before:' in '@backDeployed' attribute", ())
15971597
ERROR(attr_back_deploy_expected_colon_after_before,none,
1598-
"expected ':' after 'before' in '@_backDeploy' attribute", ())
1598+
"expected ':' after 'before' in '@backDeployed' attribute", ())
15991599
ERROR(attr_back_deploy_missing_rparen,none,
1600-
"expected ')' in '@_backDeploy' argument list", ())
1600+
"expected ')' in '@backDeployed' argument list", ())
16011601

16021602
// convention
16031603
ERROR(convention_attribute_expected_lparen,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6072,7 +6072,7 @@ ERROR(usable_from_inline_attr_in_protocol,none,
60726072
"an '@_alwaysEmitIntoClient' function|" \
60736073
"a default argument value|" \
60746074
"a property initializer in a '@frozen' type|" \
6075-
"a '@_backDeploy' function'}"
6075+
"a '@backDeployed' function'}"
60766076

60776077
#define DECL_OR_ACCESSOR "%select{%0|%0 for}"
60786078

include/swift/Parse/Parser.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,10 @@ class Parser {
10931093
ParserResult<TransposeAttr> parseTransposeAttribute(SourceLoc AtLoc,
10941094
SourceLoc Loc);
10951095

1096-
/// Parse the @_backDeploy attribute.
1097-
bool parseBackDeployAttribute(DeclAttributes &Attributes, StringRef AttrName,
1098-
SourceLoc AtLoc, SourceLoc Loc);
1096+
/// Parse the @backDeployed attribute.
1097+
bool parseBackDeployedAttribute(DeclAttributes &Attributes,
1098+
StringRef AttrName, SourceLoc AtLoc,
1099+
SourceLoc Loc);
10991100

11001101
/// Parse the @_documentation attribute.
11011102
ParserResult<DocumentationAttr> parseDocumentationAttribute(SourceLoc AtLoc,

include/swift/SIL/SILDeclRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ struct SILDeclRef {
390390
bool isNoinline() const;
391391
/// True if the function has __always inline attribute.
392392
bool isAlwaysInline() const;
393-
/// True if the function has the @_backDeploy attribute.
393+
/// True if the function has the @backDeployed attribute.
394394
bool isBackDeployed() const;
395395

396396
/// Return the expected linkage for a definition of this declaration.

lib/AST/Attr.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -400,23 +400,24 @@ const AvailableAttr *DeclAttributes::getNoAsync(const ASTContext &ctx) const {
400400
return bestAttr;
401401
}
402402

403-
const BackDeployAttr *
404-
DeclAttributes::getBackDeploy(const ASTContext &ctx) const {
405-
const BackDeployAttr *bestAttr = nullptr;
403+
const BackDeployedAttr *
404+
DeclAttributes::getBackDeployed(const ASTContext &ctx) const {
405+
const BackDeployedAttr *bestAttr = nullptr;
406406

407407
for (auto attr : *this) {
408-
auto *backDeployAttr = dyn_cast<BackDeployAttr>(attr);
409-
if (!backDeployAttr)
408+
auto *backDeployedAttr = dyn_cast<BackDeployedAttr>(attr);
409+
if (!backDeployedAttr)
410410
continue;
411411

412-
if (backDeployAttr->isInvalid() || !backDeployAttr->isActivePlatform(ctx))
412+
if (backDeployedAttr->isInvalid() ||
413+
!backDeployedAttr->isActivePlatform(ctx))
413414
continue;
414415

415416
// We have an attribute that is active for the platform, but
416417
// is it more specific than our current best?
417-
if (!bestAttr || inheritsAvailabilityFromPlatform(backDeployAttr->Platform,
418-
bestAttr->Platform)) {
419-
bestAttr = backDeployAttr;
418+
if (!bestAttr || inheritsAvailabilityFromPlatform(
419+
backDeployedAttr->Platform, bestAttr->Platform)) {
420+
bestAttr = backDeployedAttr;
420421
}
421422
}
422423

@@ -547,13 +548,14 @@ static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
547548
ASTPrinter &Printer,
548549
const PrintOptions &Options) {
549550
assert(!Attrs.empty());
551+
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
550552
Printer << "@_backDeploy(before: ";
551553
bool isFirst = true;
552554

553555
for (auto *DA : Attrs) {
554556
if (!isFirst)
555557
Printer << ", ";
556-
auto *attr = cast<BackDeployAttr>(DA);
558+
auto *attr = cast<BackDeployedAttr>(DA);
557559
Printer << platformString(attr->Platform) << " "
558560
<< attr->Version.getAsString();
559561
isFirst = false;
@@ -773,7 +775,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
773775
AttributeVector shortAvailableAttributes;
774776
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
775777
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
776-
AttributeVector backDeployAttributes;
778+
AttributeVector backDeployedAttributes;
777779
AttributeVector longAttributes;
778780
AttributeVector attributes;
779781
AttributeVector modifiers;
@@ -811,7 +813,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
811813
}
812814

813815
AttributeVector &which = DA->isDeclModifier() ? modifiers :
814-
isa<BackDeployAttr>(DA) ? backDeployAttributes :
816+
isa<BackDeployedAttr>(DA) ? backDeployedAttributes :
815817
isShortAvailable(DA) ? shortAvailableAttributes :
816818
DA->isLongAttribute() ? longAttributes :
817819
attributes;
@@ -824,8 +826,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
824826
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
825827
if (!shortAvailableAttributes.empty())
826828
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
827-
if (!backDeployAttributes.empty())
828-
printShortFormBackDeployed(backDeployAttributes, Printer, Options);
829+
if (!backDeployedAttributes.empty())
830+
printShortFormBackDeployed(backDeployedAttributes, Printer, Options);
829831

830832
for (auto DA : longAttributes)
831833
DA->print(Printer, Options, D);
@@ -1324,10 +1326,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13241326
break;
13251327
}
13261328

1327-
case DAK_BackDeploy: {
1329+
case DAK_BackDeployed: {
1330+
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
13281331
Printer.printAttrName("@_backDeploy");
13291332
Printer << "(before: ";
1330-
auto Attr = cast<BackDeployAttr>(this);
1333+
auto Attr = cast<BackDeployedAttr>(this);
13311334
Printer << platformString(Attr->Platform) << " " <<
13321335
Attr->Version.getAsString();
13331336
Printer << ")";
@@ -1534,8 +1537,8 @@ StringRef DeclAttribute::getAttrName() const {
15341537
return "transpose";
15351538
case DAK_UnavailableFromAsync:
15361539
return "_unavailableFromAsync";
1537-
case DAK_BackDeploy:
1538-
return "_backDeploy";
1540+
case DAK_BackDeployed:
1541+
return "backDeployed";
15391542
case DAK_Expose:
15401543
return "_expose";
15411544
case DAK_Documentation:
@@ -1791,7 +1794,7 @@ bool AvailableAttr::isActivePlatform(const ASTContext &ctx) const {
17911794
return isPlatformActive(Platform, ctx.LangOpts);
17921795
}
17931796

1794-
bool BackDeployAttr::isActivePlatform(const ASTContext &ctx) const {
1797+
bool BackDeployedAttr::isActivePlatform(const ASTContext &ctx) const {
17951798
return isPlatformActive(Platform, ctx.LangOpts);
17961799
}
17971800

lib/AST/Decl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,13 @@ Decl::getIntroducedOSVersion(PlatformKind Kind) const {
417417
}
418418

419419
Optional<llvm::VersionTuple>
420-
Decl::getBackDeployBeforeOSVersion(ASTContext &Ctx) const {
421-
if (auto *attr = getAttrs().getBackDeploy(Ctx))
420+
Decl::getBackDeployedBeforeOSVersion(ASTContext &Ctx) const {
421+
if (auto *attr = getAttrs().getBackDeployed(Ctx))
422422
return attr->Version;
423423

424-
// Accessors may inherit `@_backDeploy`.
424+
// Accessors may inherit `@backDeployed`.
425425
if (auto *AD = dyn_cast<AccessorDecl>(this))
426-
return AD->getStorage()->getBackDeployBeforeOSVersion(Ctx);
426+
return AD->getStorage()->getBackDeployedBeforeOSVersion(Ctx);
427427

428428
return None;
429429
}
@@ -971,8 +971,8 @@ AvailabilityContext Decl::getAvailabilityForLinkage() const {
971971
ASTContext &ctx = getASTContext();
972972

973973
// When computing availability for linkage, use the "before" version from
974-
// the @_backDeploy attribute, if present.
975-
if (auto backDeployVersion = getBackDeployBeforeOSVersion(ctx))
974+
// the @backDeployed attribute, if present.
975+
if (auto backDeployVersion = getBackDeployedBeforeOSVersion(ctx))
976976
return AvailabilityContext{VersionRange::allGTE(*backDeployVersion)};
977977

978978
auto containingContext =
@@ -8065,12 +8065,12 @@ bool AbstractFunctionDecl::isSendable() const {
80658065
}
80668066

80678067
bool AbstractFunctionDecl::isBackDeployed() const {
8068-
if (getAttrs().hasAttribute<BackDeployAttr>())
8068+
if (getAttrs().hasAttribute<BackDeployedAttr>())
80698069
return true;
80708070

80718071
// Property and subscript accessors inherit the attribute.
80728072
if (auto *AD = dyn_cast<AccessorDecl>(this)) {
8073-
if (AD->getStorage()->getAttrs().hasAttribute<BackDeployAttr>())
8073+
if (AD->getStorage()->getAttrs().hasAttribute<BackDeployedAttr>())
80748074
return true;
80758075
}
80768076

lib/AST/DeclContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,13 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
466466
/*allowUsableFromInline=*/true};
467467
}
468468

469-
if (AFD->getAttrs().hasAttribute<BackDeployAttr>()) {
469+
if (AFD->getAttrs().hasAttribute<BackDeployedAttr>()) {
470470
return {FragileFunctionKind::BackDeploy,
471471
/*allowUsableFromInline=*/true};
472472
}
473473

474474
// Property and subscript accessors inherit @_alwaysEmitIntoClient,
475-
// @_backDeploy, and @inlinable from their storage declarations.
475+
// @backDeployed, and @inlinable from their storage declarations.
476476
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
477477
auto *storage = accessor->getStorage();
478478
if (storage->getAttrs().getAttribute<InlinableAttr>()) {
@@ -483,7 +483,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
483483
return {FragileFunctionKind::AlwaysEmitIntoClient,
484484
/*allowUsableFromInline=*/true};
485485
}
486-
if (storage->getAttrs().hasAttribute<BackDeployAttr>()) {
486+
if (storage->getAttrs().hasAttribute<BackDeployedAttr>()) {
487487
return {FragileFunctionKind::BackDeploy,
488488
/*allowUsableFromInline=*/true};
489489
}

lib/Parse/ParseDecl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,14 +1961,14 @@ ParserStatus Parser::parsePlatformVersionInList(StringRef AttrName,
19611961
return makeParserSuccess();
19621962
}
19631963

1964-
bool Parser::parseBackDeployAttribute(DeclAttributes &Attributes,
1965-
StringRef AttrName, SourceLoc AtLoc,
1966-
SourceLoc Loc) {
1964+
bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes,
1965+
StringRef AttrName, SourceLoc AtLoc,
1966+
SourceLoc Loc) {
19671967
std::string AtAttrName = (llvm::Twine("@") + AttrName).str();
19681968
auto LeftLoc = Tok.getLoc();
19691969
if (!consumeIf(tok::l_paren)) {
19701970
diagnose(Loc, diag::attr_expected_lparen, AtAttrName,
1971-
DeclAttribute::isDeclModifier(DAK_BackDeploy));
1971+
DeclAttribute::isDeclModifier(DAK_BackDeployed));
19721972
return false;
19731973
}
19741974

@@ -2019,9 +2019,9 @@ bool Parser::parseBackDeployAttribute(DeclAttributes &Attributes,
20192019
assert(!PlatformAndVersions.empty());
20202020
auto AttrRange = SourceRange(Loc, Tok.getLoc());
20212021
for (auto &Item : PlatformAndVersions) {
2022-
Attributes.add(new (Context)
2023-
BackDeployAttr(AtLoc, AttrRange, Item.first, Item.second,
2024-
/*IsImplicit*/ false));
2022+
Attributes.add(new (Context) BackDeployedAttr(AtLoc, AttrRange, Item.first,
2023+
Item.second,
2024+
/*IsImplicit*/ false));
20252025
}
20262026
return true;
20272027
}
@@ -3366,8 +3366,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
33663366
message, AtLoc, SourceRange(Loc, Tok.getLoc()), false));
33673367
break;
33683368
}
3369-
case DAK_BackDeploy: {
3370-
if (!parseBackDeployAttribute(Attributes, AttrName, AtLoc, Loc))
3369+
case DAK_BackDeployed: {
3370+
if (!parseBackDeployedAttribute(Attributes, AttrName, AtLoc, Loc))
33713371
return false;
33723372
break;
33733373
}

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static void convertOwnershipConventionsGivenParamInfos(
261261

262262
static bool shouldApplyBackDeploymentThunk(ValueDecl *decl, ASTContext &ctx,
263263
ResilienceExpansion expansion) {
264-
auto backDeployBeforeVersion = decl->getBackDeployBeforeOSVersion(ctx);
264+
auto backDeployBeforeVersion = decl->getBackDeployedBeforeOSVersion(ctx);
265265
if (!backDeployBeforeVersion)
266266
return false;
267267

@@ -1139,7 +1139,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11391139
return SILDeclRef(distributedThunk).asDistributed();
11401140
}
11411141

1142-
// A call to `@_backDeploy` function may need to go through a thunk.
1142+
// A call to `@backDeployed` function may need to go through a thunk.
11431143
if (shouldApplyBackDeploymentThunk(afd, ctx,
11441144
SGF.F.getResilienceExpansion())) {
11451145
return SILDeclRef(afd).asBackDeploymentKind(

lib/SILGen/SILGenBackDeploy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void emitBackDeployIfAvailableCondition(SILGenFunction &SGF,
6262
SILLocation loc,
6363
SILBasicBlock *availableBB,
6464
SILBasicBlock *unavailableBB) {
65-
auto version = AFD->getBackDeployBeforeOSVersion(SGF.SGM.getASTContext());
65+
auto version = AFD->getBackDeployedBeforeOSVersion(SGF.SGM.getASTContext());
6666
VersionRange OSVersion = VersionRange::empty();
6767
if (version.has_value()) {
6868
OSVersion = VersionRange::allGTE(*version);

lib/SILOptimizer/UtilityPasses/SILSkippingChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static bool shouldHaveSkippedFunction(const SILFunction &F) {
7272
return false;
7373
}
7474

75-
// Functions with @_backDeploy may be copied into the client, so they
75+
// Functions with @backDeployed may be copied into the client, so they
7676
// shouldn't be skipped. The SILFunction that may be copied into the client
7777
// should be serialized and therefore is already handled above. However, a
7878
// second resilient SILFunction is also emitted for back deployed functions.

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212
//
1313
// This file implements diagnostics for fragile functions, like those with
14-
// @inlinable, @_alwaysEmitIntoClient, or @_backDeploy.
14+
// @inlinable, @_alwaysEmitIntoClient, or @backDeployed.
1515
//
1616
//===----------------------------------------------------------------------===//
1717

0 commit comments

Comments
 (0)