Cover the folding branches in Optimizer, drop dead _debug method - #125
Merged
amol- merged 2 commits intoAug 11, 2026
Merged
Conversation
optimizer.py was sitting at 86% because fold_case had no tests at all (the whole method, not just the branches called out in posit-dev#121), and fold_zeros only had subtract covered - multiply and add zero folding were completely untested. Added tests for each folding method's disabled-optimizer passthrough, the actual folding paths, and the various "nothing to fold" fallbacks, including the non-literal IF/ELSE case that's deliberately left unfolded because of the postgresql FIXME. Also removed _debug: nothing calls it except itself, and now that it's gone the unreachable branch after `return expr` in fold_case's boolean-cast case doesn't need a decision either - it just wasn't part of the count anymore once I checked, since the compiler drops statements that follow an unconditional return in the same block. optimizer.py coverage: 86% -> 100%.
Collaborator
|
|
amol- uses it on demand while working on the optimizer, so mark it with a no cover pragma (matching types.py) and say in the docstring why it isn't tested.
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.
optimizer.py was at 86% because fold_case had no tests at all - not just the two ranges called out in the issue, the whole method - and fold_zeros only had its subtract path covered, multiply and add zero-folding were completely untested.
Added tests for each folding method's disabled-optimizer passthrough, the actual folding paths, and the various "nothing to fold" fallbacks, including the non-literal IF/ELSE case that's deliberately left unfolded because of the postgresql FIXME on that branch.
Also removed
_debug, since nothing calls it except itself. Once it's gone the unreachable branch afterreturn exprin fold_case's boolean-cast case doesn't need a separate decision either - it's not part of the statement count at all once you check, the compiler drops code that follows an unconditional return in the same block.optimizer.py coverage: 86% -> 100%. Ran the full suite locally, ruff format/check, and mypy, all clean.
Closes #121