Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Value {
        name: Name,
        patterns: Vec<Pattern>,
        body: Expression,
        span: NodeSpan,
    },
    TypedValue {
        name: Name,
        patterns: Vec<(Pattern, Type)>,
        body: Expression,
        tpe: Type,
        context: Vec<Constraint>,
        marked_unsafe: bool,
        span: NodeSpan,
        annotation_span: NodeSpan,
    },
}

Variants§

§

Value

Fields

§name: Name
§patterns: Vec<Pattern>
§span: NodeSpan

Where the declaration was written, annotation and body together.

§

TypedValue

Fields

§name: Name
§patterns: Vec<(Pattern, Type)>
§tpe: Type
§context: Vec<Constraint>

The constraints the annotation wrote in front of =>, each resolved to its class, in the order written; empty for an annotation with no =>.

A field beside tpe and not a case of Type, which keeps a context out of every match over a type. Nothing needs one inside a type: a constraint stands only at the front of an annotation, and a member signature carries none. Always empty in a facade, whose context is Error::FacadeConstrained and is not resolved.

§marked_unsafe: bool

True when the annotation was written unsafe name : Type.

The word is only meaningful on a facade signature, where it declares a plain function in place of the effect a facade declares by default — see Foreign interoperability. Only a module whose binding_foreign is set can carry it: canonicalize reports Error::UnsafeOutsideFacade for one written anywhere else, so this is false on every value of an ordinary module.

§span: NodeSpan

Where the declaration was written, annotation and body together.

§annotation_span: NodeSpan

Where the name : Type annotation alone was written.

Type itself carries no span — it may have been cloned out of another module’s Interface — so this is the only thing that can answer “where was the expected type declared”. A type error uses it for the secondary label that says the annotation is what the body is being held to.

Implementations§

Source§

impl Value

Source

pub fn span(&self) -> NodeSpan

Where this declaration was written, whichever variant it is.

The typer falls back to this when a type error has no finer position of its own — see typer::Error::labels.

Source

pub fn arity(&self) -> usize

How many parameters this declaration was written with.

This is the count of patterns on the left of the =, and deliberately not the number of arrows in the declaration’s type: f : Int -> Int -> Int written f a = add a has arity 1, and returns a function for the second argument.

The rule lives here rather than at any of its readers because they feed fields a backend reads together, from different phases. typer’s Translation uses it as the callee’s arity at every call site naming this declaration, which is what decides ir::Saturation; ir::build uses it as ir::Declaration::arity, the count a direct call has to supply; and Module::to_interface records it, through Module::emitted_arity, for a module that imports the declaration. Copies that drifted apart would mark a call site saturated at a count the emitted function does not take. A facade signature has no patterns to count, and Module::emitted_arity reads its arrows instead.

Source

pub fn holds_hole(&self) -> bool

Whether the declaration’s parameters or body hold a hole, an ExpressionKind::Hole or a PatternKind::Hole — a name that did not resolve.

A hole is made only where the error for it was raised, and that error is either reported or dropped in an incomplete scope, where the failure that made the scope incomplete stands in its place (DEC-23 decision 3). So a declaration for which this is true always has an error standing behind it, which is what ir::Unchecked::reported asks of an entry. A facade signature has no body, and the body of a TypedValue is read the same way a Value’s is.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 Debug for Value

Source§

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

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

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> 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 Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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.