Skip to content

Commit e88265d

Browse files
authored
Merge pull request #80646 from atrick/62-infer-mutating
[6.2] Add a "lazy" lifetime inference for mutating interface methods
2 parents 494e597 + 939faa3 commit e88265d

File tree

2 files changed

+106
-149
lines changed

2 files changed

+106
-149
lines changed

lib/AST/LifetimeDependence.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,13 @@ class LifetimeDependenceChecker {
992992
return;
993993
}
994994
if (afd->getParameters()->size() > 0) {
995+
if (useLazyInference()) {
996+
// Assume that a mutating method does not depend on its parameters.
997+
// This is unsafe but needed because some MutableSpan APIs snuck into
998+
// the standard library interface without specifying dependencies.
999+
pushDeps(createDeps(selfIndex).add(selfIndex,
1000+
LifetimeDependenceKind::Inherit));
1001+
}
9951002
return;
9961003
}
9971004
pushDeps(createDeps(selfIndex).add(selfIndex,
@@ -1037,6 +1044,17 @@ class LifetimeDependenceChecker {
10371044
.add(newValIdx, kind));
10381045
break;
10391046
}
1047+
case AccessorKind::MutableAddress:
1048+
if (useLazyInference()) {
1049+
// Assume that a mutating method does not depend on its parameters.
1050+
// Currently only for backward interface compatibility. Even though this
1051+
// is the only useful dependence (a borrow of self is possible but not
1052+
// useful), explicit annotation is required for now to confirm that the
1053+
// mutated self cannot depend on anything stored at this address.
1054+
pushDeps(createDeps(selfIndex).add(selfIndex,
1055+
LifetimeDependenceKind::Inherit));
1056+
}
1057+
break;
10401058
default:
10411059
// Unknown mutating accessor.
10421060
break;

0 commit comments

Comments
 (0)