Repository navigation
fix: sort dynamic entires with topological order before tree shake. - #4694
Merged
Merged
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
IWANABETHATGUY
force-pushed
the
05-27-fix_4682
branch
2 times, most recently
from
May 27, 2025 09:55
e4336a7 to
8ad35d5
Compare
Contributor
Benchmarks Rust |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the tree shaking issue by sorting dynamic entries using topological order with petgraph and tarjan_scc, ensuring that each dynamic entry is included before its descendant dynamic entries. Additionally, snapshot tests and dependency adjustments have been updated to support the new ordering mechanism.
- Updated cspell.json to add new terms
- Modified tests snapshots for dynamic/static module integration
- Enhanced dynamic entry ordering in include_statements.rs via a new topological sort and dynamic entry graph construction
- Added petgraph dependency in Cargo.toml and adjusted README accordingly
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cspell.json | Added new spellings ("petgraph", "tarjan") to the list |
| crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap | Updated snapshot to reflect new dynamic entry ordering |
| crates/rolldown/tests/rolldown/tree_shaking/issue_4682/*.js | Added additional test modules for dynamic and static tree shaking |
| crates/rolldown/src/stages/link_stage/tree_shaking/include_statements.rs | Introduced topological sorting of dynamic entries and cycle detection |
| Cargo.toml and crates/rolldown/Cargo.toml | Added petgraph dependency |
| README.md | Minor documentation update by removing placeholder comments |
Comments suppressed due to low confidence (1)
crates/rolldown/src/stages/link_stage/tree_shaking/include_statements.rs:95
- The variable name 'cycled_idx' is ambiguous as it represents a set of dynamic entries involved in cycles. Consider renaming it to 'cycled_entries' for clarity.
let cycled_idx = self.get_dynamic_entries_included_order(&mut dynamic_entries);
…tements.rs Co-authored-by: Copilot <[email protected]>
IWANABETHATGUY
force-pushed
the
05-27-fix_4682
branch
from
May 27, 2025 10:17
10d96f9 to
1667770
Compare
hyfdev
approved these changes
May 27, 2025
hyfdev
added a commit
that referenced
this pull request
Nov 19, 2026
Modules reached only by dead `import()` calls are still emitted when they form a cycle through those calls.
This PR drops them, as rolldown already does when there is no cycle.
```js
// entry.mjs
import * as SDK from './sdk.mjs';
console.log(typeof SDK.used);
// sdk.mjs
export function used() { return 1; }
export function deadA() { return import('./a.mjs'); }
export function deadB() { return import('./b.mjs'); }
// a.mjs (b.mjs is the same, with `b`)
import { used } from './sdk.mjs';
export function a() { return used(); }
```
By default, main also emits `a-*.js` and `b-*.js`, which nothing imports, and `entry.js` gets an extra export for them.
With `output: { file: 'out.js', codeSplitting: false }`, main fails with `When building multiple chunks, the "output.dir" option must be used`.
With this PR, both builds emit only the entry file, which prints `function`.
Tree-shaking keeps every dynamic import target in an `import()` cycle without checking whether an `import()` that reaches it is still included.
That exception dates from #4694, when dynamic entries were checked in a single pass.
This PR removes it.
A dynamic entry is now checked again each time tree-shaking keeps a statement with an `import()` of it.
In a cycle, a top-level `import()` whose result is unused still keeps its target, as on `main`.
Dropping it can delay when the target runs.
Rollup 4.68.2 also emits one file in both modes.
The example in the issue body already builds to one file on main.
Fixes #11001
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.

Description
no entry found for keypanic atcrates\rolldown\src\module_finalizers\scope_hoisting\impl_visit_mut.rs:422:85#4682