From 556e52c9cb8aa7b2af8bae75cd3365318e5d08c2 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Mon, 25 Dec 2023 22:07:14 +0100 Subject: feat(tvix/eval): impl `unsafeDiscardStringContext` Change-Id: I7f0cc42cbebfe5cd27bf6d4f58a4af927b83646a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10423 Autosubmit: raitobezarius Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/docs/builtins.md | 2 +- tvix/eval/src/builtins/mod.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'tvix/eval') diff --git a/tvix/eval/docs/builtins.md b/tvix/eval/docs/builtins.md index f3a4a29c26f2..6e0c7b559516 100644 --- a/tvix/eval/docs/builtins.md +++ b/tvix/eval/docs/builtins.md @@ -121,7 +121,7 @@ The `impl` column indicates implementation status in tvix: | tryEval | false | | | | | typeOf | false | | | | | unsafeDiscardOutputDependency | false | | | context | -| unsafeDiscardStringContext | false | | | context | +| unsafeDiscardStringContext | false | | | | | unsafeGetAttrPos | false | | | todo | | valueSize | false | | | todo | diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 4cf9074fb8bf..b5adc3775fc0 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -1348,11 +1348,26 @@ mod placeholder_builtins { #[builtin("unsafeDiscardStringContext")] async fn builtin_unsafe_discard_string_context( - _: GenCo, - #[lazy] s: Value, + co: GenCo, + s: Value, ) -> Result { - // Tvix does not manually track contexts, and this is a no-op for us. - Ok(s) + let span = generators::request_span(&co).await; + let mut v = s + .coerce_to_string( + co, + // It's weak because + // lists, integers, floats and null are not + // accepted as parameters. + CoercionKind { + strong: false, + import_paths: true, + }, + span, + ) + .await? + .to_contextful_str()?; + v.clear_context(); + Ok(Value::String(v)) } #[builtin("addErrorContext")] -- cgit 1.4.1