Skip to content

Commit 9fcda11

Browse files
authored
[CS] Another post CSDiag cleanup (#30168)
[CS] Another post CSDiag cleanup
2 parents 101dd2d + 39d988d commit 9fcda11

File tree

6 files changed

+9
-66
lines changed

6 files changed

+9
-66
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ bool ConstraintSystem::worseThanBestSolution() const {
9494
if (getASTContext().TypeCheckerOpts.DisableConstraintSolverPerformanceHacks)
9595
return false;
9696

97-
if (retainAllSolutions())
98-
return false;
99-
10097
if (!solverState || !solverState->BestScore ||
10198
CurrentScore <= *solverState->BestScore)
10299
return false;

lib/Sema/CSSolver.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ Solution ConstraintSystem::finalize() {
7070

7171
// Update the best score we've seen so far.
7272
auto &ctx = getASTContext();
73-
if (!retainAllSolutions()) {
74-
assert(ctx.TypeCheckerOpts.DisableConstraintSolverPerformanceHacks ||
75-
!solverState->BestScore || CurrentScore <= *solverState->BestScore);
73+
assert(ctx.TypeCheckerOpts.DisableConstraintSolverPerformanceHacks ||
74+
!solverState->BestScore || CurrentScore <= *solverState->BestScore);
7675

77-
if (!solverState->BestScore || CurrentScore <= *solverState->BestScore) {
78-
solverState->BestScore = CurrentScore;
79-
}
76+
if (!solverState->BestScore || CurrentScore <= *solverState->BestScore) {
77+
solverState->BestScore = CurrentScore;
8078
}
8179

8280
for (auto tv : getTypeVariables()) {
@@ -1311,8 +1309,7 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
13111309
// Filter deduced solutions, try to figure out if there is
13121310
// a single best solution to use, if not explicitly disabled
13131311
// by constraint system options.
1314-
if (!retainAllSolutions())
1315-
filterSolutions(solutions);
1312+
filterSolutions(solutions);
13161313

13171314
// We fail if there is no solution or the expression was too complex.
13181315
return solutions.empty() || getExpressionTooComplex(solutions);

lib/Sema/CSStep.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ class SolverStep {
228228
Optional<Score> getBestScore() const { return CS.solverState->BestScore; }
229229

230230
void filterSolutions(SmallVectorImpl<Solution> &solutions, bool minimize) {
231-
if (!CS.retainAllSolutions())
232-
CS.filterSolutions(solutions, minimize);
231+
CS.filterSolutions(solutions, minimize);
233232
}
234233

235234
/// Check whether constraint solver is running in "debug" mode,

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,24 +1004,20 @@ using ConstraintList = llvm::ilist<Constraint>;
10041004
enum class ConstraintSystemFlags {
10051005
/// Whether we allow the solver to attempt fixes to the system.
10061006
AllowFixes = 0x01,
1007-
1008-
/// If set, this is going to prevent constraint system from erasing all
1009-
/// discovered solutions except the best one.
1010-
ReturnAllDiscoveredSolutions = 0x04,
10111007

10121008
/// Set if the client wants diagnostics suppressed.
1013-
SuppressDiagnostics = 0x08,
1009+
SuppressDiagnostics = 0x02,
10141010

10151011
/// If set, the client wants a best-effort solution to the constraint system,
10161012
/// but can tolerate a solution where all of the constraints are solved, but
10171013
/// not all type variables have been determined. In this case, the constraint
10181014
/// system is not applied to the expression AST, but the ConstraintSystem is
10191015
/// left in-tact.
1020-
AllowUnresolvedTypeVariables = 0x10,
1016+
AllowUnresolvedTypeVariables = 0x04,
10211017

10221018
/// If set, constraint system always reuses type of pre-typechecked
10231019
/// expression, and doesn't dig into its subexpressions.
1024-
ReusePrecheckedType = 0x20,
1020+
ReusePrecheckedType = 0x08,
10251021
};
10261022

10271023
/// Options that affect the constraint system as a whole.
@@ -2168,13 +2164,6 @@ class ConstraintSystem {
21682164
bool hasFreeTypeVariables();
21692165

21702166
private:
2171-
/// Indicates if the constraint system should retain all of the
2172-
/// solutions it has deduced regardless of their score.
2173-
bool retainAllSolutions() const {
2174-
return Options.contains(
2175-
ConstraintSystemFlags::ReturnAllDiscoveredSolutions);
2176-
}
2177-
21782167
/// Finalize this constraint system; we're done attempting to solve
21792168
/// it.
21802169
///

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,39 +2226,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
22262226
return exprType;
22272227
}
22282228

2229-
void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
2230-
Expr *&expr, DeclContext *dc, SmallPtrSetImpl<TypeBase *> &types,
2231-
FreeTypeVariableBinding allowFreeTypeVariables,
2232-
ExprTypeCheckListener *listener) {
2233-
auto &Context = dc->getASTContext();
2234-
FrontendStatsTracer StatsTracer(Context.Stats,
2235-
"get-possible-types-no-apply", expr);
2236-
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
2237-
2238-
// Construct a constraint system from this expression.
2239-
ConstraintSystemOptions options;
2240-
options |= ConstraintSystemFlags::ReturnAllDiscoveredSolutions;
2241-
options |= ConstraintSystemFlags::SuppressDiagnostics;
2242-
2243-
ConstraintSystem cs(dc, options);
2244-
2245-
// Attempt to solve the constraint system.
2246-
const Type originalType = expr->getType();
2247-
if (originalType && originalType->hasError())
2248-
expr->setType(Type());
2249-
2250-
SolutionApplicationTarget target(
2251-
expr, dc, CTP_Unused, Type(), /*isDiscarded=*/false);
2252-
if (auto viable = cs.solve(target, listener, allowFreeTypeVariables)) {
2253-
expr = target.getAsExpr();
2254-
for (auto &solution : *viable) {
2255-
auto exprType = solution.simplifyType(cs.getType(expr));
2256-
assert(exprType && !exprType->hasTypeVariable());
2257-
types.insert(exprType.getPointer());
2258-
}
2259-
}
2260-
}
2261-
22622229
static FunctionType *
22632230
getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
22642231
ConcreteDeclRef &referencedDecl) {

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,6 @@ class TypeChecker final {
839839
FreeTypeVariableBinding::Disallow,
840840
ExprTypeCheckListener *listener = nullptr);
841841

842-
static void getPossibleTypesOfExpressionWithoutApplying(
843-
Expr *&expr, DeclContext *dc, SmallPtrSetImpl<TypeBase *> &types,
844-
FreeTypeVariableBinding allowFreeTypeVariables =
845-
FreeTypeVariableBinding::Disallow,
846-
ExprTypeCheckListener *listener = nullptr);
847-
848842
/// Return the type of operator function for specified LHS, or a null
849843
/// \c Type on error.
850844
static FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,

0 commit comments

Comments
 (0)