diff options
Diffstat (limited to 'tvix/eval/src/value')
-rw-r--r-- | tvix/eval/src/value/function.rs | 9 | ||||
-rw-r--r-- | tvix/eval/src/value/thunk.rs | 5 |
2 files changed, 9 insertions, 5 deletions
diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs index c9664112f1cd..9ac35d43d837 100644 --- a/tvix/eval/src/value/function.rs +++ b/tvix/eval/src/value/function.rs @@ -65,7 +65,7 @@ impl Lambda { #[derive(Clone, Debug)] pub struct Closure { pub lambda: Rc<Lambda>, - pub upvalues: Upvalues, + pub upvalues: Rc<Upvalues>, /// true if all upvalues have been realised #[cfg(debug_assertions)] pub is_finalised: bool, @@ -73,10 +73,13 @@ pub struct Closure { impl Closure { pub fn new(lambda: Rc<Lambda>) -> Self { - Self::new_with_upvalues(Upvalues::with_capacity(lambda.upvalue_count), lambda) + Self::new_with_upvalues( + Rc::new(Upvalues::with_capacity(lambda.upvalue_count)), + lambda, + ) } - pub fn new_with_upvalues(upvalues: Upvalues, lambda: Rc<Lambda>) -> Self { + pub fn new_with_upvalues(upvalues: Rc<Upvalues>, lambda: Rc<Lambda>) -> Self { Closure { upvalues, lambda, diff --git a/tvix/eval/src/value/thunk.rs b/tvix/eval/src/value/thunk.rs index 5107c6328da4..1be13bfe893f 100644 --- a/tvix/eval/src/value/thunk.rs +++ b/tvix/eval/src/value/thunk.rs @@ -70,7 +70,7 @@ impl Thunk { pub fn new_closure(lambda: Rc<Lambda>) -> Self { Thunk(Rc::new(RefCell::new(ThunkRepr::Evaluated(Value::Closure( Closure { - upvalues: Upvalues::with_capacity(lambda.upvalue_count), + upvalues: Rc::new(Upvalues::with_capacity(lambda.upvalue_count)), lambda: lambda.clone(), #[cfg(debug_assertions)] is_finalised: false, @@ -184,7 +184,8 @@ impl Thunk { if *is_finalised { panic!("Thunk::upvalues_mut() called on a finalised closure"); } - upvalues + Rc::get_mut(upvalues) + .expect("upvalues_mut() was called on a thunk which already had multiple references to it") } thunk => panic!("upvalues() on non-suspended thunk: {thunk:?}"), }) |