Skip to content

feat(semantic): extend no_side_effects to include empty functions#20344

Draft
Dunqing wants to merge 1 commit intomainfrom
feat/semantic-empty-fn-no-side-effects
Draft

feat(semantic): extend no_side_effects to include empty functions#20344
Dunqing wants to merge 1 commit intomainfrom
feat/semantic-empty-fn-no-side-effects

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Mar 13, 2026

Summary

  • Mark functions with empty bodies and simple parameters as side-effect-free in Scoping::no_side_effects
  • Covers function declarations, function expressions, and arrow functions (non-expression body)
  • Allows Rolldown to use scoping.no_side_effects() as the single source of truth, eliminating its separate SymbolRefFlags::SideEffectsFreeFunction flag

Details

"Empty and simple params" means:

  • Body has no statements and no directives
  • All params are BindingIdentifier with no initializer (uses existing IsSimpleParameterList trait)
  • No rest parameter
  • Arrow functions must not have expression body (() => expr excluded)

Async and generator empty functions are included, consistent with esbuild and Rollup behavior.

Closes #20290

Test plan

  • Added positive tests for empty function declarations, expressions, arrows, async, generators
  • Added negative tests for non-empty bodies, non-simple parameters
  • Updated existing test expectations that now correctly remove calls to empty functions
  • cargo test -p oxc_minifier passes (470 tests)
  • cargo test -p oxc_semantic --tests passes
  • Clippy clean

🤖 Generated with Claude Code

Mark functions with empty bodies and simple parameters (no destructuring,
no defaults, no rest) as side-effect-free in `Scoping::no_side_effects`.
This allows Rolldown to use `scoping.no_side_effects()` as the single
source of truth, eliminating its separate `SideEffectsFreeFunction` flag.

Closes #20290

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added A-semantic Area - Semantic A-minifier Area - Minifier C-enhancement Category - New feature or request labels Mar 13, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 13, 2026

Merging this PR will not alter performance

✅ 53 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/semantic-empty-fn-no-side-effects (192a994) with main (5474d0a)2

Open in CodSpeed

Footnotes

  1. 3 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 (e704eae) during the generation of this report, so 5474d0a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier A-semantic Area - Semantic C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

semantic: extend no_side_effects to include empty functions

1 participant