@@ -49,7 +49,15 @@ struct RewriteSystemBuilder {
49
49
llvm::DenseMap<const ProtocolDecl *, bool > ProtocolMap;
50
50
std::vector<const ProtocolDecl *> Protocols;
51
51
52
- std::vector<std::pair<MutableTerm, MutableTerm>> AssociatedTypeRules;
52
+ // / New rules to add which will be marked 'permanent'. These are rules for
53
+ // / introducing associated types, and relationships between layout,
54
+ // / superclass and concrete type symbols. They are not eliminated by
55
+ // / homotopy reduction, since they are always added when the rewrite system
56
+ // / is built.
57
+ std::vector<std::pair<MutableTerm, MutableTerm>> PermanentRules;
58
+
59
+ // / New rules derived from requirements written by the user, which can be
60
+ // / eliminated by homotopy reduction.
53
61
std::vector<std::pair<MutableTerm, MutableTerm>> RequirementRules;
54
62
55
63
CanType getConcreteSubstitutionSchema (CanType concreteType,
@@ -141,7 +149,7 @@ void RewriteSystemBuilder::addAssociatedType(const AssociatedTypeDecl *type,
141
149
MutableTerm rhs;
142
150
rhs.add (Symbol::forAssociatedType (proto, type->getName (), Context));
143
151
144
- AssociatedTypeRules .emplace_back (lhs, rhs);
152
+ PermanentRules .emplace_back (lhs, rhs);
145
153
}
146
154
147
155
// / Lowers a generic requirement to a rewrite rule.
@@ -283,7 +291,7 @@ void RewriteSystemBuilder::processProtocolDependencies() {
283
291
MutableTerm rhs;
284
292
rhs.add (Symbol::forProtocol (proto, Context));
285
293
286
- AssociatedTypeRules .emplace_back (lhs, rhs);
294
+ PermanentRules .emplace_back (lhs, rhs);
287
295
288
296
for (auto *assocType : proto->getAssociatedTypeMembers ())
289
297
addAssociatedType (assocType, proto);
@@ -457,10 +465,9 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
457
465
RewriteSystemBuilder builder (Context, Dump);
458
466
builder.addGenericSignature (sig);
459
467
460
- // Add the initial set of rewrite rules to the rewrite system, also
461
- // providing the protocol graph to use for the linear order on terms.
468
+ // Add the initial set of rewrite rules to the rewrite system.
462
469
System.initialize (/* recordLoops=*/ false ,
463
- std::move (builder.AssociatedTypeRules ),
470
+ std::move (builder.PermanentRules ),
464
471
std::move (builder.RequirementRules ));
465
472
466
473
computeCompletion (RewriteSystem::DisallowInvalidRequirements);
@@ -498,10 +505,9 @@ void RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos
498
505
RewriteSystemBuilder builder (Context, Dump);
499
506
builder.addProtocols (protos);
500
507
501
- // Add the initial set of rewrite rules to the rewrite system, also
502
- // providing the protocol graph to use for the linear order on terms.
508
+ // Add the initial set of rewrite rules to the rewrite system.
503
509
System.initialize (/* recordLoops=*/ true ,
504
- std::move (builder.AssociatedTypeRules ),
510
+ std::move (builder.PermanentRules ),
505
511
std::move (builder.RequirementRules ));
506
512
507
513
// FIXME: Only if the protocols were written in source, though.
0 commit comments