mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #81270 from atrick/rdar150403948-lifedep-walker-recurse
Fix LifetimeDependence type inference for setters.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user