Skip to content

refactor(rust): remove FacadeScoping, use Scoping::create_symbol for facade symbols#8540

Merged
hyf0 merged 2 commits intomainfrom
refactor/remove-facade-scoping
Mar 4, 2026
Merged

refactor(rust): remove FacadeScoping, use Scoping::create_symbol for facade symbols#8540
hyf0 merged 2 commits intomainfrom
refactor/remove-facade-scoping

Conversation

@Dunqing
Copy link
Collaborator

@Dunqing Dunqing commented Mar 4, 2026

Summary

  • Remove the FacadeScoping struct and minimum_symbol_id boundary that separated "real" AST symbols from synthetic "facade" symbols using reverse-counting IDs (u32::MAX - 1 downward)
  • Use oxc's Scoping::create_symbol() API instead, giving facade symbols contiguous forward-counting IDs in the same symbol table
  • Add SymbolRefFlags::IsFacade flag to identify facade symbols, replacing the old boundary-based check
  • Simplify get_classic_data from boundary-check + HashMap fallback to direct IndexVec indexing
  • Delete SymbolIdExt trait (hardcoded u32::MAX - 2 for namespace detection), add Module::namespace_object_ref() API
  • Add SymbolRefDbForModule::merge_from_build() for correct incremental build cache handling

Test plan

  • cargo clippy -p rolldown -p rolldown_common — no errors
  • esbuild integration tests — 834 passed, 0 failed
  • rollup integration tests — 47 passed, 0 failed
  • rolldown integration tests — 744 passed, 1 failed (pre-existing util_deprecate)
  • HMR incremental build test no_accept_outside_circular — passes

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 4, 2026 03:32
@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit ba22e54
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a7a7d62073e40008f7b749
😎 Deploy Preview https://deploy-preview-8540--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit ba22187
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a7cab6b8563d00088874f0
😎 Deploy Preview https://deploy-preview-8540--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors rolldown’s Rust symbol infrastructure to remove the old “facade symbol” ID partitioning scheme and instead allocate synthetic (facade) symbols directly inside oxc’s Scoping symbol table, identifying them via a new SymbolRefFlags::IsFacade flag. This simplifies symbol bookkeeping (notably classic_data access) and fixes incremental-build cache syncing for symbols created during linking.

Changes:

  • Remove FacadeScoping/boundary-based facade symbol handling; create facade symbols with Scoping::create_symbol() and mark them with SymbolRefFlags::IsFacade.
  • Simplify symbol classic-data lookup to direct IndexVec<SymbolId, ...> indexing; add cache sync via SymbolRefDbForModule::merge_from_build().
  • Replace the deleted SymbolIdExt namespace detection with Module::namespace_object_ref() and update call sites.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rolldown_common/src/types/symbol_ref_db.rs Add IsFacade flag, simplify classic data access, and add incremental cache merge (merge_from_build).
crates/rolldown_common/src/types/ast_scopes.rs Remove FacadeScoping; allocate facade symbols in Scoping via create_symbol.
crates/rolldown_common/src/module/mod.rs Add Module::namespace_object_ref() to replace hardcoded namespace symbol IDs.
crates/rolldown_common/src/lib.rs Stop re-exporting removed SymbolIdExt.
crates/rolldown_common/src/ecmascript/symbol_id_ext.rs Delete the SymbolIdExt trait (magic namespace SymbolId value).
crates/rolldown_common/src/ecmascript/mod.rs Remove symbol_id_ext module export.
crates/rolldown/src/utils/chunk/deconflict_chunk_symbols.rs Stop iterating the removed facade-classic-data map; rely on unified classic_data.
crates/rolldown/src/stages/link_stage/tree_shaking/include_statements.rs Replace namespace checks using SymbolIdExt with Module::namespace_object_ref().
crates/rolldown/src/stages/link_stage/generate_lazy_export.rs Recreate facade symbol refs when JSON modules rebuild Scoping (old IDs become invalid).
crates/rolldown/src/stages/generate_stage/compute_cross_chunk_links.rs Replace hardcoded namespace symbol construction with module-provided namespace refs.
crates/rolldown/src/module_finalizers/mod.rs Replace SymbolIdExt namespace refs with Module::namespace_object_ref() usage.
crates/rolldown/src/bundle/bundle.rs Use merge_from_build when updating the incremental-build cache snapshot.
crates/rolldown/src/ast_scanner/mod.rs Update facade-symbol detection to use the DB’s IsFacade flag.

Copilot AI review requested due to automatic review settings March 4, 2026 03:45
@Dunqing Dunqing force-pushed the refactor/remove-facade-scoping branch from df3186a to 103f6ab Compare March 4, 2026 03:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

crates/rolldown_common/src/types/symbol_ref_db.rs:136

  • merge_from_build only extends classic_data when build_db has more symbols. If a rebuild ever produces fewer symbols (e.g. module source shrinks / different wrapping decisions), classic_data will remain longer than ast_scopes.total_symbol_count(), leaving stale per-symbol data (and potentially stale flags entries) addressable by old SymbolIds. Consider resizing classic_data to exactly new_len (truncate when shrinking) and pruning any flags keyed by removed SymbolIds to keep the DB invariant in sync with Scoping.
    // Extend classic_data for any symbols added during linking (e.g., facade symbols)
    let new_len = build_db.ast_scopes.total_symbol_count();
    let current_len = self.classic_data.len();
    for _ in current_len..new_len {
      self.classic_data.push(SymbolRefDataClassic::default());
    }

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Benchmarks Rust

group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     75.8±1.44ms        ? ?/sec    1.02     77.4±1.93ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     83.8±1.56ms        ? ?/sec    1.02     85.1±1.61ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    157.1±2.76ms        ? ?/sec    1.00    157.2±3.49ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    173.6±2.49ms        ? ?/sec    1.00    172.9±2.66ms        ? ?/sec
bundle/bundle@threejs                                        1.01     72.1±3.34ms        ? ?/sec    1.00     71.1±0.99ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     77.7±1.29ms        ? ?/sec    1.02     78.9±1.19ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    754.4±5.20ms        ? ?/sec    1.00    753.8±6.36ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    862.2±4.89ms        ? ?/sec    1.00    861.9±6.17ms        ? ?/sec
scan/scan@rome_ts                                            1.00     75.2±1.43ms        ? ?/sec    1.01     75.7±1.60ms        ? ?/sec
scan/scan@threejs                                            1.00     26.5±0.35ms        ? ?/sec    1.00     26.6±0.38ms        ? ?/sec
scan/scan@threejs10x                                         1.00    260.9±2.67ms        ? ?/sec    1.00    259.7±3.09ms        ? ?/sec

Copilot AI review requested due to automatic review settings March 4, 2026 04:15
@Dunqing Dunqing review requested due to automatic review settings March 4, 2026 04:15
@Dunqing Dunqing force-pushed the refactor/remove-facade-scoping branch from 1462722 to 103f6ab Compare March 4, 2026 04:16
Copilot AI review requested due to automatic review settings March 4, 2026 04:16
@Dunqing
Copy link
Collaborator Author

Dunqing commented Mar 4, 2026

This PR aims to standardize the handling of facade symbols, making it easier to understand.

Before:

The old FacadeScoping used reverse-counting IDs (u32::MAX - 1 downward) to keep synthetic "facade" symbols separate from real AST symbols. This was fragile — it relied on a hardcoded u32::MAX - 2 to identify namespace symbols, stored facade data in a HashMap instead of the contiguous IndexVec, and required boundary checks on every get_classic_data call.

After:

This PR switches to oxc's Scoping::create_symbol(), which gives facade symbols normal forward-counting IDs in the same table. A SymbolRefFlags::IsFacade flag replaces the boundary-based detection. The result is simpler data access (direct indexing instead of boundary check + HashMap fallback), no magic constants, and proper use of upstream APIs.

image

Additionally, we achieved a 0.5% performance improvement. Also, this change allows us to use IndexVec instead of FxHashMap, since it no longer has a Max::u32-sized Vec.

…facade symbols

Replace the two-layer FacadeScoping system (reverse-counting IDs from u32::MAX)
with oxc's Scoping::create_symbol() API, giving facade symbols contiguous IDs
in the same symbol table as real AST symbols.

Key changes:
- Remove FacadeScoping struct and minimum_symbol_id boundary from AstScopes
- Add SymbolRefFlags::IsFacade to identify facade symbols via flag instead of ID range
- Simplify get_classic_data from boundary-check + HashMap fallback to direct indexing
- Delete SymbolIdExt trait (hardcoded u32::MAX-2 for namespace detection)
- Add Module::namespace_object_ref() API to replace SymbolIdExt usage
- Add SymbolRefDbForModule::merge_from_build() for incremental build cache correctness

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Dunqing Dunqing force-pushed the refactor/remove-facade-scoping branch from 103f6ab to 8d9f1c9 Compare March 4, 2026 04:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

crates/rolldown_common/src/types/symbol_ref_db.rs:147

  • merge_from_build restores Scoping and adds IsFacade flags for newly-created facade symbols, but it doesn't merge create_reason (debug-only) for those symbols. In debug builds this can make SymbolRefDb::get_create_reason return "No create reason found" for a facade symbol, which contradicts the method’s doc comment and makes incremental-build debugging harder. Consider merging build_db.create_reason entries for symbols that are new to the cache DB when cfg(debug_assertions) is enabled.
  /// Merge immutable fields (Scoping) from a build's DB into this cache DB.
  /// Also extends `classic_data` and preserves `IsFacade` flags for facade symbols
  /// that were created during the linking phase.
  pub fn merge_from_build(&mut self, build_db: SymbolRefDbForModule) {
    // Extend classic_data for any symbols added during linking (e.g., facade symbols)
    let new_len = build_db.ast_scopes.total_symbol_count();
    let current_len = self.classic_data.len();
    for _ in current_len..new_len {
      self.classic_data.push(SymbolRefDataClassic::default());
    }

    // Preserve IsFacade flags for facade symbols added during linking
    for (symbol_id, flags) in &build_db.flags {
      if flags.contains(SymbolRefFlags::IsFacade) {
        self.flags.entry(*symbol_id).or_default().insert(SymbolRefFlags::IsFacade);
      }
    }

    let scoping = build_db.ast_scopes.into_scoping();
    self.ast_scopes.set_scoping(scoping);
  }

@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 4, 2026

Merge activity

  • Mar 4, 5:15 AM UTC: @Dunqing we removed the merge queue label because we could not find a Graphite account associated with your GitHub profile.

You must have a Graphite account in order to use the merge queue. Create an account and try again using this link

@hyf0 hyf0 enabled auto-merge (squash) March 4, 2026 06:01
@hyf0 hyf0 merged commit 22c9344 into main Mar 4, 2026
34 checks passed
@hyf0 hyf0 deleted the refactor/remove-facade-scoping branch March 4, 2026 06:11
@github-actions github-actions bot mentioned this pull request Mar 5, 2026
shulaoda added a commit that referenced this pull request Mar 5, 2026
## [1.0.0-rc.7] - 2026-03-05

⚡ Smarter Code Generation Defaults
- DCE-only minification and smart constant inlining are now enabled by default
- Produces cleaner, smaller output bundles without requiring explicit configuration

💡 LLM-Friendly Bundle Analyzer Reports
- New markdown output format for the bundle analyzer plugin with bundle summaries, module graphs, dependency chains, and optimization suggestions
- Optimization suggestions now also recommend using the entriesAware option when common chunks contain modules only reachable from specific entries


### 💥 BREAKING CHANGES

- enable minify: 'dce-only' by default (#8465) by @IWANABETHATGUY
- settings `inlineConst: { mode: 'smart', pass: 1}`  by default (#8444) by @IWANABETHATGUY

### 🚀 Features

- binding: add original getter to BindingMagicString (#8533) by @IWANABETHATGUY
- native-magic-string: add `offset` property support (#8531) by @IWANABETHATGUY
- add `output.strict` option to control `"use strict"` directive emission (#8489) by @Copilot
- watch: expose `watcher.compareContentsForPolling` (#8526) by @hyf0
- watch: use new watcher to support watch mode (#8475) by @hyf0
- rust/watch: handle bulk-change (#8466) by @hyf0
- add LLM-friendly markdown output format to bundle analyzer plugin (#8242) by @IWANABETHATGUY

### 🐛 Bug Fixes

- expose `plugins` on `NormalizedInputOptions` for `buildStart` hook (#8521) by @Copilot
- only uppercase facade symbols in JSX preserve mode (#8519) by @IWANABETHATGUY
- binding: export BindingResult in generated dts header (#8537) by @minsoo-web
- pre-resolve paths option to avoid `invoke_sync` deadlock (#8518) by @IWANABETHATGUY
- remove debug-only jsx_preset and UntranspiledSyntaxError (#8511) by @IWANABETHATGUY
- apply `topLevelVar` to exported `const`/`let` declarations (#8507) by @IWANABETHATGUY
- rolldown_plugin_vite_web_worker_post: avoid replacing `new.target` (#8488) by @sapphi-red
- update copyright year to 2026 (#8486) by @maciekzygmunt

### 🚜 Refactor

- rust: use Oxc's SymbolFlags::ConstVariable instead of custom IsConst flag (#8543) by @Dunqing
- rust: remove FacadeScoping, use Scoping::create_symbol for facade symbols (#8540) by @Dunqing
- rust/watch: remove hacky `reset_closed_for_watch_mode` (#8530) by @hyf0
- binding: return &str instead of String in filename() getter (#8534) by @IWANABETHATGUY
- rust: remove old watch mode implementation (#8525) by @hyf0
- rust/watch: simply watch logic in the binding layer (#8516) by @hyf0
- rust/watch: tweak struct/function names (#8464) by @hyf0

### 📚 Documentation

- explain how external modules work in rolldown (#8457) by @sapphi-red
- add some diagrams using graphviz (#8499) by @sapphi-red
- use `vitepress-plugin-graphviz` (#8498) by @sapphi-red
- list s390x/ppc64le prebuilt binaries (#8495) by @crusty-voidzero
- fix error type for `RolldownBuild.generate` and others (#8490) by @sapphi-red

### ⚡ Performance

- string_wizard: reduce allocations and add ASCII fast paths (#8541) by @IWANABETHATGUY
- use IndexBitSet to replace IndexVec<XXXIdx, bool> for module/stmt inclusion tracking (#8503) by @IWANABETHATGUY
- plugin: use IndexBitSet to optimize skipped plugins checking (#8497) by @ShroXd
- rust/tla: skip compute_tla if there is no module use TLA (#8487) by @ShroXd

### 🧪 Testing

- node/watch: make watch tests run in concurrent and retry-able (#8512) by @hyf0
- add test case for static flag tree-shaking (#8476) by @IWANABETHATGUY
- migrate post-banner sourcemap-with-shebang to Rust (#8477) by @Copilot

### ⚙️ Miscellaneous Tasks

- vscode: `formatOnSave` for markdown files using oxc formatter (#8536) by @minsoo-web
- deps: update test262 submodule for tests (#8528) by @sapphi-red
- remove `retry` workaround from output paths test fixtures (#8520) by @Copilot
- docs: add Shuyuan Wang (h-a-n-a) and remove from acknowledgements (#8509) by @Copilot
- consolidate top_level_var test cases using configVariants (#8508) by @IWANABETHATGUY
- add s390x and ppc64le linux gnu targets (#8493) by @Brooooooklyn

### ◀️ Revert

- fix(rolldown): increase tokio blocking threads size for watch mode (#8517) by @hyf0

### ❤️ New Contributors

* @minsoo-web made their first contribution in [#8536](#8536)
* @crusty-voidzero made their first contribution in [#8495](#8495)
* @maciekzygmunt made their first contribution in [#8486](#8486)

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants