Struct rustc_mir_build::thir::pattern::deconstruct_pat::SplitVarLenSlice[−][src]

struct SplitVarLenSlice {
    array_len: Option<u64>,
    arity: u64,
    max_slice: SliceKind,
}

This computes constructor splitting for variable-length slices, as explained at the top of the file.

A slice pattern [x, .., y] behaves like the infinite or-pattern [x, y] | [x, _, y] | [x, _, _, y] | .... The corresponding value constructors are fixed-length array constructors above a given minimum length. We obviously can’t list this infinitude of constructors. Thankfully, it turns out that for each finite set of slice patterns, all sufficiently large array lengths are equivalent.

Let’s look at an example, where we are trying to split the last pattern:

match x {
    [true, true, ..] => {}
    [.., false, false] => {}
    [..] => {}
}

Here are the results of specialization for the first few lengths:

// length 0
[] => {}
// length 1
[_] => {}
// length 2
[true, true] => {}
[false, false] => {}
[_, _] => {}
// length 3
[true, true,  _    ] => {}
[_,    false, false] => {}
[_,    _,     _    ] => {}
// length 4
[true, true, _,     _    ] => {}
[_,    _,    false, false] => {}
[_,    _,    _,     _    ] => {}
// length 5
[true, true, _, _,     _    ] => {}
[_,    _,    _, false, false] => {}
[_,    _,    _, _,     _    ] => {}

If we went above length 5, we would simply be inserting more columns full of wildcards in the middle. This means that the set of witnesses for length l >= 5 if equivalent to the set for any other l' >= 5: simply add or remove wildcards in the middle to convert between them.

This applies to any set of slice patterns: there will be a length L above which all lengths behave the same. This is exactly what we need for constructor splitting. Therefore a variable-length slice can be split into a variable-length slice of minimal length L, and many fixed-length slices of lengths < L.

For each variable-length pattern p with a prefix of length plₚ and suffix of length slₚ, only the first plₚ and the last slₚ elements are examined. Therefore, as long as L is positive (to avoid concerns about empty types), all elements after the maximum prefix length and before the maximum suffix length are not examined by any variable-length pattern, and therefore can be added/removed without affecting them - creating equivalent patterns from any sufficiently-large length.

Of course, if fixed-length patterns exist, we must be sure that our length is large enough to miss them all, so we can pick L = max(max(FIXED_LEN)+1, max(PREFIX_LEN) + max(SUFFIX_LEN))

max_slice below will be made to have arity L.

Fields

array_len: Option<u64>

If the type is an array, this is its size.

arity: u64

The arity of the input slice.

max_slice: SliceKind

The smallest slice bigger than any slice seen. max_slice.arity() is the length L described above.

Implementations

impl SplitVarLenSlice[src]

fn new(prefix: u64, suffix: u64, array_len: Option<u64>) -> Self[src]

fn split(&mut self, slices: impl Iterator<Item = SliceKind>)[src]

Pass a set of slices relative to which to split this one.

fn iter<'a>(&'a self) -> impl Iterator<Item = Slice> + Captures<'a>[src]

Iterate over the partition of this slice.

Trait Implementations

impl Debug for SplitVarLenSlice[src]

Auto Trait Implementations

impl RefUnwindSafe for SplitVarLenSlice

impl Send for SplitVarLenSlice

impl Sync for SplitVarLenSlice

impl Unpin for SplitVarLenSlice

impl UnwindSafe for SplitVarLenSlice

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.