From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/ena/src/unify/mod.rs | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'vendor/ena/src/unify') diff --git a/vendor/ena/src/unify/mod.rs b/vendor/ena/src/unify/mod.rs index 5377177be..604f3bdda 100644 --- a/vendor/ena/src/unify/mod.rs +++ b/vendor/ena/src/unify/mod.rs @@ -69,13 +69,8 @@ pub trait UnifyKey: Copy + Clone + Debug + PartialEq { fn tag() -> &'static str; - /// If true, then `self` should be preferred as root to `other`. - /// Note that we assume a consistent partial ordering, so - /// returning true implies that `other.prefer_as_root_to(self)` - /// would return false. If there is no ordering between two keys - /// (i.e., `a.prefer_as_root_to(b)` and `b.prefer_as_root_to(a)` - /// both return false) then the rank will be used to determine the - /// root in an optimal way. + /// You should return first the key that should be used as root, + /// then the other key (that will then point to the new root). /// /// NB. The only reason to implement this method is if you want to /// control what value is returned from `find()`. In general, it @@ -300,6 +295,12 @@ impl UnificationTable { pub fn len(&self) -> usize { self.values.len() } + + /// Obtains the current value for a particular key. + /// Not for end-users; they can use `probe_value`. + fn value(&self, key: S::Key) -> &VarValue { + &self.values[key.index() as usize] + } } impl UnificationTable { @@ -330,12 +331,6 @@ impl UnificationTable { }); } - /// Obtains the current value for a particular key. - /// Not for end-users; they can use `probe_value`. - fn value(&self, key: S::Key) -> &VarValue { - &self.values[key.index() as usize] - } - /// Find the root node for `vid`. This uses the standard /// union-find algorithm with path compression: /// . @@ -452,6 +447,28 @@ impl UnificationTable { /// //////////////////////////////////////////////////////////////////////// /// Public API +impl UnificationTable +where + S: UnificationStoreBase, + K: UnifyKey, + V: UnifyValue, +{ + /// Obtains current value for key without any pointer chasing; may return `None` if key has been union'd. + #[inline] + pub fn try_probe_value<'a, K1>(&'a self, id: K1) -> Option<&'a V> + where + K1: Into, + K: 'a, + { + let id = id.into(); + let v = self.value(id); + if v.parent == id { + return Some(&v.value); + } + None + } +} + impl UnificationTable where S: UnificationStoreMut, -- cgit v1.2.3