Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rspack_binding_api/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl Chunk {
.get(group)
})
.collect::<Vec<_>>();
groups.sort_unstable_by(|a, b| a.index.cmp(&b.index));
groups.sort_unstable_by_key(|a| a.index);
Ok(
groups
.iter()
Expand Down
54 changes: 40 additions & 14 deletions crates/rspack_binding_api/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,32 @@ pub struct Dependency {
}

impl Dependency {
fn as_ref(&mut self) -> napi::Result<(&dyn rspack_core::Dependency, Option<&Compilation>)> {
fn as_ref<'a>(
&'a mut self,
) -> napi::Result<(
&'a (dyn rspack_core::Dependency + 'a),
Option<&'a Compilation>,
)> {
if let Some(compilation) = self.compilation {
let compilation = unsafe { compilation.as_ref() };
let module_graph = compilation.get_module_graph();
if let Some(dependency) = internal::try_dependency_by_id(module_graph, &self.dependency_id) {
self.dependency = {
#[allow(clippy::unwrap_used)]
NonNull::new(
(&**dependency) as *const dyn rspack_core::Dependency
as *mut dyn rspack_core::Dependency,
)
.unwrap()
// SAFETY:
// We extend `'a` to `'static` to satisfy the `NonNull<dyn Dependency>` field type,
// which has an implied `'static` bound on the trait object. All actual accesses are
// still mediated by the JS wrapper lifecycle plus runtime dependency lookups, so the
// references derived from this pointer must not outlive the original allocation.
let dependency_ptr = unsafe {
std::mem::transmute::<
*const (dyn rspack_core::Dependency + 'a),
*mut (dyn rspack_core::Dependency + 'static),
>(dependency.as_ref())
};

// SAFETY:
// `dependency` is a valid reference, so the erased raw pointer is non-null.
self.dependency = unsafe { NonNull::new_unchecked(dependency_ptr) };

Ok((unsafe { self.dependency.as_ref() }, Some(compilation)))
Comment thread
CPunisher marked this conversation as resolved.
} else {
Err(napi::Error::from_reason(format!(
Expand Down Expand Up @@ -189,20 +202,33 @@ pub struct DependencyWrapper {
}

impl DependencyWrapper {
pub fn new(
dependency: &dyn rspack_core::Dependency,
pub fn new<'a>(
dependency: &'a dyn rspack_core::Dependency,
compilation_id: CompilationId,
compilation: Option<&Compilation>,
) -> Self {
let dependency_id = *dependency.id();

// SAFETY:
// We extend `'a` to `'static` to satisfy the `NonNull<dyn Dependency>` field type,
// which has an implied `'static` bound on the trait object. All actual accesses are
// still mediated by the JS wrapper lifecycle plus runtime dependency lookups, so the
// references derived from this pointer must not outlive the original allocation.
let dependency_ptr = unsafe {
std::mem::transmute::<
*const (dyn rspack_core::Dependency + 'a),
*mut (dyn rspack_core::Dependency + 'static),
>(dependency)
};

// SAFETY:
// `dependency` is a valid reference, so the erased raw pointer is non-null.
let dependency = unsafe { NonNull::new_unchecked(dependency_ptr) };

Comment thread
CPunisher marked this conversation as resolved.
#[allow(clippy::unwrap_used)]
Self {
dependency_id,
dependency: NonNull::new(
dependency as *const dyn rspack_core::Dependency as *mut dyn rspack_core::Dependency,
)
.unwrap(),
dependency,
compilation_id,
compilation: compilation
.map(|c| NonNull::new(c as *const Compilation as *mut Compilation).unwrap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ impl BuildDeps {
let mut queue = VecDeque::new();
queue.extend(std::mem::take(&mut self.pending));
queue.extend(data);
loop {
let Some(current) = queue.pop_front() else {
break;
};
while let Some(current) = queue.pop_front() {
if !self.added.insert(current.clone()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,7 @@ impl FixIssuers {
let module_graph = &mut artifact.module_graph;
let mut revoke_module = IdentifierSet::default();
let mut need_check_available_modules = IdentifierMap::default();
loop {
let Some((mid, mut parents)) = queue.pop_front() else {
break;
};

while let Some((mid, mut parents)) = queue.pop_front() {
// remove revoke_module from parents
parents.retain(|item| {
let Some(parent_mid) = item else {
Expand Down Expand Up @@ -367,10 +363,7 @@ impl FixIssuers {
// the parent which cycle_paths contains current module can be set as issuer.
let mut queue = VecDeque::with_capacity(1);
queue.push_back(mid);
loop {
let Some(current_id) = queue.pop_front() else {
break;
};
while let Some(current_id) = queue.pop_front() {
need_clean_cycle_modules.retain(|id, paths| {
for (issuer, cycle_paths) in paths {
if cycle_paths.contains(&current_id) {
Expand Down Expand Up @@ -420,10 +413,7 @@ impl FixIssuers {
let mut useless_module = IdentifierSet::default();
let mut queue = VecDeque::new();
queue.push_back((mid, paths));
loop {
let Some((current, current_parents)) = queue.pop_front() else {
break;
};
while let Some((current, current_parents)) = queue.pop_front() {
useless_module.insert(current);

for mid in current_parents {
Expand Down
29 changes: 12 additions & 17 deletions crates/rspack_core/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,24 +530,19 @@ impl Compiler {
}

let assets = self.compilation.assets();
join_all(
self
.emitted_asset_versions
.iter()
.filter_map(|(filename, _version)| {
if !assets.contains_key(filename) {
let filename = filename.to_owned();
Some(async {
if !clean_options.keep(&filename).await {
let filename = output_path.join(filename);
let _ = self.output_filesystem.remove_file(&filename).await;
}
})
} else {
None
join_all(self.emitted_asset_versions.keys().filter_map(|filename| {
if !assets.contains_key(filename) {
let filename = filename.to_owned();
Some(async {
if !clean_options.keep(&filename).await {
let filename = output_path.join(filename);
let _ = self.output_filesystem.remove_file(&filename).await;
}
}),
)
})
} else {
None
}
}))
.await;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl ConcatenatedModule {
runtime: Option<RuntimeSpec>,
compilation: &Compilation,
) -> Self {
modules.sort_unstable_by(|a, b| a.id.cmp(&b.id));
modules.sort_unstable_by_key(|a| a.id);
let id = Self::create_identifier(&root_module_ctxt, &modules, hash_function);
Self::new(id.as_str().into(), root_module_ctxt, modules, runtime)
}
Expand Down
14 changes: 2 additions & 12 deletions crates/rspack_core/src/context_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,7 @@ async fn visit_dirs(
resolve_options: &ResolveInnerOptions<'_>,
fs: Arc<dyn ReadableFileSystem>,
) -> Result<()> {
if !fs
.metadata(dir)
.await
.map(|m| m.is_directory)
.unwrap_or(false)
{
if !fs.metadata(dir).await.is_ok_and(|m| m.is_directory) {
return Ok(());
}
let include = &options.context_options.include;
Expand All @@ -443,12 +438,7 @@ async fn visit_dirs(
continue;
}

if fs
.metadata(&path)
.await
.map(|m| m.is_directory)
.unwrap_or(false)
{
if fs.metadata(&path).await.is_ok_and(|m| m.is_directory) {
if options.context_options.recursive {
visit_dirs(
ctx,
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_core/src/external_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,8 @@ impl Module for ExternalModule {
};
let mut can_mangle = false;
let mut exports_type = BuildMetaExportsType::Dynamic;

#[allow(clippy::collapsible_match)]
match resolved_external_type {
"this" => self.build_info.strict = false,
"system" => {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/utils/extract_source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub async fn extract_source_map(
let mut futures = FuturesOrdered::new();

// Use zip to consume both vectors without extra cloning
for (source, original_content) in sources.into_iter().zip(source_contents.into_iter()) {
for (source, original_content) in sources.into_iter().zip(source_contents) {
let skip_reading = original_content.is_some();
let source_root = source_root.clone();
let context = context.to_path_buf();
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/utils/find_graph_roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn find_graph_roots<
let mut roots = FxHashSet::with_capacity_and_hasher(db.len(), Default::default());

let mut keys = db.keys().copied().collect::<Vec<_>>();
keys.sort_by(|a, b| expect_get(&db, a).item.cmp(&expect_get(&db, b).item));
keys.sort_by_key(|a| expect_get(&db, a).item);

// For all non-marked nodes
for select_node in keys {
Expand All @@ -175,7 +175,7 @@ pub fn find_graph_roots<
node: select_node,
open_edges: {
let mut v: Vec<_> = expect_get(&db, &select_node).dependencies.clone();
v.sort_by(|a, b| expect_get(&db, a).item.cmp(&expect_get(&db, b).item));
v.sort_by_key(|a| expect_get(&db, a).item);
v
},
}];
Expand All @@ -192,7 +192,7 @@ pub fn find_graph_roots<
.map(|edge| expect_get(&db, edge))
.collect::<Vec<_>>();

edges.sort_by(|a, b| a.item.cmp(&b.item));
edges.sort_by_key(|a| a.item);

// Process one dependency
let dependency = stack[top_of_stack_idx]
Expand Down
9 changes: 4 additions & 5 deletions crates/rspack_loader_swc/src/rsc_transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ impl<'a, C: Comments> VisitMut for ServerActions<'a, C> {
// 2. Register any remaining exports in the post-pass that weren't handled by the visitor.
if should_track_exports {
for stmt in stmts.iter() {
#[allow(clippy::collapsible_match)]
match stmt {
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(export_default_expr)) => {
if let Expr::Ident(ident) = &*export_default_expr.expr {
Expand Down Expand Up @@ -1447,7 +1448,7 @@ impl<'a, C: Comments> VisitMut for ServerActions<'a, C> {
for mut stmt in stmts.take() {
if should_track_exports {
let mut disallowed_export_span = DUMMY_SP;

#[allow(clippy::collapsible_match)]
match &mut stmt {
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { decl, span })) => match decl {
Decl::Var(_)
Expand Down Expand Up @@ -1902,10 +1903,8 @@ impl<'a, C: Comments> VisitMut for ServerActions<'a, C> {
fn visit_mut_assign_expr(&mut self, assign_expr: &mut AssignExpr) {
let old_arrow_or_fn_expr_ident = self.arrow_or_fn_expr_ident.clone();

if let (
AssignTarget::Simple(SimpleAssignTarget::Ident(ident)),
box (Expr::Arrow(_) | Expr::Fn(_)),
) = (&assign_expr.left, &assign_expr.right)
if let (AssignTarget::Simple(SimpleAssignTarget::Ident(ident)), Expr::Arrow(_) | Expr::Fn(_)) =
(&assign_expr.left, assign_expr.right.as_ref())
{
self.arrow_or_fn_expr_ident = Some(ident.id.clone());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_copy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
.deref_mut(),
));

copied_result.sort_unstable_by(|a, b| a.0.cmp(&b.0));
copied_result.sort_unstable_by_key(|a| a.0);

// Keep track of source to destination file mappings for permission copying
let mut permission_copies = Vec::new();
Expand Down
5 changes: 2 additions & 3 deletions crates/rspack_plugin_css/src/parser_and_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@ impl ParserAndGenerator for CssParserAndGenerator {
let convention_names = export_locals_convention(&name, convention);
let convention_local_class = export_locals_convention(local_class, convention);

for (convention_name, local_class) in convention_names
.into_iter()
.zip(convention_local_class.into_iter())
for (convention_name, local_class) in
convention_names.into_iter().zip(convention_local_class)
{
if let Some(existing) = exports.get(name.as_str())
&& from.is_none()
Expand Down
5 changes: 1 addition & 4 deletions crates/rspack_plugin_css_chunking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ async fn optimize_chunks(&self, compilation: &mut Compilation) -> Result<Option<

// Process through all modules
let start = logger.time("process through all modules");
loop {
let Some(start_module_identifier) = remaining_modules.iter().next().copied() else {
break;
};
while let Some(start_module_identifier) = remaining_modules.iter().next().copied() {
remaining_modules.shift_remove(&start_module_identifier);

#[allow(clippy::unwrap_used)]
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_esm_library/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2793,8 +2793,8 @@ var {} = {{}};
for chunk_link in link.values_mut() {
let all_chunk_used_symbols = chunk_link
.refs
.iter()
.filter_map(|(_, symbol_ref)| {
.values()
.filter_map(|symbol_ref| {
if let Ref::Symbol(symbol_ref) = symbol_ref {
Some(&symbol_ref.symbol)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_esm_library/src/optimize_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ pub(crate) fn assign_dyn_import_chunk_short_names(compilation: &mut Compilation)
}

// Sort by module identifier for deterministic ordering
candidates.sort_by(|a, b| a.1.cmp(&b.1));
candidates.sort_by_key(|a| a.1);

// Compute short names and track duplicates
// name_to_chunks: maps base_name → list of (chunk_ukey, module_identifier) in sorted order
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_esm_library/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl EsmLibraryPlugin {
let mut modules_map = IdentifierIndexMap::default();
let modules = module_graph.modules();
let mut modules = modules.collect::<Vec<_>>();
modules.sort_by(|(m1, _), (m2, _)| m1.cmp(m2));
modules.sort_by_key(|(m1, _)| *m1);
let logger = compilation.get_logger("rspack.EsmLibraryPlugin");

for (idx, (module_identifier, module)) in modules.into_iter().enumerate() {
Expand Down Expand Up @@ -300,7 +300,7 @@ async fn finish_modules(
let module_graph = compilation.get_module_graph();
let mut modules_map = IdentifierIndexMap::default();
let mut modules = module_graph.modules().collect::<Vec<_>>();
modules.sort_by(|(m1, _), (m2, _)| m1.cmp(m2));
modules.sort_by_key(|(m1, _)| *m1);
let logger = compilation.get_logger("rspack.EsmLibraryPlugin");

for (idx, (module_identifier, module)) in modules.into_iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_esm_library/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ var {} = {{}};
.namespace_object_sources
.iter()
.collect::<Vec<_>>();
namespace_object_sources.sort_by(|(a, _), (b, _)| a.cmp(b));
namespace_object_sources.sort_by_key(|(a, _)| *a);
for (_, namespace) in namespace_object_sources {
render_source.add(RawStringSource::from(format!("{namespace}\n")));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_extract_css/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl RuntimeModule for CssLoadingRuntimeModule {

let mut attr = String::default();
let mut attributes: Vec<(&String, &String)> = self.attributes.iter().collect::<Vec<_>>();
attributes.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2));
attributes.sort_unstable_by_key(|(k1, _)| *k1);

for (attr_key, attr_value) in attributes {
attr += &format!("linkTag.setAttribute({attr_key}, {attr_value});\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ pub fn esm_import_dependency_get_linking_error<T: ModuleDependency>(
return Some(create_error(msg));
}
}
#[allow(clippy::collapsible_match)]
match exports_type {
ExportsType::DefaultOnly => {
if !ids.is_empty() && ids[0] != "default" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn get_hoisted_declarations<'ast>(
};

while let Some(node) = stmt_stack.pop() {
#[allow(clippy::collapsible_match)]
match node {
Statement::Block(block) => {
for s in &block.stmts {
Expand Down
Loading
Loading