Skip to content

Commit 64b2bbd

Browse files
author
Markus Westerlind
committed
perf: Avoid logging unifications that ObligationForest do not watch
1 parent 4cf514a commit 64b2bbd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

compiler/rustc_data_structures/src/logged_unification_table.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ where
3838
where
3939
K::Value: ut::UnifyValue<Error = ut::NoError>,
4040
{
41-
if !self.unify_log.get(vid).is_empty()
42-
|| self.reference_counts.get(vid).map_or(false, |c| *c != 0)
43-
{
41+
if self.needs_log(vid) {
42+
warn!("ModifiedSet {:?} => {:?}", vid, ty);
4443
self.modified_set.set(vid);
4544
}
4645
let vid = vid.into();
@@ -60,31 +59,37 @@ where
6059
value: K::Value,
6160
) -> Result<(), <K::Value as ut::UnifyValue>::Error> {
6261
let vid = self.find(vid).into();
63-
if !self.unify_log.get(vid).is_empty()
64-
|| self.reference_counts.get(vid).map_or(false, |c| *c != 0)
65-
{
62+
if self.needs_log(vid) {
6663
self.modified_set.set(vid);
6764
}
6865
self.relations.unify_var_value(vid, value)
6966
}
7067

7168
pub fn unify_var_var(&mut self, a: I, b: I) -> Result<(), <K::Value as ut::UnifyValue>::Error> {
72-
let a_root = self.relations.find(a);
73-
let b_root = self.relations.find(b);
74-
if a_root == b_root {
69+
let a = self.relations.find(a);
70+
let b = self.relations.find(b);
71+
if a == b {
7572
return Ok(());
7673
}
7774

78-
self.relations.unify_var_var(a_root, b_root)?;
75+
self.relations.unify_var_var(a, b)?;
7976

80-
if a_root == self.relations.find(a_root) {
81-
self.unify_log.unify(a_root.into(), b_root.into());
82-
} else {
83-
self.unify_log.unify(b_root.into(), a_root.into());
77+
if self.needs_log(a.into()) || self.needs_log(b.into()) {
78+
warn!("Log: {:?} {:?} => {:?}", a, b, I::from(self.relations.find(a)));
79+
if a == self.relations.find(a) {
80+
self.unify_log.unify(a.into(), b.into());
81+
} else {
82+
self.unify_log.unify(b.into(), a.into());
83+
}
8484
}
8585
Ok(())
8686
}
8787

88+
fn needs_log(&self, vid: I) -> bool {
89+
!self.unify_log.get(vid).is_empty()
90+
|| self.reference_counts.get(vid).map_or(false, |c| *c != 0)
91+
}
92+
8893
pub fn union_value(&mut self, vid: I, value: K::Value)
8994
where
9095
K::Value: ut::UnifyValue<Error = ut::NoError>,
@@ -145,6 +150,7 @@ where
145150
}
146151

147152
pub fn watch_variable(&mut self, index: I) {
153+
debug_assert!(index == self.relations.find(index).into());
148154
self.reference_counts.ensure_contains_elem(index, || 0);
149155
self.reference_counts[index] += 1;
150156
}

0 commit comments

Comments
 (0)