Skip to content

Commit

Permalink
feat: replace SymbolId with SymbolRef (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 authored Oct 25, 2023
1 parent fd5d361 commit 9c90067
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
5 changes: 2 additions & 3 deletions crates/rolldown/src/bundler/chunk/de_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ impl Chunk {
.iter()
.flat_map(|part| part.declared_symbols.iter().copied()),
)
.for_each(|symbol_id| {
let canonical_ref =
graph.symbols.par_get_canonical_ref((module.id, symbol_id).into());
.for_each(|symbol_ref| {
let canonical_ref = graph.symbols.par_get_canonical_ref(symbol_ref);

let original_name = graph.symbols.get_original_name(canonical_ref);

Expand Down
11 changes: 6 additions & 5 deletions crates/rolldown/src/bundler/module/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl NormalModule {
if !self_linker_module.is_symbol_for_namespace_referenced {
self_linker_module.is_symbol_for_namespace_referenced = true;
self_linker_module.virtual_stmt_infos.push(VirtualStmtInfo {
declared_symbols: vec![self.namespace_symbol.symbol],
declared_symbols: vec![self.namespace_symbol],
..Default::default()
});
}
Expand Down Expand Up @@ -335,9 +335,10 @@ impl NormalModule {
.into();
let symbol = symbols.create_symbol(self.id, name).symbol;
self_linker_module.wrap_symbol = Some((self.id, symbol).into());
self_linker_module
.virtual_stmt_infos
.push(VirtualStmtInfo { declared_symbols: vec![symbol], ..Default::default() });
self_linker_module.virtual_stmt_infos.push(VirtualStmtInfo {
declared_symbols: vec![(self.id, symbol).into()],
..Default::default()
});
self.initialize_namespace(self_linker_module);
}
}
Expand Down Expand Up @@ -365,7 +366,7 @@ impl NormalModule {
// FIXME: should store the symbol in `used_symbols` instead of `declared_symbols`.
// The deconflict for runtime symbols would be handled in the deconflict on cross-chunk-imported
// symbols
declared_symbols: vec![local_symbol_ref.symbol],
declared_symbols: vec![local_symbol_ref],
..Default::default()
});
local_symbol_ref
Expand Down
7 changes: 3 additions & 4 deletions crates/rolldown/src/bundler/visitors/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> Scanner<'a> {
}

fn add_declared_id(&mut self, id: SymbolId) {
self.current_stmt_info.declared_symbols.push(id);
self.current_stmt_info.declared_symbols.push((self.idx, id).into());
}

fn get_root_binding(&self, name: &Atom) -> SymbolId {
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'a> Scanner<'a> {
oxc::ast::ast::Declaration::FunctionDeclaration(fn_decl) => {
let id = fn_decl.id.as_ref().unwrap();
// FIXME: remove this line after https://github.com/web-infra-dev/oxc/pull/843 being merged.
self.current_stmt_info.declared_symbols.push(id.expect_symbol_id());
self.add_declared_id(id.expect_symbol_id());
self.add_local_export(&id.name, id.expect_symbol_id());
}
oxc::ast::ast::Declaration::ClassDeclaration(cls_decl) => {
Expand Down Expand Up @@ -247,8 +247,7 @@ impl<'a> Scanner<'a> {
SymbolFlags::None,
self.scope.root_scope_id(),
);

self.current_stmt_info.declared_symbols.push(sym_id);
self.add_declared_id(sym_id);
sym_id
});
self.add_local_default_export(local);
Expand Down
6 changes: 2 additions & 4 deletions crates/rolldown_common/src/stmt_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use oxc::semantic::SymbolId;

use crate::SymbolRef;

index_vec::define_index_type! {
Expand All @@ -10,7 +8,7 @@ index_vec::define_index_type! {
pub struct StmtInfo {
pub stmt_idx: usize,
// currently, we only store top level symbols
pub declared_symbols: Vec<SymbolId>,
pub declared_symbols: Vec<SymbolRef>,
// We will add symbols of other modules to `referenced_symbols`, so we need `SymbolRef`
// here instead of `SymbolId`.
/// Top level symbols referenced by this statement.
Expand All @@ -20,6 +18,6 @@ pub struct StmtInfo {
// Because we want declare symbols at linker, it shouldn't mutate the original `StmtInfo`.
#[derive(Default, Debug)]
pub struct VirtualStmtInfo {
pub declared_symbols: Vec<SymbolId>,
pub declared_symbols: Vec<SymbolRef>,
pub referenced_symbols: Vec<SymbolRef>,
}

0 comments on commit 9c90067

Please sign in to comment.