Skip to content

Commit 446b9b3

Browse files
committed
chore: merge origin main
2 parents fa60a57 + bbe54ce commit 446b9b3

File tree

10 files changed

+269
-97
lines changed

10 files changed

+269
-97
lines changed

crates/rspack_core/src/cache/persistent/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Cache for PersistentCache {
188188

189189
async fn before_make(&mut self, make_artifact: &mut MakeArtifact) {
190190
// TODO When does not need to pass variables through make_artifact.state, use compilation.is_rebuild to check
191-
if matches!(make_artifact.state, MakeArtifactState::Uninitialized(..)) {
191+
if matches!(make_artifact.state, MakeArtifactState::Uninitialized) {
192192
match self.make_occasion.recovery().await {
193193
Ok(artifact) => *make_artifact = artifact,
194194
Err(err) => self.warnings.push(err.to_string()),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use rspack_cacheable::{cacheable, cacheable_dyn, utils::OwnedOrRef};
2+
3+
use crate::{
4+
AffectType, AsContextDependency, AsDependencyCodeGeneration, AsModuleDependency, BoxDependency,
5+
Dependency, DependencyId,
6+
};
7+
8+
#[cacheable]
9+
#[derive(Debug, Clone, Default)]
10+
pub struct TempDependency {
11+
id: DependencyId,
12+
}
13+
14+
impl TempDependency {
15+
pub fn transform_from(dep: OwnedOrRef<BoxDependency>) -> OwnedOrRef<BoxDependency> {
16+
OwnedOrRef::Owned(Box::new(TempDependency {
17+
id: *dep.as_ref().id(),
18+
}))
19+
}
20+
}
21+
22+
#[cacheable_dyn]
23+
impl Dependency for TempDependency {
24+
fn id(&self) -> &DependencyId {
25+
&self.id
26+
}
27+
28+
fn could_affect_referencing_module(&self) -> AffectType {
29+
unreachable!()
30+
}
31+
}
32+
33+
impl AsModuleDependency for TempDependency {}
34+
impl AsDependencyCodeGeneration for TempDependency {}
35+
impl AsContextDependency for TempDependency {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod dependency;
2+
mod module;
3+
4+
pub use dependency::TempDependency;
5+
pub use module::TempModule;
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
use std::borrow::Cow;
2+
3+
use rspack_cacheable::{cacheable, cacheable_dyn, utils::OwnedOrRef};
4+
use rspack_collections::Identifiable;
5+
use rspack_error::{Result, impl_empty_diagnosable_trait};
6+
use rspack_hash::RspackHashDigest;
7+
use rspack_paths::ArcPathSet;
8+
use rspack_sources::BoxSource;
9+
use rspack_util::source_map::{ModuleSourceMapConfig, SourceMapKind};
10+
11+
use crate::{
12+
AsyncDependenciesBlockIdentifier, BoxModule, BuildInfo, BuildMeta, CodeGenerationResult,
13+
Compilation, ConcatenationScope, Context, DependenciesBlock, DependencyId, FactoryMeta, Module,
14+
ModuleGraph, ModuleIdentifier, ModuleType, RuntimeSpec, SourceType, ValueCacheVersions,
15+
};
16+
17+
#[cacheable]
18+
#[derive(Debug, Clone)]
19+
pub struct TempModule {
20+
id: ModuleIdentifier,
21+
build_info: BuildInfo,
22+
build_meta: BuildMeta,
23+
dependencies: Vec<DependencyId>,
24+
blocks: Vec<AsyncDependenciesBlockIdentifier>,
25+
}
26+
27+
impl TempModule {
28+
pub fn transform_from(module: OwnedOrRef<BoxModule>) -> OwnedOrRef<BoxModule> {
29+
let m = module.as_ref();
30+
OwnedOrRef::Owned(Box::new(Self {
31+
id: m.identifier(),
32+
build_info: m.build_info().clone(),
33+
build_meta: m.build_meta().clone(),
34+
dependencies: m.get_dependencies().to_vec(),
35+
// clean all of blocks
36+
blocks: vec![],
37+
}))
38+
}
39+
}
40+
41+
impl_empty_diagnosable_trait!(TempModule);
42+
43+
impl ModuleSourceMapConfig for TempModule {
44+
fn get_source_map_kind(&self) -> &SourceMapKind {
45+
unreachable!()
46+
}
47+
48+
fn set_source_map_kind(&mut self, _source_map: SourceMapKind) {
49+
unreachable!()
50+
}
51+
}
52+
53+
#[cacheable_dyn]
54+
#[async_trait::async_trait]
55+
impl Module for TempModule {
56+
fn factory_meta(&self) -> Option<&FactoryMeta> {
57+
unreachable!()
58+
}
59+
60+
fn set_factory_meta(&mut self, _factory_meta: FactoryMeta) {
61+
unreachable!()
62+
}
63+
64+
fn build_info(&self) -> &BuildInfo {
65+
&self.build_info
66+
}
67+
68+
fn build_info_mut(&mut self) -> &mut BuildInfo {
69+
&mut self.build_info
70+
}
71+
72+
fn build_meta(&self) -> &BuildMeta {
73+
&self.build_meta
74+
}
75+
76+
fn build_meta_mut(&mut self) -> &mut BuildMeta {
77+
&mut self.build_meta
78+
}
79+
80+
fn source_types(&self, _module_graph: &ModuleGraph) -> &[SourceType] {
81+
unreachable!()
82+
}
83+
84+
fn module_type(&self) -> &ModuleType {
85+
unreachable!()
86+
}
87+
88+
fn size(&self, _source_type: Option<&SourceType>, _compilation: Option<&Compilation>) -> f64 {
89+
unreachable!()
90+
}
91+
92+
fn source(&self) -> Option<&BoxSource> {
93+
unreachable!()
94+
}
95+
96+
fn readable_identifier(&self, _context: &Context) -> Cow<'_, str> {
97+
unreachable!()
98+
}
99+
100+
fn need_build(&self, _value_cache_versions: &ValueCacheVersions) -> bool {
101+
// return true to make sure this module always rebuild
102+
true
103+
}
104+
105+
fn depends_on(&self, _modified_file: &ArcPathSet) -> bool {
106+
// return true to make sure this module always rebuild
107+
true
108+
}
109+
110+
async fn code_generation(
111+
&self,
112+
_compilation: &Compilation,
113+
_runtime: Option<&RuntimeSpec>,
114+
_concatenation_scope: Option<ConcatenationScope>,
115+
) -> Result<CodeGenerationResult> {
116+
unreachable!()
117+
}
118+
119+
async fn get_runtime_hash(
120+
&self,
121+
_compilation: &Compilation,
122+
_runtime: Option<&RuntimeSpec>,
123+
) -> Result<RspackHashDigest> {
124+
unreachable!()
125+
}
126+
}
127+
128+
impl Identifiable for TempModule {
129+
fn identifier(&self) -> rspack_collections::Identifier {
130+
self.id
131+
}
132+
}
133+
134+
impl DependenciesBlock for TempModule {
135+
fn add_block_id(&mut self, _block: AsyncDependenciesBlockIdentifier) {
136+
unreachable!()
137+
}
138+
fn get_blocks(&self) -> &[AsyncDependenciesBlockIdentifier] {
139+
&self.blocks
140+
}
141+
fn add_dependency_id(&mut self, _dependency: DependencyId) {
142+
unreachable!()
143+
}
144+
fn remove_dependency_id(&mut self, _dependency: DependencyId) {
145+
unreachable!()
146+
}
147+
fn get_dependencies(&self) -> &[DependencyId] {
148+
&self.dependencies
149+
}
150+
}

crates/rspack_core/src/cache/persistent/occasion/make/mod.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
mod alternatives;
12
mod module_graph;
23

34
use std::sync::Arc;
45

6+
use rspack_collections::IdentifierSet;
57
use rspack_error::Result;
68

79
use super::super::{Storage, cacheable_context::CacheableContext};
810
use crate::{
9-
FileCounter,
11+
FileCounter, ModuleGraph,
1012
compilation::make::{MakeArtifact, MakeArtifactState},
1113
};
1214

@@ -57,30 +59,27 @@ impl MakeOccasion {
5759

5860
#[tracing::instrument(name = "Cache::Occasion::Make::recovery", skip_all)]
5961
pub async fn recovery(&self) -> Result<MakeArtifact> {
60-
let mut artifact = MakeArtifact::default();
61-
62-
let (partial, module_to_lazy_make, force_build_dependencies, isolated_modules) =
62+
let (partial, module_to_lazy_make, entry_dependencies) =
6363
module_graph::recovery_module_graph(&self.storage, &self.context).await?;
64-
artifact.module_graph_partial = partial;
65-
artifact.module_to_lazy_make = module_to_lazy_make;
66-
artifact.state = MakeArtifactState::Uninitialized(force_build_dependencies, isolated_modules);
6764

6865
// regenerate statistical data
69-
// TODO set make_failed_module after module.diagnostic are cacheable
70-
// make failed module include diagnostic that do not support cache, so recovery will not include failed module
71-
artifact.make_failed_module = Default::default();
66+
let mg = ModuleGraph::new([Some(&partial), None], None);
67+
// recovery make_failed_module
68+
let mut make_failed_module = IdentifierSet::default();
7269
// recovery *_dep
73-
let mg = artifact.get_module_graph();
7470
let mut file_dep = FileCounter::default();
7571
let mut context_dep = FileCounter::default();
7672
let mut missing_dep = FileCounter::default();
7773
let mut build_dep = FileCounter::default();
78-
for (_, module) in mg.modules() {
74+
for (mid, module) in mg.modules() {
7975
let build_info = module.build_info();
8076
file_dep.add_batch_file(&build_info.file_dependencies);
8177
context_dep.add_batch_file(&build_info.context_dependencies);
8278
missing_dep.add_batch_file(&build_info.missing_dependencies);
8379
build_dep.add_batch_file(&build_info.build_dependencies);
80+
if !module.diagnostics().is_empty() {
81+
make_failed_module.insert(mid);
82+
}
8483
}
8584

8685
for (_, factorize_info) in mg.dependency_factorize_info_iter() {
@@ -89,11 +88,23 @@ impl MakeOccasion {
8988
missing_dep.add_batch_file(&factorize_info.missing_dependencies());
9089
}
9190

92-
artifact.file_dependencies = file_dep;
93-
artifact.context_dependencies = context_dep;
94-
artifact.missing_dependencies = missing_dep;
95-
artifact.build_dependencies = build_dep;
91+
Ok(MakeArtifact {
92+
// write all of field here to avoid forget to update occasion when add new fields
93+
// temporary data set to default
94+
built_modules: Default::default(),
95+
revoked_modules: Default::default(),
96+
issuer_update_modules: Default::default(),
97+
98+
state: MakeArtifactState::Initialized,
99+
module_graph_partial: partial,
100+
module_to_lazy_make,
96101

97-
Ok(artifact)
102+
make_failed_module,
103+
entry_dependencies,
104+
file_dependencies: file_dep,
105+
context_dependencies: context_dep,
106+
missing_dependencies: missing_dep,
107+
build_dependencies: build_dep,
108+
})
98109
}
99110
}

0 commit comments

Comments
 (0)