Skip to main content

Declaration

Struct Declaration 

Source
pub struct Declaration {
    pub name: Name,
    pub arity: usize,
    pub tpe: Type,
    pub context: Vec<Predicate>,
    pub body: Option<Body>,
    pub span: NodeSpan,
}
Expand description

One value of a module: what a backend emits as a named binding.

Fields§

§name: Name§arity: usize

How many arguments a call site has to supply for the call to be a direct call.

For a declaration with a body this is the number of parameters it was written with, which is Body::parameters’s length — not the number of arrows in its type. f : Int -> Int -> Int written f a = add a has arity 1, and a call supplying two arguments is one direct call followed by one partial application.

For a facade signature, which has no body to count parameters off, it is the number of arrows in the signature: the companion’s export takes a plain parameter list of exactly that length, and a signature with no arrow at all is a facade constant.

§tpe: Type

The declaration’s own type, as inference solved it — or, for a facade, as the signature declares it.

§context: Vec<Predicate>

What the declaration’s annotation requires of its type variables, one Predicate per constraint written, in the order written — empty for a declaration whose annotation has no =>, for every declaration with no annotation, and for a facade signature.

Read off the declaration’s solved type, as the types on its nodes are: each predicate’s type is the variable the annotation constrained. The annotation’s variables are rigid while the body is checked, so it is always a variable of tpe.

A superclass the context implies is not listed.

§body: Option<Body>

The parameters and the expression they are in scope over, for a declaration that has a body.

None is a module foreign facade’s signature. It is the whole reason this is an Option: a facade declares what crosses the boundary and the code is in the companion, so there is nothing here to emit and zelkova_js::emit reads the signature instead.

§span: NodeSpan

Where the declaration was written, annotation and body together.

Trait Implementations§

Source§

impl Debug for Declaration

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 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> 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, 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.