Skip to content

Commit 20d5d77

Browse files
committed
RequirementMachine: Add flags for completion depth and step limits
1 parent 44eb0cf commit 20d5d77

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,14 @@ namespace swift {
433433
/// Enables debugging output from the requirement machine.
434434
bool DebugRequirementMachine = false;
435435

436+
/// Maximum iteration count for requirement machine confluent completion
437+
/// algorithm.
438+
unsigned RequirementMachineStepLimit = 1000;
439+
440+
/// Maximum term length for requirement machine confluent completion
441+
/// algorithm.
442+
unsigned RequirementMachineDepthLimit = 10;
443+
436444
/// Sets the target we are building for and updates platform conditions
437445
/// to match.
438446
///

include/swift/Option/FrontendOptions.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ def disable_requirement_machine : Flag<["-"], "disable-requirement-machine">,
283283
def debug_requirement_machine : Flag<["-"], "debug-requirement-machine">,
284284
HelpText<"Enables debugging output from the generics implementation">;
285285

286+
def requirement_machine_step_limit : Separate<["-"], "requirement-machine-step-limit">,
287+
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
288+
HelpText<"Set the maximum steps before we give up on confluent completion">;
289+
290+
def requirement_machine_depth_limit : Separate<["-"], "requirement-machine-depth-limit">,
291+
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
292+
HelpText<"Set the maximum depth before we give up on confluent completion">;
293+
286294
def debug_generic_signatures : Flag<["-"], "debug-generic-signatures">,
287295
HelpText<"Debug generic signatures">;
288296

lib/AST/RequirementMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ void RequirementMachine::addGenericSignature(CanGenericSignature sig) {
205205
Impl->System.initialize(std::move(builder.Rules),
206206
std::move(builder.Protocols));
207207

208-
// FIXME: Add command line flag
209-
auto result = Impl->System.computeConfluentCompletion(1000, 10);
208+
auto result = Impl->System.computeConfluentCompletion(
209+
Context.LangOpts.RequirementMachineStepLimit,
210+
Context.LangOpts.RequirementMachineDepthLimit);
210211

211212
switch (result) {
212213
case RewriteSystem::CompletionResult::Success:

lib/Frontend/CompilerInvocation.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,28 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
798798
Opts.DebugRequirementMachine = Args.hasArg(
799799
OPT_debug_requirement_machine);
800800

801+
if (const Arg *A = Args.getLastArg(OPT_requirement_machine_step_limit)) {
802+
unsigned limit;
803+
if (StringRef(A->getValue()).getAsInteger(10, limit)) {
804+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
805+
A->getAsString(Args), A->getValue());
806+
HadError = true;
807+
} else {
808+
Opts.RequirementMachineStepLimit = limit;
809+
}
810+
}
811+
812+
if (const Arg *A = Args.getLastArg(OPT_requirement_machine_depth_limit)) {
813+
unsigned limit;
814+
if (StringRef(A->getValue()).getAsInteger(10, limit)) {
815+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
816+
A->getAsString(Args), A->getValue());
817+
HadError = true;
818+
} else {
819+
Opts.RequirementMachineDepthLimit = limit;
820+
}
821+
}
822+
801823
return HadError || UnsupportedOS || UnsupportedArch;
802824
}
803825

0 commit comments

Comments
 (0)