about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-11-05T11·57+0300
committertazjin <tazjin@tvl.su>2022-11-06T08·10+0000
commitc877e1d920f3dce5598fd50f68c05b5e876dea5f (patch)
tree9d2815e6886ed559d422b1488d7fd33977754c59 /tvix/eval/src/vm.rs
parent116c8d81c62f2a8aee5ce2a0fb53dd3e7907fbe3 (diff)
refactor(tvix/eval): move `unwrap_or_clone_rc` to lib module r/5254
This is more generally useful than just inside the VM, until it is
stabilised in Rust itself.

Change-Id: Id9aa3d5b533ff38e3d2c6b85ad484394fdd05dcf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7186
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs7
1 files changed, 1 insertions, 6 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index c67e9f6d8899..8c45ee7363e1 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -10,6 +10,7 @@ use crate::{
     nix_search_path::NixSearchPath,
     observer::RuntimeObserver,
     opcode::{CodeIdx, Count, JumpOffset, OpCode, StackIdx, UpvalueIdx},
+    unwrap_or_clone_rc,
     upvalues::Upvalues,
     value::{Builtin, Closure, CoercionKind, Lambda, NixAttrs, NixList, Thunk, Value},
     warnings::{EvalWarning, WarningKind},
@@ -884,12 +885,6 @@ impl<'o> VM<'o> {
     }
 }
 
-// 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(
     nix_search_path: NixSearchPath,
     observer: &mut dyn RuntimeObserver,