TypedExpander

Struct TypedExpander 

Source
pub struct TypedExpander { /* private fields */ }
Expand description

The typed macros a module has, and everything their bodies may reach.

Built where the untyped expansion ends and handed to the checker, which is the only thing that can expand one: a typed macro’s body asks what its arguments are, and until the checker has run there is no answer.

Implementations§

Source§

impl TypedExpander

Source

pub fn collect(module: &Node, imported: &[&Node]) -> TypedExpander

The typed macros of a module and of the modules it imports.

imported are parsed modules, for the reason crate::expand_module_with gives: a macro is published by a module’s source, because it has no signature for an interface to carry.

Collection reports nothing. Duplicate names are refused where the untyped expander collects the same declarations one phase earlier, and reporting them again here would be the same B0200 twice.

Source

pub fn is_empty(&self) -> bool

Whether this module has any typed macro at all — the question worth asking before the checker carries a probe around, and the one asked at every call site in the module.

Source

pub fn exhausted(&self) -> bool

Whether a module-wide budget has run out, so nothing more will ever expand.

A budget is spent once and reported once, and the checker infers a call’s arguments inside a rollback — so a caller that discards what a probe reported has to ask this, or the only report there will ever be is the one it just deleted, and every expansion afterwards quietly produces nothing.

Source

pub fn report_exhaustion(&self, span: Span, diags: &mut Diagnostics)

Say again that a budget ran out, for a caller that threw the first report away.

Source

pub fn declares(&self, name: &str) -> bool

Whether name is a typed macro, and therefore this expander’s to expand.

Source

pub fn names(&self) -> Vec<Arc<str>>

Every typed macro’s name, for a diagnostic that wants to say what one is.

Source

pub fn charge_expansion( &mut self, out: &Node, span: Span, diags: &mut Diagnostics, ) -> bool

Charge an expansion this call site has already produced, without producing it again.

The budget bounds what expansion produces (docs/42 §42.6), and an expansion the checker is handed twice puts two copies in the program — so the second copy is charged even though the body ran once. That is the difference between a macro whose output keeps its argument and one that writes it twice, and charging per call site rather than per use would erase it: a doubling macro nested d deep really does produce 2^d nodes, and really does owe them.

Source

pub fn expand( &mut self, call: &Node, types: &TypeEnv, diags: &mut Diagnostics, ) -> Option<Node>

Expand one call, with what the checker inferred about its arguments.

The four-part hygiene dance is the untyped expander’s, unchanged — a typed macro differs in when it runs and in what its body may ask, not in how a name it introduces is scoped.

Trait Implementations§

Source§

impl Clone for TypedExpander

Source§

fn clone(&self) -> TypedExpander

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TypedExpander

Source§

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

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

impl Default for TypedExpander

Source§

fn default() -> TypedExpander

Returns the “default value” for a type. 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> 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.