From 1ac57b0d1cdade99cd6cdf34211aa23e63db6f97 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 11 Dec 2023 03:57:22 -0800 Subject: feat(tvix/eval): nonrecursive coerce_to_string() After this commit, the only non-builtins uses of generators are: - coerce_to_string() uses generators::request_enter_lambda() - Thunk::force() uses generators::request_enter_lambda() That's it! Once those two are taken care of, GenCo can become an implementation detail of `builtins::BuiltinGen`. No more crazy nonlocal flow control within the interpreter: if you've got a GenCo floating around in your code it's because you're writing a builtin, which isn't part of the core interpreter. The interpreter won't need GenCos to talk to itself anymore. Technically generators::request_path_import() is also used by coerce_to_string(), but that's just because the io_handle happens to be part of the VM. There's no recursion-depth issue there, so the call doesn't need to go through the generator mechanism (request_path_import() doesn't call back to the interpreter!) Change-Id: I83ce5774d49b88fdafdd61160975b4937a435bb0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10256 Reviewed-by: tazjin Tested-by: BuildkiteCI Autosubmit: Adam Joseph --- tvix/eval/src/value/json.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tvix/eval/src/value/json.rs') diff --git a/tvix/eval/src/value/json.rs b/tvix/eval/src/value/json.rs index bff04487fa50..f7ecf121de5e 100644 --- a/tvix/eval/src/value/json.rs +++ b/tvix/eval/src/value/json.rs @@ -44,8 +44,16 @@ impl Value { // Attribute sets with a callable `__toString` attribute // serialise to the string-coerced version of the result of // calling that. - if let Some(s) = attrs.try_to_string(co, CoercionKind::Weak).await { - return Ok(Ok(Json::String(s.as_str().to_string()))); + if attrs.select("__toString").is_some() { + let span = generators::request_span(co).await; + match Value::Attrs(attrs) + .coerce_to_string_(co, CoercionKind::Weak, span) + .await? + { + Value::Catchable(cek) => return Ok(Err(cek)), + Value::String(s) => return Ok(Ok(Json::String(s.as_str().to_owned()))), + _ => panic!("Value::coerce_to_string_() returned a non-string!"), + } } // Attribute sets with an `outPath` attribute -- cgit 1.4.1