about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/mod.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-27T16·55+0300
committertazjin <tazjin@tvl.su>2022-09-04T17·53+0000
commit932a70d0c25a3d7b8cfb31788348e850648e2aa1 (patch)
tree867c9c42124ca14f002f422caf6150125898b98a /tvix/eval/src/compiler/mod.rs
parent2cd08d136e2a87bbaecbebd5e42216d7e5256906 (diff)
refactor(tvix/eval): track with stack size as a simple integer r/4643
The `With` struct no longer contained any internals after the cleanup
logic for the stack had been moved into Compiler::compile_with,
leaving the `Vec<With>` to essentially act as a counter for the number
of things on the with stack.

That's inefficient of course, so with this commit it actually becomes
an integer (with an encapsulated API within scope::Scope).

Change-Id: I67a00987fc8b46b30d369a96d41e83c8af5b1998
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6311
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/compiler/mod.rs')
-rw-r--r--tvix/eval/src/compiler/mod.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 17ea8921a0c3..2fac7560a6f6 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -29,7 +29,7 @@ use crate::opcode::{CodeIdx, Count, JumpOffset, OpCode, StackIdx, UpvalueIdx};
 use crate::value::{Closure, Lambda, Value};
 use crate::warnings::{EvalWarning, WarningKind};
 
-use self::scope::{Depth, Local, LocalPosition, Scope, Upvalue, With};
+use self::scope::{Depth, Local, LocalPosition, Scope, Upvalue};
 
 /// Represents the result of compiling a piece of Nix code. If
 /// compilation was successful, the resulting bytecode can be passed
@@ -601,7 +601,7 @@ impl Compiler {
                 // Within a `let` binding, inheriting from the outer
                 // scope is a no-op *if* the identifier can be
                 // statically resolved.
-                None if self.scope().with_stack.is_empty() => {
+                None if !self.scope().has_with() => {
                     self.emit_warning(inherit.syntax().clone(), WarningKind::UselessInherit);
                     continue;
                 }
@@ -699,7 +699,7 @@ impl Compiler {
                     return;
                 }
 
-                if self.scope().with_stack.is_empty() {
+                if !self.scope().has_with() {
                     self.emit_error(node.syntax().clone(), ErrorKind::UnknownStaticVariable);
                     return;
                 }
@@ -727,7 +727,7 @@ impl Compiler {
         self.compile(node.namespace().unwrap());
         self.declare_phantom();
 
-        self.scope_mut().with_stack.push(With {});
+        self.scope_mut().push_with();
 
         let with_idx = self
             .scope()
@@ -745,7 +745,7 @@ impl Compiler {
         self.compile(node.body().unwrap());
 
         self.chunk().push_op(OpCode::OpPopWith);
-        self.scope_mut().with_stack.pop();
+        self.scope_mut().pop_with();
         self.end_scope();
     }
 
@@ -991,7 +991,7 @@ impl Compiler {
 
         // Determine whether the upvalue is a dynamic variable in the
         // enclosing context.
-        if !self.contexts[ctx_idx - 1].scope.with_stack.is_empty() {
+        if self.contexts[ctx_idx - 1].scope.has_with() {
             return Some(self.add_upvalue(ctx_idx, Upvalue::Dynamic(SmolStr::new(name))));
         }