@@ -30,14 +30,16 @@ extern crate rustc_target;
3030extern crate rustc_driver;
3131
3232use std:: any:: Any ;
33- use std:: cell:: { Cell , RefCell } ;
33+ use std:: cell:: Cell ;
3434use std:: sync:: Arc ;
35+ use std:: sync:: RwLock ;
3536
3637use cranelift_codegen:: isa:: TargetIsa ;
3738use cranelift_codegen:: settings:: { self , Configurable } ;
3839use rustc_codegen_ssa:: traits:: CodegenBackend ;
3940use rustc_codegen_ssa:: CodegenResults ;
4041use rustc_data_structures:: profiling:: SelfProfilerRef ;
42+ use rustc_data_structures:: sync:: { downcast_box_any_dyn_send, DynSend } ;
4143use rustc_errors:: ErrorGuaranteed ;
4244use rustc_metadata:: EncodedMetadata ;
4345use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
@@ -165,7 +167,7 @@ impl CodegenCx {
165167}
166168
167169pub struct CraneliftCodegenBackend {
168- pub config : RefCell < Option < BackendConfig > > ,
170+ pub config : RwLock < Option < BackendConfig > > ,
169171}
170172
171173impl CodegenBackend for CraneliftCodegenBackend {
@@ -183,7 +185,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
183185 }
184186 }
185187
186- let mut config = self . config . borrow_mut ( ) ;
188+ let mut config = self . config . write ( ) . unwrap ( ) ;
187189 if config. is_none ( ) {
188190 let new_config = BackendConfig :: from_opts ( & sess. opts . cg . llvm_args )
189191 . unwrap_or_else ( |err| sess. dcx ( ) . fatal ( err) ) ;
@@ -213,9 +215,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
213215 tcx : TyCtxt < ' _ > ,
214216 metadata : EncodedMetadata ,
215217 need_metadata_module : bool ,
216- ) -> Box < dyn Any > {
218+ ) -> Box < dyn Any + DynSend > {
217219 tcx. dcx ( ) . abort_if_errors ( ) ;
218- let config = self . config . borrow ( ) . clone ( ) . unwrap ( ) ;
220+ let config = self . config . read ( ) . unwrap ( ) . clone ( ) . unwrap ( ) ;
219221 match config. codegen_mode {
220222 CodegenMode :: Aot => driver:: aot:: run_aot ( tcx, config, metadata, need_metadata_module) ,
221223 CodegenMode :: Jit | CodegenMode :: JitLazy => {
@@ -230,14 +232,13 @@ impl CodegenBackend for CraneliftCodegenBackend {
230232
231233 fn join_codegen (
232234 & self ,
233- ongoing_codegen : Box < dyn Any > ,
235+ ongoing_codegen : Box < dyn Any + DynSend > ,
234236 sess : & Session ,
235237 _outputs : & OutputFilenames ,
236238 ) -> ( CodegenResults , FxIndexMap < WorkProductId , WorkProduct > ) {
237- ongoing_codegen
238- . downcast :: < driver:: aot:: OngoingCodegen > ( )
239+ downcast_box_any_dyn_send :: < driver:: aot:: OngoingCodegen > ( ongoing_codegen)
239240 . unwrap ( )
240- . join ( sess, self . config . borrow ( ) . as_ref ( ) . unwrap ( ) )
241+ . join ( sess, self . config . read ( ) . unwrap ( ) . as_ref ( ) . unwrap ( ) )
241242 }
242243
243244 fn link (
@@ -350,5 +351,5 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
350351/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
351352#[ no_mangle]
352353pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
353- Box :: new ( CraneliftCodegenBackend { config : RefCell :: new ( None ) } )
354+ Box :: new ( CraneliftCodegenBackend { config : RwLock :: new ( None ) } )
354355}
0 commit comments