@@ -2577,8 +2577,8 @@ static Type validateParameterType(ParamDecl *decl) {
2577
2577
}
2578
2578
2579
2579
llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo (
2580
- LifetimeDependentReturnTypeRepr *lifetimeDependentRepr, Decl *decl ,
2581
- bool allowIndex) {
2580
+ LifetimeDependentReturnTypeRepr *lifetimeDependentRepr, Type resultTy ,
2581
+ Decl *decl, bool allowIndex) {
2582
2582
auto *afd = cast<AbstractFunctionDecl>(decl);
2583
2583
auto *dc = decl->getDeclContext ();
2584
2584
auto &ctx = dc->getASTContext ();
@@ -2592,26 +2592,35 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
2592
2592
auto loc = specifier.getLoc ();
2593
2593
auto kind = specifier.getLifetimeDependenceKind ();
2594
2594
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 ;
2615
2624
}
2616
2625
if (copyLifetimeParamIndices.test (paramIndexToSet) ||
2617
2626
borrowLifetimeParamIndices.test (paramIndexToSet)) {
@@ -2846,16 +2855,6 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
2846
2855
}
2847
2856
}
2848
2857
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
-
2859
2858
// Result
2860
2859
Type resultTy;
2861
2860
if (auto fn = dyn_cast<FuncDecl>(D)) {
@@ -2867,6 +2866,16 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
2867
2866
resultTy = TupleType::getEmpty (AFD->getASTContext ());
2868
2867
}
2869
2868
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
+
2870
2879
// (Args...) -> Result
2871
2880
Type funcTy;
2872
2881
0 commit comments