@@ -140,22 +140,23 @@ void LifetimeDependenceInfo::getConcatenatedData(
140
140
}
141
141
}
142
142
143
- static bool hasEscapableResultOrYield (AbstractFunctionDecl *afd,
144
- Type resultType) {
145
- Type resultTypeInContext = afd->mapTypeIntoContext (resultType);
146
- std::optional<Type> yieldTyInContext;
147
-
143
+ static bool hasEscapableResultOrYield (AbstractFunctionDecl *afd) {
148
144
if (auto *accessor = dyn_cast<AccessorDecl>(afd)) {
149
145
if (accessor->isCoroutine ()) {
150
- yieldTyInContext = accessor->getStorage ()->getValueInterfaceType ();
151
- yieldTyInContext = accessor->mapTypeIntoContext (*yieldTyInContext);
146
+ auto yieldTyInContext = accessor->mapTypeIntoContext (
147
+ accessor->getStorage ()->getValueInterfaceType ());
148
+ return yieldTyInContext->isEscapable ();
152
149
}
153
150
}
154
- if (resultTypeInContext->isEscapable () &&
155
- (!yieldTyInContext.has_value () || (*yieldTyInContext)->isEscapable ())) {
156
- return true ;
151
+
152
+ Type resultType;
153
+ if (auto fn = dyn_cast<FuncDecl>(afd)) {
154
+ resultType = fn->getResultInterfaceType ();
155
+ } else {
156
+ auto ctor = cast<ConstructorDecl>(afd);
157
+ resultType = ctor->getResultInterfaceType ();
157
158
}
158
- return false ;
159
+ return afd-> mapTypeIntoContext (resultType)-> isEscapable () ;
159
160
}
160
161
161
162
static LifetimeDependenceKind getLifetimeDependenceKindFromDecl (
@@ -172,8 +173,7 @@ static LifetimeDependenceKind getLifetimeDependenceKindFromDecl(
172
173
}
173
174
174
175
std::optional<LifetimeDependenceInfo>
175
- LifetimeDependenceInfo::fromTypeRepr (AbstractFunctionDecl *afd, Type resultType,
176
- bool allowIndex) {
176
+ LifetimeDependenceInfo::fromTypeRepr (AbstractFunctionDecl *afd) {
177
177
auto *dc = afd->getDeclContext ();
178
178
auto &ctx = dc->getASTContext ();
179
179
auto *mod = afd->getModuleContext ();
@@ -184,7 +184,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
184
184
auto lifetimeDependentRepr =
185
185
cast<LifetimeDependentReturnTypeRepr>(afd->getResultTypeRepr ());
186
186
187
- if (hasEscapableResultOrYield (afd, resultType )) {
187
+ if (hasEscapableResultOrYield (afd)) {
188
188
diags.diagnose (lifetimeDependentRepr->getLoc (),
189
189
diag::lifetime_dependence_invalid_return_type);
190
190
return std::nullopt;
@@ -389,7 +389,7 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
389
389
}
390
390
391
391
std::optional<LifetimeDependenceInfo>
392
- LifetimeDependenceInfo::infer (AbstractFunctionDecl *afd, Type resultType ) {
392
+ LifetimeDependenceInfo::infer (AbstractFunctionDecl *afd) {
393
393
auto *dc = afd->getDeclContext ();
394
394
auto &ctx = dc->getASTContext ();
395
395
auto *mod = afd->getModuleContext ();
@@ -403,7 +403,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
403
403
return std::nullopt;
404
404
}
405
405
406
- if (hasEscapableResultOrYield (afd, resultType )) {
406
+ if (hasEscapableResultOrYield (afd)) {
407
407
return std::nullopt;
408
408
}
409
409
@@ -423,7 +423,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
423
423
}
424
424
}
425
425
426
- if (afd-> getKind () != DeclKind::Constructor && afd->hasImplicitSelfDecl ()) {
426
+ if (!cd && afd->hasImplicitSelfDecl ()) {
427
427
Type selfTypeInContext = dc->getSelfTypeInContext ();
428
428
if (selfTypeInContext->isEscapable ()) {
429
429
if (ctx.LangOpts .hasFeature (Feature::BitwiseCopyable)) {
@@ -475,7 +475,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
475
475
continue ;
476
476
}
477
477
if (candidateParam) {
478
- if (afd-> getKind () == DeclKind::Constructor && afd->isImplicit ()) {
478
+ if (cd && afd->isImplicit ()) {
479
479
diags.diagnose (
480
480
returnLoc,
481
481
diag::lifetime_dependence_cannot_infer_ambiguous_candidate,
@@ -493,7 +493,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
493
493
}
494
494
495
495
if (!candidateParam && !hasParamError) {
496
- if (afd-> getKind () == DeclKind::Constructor && afd->isImplicit ()) {
496
+ if (cd && afd->isImplicit ()) {
497
497
diags.diagnose (returnLoc,
498
498
diag::lifetime_dependence_cannot_infer_no_candidates,
499
499
" on implicit initializer" );
@@ -508,13 +508,13 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
508
508
}
509
509
510
510
std::optional<LifetimeDependenceInfo>
511
- LifetimeDependenceInfo::get (AbstractFunctionDecl *afd, Type resultType,
512
- bool allowIndex) {
511
+ LifetimeDependenceInfo::get (AbstractFunctionDecl *afd) {
512
+ assert (isa<FuncDecl>(afd) || isa<ConstructorDecl>(afd));
513
513
auto *returnTypeRepr = afd->getResultTypeRepr ();
514
514
if (isa_and_nonnull<LifetimeDependentReturnTypeRepr>(returnTypeRepr)) {
515
- return LifetimeDependenceInfo::fromTypeRepr (afd, resultType, allowIndex );
515
+ return LifetimeDependenceInfo::fromTypeRepr (afd);
516
516
}
517
- return LifetimeDependenceInfo::infer (afd, resultType );
517
+ return LifetimeDependenceInfo::infer (afd);
518
518
}
519
519
520
520
LifetimeDependenceInfo
0 commit comments