@@ -216,7 +216,15 @@ static Type getResultOrYield(AbstractFunctionDecl *afd) {
216216}
217217
218218static bool hasEscapableResultOrYield (AbstractFunctionDecl *afd) {
219- return getResultOrYield (afd)->isEscapable ();
219+ auto resultType = getResultOrYield (afd);
220+ // FIXME: This check is temporary until rdar://139976667 is fixed.
221+ // ModuleType created with ModuleType::get methods are ~Copyable and
222+ // ~Escapable because the Copyable and Escapable conformance is not added to
223+ // them by default.
224+ if (resultType->is <ModuleType>()) {
225+ return true ;
226+ }
227+ return resultType->isEscapable ();
220228}
221229
222230static std::optional<LifetimeDependenceKind>
@@ -508,6 +516,10 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
508516 return std::nullopt ;
509517 }
510518
519+ if (afd->getAttrs ().hasAttribute <UnsafeNonEscapableResultAttr>()) {
520+ return std::nullopt ;
521+ }
522+
511523 // Setters infer 'self' dependence on 'newValue'.
512524 if (auto accessor = dyn_cast<AccessorDecl>(afd)) {
513525 if (accessor->getAccessorKind () == AccessorKind::Set) {
@@ -519,10 +531,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
519531 return std::nullopt ;
520532 }
521533
522- if (afd->getAttrs ().hasAttribute <UnsafeNonEscapableResultAttr>()) {
523- return std::nullopt ;
524- }
525-
526534 auto &diags = ctx.Diags ;
527535 auto returnTypeRepr = afd->getResultTypeRepr ();
528536 auto returnLoc = returnTypeRepr ? returnTypeRepr->getLoc () : afd->getLoc ();
@@ -537,6 +545,11 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd) {
537545 }
538546 }
539547
548+ if (!ctx.LangOpts .hasFeature (Feature::LifetimeDependence)) {
549+ diags.diagnose (returnLoc, diag::lifetime_dependence_feature_required);
550+ return std::nullopt ;
551+ }
552+
540553 if (!cd && afd->hasImplicitSelfDecl ()) {
541554 Type selfTypeInContext = dc->getSelfTypeInContext ();
542555 if (selfTypeInContext->isEscapable ()) {
0 commit comments