From c9696b8e386855867dc2f27f1d4a00aa100e3534 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 16 Jan 2024 11:02:44 +0000 Subject: [PATCH] Merge pull request #145 from CertainLach/fix/lazy-array-comprehension --- --- a/cmds/jrsonnet/Cargo.toml +++ b/cmds/jrsonnet/Cargo.toml @@ -15,6 +15,7 @@ "exp-object-iteration", "exp-bigint", "exp-apply", + "exp-regex", ] # Use mimalloc as allocator mimalloc = ["mimallocator"] --- 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) -> Result { + 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( -- gitstuff