--- a/crates/jrsonnet-evaluator/src/function/arglike.rs +++ b/crates/jrsonnet-evaluator/src/function/arglike.rs @@ -3,23 +3,11 @@ use jrsonnet_interner::IStr; use jrsonnet_parser::{ArgsDesc, LocExpr}; -use crate::{evaluate, gc::GcHashMap, typed::Typed, val::ThunkValue, Context, Result, Thunk, Val}; +use crate::{evaluate, gc::GcHashMap, typed::Typed, Context, Result, Thunk, Val}; /// Marker for arguments, which can be evaluated with context set to None pub trait OptionalContext {} -#[derive(Trace)] -struct EvaluateThunk { - ctx: Context, - expr: LocExpr, -} -impl ThunkValue for EvaluateThunk { - type Output = Val; - fn get(self: Box) -> Result { - evaluate(self.ctx, &self.expr) - } -} - pub trait ArgLike { fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result>; } @@ -29,10 +17,8 @@ Ok(if tailstrict { Thunk::evaluated(evaluate(ctx, self)?) } else { - Thunk::new(EvaluateThunk { - ctx, - expr: (*self).clone(), - }) + let expr = (*self).clone(); + Thunk!(move || evaluate(ctx, &expr)) }) } } @@ -65,10 +51,8 @@ Self::Code(code) => Ok(if tailstrict { Thunk::evaluated(evaluate(ctx, code)?) } else { - Thunk::new(EvaluateThunk { - ctx, - expr: code.clone(), - }) + let code = code.clone(); + Thunk!(move || evaluate(ctx, &code)) }), Self::Val(val) => Ok(Thunk::evaluated(val.clone())), Self::Lazy(lazy) => Ok(lazy.clone()), @@ -140,10 +124,10 @@ if tailstrict { Thunk::evaluated(evaluate(ctx.clone(), arg)?) } else { - Thunk::new(EvaluateThunk { - ctx: ctx.clone(), - expr: arg.clone(), - }) + let ctx = ctx.clone(); + let arg = arg.clone(); + + Thunk!(move || evaluate(ctx, &arg)) }, )?; } @@ -162,10 +146,10 @@ if tailstrict { Thunk::evaluated(evaluate(ctx.clone(), arg)?) } else { - Thunk::new(EvaluateThunk { - ctx: ctx.clone(), - expr: arg.clone(), - }) + let ctx = ctx.clone(); + let arg = arg.clone(); + + Thunk!(move || evaluate(ctx, &arg)) }, )?; } --- a/crates/jrsonnet-evaluator/src/function/parse.rs +++ b/crates/jrsonnet-evaluator/src/function/parse.rs @@ -12,24 +12,9 @@ evaluate_named, function::builtin::ParamDefault, gc::GcHashMap, - val::ThunkValue, Context, Pending, Thunk, Val, }; - -#[derive(Trace)] -struct EvaluateNamedThunk { - ctx: Pending, - name: IStr, - value: LocExpr, -} -impl ThunkValue for EvaluateNamedThunk { - type Output = Val; - fn get(self: Box) -> Result { - evaluate_named(self.ctx.unwrap(), &self.value, self.name) - } -} - /// Creates correct [context](Context) for function body evaluation returning error on invalid call. /// /// ## Parameters @@ -105,11 +90,12 @@ destruct( ¶m.0, - Thunk::new(EvaluateNamedThunk { - ctx: fctx.clone(), - name: param.0.name().unwrap_or_else(|| "".into()), - value: param.1.clone().expect("default exists"), - }), + { + let ctx = fctx.clone(); + let name = param.0.name().unwrap_or_else(|| "".into()); + let value = param.1.clone().expect("default exists"); + Thunk!(move || evaluate_named(ctx.unwrap(), &value, name)) + }, fctx.clone(), &mut defaults, )?; @@ -241,11 +227,12 @@ if let Some(v) = ¶m.1 { destruct( ¶m.0.clone(), - Thunk::new(EvaluateNamedThunk { - ctx: fctx.clone(), - name: param.0.name().unwrap_or_else(|| "".into()), - value: v.clone(), - }), + { + let ctx = fctx.clone(); + let name = param.0.name().unwrap_or_else(|| "".into()); + let value = v.clone(); + Thunk!(move || evaluate_named(ctx.unwrap(), &value, name)) + }, fctx.clone(), &mut bindings, )?; --- a/nix/benchmarks.nix +++ b/nix/benchmarks.nix @@ -52,6 +52,7 @@ mkdir -p $out cp -r ${src}/* $out/ cd $out + chmod u+w jsonnetfile.lock.json mkdir vendor ${jsonnet-bundler}/bin/jb install ''; @@ -125,7 +126,7 @@ go-jsonnet $path > generated.jsonnet path=generated.jsonnet ''} - hyperfine -N -w4 -m20 --output=pipe --style=basic --export-markdown result.md \ + hyperfine -N -w4 -m20 --output=pipe --style=basic --export-asciidoc result.adoc \ ${concatStringsSep " " (forEach jrsonnetVariants ( variant: "\"${variant.drv}/bin/jrsonnet $path${optionalString (vendor != "") " -J${vendor}"}\" -n \"Rust${ if variant.name != "" @@ -137,7 +138,7 @@ ${optionalString (skipGo == "") "\"go-jsonnet $path${optionalString (vendor != "") " -J ${vendor}"}\" -n \"Go\""} \ ${optionalString (skipScala == "") "\"sjsonnet $path${optionalString (vendor != "") " -J ${vendor}"}\" -n \"Scala\""} \ ${optionalString (skipCpp == "") "\"jsonnet $path${optionalString (vendor != "") " -J ${vendor}"}\" -n \"C++\""} - cat result.md >> $out + cat result.adoc >> $out ''; in '' set -oux