@@ -2059,10 +2059,19 @@ struct DynamicCallableMethods {
20592059 }
20602060};
20612061
2062- // / A function that rewrites a syntactic element target in the context
2063- // / of solution application.
2064- using RewriteTargetFn = std::function<std::optional<SyntacticElementTarget>(
2065- SyntacticElementTarget)>;
2062+ // / Abstract base class for applying a solution to a SyntacticElementTarget.
2063+ class SyntacticElementTargetRewriter {
2064+ public:
2065+ virtual Solution &getSolution () const = 0;
2066+ virtual DeclContext *&getCurrentDC () const = 0;
2067+
2068+ virtual void addLocalDeclToTypeCheck (Decl *D) = 0;
2069+
2070+ virtual std::optional<SyntacticElementTarget>
2071+ rewriteTarget (SyntacticElementTarget target) = 0 ;
2072+
2073+ virtual ~SyntacticElementTargetRewriter () = default ;
2074+ };
20662075
20672076enum class ConstraintSystemPhase {
20682077 ConstraintGeneration,
@@ -2071,18 +2080,6 @@ enum class ConstraintSystemPhase {
20712080 Finalization
20722081};
20732082
2074- // / Describes the result of applying a solution to a given function.
2075- enum class SolutionApplicationToFunctionResult {
2076- // / Application of the solution succeeded.
2077- Success,
2078- // / Application of the solution failed.
2079- // / TODO: This should probably go away entirely.
2080- Failure,
2081- // / The solution could not be applied immediately, and type checking for
2082- // / this function should be delayed until later.
2083- Delay,
2084- };
2085-
20862083// / Retrieve the closure type from the constraint system.
20872084struct GetClosureType {
20882085 ConstraintSystem &cs;
@@ -5534,67 +5531,38 @@ class ConstraintSystem {
55345531 // / Apply the given solution to the given function's body and, for
55355532 // / closure expressions, the expression itself.
55365533 // /
5537- // / \param solution The solution to apply.
55385534 // / \param fn The function to which the solution is being applied.
5539- // / \param currentDC The declaration context in which transformations
5540- // / will be applied.
5541- // / \param rewriteTarget Function that performs a rewrite of any targets
5542- // / within the context.
5535+ // / \param rewriter The rewriter to apply the solution with.
55435536 // /
5544- SolutionApplicationToFunctionResult
5545- applySolution (Solution &solution, AnyFunctionRef fn, DeclContext *¤tDC,
5546- std::function<std::optional<SyntacticElementTarget>(
5547- SyntacticElementTarget)>
5548- rewriteTarget);
5537+ bool applySolution (AnyFunctionRef fn,
5538+ SyntacticElementTargetRewriter &rewriter);
55495539
55505540 // / Apply the given solution to the given closure body.
55515541 // /
5552- // /
5553- // / \param solution The solution to apply.
55545542 // / \param fn The function or closure to which the solution is being applied.
5555- // / \param currentDC The declaration context in which transformations
5556- // / will be applied.
5557- // / \param rewriteTarget Function that performs a rewrite of any targets
5558- // / within the context.
5543+ // / \param rewriter The rewriter to apply the solution with.
55595544 // /
55605545 // / \returns true if solution cannot be applied.
5561- bool applySolutionToBody (Solution &solution, AnyFunctionRef fn,
5562- DeclContext *¤tDC,
5563- std::function<std::optional<SyntacticElementTarget>(
5564- SyntacticElementTarget)>
5565- rewriteTarget);
5546+ bool applySolutionToBody (AnyFunctionRef fn,
5547+ SyntacticElementTargetRewriter &rewriter);
55665548
55675549 // / Apply the given solution to the given SingleValueStmtExpr.
55685550 // /
5569- // / \param solution The solution to apply.
55705551 // / \param SVE The SingleValueStmtExpr to rewrite.
5571- // / \param DC The declaration context in which transformations will be
5572- // / applied.
5573- // / \param rewriteTarget Function that performs a rewrite of any targets
5574- // / within the context.
5552+ // / \param rewriter The rewriter to apply the solution with.
55755553 // /
55765554 // / \returns true if solution cannot be applied.
5577- bool applySolutionToSingleValueStmt (
5578- Solution &solution, SingleValueStmtExpr *SVE, DeclContext *DC,
5579- std::function<
5580- std::optional<SyntacticElementTarget>(SyntacticElementTarget)>
5581- rewriteTarget);
5555+ bool applySolutionToSingleValueStmt (SingleValueStmtExpr *SVE,
5556+ SyntacticElementTargetRewriter &rewriter);
55825557
55835558 // / Apply the given solution to the given tap expression.
55845559 // /
5585- // / \param solution The solution to apply.
55865560 // / \param tapExpr The tap expression to which the solution is being applied.
5587- // / \param currentDC The declaration context in which transformations
5588- // / will be applied.
5589- // / \param rewriteTarget Function that performs a rewrite of any
5590- // / solution application target within the context.
5561+ // / \param rewriter The rewriter to apply the solution with.
55915562 // /
55925563 // / \returns true if solution cannot be applied.
5593- bool applySolutionToBody (Solution &solution, TapExpr *tapExpr,
5594- DeclContext *¤tDC,
5595- std::function<std::optional<SyntacticElementTarget>(
5596- SyntacticElementTarget)>
5597- rewriteTarget);
5564+ bool applySolutionToBody (TapExpr *tapExpr,
5565+ SyntacticElementTargetRewriter &rewriter);
55985566
55995567 // / Reorder the disjunctive clauses for a given expression to
56005568 // / increase the likelihood that a favored constraint will be successfully
0 commit comments