Struct tvix_eval::compiler::scope::Scope

source ·
pub struct Scope {
    locals: Vec<Local>,
    pub upvalues: Vec<Upvalue>,
    by_name: HashMap<String, ByName>,
    scope_depth: usize,
    with_stack_size: usize,
}
Expand description

Represents a scope known during compilation, which can be resolved directly to stack indices.

Fields§

§locals: Vec<Local>§upvalues: Vec<Upvalue>§by_name: HashMap<String, ByName>

Secondary by-name index over locals.

§scope_depth: usize

How many scopes “deep” are these locals?

§with_stack_size: usize

Current size of the with-stack at runtime.

Implementations§

source§

impl Scope

source

pub fn inherit(&self) -> Self

Inherit scope details from a parent scope (required for correctly nesting scopes in lambdas and thunks when special scope features like dynamic resolution are present).

source

pub fn push_with(&mut self)

Increase the with-stack size of this scope.

source

pub fn pop_with(&mut self)

Decrease the with-stack size of this scope.

source

pub fn has_with(&self) -> bool

Does this scope currently require dynamic runtime resolution of identifiers that could not be found?

source

pub fn resolve_local(&mut self, name: &str) -> LocalPosition

Resolve the stack index of a statically known local.

source

pub fn declare_phantom(&mut self, span: Span, initialised: bool) -> LocalIdx

Declare a local variable that occupies a stack slot and should be accounted for, but is not directly accessible by users (e.g. attribute sets used for with).

source

pub fn declare_local( &mut self, name: String, span: Span ) -> (LocalIdx, Option<LocalIdx>)

Declare an uninitialised, named local variable.

Returns the LocalIdx of the new local, and optionally the index of a previous local shadowed by this one.

source

pub fn mark_initialised(&mut self, idx: LocalIdx)

Mark local as initialised after compiling its expression.

source

pub fn mark_needs_finaliser(&mut self, idx: LocalIdx)

Mark local as needing a finaliser.

source

pub fn mark_must_thunk(&mut self, idx: LocalIdx)

Mark local as must be wrapped in a thunk. This happens if the local has a reference to itself in its upvalues.

source

pub fn stack_index(&self, idx: LocalIdx) -> StackIdx

Compute the runtime stack index for a given local by accounting for uninitialised variables at scopes below this one.

source

pub fn begin_scope(&mut self)

Increase the current scope depth (e.g. within a new bindings block, or with-scope).

source

pub fn end_scope(&mut self) -> (usize, Vec<Span>)

Decrease the scope depth and remove all locals still tracked for the current scope.

Returns the count of locals that were dropped while marked as initialised (used by the compiler to determine whether to emit scope cleanup operations), as well as the spans of the definitions of unused locals (used by the compiler to emit unused binding warnings).

source

pub fn scope_depth(&self) -> usize

Access the current scope depth.

Trait Implementations§

source§

impl Debug for Scope

source§

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

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

impl Default for Scope

source§

fn default() -> Scope

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

impl Index<LocalIdx> for Scope

§

type Output = Local

The returned type after indexing.
source§

fn index(&self, index: LocalIdx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V