From eeb6fd058496521ceaba784d8ebb9403f8248ce2 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 14 Dec 2023 00:44:36 +0000 Subject: [PATCH] fix: lazy object 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