Skip to content

Cover the folding branches in Optimizer, drop dead _debug method - #125

Merged
amol- merged 2 commits into
posit-dev:mainfrom
darrenhuai:test/optimizer-fold-case-and-zeros-coverage
Aug 11, 2026
Merged

Cover the folding branches in Optimizer, drop dead _debug method#125
amol- merged 2 commits into
posit-dev:mainfrom
darrenhuai:test/optimizer-fold-case-and-zeros-coverage

Conversation

@darrenhuai

Copy link
Copy Markdown
Contributor

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 after return expr in 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

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%.
@amol-

amol- commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

_debug was an helper that I use on demand when I need to debug expressions.
More than dropping it we can cover it with a no cover pragma and a comment explaining it's only used during development.

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.
@amol-
amol- merged commit 6d639d6 into posit-dev:main Aug 11, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve test coverage of the translation Optimizer

2 participants