diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/ena/src/unify | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ena/src/unify')
-rw-r--r-- | vendor/ena/src/unify/mod.rs | 43 |
1 files changed, 30 insertions, 13 deletions
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<S: UnificationStoreBase> UnificationTable<S> { 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<S::Key> { + &self.values[key.index() as usize] + } } impl<S: UnificationStoreMut> UnificationTable<S> { @@ -330,12 +331,6 @@ impl<S: UnificationStoreMut> UnificationTable<S> { }); } - /// Obtains the current value for a particular key. - /// Not for end-users; they can use `probe_value`. - fn value(&self, key: S::Key) -> &VarValue<S::Key> { - &self.values[key.index() as usize] - } - /// Find the root node for `vid`. This uses the standard /// union-find algorithm with path compression: /// <http://en.wikipedia.org/wiki/Disjoint-set_data_structure>. @@ -454,6 +449,28 @@ impl<S: UnificationStoreMut> UnificationTable<S> { impl<S, K, V> UnificationTable<S> where + S: UnificationStoreBase<Key = K, Value = V>, + K: UnifyKey<Value = V>, + 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>, + K: 'a, + { + let id = id.into(); + let v = self.value(id); + if v.parent == id { + return Some(&v.value); + } + None + } +} + +impl<S, K, V> UnificationTable<S> +where S: UnificationStoreMut<Key = K, Value = V>, K: UnifyKey<Value = V>, V: UnifyValue, |