Skip to content

Commit 05642d8

Browse files
committed
Sema: Add -solver-disable-splitter flag for debugging
We're not planning on removing the splitter because it is a big win in some cases, but we want to run it less often since it can also be a source of overhead. This flag allows us to compare performance to understand the tradeoffs better.
1 parent b895426 commit 05642d8

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,6 @@ namespace swift {
913913
/// is for testing purposes.
914914
std::vector<std::string> DebugForbidTypecheckPrefixes;
915915

916-
/// The upper bound to number of sub-expressions unsolved
917-
/// before termination of the shrink phrase of the constraint solver.
918-
unsigned SolverShrinkUnsolvedThreshold = 10;
919-
920-
/// Disable the shrink phase of the expression type checker.
921-
bool SolverDisableShrink = false;
922-
923916
/// Enable experimental operator designated types feature.
924917
bool EnableOperatorDesignatedTypes = false;
925918

@@ -935,6 +928,9 @@ namespace swift {
935928
/// Allow request evalutation to perform type checking lazily, instead of
936929
/// eagerly typechecking source files after parsing.
937930
bool EnableLazyTypecheck = false;
931+
932+
/// Disable the component splitter phase of the expression type checker.
933+
bool SolverDisableSplitter = false;
938934
};
939935

940936
/// Options for controlling the behavior of the Clang importer.

include/swift/Option/FrontendOptions.td

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,17 @@ def downgrade_typecheck_interface_error : Flag<["-"], "downgrade-typecheck-inter
825825
def enable_volatile_modules : Flag<["-"], "enable-volatile-modules">,
826826
HelpText<"Load Swift modules in memory">;
827827

828-
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;
828+
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">,
829+
HelpText<"Expression type checking timeout, in seconds">;
829830

830-
def solver_scope_threshold_EQ : Joined<["-"], "solver-scope-threshold=">;
831+
def solver_scope_threshold_EQ : Joined<["-"], "solver-scope-threshold=">,
832+
HelpText<"Expression type checking scope limit">;
831833

832-
def solver_trail_threshold_EQ : Joined<["-"], "solver-trail-threshold=">;
834+
def solver_trail_threshold_EQ : Joined<["-"], "solver-trail-threshold=">,
835+
HelpText<"Expression type checking trail change limit">;
833836

834-
def solver_disable_shrink :
835-
Flag<["-"], "solver-disable-shrink">,
836-
HelpText<"Disable the shrink phase of expression type checking">;
837+
def solver_disable_splitter : Flag<["-"], "solver-disable-splitter">,
838+
HelpText<"Disable the component splitter phase of expression type checking">;
837839

838840
def disable_constraint_solver_performance_hacks : Flag<["-"], "disable-constraint-solver-performance-hacks">,
839841
HelpText<"Disable all the hacks in the constraint solver">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,6 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
17751775
Opts.SolverScopeThreshold);
17761776
setUnsignedIntegerArgument(OPT_solver_trail_threshold_EQ,
17771777
Opts.SolverTrailThreshold);
1778-
setUnsignedIntegerArgument(OPT_solver_shrink_unsolved_threshold,
1779-
Opts.SolverShrinkUnsolvedThreshold);
17801778

17811779
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
17821780
Opts.DebugTimeExpressions |=
@@ -1865,8 +1863,8 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
18651863
Opts.DebugForbidTypecheckPrefixes.push_back(A);
18661864
}
18671865

1868-
if (Args.getLastArg(OPT_solver_disable_shrink))
1869-
Opts.SolverDisableShrink = true;
1866+
if (Args.getLastArg(OPT_solver_disable_splitter))
1867+
Opts.SolverDisableSplitter = true;
18701868

18711869
if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::Immediate)
18721870
Opts.DeferToRuntime = true;

lib/Sema/CSStep.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void SplitterStep::computeFollowupSteps(
9595
// Contract the edges of the constraint graph.
9696
CG.optimize();
9797

98+
if (CS.getASTContext().TypeCheckerOpts.SolverDisableSplitter) {
99+
steps.push_back(std::make_unique<ComponentStep>(
100+
CS, 0, &CS.InactiveConstraints, Solutions));
101+
return;
102+
}
103+
98104
// Compute the connected components of the constraint graph.
99105
auto components = CG.computeConnectedComponents(CS.getTypeVariables());
100106
unsigned numComponents = components.size();

validation-test/Sema/type_checker_perf/fast/array_concatenation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -solver-disable-shrink
1+
// RUN: %target-typecheck-verify-swift
22

33
// Self-contained test case
44
protocol P1 {}; func f<T: P1>(_: T, _: T) -> T { fatalError() }

validation-test/Sema/type_checker_perf/fast/property_vs_unapplied_func.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1 -solver-disable-shrink
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
22
// REQUIRES: tools-release,no_asan
33

44
struct Date {

validation-test/Sema/type_checker_perf/slow/rdar26564101.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1 -solver-disable-shrink
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
22
// REQUIRES: tools-release,no_asan
33
// UNSUPPORTED: swift_test_mode_optimize_none && OS=linux-gnu
44

0 commit comments

Comments
 (0)