struct SplitVarLenSlice {
    array_len: Option<usize>,
    arity: usize,
    max_slice: SliceKind,
}
Expand description

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<usize>

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

§arity: usize

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§

source§

impl SplitVarLenSlice

source

fn new(prefix: usize, suffix: usize, array_len: Option<usize>) -> Self

source

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

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

source

fn iter(&self) -> impl Iterator<Item = Slice> + Captures<'_>

Iterate over the partition of this slice.

Trait Implementations§

source§

impl Debug for SplitVarLenSlice

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.

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: 48 bytes