@@ -198,34 +198,41 @@ void LifetimeDependenceInfo::getConcatenatedData(
198198 }
199199}
200200
201- static Type getResultOrYield (AbstractFunctionDecl *afd) {
202- if (auto *accessor = dyn_cast<AccessorDecl>(afd)) {
203- if (accessor->isCoroutine ()) {
204- auto yieldTyInContext = accessor->mapTypeIntoContext (
205- accessor->getStorage ()->getValueInterfaceType ());
206- return yieldTyInContext;
207- }
208- }
201+ static Type getResultWithoutYield (AbstractFunctionDecl *afd) {
209202 Type resultType;
210203 if (auto fn = dyn_cast<FuncDecl>(afd)) {
211- resultType = fn->getResultInterfaceType ();
204+ resultType = fn->getResultInterfaceTypeWithoutYields ();
212205 } else {
213206 auto ctor = cast<ConstructorDecl>(afd);
214207 resultType = ctor->getResultInterfaceType ();
215208 }
216209 return afd->mapTypeIntoContext (resultType);
217210}
218211
212+ static Type getYields (AbstractFunctionDecl *afd) {
213+ if (auto fn = dyn_cast<FuncDecl>(afd))
214+ return afd->mapTypeIntoContext (fn->getYieldsInterfaceType ());
215+
216+ return TupleType::getEmpty (afd->getASTContext ());;
217+ }
218+
219219static bool hasEscapableResultOrYield (AbstractFunctionDecl *afd) {
220- auto resultType = getResultOrYield (afd);
220+ auto resultType = getResultWithoutYield (afd);
221221 // FIXME: This check is temporary until rdar://139976667 is fixed.
222222 // ModuleType created with ModuleType::get methods are ~Copyable and
223223 // ~Escapable because the Copyable and Escapable conformance is not added to
224224 // them by default.
225225 if (resultType->is <ModuleType>()) {
226226 return true ;
227227 }
228- return resultType->isEscapable ();
228+ if (!resultType->isEscapable ())
229+ return false ;
230+
231+ resultType = getYields (afd);
232+ if (auto *yieldResult = resultType->getAs <YieldResultType>())
233+ resultType = yieldResult->getResultType ();
234+
235+ return resultType->is <ModuleType>() || resultType->isEscapable ();
229236}
230237
231238static std::optional<LifetimeDependenceKind>
@@ -512,7 +519,8 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
512519 return std::nullopt ;
513520 }
514521
515- if (getResultOrYield (afd)->hasError ()) {
522+ if (getResultWithoutYield (afd)->hasError () ||
523+ getYields (afd)->hasError ()) {
516524 return std::nullopt ;
517525 }
518526
0 commit comments