refactor(tvix/eval): remove Value::Json and related functionality

Currently Value::Json is used in combination with VMRequest::ToJson to
recursively convert tvix Value to serde_json::Value. This functionality
is used in builtins.toJSON as well as derivation __structuredAttrs.

Both Value::Json and VMRequest::ToJson were removed in this commit.

Related functionality in vm.rs is also removed: vm.rs does not know
about JSON anymore.

Recursively converting to serde_json now happens without going through
the VM.

Thrown errors that are part of the value of toJSON are now directly
propagated as ErrorKind, were-as previously there was a split between
CatchableErrorKind and ErrorKind, where eventually CatchableErrorKind
would be converted to ErrorKind::Catchable.

Change-Id: I066f064926c491e4c087a984f07af43d19124cfe
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12732
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Bob van der Linden 2024-11-03 16:59:40 +01:00
parent b6e524c726
commit 9aa479648b
8 changed files with 27 additions and 109 deletions

View file

@ -442,17 +442,20 @@ mod pure_builtins {
#[builtin("fromJSON")]
async fn builtin_from_json(co: GenCo, json: Value) -> Result<Value, ErrorKind> {
let json_str = json.to_str()?;
serde_json::from_slice(&json_str).map_err(|err| err.into())
}
#[builtin("toJSON")]
async fn builtin_to_json(co: GenCo, val: Value) -> Result<Value, ErrorKind> {
match val.into_contextful_json(&co).await? {
Err(cek) => Ok(Value::from(cek)),
Ok((json_value, ctx)) => {
let json_str = serde_json::to_string(&json_value)?;
Ok(NixString::new_context_from(ctx, json_str).into())
match val.into_contextful_json(&co).await {
Err(ErrorKind::CatchableError(catchable)) => Ok(Value::Catchable(Box::new(catchable))),
Err(err) => Err(err),
Ok((json, context)) => {
let json_str = serde_json::to_string(&json)
.map_err(|err| ErrorKind::JsonError(err.to_string()))?;
Ok(Value::String(NixString::new_context_from(
context, json_str,
)))
}
}
}

View file

@ -122,7 +122,6 @@ fn value_variant_to_xml<W: Write>(w: &mut XmlEmitter<W>, value: &Value) -> Resul
| Value::Blueprint(_)
| Value::DeferredUpvalue(_)
| Value::UnresolvedPath(_)
| Value::Json(..)
| Value::FinaliseRequest(_) => {
return Err(ErrorKind::TvixBug {
msg: "internal value variant encountered in builtins.toXML",