Skip to content

Commit 0dfa1fc

Browse files
committed
Update spelling for representing lifetime dependencies to @_lifetime
1 parent 44e05fa commit 0dfa1fc

File tree

14 files changed

+81
-43
lines changed

14 files changed

+81
-43
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,11 @@ BridgedLifetimeEntry BridgedLifetimeEntry_createParsed(
11651165
BridgedASTContext cContext, BridgedSourceRange cRange,
11661166
BridgedArrayRef cSources, BridgedLifetimeDescriptor cTarget);
11671167

1168-
SWIFT_NAME("BridgedLifetimeAttr.createParsed(_:atLoc:range:entry:)")
1168+
SWIFT_NAME(
1169+
"BridgedLifetimeAttr.createParsed(_:atLoc:range:entry:isUnderscored:)")
11691170
BridgedLifetimeAttr BridgedLifetimeAttr_createParsed(
11701171
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
1171-
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry);
1172+
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry, bool isUnderscored);
11721173

11731174
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedMacroSyntax {
11741175
BridgedMacroSyntaxFreestanding,

include/swift/AST/Attr.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ class DeclAttribute : public AttributeBase {
239239

240240
NumFeatures : 31
241241
);
242+
243+
SWIFT_INLINE_BITFIELD(LifetimeAttr, DeclAttribute, 1,
244+
isUnderscored : 1
245+
);
242246
} Bits;
243247
// clang-format on
244248

@@ -3351,26 +3355,33 @@ class LifetimeAttr final : public DeclAttribute {
33513355
LifetimeEntry *entry;
33523356

33533357
LifetimeAttr(SourceLoc atLoc, SourceRange baseRange, bool implicit,
3354-
LifetimeEntry *entry)
3358+
LifetimeEntry *entry, bool isUnderscored)
33553359
: DeclAttribute(DeclAttrKind::Lifetime, atLoc, baseRange, implicit),
3356-
entry(entry) {}
3360+
entry(entry) {
3361+
Bits.LifetimeAttr.isUnderscored = isUnderscored;
3362+
}
33573363

33583364
public:
33593365
static LifetimeAttr *create(ASTContext &context, SourceLoc atLoc,
33603366
SourceRange baseRange, bool implicit,
3361-
LifetimeEntry *entry);
3367+
LifetimeEntry *entry, bool isUnderscored);
33623368

33633369
LifetimeEntry *getLifetimeEntry() const { return entry; }
33643370

3371+
bool isUnderscored() const { return bool(Bits.LifetimeAttr.isUnderscored); }
3372+
33653373
static bool classof(const DeclAttribute *DA) {
33663374
return DA->getKind() == DeclAttrKind::Lifetime;
33673375
}
33683376

33693377
/// Create a copy of this attribute.
33703378
LifetimeAttr *clone(ASTContext &ctx) const {
3371-
return new (ctx) LifetimeAttr(AtLoc, Range, isImplicit(), entry);
3379+
return new (ctx)
3380+
LifetimeAttr(AtLoc, Range, isImplicit(), entry, isUnderscored());
33723381
}
33733382

3383+
std::string getString() const;
3384+
33743385
bool isEquivalent(const LifetimeAttr *other, Decl *attachedTo) const;
33753386
};
33763387

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ DECL_ATTR(lifetime, Lifetime,
842842
OnAccessor | OnConstructor | OnFunc | OnSubscript,
843843
LongAttribute | ABIBreakingToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove | AllowMultipleAttributes | EquivalentInABIAttr,
844844
161)
845+
DECL_ATTR_ALIAS(_lifetime, Lifetime)
845846

846847
SIMPLE_DECL_ATTR(_addressableSelf, AddressableSelf,
847848
OnAccessor | OnConstructor | OnFunc | OnSubscript,

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8259,6 +8259,9 @@ ERROR(pack_iteration_where_clause_not_supported, none,
82598259
// MARK: Lifetime Dependence Syntax
82608260
//------------------------------------------------------------------------------
82618261

8262+
ERROR(use_lifetime_underscored, PointsToFirstBadToken,
8263+
"Unsupported use of @lifetime, use @_lifetime to specify lifetime dependencies", ())
8264+
82628265
ERROR(lifetime_dependence_invalid_param_name, none,
82638266
"invalid parameter name specified %0", (Identifier))
82648267
ERROR(lifetime_dependence_invalid_param_index, none,
@@ -8293,7 +8296,7 @@ ERROR(lifetime_dependence_immortal_alone, none,
82938296
"cannot specify any other dependence source along with immortal", ())
82948297
ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
82958298
"cannot copy the lifetime of an Escapable type, use "
8296-
"'@lifetime(%1%0)' instead",
8299+
"'@_lifetime(%1%0)' instead",
82978300
(StringRef, StringRef))
82988301
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
82998302
"invalid use of %0 dependence with %1 ownership",
@@ -8324,11 +8327,11 @@ ERROR(lifetime_dependence_feature_required_inout, none,
83248327
(StringRef, Identifier))
83258328

83268329
ERROR(lifetime_dependence_cannot_infer_return, none,
8327-
"%0 with a ~Escapable result requires '@lifetime(...)'", (StringRef))
8330+
"%0 with a ~Escapable result requires '@_lifetime(...)'", (StringRef))
83288331
ERROR(lifetime_dependence_cannot_infer_mutating, none,
8329-
"%0 with a ~Escapable 'self' requires '@lifetime(self: ...)'", (StringRef))
8332+
"%0 with a ~Escapable 'self' requires '@_lifetime(self: ...)'", (StringRef))
83308333
ERROR(lifetime_dependence_cannot_infer_inout, none,
8331-
"%0 with a ~Escapable 'inout' parameter requires '@lifetime(%1: ...)'",
8334+
"%0 with a ~Escapable 'inout' parameter requires '@_lifetime(%1: ...)'",
83328335
(StringRef, Identifier))
83338336

83348337
//------------------------------------------------------------------------------
@@ -8339,15 +8342,15 @@ ERROR(lifetime_dependence_cannot_infer_return_no_param, none,
83398342
"%0 with a ~Escapable result needs a parameter to depend on",
83408343
(StringRef))
83418344
NOTE(lifetime_dependence_cannot_infer_return_immortal, none,
8342-
"'@lifetime(immortal)' can be used to indicate that values produced by "
8345+
"'@_lifetime(immortal)' can be used to indicate that values produced by "
83438346
"this initializer have no lifetime dependencies", ())
83448347
ERROR(lifetime_dependence_cannot_infer_bitwisecopyable, none,
83458348
"cannot infer lifetime dependence on %0 because '%1' is BitwiseCopyable, "
8346-
"specify '@lifetime(borrow self)'",
8349+
"specify '@_lifetime(borrow self)'",
83478350
(StringRef, StringRef))
83488351
ERROR(lifetime_dependence_cannot_infer_kind, none,
83498352
"cannot infer the lifetime dependence scope on %0 with a ~Escapable "
8350-
"parameter, specify '@lifetime(borrow %1)' or '@lifetime(copy %1)'",
8353+
"parameter, specify '@_lifetime(borrow %1)' or '@_lifetime(copy %1)'",
83518354
(StringRef, StringRef))
83528355
ERROR(lifetime_dependence_cannot_infer_scope_ownership, none,
83538356
"cannot borrow the lifetime of '%0', which has consuming ownership on %1",

include/swift/AST/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,9 @@ class ModuleDecl
11581158
/// \returns true if this module is the "swift" standard library module.
11591159
bool isStdlibModule() const;
11601160

1161+
/// \returns true if this module is the "Cxx" module.
1162+
bool isCxxModule() const;
1163+
11611164
/// \returns true if this module is the "_Concurrency" standard library module.
11621165
bool isConcurrencyModule() const;
11631166

include/swift/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,8 @@ class Parser {
11271127
);
11281128

11291129
/// Parse the @lifetime attribute.
1130-
ParserResult<LifetimeAttr> parseLifetimeAttribute(SourceLoc AtLoc,
1131-
SourceLoc Loc);
1130+
ParserResult<LifetimeAttr>
1131+
parseLifetimeAttribute(StringRef attrName, SourceLoc atLoc, SourceLoc loc);
11321132

11331133
/// Common utility to parse swift @lifetime decl attribute and SIL @lifetime
11341134
/// type modifier.

lib/AST/Attr.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
16901690

16911691
case DeclAttrKind::Lifetime: {
16921692
auto *attr = cast<LifetimeAttr>(this);
1693-
Printer << attr->getLifetimeEntry()->getString();
1693+
Printer << attr->getString();
16941694
break;
16951695
}
16961696

@@ -1962,7 +1962,7 @@ StringRef DeclAttribute::getAttrName() const {
19621962
return "_allowFeatureSuppression";
19631963
}
19641964
case DeclAttrKind::Lifetime:
1965-
return "lifetime";
1965+
return cast<LifetimeAttr>(this)->isUnderscored() ? "_lifetime" : "lifetime";
19661966
}
19671967
llvm_unreachable("bad DeclAttrKind");
19681968
}
@@ -3224,8 +3224,15 @@ isEquivalent(const AllowFeatureSuppressionAttr *other, Decl *attachedTo) const {
32243224

32253225
LifetimeAttr *LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
32263226
SourceRange baseRange, bool implicit,
3227-
LifetimeEntry *entry) {
3228-
return new (context) LifetimeAttr(atLoc, baseRange, implicit, entry);
3227+
LifetimeEntry *entry, bool isUnderscored) {
3228+
return new (context)
3229+
LifetimeAttr(atLoc, baseRange, implicit, entry, isUnderscored);
3230+
}
3231+
3232+
std::string LifetimeAttr::getString() const {
3233+
return (isUnderscored() ? std::string("@_lifetime")
3234+
: std::string("@lifetime")) +
3235+
getLifetimeEntry()->getString();
32293236
}
32303237

32313238
bool LifetimeAttr::isEquivalent(const LifetimeAttr *other,

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,11 @@ BridgedLifetimeEntry BridgedLifetimeEntry_createParsed(
527527

528528
BridgedLifetimeAttr BridgedLifetimeAttr_createParsed(
529529
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
530-
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry) {
530+
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry,
531+
bool isUnderscored) {
531532
return LifetimeAttr::create(cContext.unbridged(), cAtLoc.unbridged(),
532533
cRange.unbridged(), /*implicit=*/false,
533-
cEntry.unbridged());
534+
cEntry.unbridged(), isUnderscored);
534535
}
535536

536537
BridgedMacroRole BridgedMacroRole_fromString(BridgedStringRef str) {

lib/AST/LifetimeDependence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LifetimeEntry::create(const ASTContext &ctx, SourceLoc startLoc,
3838
}
3939

4040
std::string LifetimeEntry::getString() const {
41-
std::string result = "@lifetime(";
41+
std::string result = "(";
4242
if (targetDescriptor.has_value()) {
4343
result += targetDescriptor->getString();
4444
result += ": ";

lib/AST/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,10 @@ bool ModuleDecl::isStdlibModule() const {
20172017
return !getParent() && getName() == getASTContext().StdlibModuleName;
20182018
}
20192019

2020+
bool ModuleDecl::isCxxModule() const {
2021+
return !getParent() && getName() == getASTContext().Id_Cxx;
2022+
}
2023+
20202024
bool ModuleDecl::isConcurrencyModule() const {
20212025
return !getParent() && getName() == getASTContext().Id_Concurrency;
20222026
}

0 commit comments

Comments
 (0)