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
impl TypedExpander
Sourcepub fn collect(module: &Node, imported: &[&Node]) -> TypedExpander
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn exhausted(&self) -> bool
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.
Sourcepub fn report_exhaustion(&self, span: Span, diags: &mut Diagnostics)
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.
Sourcepub fn declares(&self, name: &str) -> bool
pub fn declares(&self, name: &str) -> bool
Whether name is a typed macro, and therefore this expander’s to expand.
Sourcepub fn names(&self) -> Vec<Arc<str>>
pub fn names(&self) -> Vec<Arc<str>>
Every typed macro’s name, for a diagnostic that wants to say what one is.
Sourcepub fn charge_expansion(
&mut self,
out: &Node,
span: Span,
diags: &mut Diagnostics,
) -> bool
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.
Sourcepub fn expand(
&mut self,
call: &Node,
types: &TypeEnv,
diags: &mut Diagnostics,
) -> Option<Node>
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
impl Clone for TypedExpander
Source§fn clone(&self) -> TypedExpander
fn clone(&self) -> TypedExpander
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more