Skip to content

Commit 5c6608f

Browse files
committed
[Constraint solver] Remove the FallbackDiagnosticListener.
It doesn’t do anything any more, because we’re handling error diagnostics locally without callbacks. Also collapse typeCheckExpressionImpl() into typeCheckExpression().
1 parent f8fd197 commit 5c6608f

File tree

2 files changed

+5
-56
lines changed

2 files changed

+5
-56
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,38 +2062,6 @@ bool GenericRequirementsCheckListener::diagnoseUnsatisfiedRequirement(
20622062
return false;
20632063
}
20642064

2065-
/// Sometimes constraint solver fails without producing any diagnostics,
2066-
/// that leads to crashes down the line in AST Verifier or SILGen
2067-
/// which, as a result, are much harder to figure out.
2068-
///
2069-
/// This class is intended to guard against situations like that by
2070-
/// keeping track of failures of different type-check phases, and
2071-
/// emitting fallback fatal error if any of them fail without producing
2072-
/// error diagnostic, and there were no errors emitted or scheduled to be
2073-
/// emitted previously.
2074-
class FallbackDiagnosticListener : public ExprTypeCheckListener {
2075-
ASTContext &Context;
2076-
TypeCheckExprOptions Options;
2077-
ExprTypeCheckListener *BaseListener;
2078-
2079-
public:
2080-
FallbackDiagnosticListener(ASTContext &ctx, TypeCheckExprOptions options,
2081-
ExprTypeCheckListener *base)
2082-
: Context(ctx), Options(options), BaseListener(base) {}
2083-
2084-
bool builtConstraints(ConstraintSystem &cs, Expr *expr) override {
2085-
return BaseListener ? BaseListener->builtConstraints(cs, expr) : false;
2086-
}
2087-
2088-
Expr *foundSolution(Solution &solution, Expr *expr) override {
2089-
return BaseListener ? BaseListener->foundSolution(solution, expr) : expr;
2090-
}
2091-
2092-
Expr *appliedSolution(Solution &solution, Expr *expr) override {
2093-
return BaseListener ? BaseListener->appliedSolution(solution, expr) : expr;
2094-
}
2095-
};
2096-
20972065
#pragma mark High-level entry points
20982066
Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
20992067
TypeLoc convertType,
@@ -2102,18 +2070,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
21022070
ExprTypeCheckListener *listener,
21032071
ConstraintSystem *baseCS) {
21042072
auto &Context = dc->getASTContext();
2105-
FallbackDiagnosticListener diagListener(Context, options, listener);
2106-
return typeCheckExpressionImpl(expr, dc, convertType, convertTypePurpose,
2107-
options, diagListener, baseCS);
2108-
}
2109-
2110-
Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
2111-
TypeLoc convertType,
2112-
ContextualTypePurpose convertTypePurpose,
2113-
TypeCheckExprOptions options,
2114-
ExprTypeCheckListener &listener,
2115-
ConstraintSystem *baseCS) {
2116-
auto &Context = dc->getASTContext();
21172073
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr", expr);
21182074
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
21192075

@@ -2188,7 +2144,7 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
21882144

21892145
SmallVector<Solution, 4> viable;
21902146
// Attempt to solve the constraint system.
2191-
if (cs.solve(expr, convertTo, &listener, viable, allowFreeTypeVariables))
2147+
if (cs.solve(expr, convertTo, listener, viable, allowFreeTypeVariables))
21922148
return Type();
21932149

21942150
// If the client allows the solution to have unresolved type expressions,
@@ -2202,7 +2158,8 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
22022158

22032159
auto result = expr;
22042160
auto &solution = viable[0];
2205-
result = listener.foundSolution(solution, result);
2161+
if (listener)
2162+
result = listener->foundSolution(solution, result);
22062163
if (!result)
22072164
return Type();
22082165

@@ -2223,7 +2180,8 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
22232180
result = resultTarget->getAsExpr();
22242181

22252182
// Notify listener that we've applied the solution.
2226-
result = listener.appliedSolution(solution, result);
2183+
if (listener)
2184+
result = listener->appliedSolution(solution, result);
22272185
if (!result)
22282186
return Type();
22292187

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -856,15 +856,6 @@ class TypeChecker final {
856856
TypeCheckExprOptions(), listener);
857857
}
858858

859-
private:
860-
static Type typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
861-
TypeLoc convertType,
862-
ContextualTypePurpose convertTypePurpose,
863-
TypeCheckExprOptions options,
864-
ExprTypeCheckListener &listener,
865-
constraints::ConstraintSystem *baseCS);
866-
867-
public:
868859
/// Type check the given expression and return its type without
869860
/// applying the solution.
870861
///

0 commit comments

Comments
 (0)