Add get_without_compacting for debug_assert

This commit is contained in:
Richard Feldman 2019-12-19 22:44:37 -05:00
parent fbf5dbdf43
commit ee4bf21942
3 changed files with 32 additions and 12 deletions

View file

@ -271,13 +271,9 @@ impl<S: UnificationStore> UnificationTable<S> {
/// NB. This is a building-block operation and you would probably /// NB. This is a building-block operation and you would probably
/// prefer to call `probe` below. /// prefer to call `probe` below.
pub fn get_root_key(&mut self, vid: S::Key) -> S::Key { pub fn get_root_key(&mut self, vid: S::Key) -> S::Key {
let redirect = {
match self.value(vid).parent(vid) { match self.value(vid).parent(vid) {
None => return vid, None => vid,
Some(redirect) => redirect, Some(redirect) => {
}
};
let root_key: S::Key = self.get_root_key(redirect); let root_key: S::Key = self.get_root_key(redirect);
if root_key != redirect { if root_key != redirect {
// Path compression // Path compression
@ -286,6 +282,15 @@ impl<S: UnificationStore> UnificationTable<S> {
root_key root_key
} }
}
}
pub fn get_root_key_without_compacting(&self, vid: S::Key) -> S::Key {
match self.value(vid).parent(vid) {
None => vid,
Some(redirect) => self.get_root_key_without_compacting(redirect),
}
}
pub fn is_redirect(&mut self, vid: S::Key) -> bool { pub fn is_redirect(&mut self, vid: S::Key) -> bool {
self.value(vid).raw_parent() != vid self.value(vid).raw_parent() != vid
@ -408,4 +413,15 @@ where
let id = self.get_root_key(id); let id = self.get_root_key(id);
self.value(id).value.clone() self.value(id).value.clone()
} }
/// This is for a debug_assert! in solve() only. Do not use it elsewhere!
pub fn probe_value_without_compacting<K1>(&self, id: K1) -> V
where
K1: Into<K>,
{
let id = id.into();
let id = self.get_root_key_without_compacting(id);
self.value(id).value.clone()
}
} }

View file

@ -229,7 +229,7 @@ fn solve(
// check that things went well // check that things went well
debug_assert!(rigid_vars debug_assert!(rigid_vars
.iter() .iter()
.all(|&var| subs.get(var).rank == Rank::none())); .all(|&var| subs.get_without_compacting(var).rank == Rank::none()));
let mut new_vars_by_symbol = vars_by_symbol.clone(); let mut new_vars_by_symbol = vars_by_symbol.clone();

View file

@ -159,6 +159,10 @@ impl Subs {
self.utable.probe_value(key) self.utable.probe_value(key)
} }
pub fn get_without_compacting(&self, key: Variable) -> Descriptor {
self.utable.probe_value_without_compacting(key)
}
pub fn get_root_key(&mut self, key: Variable) -> Variable { pub fn get_root_key(&mut self, key: Variable) -> Variable {
self.utable.get_root_key(key) self.utable.get_root_key(key)
} }