rustc_data_structures::unify

Struct UnificationTable

source
pub struct UnificationTable<S>{
    values: S,
}
Expand description

Table of unification keys and their values. You must define a key type K that implements the UnifyKey trait. Unification tables can be used in two-modes:

  • in-place (UnificationTable<InPlace<K>> or InPlaceUnificationTable<K>):
    • This is the standard mutable mode, where the array is modified in place.
    • To do backtracking, you can employ the snapshot and rollback_to methods.
  • persistent (UnificationTable<Persistent<K>> or PersistentUnificationTable<K>):
    • In this mode, we use a persistent vector to store the data, so that cloning the table is an O(1) operation.
    • This implies that ordinary operations are quite a bit slower though.
    • Requires the persistent feature be selected in your Cargo.toml file.

Fields§

§values: S

Implementations§

source§

impl<K> UnificationTable<InPlace<K, Vec<VarValue<K>>, ()>>
where K: UnifyKey,

source

pub fn with_log<'a, L>( &'a mut self, undo_log: L, ) -> UnificationTable<InPlace<K, &'a mut Vec<VarValue<K>>, L>>
where L: UndoLogs<UndoLog<Delegate<K>>>,

Creates a UnificationTable using an external undo_log, allowing mutating methods to be called if L does not implement UndoLogs

source§

impl<S> UnificationTable<S>

source§

impl<S> UnificationTable<S>

source

pub fn snapshot(&mut self) -> Snapshot<S>

Starts a new snapshot. Each snapshot must be either rolled back or committed in a “LIFO” (stack) order.

source

pub fn rollback_to(&mut self, snapshot: Snapshot<S>)

Reverses all changes since the last snapshot. Also removes any keys that have been created since then.

source

pub fn commit(&mut self, snapshot: Snapshot<S>)

Commits all changes since the last snapshot. Of course, they can still be undone if there is a snapshot further out.

source

pub fn vars_since_snapshot( &self, snapshot: &Snapshot<S>, ) -> Range<<S as UnificationStoreBase>::Key>

Returns the keys of all variables created since the snapshot.

source§

impl<S> UnificationTable<S>

source

pub fn len(&self) -> usize

Returns the number of keys created so far.

source§

impl<S> UnificationTable<S>

source

pub fn new_key( &mut self, value: <S as UnificationStoreBase>::Value, ) -> <S as UnificationStoreBase>::Key

Creates a fresh key with the given value.

source

pub fn reserve(&mut self, num_new_keys: usize)

Reserve memory for num_new_keys to be created. Does not actually create the new keys; you must then invoke new_key.

source

pub fn reset_unifications( &mut self, value: impl FnMut(<S as UnificationStoreBase>::Key) -> <S as UnificationStoreBase>::Value, )

Clears all unifications that have been performed, resetting to the initial state. The values of each variable are given by the closure.

source§

impl<S, K, V> UnificationTable<S>
where S: UnificationStoreBase<Key = K, Value = V>, K: UnifyKey<Value = V>, V: UnifyValue,

//////////////////////////////////////////////////////////////////////// Public API

source

pub fn try_probe_value<'a, K1>(&'a self, id: K1) -> Option<&'a V>
where K1: Into<K>, K: 'a,

Obtains current value for key without any pointer chasing; may return None if key has been union’d.

source§

impl<S, K, V> UnificationTable<S>
where S: UnificationStoreMut<Key = K, Value = V>, K: UnifyKey<Value = V>, V: UnifyValue,

source

pub fn union<K1, K2>(&mut self, a_id: K1, b_id: K2)
where K1: Into<K>, K2: Into<K>, V: UnifyValue<Error = NoError>,

Unions two keys without the possibility of failure; only applicable when unify values use NoError as their error type.

source

pub fn union_value<K1>(&mut self, id: K1, value: V)
where K1: Into<K>, V: UnifyValue<Error = NoError>,

Unions a key and a value without the possibility of failure; only applicable when unify values use NoError as their error type.

source

pub fn unioned<K1, K2>(&mut self, a_id: K1, b_id: K2) -> bool
where K1: Into<K>, K2: Into<K>,

Given two keys, indicates whether they have been unioned together.

source

pub fn find<K1>(&mut self, id: K1) -> K
where K1: Into<K>,

Given a key, returns the (current) root key.

source

pub fn unify_var_var<K1, K2>( &mut self, a_id: K1, b_id: K2, ) -> Result<(), <V as UnifyValue>::Error>
where K1: Into<K>, K2: Into<K>,

Unions together two variables, merging their values. If merging the values fails, the error is propagated and this method has no effect.

source

pub fn unify_var_value<K1>( &mut self, a_id: K1, b: V, ) -> Result<(), <V as UnifyValue>::Error>
where K1: Into<K>,

Sets the value of the key a_id to b, attempting to merge with the previous value.

source

pub fn probe_value<K1>(&mut self, id: K1) -> V
where K1: Into<K>,

Returns the current value for the given key. If the key has been union’d, this will give the value from the current root.

source

pub fn inlined_probe_value<K1>(&mut self, id: K1) -> V
where K1: Into<K>,

Trait Implementations§

source§

impl<S> Clone for UnificationTable<S>

source§

fn clone(&self) -> UnificationTable<S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S> Debug for UnificationTable<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<S> Default for UnificationTable<S>

source§

fn default() -> UnificationTable<S>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for UnificationTable<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for UnificationTable<S>
where S: RefUnwindSafe,

§

impl<S> Send for UnificationTable<S>
where S: Send,

§

impl<S> Sync for UnificationTable<S>
where S: Sync,

§

impl<S> Unpin for UnificationTable<S>
where S: Unpin,

§

impl<S> UnwindSafe for UnificationTable<S>
where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Aligned for T

source§

const ALIGN: Alignment = const ALIGN: Alignment = Alignment::of::<Self>();

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.