Merge pull request #81270 from atrick/rdar150403948-lifedep-walker-recurse

Fix LifetimeDependence type inference for setters.
This commit is contained in:
Andrew Trick
2025-05-03 08:25:02 -07:00
committed by GitHub
2 changed files with 32 additions and 5 deletions

View File

@@ -1126,12 +1126,19 @@ protected:
if (paramTypeInContext->hasError()) {
return;
}
auto kind = inferLifetimeDependenceKind(paramTypeInContext,
param->getValueOwnership());
auto targetDeps =
createDeps(selfIndex).add(selfIndex, LifetimeDependenceKind::Inherit);
pushDeps(createDeps(selfIndex)
.add(selfIndex, LifetimeDependenceKind::Inherit)
.add(newValIdx, *kind));
// The 'newValue' dependence kind must match the getter's dependence kind
// because generated the implementation '_modify' accessor composes the
// getter's result with the setter's 'newValue'. In particular, if the
// result type is non-Escapable then the setter must not depend on
// 'newValue'.
if (!paramTypeInContext->isEscapable()) {
targetDeps = std::move(targetDeps)
.add(newValIdx, LifetimeDependenceKind::Inherit);
}
pushDeps(std::move(targetDeps));
break;
}
case AccessorKind::MutableAddress:

View File

@@ -24,4 +24,24 @@ extension NE {
return NE(pointer: _pointer)
}
}
public struct NCNE<Element>: ~Swift.Copyable & ~Swift.Escapable {
var e: Element
}
extension NCNE where Element : Swift.BitwiseCopyable {
// Ensure that lifetime dependence diagnostics accessp the generated _modify accessor:
// the getter dependency must match the setter's mewValue dependence.
// In this case, the getter has no dependency because the result is BitwiseCopyable. The setter cannot, therefore,
// have a borrow dependency no 'newValue' which is produced by the getter.
public subscript() -> Element {
get {
return e
}
//@lifetime(self: copy self, self: copy newValue)
set {
e = newValue
}
}
}
#endif