Skip to content

Add a "lazy" lifetime inference for mutating interface methods #80621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/AST/LifetimeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,13 @@ class LifetimeDependenceChecker {
return;
}
if (afd->getParameters()->size() > 0) {
if (useLazyInference()) {
// Assume that a mutating method does not depend on its parameters.
// This is unsafe but needed because some MutableSpan APIs snuck into
// the standard library interface without specifying dependencies.
pushDeps(createDeps(selfIndex).add(selfIndex,
LifetimeDependenceKind::Inherit));
}
return;
}
pushDeps(createDeps(selfIndex).add(selfIndex,
Expand Down Expand Up @@ -1115,6 +1122,17 @@ class LifetimeDependenceChecker {
.add(newValIdx, *kind));
break;
}
case AccessorKind::MutableAddress:
if (useLazyInference()) {
// Assume that a mutating method does not depend on its parameters.
// Currently only for backward interface compatibility. Even though this
// is the only useful dependence (a borrow of self is possible but not
// useful), explicit annotation is required for now to confirm that the
// mutated self cannot depend on anything stored at this address.
pushDeps(createDeps(selfIndex).add(selfIndex,
LifetimeDependenceKind::Inherit));
}
break;
default:
// Unknown mutating accessor.
break;
Expand Down
Loading