From 86361f0f4a754370b42ae3568ece4bc43850f36b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 29 Dec 2022 17:34:08 +0300 Subject: refactor(tvix/eval): remove extra Rc<..> around Value::Attrs The `im::OrdMap` is already small and cheap to copy while sharing memory, so this is not required anymore. Only the `KV` variant may have slightly larger content, but in practice this doesn't seem to make a difference when comparing the two variants and this one is less complicated. Change-Id: I64a563b209a2444125653777551373cb2989ca7d Reviewed-on: https://cl.tvl.fyi/c/depot/+/7677 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/value/attrs.rs | 11 +++++++++++ tvix/eval/src/value/mod.rs | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index adf56567fb0d..a41e7ce58a12 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -173,6 +173,17 @@ impl NixAttrs { Self(AttrsRep::Empty) } + /// Compare two attribute sets by pointer equality. Only makes + /// sense for some attribute set reprsentations, i.e. returning + /// `false` does not mean that the two attribute sets do not have + /// equal *content*. + pub fn ptr_eq(&self, other: &Self) -> bool { + match (&self.0, &other.0) { + (AttrsRep::Im(lhs), AttrsRep::Im(rhs)) => lhs.ptr_eq(rhs), + _ => false, + } + } + /// Return an attribute set containing the merge of the two /// provided sets. Keys from the `other` set have precedence. pub fn update(self, other: Self) -> Self { diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 7791a4a8c33d..b5585923a301 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -39,7 +39,7 @@ pub enum Value { Float(f64), String(NixString), Path(PathBuf), - Attrs(Rc), + Attrs(Box), List(NixList), Closure(Rc), // must use Rc here in order to get proper pointer equality Builtin(Builtin), @@ -154,7 +154,7 @@ where impl Value { /// Construct a [`Value::Attrs`] from a [`NixAttrs`]. pub fn attrs(attrs: NixAttrs) -> Self { - Self::Attrs(Rc::new(attrs)) + Self::Attrs(Box::new(attrs)) } } @@ -303,7 +303,7 @@ impl Value { gen_cast!(as_int, i64, "int", Value::Integer(x), *x); gen_cast!(as_float, f64, "float", Value::Float(x), *x); gen_cast!(to_str, NixString, "string", Value::String(s), s.clone()); - gen_cast!(to_attrs, Rc, "set", Value::Attrs(a), a.clone()); + gen_cast!(to_attrs, Box, "set", Value::Attrs(a), a.clone()); gen_cast!(to_list, NixList, "list", Value::List(l), l.clone()); gen_cast!( as_closure, -- cgit 1.4.1