git.delta.rocks / jrsonnet / refs/commits / eeb6fd058496

difftreelog

fix lazy object comprehension

Yaroslav Bolyukin2023-12-14parent: #e7b9349.patch.diff
in: master

2 files changed

modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
before · cmds/jrsonnet/Cargo.toml
1[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 = true
modifiedcrates/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(