Skip to content

Commit 1b34cbe

Browse files
authored
Merge pull request #82146 from meg-gupta/cpunderscore
[6.2] Update spelling for representing lifetime dependencies to @_lifetime
2 parents 9bf7538 + 8d3f386 commit 1b34cbe

File tree

102 files changed

+1287
-1002
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1287
-1002
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+
WARNING(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/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ struct PrintOptions {
355355
/// as public
356356
bool SuppressIsolatedDeinit = false;
357357

358+
/// Suppress @_lifetime attribute and emit @lifetime instead.
359+
bool SuppressLifetimes = false;
360+
358361
/// Whether to print the \c{/*not inherited*/} comment on factory initializers.
359362
bool PrintFactoryInitializerComment = true;
360363

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ EXPERIMENTAL_FEATURE(CopyBlockOptimization, true)
526526
/// in a file scope.
527527
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
528528

529+
/// Enable @_lifetime attribute
530+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)
531+
529532
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
530533
#undef EXPERIMENTAL_FEATURE
531534
#undef UPCOMING_FEATURE

include/swift/Parse/Parser.h

Lines changed: 4 additions & 3 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.
@@ -1158,7 +1158,8 @@ class Parser {
11581158

11591159
bool isParameterSpecifier() {
11601160
if (Tok.is(tok::kw_inout)) return true;
1161-
if (Context.LangOpts.hasFeature(Feature::LifetimeDependence) &&
1161+
if ((Context.LangOpts.hasFeature(Feature::LifetimeDependence) ||
1162+
Context.LangOpts.hasFeature(Feature::Lifetimes)) &&
11621163
isSILLifetimeDependenceToken())
11631164
return true;
11641165
if (!canHaveParameterSpecifierContextualKeyword()) return false;

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,13 @@ suppressingFeatureIsolatedDeinit(PrintOptions &options,
32583258
action();
32593259
}
32603260

3261+
static void
3262+
suppressingFeatureLifetimes(PrintOptions &options,
3263+
llvm::function_ref<void()> action) {
3264+
llvm::SaveAndRestore<bool> scope(options.SuppressLifetimes, true);
3265+
action();
3266+
}
3267+
32613268
namespace {
32623269
struct ExcludeAttrRAII {
32633270
std::vector<AnyAttrKind> &ExcludeAttrList;

lib/AST/Attr.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,11 @@ 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+
if (!attr->isUnderscored() || Options.SuppressLifetimes) {
1687+
Printer << "@lifetime" << attr->getLifetimeEntry()->getString();
1688+
} else {
1689+
Printer << "@_lifetime" << attr->getLifetimeEntry()->getString();
1690+
}
16871691
break;
16881692
}
16891693

@@ -1951,7 +1955,7 @@ StringRef DeclAttribute::getAttrName() const {
19511955
return "_allowFeatureSuppression";
19521956
}
19531957
case DeclAttrKind::Lifetime:
1954-
return "lifetime";
1958+
return cast<LifetimeAttr>(this)->isUnderscored() ? "_lifetime" : "lifetime";
19551959
}
19561960
llvm_unreachable("bad DeclAttrKind");
19571961
}
@@ -3144,8 +3148,15 @@ isEquivalent(const AllowFeatureSuppressionAttr *other, Decl *attachedTo) const {
31443148

31453149
LifetimeAttr *LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
31463150
SourceRange baseRange, bool implicit,
3147-
LifetimeEntry *entry) {
3148-
return new (context) LifetimeAttr(atLoc, baseRange, implicit, entry);
3151+
LifetimeEntry *entry, bool isUnderscored) {
3152+
return new (context)
3153+
LifetimeAttr(atLoc, baseRange, implicit, entry, isUnderscored);
3154+
}
3155+
3156+
std::string LifetimeAttr::getString() const {
3157+
return (isUnderscored() ? std::string("@_lifetime")
3158+
: std::string("@lifetime")) +
3159+
getLifetimeEntry()->getString();
31493160
}
31503161

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

0 commit comments

Comments
 (0)