@@ -34,7 +34,7 @@ extern crate rustc_target;
34
34
extern crate rustc_driver;
35
35
36
36
use std:: any:: Any ;
37
- use std:: cell:: { Cell , RefCell } ;
37
+ use std:: cell:: Cell ;
38
38
use std:: env;
39
39
use std:: sync:: Arc ;
40
40
@@ -155,7 +155,7 @@ impl CodegenCx {
155
155
}
156
156
157
157
pub struct CraneliftCodegenBackend {
158
- pub config : RefCell < Option < BackendConfig > > ,
158
+ pub config : Option < BackendConfig > ,
159
159
}
160
160
161
161
impl CodegenBackend for CraneliftCodegenBackend {
@@ -177,13 +177,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
177
177
sess. dcx ( )
178
178
. fatal ( "`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift" ) ;
179
179
}
180
-
181
- let mut config = self . config . borrow_mut ( ) ;
182
- if config. is_none ( ) {
183
- let new_config = BackendConfig :: from_opts ( & sess. opts . cg . llvm_args )
184
- . unwrap_or_else ( |err| sess. dcx ( ) . fatal ( err) ) ;
185
- * config = Some ( new_config) ;
186
- }
187
180
}
188
181
189
182
fn target_features ( & self , sess : & Session , _allow_unstable : bool ) -> Vec < rustc_span:: Symbol > {
@@ -221,7 +214,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
221
214
need_metadata_module : bool ,
222
215
) -> Box < dyn Any > {
223
216
tcx. dcx ( ) . abort_if_errors ( ) ;
224
- let config = self . config . borrow ( ) . clone ( ) . unwrap ( ) ;
217
+ let config = self . config . clone ( ) . unwrap_or_else ( || {
218
+ BackendConfig :: from_opts ( & tcx. sess . opts . cg . llvm_args )
219
+ . unwrap_or_else ( |err| tcx. sess . dcx ( ) . fatal ( err) )
220
+ } ) ;
225
221
match config. codegen_mode {
226
222
CodegenMode :: Aot => driver:: aot:: run_aot ( tcx, metadata, need_metadata_module) ,
227
223
CodegenMode :: Jit | CodegenMode :: JitLazy => {
@@ -369,5 +365,5 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
369
365
/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
370
366
#[ no_mangle]
371
367
pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
372
- Box :: new ( CraneliftCodegenBackend { config : RefCell :: new ( None ) } )
368
+ Box :: new ( CraneliftCodegenBackend { config : None } )
373
369
}
0 commit comments