@@ -488,6 +488,52 @@ int Atom::compare(Atom other, const ProtocolGraph &graph) const {
488
488
return result;
489
489
}
490
490
491
+ // / For a superclass or concrete type atom
492
+ // /
493
+ // / [concrete: Foo<X1, ..., Xn>]
494
+ // / [superclass: Foo<X1, ..., Xn>]
495
+ // /
496
+ // / Return a new atom where the prefix T is prepended to each of the
497
+ // / substitutions:
498
+ // /
499
+ // / [concrete: Foo<T.X1, ..., T.Xn>]
500
+ // / [superclass: Foo<T.X1, ..., T.Xn>]
501
+ // /
502
+ // / Asserts if this is not a superclass or concrete type atom.
503
+ Atom Atom::prependPrefixToConcreteSubstitutions (
504
+ const MutableTerm &prefix,
505
+ RewriteContext &ctx) const {
506
+ assert (isSuperclassOrConcreteType ());
507
+
508
+ if (prefix.empty ())
509
+ return *this ;
510
+
511
+ SmallVector<Term, 2 > substitutions;
512
+ for (auto term : getSubstitutions ()) {
513
+ MutableTerm mutTerm;
514
+ mutTerm.append (prefix);
515
+ mutTerm.append (term);
516
+
517
+ substitutions.push_back (Term::get (mutTerm, ctx));
518
+ }
519
+
520
+ switch (getKind ()) {
521
+ case Kind::Superclass:
522
+ return Atom::forSuperclass (getSuperclass (), substitutions, ctx);
523
+ case Kind::ConcreteType:
524
+ return Atom::forConcreteType (getConcreteType (), substitutions, ctx);
525
+
526
+ case Kind::GenericParam:
527
+ case Kind::Name:
528
+ case Kind::Protocol:
529
+ case Kind::AssociatedType:
530
+ case Kind::Layout:
531
+ break ;
532
+ }
533
+
534
+ llvm_unreachable (" Bad atom kind" );
535
+ }
536
+
491
537
// / Print the atom using our mnemonic representation.
492
538
void Atom::dump (llvm::raw_ostream &out) const {
493
539
auto dumpSubstitutions = [&]() {
@@ -1286,6 +1332,11 @@ RewriteSystem::computeCriticalPair(const Rule &lhs, const Rule &rhs) const {
1286
1332
case OverlapKind::Second: {
1287
1333
// lhs == TU -> X, rhs == UV -> Y.
1288
1334
1335
+ if (v.back ().isSuperclassOrConcreteType ()) {
1336
+ v.back () = v.back ().prependPrefixToConcreteSubstitutions (
1337
+ t, Context);
1338
+ }
1339
+
1289
1340
// Compute the term XV.
1290
1341
MutableTerm xv;
1291
1342
xv.append (lhs.getRHS ());
0 commit comments