@@ -140,22 +140,23 @@ void LifetimeDependenceInfo::getConcatenatedData(
140140 }
141141}
142142
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) {
148144 if (auto *accessor = dyn_cast<AccessorDecl>(afd)) {
149145 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 ();
152149 }
153150 }
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 ();
157158 }
158- return false ;
159+ return afd-> mapTypeIntoContext (resultType)-> isEscapable () ;
159160}
160161
161162static LifetimeDependenceKind getLifetimeDependenceKindFromDecl (
@@ -172,8 +173,7 @@ static LifetimeDependenceKind getLifetimeDependenceKindFromDecl(
172173}
173174
174175std::optional<LifetimeDependenceInfo>
175- LifetimeDependenceInfo::fromTypeRepr (AbstractFunctionDecl *afd, Type resultType,
176- bool allowIndex) {
176+ LifetimeDependenceInfo::fromTypeRepr (AbstractFunctionDecl *afd) {
177177 auto *dc = afd->getDeclContext ();
178178 auto &ctx = dc->getASTContext ();
179179 auto *mod = afd->getModuleContext ();
@@ -184,7 +184,7 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
184184 auto lifetimeDependentRepr =
185185 cast<LifetimeDependentReturnTypeRepr>(afd->getResultTypeRepr ());
186186
187- if (hasEscapableResultOrYield (afd, resultType )) {
187+ if (hasEscapableResultOrYield (afd)) {
188188 diags.diagnose (lifetimeDependentRepr->getLoc (),
189189 diag::lifetime_dependence_invalid_return_type);
190190 return std::nullopt ;
@@ -389,7 +389,7 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::fromTypeRepr(
389389}
390390
391391std::optional<LifetimeDependenceInfo>
392- LifetimeDependenceInfo::infer (AbstractFunctionDecl *afd, Type resultType ) {
392+ LifetimeDependenceInfo::infer (AbstractFunctionDecl *afd) {
393393 auto *dc = afd->getDeclContext ();
394394 auto &ctx = dc->getASTContext ();
395395 auto *mod = afd->getModuleContext ();
@@ -403,7 +403,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
403403 return std::nullopt ;
404404 }
405405
406- if (hasEscapableResultOrYield (afd, resultType )) {
406+ if (hasEscapableResultOrYield (afd)) {
407407 return std::nullopt ;
408408 }
409409
@@ -423,7 +423,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
423423 }
424424 }
425425
426- if (afd-> getKind () != DeclKind::Constructor && afd->hasImplicitSelfDecl ()) {
426+ if (!cd && afd->hasImplicitSelfDecl ()) {
427427 Type selfTypeInContext = dc->getSelfTypeInContext ();
428428 if (selfTypeInContext->isEscapable ()) {
429429 if (ctx.LangOpts .hasFeature (Feature::BitwiseCopyable)) {
@@ -475,7 +475,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
475475 continue ;
476476 }
477477 if (candidateParam) {
478- if (afd-> getKind () == DeclKind::Constructor && afd->isImplicit ()) {
478+ if (cd && afd->isImplicit ()) {
479479 diags.diagnose (
480480 returnLoc,
481481 diag::lifetime_dependence_cannot_infer_ambiguous_candidate,
@@ -493,7 +493,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
493493 }
494494
495495 if (!candidateParam && !hasParamError) {
496- if (afd-> getKind () == DeclKind::Constructor && afd->isImplicit ()) {
496+ if (cd && afd->isImplicit ()) {
497497 diags.diagnose (returnLoc,
498498 diag::lifetime_dependence_cannot_infer_no_candidates,
499499 " on implicit initializer" );
@@ -508,13 +508,13 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
508508}
509509
510510std::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));
513513 auto *returnTypeRepr = afd->getResultTypeRepr ();
514514 if (isa_and_nonnull<LifetimeDependentReturnTypeRepr>(returnTypeRepr)) {
515- return LifetimeDependenceInfo::fromTypeRepr (afd, resultType, allowIndex );
515+ return LifetimeDependenceInfo::fromTypeRepr (afd);
516516 }
517- return LifetimeDependenceInfo::infer (afd, resultType );
517+ return LifetimeDependenceInfo::infer (afd);
518518}
519519
520520LifetimeDependenceInfo
0 commit comments