about summary refs log tree commit diff
path: root/tvix/eval/src/value/attrs.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-24T13·00+0300
committertazjin <tazjin@tvl.su>2022-09-29T11·47+0000
commitd54aeb1f2055bdac05cb62ab30b6c63dc86a78e0 (patch)
tree225df28fca4e3ba540e1537cb7743135303d491e /tvix/eval/src/value/attrs.rs
parent3f2160627895e7d1fe3236812b83bddc5d3049f5 (diff)
chore(tvix/eval): remove existing nested key implementation r/4990
This implementation, which only ever worked for non-recursive
attribute sets, is no longer needed and thus removed here.

We have a new implementation of these nested keys coming up instead.

Change-Id: I0c2875154026a4f5f6e0aa038e465f54444bf721
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6783
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/value/attrs.rs')
-rw-r--r--tvix/eval/src/value/attrs.rs75
1 files changed, 1 insertions, 74 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs
index 5eb258cc9e47..318a8cfa8209 100644
--- a/tvix/eval/src/value/attrs.rs
+++ b/tvix/eval/src/value/attrs.rs
@@ -8,7 +8,6 @@
 use std::collections::btree_map;
 use std::collections::BTreeMap;
 use std::fmt::Display;
-use std::rc::Rc;
 
 use crate::errors::ErrorKind;
 use crate::vm::VM;
@@ -248,23 +247,11 @@ impl NixAttrs {
 
         for _ in 0..count {
             let value = stack_slice.pop().unwrap();
-
-            // It is at this point that nested attribute sets need to
-            // be constructed (if they exist).
-            //
             let key = stack_slice.pop().unwrap();
+
             match key {
                 Value::String(ks) => set_attr(&mut attrs, ks, value)?,
 
-                Value::AttrPath(mut path) => {
-                    set_nested_attr(
-                        &mut attrs,
-                        path.pop().expect("AttrPath is never empty"),
-                        path,
-                        value,
-                    )?;
-                }
-
                 Value::Null => {
                     // This is in fact valid, but leads to the value
                     // being ignored and nothing being set, i.e. `{
@@ -410,66 +397,6 @@ fn set_attr(attrs: &mut NixAttrs, key: NixString, value: Value) -> Result<(), Er
     }
 }
 
-/// Set a nested attribute inside of an attribute set, throwing a
-/// duplicate key error if a non-hashmap entry already exists on the
-/// path.
-///
-/// There is some optimisation potential for this simple implementation
-/// if it becomes a problem.
-fn set_nested_attr(
-    attrs: &mut NixAttrs,
-    key: NixString,
-    mut path: Vec<NixString>,
-    value: Value,
-) -> Result<(), ErrorKind> {
-    // If there is no next key we are at the point where we
-    // should insert the value itself.
-    if path.is_empty() {
-        return set_attr(attrs, key, value);
-    }
-
-    // If there is not we go one step further down, in which case we
-    // need to ensure that there either is no entry, or the existing
-    // entry is a hashmap into which to insert the next value.
-    //
-    // If a value of a different type exists, the user specified a
-    // duplicate key.
-    match attrs.0.map_mut().entry(key) {
-        // Vacant entry -> new attribute set is needed.
-        btree_map::Entry::Vacant(entry) => {
-            let mut map = NixAttrs(AttrsRep::Map(BTreeMap::new()));
-
-            // TODO(tazjin): technically recursing further is not
-            // required, we can create the whole hierarchy here, but
-            // it's noisy.
-            set_nested_attr(&mut map, path.pop().expect("next key exists"), path, value)?;
-
-            entry.insert(Value::Attrs(Rc::new(map)));
-        }
-
-        // Occupied entry: Either error out if there is something
-        // other than attrs, or insert the next value.
-        btree_map::Entry::Occupied(mut entry) => match entry.get_mut() {
-            Value::Attrs(attrs) => {
-                set_nested_attr(
-                    Rc::make_mut(attrs),
-                    path.pop().expect("next key exists"),
-                    path,
-                    value,
-                )?;
-            }
-
-            _ => {
-                return Err(ErrorKind::DuplicateAttrsKey {
-                    key: entry.key().as_str().to_string(),
-                })
-            }
-        },
-    }
-
-    Ok(())
-}
-
 /// Internal helper type to track the iteration status of an iterator
 /// over the name/value representation.
 #[derive(Debug)]