[ConstraintSystem] Add an option to disable the constraint solver perf hacks.

This is helpful in experimenting with constraint solver changes that
might help us remove some of these unsound options. It's not ever mean
to be enabled, but if we're able to remove the things guarded by the
option we can eventually remove the option.
This commit is contained in:
Mark Lacey
2018-08-06 11:48:19 -07:00
parent b8cb40b950
commit 3c9cb97c86
6 changed files with 27 additions and 3 deletions

View File

@@ -122,6 +122,9 @@ namespace swift {
/// completions.
bool CodeCompleteCallPatternHeuristics = false;
/// Disable constraint system performance hacks.
bool DisableConstraintSolverPerformanceHacks = false;
///
/// Flags for use by tests
///

View File

@@ -183,6 +183,9 @@ def debug_time_function_bodies : Flag<["-"], "debug-time-function-bodies">,
def debug_time_expression_type_checking : Flag<["-"], "debug-time-expression-type-checking">,
HelpText<"Dumps the time it takes to type-check each expression">;
def disable_constraint_solver_performance_hacks : Flag<["-"], "disable-constraint-solver-performance-hacks">,
HelpText<"Disable all the hacks in the constraint solver">;
def debug_assert_immediately : Flag<["-"], "debug-assert-immediately">,
DebugCrashOpt, HelpText<"Force an assertion failure immediately">;
def debug_assert_after_parse : Flag<["-"], "debug-assert-after-parse">,

View File

@@ -352,6 +352,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.UseDarwinPreStableABIBit = true;
#endif
Opts.DisableConstraintSolverPerformanceHacks |=
Args.hasArg(OPT_disable_constraint_solver_performance_hacks);
// Must be processed after any other language options that could affect
// platform conditions.
bool UnsupportedOS, UnsupportedArch;

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -3539,6 +3539,8 @@ Type ConstraintSystem::generateConstraints(Pattern *pattern,
}
void ConstraintSystem::optimizeConstraints(Expr *e) {
if (TC.getLangOpts().DisableConstraintSolverPerformanceHacks)
return;
SmallVector<Expr *, 16> linkedExprs;

View File

@@ -86,6 +86,9 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
}
bool ConstraintSystem::worseThanBestSolution() const {
if (TC.getLangOpts().DisableConstraintSolverPerformanceHacks)
return false;
if (retainAllSolutions())
return false;

View File

@@ -129,9 +129,13 @@ Solution ConstraintSystem::finalize(
// Update the best score we've seen so far.
if (solverState && !retainAllSolutions()) {
assert(!solverState->BestScore || CurrentScore <= *solverState->BestScore);
assert(TC.getLangOpts().DisableConstraintSolverPerformanceHacks ||
!solverState->BestScore || CurrentScore <= *solverState->BestScore);
if (!solverState->BestScore || CurrentScore <= *solverState->BestScore) {
solverState->BestScore = CurrentScore;
}
}
for (auto tv : TypeVariables) {
if (getFixedType(tv))
@@ -1763,6 +1767,9 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
Constraint *successfulConstraint,
ASTContext &ctx) {
if (ctx.LangOpts.DisableConstraintSolverPerformanceHacks)
return false;
// If the successfully applied constraint is favored, we'll consider that to
// be the "best".
if (successfulConstraint->isFavored() && !constraint->isFavored()) {
@@ -1832,6 +1839,9 @@ static bool shouldSkipDisjunctionChoice(ConstraintSystem &cs,
if (!cs.shouldAttemptFixes() && choice.isUnavailable())
return true;
if (cs.TC.getLangOpts().DisableConstraintSolverPerformanceHacks)
return false;
// Don't attempt to solve for generic operators if we already have
// a non-generic solution.