Skip to content

Commit

Permalink
Merge pull request #145 from CertainLach/fix/lazy-array-comprehension
Browse files Browse the repository at this point in the history
fix: lazy object comprehension
  • Loading branch information
CertainLach authored Jan 16, 2024
2 parents 58696dc + eeb6fd0 commit c9696b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmds/jrsonnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ experimental = [
"exp-object-iteration",
"exp-bigint",
"exp-apply",
"exp-regex",
]
# Use mimalloc as allocator
mimalloc = ["mimallocator"]
Expand Down
18 changes: 16 additions & 2 deletions crates/jrsonnet-evaluator/src/evaluate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,24 @@ pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {
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(
Expand Down

0 comments on commit c9696b8

Please sign in to comment.