about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-03T01·20+0300
committertazjin <tazjin@tvl.su>2022-09-08T20·17+0000
commit09eaa0d4ae63b0513c934535a40fa2aaa25846e1 (patch)
tree8070b85c5408b5f3d7073c025a322c27502fc581 /tvix/eval/src
parentfe047885d75a97bd303176847db7fdb2a781344d (diff)
fix(tvix/eval): address current clippy & grfn lints r/4763
Change-Id: I65c6feb9f817b5b367d37204a1f57acfe4100d97
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6430
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/compiler/mod.rs8
-rw-r--r--tvix/eval/src/compiler/scope.rs9
-rw-r--r--tvix/eval/src/disassembler.rs34
-rw-r--r--tvix/eval/src/eval.rs2
-rw-r--r--tvix/eval/src/vm.rs17
5 files changed, 32 insertions, 38 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index f9a2dd32c88d..269604a859bd 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -54,6 +54,7 @@ impl LambdaCtx {
         }
     }
 
+    #[allow(clippy::let_and_return)] // due to disassembler
     fn inherit(&self) -> Self {
         let ctx = LambdaCtx {
             lambda: Lambda::new_anonymous(),
@@ -61,6 +62,7 @@ impl LambdaCtx {
         };
 
         #[cfg(feature = "disassembler")]
+        #[allow(clippy::redundant_closure_call)]
         let ctx = (|mut c: Self| {
             c.lambda.chunk.codemap = self.lambda.chunk.codemap.clone();
             c
@@ -822,7 +824,7 @@ impl Compiler<'_> {
             LocalPosition::Recursive(idx) => self.thunk(slot, &node, move |compiler, node, _| {
                 let upvalue_idx = compiler.add_upvalue(
                     compiler.contexts.len() - 1,
-                    &node,
+                    node,
                     UpvalueKind::Local(idx),
                 );
                 compiler.push_op(OpCode::OpGetUpvalue(upvalue_idx), node);
@@ -1350,10 +1352,10 @@ fn prepare_globals(additional: HashMap<&'static str, Value>) -> GlobalsMap {
     globals
 }
 
-pub fn compile<'code>(
+pub fn compile(
     expr: ast::Expr,
     location: Option<PathBuf>,
-    file: &'code codemap::File,
+    file: &codemap::File,
     globals: HashMap<&'static str, Value>,
 
     #[cfg(feature = "disassembler")] codemap: Rc<codemap::CodeMap>,
diff --git a/tvix/eval/src/compiler/scope.rs b/tvix/eval/src/compiler/scope.rs
index eb722a2c6972..874c6168c1c7 100644
--- a/tvix/eval/src/compiler/scope.rs
+++ b/tvix/eval/src/compiler/scope.rs
@@ -180,10 +180,11 @@ impl Scope {
     /// correctly nesting scopes in lambdas and thunks when special
     /// scope features like poisoning are present).
     pub fn inherit(&self) -> Self {
-        let mut scope = Self::default();
-        scope.poisoned_tokens = self.poisoned_tokens.clone();
-        scope.scope_depth = self.scope_depth;
-        scope
+        Self {
+            poisoned_tokens: self.poisoned_tokens.clone(),
+            scope_depth: self.scope_depth,
+            ..Default::default()
+        }
     }
 
     /// Check whether a given token is poisoned.
diff --git a/tvix/eval/src/disassembler.rs b/tvix/eval/src/disassembler.rs
index a555f9179102..b089797f8ab1 100644
--- a/tvix/eval/src/disassembler.rs
+++ b/tvix/eval/src/disassembler.rs
@@ -13,34 +13,36 @@ use crate::value::Value;
 /// failure exits from the VM).
 pub struct Tracer(TabWriter<Stderr>);
 
-impl Tracer {
-    pub fn new() -> Self {
+impl Default for Tracer {
+    fn default() -> Self {
         Tracer(TabWriter::new(std::io::stderr()))
     }
+}
 
+impl Tracer {
     pub fn trace(&mut self, op: &OpCode, ip: usize, stack: &[Value]) {
-        write!(&mut self.0, "{:04} {:?}\t[ ", ip, op).ok();
+        let _ = write!(&mut self.0, "{:04} {:?}\t[ ", ip, op);
 
         for val in stack {
-            write!(&mut self.0, "{} ", val).ok();
+            let _ = write!(&mut self.0, "{} ", val);
         }
 
-        write!(&mut self.0, "]\n").ok();
+        let _ = writeln!(&mut self.0, "]");
     }
 
     pub fn literal(&mut self, line: &str) {
-        let _ = write!(&mut self.0, "{}\n", line);
+        let _ = writeln!(&mut self.0, "{}", line);
     }
 }
 
 impl Drop for Tracer {
     fn drop(&mut self) {
-        self.0.flush().ok();
+        let _ = self.0.flush();
     }
 }
 
 fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offset: usize) {
-    write!(tw, "{:0width$}\t ", offset, width = width).ok();
+    let _ = write!(tw, "{:0width$}\t ", offset, width = width);
 
     let span = chunk.get_span(CodeIdx(offset));
 
@@ -51,10 +53,9 @@ fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offse
         write!(tw, "{:4}\t", loc.begin.line + 1).unwrap();
     }
 
-    match chunk.code[offset] {
-        OpCode::OpConstant(idx) => write!(tw, "OpConstant({})\n", chunk.constant(idx)).ok(),
-
-        op => write!(tw, "{:?}\n", op).ok(),
+    let _ = match chunk.code[offset] {
+        OpCode::OpConstant(idx) => writeln!(tw, "OpConstant({})", chunk.constant(idx)),
+        op => writeln!(tw, "{:?}", op),
     };
 }
 
@@ -63,17 +64,16 @@ fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offse
 pub fn disassemble_chunk(chunk: &Chunk) {
     let mut tw = TabWriter::new(std::io::stderr());
 
-    write!(
+    let _ = writeln!(
         &mut tw,
-        "=== compiled bytecode ({} operations) ===\n",
+        "=== compiled bytecode ({} operations) ===",
         chunk.code.len()
-    )
-    .ok();
+    );
 
     let width = format!("{}", chunk.code.len()).len();
     for (idx, _) in chunk.code.iter().enumerate() {
         disassemble_op(&mut tw, chunk, width, idx);
     }
 
-    tw.flush().ok();
+    let _ = tw.flush();
 }
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 296887451610..ecf0824871a0 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -24,7 +24,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
             eprintln!("parse error: {}", err);
         }
         return Err(Error {
-            kind: ErrorKind::ParseErrors(errors.to_vec()).into(),
+            kind: ErrorKind::ParseErrors(errors.to_vec()),
             span: file.span,
         });
     }
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index b2785c511798..5d26afe3f304 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -25,6 +25,7 @@ impl CallFrame {
     }
 }
 
+#[derive(Default)]
 pub struct VM {
     frames: Vec<CallFrame>,
     stack: Vec<Value>,
@@ -161,6 +162,7 @@ impl VM {
         }
     }
 
+    #[allow(clippy::let_and_return)] // due to disassembler
     /// Execute the given lambda in this VM's context, returning its
     /// value after its stack frame completes.
     pub fn call(
@@ -610,7 +612,7 @@ impl VM {
                 ..
             }) => match up {
                 Some(idx) => Ok(self.frame().upvalue(idx).clone()),
-                None => Ok(Value::DynamicUpvalueMissing(ident.into())),
+                None => Ok(Value::DynamicUpvalueMissing(ident)),
             },
 
             Err(err) => Err(err),
@@ -696,17 +698,6 @@ impl VM {
             _ => Ok(()),
         }
     }
-
-    pub fn new() -> Self {
-        VM {
-            frames: vec![],
-            stack: vec![],
-            with_stack: vec![],
-
-            #[cfg(feature = "disassembler")]
-            tracer: crate::disassembler::Tracer::new(),
-        }
-    }
 }
 
 // TODO: use Rc::unwrap_or_clone once it is stabilised.
@@ -716,7 +707,7 @@ fn unwrap_or_clone_rc<T: Clone>(rc: Rc<T>) -> T {
 }
 
 pub fn run_lambda(lambda: Lambda) -> EvalResult<Value> {
-    let mut vm = VM::new();
+    let mut vm = VM::default();
     let value = vm.call(Rc::new(lambda), vec![], 0)?;
     vm.force_for_output(&value)?;
     Ok(value)