Skip to content

Commit 95f122f

Browse files
committed
RequirementMachine: Add -enable-requirement-machine-loop-normalization flag
1 parent a0c3045 commit 95f122f

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ namespace swift {
545545
/// enabled. It can be disabled for debugging and testing.
546546
bool EnableRequirementMachineConcreteContraction = true;
547547

548+
/// Enable the stronger minimization algorithm. This is just for debugging;
549+
/// if you have a testcase which requires this, please submit a bug report.
550+
bool EnableRequirementMachineLoopNormalization = false;
551+
548552
/// Enables dumping type witness systems from associated type inference.
549553
bool DumpTypeWitnessSystems = false;
550554

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ def disable_requirement_machine_concrete_contraction : Flag<["-"], "disable-requ
359359
HelpText<"Disable preprocessing pass to eliminate conformance requirements "
360360
"on generic parameters which are made concrete">;
361361

362+
def enable_requirement_machine_loop_normalization : Flag<["-"], "enable-requirement-machine-loop-normalization">,
363+
HelpText<"Enable stronger minimization algorithm, for debugging only">;
364+
362365
def dump_type_witness_systems : Flag<["-"], "dump-type-witness-systems">,
363366
HelpText<"Enables dumping type witness systems from associated type inference">;
364367

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "llvm/Support/Debug.h"
6060
#include "llvm/Support/raw_ostream.h"
6161
#include <algorithm>
62+
#include "RewriteContext.h"
6263
#include "RewriteSystem.h"
6364

6465
using namespace swift;
@@ -627,6 +628,10 @@ void RewriteSystem::deleteRule(unsigned ruleID,
627628
if (!changed)
628629
continue;
629630

631+
if (Context.getASTContext().LangOpts.EnableRequirementMachineLoopNormalization) {
632+
loop.computeNormalForm(*this);
633+
}
634+
630635
// The loop's path has changed, so we must invalidate the cached
631636
// result of findRulesAppearingOnceInEmptyContext().
632637
loop.markDirty();
@@ -723,6 +728,12 @@ void RewriteSystem::minimizeRewriteSystem() {
723728
propagateExplicitBits();
724729
processConflicts();
725730

731+
if (Context.getASTContext().LangOpts.EnableRequirementMachineLoopNormalization) {
732+
for (auto &loop : Loops) {
733+
loop.computeNormalForm(*this);
734+
}
735+
}
736+
726737
// First pass:
727738
// - Eliminate all LHS-simplified non-conformance rules.
728739
// - Eliminate all RHS-simplified and substitution-simplified rules.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10051005
if (Args.hasArg(OPT_disable_requirement_machine_concrete_contraction))
10061006
Opts.EnableRequirementMachineConcreteContraction = false;
10071007

1008+
if (Args.hasArg(OPT_enable_requirement_machine_loop_normalization))
1009+
Opts.EnableRequirementMachineLoopNormalization = true;
1010+
10081011
Opts.DumpTypeWitnessSystems = Args.hasArg(OPT_dump_type_witness_systems);
10091012

10101013
return HadError || UnsupportedOS || UnsupportedArch;

0 commit comments

Comments
 (0)