fix(treeshake): preserve side-effect-free spread arguments in manual-pure chains#10432
Merged
Merged
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
Merging this PR will not alter performance
Comparing Footnotes
|
hyfdev
approved these changes
Jul 24, 2026
Member
Merge activity
|
…pure chains (#10432) Follow-up to #10427. #10427 restored the eagerly-evaluated child effects of manual-pure chains, but its eager-child walk maps *every* spread argument to an unknown side effect. So a manual-pure chain wrapping a statically-safe spread — `make(...[]).value`, `make(...'').value`, `make(...[])()` — is now retained wholesale, even though spreading an array, string, or template literal only runs built-in iterators. Rollup drops these. ## Fix Surface spread arguments distinctly from plain eager children (new `EagerChild` enum) and analyze them with `analyze_spread_argument`, mirroring oxc's `Argument::may_have_side_effects`: - array / string / template-literal operands are analyzed through the (oxc-gated) expression analyzer, so a side-effectful element (`make(...[effect()])`) or a nested spread (`make(...[...x])`) still retains the statement; - any other operand stays conservatively unknown, since evaluating or iterating it may run a user-defined `Symbol.iterator`. ## Tests New unit test `test_manual_pure_chains_drop_side_effect_free_spreads` covers both directions: safe literal spreads become removable, while effectful or opaque spreads stay retained — including the nested-spread (`...[...x]`) and bare-identifier (`...x`) cases that must not under-retain.
graphite-app
Bot
force-pushed
the
fix/manual-pure-safe-spreads
branch
from
July 24, 2026 06:08
1578552 to
f9c87c2
Compare
graphite-app Bot
pushed a commit
that referenced
this pull request
Jul 25, 2026
…move matrix to unit tests (#10436) Follow-up to #10427 / #10432 (both merged). There's exactly one JS-side `manualPureFunctions` test — the `manual-pure-functions` fixture (added in #10427). It re-tested the retain/remove behavior matrix that the Rust `stmt_eval_analyzer` unit tests already own. A JS fixture only needs to smoke-test that the option is wired through the pipeline; the exhaustive behavior belongs in fast, precise Rust unit tests. ## Changes - **Fixture → minimal smoke test.** `main.js` is now a single case: a listed function's call (`` styled.div`...` ``) is dropped, leaving just `import "styled-components";`. That alone proves the `manualPureFunctions` option reaches the pipeline — without it, the call would be retained. Snapshot regenerated against a fresh debug build. - **Rust unit test.** `test_manual_pure_chains_without_eager_children_are_side_effect_free` covers the removed shapes (`make.div`, `` make.div`x` ``, `make?.div()`, `make()()`, `make().div()`) that previously had end-to-end-only coverage. The retained-child and spread matrices were already unit-tested (`test_manual_pure_chains_keep_eager_child_side_effects`, `test_manual_pure_chains_drop_side_effect_free_spreads`). Test-only; no behavior change.
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.
Follow-up to #10427.
#10427 restored the eagerly-evaluated child effects of manual-pure chains, but its eager-child walk maps every spread argument to an unknown side effect. So a manual-pure chain wrapping a statically-safe spread —
make(...[]).value,make(...'').value,make(...[])()— is now retained wholesale, even though spreading an array, string, or template literal only runs built-in iterators. Rollup drops these.Fix
Surface spread arguments distinctly from plain eager children (new
EagerChildenum) and analyze them withanalyze_spread_argument, mirroring oxc'sArgument::may_have_side_effects:make(...[effect()])) or a nested spread (make(...[...x])) still retains the statement;Symbol.iterator.Tests
New unit test
test_manual_pure_chains_drop_side_effect_free_spreadscovers both directions: safe literal spreads become removable, while effectful or opaque spreads stay retained — including the nested-spread (...[...x]) and bare-identifier (...x) cases that must not under-retain.