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
15 "exp-object-iteration",15 "exp-object-iteration",
16 "exp-bigint",16 "exp-bigint",
17 "exp-apply",17 "exp-apply",
18 "exp-regex",
18]19]
19# Use mimalloc as allocator20# Use mimalloc as allocator
20mimalloc = ["mimallocator"]21mimalloc = ["mimallocator"]
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(