pub struct Scope {
locals: Vec<Local>,
pub upvalues: Vec<Upvalue>,
by_name: FxHashMap<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: FxHashMap<String, ByName>Secondary by-name index over locals.
scope_depth: usizeHow many scopes “deep” are these locals?
with_stack_size: usizeCurrent size of the with-stack at runtime.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn inherit(&self) -> Self
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).
Sourcepub fn has_with(&self) -> bool
pub fn has_with(&self) -> bool
Does this scope currently require dynamic runtime resolution of identifiers that could not be found?
Sourcepub fn resolve_local(&self, name: &str) -> LocalPosition
pub fn resolve_local(&self, name: &str) -> LocalPosition
Resolve the stack index of a statically known local.
Sourcepub fn declare_phantom(&mut self, span: Span, initialised: bool) -> LocalIdx
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).
Sourcepub fn declare_local(
&mut self,
name: String,
span: Span,
) -> (LocalIdx, Option<LocalIdx>)
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.
pub fn declare_constant(&mut self, name: String) -> LocalIdx
Sourcepub fn mark_initialised(&mut self, idx: LocalIdx)
pub fn mark_initialised(&mut self, idx: LocalIdx)
Mark local as initialised after compiling its expression.
pub fn mark_used(&mut self, idx: LocalIdx)
Sourcepub fn mark_needs_finaliser(&mut self, idx: LocalIdx)
pub fn mark_needs_finaliser(&mut self, idx: LocalIdx)
Mark local as needing a finaliser.
Sourcepub fn mark_must_thunk(&mut self, idx: LocalIdx)
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.
Sourcepub fn stack_index(&self, idx: LocalIdx) -> StackIdx
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.
Sourcepub fn begin_scope(&mut self, name: &'static str) -> ScopeGuard
pub fn begin_scope(&mut self, name: &'static str) -> ScopeGuard
Increase the current scope depth (e.g. within a new bindings
block, or with-scope). Pass a short descriptive string as
name. This will be used in debug builds to aid debugging
scoping issues. The returned ScopeGuard must be passed back
to end_scope.
Sourcepub fn end_scope(&mut self, guard: ScopeGuard) -> (usize, Vec<Span>)
pub fn end_scope(&mut self, guard: ScopeGuard) -> (usize, Vec<Span>)
Decrease the scope depth and remove all locals still tracked for the current scope. Pass in the ScopeGuard instance you obtained when opening this scope via Scope::begin_scope. The ScopeGuard instances have to be passed on the correct order. In other words: the last scope opened must be the first one closed. If the order mismatched this will panic in debug builds.
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).
Sourcepub fn scope_depth(&self) -> usize
pub fn scope_depth(&self) -> usize
Access the current scope depth.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scope
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnsafeUnpin for Scope
impl UnwindSafe for Scope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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