Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d033eec

Browse files
authored
Merge pull request #81270 from atrick/rdar150403948-lifedep-walker-recurse
Fix LifetimeDependence type inference for setters.
2 parents ff790c6 + 88bbc18 commit d033eec

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

lib/AST/LifetimeDependence.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -1126,12 +1126,19 @@ class LifetimeDependenceChecker {
11261126
if (paramTypeInContext->hasError()) {
11271127
return;
11281128
}
1129-
auto kind = inferLifetimeDependenceKind(paramTypeInContext,
1130-
param->getValueOwnership());
1131-
1132-
pushDeps(createDeps(selfIndex)
1133-
.add(selfIndex, LifetimeDependenceKind::Inherit)
1134-
.add(newValIdx, *kind));
1129+
auto targetDeps =
1130+
createDeps(selfIndex).add(selfIndex, LifetimeDependenceKind::Inherit);
1131+
1132+
// The 'newValue' dependence kind must match the getter's dependence kind
1133+
// because generated the implementation '_modify' accessor composes the
1134+
// getter's result with the setter's 'newValue'. In particular, if the
1135+
// result type is non-Escapable then the setter must not depend on
1136+
// 'newValue'.
1137+
if (!paramTypeInContext->isEscapable()) {
1138+
targetDeps = std::move(targetDeps)
1139+
.add(newValIdx, LifetimeDependenceKind::Inherit);
1140+
}
1141+
pushDeps(std::move(targetDeps));
11351142
break;
11361143
}
11371144
case AccessorKind::MutableAddress:

test/SILOptimizer/lifetime_dependence/Inputs/lifetime_depend_diagnose.swiftinterface

+20
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,24 @@ extension NE {
2424
return NE(pointer: _pointer)
2525
}
2626
}
27+
28+
public struct NCNE<Element>: ~Swift.Copyable & ~Swift.Escapable {
29+
var e: Element
30+
}
31+
32+
extension NCNE where Element : Swift.BitwiseCopyable {
33+
// Ensure that lifetime dependence diagnostics accessp the generated _modify accessor:
34+
// the getter dependency must match the setter's mewValue dependence.
35+
// In this case, the getter has no dependency because the result is BitwiseCopyable. The setter cannot, therefore,
36+
// have a borrow dependency no 'newValue' which is produced by the getter.
37+
public subscript() -> Element {
38+
get {
39+
return e
40+
}
41+
//@lifetime(self: copy self, self: copy newValue)
42+
set {
43+
e = newValue
44+
}
45+
}
46+
}
2747
#endif

0 commit comments

Comments
 (0)