difftreelog
fix lazy object comprehension
in: master
2 files changed
cmds/jrsonnet/Cargo.tomldiffbeforeafterboth1[package]2name = "jrsonnet"3description = "Rust jsonnet implementation"4version.workspace = true5repository.workspace = true6authors = ["Yaroslav Bolyukin <iam@lach.pw>"]7license = "MIT"8edition = "2021"910[features]11experimental = [12 "exp-preserve-order",13 "exp-destruct",14 "exp-null-coaelse",15 "exp-object-iteration",16 "exp-bigint",17 "exp-apply",18]19# Use mimalloc as allocator20mimalloc = ["mimallocator"]21# Experimental feature, which allows to preserve order of object fields22exp-preserve-order = [23 "jrsonnet-evaluator/exp-preserve-order",24 "jrsonnet-cli/exp-preserve-order",25]26# Destructuring of locals27exp-destruct = ["jrsonnet-evaluator/exp-destruct"]28# Iteration over objects yields [key, value] elements29exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]30# Bigint type31exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]32# std.regex and co.33exp-regex = ["jrsonnet-cli/exp-regex"]34# obj?.field, obj?.['field']35exp-null-coaelse = [36 "jrsonnet-evaluator/exp-null-coaelse",37 "jrsonnet-parser/exp-null-coaelse",38 "jrsonnet-cli/exp-null-coaelse",39]40# --exp-apply41exp-apply = []4243# std.thisFile support44legacy-this-file = ["jrsonnet-cli/legacy-this-file"]4546nightly = ["jrsonnet-evaluator/nightly"]4748[dependencies]49jrsonnet-evaluator.workspace = true50jrsonnet-parser.workspace = true51jrsonnet-cli.workspace = true52jrsonnet-gcmodule.workspace = true5354mimallocator = { workspace = true, optional = true }55thiserror.workspace = true56clap = { workspace = true, features = ["derive"] }57clap_complete.workspace = true58serde_json.workspace = true59serde = { workspace = true, features = ["derive"] }60ass-stroke.workspace = true1[package]2name = "jrsonnet"3description = "Rust jsonnet implementation"4version.workspace = true5repository.workspace = true6authors = ["Yaroslav Bolyukin <iam@lach.pw>"]7license = "MIT"8edition = "2021"910[features]11experimental = [12 "exp-preserve-order",13 "exp-destruct",14 "exp-null-coaelse",15 "exp-object-iteration",16 "exp-bigint",17 "exp-apply",18 "exp-regex",19]20# Use mimalloc as allocator21mimalloc = ["mimallocator"]22# Experimental feature, which allows to preserve order of object fields23exp-preserve-order = [24 "jrsonnet-evaluator/exp-preserve-order",25 "jrsonnet-cli/exp-preserve-order",26]27# Destructuring of locals28exp-destruct = ["jrsonnet-evaluator/exp-destruct"]29# Iteration over objects yields [key, value] elements30exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]31# Bigint type32exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]33# std.regex and co.34exp-regex = ["jrsonnet-cli/exp-regex"]35# obj?.field, obj?.['field']36exp-null-coaelse = [37 "jrsonnet-evaluator/exp-null-coaelse",38 "jrsonnet-parser/exp-null-coaelse",39 "jrsonnet-cli/exp-null-coaelse",40]41# --exp-apply42exp-apply = []4344# std.thisFile support45legacy-this-file = ["jrsonnet-cli/legacy-this-file"]4647nightly = ["jrsonnet-evaluator/nightly"]4849[dependencies]50jrsonnet-evaluator.workspace = true51jrsonnet-parser.workspace = true52jrsonnet-cli.workspace = true53jrsonnet-gcmodule.workspace = true5455mimallocator = { workspace = true, optional = true }56thiserror.workspace = true57clap = { workspace = true, features = ["derive"] }58clap_complete.workspace = true59serde_json.workspace = true60serde = { workspace = true, features = ["derive"] }61ass-stroke.workspace = truecrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -596,10 +596,24 @@
ArrComp(expr, comp_specs) => {
let mut out = Vec::new();
evaluate_comp(ctx, comp_specs, &mut |ctx| {
- out.push(evaluate(ctx, expr)?);
+ #[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)
+ }
+ }
+ out.push(Thunk::new(EvaluateThunk {
+ ctx,
+ expr: expr.clone(),
+ }));
Ok(())
})?;
- Val::Arr(ArrValue::eager(out))
+ Val::Arr(ArrValue::lazy(out))
}
Obj(body) => Val::Obj(evaluate_object(ctx, body)?),
ObjExtend(a, b) => evaluate_add_op(