Skip to main content

rspack_core/artifacts/
mod.rs

1mod async_modules_artifact;
2mod build_chunk_graph_artifact;
3mod build_module_graph_artifact;
4mod cgc_runtime_requirements_artifact;
5mod cgm_hash_artifact;
6mod cgm_runtime_requirement_artifact;
7mod chunk_hashes_artifact;
8mod chunk_ids_artifact;
9mod chunk_render_artifact;
10mod chunk_render_cache_artifact;
11mod code_generate_cache_artifact;
12mod code_generation_results;
13mod dependencies_diagnostics_artifact;
14mod imported_by_defer_modules_artifact;
15mod module_graph_cache_artifact;
16mod module_ids_artifact;
17mod module_static_cache_artifact;
18mod process_runtime_requirements_cache_artifact;
19mod side_effects_do_optimize_artifact;
20
21use std::{mem, sync::Arc};
22
23use atomic_refcell::AtomicRefCell;
24
25use crate::incremental::{Incremental, IncrementalPasses};
26
27/// Trait for artifacts used in incremental compilation.
28///
29/// This trait associates each artifact with its corresponding incremental pass.
30pub trait ArtifactExt: Sized {
31  /// The incremental pass associated with this artifact.
32  ///
33  /// This constant defines which incremental compilation pass this artifact
34  /// belongs to.
35  const PASS: IncrementalPasses;
36
37  /// Determines whether this artifact should be recovered from the previous compilation.
38  ///
39  /// Returns `true` if the artifact's pass is empty (always recover) or if
40  /// the incremental system has readable mutations for this artifact's pass.
41  fn should_recover(incremental: &Incremental) -> bool {
42    incremental.mutations_readable(Self::PASS)
43  }
44
45  /// Recovers the artifact from the old compilation to the new compilation
46  /// if the incremental pass allows it.
47  fn recover(incremental: &Incremental, new: &mut Self, old: &mut Self) {
48    if Self::should_recover(incremental) {
49      mem::swap(new, old);
50    }
51  }
52}
53
54/// Recovers an artifact from the old compilation to the new compilation
55/// if the incremental pass allows it.
56pub fn recover_artifact<T: ArtifactExt>(incremental: &Incremental, new: &mut T, old: &mut T) {
57  T::recover(incremental, new, old);
58}
59
60// Implementation for Box<T> - used when "napi" feature is disabled
61// where BindingCell<T> is a type alias for Box<T>
62#[cfg(not(feature = "napi"))]
63impl<T: ArtifactExt> ArtifactExt for Box<T> {
64  const PASS: IncrementalPasses = T::PASS;
65
66  fn recover(incremental: &Incremental, new: &mut Self, old: &mut Self) {
67    if Self::should_recover(incremental) {
68      mem::swap(new, old);
69    }
70  }
71}
72
73// Implementation for BindingCell<T> - used when "napi" feature is enabled
74#[cfg(feature = "napi")]
75impl<T: ArtifactExt + Into<crate::BindingCell<T>>> ArtifactExt for crate::BindingCell<T> {
76  const PASS: IncrementalPasses = T::PASS;
77
78  fn recover(incremental: &Incremental, new: &mut Self, old: &mut Self) {
79    if Self::should_recover(incremental) {
80      mem::swap(new, old);
81    }
82  }
83}
84
85// Implementation for Arc<AtomicRefCell<T>> - used for shared artifacts
86impl<T: ArtifactExt> ArtifactExt for Arc<AtomicRefCell<T>> {
87  const PASS: IncrementalPasses = T::PASS;
88
89  fn recover(incremental: &Incremental, new: &mut Self, old: &mut Self) {
90    if Self::should_recover(incremental) {
91      mem::swap(new, old);
92    }
93  }
94}
95
96pub use async_modules_artifact::AsyncModulesArtifact;
97pub(crate) use build_chunk_graph_artifact::use_code_splitting_cache;
98pub use build_chunk_graph_artifact::*;
99pub use build_module_graph_artifact::*;
100pub use cgc_runtime_requirements_artifact::CgcRuntimeRequirementsArtifact;
101pub use cgm_hash_artifact::*;
102pub use cgm_runtime_requirement_artifact::*;
103pub use chunk_hashes_artifact::*;
104pub use chunk_ids_artifact::*;
105pub use chunk_render_artifact::ChunkRenderArtifact;
106pub use chunk_render_cache_artifact::ChunkRenderCacheArtifact;
107pub use code_generate_cache_artifact::CodeGenerateCacheArtifact;
108pub use code_generation_results::*;
109pub use dependencies_diagnostics_artifact::DependenciesDiagnosticsArtifact;
110pub use imported_by_defer_modules_artifact::ImportedByDeferModulesArtifact;
111pub use module_graph_cache_artifact::*;
112pub use module_ids_artifact::ModuleIdsArtifact;
113pub use module_static_cache_artifact::*;
114pub use process_runtime_requirements_cache_artifact::ProcessRuntimeRequirementsCacheArtifact;
115pub use side_effects_do_optimize_artifact::*;