|
20 | 20 | #include "swift/AST/TypeRepr.h"
|
21 | 21 | #include "swift/Basic/Assertions.h"
|
22 | 22 | #include "swift/Basic/Defer.h"
|
| 23 | +#include "swift/Basic/Range.h" |
23 | 24 |
|
24 | 25 | namespace swift {
|
25 | 26 |
|
@@ -444,6 +445,16 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
|
444 | 445 | if (accessor->getAccessorKind() == AccessorKind::Set) {
|
445 | 446 | return inferSetter(accessor);
|
446 | 447 | }
|
| 448 | + } else if (auto *fd = dyn_cast<FuncDecl>(afd)) { |
| 449 | + // Infer self dependence for a mutating function with no result. |
| 450 | + // |
| 451 | + // FIXME: temporary hack until we have dependsOn(self: param) syntax. |
| 452 | + // Do not apply this to accessors (_modify). _modify is handled below like a |
| 453 | + // mutating method. |
| 454 | + if (fd->isMutating() && fd->getResultInterfaceType()->isVoid() |
| 455 | + && !dc->getSelfTypeInContext()->isEscapable()) { |
| 456 | + return inferMutatingSelf(afd); |
| 457 | + } |
447 | 458 | }
|
448 | 459 |
|
449 | 460 | if (hasEscapableResultOrYield(afd)) {
|
@@ -487,6 +498,11 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
|
487 | 498 | return std::nullopt;
|
488 | 499 | }
|
489 | 500 |
|
| 501 | + // Infer method dependence: result depends on self. |
| 502 | + // |
| 503 | + // This includes _modify. A _modify's yielded value depends on self. The |
| 504 | + // caller of the _modify ensures that the 'self' depends on any value stored |
| 505 | + // to the yielded address. |
490 | 506 | return LifetimeDependenceInfo::getForIndex(
|
491 | 507 | afd, resultIndex, /*selfIndex */ afd->getParameters()->size(), kind);
|
492 | 508 | }
|
@@ -551,7 +567,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
|
551 | 567 | afd, resultIndex, *candidateParamIndex, *candidateLifetimeKind);
|
552 | 568 | }
|
553 | 569 |
|
554 |
| -/// Infer LifetimeDependenceInfo on a setter where 'self' is nonescapable. |
| 570 | +/// Infer LifetimeDependence on a setter where 'self' is nonescapable. |
555 | 571 | std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::inferSetter(
|
556 | 572 | AbstractFunctionDecl *afd) {
|
557 | 573 |
|
|
0 commit comments