Skip to content

refactor(minifier): route all peephole mutations through typed helpers#23196

Merged
graphite-app[bot] merged 1 commit into
mainfrom
minifier-stack/mutation-helpers
Jun 15, 2026
Merged

refactor(minifier): route all peephole mutations through typed helpers#23196
graphite-app[bot] merged 1 commit into
mainfrom
minifier-stack/mutation-helpers

Conversation

@Dunqing

@Dunqing Dunqing commented Jun 10, 2026

Copy link
Copy Markdown
Member

Developed with AI assistance (Claude Code); reviewed, tested, and benchmarked by the contributor.

Summary

Replaces the ~190 manual ctx.state.changed = true writes scattered across crates/oxc_minifier/src/peephole/ with typed mutation helpers on MinifierTraverseCtx (replace_expression, replace_statement, replace_assignment_target_property, replace_property_key, replace_for_statement_left, drop_expression, drop_statement, drop_class_element, notice_change).

The mutation signal itself becomes a private mutated: bool on MinifierState, readable only via take_mutated() (read-and-reset in a single call) — the compiler now enforces that the fixed-point loop's signal can only be set by the helpers and only consumed by the loop driver.

"Forgot to mark the loop dirty" — the bug pattern behind #22722 and #22552 — becomes structurally hard to write. The migration also carries the latent silent-mutation fixes surfaced by routing every mutation through a helper (missed *slot = … writes in remove_unused_expression, convert_to_dotted_properties, minimize_statements, and field-write bypass sites), plus idempotency gates in try_fold_if so the typed helpers don't block fixed-point convergence.

This is stage 1 of 2 re-cutting the approach prototyped in #22736; the incremental scoping refresh stacks on top.

Verification

  • cargo test -p oxc_minifier — 509 pass
  • just minsizebit-identical output across the entire size-test corpus (this PR is a pure refactor)
  • cargo coverage -- minifier — conformance unchanged
  • clippy (all features/targets) clean
  • allocs_minifier.snap: small arena-only deltas (+0.02–0.08%) from helper call-site construction patterns; sys allocs unchanged

@github-actions github-actions Bot added the A-minifier Area - Minifier label Jun 10, 2026

Dunqing commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq

codspeed-hq Bot commented Jun 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 52 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing minifier-stack/mutation-helpers (8e9ace2) with main (af1b897)2

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (7cafe3b) during the generation of this report, so af1b897 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Dunqing Dunqing force-pushed the minifier-stack/mutation-helpers branch 3 times, most recently from a4fe763 to 8e9ace2 Compare June 15, 2026 09:04
@graphite-app graphite-app Bot added the 0-merge Merge with Graphite Merge Queue label Jun 15, 2026
@graphite-app

graphite-app Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Merge activity

#23196)

> Developed with AI assistance (Claude Code); reviewed, tested, and benchmarked by the contributor.

## Summary

Replaces the ~190 manual `ctx.state.changed = true` writes scattered across `crates/oxc_minifier/src/peephole/` with typed mutation helpers on `MinifierTraverseCtx` (`replace_expression`, `replace_statement`, `replace_assignment_target_property`, `replace_property_key`, `replace_for_statement_left`, `drop_expression`, `drop_statement`, `drop_class_element`, `notice_change`).

The mutation signal itself becomes a private `mutated: bool` on `MinifierState`, readable only via `take_mutated()` (read-and-reset in a single call) — the compiler now enforces that the fixed-point loop's signal can only be set by the helpers and only consumed by the loop driver.

"Forgot to mark the loop dirty" — the bug pattern behind #22722 and #22552 — becomes structurally hard to write. The migration also carries the latent silent-mutation fixes surfaced by routing every mutation through a helper (missed `*slot = …` writes in `remove_unused_expression`, `convert_to_dotted_properties`, `minimize_statements`, and field-write bypass sites), plus idempotency gates in `try_fold_if` so the typed helpers don't block fixed-point convergence.

This is stage 1 of 2 re-cutting the approach prototyped in #22736; the incremental scoping refresh stacks on top.

## Verification

- `cargo test -p oxc_minifier` — 509 pass
- `just minsize` — **bit-identical output** across the entire size-test corpus (this PR is a pure refactor)
- `cargo coverage -- minifier` — conformance unchanged
- clippy (all features/targets) clean
- `allocs_minifier.snap`: small arena-only deltas (+0.02–0.08%) from helper call-site construction patterns; sys allocs unchanged
@graphite-app graphite-app Bot force-pushed the minifier-stack/mutation-helpers branch from 8e9ace2 to 09176f8 Compare June 15, 2026 15:07
@graphite-app graphite-app Bot merged commit 09176f8 into main Jun 15, 2026
29 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jun 15, 2026
@graphite-app graphite-app Bot deleted the minifier-stack/mutation-helpers branch June 15, 2026 15:12
camc314 pushed a commit that referenced this pull request Jul 3, 2026
#23196)

> Developed with AI assistance (Claude Code); reviewed, tested, and benchmarked by the contributor.

## Summary

Replaces the ~190 manual `ctx.state.changed = true` writes scattered across `crates/oxc_minifier/src/peephole/` with typed mutation helpers on `MinifierTraverseCtx` (`replace_expression`, `replace_statement`, `replace_assignment_target_property`, `replace_property_key`, `replace_for_statement_left`, `drop_expression`, `drop_statement`, `drop_class_element`, `notice_change`).

The mutation signal itself becomes a private `mutated: bool` on `MinifierState`, readable only via `take_mutated()` (read-and-reset in a single call) — the compiler now enforces that the fixed-point loop's signal can only be set by the helpers and only consumed by the loop driver.

"Forgot to mark the loop dirty" — the bug pattern behind #22722 and #22552 — becomes structurally hard to write. The migration also carries the latent silent-mutation fixes surfaced by routing every mutation through a helper (missed `*slot = …` writes in `remove_unused_expression`, `convert_to_dotted_properties`, `minimize_statements`, and field-write bypass sites), plus idempotency gates in `try_fold_if` so the typed helpers don't block fixed-point convergence.

This is stage 1 of 2 re-cutting the approach prototyped in #22736; the incremental scoping refresh stacks on top.

## Verification

- `cargo test -p oxc_minifier` — 509 pass
- `just minsize` — **bit-identical output** across the entire size-test corpus (this PR is a pure refactor)
- `cargo coverage -- minifier` — conformance unchanged
- clippy (all features/targets) clean
- `allocs_minifier.snap`: small arena-only deltas (+0.02–0.08%) from helper call-site construction patterns; sys allocs unchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant