Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lazy object comprehension #145

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -89,7 +89,7 @@
specs: &[CompSpec],
callback: &mut impl FnMut(Context) -> Result<()>,
) -> Result<()> {
match specs.get(0) {

Check warning on line 92 in crates/jrsonnet-evaluator/src/evaluate/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

accessing first element with `specs.get(0)`

warning: accessing first element with `specs.get(0)` --> crates/jrsonnet-evaluator/src/evaluate/mod.rs:92:8 | 92 | match specs.get(0) { | ^^^^^^^^^^^^ help: try: `specs.first()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first note: the lint level is defined here --> crates/jrsonnet-evaluator/src/lib.rs:5:2 | 5 | clippy::all, | ^^^^^^^^^^^ = note: `#[warn(clippy::get_first)]` implied by `#[warn(clippy::all)]`
None => callback(ctx)?,
Some(CompSpec::IfSpec(IfSpecData(cond))) => {
if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {
Expand Down Expand Up @@ -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(
Expand Down
Loading