@@ -2062,38 +2062,6 @@ bool GenericRequirementsCheckListener::diagnoseUnsatisfiedRequirement(
2062
2062
return false ;
2063
2063
}
2064
2064
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
-
2097
2065
#pragma mark High-level entry points
2098
2066
Type TypeChecker::typeCheckExpression (Expr *&expr, DeclContext *dc,
2099
2067
TypeLoc convertType,
@@ -2102,18 +2070,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2102
2070
ExprTypeCheckListener *listener,
2103
2071
ConstraintSystem *baseCS) {
2104
2072
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 ();
2117
2073
FrontendStatsTracer StatsTracer (Context.Stats , " typecheck-expr" , expr);
2118
2074
PrettyStackTraceExpr stackTrace (Context, " type-checking" , expr);
2119
2075
@@ -2188,7 +2144,7 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
2188
2144
2189
2145
SmallVector<Solution, 4 > viable;
2190
2146
// Attempt to solve the constraint system.
2191
- if (cs.solve (expr, convertTo, & listener, viable, allowFreeTypeVariables))
2147
+ if (cs.solve (expr, convertTo, listener, viable, allowFreeTypeVariables))
2192
2148
return Type ();
2193
2149
2194
2150
// If the client allows the solution to have unresolved type expressions,
@@ -2202,7 +2158,8 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
2202
2158
2203
2159
auto result = expr;
2204
2160
auto &solution = viable[0 ];
2205
- result = listener.foundSolution (solution, result);
2161
+ if (listener)
2162
+ result = listener->foundSolution (solution, result);
2206
2163
if (!result)
2207
2164
return Type ();
2208
2165
@@ -2223,7 +2180,8 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
2223
2180
result = resultTarget->getAsExpr ();
2224
2181
2225
2182
// Notify listener that we've applied the solution.
2226
- result = listener.appliedSolution (solution, result);
2183
+ if (listener)
2184
+ result = listener->appliedSolution (solution, result);
2227
2185
if (!result)
2228
2186
return Type ();
2229
2187
0 commit comments