Skip to content

Preserve Boolean call arguments and bounded OR chains - #25

Closed
EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/boolean-call-argument-values
Closed

EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/boolean-call-argument-values

Conversation

@EiNSTeiN-

Copy link
Copy Markdown
Contributor

I am opening this PR to keep a Boolean expression as one call argument and preserve its operand evaluation order. The code below currently decompiles incorrectly in Python 3.14:

def select(call, before, first, second, last, after):
    return call(before(), (first() and second()) or last(), after())

The current output adds an argument and evaluates first() twice:

def select(call, before, first, second, last, after):
    return call(before(), first(), first() and second() or last(), after())

The value-chain recognizer leaves the initial COPY-retained operand on the stack after pushing the reconstructed expression. A later call then sees an extra argument, or consumes its callee/NULL prefix incorrectly. This change consumes the matching retained operand while preserving unrelated argument and callee entries, including an earlier argument with the same value.

The same reconstruction also handles multiple OR tails:

def alternatives(a, b, c, d, e):
    return bool((a and b) or c or d or e)

The current parser can emit None(a and (b or bool), c or d or e) instead. Each non-final OR operand must prove the same COPY/TO_BOOL/true-jump-to-one-merge protocol and matching discard. Arbitrary branches or different merge targets still fail recognition. The retained operand must be consumed together with this reconstruction so that extending the chain does not corrupt the enclosing call's stack.

Variations include a preceding OR chain, method calls within an operand, storing the expression in a local variable, and other arguments before or after the expression. Pure AND and OR chains continue through their existing paths.

The recognizer applies to Python 3.13+, matching the introduction of TO_BOOL and its COPY-based value-preservation protocol. The Boolean source expressions themselves predate this bytecode layout.

@ejfkdev

ejfkdev commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Merged via consolidated PR #28 (commit e629b6c). Your fix, fixtures, behavior cases and integration test are all included and verified together: real-world corpus 6411/6411, stdlib corpus 528/528, behavior tests green on 3.9-3.14. Thanks for the detailed reports and repros!

@ejfkdev ejfkdev closed this Oct 23, 2026
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.

2 participants