Commit d07d522
Optimize redundant bool check (#7176)
* Add compile_bool_op_inner and optimize nested opposite-operator BoolOps to avoid redundant __bool__ calls
When a nested BoolOp has the opposite operator (e.g., `And` inside `Or`),
the inner BoolOp's short-circuit exits are redirected to skip the outer
BoolOp's redundant truth test. This avoids calling `__bool__()` twice on
the same value (e.g., `Test() and False or False` previously called
`Test().__bool__()` twice instead of once).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add snapshot test for nested BoolOp bytecode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add runtime test for redundant __bool__ check (issue #3567)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Apply clippy and rustfmt
* Apply ruff format
* Refactor compile_bool_op: extract emit_short_circuit_test and unify with compile_bool_op_inner
Reduce code duplication by:
- Extracting the repeated Copy + conditional jump pattern into emit_short_circuit_test
- Merging compile_bool_op and compile_bool_op_inner into a single
compile_bool_op_with_target with an optional short_circuit_target parameter
- Keeping compile_bool_op as a thin wrapper for the public interface
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Relocate redundant __bool__ check test snippet
* Update extra_tests/snippets/syntax_short_circuit_bool.py
* Fix assertion in syntax_short_circuit_bool
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>1 parent f0f3c9c commit d07d522
File tree
3 files changed
+79
-21
lines changed- crates/codegen/src
- snapshots
- extra_tests/snippets
3 files changed
+79
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6611 | 6611 | | |
6612 | 6612 | | |
6613 | 6613 | | |
6614 | | - | |
| 6614 | + | |
| 6615 | + | |
6615 | 6616 | | |
| 6617 | + | |
| 6618 | + | |
| 6619 | + | |
| 6620 | + | |
| 6621 | + | |
| 6622 | + | |
| 6623 | + | |
| 6624 | + | |
| 6625 | + | |
| 6626 | + | |
| 6627 | + | |
6616 | 6628 | | |
| 6629 | + | |
6617 | 6630 | | |
6618 | 6631 | | |
6619 | | - | |
6620 | | - | |
6621 | | - | |
6622 | | - | |
6623 | | - | |
6624 | | - | |
6625 | | - | |
6626 | | - | |
6627 | | - | |
6628 | | - | |
6629 | | - | |
6630 | | - | |
6631 | | - | |
6632 | | - | |
6633 | | - | |
6634 | | - | |
6635 | | - | |
6636 | | - | |
6637 | | - | |
6638 | | - | |
| 6632 | + | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
| 6636 | + | |
| 6637 | + | |
| 6638 | + | |
| 6639 | + | |
| 6640 | + | |
| 6641 | + | |
| 6642 | + | |
| 6643 | + | |
| 6644 | + | |
| 6645 | + | |
| 6646 | + | |
| 6647 | + | |
| 6648 | + | |
6639 | 6649 | | |
6640 | 6650 | | |
| 6651 | + | |
| 6652 | + | |
6641 | 6653 | | |
6642 | 6654 | | |
6643 | 6655 | | |
| |||
6647 | 6659 | | |
6648 | 6660 | | |
6649 | 6661 | | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
6650 | 6676 | | |
6651 | 6677 | | |
6652 | 6678 | | |
| |||
9006 | 9032 | | |
9007 | 9033 | | |
9008 | 9034 | | |
| 9035 | + | |
| 9036 | + | |
| 9037 | + | |
| 9038 | + | |
| 9039 | + | |
| 9040 | + | |
| 9041 | + | |
| 9042 | + | |
| 9043 | + | |
9009 | 9044 | | |
9010 | 9045 | | |
9011 | 9046 | | |
| |||
Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments