rustc_data_structures::transitive_relation

Struct TransitiveRelation

Source
pub struct TransitiveRelation<T> {
    builder: Frozen<TransitiveRelationBuilder<T>>,
    closure: Frozen<BitMatrix<usize, usize>>,
}

Fields§

§builder: Frozen<TransitiveRelationBuilder<T>>§closure: Frozen<BitMatrix<usize, usize>>

Implementations§

Source§

impl<T: Eq + Hash + Copy> TransitiveRelation<T>

Source

pub fn maybe_map<F, U>(&self, f: F) -> Option<TransitiveRelation<U>>
where F: FnMut(T) -> Option<U>, U: Clone + Debug + Eq + Hash + Copy,

Applies the (partial) function to each edge and returns a new relation including transitive closures.

Source

pub fn contains(&self, a: T, b: T) -> bool

Checks whether a < target (transitively)

Source

pub fn reachable_from(&self, a: T) -> Vec<T>

Thinking of x R y as an edge x -> y in a graph, this returns all things reachable from a.

Really this probably ought to be impl Iterator<Item = &T>, but I’m too lazy to make that work, and – given the caching strategy – it’d be a touch tricky anyhow.

Source

pub fn postdom_upper_bound(&self, a: T, b: T) -> Option<T>

Picks what I am referring to as the “postdominating” upper-bound for a and b. This is usually the least upper bound, but in cases where there is no single least upper bound, it is the “mutual immediate postdominator”, if you imagine a graph where a < b means a -> b.

This function is needed because region inference currently requires that we produce a single “UB”, and there is no best choice for the LUB. Rather than pick arbitrarily, I pick a less good, but predictable choice. This should help ensure that region inference yields predictable results (though it itself is not fully sufficient).

Examples are probably clearer than any prose I could write (there are corresponding tests below, btw). In each case, the query is postdom_upper_bound(a, b):

// Returns Some(x), which is also LUB.
a -> a1 -> x
           ^
           |
b -> b1 ---+

// Returns `Some(x)`, which is not LUB (there is none)
// diagonal edges run left-to-right.
a -> a1 -> x
  \/       ^
  /\       |
b -> b1 ---+

// Returns `None`.
a -> a1
b -> b1
Source

pub fn mutual_immediate_postdominator(&self, mubs: Vec<T>) -> Option<T>

Viewing the relation as a graph, computes the “mutual immediate postdominator” of a set of points (if one exists). See postdom_upper_bound for details.

Source

pub fn minimal_upper_bounds(&self, a: T, b: T) -> Vec<T>

Returns the set of bounds X such that:

  • a < X and b < X
  • there is no Y != X such that a < Y and Y < X
    • except for the case where X < a (i.e., a strongly connected component in the graph). In that case, the smallest representative of the SCC is returned (as determined by the internal indices).

Note that this set can, in principle, have any size.

Source

pub fn parents(&self, a: T) -> Vec<T>

Given an element A, returns the maximal set {B} of elements B such that

  • A != B
  • A R B is true
  • for each i, j: B[i] R B[j] does not hold

The intuition is that this moves “one step up” through a lattice (where the relation is encoding the <= relation for the lattice). So e.g., if the relation is -> and we have

a -> b -> d -> f
|              ^
+--> c -> e ---+

then parents(a) returns [b, c]. The postdom_parent function would further reduce this to just f.

Source

fn with_closure<OP, R>(&self, op: OP) -> R
where OP: FnOnce(&BitMatrix<usize, usize>) -> R,

Source

pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> + '_

Lists all the base edges in the graph: the initial non-transitive set of element relations, which will be later used as the basis for the transitive closure computation.

Trait Implementations§

Source§

impl<T: Clone> Clone for TransitiveRelation<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TransitiveRelation<T>

Source§

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

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

impl<T> Deref for TransitiveRelation<T>

Source§

type Target = Frozen<TransitiveRelationBuilder<T>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T> DynSend for TransitiveRelation<T>
where T: DynSend,

§

impl<T> DynSync for TransitiveRelation<T>
where T: DynSync,

§

impl<T> Freeze for TransitiveRelation<T>

§

impl<T> RefUnwindSafe for TransitiveRelation<T>
where T: RefUnwindSafe,

§

impl<T> Send for TransitiveRelation<T>
where T: Send,

§

impl<T> Sync for TransitiveRelation<T>
where T: Sync,

§

impl<T> Unpin for TransitiveRelation<T>
where T: Unpin,

§

impl<T> UnwindSafe for TransitiveRelation<T>
where T: 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> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 128 bytes