Test that short-circuiting actually short-circuits - #97
Merged
Conversation
`&&`/`||` and the ternary already had laziness tests, but only for the
AST interpreter (test_expr_eval.cpp's RightSideNotEvaluatedWhenShortCircuited
and OnlyChosenBranchEvaluates). The compiled path's own test asserted only
the RESULT -- which an eager compiler computes just as correctly -- so
nothing would have failed if the JumpIfFalse/JumpIfTrue the compiler emits
around the right operand or the untaken branch ever went away. The list
comprehensions' `if`/`if-else` clauses had the same gap in both engines:
their tests check the resulting list, which an eager implementation also
gets right.
Six tests that close it, each running a marker echo() from inside the
branch that must never run and asserting the exact echo output, so an
extra evaluation shows up as an extra line:
BytecodeCompiler.ShortCircuitDoesNotEvaluateRightOperandCompiled
BytecodeCompiler.TernaryOnlyEvaluatesChosenBranchCompiled
ListComprehension.ForIfSkipsBodyWhenConditionFails{Interpreted,Compiled}
ListComprehension.ForIfElseEvaluatesOnlyTheChosenBranch{Interpreted,Compiled}
Verified non-vacuous by mutation: inverting the VM's jumps in
bytecode_compiler.cpp fails all four compiled tests (and leaves the
interpreted ones passing), while making expr_eval.cpp's ListCompIf/
ListCompIfElse cases eager fails both interpreted ones. That second run is
also what showed the interpreted variants need an explicit ScopedVm(false)
-- a top-level list comprehension compiles by default, so without it they
were re-testing the VM.
No behavior change; the evaluator was already correct on all six.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What
&&/||and the ternary already had laziness tests, but only for the AST interpreter (test_expr_eval.cpp'sRightSideNotEvaluatedWhenShortCircuitedandOnlyChosenBranchEvaluates). The compiled path's own test (TernaryAndShortCircuitLogicalOps) asserts only the result — which an eager compiler computes just as correctly — so nothing would have failed if theJumpIfFalse/JumpIfTruethe compiler emits around the right operand or the untaken branch ever went away.The list comprehensions'
if/if-elseclauses had the same gap in both engines: their tests check the resulting list, which an eager implementation also gets right.Tests added
Each runs a marker
echo()from inside the branch that must never run, and asserts the exact echo output — an extra evaluation shows up as an extra line.BytecodeCompiler.ShortCircuitDoesNotEvaluateRightOperandCompiled&&and||, both directionsBytecodeCompiler.TernaryOnlyEvaluatesChosenBranchCompiledListComprehension.ForIfSkipsBodyWhenConditionFails{Interpreted,Compiled}ListComprehension.ForIfElseEvaluatesOnlyTheChosenBranch{Interpreted,Compiled}Verified non-vacuous by mutation
bytecode_compiler.cppexpr_eval.cpp'sListCompIf/ListCompIfElsecases eagerThat second run is also what showed the interpreted variants need an explicit
ScopedVm(false)— a top-level list comprehension compiles by default, so without it they were re-testing the VM.Result
No behavior change; the evaluator was already correct on all six cases. Full suite passes (865 tests), and again under
OSCAD_BYTECODE_VM=0and=1.Version bumped 0.32.0 → 0.32.1.
🤖 Generated with Claude Code