@@ -2577,8 +2577,8 @@ static Type validateParameterType(ParamDecl *decl) {
25772577}
25782578
25792579llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo (
2580- LifetimeDependentReturnTypeRepr *lifetimeDependentRepr, Decl *decl ,
2581- bool allowIndex) {
2580+ LifetimeDependentReturnTypeRepr *lifetimeDependentRepr, Type resultTy ,
2581+ Decl *decl, bool allowIndex) {
25822582 auto *afd = cast<AbstractFunctionDecl>(decl);
25832583 auto *dc = decl->getDeclContext ();
25842584 auto &ctx = dc->getASTContext ();
@@ -2592,26 +2592,35 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
25922592 auto loc = specifier.getLoc ();
25932593 auto kind = specifier.getLifetimeDependenceKind ();
25942594
2595- // Sema cannot diagnose illegal lifetime dependence kinds when no
2596- // ownership parameter modifiers are specified. They can be diagnosed
2597- // later in SIL.
2598- if (ownership != ValueOwnership::Default) {
2599- if (kind == LifetimeDependenceKind::Borrow &&
2600- ownership != ValueOwnership::Shared) {
2601- diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind, " borrow" ,
2602- getOwnershipSpelling (ownership));
2603- return true ;
2604- } else if (kind == LifetimeDependenceKind::Mutate &&
2605- ownership != ValueOwnership::InOut) {
2606- diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind, " mutate" ,
2607- getOwnershipSpelling (ownership));
2608- return true ;
2609- } else if (kind == LifetimeDependenceKind::Consume &&
2610- ownership != ValueOwnership::Owned) {
2611- diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind,
2612- " consume" , getOwnershipSpelling (ownership));
2613- return true ;
2614- }
2595+ /* TODO: Enable this
2596+ if (TypeChecker::conformsToKnownProtocol(resultTy,
2597+ InvertibleProtocolKind::Escapable,
2598+ dc->getParentModule())) {
2599+ diags.diagnose(loc, diag::lifetime_dependence_invalid_return_type);
2600+ return true;
2601+ }
2602+ */
2603+ if (ownership == ValueOwnership::Default) {
2604+ diags.diagnose (loc, diag::lifetime_dependence_missing_ownership_modifier);
2605+ return true ;
2606+ }
2607+ if (kind == LifetimeDependenceKind::Borrow &&
2608+ ownership != ValueOwnership::Shared) {
2609+ diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind, " borrow" ,
2610+ getOwnershipSpelling (ownership));
2611+ return true ;
2612+ }
2613+ if (kind == LifetimeDependenceKind::Mutate &&
2614+ ownership != ValueOwnership::InOut) {
2615+ diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind, " mutate" ,
2616+ getOwnershipSpelling (ownership));
2617+ return true ;
2618+ }
2619+ if (kind == LifetimeDependenceKind::Consume &&
2620+ ownership != ValueOwnership::Owned) {
2621+ diags.diagnose (loc, diag::lifetime_dependence_cannot_use_kind, " consume" ,
2622+ getOwnershipSpelling (ownership));
2623+ return true ;
26152624 }
26162625 if (copyLifetimeParamIndices.test (paramIndexToSet) ||
26172626 borrowLifetimeParamIndices.test (paramIndexToSet)) {
@@ -2846,16 +2855,6 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
28462855 }
28472856 }
28482857
2849- auto *returnTypeRepr = AFD->getResultTypeRepr ();
2850- llvm::Optional<LifetimeDependenceInfo> lifetimeDependenceInfo;
2851- if (returnTypeRepr) {
2852- if (auto *lifetimeDependentRepr =
2853- dyn_cast<LifetimeDependentReturnTypeRepr>(returnTypeRepr)) {
2854- lifetimeDependenceInfo = validateLifetimeDependenceInfo (
2855- lifetimeDependentRepr, D, /* allowIndex*/ false );
2856- }
2857- }
2858-
28592858 // Result
28602859 Type resultTy;
28612860 if (auto fn = dyn_cast<FuncDecl>(D)) {
@@ -2867,6 +2866,16 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
28672866 resultTy = TupleType::getEmpty (AFD->getASTContext ());
28682867 }
28692868
2869+ auto *returnTypeRepr = AFD->getResultTypeRepr ();
2870+ llvm::Optional<LifetimeDependenceInfo> lifetimeDependenceInfo;
2871+ if (returnTypeRepr) {
2872+ if (auto *lifetimeDependentRepr =
2873+ dyn_cast<LifetimeDependentReturnTypeRepr>(returnTypeRepr)) {
2874+ lifetimeDependenceInfo = validateLifetimeDependenceInfo (
2875+ lifetimeDependentRepr, resultTy, D, /* allowIndex*/ false );
2876+ }
2877+ }
2878+
28702879 // (Args...) -> Result
28712880 Type funcTy;
28722881
0 commit comments