Skip to content

Commit 6eaa07a

Browse files
authored
Merge pull request #80540 from swiftlang/revert-80452-lifetimeinout
Revert "Add support for inout lifetime dependence"
2 parents e75ee3f + 39e1791 commit 6eaa07a

26 files changed

+156
-251
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,8 @@ BridgedInlineAttr BridgedInlineAttr_createParsed(BridgedASTContext cContext,
10861086

10871087
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedParsedLifetimeDependenceKind {
10881088
BridgedParsedLifetimeDependenceKindDefault,
1089-
BridgedParsedLifetimeDependenceKindBorrow,
1089+
BridgedParsedLifetimeDependenceKindScope,
10901090
BridgedParsedLifetimeDependenceKindInherit,
1091-
BridgedParsedLifetimeDependenceKindInout
10921091
};
10931092

10941093
class BridgedLifetimeDescriptor {

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8169,11 +8169,8 @@ ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
81698169
"'@lifetime(borrow %0)' instead",
81708170
(StringRef))
81718171
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
8172-
"invalid use of %0 dependence with %1 ownership",
8173-
(StringRef, StringRef))
8174-
ERROR(lifetime_dependence_cannot_use_default_escapable_consuming, none,
8175-
"invalid lifetime dependence on an Escapable value with %0 ownership",
8176-
(StringRef))
8172+
"invalid use of borrow dependence with consuming ownership",
8173+
())
81778174
ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
81788175
"invalid use of borrow dependence on the same inout parameter",
81798176
())

include/swift/AST/LifetimeDependence.h

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ class SILResultInfo;
3838

3939
enum class ParsedLifetimeDependenceKind : uint8_t {
4040
Default = 0,
41-
Borrow,
42-
Inherit, // Only used with deserialized decls
43-
Inout
41+
Scope,
42+
Inherit // Only used with deserialized decls
4443
};
4544

4645
enum class LifetimeDependenceKind : uint8_t { Inherit = 0, Scope };
@@ -183,7 +182,6 @@ class LifetimeEntry final
183182
ArrayRef<LifetimeDescriptor> sources,
184183
std::optional<LifetimeDescriptor> targetDescriptor = std::nullopt);
185184

186-
std::string getString() const;
187185
SourceLoc getLoc() const { return startLoc; }
188186
SourceLoc getStartLoc() const { return startLoc; }
189187
SourceLoc getEndLoc() const { return endLoc; }
@@ -195,6 +193,35 @@ class LifetimeEntry final
195193
std::optional<LifetimeDescriptor> getTargetDescriptor() const {
196194
return targetDescriptor;
197195
}
196+
197+
std::string getString() const {
198+
std::string result = "@lifetime(";
199+
if (targetDescriptor.has_value()) {
200+
result += targetDescriptor->getString();
201+
result += ": ";
202+
}
203+
204+
bool firstElem = true;
205+
for (auto source : getSources()) {
206+
if (!firstElem) {
207+
result += ", ";
208+
}
209+
switch (source.getParsedLifetimeDependenceKind()) {
210+
case ParsedLifetimeDependenceKind::Scope:
211+
result += "borrow ";
212+
break;
213+
case ParsedLifetimeDependenceKind::Inherit:
214+
result += "copy ";
215+
break;
216+
default:
217+
break;
218+
}
219+
result += source.getString();
220+
firstElem = false;
221+
}
222+
result += ")";
223+
return result;
224+
}
198225
};
199226

200227
class LifetimeDependenceInfo {
@@ -339,9 +366,6 @@ filterEscapableLifetimeDependencies(GenericSignature sig,
339366
SmallVectorImpl<LifetimeDependenceInfo> &outputs,
340367
llvm::function_ref<Type (unsigned targetIndex)> getSubstTargetType);
341368

342-
StringRef
343-
getNameForParsedLifetimeDependenceKind(ParsedLifetimeDependenceKind kind);
344-
345369
} // namespace swift
346370

347371
#endif

include/swift/Basic/Features.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,6 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
416416
/// Enable returning non-escapable types from functions.
417417
EXPERIMENTAL_FEATURE(LifetimeDependence, true)
418418

419-
/// Enable inout lifetime dependence - @lifetime(&arg)
420-
EXPERIMENTAL_FEATURE(InoutLifetimeDependence, true)
421-
422419
/// Enable the `@_staticExclusiveOnly` attribute.
423420
EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
424421

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,10 @@ unbridged(BridgedParsedLifetimeDependenceKind kind) {
470470
switch (kind) {
471471
case BridgedParsedLifetimeDependenceKindDefault:
472472
return swift::ParsedLifetimeDependenceKind::Default;
473-
case BridgedParsedLifetimeDependenceKindBorrow:
474-
return swift::ParsedLifetimeDependenceKind::Borrow;
473+
case BridgedParsedLifetimeDependenceKindScope:
474+
return swift::ParsedLifetimeDependenceKind::Scope;
475475
case BridgedParsedLifetimeDependenceKindInherit:
476476
return swift::ParsedLifetimeDependenceKind::Inherit;
477-
case BridgedParsedLifetimeDependenceKindInout:
478-
return swift::ParsedLifetimeDependenceKind::Inout;
479477
}
480478
llvm_unreachable("unhandled enum value");
481479
}

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,6 @@ static bool usesFeatureLifetimeDependence(Decl *decl) {
270270
return false;
271271
}
272272

273-
static bool usesFeatureInoutLifetimeDependence(Decl *decl) {
274-
for (auto attr : decl->getAttrs().getAttributes<LifetimeAttr>()) {
275-
for (auto source : attr->getLifetimeEntry()->getSources()) {
276-
if (source.getParsedLifetimeDependenceKind() ==
277-
ParsedLifetimeDependenceKind::Inout) {
278-
return true;
279-
}
280-
}
281-
}
282-
return false;
283-
}
284-
285273
UNINTERESTING_FEATURE(DynamicActorIsolation)
286274
UNINTERESTING_FEATURE(NonfrozenEnumExhaustivity)
287275
UNINTERESTING_FEATURE(ClosureIsolation)

0 commit comments

Comments
 (0)