Skip to content

Commit 6235b28

Browse files
authored
Merge pull request #80621 from atrick/infer-lazy-inout
Add a "lazy" lifetime inference for mutating interface methods
2 parents 56746e3 + 7613c5e commit 6235b28

File tree

2 files changed

+106
-149
lines changed

2 files changed

+106
-149
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,13 @@ class LifetimeDependenceChecker {
10741074
return;
10751075
}
10761076
if (afd->getParameters()->size() > 0) {
1077+
if (useLazyInference()) {
1078+
// Assume that a mutating method does not depend on its parameters.
1079+
// This is unsafe but needed because some MutableSpan APIs snuck into
1080+
// the standard library interface without specifying dependencies.
1081+
pushDeps(createDeps(selfIndex).add(selfIndex,
1082+
LifetimeDependenceKind::Inherit));
1083+
}
10771084
return;
10781085
}
10791086
pushDeps(createDeps(selfIndex).add(selfIndex,
@@ -1120,6 +1127,17 @@ class LifetimeDependenceChecker {
11201127
.add(newValIdx, *kind));
11211128
break;
11221129
}
1130+
case AccessorKind::MutableAddress:
1131+
if (useLazyInference()) {
1132+
// Assume that a mutating method does not depend on its parameters.
1133+
// Currently only for backward interface compatibility. Even though this
1134+
// is the only useful dependence (a borrow of self is possible but not
1135+
// useful), explicit annotation is required for now to confirm that the
1136+
// mutated self cannot depend on anything stored at this address.
1137+
pushDeps(createDeps(selfIndex).add(selfIndex,
1138+
LifetimeDependenceKind::Inherit));
1139+
}
1140+
break;
11231141
default:
11241142
// Unknown mutating accessor.
11251143
break;

0 commit comments

Comments
 (0)