@@ -2339,20 +2339,18 @@ isInvalidPartialApplication(ConstraintSystem &cs,
23392339 return {true , level};
23402340}
23412341
2342- // / Walk a closure AST to determine its effects.
2343- // /
2344- // / \returns a function's extended info describing the effects, as
2345- // / determined syntactically.
23462342FunctionType::ExtInfo ConstraintSystem::closureEffects (ClosureExpr *expr) {
2347- auto known = closureEffectsCache.find (expr);
2348- if (known != closureEffectsCache.end ())
2349- return known->second ;
2343+ return evaluateOrDefault (
2344+ getASTContext ().evaluator , ClosureEffectsRequest{expr},
2345+ FunctionType::ExtInfo ());
2346+ }
23502347
2348+ FunctionType::ExtInfo ClosureEffectsRequest::evaluate (
2349+ Evaluator &evaluator, ClosureExpr *expr) const {
23512350 // A walker that looks for 'try' and 'throw' expressions
23522351 // that aren't nested within closures, nested declarations,
23532352 // or exhaustive catches.
23542353 class FindInnerThrows : public ASTWalker {
2355- ConstraintSystem &CS;
23562354 DeclContext *DC;
23572355 bool FoundThrow = false ;
23582356
@@ -2449,7 +2447,7 @@ FunctionType::ExtInfo ConstraintSystem::closureEffects(ClosureExpr *expr) {
24492447 // Okay, now it should be safe to coerce the pattern.
24502448 // Pull the top-level pattern back out.
24512449 pattern = LabelItem.getPattern ();
2452- Type exnType = CS. getASTContext ().getErrorDecl ()->getDeclaredInterfaceType ();
2450+ Type exnType = DC-> getASTContext ().getErrorDecl ()->getDeclaredInterfaceType ();
24532451
24542452 if (!exnType)
24552453 return false ;
@@ -2501,8 +2499,8 @@ FunctionType::ExtInfo ConstraintSystem::closureEffects(ClosureExpr *expr) {
25012499 }
25022500
25032501 public:
2504- FindInnerThrows (ConstraintSystem &cs, DeclContext *dc)
2505- : CS(cs), DC(dc) {}
2502+ FindInnerThrows (DeclContext *dc)
2503+ : DC(dc) {}
25062504
25072505 bool foundThrow () { return FoundThrow; }
25082506 };
@@ -2525,23 +2523,21 @@ FunctionType::ExtInfo ConstraintSystem::closureEffects(ClosureExpr *expr) {
25252523 if (!body)
25262524 return ASTExtInfoBuilder ().withConcurrent (concurrent).build ();
25272525
2528- auto throwFinder = FindInnerThrows (* this , expr);
2526+ auto throwFinder = FindInnerThrows (expr);
25292527 body->walk (throwFinder);
2530- auto result = ASTExtInfoBuilder ()
2531- .withThrows (throwFinder.foundThrow ())
2532- .withAsync (bool (findAsyncNode (expr)))
2533- .withConcurrent (concurrent)
2534- .build ();
2535- closureEffectsCache[expr] = result;
2536- return result;
2528+ return ASTExtInfoBuilder ()
2529+ .withThrows (throwFinder.foundThrow ())
2530+ .withAsync (bool (findAsyncNode (expr)))
2531+ .withConcurrent (concurrent)
2532+ .build ();
25372533}
25382534
25392535bool ConstraintSystem::isAsynchronousContext (DeclContext *dc) {
25402536 if (auto func = dyn_cast<AbstractFunctionDecl>(dc))
25412537 return func->isAsyncContext ();
25422538
2543- if (auto closure = dyn_cast<ClosureExpr >(dc))
2544- return closureEffects ( closure). isAsync ();
2539+ if (auto closure = dyn_cast<AbstractClosureExpr >(dc))
2540+ return closure-> isBodyAsync ();
25452541
25462542 return false ;
25472543}
0 commit comments