feat(tvix/eval): context-aware concatStringsSep

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>
This commit is contained in:
Ryan Lahfa 2023-12-26 00:41:55 +01:00 committed by clbot
parent 88fcab68d4
commit 0e6285ec8b

View file

@ -3,6 +3,7 @@
//! See //tvix/eval/docs/builtins.md for a some context on the //! See //tvix/eval/docs/builtins.md for a some context on the
//! available builtins in Nix. //! available builtins in Nix.
use crate::NixContext;
use builtin_macros::builtins; use builtin_macros::builtins;
use genawaiter::rc::Gen; use genawaiter::rc::Gen;
use imbl::OrdMap; use imbl::OrdMap;
@ -255,7 +256,11 @@ mod pure_builtins {
separator: Value, separator: Value,
list: Value, list: Value,
) -> Result<Value, ErrorKind> { ) -> 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 list = list.to_list()?;
let mut res = String::new(); let mut res = String::new();
for (i, val) in list.into_iter().enumerate() { for (i, val) in list.into_iter().enumerate() {
@ -272,11 +277,22 @@ mod pure_builtins {
) )
.await .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)), 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")] #[builtin("deepSeq")]