about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 65534006d0e1..6de9cd03c49c 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -203,10 +203,10 @@ impl VM {
                 OpCode::OpAttrPath(count) => self.run_attr_path(count)?,
 
                 OpCode::OpAttrsUpdate => {
-                    let rhs = self.pop().to_attrs()?;
-                    let lhs = self.pop().to_attrs()?;
+                    let rhs = unwrap_or_clone_rc(self.pop().to_attrs()?);
+                    let lhs = unwrap_or_clone_rc(self.pop().to_attrs()?);
 
-                    self.push(Value::Attrs(Rc::new(lhs.update(&rhs))))
+                    self.push(Value::Attrs(Rc::new(lhs.update(rhs))))
                 }
 
                 OpCode::OpAttrsSelect => {
@@ -414,6 +414,12 @@ impl VM {
     }
 }
 
+// TODO: use Rc::unwrap_or_clone once it is stabilised.
+// https://doc.rust-lang.org/std/rc/struct.Rc.html#method.unwrap_or_clone
+fn unwrap_or_clone_rc<T: Clone>(rc: Rc<T>) -> T {
+    Rc::try_unwrap(rc).unwrap_or_else(|rc| (*rc).clone())
+}
+
 pub fn run_lambda(lambda: Lambda) -> EvalResult<Value> {
     let mut vm = VM {
         frames: vec![],