@@ -2059,10 +2059,17 @@ struct DynamicCallableMethods {
2059
2059
}
2060
2060
};
2061
2061
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 std::optional<SyntacticElementTarget>
2069
+ rewriteTarget (SyntacticElementTarget target) = 0 ;
2070
+
2071
+ virtual ~SyntacticElementTargetRewriter () = default ;
2072
+ };
2066
2073
2067
2074
enum class ConstraintSystemPhase {
2068
2075
ConstraintGeneration,
@@ -5534,67 +5541,38 @@ class ConstraintSystem {
5534
5541
// / Apply the given solution to the given function's body and, for
5535
5542
// / closure expressions, the expression itself.
5536
5543
// /
5537
- // / \param solution The solution to apply.
5538
5544
// / \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.
5545
+ // / \param rewriter The rewriter to apply the solution with.
5543
5546
// /
5544
5547
SolutionApplicationToFunctionResult
5545
- applySolution (Solution &solution, AnyFunctionRef fn, DeclContext *¤tDC,
5546
- std::function<std::optional<SyntacticElementTarget>(
5547
- SyntacticElementTarget)>
5548
- rewriteTarget);
5548
+ applySolution (AnyFunctionRef fn, SyntacticElementTargetRewriter &rewriter);
5549
5549
5550
5550
// / Apply the given solution to the given closure body.
5551
5551
// /
5552
- // /
5553
- // / \param solution The solution to apply.
5554
5552
// / \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.
5553
+ // / \param rewriter The rewriter to apply the solution with.
5559
5554
// /
5560
5555
// / \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);
5556
+ bool applySolutionToBody (AnyFunctionRef fn,
5557
+ SyntacticElementTargetRewriter &rewriter);
5566
5558
5567
5559
// / Apply the given solution to the given SingleValueStmtExpr.
5568
5560
// /
5569
- // / \param solution The solution to apply.
5570
5561
// / \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.
5562
+ // / \param rewriter The rewriter to apply the solution with.
5575
5563
// /
5576
5564
// / \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);
5565
+ bool applySolutionToSingleValueStmt (SingleValueStmtExpr *SVE,
5566
+ SyntacticElementTargetRewriter &rewriter);
5582
5567
5583
5568
// / Apply the given solution to the given tap expression.
5584
5569
// /
5585
- // / \param solution The solution to apply.
5586
5570
// / \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.
5571
+ // / \param rewriter The rewriter to apply the solution with.
5591
5572
// /
5592
5573
// / \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);
5574
+ bool applySolutionToBody (TapExpr *tapExpr,
5575
+ SyntacticElementTargetRewriter &rewriter);
5598
5576
5599
5577
// / Reorder the disjunctive clauses for a given expression to
5600
5578
// / increase the likelihood that a favored constraint will be successfully
0 commit comments