@@ -36,7 +36,6 @@ use std::{
3636 } ,
3737} ;
3838
39- use atomic_refcell:: AtomicRefCell ;
4039use dashmap:: DashSet ;
4140use futures:: future:: BoxFuture ;
4241use indexmap:: IndexMap ;
@@ -72,13 +71,13 @@ use crate::{
7271 CodeGenerationJob , CodeGenerationResult , CodeGenerationResults , CompilationLogger ,
7372 CompilationLogging , CompilerOptions , CompilerPlatform , ConcatenationScope ,
7473 DependenciesDiagnosticsArtifact , DependencyCodeGeneration , DependencyId , DependencyTemplate ,
75- DependencyTemplateType , DependencyType , DerefOption , Entry , EntryData , EntryOptions ,
76- EntryRuntime , Entrypoint , ExecuteModuleId , ExtendedReferencedExport , Filename , ImportPhase ,
77- ImportVarMap , ImportedByDeferModulesArtifact , MemoryGCStorage , ModuleFactory , ModuleGraph ,
74+ DependencyTemplateType , DependencyType , Entry , EntryData , EntryOptions , EntryRuntime , Entrypoint ,
75+ ExecuteModuleId , ExtendedReferencedExport , Filename , ImportPhase , ImportVarMap ,
76+ ImportedByDeferModulesArtifact , MemoryGCStorage , ModuleFactory , ModuleGraph ,
7877 ModuleGraphCacheArtifact , ModuleIdentifier , ModuleIdsArtifact , ModuleStaticCache , PathData ,
7978 ProcessRuntimeRequirementsCacheArtifact , ResolverFactory , RuntimeGlobals , RuntimeKeyMap ,
8079 RuntimeMode , RuntimeModule , RuntimeSpec , RuntimeSpecMap , RuntimeTemplate , SharedPluginDriver ,
81- SideEffectsOptimizeArtifact , SourceType , Stats , ValueCacheVersions ,
80+ SideEffectsOptimizeArtifact , SourceType , Stats , StealCell , ValueCacheVersions ,
8281 compilation:: build_module_graph:: {
8382 BuildModuleGraphArtifact , ModuleExecutor , UpdateParam , update_module_graph,
8483 } ,
@@ -227,11 +226,11 @@ pub struct Compilation {
227226 pub runtime_template : RuntimeTemplate ,
228227
229228 // artifact for infer_async_modules_plugin
230- pub async_modules_artifact : Arc < AtomicRefCell < AsyncModulesArtifact > > ,
229+ pub async_modules_artifact : StealCell < AsyncModulesArtifact > ,
231230 // artifact for collect_dependencies_diagnostics
232- pub dependencies_diagnostics_artifact : Arc < AtomicRefCell < DependenciesDiagnosticsArtifact > > ,
231+ pub dependencies_diagnostics_artifact : StealCell < DependenciesDiagnosticsArtifact > ,
233232 // artifact for side_effects_flag_plugin
234- pub side_effects_optimize_artifact : DerefOption < SideEffectsOptimizeArtifact > ,
233+ pub side_effects_optimize_artifact : StealCell < SideEffectsOptimizeArtifact > ,
235234 // artifact for module_ids
236235 pub module_ids_artifact : ModuleIdsArtifact ,
237236 // artifact for named_chunk_ids
@@ -282,7 +281,7 @@ pub struct Compilation {
282281
283282 pub modified_files : ArcPathSet ,
284283 pub removed_files : ArcPathSet ,
285- pub build_module_graph_artifact : DerefOption < BuildModuleGraphArtifact > ,
284+ pub build_module_graph_artifact : StealCell < BuildModuleGraphArtifact > ,
286285 pub input_filesystem : Arc < dyn ReadableFileSystem > ,
287286
288287 pub intermediate_filesystem : Arc < dyn IntermediateFileSystem > ,
@@ -362,12 +361,10 @@ impl Compilation {
362361 resolver_factory,
363362 loader_resolver_factory,
364363
365- async_modules_artifact : Arc :: new ( AtomicRefCell :: new ( AsyncModulesArtifact :: default ( ) ) ) ,
364+ async_modules_artifact : StealCell :: new ( AsyncModulesArtifact :: default ( ) ) ,
366365 imported_by_defer_modules_artifact : Default :: default ( ) ,
367- dependencies_diagnostics_artifact : Arc :: new ( AtomicRefCell :: new (
368- DependenciesDiagnosticsArtifact :: default ( ) ,
369- ) ) ,
370- side_effects_optimize_artifact : DerefOption :: new ( Default :: default ( ) ) ,
366+ dependencies_diagnostics_artifact : StealCell :: new ( DependenciesDiagnosticsArtifact :: default ( ) ) ,
367+ side_effects_optimize_artifact : StealCell :: new ( Default :: default ( ) ) ,
371368 module_ids_artifact : Default :: default ( ) ,
372369 named_chunk_ids_artifact : Default :: default ( ) ,
373370 code_generation_results : Default :: default ( ) ,
@@ -408,7 +405,7 @@ impl Compilation {
408405 module_executor,
409406 in_finish_make : AtomicBool :: new ( false ) ,
410407
411- build_module_graph_artifact : DerefOption :: new ( BuildModuleGraphArtifact :: default ( ) ) ,
408+ build_module_graph_artifact : StealCell :: new ( BuildModuleGraphArtifact :: default ( ) ) ,
412409 modified_files,
413410 removed_files,
414411 input_filesystem,
@@ -428,26 +425,16 @@ impl Compilation {
428425 self . compiler_id
429426 }
430427
431- pub fn recover_module_graph_to_new_compilation ( & mut self , new_compilation : & mut Compilation ) {
432- self
433- . build_module_graph_artifact
434- . get_module_graph_mut ( )
435- . reset ( ) ;
436- std:: mem:: swap (
437- & mut self . build_module_graph_artifact ,
438- & mut new_compilation. build_module_graph_artifact ,
439- ) ;
440- }
441428 pub fn swap_build_module_graph_artifact ( & mut self , make_artifact : & mut BuildModuleGraphArtifact ) {
442- self . build_module_graph_artifact . swap ( make_artifact) ;
429+ mem :: swap ( & mut * self . build_module_graph_artifact , make_artifact) ;
443430 }
444431 pub fn get_module_graph ( & self ) -> & ModuleGraph {
445432 self . build_module_graph_artifact . get_module_graph ( )
446433 }
447434
448435 // it will return None during make phase since mg is incomplete
449436 pub fn module_by_identifier ( & self , identifier : & ModuleIdentifier ) -> Option < & BoxModule > {
450- if self . build_module_graph_artifact . is_none ( ) {
437+ if self . build_module_graph_artifact . is_stolen ( ) {
451438 return None ;
452439 }
453440 if let Some ( module) = self . get_module_graph ( ) . module_by_identifier ( identifier) {
@@ -661,23 +648,23 @@ impl Compilation {
661648 self . add_entry ( entry, options) . await ?;
662649 }
663650
664- let make_artifact = self . build_module_graph_artifact . take ( ) ;
665- self . build_module_graph_artifact . replace (
666- update_module_graph (
667- self ,
668- make_artifact ,
669- vec ! [ UpdateParam :: BuildEntry (
670- self
671- . entries
672- . values ( )
673- . flat_map ( |item| item . all_dependencies( ) )
674- . chain ( self . global_entry . all_dependencies ( ) )
675- . copied ( )
676- . collect ( ) ,
677- ) ] ,
678- )
679- . await ? ,
680- ) ;
651+ let make_artifact = self . build_module_graph_artifact . steal ( ) ;
652+ let make_artifact = update_module_graph (
653+ self ,
654+ make_artifact ,
655+ vec ! [ UpdateParam :: BuildEntry (
656+ self
657+ . entries
658+ . values ( )
659+ . flat_map ( |item| item . all_dependencies ( ) )
660+ . chain ( self . global_entry . all_dependencies( ) )
661+ . copied ( )
662+ . collect ( ) ,
663+ ) ] ,
664+ )
665+ . await ? ;
666+ self . build_module_graph_artifact = make_artifact . into ( ) ;
667+
681668 Ok ( ( ) )
682669 }
683670
@@ -712,23 +699,23 @@ impl Compilation {
712699
713700 // Recheck entry and clean useless entry
714701 // This should before finish_modules hook is called, ensure providedExports effects on new added modules
715- let make_artifact = self . build_module_graph_artifact . take ( ) ;
716- self . build_module_graph_artifact . replace (
717- update_module_graph (
718- self ,
719- make_artifact ,
720- vec ! [ UpdateParam :: BuildEntry (
721- self
722- . entries
723- . values ( )
724- . flat_map ( |item| item . all_dependencies( ) )
725- . chain ( self . global_entry . all_dependencies ( ) )
726- . copied ( )
727- . collect ( ) ,
728- ) ] ,
729- )
730- . await ? ,
731- ) ;
702+ let make_artifact = self . build_module_graph_artifact . steal ( ) ;
703+ let make_artifact = update_module_graph (
704+ self ,
705+ make_artifact ,
706+ vec ! [ UpdateParam :: BuildEntry (
707+ self
708+ . entries
709+ . values ( )
710+ . flat_map ( |item| item . all_dependencies ( ) )
711+ . chain ( self . global_entry . all_dependencies( ) )
712+ . copied ( )
713+ . collect ( ) ,
714+ ) ] ,
715+ )
716+ . await ? ;
717+ self . build_module_graph_artifact = make_artifact . into ( ) ;
718+
732719 Ok ( ( ) )
733720 }
734721
@@ -1029,19 +1016,18 @@ impl Compilation {
10291016 module_identifiers : IdentifierSet ,
10301017 f : impl Fn ( Vec < & BoxModule > ) -> T ,
10311018 ) -> Result < T > {
1032- let artifact = self . build_module_graph_artifact . take ( ) ;
1019+ let artifact = self . build_module_graph_artifact . steal ( ) ;
10331020
10341021 // https://github.com/webpack/webpack/blob/19ca74127f7668aaf60d59f4af8fcaee7924541a/lib/Compilation.js#L2462C21-L2462C25
10351022 self . module_graph_cache_artifact . unfreeze ( ) ;
10361023
1037- self . build_module_graph_artifact . replace (
1038- update_module_graph (
1039- self ,
1040- artifact,
1041- vec ! [ UpdateParam :: ForceBuildModules ( module_identifiers. clone( ) ) ] ,
1042- )
1043- . await ?,
1044- ) ;
1024+ let artifact = update_module_graph (
1025+ self ,
1026+ artifact,
1027+ vec ! [ UpdateParam :: ForceBuildModules ( module_identifiers. clone( ) ) ] ,
1028+ )
1029+ . await ?;
1030+ self . build_module_graph_artifact = artifact. into ( ) ;
10451031
10461032 let module_graph = self . get_module_graph ( ) ;
10471033 Ok ( f ( module_identifiers
0 commit comments