TransitiveRelation in rustc_data_structures::transitive_relation - Rust (original) (raw)

Struct TransitiveRelation

Source

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

Source§

Source

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

Source

Checks whether a < target (transitively)

Source

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

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

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

Returns the set of bounds X such that:

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

Source

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

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

Given an element A, elements B with the lowest index such that A R Band B R A, or A if no such element exists.

Source

Source

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.

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