@@ -2059,10 +2059,19 @@ 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 void addLocalDeclToTypeCheck (Decl *D) = 0;
2069
+
2070
+ virtual std::optional<SyntacticElementTarget>
2071
+ rewriteTarget (SyntacticElementTarget target) = 0 ;
2072
+
2073
+ virtual ~SyntacticElementTargetRewriter () = default ;
2074
+ };
2066
2075
2067
2076
enum class ConstraintSystemPhase {
2068
2077
ConstraintGeneration,
@@ -2071,18 +2080,6 @@ enum class ConstraintSystemPhase {
2071
2080
Finalization
2072
2081
};
2073
2082
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
-
2086
2083
// / Retrieve the closure type from the constraint system.
2087
2084
struct GetClosureType {
2088
2085
ConstraintSystem &cs;
@@ -5534,67 +5531,38 @@ class ConstraintSystem {
5534
5531
// / Apply the given solution to the given function's body and, for
5535
5532
// / closure expressions, the expression itself.
5536
5533
// /
5537
- // / \param solution The solution to apply.
5538
5534
// / \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.
5543
5536
// /
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);
5549
5539
5550
5540
// / Apply the given solution to the given closure body.
5551
5541
// /
5552
- // /
5553
- // / \param solution The solution to apply.
5554
5542
// / \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.
5559
5544
// /
5560
5545
// / \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);
5566
5548
5567
5549
// / Apply the given solution to the given SingleValueStmtExpr.
5568
5550
// /
5569
- // / \param solution The solution to apply.
5570
5551
// / \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.
5575
5553
// /
5576
5554
// / \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);
5582
5557
5583
5558
// / Apply the given solution to the given tap expression.
5584
5559
// /
5585
- // / \param solution The solution to apply.
5586
5560
// / \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.
5591
5562
// /
5592
5563
// / \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);
5598
5566
5599
5567
// / Reorder the disjunctive clauses for a given expression to
5600
5568
// / increase the likelihood that a favored constraint will be successfully
0 commit comments