fix: tryEagerEval does not force unevaluated lazy thunks#949
Merged
stephenamar-db merged 2 commits intoJun 18, 2026
Conversation
Collaborator
|
rebase |
6c87e96 to
ba16bd2
Compare
Motivation: The resolveAsDouble optimization called binding.value on scope bindings, which forced lazy thunk evaluation even when the result would be discarded (e.g., dead branches). This violated Jsonnet's lazy evaluation semantics — side effects like std.trace or error in unused bindings would execute when they should not. Modification: In resolveAsDouble, pattern match on the binding directly instead of calling binding.value. Only Val.Num (already evaluated numbers) are used; unevaluated lazy thunks return NaN (skip), preserving lazy semantics. Result: `local a = error "x"; local b = a + 1; if false then b else 0` now returns 0 without evaluating 'a', matching go-jsonnet and jrsonnet behavior.
ba16bd2 to
039bb95
Compare
stephenamar-db
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
tryEagerEvaloptimization forced evaluation of lazy thunks by callingbinding.valueon scope bindings, violating Jsonnet's lazy evaluation semantics. Unused bindings with side effects (e.g.,error,std.trace) were evaluated even when their results were never needed.Modification
resolveAsDoubleto pattern-match on the binding directly instead of forcing.valueVal.Numbindings are used for eager evaluationDouble.NaN(skip optimization), preserving lazy semanticsResult
local a = error "should not be evaluated"; local b = a + 1; if false then b else 0now correctly returns0without evaluatinga, matching go-jsonnet and jrsonnet lazy evaluation semantics.References
local f(x) = x; local y = f(error "boom"); if true then 42 else y424242✅local a = error "x"; if false then a + 1 else 0000✅0✅