feat(ecmascript): add known-globals to side-effect-free property reads#20212
feat(ecmascript): add known-globals to side-effect-free property reads#20212graphite-app[bot] merged 1 commit intomainfrom
Conversation
638deef to
f0db348
Compare
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
Ports Rolldown-style “known globals” knowledge into Oxc’s side-effect detection so the minifier/DCE can treat certain global identifier accesses and global property reads as side-effect-free, enabling more aggressive reductions and updating tests accordingly.
Changes:
- Mark accesses to a large set of known global identifiers as side-effect-free (and add support for known global property reads + select 3-level chains).
- Add
property_write_side_effects()to the side-effects context and implementMayHaveSideEffectsforAssignmentExpression/UpdateExpression. - Update and extend minifier test expectations to reflect improved side-effect detection.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_ecmascript/src/side_effects/expressions.rs | Adds known-global identifier/property handling and new assignment/update side-effect logic. |
| crates/oxc_ecmascript/src/side_effects/context.rs | Introduces property_write_side_effects() hook on the side-effects context. |
| crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs | Adds tests for known globals/property reads/deep chains and updates expectations. |
| crates/oxc_minifier/tests/peephole/substitute_alternate_syntax.rs | Updates expected outputs enabled by improved purity detection. |
| crates/oxc_minifier/tests/peephole/oxc.rs | Updates integration expectation based on new optimizations. |
| crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs | Updates keep-names related expectations for inlining behavior. |
Merging this PR will degrade performance by 6.3%
Performance Changes
Comparing Footnotes
|
1f9ac5c to
3089aca
Compare
3089aca to
cacff2f
Compare
8172e82 to
7857402
Compare
4c397f0 to
4d3b18e
Compare
7857402 to
cb8b1f6
Compare
4d3b18e to
4d6a096
Compare
cb8b1f6 to
139ab68
Compare
4d6a096 to
d12655d
Compare
Merge activity
|
#20212) ## Summary close: #13067 Part of #19673 Depends on #20217. Port known-globals lists from Rolldown to Oxc's side-effect detection: - **Global identifiers** (Math, Array, console, DOM classes, etc.) are now considered side-effect-free to access via `is_known_global_identifier`, matching Rolldown's `GLOBAL_IDENT` set - **Property reads** like `Math.PI`, `console.log`, `Object.keys` are considered side-effect-free via `is_known_global_property` - **3-level chains** like `Object.prototype.hasOwnProperty` are supported via `is_known_global_property_deep` ## Test plan - [x] Added tests for known global identifiers (Math, Array, Object, console, etc.) - [x] Added tests for known global property reads (Math.PI, Object.keys, etc.) - [x] Added tests for 3-level chains (Object.prototype.hasOwnProperty, etc.) - [x] Existing minifier test expectations updated for improved side-effect detection - [x] All existing tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code)
c4c894c to
e7163b6
Compare
### 🚀 Features - e7163b6 ecmascript: Add known-globals to side-effect-free property reads (#20212) (Dunqing) - 139ab68 ecmascript: Add `property_write_side_effects` to `MayHaveSideEffectsContext` (#20217) (Dunqing) ### 🐛 Bug Fixes - 78c264a parser: Fix conditional expressions with arrow-function alternates in TS (#20356) (camc314) - 5c97b14 minifier: Recognize object spread of object literals as side-effect-free (#20299) (Boshen) - 1ff5c1d transformer/typescript: Rewrite extensions in dynamic `import()` expressions (#20121) (Sverre Johansen) - 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen) - ade14d4 ecmascript: Enhance side-effect detection for classes, TypedArrays, computed members, and spread (#20213) (Dunqing) ### ⚡ Performance - 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen) ### 📚 Documentation - e4aa5b5 parser/napi, linter/plugins: Add JSDoc comments to raw transfer constants (#20286) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Summary
close: #13067
Part of #19673
Depends on #20217.
Port known-globals lists from Rolldown to Oxc's side-effect detection:
is_known_global_identifier, matching Rolldown'sGLOBAL_IDENTsetMath.PI,console.log,Object.keysare considered side-effect-free viais_known_global_propertyObject.prototype.hasOwnPropertyare supported viais_known_global_property_deepTest plan
🤖 Generated with Claude Code