difftreelog
refactor remove manual ThunkValue implementations
in: master
3 files changed
crates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterboth--- 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<Self>) -> Result<Val> {
- evaluate(self.ctx, &self.expr)
- }
-}
-
pub trait ArgLike {
fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result<Thunk<Val>>;
}
@@ -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))
},
)?;
}
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth12 evaluate_named,12 evaluate_named,13 function::builtin::ParamDefault,13 function::builtin::ParamDefault,14 gc::GcHashMap,14 gc::GcHashMap,15 val::ThunkValue,16 Context, Pending, Thunk, Val,15 Context, Pending, Thunk, Val,17};16};1819#[derive(Trace)]20struct EvaluateNamedThunk {21 ctx: Pending<Context>,22 name: IStr,23 value: LocExpr,24}2526impl ThunkValue for EvaluateNamedThunk {27 type Output = Val;28 fn get(self: Box<Self>) -> Result<Val> {29 evaluate_named(self.ctx.unwrap(), &self.value, self.name)30 }31}321733/// Creates correct [context](Context) for function body evaluation returning error on invalid call.18/// Creates correct [context](Context) for function body evaluation returning error on invalid call.34///19///10590106 destruct(91 destruct(107 ¶m.0,92 ¶m.0,108 Thunk::new(EvaluateNamedThunk {93 {109 ctx: fctx.clone(),94 let ctx = fctx.clone();110 name: param.0.name().unwrap_or_else(|| "<destruct>".into()),95 let name = param.0.name().unwrap_or_else(|| "<destruct>".into());111 value: param.1.clone().expect("default exists"),96 let value = param.1.clone().expect("default exists");97 Thunk!(move || evaluate_named(ctx.unwrap(), &value, name))112 }),98 },113 fctx.clone(),99 fctx.clone(),114 &mut defaults,100 &mut defaults,115 )?;101 )?;241 if let Some(v) = ¶m.1 {227 if let Some(v) = ¶m.1 {242 destruct(228 destruct(243 ¶m.0.clone(),229 ¶m.0.clone(),244 Thunk::new(EvaluateNamedThunk {230 {245 ctx: fctx.clone(),231 let ctx = fctx.clone();246 name: param.0.name().unwrap_or_else(|| "<destruct>".into()),232 let name = param.0.name().unwrap_or_else(|| "<destruct>".into());247 value: v.clone(),233 let value = v.clone();234 Thunk!(move || evaluate_named(ctx.unwrap(), &value, name))248 }),235 },249 fctx.clone(),236 fctx.clone(),250 &mut bindings,237 &mut bindings,251 )?;238 )?;nix/benchmarks.nixdiffbeforeafterboth--- 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