Skip to content

[ConstraintSolver] NFC: Add option to control early termination of shrinking phase #11085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ namespace swift {

unsigned SolverBindingThreshold = 1024 * 1024;

/// \brief The upper bound to number of sub-expressions unsolved
/// before termination of the shrink phrase of the constraint solver.
unsigned SolverShrinkUnsolvedThreshold = 5;

/// The maximum depth to which to test decl circularity.
unsigned MaxCircularityDepth = 500;

Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def solver_memory_threshold : Separate<["-"], "solver-memory-threshold">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Set the upper bound for memory consumption, in bytes, by the constraint solver">;

def solver_shrink_unsolved_threshold : Separate<["-"], "solver-shrink-unsolved-threshold">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Set The upper bound to number of sub-expressions unsolved before termination of the shrink phrase">;

def value_recursion_threshold : Separate<["-"], "value-recursion-threshold">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Set the maximum depth for direct recursion in value types">;
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ static void addCommonFrontendArgs(const ToolChain &TC,
inputArgs.AddLastArg(arguments, options::OPT_swift_version);
inputArgs.AddLastArg(arguments, options::OPT_enforce_exclusivity_EQ);
inputArgs.AddLastArg(arguments, options::OPT_stats_output_dir);
inputArgs.AddLastArg(arguments,
options::OPT_solver_shrink_unsolved_threshold);

// Pass on any build config options
inputArgs.AddAllArgs(arguments, options::OPT_D);
Expand Down
11 changes: 11 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,17 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.SolverMemoryThreshold = threshold;
}

if (const Arg *A = Args.getLastArg(OPT_solver_shrink_unsolved_threshold)) {
unsigned threshold;
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
return true;
}

Opts.SolverShrinkUnsolvedThreshold = threshold;
}

if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
unsigned threshold;
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,8 @@ class ConstraintSystem {
}
}

return unsolvedDisjunctions >= 5;
unsigned threshold = cs->TC.getLangOpts().SolverShrinkUnsolvedThreshold;
return unsolvedDisjunctions >= threshold;
}
};

Expand Down