Skip to content

Add dead branch removal - #149

Merged
dflook merged 18 commits into
mainfrom
dead-branch-removal
Jul 31, 2026
Merged

Add dead branch removal#149
dflook merged 18 commits into
mainfrom
dead-branch-removal

Conversation

@dflook

@dflook dflook commented Jul 26, 2026

Copy link
Copy Markdown
Owner
  • Add constant folding for BoolOp and Compare nodes
  • Add RemoveDeadBranches transform to safely remove dead If branches and in-line the surviving branch, only when it doesn't change program behaviour
  • Re-write RemoveDebug transform to explicitly mark debug as False, and rely on the dead branch removal to trim it

This fixes some problems with the previous RemoveDebug transform:

  • The whole branch was removed without accounting for how it affects enclosing function symbol table
  • The else branch would be removed along with the body

Also fixes SuiteTransformer not transforming some suites like exception handler blocks.

dflook added 18 commits July 26, 2026 22:44
- Add constant folding for BoolOp and Compare nodes
- Add RemoveDeadBranches transform to safely remove dead If branches and in-line the surviving branch, only when it doesn't change program behaviour
- Re-write RemoveDebug transform to explicitly mark __debug__ as False, and rely on the dead branch removal to trim it

This fixes some problems with the previous RemoveDebug transform:
- The whole branch was removed with accounting for how it affects enclosing function symbol table
- The else branch would be removed along with the body

Also fixes SuiteTransformer not transforming some suites like exception handler blocks.
Show larger than base for all python versions
Show time delta for slowest entries.
covering new changes:
- bool folding
- SuiteTransformer descending into more blocks
- RemoveDebug changes
- RemoveDeadBranches
Even with a fixed hash seed renaming would vary between runs
Exploring a namespace down to other namespace nodes isn't quite enough, some namespace nodes have child nodes in their parent namespace.
The problematic one here is NamedExpr targets inside a comprehension.

Also enhances RemoveDeadBranches to fully remove orelse suites if they only consist of the literal zero expression placeholder.
This is through evaluation of minifier internal values - not used fixable.
When DeprecationWarnings become errors (through interpreter options, or future Python versions), then it'll just stop folding.
Until then we can do it, just swallow the warning.
It generates a DeprecationWarning since 3.12
@dflook
dflook merged commit 2c6d059 into main Jul 31, 2026
75 checks passed
@dflook
dflook deleted the dead-branch-removal branch July 31, 2026 16:20
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.

1 participant