Skip to content

Commit 286e91d

Browse files
committed
RequirementMachine: Temporarily disable associated type merging when minimizing protocol signatures
Also while plumbing this through, don't record homotopy generators unless we're minimizing a protocol signature, since they're not used for anything else yet.
1 parent 85dfbcd commit 286e91d

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
409409

410410
// Add the initial set of rewrite rules to the rewrite system, also
411411
// providing the protocol graph to use for the linear order on terms.
412-
System.initialize(std::move(builder.AssociatedTypeRules),
412+
System.initialize(/*recordHomotopyGenerators=*/false,
413+
std::move(builder.AssociatedTypeRules),
413414
std::move(builder.RequirementRules),
414415
std::move(builder.Protocols));
415416

@@ -450,7 +451,8 @@ void RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos
450451

451452
// Add the initial set of rewrite rules to the rewrite system, also
452453
// providing the protocol graph to use for the linear order on terms.
453-
System.initialize(std::move(builder.AssociatedTypeRules),
454+
System.initialize(/*recordHomotopyGenerators=*/true,
455+
std::move(builder.AssociatedTypeRules),
454456
std::move(builder.RequirementRules),
455457
std::move(builder.Protocols));
456458

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ RewriteSystem::RewriteSystem(RewriteContext &ctx)
8888
Initialized = 0;
8989
Complete = 0;
9090
Minimized = 0;
91+
RecordHomotopyGenerators = 0;
9192
}
9293

9394
RewriteSystem::~RewriteSystem() {
@@ -96,12 +97,14 @@ RewriteSystem::~RewriteSystem() {
9697
}
9798

9899
void RewriteSystem::initialize(
100+
bool recordHomotopyGenerators,
99101
std::vector<std::pair<MutableTerm, MutableTerm>> &&associatedTypeRules,
100102
std::vector<std::pair<MutableTerm, MutableTerm>> &&requirementRules,
101103
ProtocolGraph &&graph) {
102104
assert(!Initialized);
103105
Initialized = 1;
104106

107+
RecordHomotopyGenerators = recordHomotopyGenerators;
105108
Protos = graph;
106109

107110
for (const auto &rule : associatedTypeRules) {
@@ -170,7 +173,7 @@ bool RewriteSystem::addRule(MutableTerm lhs, MutableTerm rhs,
170173
if (path) {
171174
// We already have a loop, since the simplified lhs is identical to the
172175
// simplified rhs.
173-
HomotopyGenerators.emplace_back(lhs, loop);
176+
recordHomotopyGenerator(lhs, loop);
174177

175178
if (Debug.contains(DebugFlags::Add)) {
176179
llvm::dbgs() << "## Recorded trivial loop at " << lhs << ": ";
@@ -206,7 +209,7 @@ bool RewriteSystem::addRule(MutableTerm lhs, MutableTerm rhs,
206209
// add a rewrite step applying the new rule in reverse to close the loop.
207210
loop.add(RewriteStep::forRewriteRule(/*startOffset=*/0, /*endOffset=*/0,
208211
newRuleID, /*inverse=*/true));
209-
HomotopyGenerators.emplace_back(lhs, loop);
212+
recordHomotopyGenerator(lhs, loop);
210213

211214
if (Debug.contains(DebugFlags::Add)) {
212215
llvm::dbgs() << "## Recorded non-trivial loop at " << lhs << ": ";
@@ -376,7 +379,7 @@ void RewriteSystem::simplifyRewriteSystem() {
376379
loop.add(RewriteStep::forRewriteRule(/*startOffset=*/0, /*endOffset=*/0,
377380
newRuleID, /*inverse=*/true));
378381

379-
HomotopyGenerators.emplace_back(MutableTerm(lhs), loop);
382+
recordHomotopyGenerator(MutableTerm(lhs), loop);
380383

381384
if (Debug.contains(DebugFlags::Completion)) {
382385
llvm::dbgs() << "$ Right hand side simplification recorded a loop: ";

lib/AST/RequirementMachine/RewriteSystem.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ class RewriteSystem final {
379379
/// Whether we've minimized the rewrite system.
380380
unsigned Minimized : 1;
381381

382+
/// If set, record homotopy generators in the completion procedure.
383+
unsigned RecordHomotopyGenerators : 1;
384+
382385
public:
383386
explicit RewriteSystem(RewriteContext &ctx);
384387
~RewriteSystem();
@@ -394,7 +397,8 @@ class RewriteSystem final {
394397
/// Return the object recording information about known protocols.
395398
const ProtocolGraph &getProtocols() const { return Protos; }
396399

397-
void initialize(std::vector<std::pair<MutableTerm, MutableTerm>> &&assocaitedTypeRules,
400+
void initialize(bool recordHomotopyGenerators,
401+
std::vector<std::pair<MutableTerm, MutableTerm>> &&assocaitedTypeRules,
398402
std::vector<std::pair<MutableTerm, MutableTerm>> &&requirementRules,
399403
ProtocolGraph &&protos);
400404

@@ -452,6 +456,21 @@ class RewriteSystem final {
452456
void verifyRewriteRules(ValidityPolicy policy) const;
453457

454458
private:
459+
void recordHomotopyGenerator(HomotopyGenerator loop) {
460+
if (!RecordHomotopyGenerators)
461+
return;
462+
463+
HomotopyGenerators.push_back(loop);
464+
}
465+
466+
void recordHomotopyGenerator(MutableTerm basepoint,
467+
RewritePath path) {
468+
if (!RecordHomotopyGenerators)
469+
return;
470+
471+
HomotopyGenerators.emplace_back(basepoint, path);
472+
}
473+
455474
bool
456475
computeCriticalPair(
457476
ArrayRef<Symbol>::const_iterator from,

lib/AST/RequirementMachine/RewriteSystemCompletion.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ void RewriteSystem::processMergedAssociatedTypes() {
291291
/// If so, record this rule for later. We'll try to merge the associated
292292
/// types in RewriteSystem::processMergedAssociatedTypes().
293293
void RewriteSystem::checkMergedAssociatedType(Term lhs, Term rhs) {
294+
// FIXME: Figure out 3-cell representation for merged associated types
295+
if (RecordHomotopyGenerators)
296+
return;
297+
294298
if (lhs.size() == rhs.size() &&
295299
std::equal(lhs.begin(), lhs.end() - 1, rhs.begin()) &&
296300
lhs.back().getKind() == Symbol::Kind::AssociatedType &&
@@ -581,7 +585,7 @@ RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
581585
llvm::dbgs() << "\n\n";
582586

583587
// Record the trivial loop.
584-
HomotopyGenerators.push_back(loop);
588+
recordHomotopyGenerator(loop);
585589
}
586590
}
587591
});

0 commit comments

Comments
 (0)