Skip to content

Commit a9b8317

Browse files
committed
Update spelling for representing lifetime dependencies to @_lifetime
1 parent 6e6a57b commit a9b8317

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
@@ -1144,10 +1144,11 @@ BridgedLifetimeEntry BridgedLifetimeEntry_createParsed(
11441144
BridgedASTContext cContext, BridgedSourceRange cRange,
11451145
BridgedArrayRef cSources, BridgedLifetimeDescriptor cTarget);
11461146

1147-
SWIFT_NAME("BridgedLifetimeAttr.createParsed(_:atLoc:range:entry:)")
1147+
SWIFT_NAME(
1148+
"BridgedLifetimeAttr.createParsed(_:atLoc:range:entry:isUnderscored:)")
11481149
BridgedLifetimeAttr BridgedLifetimeAttr_createParsed(
11491150
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
1150-
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry);
1151+
BridgedSourceRange cRange, BridgedLifetimeEntry cEntry, bool isUnderscored);
11511152

11521153
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedMacroSyntax {
11531154
BridgedMacroSyntaxFreestanding,

include/swift/AST/Attr.h

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

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

@@ -3219,26 +3223,33 @@ class LifetimeAttr final : public DeclAttribute {
32193223
LifetimeEntry *entry;
32203224

32213225
LifetimeAttr(SourceLoc atLoc, SourceRange baseRange, bool implicit,
3222-
LifetimeEntry *entry)
3226+
LifetimeEntry *entry, bool isUnderscored)
32233227
: DeclAttribute(DeclAttrKind::Lifetime, atLoc, baseRange, implicit),
3224-
entry(entry) {}
3228+
entry(entry) {
3229+
Bits.LifetimeAttr.isUnderscored = isUnderscored;
3230+
}
32253231

32263232
public:
32273233
static LifetimeAttr *create(ASTContext &context, SourceLoc atLoc,
32283234
SourceRange baseRange, bool implicit,
3229-
LifetimeEntry *entry);
3235+
LifetimeEntry *entry, bool isUnderscored);
32303236

32313237
LifetimeEntry *getLifetimeEntry() const { return entry; }
32323238

3239+
bool isUnderscored() const { return bool(Bits.LifetimeAttr.isUnderscored); }
3240+
32333241
static bool classof(const DeclAttribute *DA) {
32343242
return DA->getKind() == DeclAttrKind::Lifetime;
32353243
}
32363244

32373245
/// Create a copy of this attribute.
32383246
LifetimeAttr *clone(ASTContext &ctx) const {
3239-
return new (ctx) LifetimeAttr(AtLoc, Range, isImplicit(), entry);
3247+
return new (ctx)
3248+
LifetimeAttr(AtLoc, Range, isImplicit(), entry, isUnderscored());
32403249
}
32413250

3251+
std::string getString() const;
3252+
32423253
bool isEquivalent(const LifetimeAttr *other, Decl *attachedTo) const;
32433254
};
32443255

include/swift/AST/DeclAttr.def

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

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

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8195,6 +8195,9 @@ ERROR(pack_iteration_where_clause_not_supported, none,
81958195
// MARK: Lifetime Dependence Syntax
81968196
//------------------------------------------------------------------------------
81978197

8198+
ERROR(use_lifetime_underscored, PointsToFirstBadToken,
8199+
"Unsupported use of @lifetime, use @_lifetime to specify lifetime dependencies", ())
8200+
81988201
ERROR(lifetime_dependence_invalid_param_name, none,
81998202
"invalid parameter name specified %0", (Identifier))
82008203
ERROR(lifetime_dependence_invalid_param_index, none,
@@ -8229,7 +8232,7 @@ ERROR(lifetime_dependence_immortal_alone, none,
82298232
"cannot specify any other dependence source along with immortal", ())
82308233
ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
82318234
"cannot copy the lifetime of an Escapable type, use "
8232-
"'@lifetime(%1%0)' instead",
8235+
"'@_lifetime(%1%0)' instead",
82338236
(StringRef, StringRef))
82348237
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
82358238
"invalid use of %0 dependence with %1 ownership",
@@ -8260,11 +8263,11 @@ ERROR(lifetime_dependence_feature_required_inout, none,
82608263
(StringRef, Identifier))
82618264

82628265
ERROR(lifetime_dependence_cannot_infer_return, none,
8263-
"%0 with a ~Escapable result requires '@lifetime(...)'", (StringRef))
8266+
"%0 with a ~Escapable result requires '@_lifetime(...)'", (StringRef))
82648267
ERROR(lifetime_dependence_cannot_infer_mutating, none,
8265-
"%0 with a ~Escapable 'self' requires '@lifetime(self: ...)'", (StringRef))
8268+
"%0 with a ~Escapable 'self' requires '@_lifetime(self: ...)'", (StringRef))
82668269
ERROR(lifetime_dependence_cannot_infer_inout, none,
8267-
"%0 with a ~Escapable 'inout' parameter requires '@lifetime(%1: ...)'",
8270+
"%0 with a ~Escapable 'inout' parameter requires '@_lifetime(%1: ...)'",
82688271
(StringRef, Identifier))
82698272

82708273
//------------------------------------------------------------------------------
@@ -8275,15 +8278,15 @@ ERROR(lifetime_dependence_cannot_infer_return_no_param, none,
82758278
"%0 with a ~Escapable result needs a parameter to depend on",
82768279
(StringRef))
82778280
NOTE(lifetime_dependence_cannot_infer_return_immortal, none,
8278-
"'@lifetime(immortal)' can be used to indicate that values produced by "
8281+
"'@_lifetime(immortal)' can be used to indicate that values produced by "
82798282
"this initializer have no lifetime dependencies", ())
82808283
ERROR(lifetime_dependence_cannot_infer_bitwisecopyable, none,
82818284
"cannot infer lifetime dependence on %0 because '%1' is BitwiseCopyable, "
8282-
"specify '@lifetime(borrow self)'",
8285+
"specify '@_lifetime(borrow self)'",
82838286
(StringRef, StringRef))
82848287
ERROR(lifetime_dependence_cannot_infer_kind, none,
82858288
"cannot infer the lifetime dependence scope on %0 with a ~Escapable "
8286-
"parameter, specify '@lifetime(borrow %1)' or '@lifetime(copy %1)'",
8289+
"parameter, specify '@_lifetime(borrow %1)' or '@_lifetime(copy %1)'",
82878290
(StringRef, StringRef))
82888291
ERROR(lifetime_dependence_cannot_infer_scope_ownership, none,
82898292
"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
@@ -1166,6 +1166,9 @@ class ModuleDecl
11661166
/// \returns true if this module is the "swift" standard library module.
11671167
bool isStdlibModule() const;
11681168

1169+
/// \returns true if this module is the "Cxx" module.
1170+
bool isCxxModule() const;
1171+
11691172
/// \returns true if this module is the "_Concurrency" standard library module.
11701173
bool isConcurrencyModule() const;
11711174

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
@@ -1683,7 +1683,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
16831683

16841684
case DeclAttrKind::Lifetime: {
16851685
auto *attr = cast<LifetimeAttr>(this);
1686-
Printer << attr->getLifetimeEntry()->getString();
1686+
Printer << attr->getString();
16871687
break;
16881688
}
16891689

@@ -1951,7 +1951,7 @@ StringRef DeclAttribute::getAttrName() const {
19511951
return "_allowFeatureSuppression";
19521952
}
19531953
case DeclAttrKind::Lifetime:
1954-
return "lifetime";
1954+
return cast<LifetimeAttr>(this)->isUnderscored() ? "_lifetime" : "lifetime";
19551955
}
19561956
llvm_unreachable("bad DeclAttrKind");
19571957
}
@@ -3144,8 +3144,15 @@ isEquivalent(const AllowFeatureSuppressionAttr *other, Decl *attachedTo) const {
31443144

31453145
LifetimeAttr *LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
31463146
SourceRange baseRange, bool implicit,
3147-
LifetimeEntry *entry) {
3148-
return new (context) LifetimeAttr(atLoc, baseRange, implicit, entry);
3147+
LifetimeEntry *entry, bool isUnderscored) {
3148+
return new (context)
3149+
LifetimeAttr(atLoc, baseRange, implicit, entry, isUnderscored);
3150+
}
3151+
3152+
std::string LifetimeAttr::getString() const {
3153+
return (isUnderscored() ? std::string("@_lifetime")
3154+
: std::string("@lifetime")) +
3155+
getLifetimeEntry()->getString();
31493156
}
31503157

31513158
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)