@@ -30,14 +30,16 @@ extern crate rustc_target;
30
30
extern crate rustc_driver;
31
31
32
32
use std:: any:: Any ;
33
- use std:: cell:: { Cell , RefCell } ;
33
+ use std:: cell:: Cell ;
34
34
use std:: sync:: Arc ;
35
+ use std:: sync:: RwLock ;
35
36
36
37
use cranelift_codegen:: isa:: TargetIsa ;
37
38
use cranelift_codegen:: settings:: { self , Configurable } ;
38
39
use rustc_codegen_ssa:: traits:: CodegenBackend ;
39
40
use rustc_codegen_ssa:: CodegenResults ;
40
41
use rustc_data_structures:: profiling:: SelfProfilerRef ;
42
+ use rustc_data_structures:: sync:: { downcast_box_any_dyn_send, DynSend } ;
41
43
use rustc_errors:: ErrorGuaranteed ;
42
44
use rustc_metadata:: EncodedMetadata ;
43
45
use rustc_middle:: dep_graph:: { WorkProduct , WorkProductId } ;
@@ -165,7 +167,7 @@ impl CodegenCx {
165
167
}
166
168
167
169
pub struct CraneliftCodegenBackend {
168
- pub config : RefCell < Option < BackendConfig > > ,
170
+ pub config : RwLock < Option < BackendConfig > > ,
169
171
}
170
172
171
173
impl CodegenBackend for CraneliftCodegenBackend {
@@ -183,7 +185,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
183
185
}
184
186
}
185
187
186
- let mut config = self . config . borrow_mut ( ) ;
188
+ let mut config = self . config . write ( ) . unwrap ( ) ;
187
189
if config. is_none ( ) {
188
190
let new_config = BackendConfig :: from_opts ( & sess. opts . cg . llvm_args )
189
191
. unwrap_or_else ( |err| sess. dcx ( ) . fatal ( err) ) ;
@@ -213,9 +215,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
213
215
tcx : TyCtxt < ' _ > ,
214
216
metadata : EncodedMetadata ,
215
217
need_metadata_module : bool ,
216
- ) -> Box < dyn Any > {
218
+ ) -> Box < dyn Any + DynSend > {
217
219
tcx. dcx ( ) . abort_if_errors ( ) ;
218
- let config = self . config . borrow ( ) . clone ( ) . unwrap ( ) ;
220
+ let config = self . config . read ( ) . unwrap ( ) . clone ( ) . unwrap ( ) ;
219
221
match config. codegen_mode {
220
222
CodegenMode :: Aot => driver:: aot:: run_aot ( tcx, config, metadata, need_metadata_module) ,
221
223
CodegenMode :: Jit | CodegenMode :: JitLazy => {
@@ -230,14 +232,13 @@ impl CodegenBackend for CraneliftCodegenBackend {
230
232
231
233
fn join_codegen (
232
234
& self ,
233
- ongoing_codegen : Box < dyn Any > ,
235
+ ongoing_codegen : Box < dyn Any + DynSend > ,
234
236
sess : & Session ,
235
237
_outputs : & OutputFilenames ,
236
238
) -> ( CodegenResults , FxIndexMap < WorkProductId , WorkProduct > ) {
237
- ongoing_codegen
238
- . downcast :: < driver:: aot:: OngoingCodegen > ( )
239
+ downcast_box_any_dyn_send :: < driver:: aot:: OngoingCodegen > ( ongoing_codegen)
239
240
. unwrap ( )
240
- . join ( sess, self . config . borrow ( ) . as_ref ( ) . unwrap ( ) )
241
+ . join ( sess, self . config . read ( ) . unwrap ( ) . as_ref ( ) . unwrap ( ) )
241
242
}
242
243
243
244
fn link (
@@ -350,5 +351,5 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
350
351
/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
351
352
#[ no_mangle]
352
353
pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
353
- Box :: new ( CraneliftCodegenBackend { config : RefCell :: new ( None ) } )
354
+ Box :: new ( CraneliftCodegenBackend { config : RwLock :: new ( None ) } )
354
355
}
0 commit comments