refactor(minifier): make DCE remove more code to align with rollup#12427
Merged
Conversation
Contributor
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
aca9e0a to
687e708
Compare
CodSpeed Instrumentation Performance ReportMerging #12427 will not alter performanceComparing Summary
|
Member
Author
Merge activity
|
687e708 to
1cf08c0
Compare
Dunqing
added a commit
that referenced
this pull request
May 26, 2026
…places an identifier Before the minifier's incremental-scoping refactor (#22736), the per-pass `LiveUsageCollector` walked the live program at `exit_program` and rebuilt `Scoping::resolved_references` from scratch. That walk silently masked the fact that `ReplaceGlobalDefines` never told `Scoping` about the identifier references it was replacing — the next minifier pass would simply recompute them and find that the replaced identifier had no surviving occurrences. With the LiveUsageCollector gone, only references that the minifier itself drops via `replace_*`/`drop_*` helpers are pruned. References that callers drop before `dead_code_elimination_with_scoping` get to run are now visible as stale entries in `resolved_references`, and `symbol_is_unused` returns `false` for symbols whose every textual occurrence has been replaced. Concretely, the existing `replace_global_defines::declare_const` integration test (added by #12427 to align with rollup) fails: the test expects the `declare const IS_PROD: boolean;` line to be DCE'd after every reference to `IS_PROD` is replaced with `true`, but the leaked references keep DCE from seeing IS_PROD as unused. The fix delegates reference deletion to the plugin: when `replace_identifier_define_impl` returns a replacement value, the caller captures the old identifier's `(reference_id, symbol_id, name)` BEFORE the replacement and calls `Scoping::delete_reference` (resolved case) or `delete_root_unresolved_reference` (truly global case) only AFTER the AST mutation actually commits. The split matters at the assignment-target site — `replace_define_with_assignment_expr` may bail when the replacement value isn't a valid LHS (e.g. `IS_PROD = 0` with define `IS_PROD -> true` would need `true = 0`, which `assignment_target_from_expr` rejects); the reference must stay in that case. New test `declare_const_assignment_target_bailout` pins the bail path.
Dunqing
added a commit
that referenced
this pull request
Jun 9, 2026
…places an identifier Before the minifier's incremental-scoping refactor (#22736), the per-pass `LiveUsageCollector` walked the live program at `exit_program` and rebuilt `Scoping::resolved_references` from scratch. That walk silently masked the fact that `ReplaceGlobalDefines` never told `Scoping` about the identifier references it was replacing — the next minifier pass would simply recompute them and find that the replaced identifier had no surviving occurrences. With the LiveUsageCollector gone, only references that the minifier itself drops via `replace_*`/`drop_*` helpers are pruned. References that callers drop before `dead_code_elimination_with_scoping` get to run are now visible as stale entries in `resolved_references`, and `symbol_is_unused` returns `false` for symbols whose every textual occurrence has been replaced. Concretely, the existing `replace_global_defines::declare_const` integration test (added by #12427 to align with rollup) fails: the test expects the `declare const IS_PROD: boolean;` line to be DCE'd after every reference to `IS_PROD` is replaced with `true`, but the leaked references keep DCE from seeing IS_PROD as unused. The fix delegates reference deletion to the plugin: when `replace_identifier_define_impl` returns a replacement value, the caller captures the old identifier's `(reference_id, symbol_id, name)` BEFORE the replacement and calls `Scoping::delete_reference` (resolved case) or `delete_root_unresolved_reference` (truly global case) only AFTER the AST mutation actually commits. The split matters at the assignment-target site — `replace_define_with_assignment_expr` may bail when the replacement value isn't a valid LHS (e.g. `IS_PROD = 0` with define `IS_PROD -> true` would need `true = 0`, which `assignment_target_from_expr` rejects); the reference must stay in that case. New test `declare_const_assignment_target_bailout` pins the bail path.
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.
No description provided.