Skip to main content

ScopeManager

Struct ScopeManager 

Source
pub struct ScopeManager<'a> {
    pub frames: Vec<ScopeFrame<'a>>,
    pub codesize_hints: BTreeMap<String, usize>,
    pub codesizes: BTreeMap<String, usize>,
    pub codesize_hints_used: bool,
    measurements: Vec<usize>,
}
Expand description

Tracks the macro call stack during compilation.

Provides scope identifiers for label operations and exposes the call stack for argument resolution.

Fields§

§frames: Vec<ScopeFrame<'a>>

Stack of scope frames from root to current

§codesize_hints: BTreeMap<String, usize>

Macro sizes from the previous compile pass, for __codesize values that cannot be measured in the code they are part of

§codesizes: BTreeMap<String, usize>

Macro sizes generated in this pass, the hints of the next pass

§codesize_hints_used: bool

Whether a hint was used, so the sizes must be compiled again until they are stable

§measurements: Vec<usize>

Frame indices where a __codesize measurement of another macro starts

Implementations§

Source§

impl<'a> ScopeManager<'a>

Source

pub fn new() -> Self

Creates a new empty scope manager.

Source

pub fn start_measurement(&mut self)

Starts measuring a macro for __codesize, in a frame pushed after this call

Source

pub fn end_measurement(&mut self)

Ends the innermost __codesize measurement

Source

pub fn codesize_hint(&mut self, macro_name: &str) -> Option<usize>

The size from the previous pass for a __codesize of the enclosing macro macro_name.

It is only needed when the reference sits in a measurement of another macro that does not contain macro_name, which therefore cannot be measured there. Using it records that the sizes must be compiled again until they are stable.

Source

pub fn current_scope(&self) -> ScopeId

Returns the scope identifier for the currently executing macro.

Used when defining labels or creating jumps within the current macro body.

Source

pub fn parent_scope(&self) -> ScopeId

Returns the scope identifier for the calling macro.

Used when resolving label arguments that should be looked up in the caller’s scope. Returns the root scope if called from the top level.

Source

pub fn push_macro(&mut self, macro_def: &'a MacroDefinition, offset: usize)

Enters a new macro context.

Adds the macro to the call stack at the given bytecode offset. Use for root macros (MAIN/CONSTRUCTOR) without invocation details.

Source

pub fn push_macro_with_invocation( &mut self, macro_def: &'a MacroDefinition, offset: usize, invocation: MacroInvocation, )

Enters a new macro context with invocation arguments.

Like push_macro, but includes the invocation details for argument resolution.

Source

pub fn pop_macro(&mut self) -> Option<&'a MacroDefinition>

Exits the current macro context.

Removes the top frame from the call stack and returns the macro definition.

Source

pub fn current_macro(&self) -> Option<&'a MacroDefinition>

Returns the macro definition at the top of the call stack, or None if empty.

Source

pub fn macro_stack(&self) -> Vec<&'a MacroDefinition>

Returns all macro definitions from root to current as a vector.

Source

pub fn macro_at_depth(&self, depth: usize) -> Option<&'a MacroDefinition>

Returns the macro definition at the specified call stack depth, or None if out of bounds.

Source

pub fn depth(&self) -> usize

Returns the number of frames in the call stack.

Source

pub fn invocation_stack( &self, ) -> impl Iterator<Item = (usize, Option<&MacroInvocation>)> + '_

Returns an iterator over (offset, invocation) pairs for all frames.

Invocation is None for root macros.

Source

pub fn invocation_vec(&self) -> Vec<(usize, &MacroInvocation)>

Returns (offset, invocation) pairs for all frames with invocation details.

Root macros without invocations are excluded from the result.

Source

pub fn invocation_vec_up_to_depth( &self, target_depth: usize, ) -> Vec<(usize, &MacroInvocation)>

Returns (offset, invocation) pairs up to the specified depth.

Used to get the invocation context when resolving arguments for a macro at target_depth.

Source

pub fn current_invocation(&self) -> Option<&MacroInvocation>

Returns the invocation details for the current macro, or None if unavailable.

Source

pub fn current_invocation_with_offset( &self, ) -> Option<(usize, Option<&MacroInvocation>)>

Returns the bytecode offset and invocation details for the current macro.

Source

fn build_scope_id(&self, target_depth: usize) -> ScopeId

Builds a scope ID at a specific depth in the call stack.

§Arguments
  • target_depth - The depth to build the scope ID for (0 = root)
§Panics

Panics if target_depth is greater than the current stack depth.

Trait Implementations§

Source§

impl<'a> Default for ScopeManager<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ScopeManager<'a>

§

impl<'a> RefUnwindSafe for ScopeManager<'a>

§

impl<'a> Send for ScopeManager<'a>

§

impl<'a> Sync for ScopeManager<'a>

§

impl<'a> Unpin for ScopeManager<'a>

§

impl<'a> UnsafeUnpin for ScopeManager<'a>

§

impl<'a> UnwindSafe for ScopeManager<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 104 bytes