Skip to content

Commit f3d0f7a

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 e84ad6c commit f3d0f7a

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
@@ -2214,15 +2214,12 @@ class UnavailableFromAsyncAttr : public DeclAttribute {
22142214

22152215
/// The @_backDeploy(...) attribute, used to make function declarations available
22162216
/// for back deployment to older OSes via emission into the client binary.
2217-
class BackDeployAttr: public DeclAttribute {
2217+
class BackDeployedAttr : public DeclAttribute {
22182218
public:
2219-
BackDeployAttr(SourceLoc AtLoc, SourceRange Range,
2220-
PlatformKind Platform,
2221-
const llvm::VersionTuple Version,
2222-
bool Implicit)
2223-
: DeclAttribute(DAK_BackDeploy, AtLoc, Range, Implicit),
2224-
Platform(Platform),
2225-
Version(Version) {}
2219+
BackDeployedAttr(SourceLoc AtLoc, SourceRange Range, PlatformKind Platform,
2220+
const llvm::VersionTuple Version, bool Implicit)
2221+
: DeclAttribute(DAK_BackDeployed, AtLoc, Range, Implicit),
2222+
Platform(Platform), Version(Version) {}
22262223

22272224
/// The platform the symbol is available for back deployment on.
22282225
const PlatformKind Platform;
@@ -2234,7 +2231,7 @@ class BackDeployAttr: public DeclAttribute {
22342231
bool isActivePlatform(const ASTContext &ctx) const;
22352232

22362233
static bool classof(const DeclAttribute *DA) {
2237-
return DA->getKind() == DAK_BackDeploy;
2234+
return DA->getKind() == DAK_BackDeployed;
22382235
}
22392236
};
22402237

@@ -2367,9 +2364,9 @@ class DeclAttributes {
23672364
/// otherwise.
23682365
const AvailableAttr *getNoAsync(const ASTContext &ctx) const;
23692366

2370-
/// Returns the \c @_backDeploy attribute that is active for the current
2367+
/// Returns the `@backDeployed` attribute that is active for the current
23712368
/// platform.
2372-
const BackDeployAttr *getBackDeploy(const ASTContext &ctx) const;
2369+
const BackDeployedAttr *getBackDeployed(const ASTContext &ctx) const;
23732370

23742371
SWIFT_DEBUG_DUMPER(dump(const Decl *D = nullptr));
23752372
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
@@ -853,9 +853,9 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
853853
Optional<llvm::VersionTuple> getIntroducedOSVersion(PlatformKind Kind) const;
854854

855855
/// Returns the OS version in which the decl became ABI as specified by the
856-
/// @_backDeploy attribute.
856+
/// @backDeployed attribute.
857857
Optional<llvm::VersionTuple>
858-
getBackDeployBeforeOSVersion(ASTContext &Ctx) const;
858+
getBackDeployedBeforeOSVersion(ASTContext &Ctx) const;
859859

860860
/// Returns the starting location of the entire declaration.
861861
SourceLoc getStartLoc() const { return getSourceRange().Start; }
@@ -6740,8 +6740,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
67406740
/// \return the synthesized thunk, or null if the base of the call has
67416741
/// diagnosed errors during type checking.
67426742
FuncDecl *getDistributedThunk() const;
6743-
6744-
/// Returns 'true' if the function has (or inherits) the @c @_backDeploy
6743+
6744+
/// Returns 'true' if the function has (or inherits) the `@backDeployed`
67456745
/// attribute.
67466746
bool isBackDeployed() const;
67476747

include/swift/AST/DiagnosticsParse.def

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

15831583
// backDeploy
15841584
ERROR(attr_back_deploy_expected_before_label,none,
1585-
"expected 'before:' in '@_backDeploy' attribute", ())
1585+
"expected 'before:' in '@backDeployed' attribute", ())
15861586
ERROR(attr_back_deploy_expected_colon_after_before,none,
1587-
"expected ':' after 'before' in '@_backDeploy' attribute", ())
1587+
"expected ':' after 'before' in '@backDeployed' attribute", ())
15881588
ERROR(attr_back_deploy_missing_rparen,none,
1589-
"expected ')' in '@_backDeploy' argument list", ())
1589+
"expected ')' in '@backDeployed' argument list", ())
15901590

15911591
// convention
15921592
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
@@ -6009,7 +6009,7 @@ ERROR(usable_from_inline_attr_in_protocol,none,
60096009
"an '@_alwaysEmitIntoClient' function|" \
60106010
"a default argument value|" \
60116011
"a property initializer in a '@frozen' type|" \
6012-
"a '@_backDeploy' function'}"
6012+
"a '@backDeployed' function'}"
60136013

60146014
#define DECL_OR_ACCESSOR "%select{%0|%0 for}"
60156015

include/swift/Parse/Parser.h

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

1089-
/// Parse the @_backDeploy attribute.
1090-
bool parseBackDeployAttribute(DeclAttributes &Attributes, StringRef AttrName,
1091-
SourceLoc AtLoc, SourceLoc Loc);
1089+
/// Parse the @backDeployed attribute.
1090+
bool parseBackDeployedAttribute(DeclAttributes &Attributes,
1091+
StringRef AttrName, SourceLoc AtLoc,
1092+
SourceLoc Loc);
10921093

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

include/swift/SIL/SILDeclRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ struct SILDeclRef {
378378
bool isNoinline() const;
379379
/// True if the function has __always inline attribute.
380380
bool isAlwaysInline() const;
381-
/// True if the function has the @_backDeploy attribute.
381+
/// True if the function has the @backDeployed attribute.
382382
bool isBackDeployed() const;
383383

384384
/// 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
@@ -398,23 +398,24 @@ const AvailableAttr *DeclAttributes::getNoAsync(const ASTContext &ctx) const {
398398
return bestAttr;
399399
}
400400

401-
const BackDeployAttr *
402-
DeclAttributes::getBackDeploy(const ASTContext &ctx) const {
403-
const BackDeployAttr *bestAttr = nullptr;
401+
const BackDeployedAttr *
402+
DeclAttributes::getBackDeployed(const ASTContext &ctx) const {
403+
const BackDeployedAttr *bestAttr = nullptr;
404404

405405
for (auto attr : *this) {
406-
auto *backDeployAttr = dyn_cast<BackDeployAttr>(attr);
407-
if (!backDeployAttr)
406+
auto *backDeployedAttr = dyn_cast<BackDeployedAttr>(attr);
407+
if (!backDeployedAttr)
408408
continue;
409409

410-
if (backDeployAttr->isInvalid() || !backDeployAttr->isActivePlatform(ctx))
410+
if (backDeployedAttr->isInvalid() ||
411+
!backDeployedAttr->isActivePlatform(ctx))
411412
continue;
412413

413414
// We have an attribute that is active for the platform, but
414415
// is it more specific than our current best?
415-
if (!bestAttr || inheritsAvailabilityFromPlatform(backDeployAttr->Platform,
416-
bestAttr->Platform)) {
417-
bestAttr = backDeployAttr;
416+
if (!bestAttr || inheritsAvailabilityFromPlatform(
417+
backDeployedAttr->Platform, bestAttr->Platform)) {
418+
bestAttr = backDeployedAttr;
418419
}
419420
}
420421

@@ -545,13 +546,14 @@ static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
545546
ASTPrinter &Printer,
546547
const PrintOptions &Options) {
547548
assert(!Attrs.empty());
549+
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
548550
Printer << "@_backDeploy(before: ";
549551
bool isFirst = true;
550552

551553
for (auto *DA : Attrs) {
552554
if (!isFirst)
553555
Printer << ", ";
554-
auto *attr = cast<BackDeployAttr>(DA);
556+
auto *attr = cast<BackDeployedAttr>(DA);
555557
Printer << platformString(attr->Platform) << " "
556558
<< attr->Version.getAsString();
557559
isFirst = false;
@@ -771,7 +773,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
771773
AttributeVector shortAvailableAttributes;
772774
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
773775
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
774-
AttributeVector backDeployAttributes;
776+
AttributeVector backDeployedAttributes;
775777
AttributeVector longAttributes;
776778
AttributeVector attributes;
777779
AttributeVector modifiers;
@@ -809,7 +811,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
809811
}
810812

811813
AttributeVector &which = DA->isDeclModifier() ? modifiers :
812-
isa<BackDeployAttr>(DA) ? backDeployAttributes :
814+
isa<BackDeployedAttr>(DA) ? backDeployedAttributes :
813815
isShortAvailable(DA) ? shortAvailableAttributes :
814816
DA->isLongAttribute() ? longAttributes :
815817
attributes;
@@ -822,8 +824,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
822824
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
823825
if (!shortAvailableAttributes.empty())
824826
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
825-
if (!backDeployAttributes.empty())
826-
printShortFormBackDeployed(backDeployAttributes, Printer, Options);
827+
if (!backDeployedAttributes.empty())
828+
printShortFormBackDeployed(backDeployedAttributes, Printer, Options);
827829

828830
for (auto DA : longAttributes)
829831
DA->print(Printer, Options, D);
@@ -1322,10 +1324,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13221324
break;
13231325
}
13241326

1325-
case DAK_BackDeploy: {
1327+
case DAK_BackDeployed: {
1328+
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
13261329
Printer.printAttrName("@_backDeploy");
13271330
Printer << "(before: ";
1328-
auto Attr = cast<BackDeployAttr>(this);
1331+
auto Attr = cast<BackDeployedAttr>(this);
13291332
Printer << platformString(Attr->Platform) << " " <<
13301333
Attr->Version.getAsString();
13311334
Printer << ")";
@@ -1500,8 +1503,8 @@ StringRef DeclAttribute::getAttrName() const {
15001503
return "transpose";
15011504
case DAK_UnavailableFromAsync:
15021505
return "_unavailableFromAsync";
1503-
case DAK_BackDeploy:
1504-
return "_backDeploy";
1506+
case DAK_BackDeployed:
1507+
return "backDeployed";
15051508
case DAK_Expose:
15061509
return "_expose";
15071510
case DAK_Documentation:
@@ -1749,7 +1752,7 @@ bool AvailableAttr::isActivePlatform(const ASTContext &ctx) const {
17491752
return isPlatformActive(Platform, ctx.LangOpts);
17501753
}
17511754

1752-
bool BackDeployAttr::isActivePlatform(const ASTContext &ctx) const {
1755+
bool BackDeployedAttr::isActivePlatform(const ASTContext &ctx) const {
17531756
return isPlatformActive(Platform, ctx.LangOpts);
17541757
}
17551758

lib/AST/Decl.cpp

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

391391
Optional<llvm::VersionTuple>
392-
Decl::getBackDeployBeforeOSVersion(ASTContext &Ctx) const {
393-
if (auto *attr = getAttrs().getBackDeploy(Ctx))
392+
Decl::getBackDeployedBeforeOSVersion(ASTContext &Ctx) const {
393+
if (auto *attr = getAttrs().getBackDeployed(Ctx))
394394
return attr->Version;
395395

396-
// Accessors may inherit `@_backDeploy`.
396+
// Accessors may inherit `@backDeployed`.
397397
if (auto *AD = dyn_cast<AccessorDecl>(this))
398-
return AD->getStorage()->getBackDeployBeforeOSVersion(Ctx);
398+
return AD->getStorage()->getBackDeployedBeforeOSVersion(Ctx);
399399

400400
return None;
401401
}
@@ -943,8 +943,8 @@ AvailabilityContext Decl::getAvailabilityForLinkage() const {
943943
ASTContext &ctx = getASTContext();
944944

945945
// When computing availability for linkage, use the "before" version from
946-
// the @_backDeploy attribute, if present.
947-
if (auto backDeployVersion = getBackDeployBeforeOSVersion(ctx))
946+
// the @backDeployed attribute, if present.
947+
if (auto backDeployVersion = getBackDeployedBeforeOSVersion(ctx))
948948
return AvailabilityContext{VersionRange::allGTE(*backDeployVersion)};
949949

950950
auto containingContext =
@@ -7983,12 +7983,12 @@ bool AbstractFunctionDecl::isSendable() const {
79837983
}
79847984

79857985
bool AbstractFunctionDecl::isBackDeployed() const {
7986-
if (getAttrs().hasAttribute<BackDeployAttr>())
7986+
if (getAttrs().hasAttribute<BackDeployedAttr>())
79877987
return true;
79887988

79897989
// Property and subscript accessors inherit the attribute.
79907990
if (auto *AD = dyn_cast<AccessorDecl>(this)) {
7991-
if (AD->getStorage()->getAttrs().hasAttribute<BackDeployAttr>())
7991+
if (AD->getStorage()->getAttrs().hasAttribute<BackDeployedAttr>())
79927992
return true;
79937993
}
79947994

lib/AST/DeclContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
431431
/*allowUsableFromInline=*/true};
432432
}
433433

434-
if (AFD->getAttrs().hasAttribute<BackDeployAttr>()) {
434+
if (AFD->getAttrs().hasAttribute<BackDeployedAttr>()) {
435435
return {FragileFunctionKind::BackDeploy,
436436
/*allowUsableFromInline=*/true};
437437
}
438438

439439
// Property and subscript accessors inherit @_alwaysEmitIntoClient,
440-
// @_backDeploy, and @inlinable from their storage declarations.
440+
// @backDeployed, and @inlinable from their storage declarations.
441441
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
442442
auto *storage = accessor->getStorage();
443443
if (storage->getAttrs().getAttribute<InlinableAttr>()) {
@@ -448,7 +448,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
448448
return {FragileFunctionKind::AlwaysEmitIntoClient,
449449
/*allowUsableFromInline=*/true};
450450
}
451-
if (storage->getAttrs().hasAttribute<BackDeployAttr>()) {
451+
if (storage->getAttrs().hasAttribute<BackDeployedAttr>()) {
452452
return {FragileFunctionKind::BackDeploy,
453453
/*allowUsableFromInline=*/true};
454454
}

lib/Parse/ParseDecl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,14 +1950,14 @@ ParserStatus Parser::parsePlatformVersionInList(StringRef AttrName,
19501950
return makeParserSuccess();
19511951
}
19521952

1953-
bool Parser::parseBackDeployAttribute(DeclAttributes &Attributes,
1954-
StringRef AttrName, SourceLoc AtLoc,
1955-
SourceLoc Loc) {
1953+
bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes,
1954+
StringRef AttrName, SourceLoc AtLoc,
1955+
SourceLoc Loc) {
19561956
std::string AtAttrName = (llvm::Twine("@") + AttrName).str();
19571957
auto LeftLoc = Tok.getLoc();
19581958
if (!consumeIf(tok::l_paren)) {
19591959
diagnose(Loc, diag::attr_expected_lparen, AtAttrName,
1960-
DeclAttribute::isDeclModifier(DAK_BackDeploy));
1960+
DeclAttribute::isDeclModifier(DAK_BackDeployed));
19611961
return false;
19621962
}
19631963

@@ -2008,9 +2008,9 @@ bool Parser::parseBackDeployAttribute(DeclAttributes &Attributes,
20082008
assert(!PlatformAndVersions.empty());
20092009
auto AttrRange = SourceRange(Loc, Tok.getLoc());
20102010
for (auto &Item : PlatformAndVersions) {
2011-
Attributes.add(new (Context)
2012-
BackDeployAttr(AtLoc, AttrRange, Item.first, Item.second,
2013-
/*IsImplicit*/ false));
2011+
Attributes.add(new (Context) BackDeployedAttr(AtLoc, AttrRange, Item.first,
2012+
Item.second,
2013+
/*IsImplicit*/ false));
20142014
}
20152015
return true;
20162016
}
@@ -3109,8 +3109,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
31093109
message, AtLoc, SourceRange(Loc, Tok.getLoc()), false));
31103110
break;
31113111
}
3112-
case DAK_BackDeploy: {
3113-
if (!parseBackDeployAttribute(Attributes, AttrName, AtLoc, Loc))
3112+
case DAK_BackDeployed: {
3113+
if (!parseBackDeployedAttribute(Attributes, AttrName, AtLoc, Loc))
31143114
return false;
31153115
break;
31163116
}

0 commit comments

Comments
 (0)