Skip to content

Commit 1f232f7

Browse files
committed
[Constraint solver] Remove ExprTypeCheckListener.
The last client of this listener-based interface has been refactored, so remove it.
1 parent 87d86f3 commit 1f232f7

File tree

4 files changed

+11
-83
lines changed

4 files changed

+11
-83
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ static bool debugConstraintSolverForTarget(
11411141

11421142
Optional<std::vector<Solution>> ConstraintSystem::solve(
11431143
SolutionApplicationTarget &target,
1144-
ExprTypeCheckListener *listener,
11451144
FreeTypeVariableBinding allowFreeTypeVariables
11461145
) {
11471146
llvm::SaveAndRestore<bool> debugForExpr(
@@ -1171,7 +1170,7 @@ Optional<std::vector<Solution>> ConstraintSystem::solve(
11711170
// when there is an error and attempts to salvage an ill-formed program.
11721171
for (unsigned stage = 0; stage != 2; ++stage) {
11731172
auto solution = (stage == 0)
1174-
? solveImpl(target, listener, allowFreeTypeVariables)
1173+
? solveImpl(target, allowFreeTypeVariables)
11751174
: salvage();
11761175

11771176
switch (solution.getKind()) {
@@ -1237,7 +1236,6 @@ Optional<std::vector<Solution>> ConstraintSystem::solve(
12371236

12381237
SolutionResult
12391238
ConstraintSystem::solveImpl(SolutionApplicationTarget &target,
1240-
ExprTypeCheckListener *listener,
12411239
FreeTypeVariableBinding allowFreeTypeVariables) {
12421240
if (getASTContext().TypeCheckerOpts.DebugConstraintSolver) {
12431241
auto &log = getASTContext().TypeCheckerDebug->getStream();
@@ -1260,13 +1258,6 @@ ConstraintSystem::solveImpl(SolutionApplicationTarget &target,
12601258
if (generateConstraints(target, allowFreeTypeVariables))
12611259
return SolutionResult::forError();;
12621260

1263-
// Notify the listener that we've built the constraint system.
1264-
if (Expr *expr = target.getAsExpr()) {
1265-
if (listener && listener->builtConstraints(*this, expr)) {
1266-
return SolutionResult::forError();
1267-
}
1268-
}
1269-
12701261
// Try to solve the constraint system using computed suggestions.
12711262
SmallVector<Solution, 4> solutions;
12721263
solve(solutions, allowFreeTypeVariables);

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,8 +2309,7 @@ class ConstraintSystem {
23092309
friend Optional<SolutionApplicationTarget>
23102310
swift::TypeChecker::typeCheckExpression(SolutionApplicationTarget &target,
23112311
bool &unresolvedTypeExprs,
2312-
TypeCheckExprOptions options,
2313-
ExprTypeCheckListener *listener);
2312+
TypeCheckExprOptions options);
23142313

23152314
/// Emit the fixes computed as part of the solution, returning true if we were
23162315
/// able to emit an error message, or false if none of the fixits worked out.
@@ -4453,11 +4452,9 @@ class ConstraintSystem {
44534452
/// Solve the system of constraints generated from provided expression.
44544453
///
44554454
/// \param target The target to generate constraints from.
4456-
/// \param listener The callback to check solving progress.
44574455
/// \param allowFreeTypeVariables How to bind free type variables in
44584456
/// the solution.
44594457
SolutionResult solveImpl(SolutionApplicationTarget &target,
4460-
ExprTypeCheckListener *listener,
44614458
FreeTypeVariableBinding allowFreeTypeVariables
44624459
= FreeTypeVariableBinding::Disallow);
44634460

@@ -4470,15 +4467,13 @@ class ConstraintSystem {
44704467
///
44714468
/// \param target The target that we'll generate constraints from, which
44724469
/// may be updated by the solving process.
4473-
/// \param listener The callback to check solving progress.
44744470
/// \param allowFreeTypeVariables How to bind free type variables in
44754471
/// the solution.
44764472
///
44774473
/// \returns the set of solutions, if any were found, or \c None if an
44784474
/// error occurred. When \c None, an error has been emitted.
44794475
Optional<std::vector<Solution>> solve(
44804476
SolutionApplicationTarget &target,
4481-
ExprTypeCheckListener *listener,
44824477
FreeTypeVariableBinding allowFreeTypeVariables
44834478
= FreeTypeVariableBinding::Disallow);
44844479

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,16 +1958,6 @@ bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc) {
19581958
return true;
19591959
}
19601960

1961-
ExprTypeCheckListener::~ExprTypeCheckListener() { }
1962-
1963-
bool ExprTypeCheckListener::builtConstraints(ConstraintSystem &cs, Expr *expr) {
1964-
return false;
1965-
}
1966-
1967-
Expr *ExprTypeCheckListener::appliedSolution(Solution &solution, Expr *expr) {
1968-
return expr;
1969-
}
1970-
19711961
void ParentConditionalConformance::diagnoseConformanceStack(
19721962
DiagnosticEngine &diags, SourceLoc loc,
19731963
ArrayRef<ParentConditionalConformance> conformances) {
@@ -1999,14 +1989,13 @@ bool GenericRequirementsCheckListener::diagnoseUnsatisfiedRequirement(
19991989
Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
20001990
TypeLoc convertType,
20011991
ContextualTypePurpose convertTypePurpose,
2002-
TypeCheckExprOptions options,
2003-
ExprTypeCheckListener *listener) {
1992+
TypeCheckExprOptions options) {
20041993
SolutionApplicationTarget target(
20051994
expr, dc, convertTypePurpose, convertType,
20061995
options.contains(TypeCheckExprFlags::IsDiscarded));
20071996
bool unresolvedTypeExprs = false;
20081997
auto resultTarget = typeCheckExpression(
2009-
target, unresolvedTypeExprs, options, listener);
1998+
target, unresolvedTypeExprs, options);
20101999
if (!resultTarget) {
20112000
expr = target.getAsExpr();
20122001
return Type();
@@ -2027,8 +2016,7 @@ Optional<SolutionApplicationTarget>
20272016
TypeChecker::typeCheckExpression(
20282017
SolutionApplicationTarget &target,
20292018
bool &unresolvedTypeExprs,
2030-
TypeCheckExprOptions options,
2031-
ExprTypeCheckListener *listener) {
2019+
TypeCheckExprOptions options) {
20322020
unresolvedTypeExprs = false;
20332021
Expr *expr = target.getAsExpr();
20342022
DeclContext *dc = target.getDeclContext();
@@ -2076,7 +2064,7 @@ TypeChecker::typeCheckExpression(
20762064
allowFreeTypeVariables = FreeTypeVariableBinding::UnresolvedType;
20772065

20782066
// Attempt to solve the constraint system.
2079-
auto viable = cs.solve(target, listener, allowFreeTypeVariables);
2067+
auto viable = cs.solve(target, allowFreeTypeVariables);
20802068
if (!viable) {
20812069
target.setExpr(expr);
20822070
return None;
@@ -2107,13 +2095,6 @@ TypeChecker::typeCheckExpression(
21072095
}
21082096
Expr *result = resultTarget->getAsExpr();
21092097

2110-
// Notify listener that we've applied the solution.
2111-
if (listener) {
2112-
result = listener->appliedSolution(solution, result);
2113-
if (!result)
2114-
return None;
2115-
}
2116-
21172098
// Unless the client has disabled them, perform syntactic checks on the
21182099
// expression now.
21192100
if (!cs.shouldSuppressDiagnostics()) {
@@ -2137,8 +2118,7 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
21372118
Type TypeChecker::
21382119
getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
21392120
ConcreteDeclRef &referencedDecl,
2140-
FreeTypeVariableBinding allowFreeTypeVariables,
2141-
ExprTypeCheckListener *listener) {
2121+
FreeTypeVariableBinding allowFreeTypeVariables) {
21422122
auto &Context = dc->getASTContext();
21432123
FrontendStatsTracer StatsTracer(Context.Stats,
21442124
"typecheck-expr-no-apply", expr);
@@ -2162,7 +2142,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
21622142
expr->setType(Type());
21632143
SolutionApplicationTarget target(
21642144
expr, dc, CTP_Unused, Type(), /*isDiscarded=*/false);
2165-
auto viable = cs.solve(target, listener, allowFreeTypeVariables);
2145+
auto viable = cs.solve(target, allowFreeTypeVariables);
21662146
if (!viable) {
21672147
recoverOriginalType();
21682148
return Type();

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -258,33 +258,6 @@ enum class FreeTypeVariableBinding {
258258
UnresolvedType
259259
};
260260

261-
/// An abstract interface that can interact with the type checker during
262-
/// the type checking of a particular expression.
263-
class ExprTypeCheckListener {
264-
public:
265-
virtual ~ExprTypeCheckListener();
266-
267-
/// Callback invoked once the constraint system has been constructed.
268-
///
269-
/// \param cs The constraint system that has been constructed.
270-
///
271-
/// \param expr The pre-checked expression from which the constraint system
272-
/// was generated.
273-
///
274-
/// \returns true if an error occurred that is not itself part of the
275-
/// constraint system, or false otherwise.
276-
virtual bool builtConstraints(constraints::ConstraintSystem &cs, Expr *expr);
277-
278-
/// Callback invokes once the chosen solution has been applied to the
279-
/// expression.
280-
///
281-
/// The callback may further alter the expression, returning either a
282-
/// new expression (to replace the result) or a null pointer to indicate
283-
/// failure.
284-
virtual Expr *appliedSolution(constraints::Solution &solution,
285-
Expr *expr);
286-
};
287-
288261
/// A conditional conformance that implied some other requirements. That is, \c
289262
/// ConformingType conforming to \c Protocol may have required additional
290263
/// requirements to be satisfied.
@@ -757,23 +730,17 @@ Expr *findLHS(DeclContext *DC, Expr *E, Identifier name);
757730
///
758731
/// \param options Options that control how type checking is performed.
759732
///
760-
/// \param listener If non-null, a listener that will be notified of important
761-
/// events in the type checking of this expression, and which can introduce
762-
/// additional constraints.
763-
///
764733
/// \returns The type of the top-level expression, or Type() if an
765734
/// error occurred.
766735
Type typeCheckExpression(Expr *&expr, DeclContext *dc,
767736
TypeLoc convertType = TypeLoc(),
768737
ContextualTypePurpose convertTypePurpose = CTP_Unused,
769-
TypeCheckExprOptions options = TypeCheckExprOptions(),
770-
ExprTypeCheckListener *listener = nullptr);
738+
TypeCheckExprOptions options = TypeCheckExprOptions());
771739

772740
Optional<constraints::SolutionApplicationTarget>
773741
typeCheckExpression(constraints::SolutionApplicationTarget &target,
774742
bool &unresolvedTypeExprs,
775-
TypeCheckExprOptions options = TypeCheckExprOptions(),
776-
ExprTypeCheckListener *listener = nullptr);
743+
TypeCheckExprOptions options = TypeCheckExprOptions());
777744

778745
/// Type check the given expression and return its type without
779746
/// applying the solution.
@@ -786,17 +753,12 @@ typeCheckExpression(constraints::SolutionApplicationTarget &target,
786753
/// \param allowFreeTypeVariables Whether free type variables are allowed in
787754
/// the solution, and what to do with them.
788755
///
789-
/// \param listener If non-null, a listener that will be notified of important
790-
/// events in the type checking of this expression, and which can introduce
791-
/// additional constraints.
792-
///
793756
/// \returns the type of \p expr on success, Type() otherwise.
794757
/// FIXME: expr may still be modified...
795758
Type getTypeOfExpressionWithoutApplying(
796759
Expr *&expr, DeclContext *dc, ConcreteDeclRef &referencedDecl,
797760
FreeTypeVariableBinding allowFreeTypeVariables =
798-
FreeTypeVariableBinding::Disallow,
799-
ExprTypeCheckListener *listener = nullptr);
761+
FreeTypeVariableBinding::Disallow);
800762

801763
/// Return the type of operator function for specified LHS, or a null
802764
/// \c Type on error.

0 commit comments

Comments
 (0)