From 0e6285ec8bf528ff3c964b59bf577487ff53306f Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 26 Dec 2023 00:41:55 +0100 Subject: feat(tvix/eval): context-aware `concatStringsSep` Change-Id: Id0e169084d26dc598091d157563c4d959b66279b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10431 Autosubmit: raitobezarius Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/builtins/mod.rs | 22 +++++++++++++++++++--- 1 file 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 { - 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")] -- cgit 1.4.1