@@ -1909,57 +1909,6 @@ bool GenericRequirementsCheckListener::diagnoseUnsatisfiedRequirement(
1909
1909
return false ;
1910
1910
}
1911
1911
1912
- bool TypeChecker::
1913
- solveForExpression (Expr *&expr, DeclContext *dc, Type convertType,
1914
- FreeTypeVariableBinding allowFreeTypeVariables,
1915
- ExprTypeCheckListener *listener, ConstraintSystem &cs,
1916
- SmallVectorImpl<Solution> &viable,
1917
- TypeCheckExprOptions options) {
1918
- // Attempt to solve the constraint system.
1919
- auto solution = cs.solve (expr,
1920
- convertType,
1921
- listener,
1922
- viable,
1923
- allowFreeTypeVariables);
1924
-
1925
- // The constraint system has failed
1926
- if (solution == ConstraintSystem::SolutionKind::Error)
1927
- return true ;
1928
-
1929
- // If the system is unsolved or there are multiple solutions present but
1930
- // type checker options do not allow unresolved types, let's try to salvage
1931
- if (solution == ConstraintSystem::SolutionKind::Unsolved
1932
- || (viable.size () != 1 &&
1933
- !options.contains (TypeCheckExprFlags::AllowUnresolvedTypeVariables))) {
1934
- if (options.contains (TypeCheckExprFlags::SuppressDiagnostics))
1935
- return true ;
1936
-
1937
- // Try to provide a decent diagnostic.
1938
- if (cs.salvage (viable, expr)) {
1939
- // If salvage produced an error message, then it failed to salvage the
1940
- // expression, just bail out having reported the error.
1941
- return true ;
1942
- }
1943
-
1944
- // The system was salvaged; continue on as if nothing happened.
1945
- }
1946
-
1947
- if (getLangOpts ().DebugConstraintSolver ) {
1948
- auto &log = Context.TypeCheckerDebug ->getStream ();
1949
- if (viable.size () == 1 ) {
1950
- log << " ---Solution---\n " ;
1951
- viable[0 ].dump (log);
1952
- } else {
1953
- for (unsigned i = 0 , e = viable.size (); i != e; ++i) {
1954
- log << " --- Solution #" << i << " ---\n " ;
1955
- viable[i].dump (log);
1956
- }
1957
- }
1958
- }
1959
-
1960
- return false ;
1961
- }
1962
-
1963
1912
#pragma mark High-level entry points
1964
1913
Type TypeChecker::typeCheckExpression (Expr *&expr, DeclContext *dc,
1965
1914
TypeLoc convertType,
@@ -1976,6 +1925,13 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
1976
1925
1977
1926
// Construct a constraint system from this expression.
1978
1927
ConstraintSystemOptions csOptions = ConstraintSystemFlags::AllowFixes;
1928
+
1929
+ if (options.contains (TypeCheckExprFlags::SuppressDiagnostics))
1930
+ csOptions |= ConstraintSystemFlags::SuppressDiagnostics;
1931
+
1932
+ if (options.contains (TypeCheckExprFlags::AllowUnresolvedTypeVariables))
1933
+ csOptions |= ConstraintSystemFlags::AllowUnresolvedTypeVariables;
1934
+
1979
1935
ConstraintSystem cs (*this , dc, csOptions);
1980
1936
cs.baseCS = baseCS;
1981
1937
CleanupIllFormedExpressionRAII cleanup (expr);
@@ -2007,9 +1963,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2007
1963
// that we don't later treat it as an actual conversion constraint.
2008
1964
if (options.contains (TypeCheckExprFlags::ConvertTypeIsOnlyAHint))
2009
1965
convertType = TypeLoc ();
2010
-
2011
- bool suppressDiagnostics =
2012
- options.contains (TypeCheckExprFlags::SuppressDiagnostics);
2013
1966
2014
1967
// If the client can handle unresolved type variables, leave them in the
2015
1968
// system.
@@ -2019,8 +1972,8 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2019
1972
2020
1973
// Attempt to solve the constraint system.
2021
1974
SmallVector<Solution, 4 > viable;
2022
- if (solveForExpression (expr, dc, convertType.getType (),
2023
- allowFreeTypeVariables, listener, cs, viable, options ))
1975
+ if (cs. solve (expr, convertType.getType (), listener, viable ,
1976
+ allowFreeTypeVariables))
2024
1977
return Type ();
2025
1978
2026
1979
// If the client allows the solution to have unresolved type expressions,
@@ -2046,11 +1999,10 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2046
1999
}
2047
2000
2048
2001
// Apply the solution to the expression.
2049
- bool isDiscarded = options.contains (TypeCheckExprFlags::IsDiscarded);
2050
- bool skipClosures = options.contains (TypeCheckExprFlags::SkipMultiStmtClosures);
2051
- result = cs.applySolution (solution, result, convertType.getType (),
2052
- isDiscarded, suppressDiagnostics,
2053
- skipClosures);
2002
+ result = cs.applySolution (
2003
+ solution, result, convertType.getType (),
2004
+ options.contains (TypeCheckExprFlags::IsDiscarded),
2005
+ options.contains (TypeCheckExprFlags::SkipMultiStmtClosures));
2054
2006
if (!result) {
2055
2007
// Failure already diagnosed, above, as part of applying the solution.
2056
2008
return Type ();
@@ -2072,7 +2024,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2072
2024
2073
2025
// Unless the client has disabled them, perform syntactic checks on the
2074
2026
// expression now.
2075
- if (!suppressDiagnostics &&
2027
+ if (!cs. shouldSuppressDiagnostics () &&
2076
2028
!options.contains (TypeCheckExprFlags::DisableStructuralChecks)) {
2077
2029
bool isExprStmt = options.contains (TypeCheckExprFlags::IsExprStmt);
2078
2030
performSyntacticExprDiagnostics (*this , result, dc, isExprStmt);
@@ -2092,7 +2044,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
2092
2044
referencedDecl = nullptr ;
2093
2045
2094
2046
// Construct a constraint system from this expression.
2095
- ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes );
2047
+ ConstraintSystem cs (*this , dc, ConstraintSystemFlags::SuppressDiagnostics );
2096
2048
CleanupIllFormedExpressionRAII cleanup (expr);
2097
2049
2098
2050
// Attempt to solve the constraint system.
@@ -2108,9 +2060,8 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
2108
2060
// re-check.
2109
2061
if (needClearType)
2110
2062
expr->setType (Type ());
2111
- if (solveForExpression (expr, dc, /* convertType*/ Type (),
2112
- allowFreeTypeVariables, listener, cs, viable,
2113
- TypeCheckExprFlags::SuppressDiagnostics)) {
2063
+ if (cs.solve (expr, /* convertType*/ Type (), listener, viable,
2064
+ allowFreeTypeVariables)) {
2114
2065
recoverOriginalType ();
2115
2066
return Type ();
2116
2067
}
@@ -2177,8 +2128,8 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
2177
2128
2178
2129
// Construct a constraint system from this expression.
2179
2130
ConstraintSystemOptions options;
2180
- options |= ConstraintSystemFlags::AllowFixes;
2181
2131
options |= ConstraintSystemFlags::ReturnAllDiscoveredSolutions;
2132
+ options |= ConstraintSystemFlags::SuppressDiagnostics;
2182
2133
2183
2134
ConstraintSystem cs (*this , dc, options);
2184
2135
@@ -2194,9 +2145,8 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
2194
2145
if (originalType && originalType->hasError ())
2195
2146
expr->setType (Type ());
2196
2147
2197
- solveForExpression (expr, dc, /* convertType*/ Type (), allowFreeTypeVariables,
2198
- listener, cs, viable,
2199
- TypeCheckExprFlags::SuppressDiagnostics);
2148
+ cs.solve (expr, /* convertType*/ Type (), listener, viable,
2149
+ allowFreeTypeVariables);
2200
2150
}
2201
2151
2202
2152
for (auto &solution : viable) {
@@ -2210,7 +2160,7 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
2210
2160
PrettyStackTraceExpr stackTrace (Context, " type-checking" , expr);
2211
2161
2212
2162
// Construct a constraint system from this expression.
2213
- ConstraintSystem CS (*this , DC, ConstraintSystemFlags::AllowFixes );
2163
+ ConstraintSystem CS (*this , DC, ConstraintSystemFlags::SuppressDiagnostics );
2214
2164
CleanupIllFormedExpressionRAII cleanup (expr);
2215
2165
2216
2166
auto *SE = cast<SequenceExpr>(expr);
0 commit comments