Skip to content

Commit c45e85f

Browse files
authored
Merge pull request #11085 from xedin/stop-shrinking-flag
[ConstraintSolver] NFC: Add option to control early termination of shrinking phase
2 parents fc04cc9 + 4f88725 commit c45e85f

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ namespace swift {
171171

172172
unsigned SolverBindingThreshold = 1024 * 1024;
173173

174+
/// \brief The upper bound to number of sub-expressions unsolved
175+
/// before termination of the shrink phrase of the constraint solver.
176+
unsigned SolverShrinkUnsolvedThreshold = 5;
177+
174178
/// The maximum depth to which to test decl circularity.
175179
unsigned MaxCircularityDepth = 500;
176180

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def solver_memory_threshold : Separate<["-"], "solver-memory-threshold">,
256256
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
257257
HelpText<"Set the upper bound for memory consumption, in bytes, by the constraint solver">;
258258

259+
def solver_shrink_unsolved_threshold : Separate<["-"], "solver-shrink-unsolved-threshold">,
260+
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
261+
HelpText<"Set The upper bound to number of sub-expressions unsolved before termination of the shrink phrase">;
262+
259263
def value_recursion_threshold : Separate<["-"], "value-recursion-threshold">,
260264
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
261265
HelpText<"Set the maximum depth for direct recursion in value types">;

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ static void addCommonFrontendArgs(const ToolChain &TC,
151151
inputArgs.AddLastArg(arguments, options::OPT_swift_version);
152152
inputArgs.AddLastArg(arguments, options::OPT_enforce_exclusivity_EQ);
153153
inputArgs.AddLastArg(arguments, options::OPT_stats_output_dir);
154+
inputArgs.AddLastArg(arguments,
155+
options::OPT_solver_shrink_unsolved_threshold);
154156

155157
// Pass on any build config options
156158
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,17 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10601060
Opts.SolverMemoryThreshold = threshold;
10611061
}
10621062

1063+
if (const Arg *A = Args.getLastArg(OPT_solver_shrink_unsolved_threshold)) {
1064+
unsigned threshold;
1065+
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
1066+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1067+
A->getAsString(Args), A->getValue());
1068+
return true;
1069+
}
1070+
1071+
Opts.SolverShrinkUnsolvedThreshold = threshold;
1072+
}
1073+
10631074
if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
10641075
unsigned threshold;
10651076
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,8 @@ class ConstraintSystem {
10741074
}
10751075
}
10761076

1077-
return unsolvedDisjunctions >= 5;
1077+
unsigned threshold = cs->TC.getLangOpts().SolverShrinkUnsolvedThreshold;
1078+
return unsolvedDisjunctions >= threshold;
10781079
}
10791080
};
10801081

0 commit comments

Comments
 (0)