-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Rename side_effects and implement it everywhere #86675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lukesandberg
wants to merge
6
commits into
simple_side_effect_free_analysis
Choose a base branch
from
use_side_effect_analysis
base: simple_side_effect_free_analysis
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94da85a
Rename side_effects and implement it everywhere
lukesandberg 4ed3a71
simplify the side_effects api by moving the package glob into Ecmascr…
lukesandberg c0abd04
fix a benchmark
lukesandberg 49fff24
clippy
lukesandberg 41a7d5e
integrate into binding_usage_info
lukesandberg f544707
fix a name
lukesandberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawEcmascriptModuleincorrectly marks itself as side-effect-free. This can cause tree-shaking to incorrectly remove the module, even though it may contain side effects. The comment "Is this correct?" indicates the developer was uncertain about this decision.View Details
Analysis
RawEcmascriptModule incorrectly marks itself as side-effect-free
What fails:
RawEcmascriptModule.side_effects()incorrectly returnsModuleSideEffects::SideEffectFree, causing tree-shaking to remove module evaluation even when the module may contain side effects. This affects prebundled code likenext/dist/compiled/next-devtools/index.jswhich may have initialization, global state modifications, or other side effects at module load time.How to trigger it: When tree-shaking is enabled with
TreeShakingMode::ModuleFragmentsand a module imports aRawEcmascriptModulewithModulePart::Evaluation, the module's evaluation is completely ignored due to the falseSideEffectFreemarking. This occurs in the reference resolution code inturbopack/crates/turbopack-ecmascript/src/references/esm/base.rs:Result: The module's evaluation is marked as
Ignore, meaning any side effects that should execute when the module is imported are skipped entirely.Expected:
RawEcmascriptModuleshould conservatively mark itself asSideEffectful, consistent with the comparableRawModuleimplementation inturbopack/crates/turbopack-core/src/raw_module.rs. A raw module can contain arbitrary JavaScript code with side effects (initialization, event listeners, global state modifications), even without imports/requires, and those effects should not be elided by tree-shaking.Fix applied: Changed
crates/next-core/src/raw_ecmascript_module.rsline 104 fromModuleSideEffects::SideEffectFreetoModuleSideEffects::SideEffectfulto match the pattern used byRawModuleand remove the developer's uncertain comment "Is this correct?".