feat: add exception-aware dead-code elimination - #736
Open
nahime0 wants to merge 7 commits into
Open
Conversation
Greptile SummaryThis PR adds exception-type-aware dead-code elimination and integrates it before declaration reachability.
Confidence Score: 4/5The PR is not yet safe to merge because a condition-side caught-variable rebind can still cause DCE to remove a reachable nested catch. Active caught-variable bindings are invalidated only after an enclosing statement and all its nested bodies have been optimized, so catch reachability inside a selected branch can still observe the pre-rebind exception class and delete the runtime-matching handler. Files Needing Attention: src/optimize/control/dce.rs, src/optimize/exception_flow.rs, src/optimize/control/dce/tries.rs
|
| Filename | Overview |
|---|---|
| src/optimize/exception_flow.rs | Adds throwable-domain inference and catch routing, but active caught-variable domains can remain stale while nested branch bodies are optimized. |
| src/optimize/control/dce.rs | Wires caught-binding invalidation into DCE after each statement; its post-statement placement leaves nested-body processing exposed to stale domains. |
| src/optimize/control/dce/tries.rs | Uses exception-flow reachability to remove impossible catches and applies handler-specific guard invalidation. |
| src/optimize/control/dce/writes/finally_paths.rs | Adds path-sensitive finally invalidation and preserves explicitly throwing exit/die argument paths. |
| src/optimize.rs | Constructs and scopes reusable exception-flow analysis alongside existing callable and by-reference analyses. |
| src/pipeline.rs | Integrates exception-aware DCE before declaration reachability and EIR lowering. |
| src/ir_lower/stmt/exceptions.rs | Routes catchless try/finally through runtime handler-based lowering so call-induced throws execute the finalizer. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Checked PHP AST] --> B[Exception-flow analysis]
B --> C[Exception-aware AST DCE]
C --> D[Declaration reachability]
D --> E[EIR lowering]
E --> F[Validated EIR]
Reviews (5): Last reviewed commit: "fix(optimizer): preserve implicit string..." | Re-trigger Greptile
nahime0
force-pushed
the
feat/exception-aware-dce-2
branch
from
August 20, 2026 19:50
ecf0286 to
17d21ce
Compare
nahime0
force-pushed
the
feat/exception-aware-dce-2
branch
from
August 21, 2026 08:11
17d21ce to
2ce318c
Compare
Infer exact and constrained throwable domains from explicit throws, proven operator failures, and fixed-point callable summaries. Route catches in source order and invalidate catch/finally guards only along matching executable paths while preserving conservative dynamic-call barriers.
Exercise exact and constrained catch routing, callable and method throw summaries, nested rethrows, type-specific guard invalidation, conservative dispatch barriers, and exit-only finally paths.
Record the completed roadmap item and describe typed handler routing, caught-variable rethrows, call-aware guard invalidation, and finally-path precision.
Verify that exception-aware DCE removes a disjoint catch before declaration reachability scans its references, allowing a catch-only function declaration to be pruned before EIR lowering.
nahime0
force-pushed
the
feat/exception-aware-dce-2
branch
from
August 21, 2026 14:01
a56842d to
3a38f43
Compare
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.
Summary
Behavior
Throwable = Exception | Errorroot partition.throw $eretains useful type information.exitanddiepaths from finally-entry invalidation because PHP does not execute finally after process termination.Conservative boundaries
The optimizer retains an unknown throwable domain for dynamic or unresolved calls, late-bound/open instance dispatch, external constructors, trait-provided methods or constructors, and operand-dependent runtime failures that cannot be classified exactly. These paths continue to keep potentially matching handlers and their guard invalidations.
Pipeline integration
The post-typecheck optimizer constructs exception summaries from the complete checked program. Exception-aware DCE then removes impossible handlers and non-observable paths. The declaration-reachability pass from #714 runs afterward, reconciles
CheckResult, and prunes functions, classes, methods, externs, and libraries that are no longer reachable before EIR lowering.A dedicated integration regression verifies that a function referenced only by a disjoint catch is removed by declaration reachability after exception-aware DCE drops that handler.
Tests
cargo buildcargo test --test codegen_tests dead_code_elimination::tries- 51 passedcargo test --lib optimize::tests::dce::tries- 17 passedcargo test --test codegen_tests declaration_reachability- 42 passedcargo test --lib optimize::reachability- 74 passedrustfmt --checkandgit diff --checkCI remains responsible for the complete macOS AArch64, Linux AArch64, and Linux x86_64 matrix.