mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Add get_without_compacting for debug_assert
This commit is contained in:
parent
fbf5dbdf43
commit
ee4bf21942
3 changed files with 32 additions and 12 deletions
|
@ -271,20 +271,25 @@ impl<S: UnificationStore> UnificationTable<S> {
|
|||
/// NB. This is a building-block operation and you would probably
|
||||
/// prefer to call `probe` below.
|
||||
pub fn get_root_key(&mut self, vid: S::Key) -> S::Key {
|
||||
let redirect = {
|
||||
match self.value(vid).parent(vid) {
|
||||
None => return vid,
|
||||
Some(redirect) => redirect,
|
||||
match self.value(vid).parent(vid) {
|
||||
None => vid,
|
||||
Some(redirect) => {
|
||||
let root_key: S::Key = self.get_root_key(redirect);
|
||||
if root_key != redirect {
|
||||
// Path compression
|
||||
self.update_value(vid, |value| value.parent = root_key);
|
||||
}
|
||||
|
||||
root_key
|
||||
}
|
||||
};
|
||||
|
||||
let root_key: S::Key = self.get_root_key(redirect);
|
||||
if root_key != redirect {
|
||||
// Path compression
|
||||
self.update_value(vid, |value| value.parent = 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 {
|
||||
|
@ -408,4 +413,15 @@ where
|
|||
let id = self.get_root_key(id);
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ fn solve(
|
|||
// check that things went well
|
||||
debug_assert!(rigid_vars
|
||||
.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();
|
||||
|
||||
|
|
|
@ -159,6 +159,10 @@ impl Subs {
|
|||
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 {
|
||||
self.utable.get_root_key(key)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue