Skip to main content

Signature

Struct Signature 

Source
pub struct Signature {
    pub receiver: Option<Ty>,
    pub params: Vec<Ty>,
    pub ret: Ty,
}
Expand description

A declaration’s boundary, as the checker resolved it for that body.

Every type here is the one the checker held while it walked this declaration’s body, not a re-derivation from the source: an annotation is resolved once, against the module it was written in, and this is that answer rather than a second reading of it.

The three parts are kept apart the way a declaration keeps them. params is in declaration order and holds one entry per written parameter; receiver is the type of self and is Some only for a method, so a consumer that has to place arguments knows the receiver comes first without inferring it from a count. ret is Ty::Unit for a declaration with no ->, because a function with no declared return type returns () and that is a settled type rather than an absence.

§Three kinds of declaration have one

A function or a method, written with a fn; a struct, whose initializer Point(x: 0.0) is a call the checker synthesizes a signature for out of the fields, so params is the field types in declaration order; and one case of an enum, whose params is its payload types. The last two are what publishes a declared type’s shape — the only other thing that knows it is the lowering, which turns it into slot numbers and keeps no names.

A struct’s and a case’s types are the declaration’s own, so a generic declaration records the Ty::Param it was written with; a consumer holding a use completes them with Ty::instantiate.

Fields§

§receiver: Option<Ty>

The type of self, for a method, and nothing for a free function.

§params: Vec<Ty>

The declared parameters, in declaration order, receiver excluded.

§Which question this answers

What a call supplies, not what the callee’s binding holds. The two are the same type for every parameter shape but one, and the exception is worth stating because a consumer that reads this field as the second question gets a wrong answer silently.

A variadic parameter is recorded as its element type, because a call site passes elements: fn count(items: Int...) records Int here. Inside the body items is the Array<Int> the callee made of them, and nothing in this struct says so. A consumer that needs the binding’s type reads variadic off the declaration’s own Param and wraps — which is what cove_ir::lower does too, after first asking this field and being told Int.

A var parameter needs no such note: it names the caller’s storage, and the type of that storage is the type recorded here. What a var changes is where the binding lives, not what it holds, and this struct records no marking at all.

§ret: Ty

What a call to this declaration answers.

Trait Implementations§

Source§

impl Clone for Signature

Source§

fn clone(&self) -> Signature

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 Signature

Source§

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

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

impl PartialEq for Signature

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Signature

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