@@ -267,7 +267,8 @@ void Atom::dump(llvm::raw_ostream &out) const {
267
267
// /
268
268
// / First we compare length, then perform a lexicographic comparison
269
269
// / on atoms if the two terms have the same length.
270
- int Term::compare (const Term &other, const ProtocolGraph &graph) const {
270
+ int MutableTerm::compare (const MutableTerm &other,
271
+ const ProtocolGraph &graph) const {
271
272
if (size () != other.size ())
272
273
return size () < other.size () ? -1 : 1 ;
273
274
@@ -289,17 +290,17 @@ int Term::compare(const Term &other, const ProtocolGraph &graph) const {
289
290
290
291
// / Find the start of \p other in this term, returning end() if
291
292
// / \p other does not occur as a subterm of this term.
292
- decltype (Term ::Atoms)::const_iterator
293
- Term ::findSubTerm(const Term &other) const {
293
+ decltype (MutableTerm ::Atoms)::const_iterator
294
+ MutableTerm ::findSubTerm(const MutableTerm &other) const {
294
295
if (other.size () > size ())
295
296
return end ();
296
297
297
298
return std::search (begin (), end (), other.begin (), other.end ());
298
299
}
299
300
300
301
// / Non-const variant of the above.
301
- decltype (Term ::Atoms)::iterator
302
- Term ::findSubTerm(const Term &other) {
302
+ decltype (MutableTerm ::Atoms)::iterator
303
+ MutableTerm ::findSubTerm(const MutableTerm &other) {
303
304
if (other.size () > size ())
304
305
return end ();
305
306
@@ -311,7 +312,8 @@ Term::findSubTerm(const Term &other) {
311
312
// / order on terms. Returns true if the term contained \p lhs;
312
313
// / otherwise returns false, in which case the term remains
313
314
// / unchanged.
314
- bool Term::rewriteSubTerm (const Term &lhs, const Term &rhs) {
315
+ bool MutableTerm::rewriteSubTerm (const MutableTerm &lhs,
316
+ const MutableTerm &rhs) {
315
317
// Find the start of lhs in this term.
316
318
auto found = findSubTerm (lhs);
317
319
@@ -362,7 +364,8 @@ bool Term::rewriteSubTerm(const Term &lhs, const Term &rhs) {
362
364
// /
363
365
// / Note that this relation is not commutative; we need to check
364
366
// / for overlap between both (X and Y) and (Y and X).
365
- bool Term::checkForOverlap (const Term &other, Term &result) const {
367
+ bool MutableTerm::checkForOverlap (const MutableTerm &other,
368
+ MutableTerm &result) const {
366
369
assert (result.size () == 0 );
367
370
368
371
// If the other term is longer than this term, there's no way
@@ -420,7 +423,7 @@ bool Term::checkForOverlap(const Term &other, Term &result) const {
420
423
return false ;
421
424
}
422
425
423
- void Term ::dump (llvm::raw_ostream &out) const {
426
+ void MutableTerm ::dump (llvm::raw_ostream &out) const {
424
427
bool first = true ;
425
428
426
429
for (auto atom : Atoms) {
@@ -445,8 +448,8 @@ void Term::dump(llvm::raw_ostream &out) const {
445
448
// / The bound associated types in the interface type are ignored; the
446
449
// / resulting term consists entirely of a root atom followed by zero
447
450
// / or more name atoms.
448
- Term RewriteContext::getTermForType (CanType paramType,
449
- const ProtocolDecl *proto) {
451
+ MutableTerm RewriteContext::getTermForType (CanType paramType,
452
+ const ProtocolDecl *proto) {
450
453
assert (paramType->isTypeParameter ());
451
454
452
455
// Collect zero or more nested type names in reverse order.
@@ -467,7 +470,7 @@ Term RewriteContext::getTermForType(CanType paramType,
467
470
468
471
std::reverse (atoms.begin (), atoms.end ());
469
472
470
- return Term (atoms);
473
+ return MutableTerm (atoms);
471
474
}
472
475
473
476
void Rule::dump (llvm::raw_ostream &out) const {
@@ -478,21 +481,22 @@ void Rule::dump(llvm::raw_ostream &out) const {
478
481
out << " [deleted]" ;
479
482
}
480
483
481
- void RewriteSystem::initialize (std::vector<std::pair<Term, Term>> &&rules,
482
- ProtocolGraph &&graph) {
484
+ void RewriteSystem::initialize (
485
+ std::vector<std::pair<MutableTerm, MutableTerm>> &&rules,
486
+ ProtocolGraph &&graph) {
483
487
Protos = graph;
484
488
485
489
// FIXME: Probably this sort is not necessary
486
490
std::sort (rules.begin (), rules.end (),
487
- [&](std::pair<Term, Term > lhs,
488
- std::pair<Term, Term > rhs) -> int {
491
+ [&](std::pair<MutableTerm, MutableTerm > lhs,
492
+ std::pair<MutableTerm, MutableTerm > rhs) -> int {
489
493
return lhs.first .compare (rhs.first , graph) < 0 ;
490
494
});
491
495
for (const auto &rule : rules)
492
496
addRule (rule.first , rule.second );
493
497
}
494
498
495
- bool RewriteSystem::addRule (Term lhs, Term rhs) {
499
+ bool RewriteSystem::addRule (MutableTerm lhs, MutableTerm rhs) {
496
500
// Simplify the rule as much as possible with the rules we have so far.
497
501
//
498
502
// This avoids unnecessary work in the completion algorithm.
@@ -564,7 +568,7 @@ bool RewriteSystem::addRule(Term lhs, Term rhs) {
564
568
}
565
569
566
570
// / Reduce a term by applying all rewrite rules until fixed point.
567
- bool RewriteSystem::simplify (Term &term) const {
571
+ bool RewriteSystem::simplify (MutableTerm &term) const {
568
572
bool changed = false ;
569
573
570
574
if (DebugSimplify) {
@@ -754,7 +758,7 @@ void RewriteSystem::processMergedAssociatedTypes() {
754
758
}
755
759
756
760
// Build the term X.[P1&P2:T].
757
- Term mergedTerm = lhs;
761
+ MutableTerm mergedTerm = lhs;
758
762
mergedTerm.back () = mergedAtom;
759
763
760
764
// Add the rule X.[P1:T] => X.[P1&P2:T].
@@ -789,11 +793,11 @@ void RewriteSystem::processMergedAssociatedTypes() {
789
793
//
790
794
// [P1&P2].[Q] => [P1&P2]
791
795
//
792
- Term newLHS;
796
+ MutableTerm newLHS;
793
797
newLHS.add (mergedAtom);
794
798
newLHS.add (otherLHS[1 ]);
795
799
796
- Term newRHS;
800
+ MutableTerm newRHS;
797
801
newRHS.add (mergedAtom);
798
802
799
803
addRule (newLHS, newRHS);
@@ -832,7 +836,7 @@ RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
832
836
auto pair = Worklist.front ();
833
837
Worklist.pop_front ();
834
838
835
- Term first;
839
+ MutableTerm first;
836
840
837
841
const auto &lhs = Rules[pair.first ];
838
842
const auto &rhs = Rules[pair.second ];
@@ -867,7 +871,7 @@ RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
867
871
//
868
872
// 1) lhs == TUV and rhs == U
869
873
// 2) lhs == TU and rhs == UV
870
- Term second = first;
874
+ MutableTerm second = first;
871
875
872
876
// In both cases, rewrite the term TUV using both rules to
873
877
// produce two new terms X and Y.
0 commit comments