Skip to content

Commit 01e3021

Browse files
committed
merge origin main
1 parent a50892d commit 01e3021

12 files changed

Lines changed: 120 additions & 106 deletions

File tree

crates/rspack_binding_api/src/allocator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use napi::{Env, bindgen_prelude::ToNapiValue, sys::napi_env};
24
use rspack_core::BindingCell;
35

@@ -57,7 +59,7 @@ impl rspack_core::NapiAllocator for NapiAllocatorImpl {
5759
fn allocate_assets(
5860
&self,
5961
env: napi_env,
60-
val: &BindingCell<rustc_hash::FxHashMap<String, rspack_core::CompilationAsset>>,
62+
val: &BindingCell<rustc_hash::FxHashMap<Arc<str>, rspack_core::CompilationAsset>>,
6163
) -> napi::Result<napi::sys::napi_value> {
6264
let assets = Assets::new(val.downgrade());
6365
unsafe { ToNapiValue::to_napi_value(env, assets) }

crates/rspack_binding_api/src/build_info.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{cell::RefCell, sync::LazyLock};
1+
use std::{
2+
cell::RefCell,
3+
sync::{Arc, LazyLock},
4+
};
25

36
use napi::{
47
Env, JsString, JsValue, Property, PropertyAttributes, Unknown,
@@ -24,17 +27,17 @@ define_symbols! {
2427
// Record<string, Source>
2528
#[napi]
2629
pub struct Assets {
27-
i: WeakBindingCell<FxHashMap<String, rspack_core::CompilationAsset>>,
30+
i: WeakBindingCell<FxHashMap<Arc<str>, rspack_core::CompilationAsset>>,
2831
}
2932

3033
impl Assets {
31-
pub fn new(i: WeakBindingCell<FxHashMap<String, rspack_core::CompilationAsset>>) -> Self {
34+
pub fn new(i: WeakBindingCell<FxHashMap<Arc<str>, rspack_core::CompilationAsset>>) -> Self {
3235
Self { i }
3336
}
3437

3538
fn with_ref<T>(
3639
&self,
37-
f: impl FnOnce(&FxHashMap<String, rspack_core::CompilationAsset>) -> napi::Result<T>,
40+
f: impl FnOnce(&FxHashMap<Arc<str>, rspack_core::CompilationAsset>) -> napi::Result<T>,
3841
) -> napi::Result<T> {
3942
match self.i.upgrade() {
4043
Some(reference) => f(reference.as_ref()),

crates/rspack_binding_api/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl Module {
458458
};
459459

460460
module.build_info_mut().assets.insert(
461-
filename,
461+
filename.into(),
462462
rspack_core::CompilationAsset {
463463
source: Some(source.try_into()?),
464464
info: asset_info,

crates/rspack_core/src/binding/cell.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ mod napi_binding {
123123
}
124124
HeapVariant::Assets(assets) => {
125125
let binding_cell = BindingCell {
126-
ptr: assets.as_ref() as *const FxHashMap<String, CompilationAsset>
127-
as *mut FxHashMap<String, CompilationAsset>,
126+
ptr: assets.as_ref() as *const FxHashMap<Arc<str>, CompilationAsset>
127+
as *mut FxHashMap<Arc<str>, CompilationAsset>,
128128
heap: heap.clone(),
129129
};
130130
let napi_val = allocator.allocate_assets(raw_env, &binding_cell)?;
@@ -165,7 +165,7 @@ mod napi_binding {
165165
CodeGenerationResults(Box<CodeGenerationResults>),
166166
CodeGenerationResult(Box<CodeGenerationResult>),
167167
Sources(Box<FxHashMap<SourceType, BoxSource>>),
168-
Assets(Box<FxHashMap<String, CompilationAsset>>),
168+
Assets(Box<FxHashMap<Arc<str>, CompilationAsset>>),
169169
}
170170

171171
#[derive(Debug)]
@@ -276,11 +276,11 @@ mod napi_binding {
276276
}
277277
}
278278

279-
impl BindingCell<FxHashMap<String, CompilationAsset>> {
280-
pub fn new(assets: FxHashMap<String, CompilationAsset>) -> Self {
279+
impl BindingCell<FxHashMap<Arc<str>, CompilationAsset>> {
280+
pub fn new(assets: FxHashMap<Arc<str>, CompilationAsset>) -> Self {
281281
let boxed = Box::new(assets);
282-
let ptr = boxed.as_ref() as *const FxHashMap<String, CompilationAsset>
283-
as *mut FxHashMap<String, CompilationAsset>;
282+
let ptr = boxed.as_ref() as *const FxHashMap<Arc<str>, CompilationAsset>
283+
as *mut FxHashMap<Arc<str>, CompilationAsset>;
284284
let heap = Arc::new(Heap {
285285
variant: HeapVariant::Assets(boxed),
286286
jsobject: Default::default(),
@@ -289,10 +289,10 @@ mod napi_binding {
289289
}
290290
}
291291

292-
impl From<FxHashMap<String, CompilationAsset>>
293-
for BindingCell<FxHashMap<String, CompilationAsset>>
292+
impl From<FxHashMap<Arc<str>, CompilationAsset>>
293+
for BindingCell<FxHashMap<Arc<str>, CompilationAsset>>
294294
{
295-
fn from(assets: FxHashMap<String, CompilationAsset>) -> Self {
295+
fn from(assets: FxHashMap<Arc<str>, CompilationAsset>) -> Self {
296296
Self::new(assets)
297297
}
298298
}
@@ -422,7 +422,12 @@ mod napi_binding {
422422
CodeGenerationResult
423423
);
424424
deserialize_variant!(type_id, boxed, HeapVariant::Sources, FxHashMap<SourceType, BoxSource>);
425-
deserialize_variant!(type_id, boxed, HeapVariant::Assets, FxHashMap<String, CompilationAsset>);
425+
deserialize_variant!(
426+
type_id,
427+
boxed,
428+
HeapVariant::Assets,
429+
FxHashMap<Arc<str>, CompilationAsset>
430+
);
426431

427432
unreachable!()
428433
}

crates/rspack_core/src/binding/napi_allocator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use napi::sys::{napi_env, napi_value};
24
use once_cell::sync::OnceCell;
35
use rspack_sources::BoxSource;
@@ -34,7 +36,7 @@ pub trait NapiAllocator {
3436
fn allocate_assets(
3537
&self,
3638
env: napi_env,
37-
val: &BindingCell<FxHashMap<String, CompilationAsset>>,
39+
val: &BindingCell<FxHashMap<Arc<str>, CompilationAsset>>,
3840
) -> napi::Result<napi_value>;
3941
}
4042

crates/rspack_core/src/chunk_group.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ impl ChunkGroupKind {
409409
}
410410
}
411411

412-
pub fn name(&self) -> Option<&str> {
412+
pub fn name(&self) -> Option<&Arc<str>> {
413413
match self {
414-
ChunkGroupKind::Entrypoint { options, .. } => options.name.as_deref(),
415-
ChunkGroupKind::Normal { options } => options.name.as_deref(),
414+
ChunkGroupKind::Entrypoint { options, .. } => options.name.as_ref(),
415+
ChunkGroupKind::Normal { options } => options.name.as_ref(),
416416
}
417417
}
418418
}

crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,92 +1555,92 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
15551555
let loc = block.loc();
15561556

15571557
let cgi = if let Some(entry_options) = entry_options {
1558-
let cgi =
1559-
if let Some(cgi) = chunk_name.and_then(|name| self.named_async_entrypoints.get(name.as_ref())) {
1560-
let cgi = self.chunk_group_infos.expect_get(cgi);
1558+
let cgi = if let Some(cgi) =
1559+
chunk_name.and_then(|name| self.named_async_entrypoints.get(name.as_ref()))
1560+
{
1561+
let cgi = self.chunk_group_infos.expect_get(cgi);
15611562

1562-
compilation
1563-
.build_chunk_graph_artifact
1564-
.chunk_group_by_ukey
1565-
.expect_get_mut(&cgi.chunk_group)
1566-
.add_origin(Some(module_id), loc, request);
1563+
compilation
1564+
.build_chunk_graph_artifact
1565+
.chunk_group_by_ukey
1566+
.expect_get_mut(&cgi.chunk_group)
1567+
.add_origin(Some(module_id), loc, request);
15671568

1568-
compilation
1569-
.build_chunk_graph_artifact
1570-
.chunk_graph
1571-
.connect_block_and_chunk_group(block_id, cgi.chunk_group);
1572-
cgi.ukey
1573-
} else {
1574-
let entry_options = entry_options.clone();
1575-
let chunk = compilation
1576-
.build_chunk_graph_artifact
1577-
.chunk_by_ukey
1578-
.expect_get_mut(&chunk_ukey);
1579-
if let Some(filename) = &entry_options.filename {
1580-
chunk.set_filename_template(Some(filename.clone()));
1581-
}
1582-
let mut entrypoint = ChunkGroup::new(ChunkGroupKind::new_entrypoint(
1583-
false,
1584-
Box::new(entry_options.clone()),
1585-
));
1586-
1587-
self.stat_chunk_group_created += 1;
1588-
let cgi = ChunkGroupInfo::new(
1589-
entrypoint.ukey,
1590-
Arc::new(
1591-
RuntimeSpec::from_entry_options(&entry_options)
1592-
.expect("should have runtime for AsyncEntrypoint"),
1593-
),
1594-
entry_options
1595-
.chunk_loading
1596-
.as_ref()
1597-
.map_or(item_chunk_group_info.chunk_loading, |x| {
1598-
!matches!(x, ChunkLoading::Disable)
1599-
}),
1600-
entry_options
1601-
.async_chunks
1602-
.unwrap_or(item_chunk_group_info.async_chunks),
1603-
);
1604-
let ukey = cgi.ukey;
1569+
compilation
1570+
.build_chunk_graph_artifact
1571+
.chunk_graph
1572+
.connect_block_and_chunk_group(block_id, cgi.chunk_group);
1573+
cgi.ukey
1574+
} else {
1575+
let entry_options = entry_options.clone();
1576+
let chunk = compilation
1577+
.build_chunk_graph_artifact
1578+
.chunk_by_ukey
1579+
.expect_get_mut(&chunk_ukey);
1580+
if let Some(filename) = &entry_options.filename {
1581+
chunk.set_filename_template(Some(filename.clone()));
1582+
}
1583+
let mut entrypoint = ChunkGroup::new(ChunkGroupKind::new_entrypoint(
1584+
false,
1585+
Box::new(entry_options.clone()),
1586+
));
16051587

1606-
self.chunk_group_infos.entry(ukey).or_insert(cgi);
1588+
self.stat_chunk_group_created += 1;
1589+
let cgi = ChunkGroupInfo::new(
1590+
entrypoint.ukey,
1591+
Arc::new(
1592+
RuntimeSpec::from_entry_options(&entry_options)
1593+
.expect("should have runtime for AsyncEntrypoint"),
1594+
),
1595+
entry_options
1596+
.chunk_loading
1597+
.as_ref()
1598+
.map_or(item_chunk_group_info.chunk_loading, |x| {
1599+
!matches!(x, ChunkLoading::Disable)
1600+
}),
1601+
entry_options
1602+
.async_chunks
1603+
.unwrap_or(item_chunk_group_info.async_chunks),
1604+
);
1605+
let ukey = cgi.ukey;
16071606

1608-
entrypoint.set_runtime_chunk(chunk.ukey());
1609-
entrypoint.set_entrypoint_chunk(chunk.ukey());
1610-
compilation
1611-
.build_chunk_graph_artifact
1612-
.async_entrypoints
1613-
.push(entrypoint.ukey);
1614-
self.next_chunk_group_index += 1;
1615-
entrypoint.index = Some(self.next_chunk_group_index);
1616-
1617-
if let Some(name) = entrypoint.kind.name() {
1618-
let name_key: Arc<str> = Arc::from(name);
1619-
self.named_async_entrypoints.insert(name_key.clone(), ukey);
1620-
compilation
1621-
.build_chunk_graph_artifact
1622-
.named_chunk_groups
1623-
.insert(name_key.clone(), entrypoint.ukey);
1624-
compilation
1625-
.build_chunk_graph_artifact
1626-
.named_chunks
1627-
.insert(name_key, chunk.ukey());
1628-
}
1607+
self.chunk_group_infos.entry(ukey).or_insert(cgi);
16291608

1630-
entrypoint.connect_chunk(chunk);
1609+
entrypoint.set_runtime_chunk(chunk.ukey());
1610+
entrypoint.set_entrypoint_chunk(chunk.ukey());
1611+
compilation
1612+
.build_chunk_graph_artifact
1613+
.async_entrypoints
1614+
.push(entrypoint.ukey);
1615+
self.next_chunk_group_index += 1;
1616+
entrypoint.index = Some(self.next_chunk_group_index);
16311617

1632-
self.chunk_group_info_map.insert(entrypoint.ukey, ukey);
1618+
if let Some(name) = entrypoint.kind.name() {
1619+
self.named_async_entrypoints.insert(name.clone(), ukey);
16331620
compilation
16341621
.build_chunk_graph_artifact
1635-
.chunk_graph
1636-
.connect_block_and_chunk_group(block_id, entrypoint.ukey);
1637-
1622+
.named_chunk_groups
1623+
.insert(name.clone(), entrypoint.ukey);
16381624
compilation
16391625
.build_chunk_graph_artifact
1640-
.chunk_group_by_ukey
1641-
.add(entrypoint);
1642-
ukey
1643-
};
1626+
.named_chunks
1627+
.insert(name.clone(), chunk.ukey());
1628+
}
1629+
1630+
entrypoint.connect_chunk(chunk);
1631+
1632+
self.chunk_group_info_map.insert(entrypoint.ukey, ukey);
1633+
compilation
1634+
.build_chunk_graph_artifact
1635+
.chunk_graph
1636+
.connect_block_and_chunk_group(block_id, entrypoint.ukey);
1637+
1638+
compilation
1639+
.build_chunk_graph_artifact
1640+
.chunk_group_by_ukey
1641+
.add(entrypoint);
1642+
ukey
1643+
};
16441644

16451645
let cgi = self.chunk_group_infos.expect_get(&cgi);
16461646
entrypoint = Some(cgi.chunk_group);
@@ -1714,11 +1714,11 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
17141714
chunk_group.index = Some(self.next_chunk_group_index);
17151715

17161716
if let Some(name) = chunk_group.kind.name() {
1717-
self.named_chunk_groups.insert(Arc::from(name), info_ukey);
1717+
self.named_chunk_groups.insert(name.clone(), info_ukey);
17181718
compilation
17191719
.build_chunk_graph_artifact
17201720
.named_chunk_groups
1721-
.insert(Arc::from(name), chunk_group.ukey);
1721+
.insert(name.clone(), chunk_group.ukey);
17221722
}
17231723

17241724
chunk_group.connect_chunk(chunk);

crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::VecDeque, iter::once, sync::{atomic::AtomicU32, Arc}};
1+
use std::{collections::VecDeque, iter::once, sync::atomic::AtomicU32};
22

33
use itertools::Itertools;
44
use rspack_collections::{DatabaseItem, Identifier, IdentifierSet};
@@ -162,7 +162,7 @@ impl Task<ExecutorTaskContext> for ExecuteTask {
162162
execute_result.cacheable = false;
163163
}
164164
for (name, asset) in build_info.assets.as_ref() {
165-
assets.insert(Arc::from(name.as_str()), asset.clone());
165+
assets.insert(name.clone(), asset.clone());
166166
}
167167
if !has_error && make_failed_module.contains(&m) {
168168
let diagnostics = module.diagnostics();

crates/rspack_core/src/compilation/build_module_graph/module_executor/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod execute;
55
mod module_tracker;
66
mod overwrite;
77

8+
use std::sync::Arc;
9+
810
use rspack_collections::{Identifier, IdentifierDashMap, IdentifierDashSet};
911
use rspack_error::Result;
1012
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
@@ -42,7 +44,7 @@ pub struct ModuleExecutor {
4244
// temporary data, used by hook_after_finish_modules
4345
event_sender: Option<UnboundedSender<Event>>,
4446
stop_receiver: Option<oneshot::Receiver<ExecutorTaskContext>>,
45-
module_assets: IdentifierDashMap<HashMap<String, CompilationAsset>>,
47+
module_assets: IdentifierDashMap<HashMap<Arc<str>, CompilationAsset>>,
4648
code_generated_modules: IdentifierDashSet,
4749
pub executed_runtime_modules: IdentifierDashMap<ExecutedRuntimeModule>,
4850
}
@@ -208,7 +210,7 @@ impl ModuleExecutor {
208210
.module_assets
209211
.entry(origin_module_identifier)
210212
.or_default()
211-
.extend(assets.into_iter().map(|(k, v)| (k.to_string(), v)));
213+
.extend(assets.into_iter());
212214
}
213215

214216
for id in code_generated_modules {

crates/rspack_core/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct BuildInfo {
107107
#[cacheable(with=AsOption<AsVec<AsPreset>>)]
108108
pub top_level_declarations: Option<HashSet<Atom>>,
109109
pub module_concatenation_bailout: Option<String>,
110-
pub assets: BindingCell<HashMap<String, CompilationAsset>>,
110+
pub assets: BindingCell<HashMap<Arc<str>, CompilationAsset>>,
111111
pub module: bool,
112112
pub inline_exports: bool,
113113
pub collected_typescript_info: Option<CollectedTypeScriptInfo>,

0 commit comments

Comments
 (0)