Skip to main content

Bound

Enum Bound 

Source
pub enum Bound {
    Is(ScalarType),
    Kind(CapKind),
}
Expand description

What a catalog type variable is required to be.

Without a way to state this, sum would accept Vec[Bool] and Vec[Float] — the first a nonsense addition of booleans, the second a silent reinterpretation of float bits as an integer.

§Why the scalar shape is not a capability, and why the other one is

sum, product, min and max each lower to an ExtractScalar at ScalarKind::Int followed by an IntBinOp or an IntCmp, so CapKind::Numeric — which is Int, UInt, Byte and Float — would bless Vec[Float].sum() and return the float’s bits added as an integer. A capability is the wrong width for an Int-only lowering.

The capabilities the catalog would otherwise want are already enforced from the receiver’s type rather than per row, which is stronger: a Map key must be hash-stable and a heap element orderable wherever that collection is built, not only when a particular method is called (Inferer::require_collection_invariants, ADR-057 Decision 3).

So the scalar arm is not a capability. The second arm is: sorted orders its elements through the element descriptor’s compare callback, and a Vec[T] whose T is a function value has none. That is CapKind::Ord, and it is a fact about the row rather than about the receiver’s type — a Vec is a perfectly good Vec of unorderable things right up until someone sorts it — so require_collection_invariants is the wrong door for it and the row has to say it itself.

The match on this enum in praxis_hir’s apply_bounds is exhaustive, so a third arm is a compile error to add halfway rather than a silent omission.

Variants§

§

Is(ScalarType)

Exactly one scalar, and nothing else. Discharged by unification, so a failure is the ordinary expected Int, found Bool reported at the method name, and an element type nothing has named yet is pinned rather than merely permitted — which is what v.map(f).sum() needs.

§

Kind(CapKind)

One capability, and any type that has it. Discharged through the constraint channel, not by unification: a bound on a variable nothing has pinned yet cannot be answered, and fn top(v) { v.sorted() } is exactly that shape until a call site says what v holds. That is the whole reason this arm is not spelled as a set of scalars.

Trait Implementations§

Source§

impl Clone for Bound

Source§

fn clone(&self) -> Bound

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Bound

Source§

impl Debug for Bound

Source§

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

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

impl Eq for Bound

Source§

impl PartialEq for Bound

Source§

fn eq(&self, other: &Bound) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Bound

Auto Trait Implementations§

§

impl Freeze for Bound

§

impl RefUnwindSafe for Bound

§

impl Send for Bound

§

impl Sync for Bound

§

impl Unpin for Bound

§

impl UnsafeUnpin for Bound

§

impl UnwindSafe for Bound

Blanket Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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> 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.