@@ -4,7 +4,7 @@ use std::{
44 ptr:: NonNull ,
55 sync:: {
66 atomic:: { AtomicUsize , Ordering } ,
7- Arc , Mutex ,
7+ Arc ,
88 } ,
99} ;
1010
@@ -143,7 +143,7 @@ pub struct NormalModule {
143143 #[ cacheable( with=AsMap ) ]
144144 cached_source_sizes : DashMap < SourceType , f64 , BuildHasherDefault < FxHasher > > ,
145145 #[ cacheable( with=Skip ) ]
146- diagnostics : Mutex < Vec < Diagnostic > > ,
146+ diagnostics : Vec < Diagnostic > ,
147147
148148 code_generation_dependencies : Option < Vec < Box < dyn ModuleDependency > > > ,
149149 presentational_dependencies : Option < Vec < Box < dyn DependencyTemplate > > > ,
@@ -231,7 +231,7 @@ impl NormalModule {
231231 debug_id : DEBUG_ID . fetch_add ( 1 , Ordering :: Relaxed ) ,
232232
233233 cached_source_sizes : DashMap :: default ( ) ,
234- diagnostics : Mutex :: new ( Default :: default ( ) ) ,
234+ diagnostics : Default :: default ( ) ,
235235 code_generation_dependencies : None ,
236236 presentational_dependencies : None ,
237237 factory_meta : None ,
@@ -371,11 +371,6 @@ impl Module for NormalModule {
371371 & self . module_type
372372 }
373373
374- fn get_diagnostics ( & self ) -> Vec < Diagnostic > {
375- let guard = self . diagnostics . lock ( ) . expect ( "should have diagnostics" ) ;
376- guard. clone ( )
377- }
378-
379374 fn source_types ( & self ) -> & [ SourceType ] {
380375 self . parser_and_generator . source_types ( )
381376 }
@@ -408,8 +403,6 @@ impl Module for NormalModule {
408403 build_context : BuildContext ,
409404 _compilation : Option < & Compilation > ,
410405 ) -> Result < BuildResult > {
411- self . clear_diagnostics ( ) ;
412-
413406 // so does webpack
414407 self . parsed = true ;
415408
@@ -545,7 +538,7 @@ impl Module for NormalModule {
545538 if no_parse {
546539 self . parsed = false ;
547540 self . original_source = Some ( original_source. clone ( ) ) ;
548- self . source = NormalModuleSource :: new_built ( original_source, self . clone_diagnostics ( ) ) ;
541+ self . source = NormalModuleSource :: new_built ( original_source, self . diagnostics . clone ( ) ) ;
549542 self . code_generation_dependencies = Some ( Vec :: new ( ) ) ;
550543 self . presentational_dependencies = Some ( Vec :: new ( ) ) ;
551544
@@ -607,7 +600,7 @@ impl Module for NormalModule {
607600 // Only side effects used in code_generate can stay here
608601 // Other side effects should be set outside use_cache
609602 self . original_source = Some ( source. clone ( ) ) ;
610- self . source = NormalModuleSource :: new_built ( source, self . clone_diagnostics ( ) ) ;
603+ self . source = NormalModuleSource :: new_built ( source, self . diagnostics . clone ( ) ) ;
611604 self . code_generation_dependencies = Some ( code_generation_dependencies) ;
612605 self . presentational_dependencies = Some ( presentational_dependencies) ;
613606
@@ -798,30 +791,16 @@ impl Module for NormalModule {
798791}
799792
800793impl Diagnosable for NormalModule {
801- fn add_diagnostic ( & self , diagnostic : Diagnostic ) {
802- self
803- . diagnostics
804- . lock ( )
805- . expect ( "should be able to lock diagnostics" )
806- . push ( diagnostic) ;
794+ fn add_diagnostic ( & mut self , diagnostic : Diagnostic ) {
795+ self . diagnostics . push ( diagnostic) ;
807796 }
808797
809- fn add_diagnostics ( & self , mut diagnostics : Vec < Diagnostic > ) {
810- self
811- . diagnostics
812- . lock ( )
813- . expect ( "should be able to lock diagnostics" )
814- . append ( & mut diagnostics) ;
798+ fn add_diagnostics ( & mut self , mut diagnostics : Vec < Diagnostic > ) {
799+ self . diagnostics . append ( & mut diagnostics) ;
815800 }
816801
817- fn clone_diagnostics ( & self ) -> Vec < Diagnostic > {
818- self
819- . diagnostics
820- . lock ( )
821- . expect ( "should be able to lock diagnostics" )
822- . iter ( )
823- . cloned ( )
824- . collect ( )
802+ fn diagnostics ( & self ) -> Cow < [ Diagnostic ] > {
803+ Cow :: Borrowed ( & self . diagnostics )
825804 }
826805}
827806
@@ -851,12 +830,4 @@ impl NormalModule {
851830 }
852831 Ok ( RawStringSource :: from ( content. into_string_lossy ( ) ) . boxed ( ) )
853832 }
854-
855- fn clear_diagnostics ( & mut self ) {
856- self
857- . diagnostics
858- . lock ( )
859- . expect ( "should be able to lock diagnostics" )
860- . clear ( )
861- }
862833}
0 commit comments