- pub fn relate_vars(&mut self, a: ty::TyVid, dir: RelationDir, b: ty::TyVid) {
- let a = self.root_var(a);
- let b = self.root_var(b);
- if a != b {
- if dir == EqTo {
- // a and b must be equal which we mark in the unification table
- let root = self.eq_relations.union(a, b);
- // In addition to being equal, all relations from the variable which is no longer
- // the root must be added to the root so they are not forgotten as the other
- // variable should no longer be referenced (other than to get the root)
- let other = if a == root { b } else { a };
- let count = {
- let (relations, root_relations) = if other.index < root.index {
- let (pre, post) = self.values.split_at_mut(root.index as usize);
- (relations(&mut pre[other.index as usize]), relations(&mut post[0]))
- } else {
- let (pre, post) = self.values.split_at_mut(other.index as usize);
- (relations(&mut post[0]), relations(&mut pre[root.index as usize]))
- };
- root_relations.extend_from_slice(relations);
- relations.len()
- };
- self.values.record(RelateRange(root, count));
- } else {
- self.relations(a).push((dir, b));
- self.relations(b).push((dir.opposite(), a));
- self.values.record(Relate(a, b));
- }
- }
+ pub fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
+ debug_assert!(self.probe(a).is_none());
+ debug_assert!(self.probe(b).is_none());
+ self.eq_relations.union(a, b);