about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/scope.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-13T13·04+0300
committertazjin <tazjin@tvl.su>2022-09-13T14·41+0000
commitc28ecbee970c0a16b7f93241a5a2ef2df49406c6 (patch)
tree8abad92f1a9be60e69cbdcdaed00efc9b64bee2b /tvix/eval/src/compiler/scope.rs
parent268605140eae3cbfae5ddd18bd83b877e5da5748 (diff)
refactor(tvix/eval): encapsulate scope_depth in compiler::scope r/4840
This field no longer needs to be directly accessible by the compiler.

Addresses a sterni lint from cl/6466

Change-Id: I5e6791943d7f0ab3d9b7a30bb1654c4a6a435b1f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6564
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to '')
-rw-r--r--tvix/eval/src/compiler/scope.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/tvix/eval/src/compiler/scope.rs b/tvix/eval/src/compiler/scope.rs
index 1909a8dc8a..29947ea4a2 100644
--- a/tvix/eval/src/compiler/scope.rs
+++ b/tvix/eval/src/compiler/scope.rs
@@ -123,7 +123,7 @@ pub struct Scope {
     pub upvalues: Vec<Upvalue>,
 
     /// How many scopes "deep" are these locals?
-    pub scope_depth: usize,
+    scope_depth: usize,
 
     /// Current size of the `with`-stack at runtime.
     with_stack_size: usize,
@@ -272,6 +272,12 @@ impl Scope {
         StackIdx(idx.0 - uninitialised_count)
     }
 
+    /// Increase the current scope depth (e.g. within a new bindings
+    /// block, or `with`-scope).
+    pub fn begin_scope(&mut self) {
+        self.scope_depth += 1;
+    }
+
     /// Decrease the scope depth and remove all locals still tracked
     /// for the current scope.
     ///
@@ -314,4 +320,9 @@ impl Scope {
 
         (pops, unused_spans)
     }
+
+    /// Access the current scope depth.
+    pub fn scope_depth(&self) -> usize {
+        self.scope_depth
+    }
 }