Skip to content
Closed
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
4 changes: 2 additions & 2 deletions crates/rspack_binding_api/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl JsCompilation {
.into_iter()
.map(|dependency_id| {
let dependency = module_graph.dependency_by_id(&dependency_id);
if let Some(factorize_info) = FactorizeInfo::get_from(dependency)
if let Some(factorize_info) = FactorizeInfo::get_from(dependency.as_ref())
&& let Some(diagnostic) = factorize_info.diagnostics().first()
{
return Either::A(diagnostic.to_string());
Expand Down Expand Up @@ -942,7 +942,7 @@ impl JsCompilation {
.into_iter()
.map(|dependency_id| {
let dependency = module_graph.dependency_by_id(&dependency_id);
if let Some(factorize_info) = FactorizeInfo::get_from(dependency)
if let Some(factorize_info) = FactorizeInfo::get_from(dependency.as_ref())
&& let Some(diagnostic) = factorize_info.diagnostics().first()
{
return Either::A(diagnostic.to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl BuildModuleGraphArtifact {
let dep_diagnostics = self.make_failed_dependencies.iter().flat_map(|dep_id| {
let dep = mg.dependency_by_id(dep_id);
let origin_module_identifier = mg.get_parent_module(dep_id);
FactorizeInfo::get_from(dep)
FactorizeInfo::get_from(dep.as_ref())
.expect("should have factorize info")
.diagnostics()
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl MakeOccasion {
// recovery make_failed_dependencies
let mut make_failed_dependencies = FxHashSet::default();
for (dep_id, dep) in mg.dependencies() {
if let Some(info) = FactorizeInfo::get_from(dep) {
if let Some(info) = FactorizeInfo::get_from(dep.as_ref()) {
if !info.is_success() {
make_failed_dependencies.insert(*dep_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::{
atomic::{AtomicUsize, Ordering},
};

use dyn_clone::clone_box;
use rayon::prelude::*;
use rspack_cacheable::{cacheable, utils::OwnedOrRef};
use rspack_collections::IdentifierSet;
Expand Down Expand Up @@ -71,7 +72,7 @@ pub fn save_module_graph(
.par_iter()
.map(|dep_id| {
(
mg.dependency_by_id(dep_id).into(),
clone_box(mg.dependency_by_id(dep_id).as_ref()).into(),
mg.get_parent_block(dep_id).map(Into::into),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod factorize;
pub mod lazy;
pub mod process_dependencies;

use dyn_clone::clone_box;
use rspack_error::Result;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

Expand Down Expand Up @@ -47,13 +48,13 @@ pub async fn repair(
Box::new(factorize::FactorizeTask {
compiler_id: compilation.compiler_id(),
compilation_id: compilation.id(),
module_factory: compilation.get_dependency_factory(dependency),
module_factory: compilation.get_dependency_factory(dependency.as_ref()),
original_module_identifier: None,
original_module_source: None,
issuer: None,
issuer_layer: None,
original_module_context: None,
dependencies: vec![dependency.clone()],
dependencies: vec![clone_box(dependency.as_ref())],
resolve_options: None,
options: compilation.options.clone(),
resolver_factory: compilation.resolver_factory.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use dyn_clone::clone_box;
use rustc_hash::FxHashMap as HashMap;

use super::{TaskContext, factorize::FactorizeTask};
Expand Down Expand Up @@ -66,7 +67,7 @@ impl Task<TaskContext> for ProcessDependenciesTask {
sorted_dependencies
.entry(resource_identifier)
.or_insert(vec![])
.push(dependency.clone());
.push(clone_box(dependency.as_ref()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Task<ExecutorTaskContext> for ExecuteTask {
for dep_id in module.get_dependencies() {
if !has_error && make_failed_dependencies.contains(dep_id) {
let dep = mg.dependency_by_id(dep_id);
let diagnostics = FactorizeInfo::get_from(dep)
let diagnostics = FactorizeInfo::get_from(dep.as_ref())
.expect("should have factorize info")
.diagnostics();
let errors: Vec<_> = diagnostics
Expand Down
10 changes: 5 additions & 5 deletions crates/rspack_core/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ use crate::{
ChunkRenderCacheArtifact, ChunkRenderResult, ChunkUkey, CodeGenerateCacheArtifact,
CodeGenerationJob, CodeGenerationResult, CodeGenerationResults, CompilationLogger,
CompilationLogging, CompilerOptions, CompilerPlatform, ConcatenationScope,
DependenciesDiagnosticsArtifact, DependencyId, DependencyTemplate, DependencyTemplateType,
DependencyType, Entry, EntryData, EntryOptions, EntryRuntime, Entrypoint, ExecuteModuleId,
ExportsInfoArtifact, ExtendedReferencedExport, Filename, ImportPhase, ImportVarMap,
ImportedByDeferModulesArtifact, MemoryGCStorage, ModuleFactory, ModuleGraph,
DependenciesDiagnosticsArtifact, Dependency, DependencyId, DependencyTemplate,
DependencyTemplateType, DependencyType, Entry, EntryData, EntryOptions, EntryRuntime, Entrypoint,
ExecuteModuleId, ExportsInfoArtifact, ExtendedReferencedExport, Filename, ImportPhase,
ImportVarMap, ImportedByDeferModulesArtifact, MemoryGCStorage, ModuleFactory, ModuleGraph,
ModuleGraphCacheArtifact, ModuleIdentifier, ModuleIdsArtifact, ModuleStaticCache, PathData,
ProcessRuntimeRequirementsCacheArtifact, ResolverFactory, RuntimeGlobals, RuntimeKeyMap,
RuntimeMode, RuntimeModule, RuntimeSpec, RuntimeSpecMap, RuntimeTemplate, SharedPluginDriver,
Expand Down Expand Up @@ -1216,7 +1216,7 @@ impl Compilation {
.insert(dependency_type, module_factory);
}

pub fn get_dependency_factory(&self, dependency: &BoxDependency) -> Arc<dyn ModuleFactory> {
pub fn get_dependency_factory(&self, dependency: &dyn Dependency) -> Arc<dyn ModuleFactory> {
let dependency_type = dependency.dependency_type();
self
.dependency_factories
Expand Down
42 changes: 21 additions & 21 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ use swc_experimental_ecma_semantic::resolver::{Semantic, resolver};
use swc_node_comments::SwcComments;

use crate::{
AsyncDependenciesBlockIdentifier, BoxDependency, BoxDependencyTemplate, BoxModule,
BoxModuleDependency, BuildContext, BuildInfo, BuildMeta, BuildMetaDefaultObject,
BuildMetaExportsType, BuildResult, ChunkGraph, ChunkInitFragments, ChunkRenderContext,
CodeGenerationDataTopLevelDeclarations, CodeGenerationExportsFinalNames,
CodeGenerationPublicPathAutoReplace, CodeGenerationResult, Compilation, ConcatenatedModuleIdent,
ConcatenationScope, ConditionalInitFragment, ConnectionState, Context, DEFAULT_EXPORT,
DEFAULT_EXPORT_ATOM, DependenciesBlock, DependencyId, DependencyType, ExportInfoHashKey,
ExportProvided, ExportsArgument, ExportsInfoArtifact, ExportsInfoGetter, ExportsType,
FactoryMeta, GetUsedNameParam, ImportedByDeferModulesArtifact, InitFragment, InitFragmentStage,
LibIdentOptions, Module, ModuleArgument, ModuleCodeGenerationContext, ModuleGraph,
ModuleGraphCacheArtifact, ModuleGraphConnection, ModuleIdentifier, ModuleLayer,
ModuleStaticCache, ModuleType, NAMESPACE_OBJECT_EXPORT, ParserOptions, PrefetchExportsInfoMode,
Resolve, RuntimeCondition, RuntimeGlobals, RuntimeSpec, SourceType, URLStaticMode, UsageState,
UsedName, UsedNameItem, escape_identifier, filter_runtime, find_target, get_runtime_key,
impl_source_map_config, merge_runtime_condition, merge_runtime_condition_non_false,
module_update_hash, property_access, property_name,
render_make_deferred_namespace_mode_from_exports_type, reserved_names::RESERVED_NAMES,
subtract_runtime_condition, to_identifier_with_escaped, to_normal_comment,
AsyncDependenciesBlockIdentifier, BoxDependencyTemplate, BoxModule, BoxModuleDependency,
BuildContext, BuildInfo, BuildMeta, BuildMetaDefaultObject, BuildMetaExportsType, BuildResult,
ChunkGraph, ChunkInitFragments, ChunkRenderContext, CodeGenerationDataTopLevelDeclarations,
CodeGenerationExportsFinalNames, CodeGenerationPublicPathAutoReplace, CodeGenerationResult,
Compilation, ConcatenatedModuleIdent, ConcatenationScope, ConditionalInitFragment,
ConnectionState, Context, DEFAULT_EXPORT, DEFAULT_EXPORT_ATOM, DependenciesBlock, Dependency,
DependencyId, DependencyType, ExportInfoHashKey, ExportProvided, ExportsArgument,
ExportsInfoArtifact, ExportsInfoGetter, ExportsType, FactoryMeta, GetUsedNameParam,
ImportedByDeferModulesArtifact, InitFragment, InitFragmentStage, LibIdentOptions, Module,
ModuleArgument, ModuleCodeGenerationContext, ModuleGraph, ModuleGraphCacheArtifact,
ModuleGraphConnection, ModuleIdentifier, ModuleLayer, ModuleStaticCache, ModuleType,
NAMESPACE_OBJECT_EXPORT, ParserOptions, PrefetchExportsInfoMode, Resolve, RuntimeCondition,
RuntimeGlobals, RuntimeSpec, SourceType, URLStaticMode, UsageState, UsedName, UsedNameItem,
escape_identifier, filter_runtime, find_target, get_runtime_key, impl_source_map_config,
merge_runtime_condition, merge_runtime_condition_non_false, module_update_hash, property_access,
property_name, render_make_deferred_namespace_mode_from_exports_type,
reserved_names::RESERVED_NAMES, subtract_runtime_condition, to_identifier_with_escaped,
to_normal_comment,
};

type ExportsDefinitionArgs = Vec<(String, String)>;
Expand Down Expand Up @@ -799,7 +799,7 @@ impl Module for ConcatenatedModule {
for dep_id in module.get_dependencies().iter() {
let dep = module_graph.dependency_by_id(dep_id);
let module_id_of_dep = module_graph.module_identifier_by_dependency_id(dep_id);
if !is_esm_dep_like(dep) || !modules.contains(&module_id_of_dep) {
if !is_esm_dep_like(dep.as_ref()) || !modules.contains(&module_id_of_dep) {
self.dependencies.push(*dep_id);
}
}
Expand Down Expand Up @@ -2221,7 +2221,7 @@ impl ConcatenatedModule {
.into_iter()
.filter_map(|connection| {
let dep = mg.dependency_by_id(&connection.dependency_id);
if !is_esm_dep_like(dep) {
if !is_esm_dep_like(dep.as_ref()) {
return None;
}
let ref_module = mg
Expand Down Expand Up @@ -3117,7 +3117,7 @@ impl ConcatenatedModule {
}
}

pub fn is_esm_dep_like(dep: &BoxDependency) -> bool {
pub fn is_esm_dep_like(dep: &dyn Dependency) -> bool {
matches!(
dep.dependency_type(),
DependencyType::EsmImportSpecifier
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_core/src/dependency/dependency_trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, fmt::Debug};
use std::{any::Any, fmt::Debug, sync::Arc};

use dyn_clone::{DynClone, clone_trait_object};
use rspack_cacheable::cacheable_dyn;
Expand Down Expand Up @@ -149,3 +149,4 @@ impl dyn Dependency + '_ {
clone_trait_object!(Dependency);

pub type BoxDependency = Box<dyn Dependency>;
pub type ArcDependency = Arc<dyn Dependency>;
6 changes: 3 additions & 3 deletions crates/rspack_core/src/dependency/factorize_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rspack_cacheable::cacheable;
use rspack_error::Diagnostic;
use rspack_paths::ArcPathSet;

use super::{BoxDependency, DependencyId};
use super::{Dependency, DependencyId};

#[cacheable]
#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -31,7 +31,7 @@ impl FactorizeInfo {
}
}

pub fn get_from(dep: &BoxDependency) -> Option<&FactorizeInfo> {
pub fn get_from(dep: &dyn Dependency) -> Option<&FactorizeInfo> {
if let Some(d) = dep.as_context_dependency() {
Some(d.factorize_info())
} else if let Some(d) = dep.as_module_dependency() {
Expand All @@ -41,7 +41,7 @@ impl FactorizeInfo {
}
}

pub fn revoke(dep: &mut BoxDependency) -> Option<FactorizeInfo> {
pub fn revoke(dep: &mut dyn Dependency) -> Option<FactorizeInfo> {
if let Some(d) = dep.as_context_dependency_mut() {
Some(std::mem::take(d.factorize_info_mut()))
} else if let Some(d) = dep.as_module_dependency_mut() {
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/incremental/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use rspack_collections::{IdentifierSet, UkeySet};

use crate::{
AffectType, BoxDependency, ChunkUkey, Compilation, DependencyId, ModuleGraph, ModuleIdentifier,
AffectType, ChunkUkey, Compilation, Dependency, DependencyId, ModuleGraph, ModuleIdentifier,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -254,7 +254,7 @@ fn compute_affected_modules_with_module_graph(
built_modules: IdentifierSet,
built_dependencies: UkeySet<DependencyId>,
) -> IdentifierSet {
fn reduce_affect_type<'a>(dependencies: impl Iterator<Item = &'a BoxDependency>) -> AffectType {
fn reduce_affect_type<'a>(dependencies: impl Iterator<Item = &'a dyn Dependency>) -> AffectType {
let mut affected = AffectType::False;
for dependency in dependencies {
match dependency.could_affect_referencing_module() {
Expand Down Expand Up @@ -285,7 +285,7 @@ fn compute_affected_modules_with_module_graph(
match reduce_affect_type(
connections
.iter()
.map(|c| module_graph.dependency_by_id(&c.dependency_id)),
.map(|c| module_graph.dependency_by_id(&c.dependency_id).as_ref()),
) {
AffectType::False => None,
AffectType::True => Some(AffectedModuleKind::Direct(referencing_module)),
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/module_graph/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
///
/// This module provides restricted access to potentially unsafe ModuleGraph operations
/// that should only be used in specific contexts where items may legitimately not exist.
use crate::{BoxDependency, DependencyId, ModuleGraph, ModuleGraphModule, ModuleIdentifier};
use crate::{ArcDependency, DependencyId, ModuleGraph, ModuleGraphModule, ModuleIdentifier};

/// Try to get a dependency by ID, returning None if not found.
///
Expand All @@ -30,7 +30,7 @@ use crate::{BoxDependency, DependencyId, ModuleGraph, ModuleGraphModule, ModuleI
pub fn try_dependency_by_id<'a>(
module_graph: &'a ModuleGraph,
dependency_id: &DependencyId,
) -> Option<&'a BoxDependency> {
) -> Option<&'a ArcDependency> {
module_graph.inner.dependencies.get(dependency_id)
}

Expand Down
Loading
Loading