Skip to main content

Function

Struct Function 

Source
pub struct Function {
    pub def_id: DefId,
    pub name: String,
    pub generics: u32,
    pub bounds: Vec<Vec<DefId>>,
    pub takes_env: bool,
    pub capture_count: u32,
    pub params: u32,
    pub locals: Vec<Local>,
    pub ret_ty: Ty,
    pub is_async: bool,
    pub body: Expr,
    pub span: Span,
}
Expand description

A typed function.

Fields§

§def_id: DefId§name: String§generics: u32

Number of generic parameters; generic functions are monomorphized before codegen.

§bounds: Vec<Vec<DefId>>

Trait bounds per generic parameter (bounds[i] are the trait DefIds the i-th parameter must satisfy). Checked at monomorphization once the concrete type argument is known.

§takes_env: bool

Whether this function is the code of a function value (a closure or a bare-fn wrapper). Such functions take a leading environment pointer in their ABI: (env_ptr, params...). Normal, directly called functions do not.

§capture_count: u32

For a closure, the number of leading locals that are captured variables loaded from the environment at entry (0 for a bare-fn wrapper). The captured locals precede the real parameters.

§params: u32

The first params entries of locals are the real parameters (after any captures). For a closure the captured locals occupy indices 0..capture_count and the parameters capture_count...

§locals: Vec<Local>§ret_ty: Ty§is_async: bool

Whether this function was declared async. ret_ty is already Ty::Future(output) when true; this flag is what tells nova-mir which functions to treat specially, since a non-async function may also return a Future (by calling an async fn and not awaiting it), so ret_ty alone can’t distinguish them — which is the whole reason this flag exists rather than a test on ret_ty’s shape.

What nova-mir does with it is that crate’s contract (nova-mir/src/async_lower.rs), not restated here, for the reason ExprKind::Await’s doc gives.

§body: Expr§span: Span

Trait Implementations§

Source§

impl Debug for Function

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.