mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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()) {
|
if (paramTypeInContext->hasError()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto kind = inferLifetimeDependenceKind(paramTypeInContext,
|
auto targetDeps =
|
||||||
param->getValueOwnership());
|
createDeps(selfIndex).add(selfIndex, LifetimeDependenceKind::Inherit);
|
||||||
|
|
||||||
pushDeps(createDeps(selfIndex)
|
// The 'newValue' dependence kind must match the getter's dependence kind
|
||||||
.add(selfIndex, LifetimeDependenceKind::Inherit)
|
// because generated the implementation '_modify' accessor composes the
|
||||||
.add(newValIdx, *kind));
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
case AccessorKind::MutableAddress:
|
case AccessorKind::MutableAddress:
|
||||||
|
|||||||
@@ -24,4 +24,24 @@ extension NE {
|
|||||||
return NE(pointer: _pointer)
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user