about summary refs log tree commit diff
path: root/tvix/eval/src/builtins
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2023-12-25T23·41+0100
committerclbot <clbot@tvl.fyi>2024-01-03T18·15+0000
commit0e6285ec8bf528ff3c964b59bf577487ff53306f (patch)
tree8f10b3ee5bcb8ca61f7fecf0de04af40f9a2bc63 /tvix/eval/src/builtins
parent88fcab68d4c3fa33cb2bf14d057a3a2dcc0120d5 (diff)
feat(tvix/eval): context-aware `concatStringsSep` r/7327
Change-Id: Id0e169084d26dc598091d157563c4d959b66279b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10431
Autosubmit: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r--tvix/eval/src/builtins/mod.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 22aa48668294..89ab5edb1bc9 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -3,6 +3,7 @@
 //! See //tvix/eval/docs/builtins.md for a some context on the
 //! available builtins in Nix.
 
+use crate::NixContext;
 use builtin_macros::builtins;
 use genawaiter::rc::Gen;
 use imbl::OrdMap;
@@ -255,7 +256,11 @@ mod pure_builtins {
         separator: Value,
         list: Value,
     ) -> Result<Value, ErrorKind> {
-        let separator = separator.to_str()?;
+        let mut separator = separator.to_contextful_str()?;
+        let mut context = NixContext::new();
+        if let Some(sep_context) = separator.context_mut() {
+            context = context.join(sep_context);
+        }
         let list = list.to_list()?;
         let mut res = String::new();
         for (i, val) in list.into_iter().enumerate() {
@@ -272,11 +277,22 @@ mod pure_builtins {
             )
             .await
             {
-                Ok(s) => res.push_str(s.as_str()),
+                Ok(mut s) => {
+                    res.push_str(s.as_str());
+                    if let Some(ref mut other_context) = s.context_mut() {
+                        // It is safe to consume the other context here
+                        // because the `list` and `separator` are originally
+                        // moved, here.
+                        // We are not going to use them again
+                        // because the result here is a string.
+                        context = context.join(other_context);
+                    }
+                }
                 Err(c) => return Ok(Value::Catchable(c)),
             }
         }
-        Ok(res.into())
+        // FIXME: pass immediately the string res.
+        Ok(NixString::new_context_from(context, &res).into())
     }
 
     #[builtin("deepSeq")]