Skip to content

Commit d99d881

Browse files
committed
[CS] NFC: Factor out base class SyntacticElementTargetRewriter
Pass this instead of a function for rewriting targets.
1 parent 002c6d1 commit d99d881

File tree

3 files changed

+110
-167
lines changed

3 files changed

+110
-167
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,17 @@ 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 std::optional<SyntacticElementTarget>
2069+
rewriteTarget(SyntacticElementTarget target) = 0;
2070+
2071+
virtual ~SyntacticElementTargetRewriter() = default;
2072+
};
20662073

20672074
enum class ConstraintSystemPhase {
20682075
ConstraintGeneration,
@@ -5534,67 +5541,38 @@ class ConstraintSystem {
55345541
/// Apply the given solution to the given function's body and, for
55355542
/// closure expressions, the expression itself.
55365543
///
5537-
/// \param solution The solution to apply.
55385544
/// \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.
55435546
///
55445547
SolutionApplicationToFunctionResult
5545-
applySolution(Solution &solution, AnyFunctionRef fn, DeclContext *&currentDC,
5546-
std::function<std::optional<SyntacticElementTarget>(
5547-
SyntacticElementTarget)>
5548-
rewriteTarget);
5548+
applySolution(AnyFunctionRef fn, SyntacticElementTargetRewriter &rewriter);
55495549

55505550
/// Apply the given solution to the given closure body.
55515551
///
5552-
///
5553-
/// \param solution The solution to apply.
55545552
/// \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.
55595554
///
55605555
/// \returns true if solution cannot be applied.
5561-
bool applySolutionToBody(Solution &solution, AnyFunctionRef fn,
5562-
DeclContext *&currentDC,
5563-
std::function<std::optional<SyntacticElementTarget>(
5564-
SyntacticElementTarget)>
5565-
rewriteTarget);
5556+
bool applySolutionToBody(AnyFunctionRef fn,
5557+
SyntacticElementTargetRewriter &rewriter);
55665558

55675559
/// Apply the given solution to the given SingleValueStmtExpr.
55685560
///
5569-
/// \param solution The solution to apply.
55705561
/// \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.
55755563
///
55765564
/// \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);
55825567

55835568
/// Apply the given solution to the given tap expression.
55845569
///
5585-
/// \param solution The solution to apply.
55865570
/// \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.
55915572
///
55925573
/// \returns true if solution cannot be applied.
5593-
bool applySolutionToBody(Solution &solution, TapExpr *tapExpr,
5594-
DeclContext *&currentDC,
5595-
std::function<std::optional<SyntacticElementTarget>(
5596-
SyntacticElementTarget)>
5597-
rewriteTarget);
5574+
bool applySolutionToBody(TapExpr *tapExpr,
5575+
SyntacticElementTargetRewriter &rewriter);
55985576

55995577
/// Reorder the disjunctive clauses for a given expression to
56005578
/// increase the likelihood that a favored constraint will be successfully

0 commit comments

Comments
 (0)