@@ -34,7 +34,7 @@ extern crate rustc_target;
3434extern crate rustc_driver;
3535
3636use std:: any:: Any ;
37- use std:: cell:: { Cell , RefCell } ;
37+ use std:: cell:: Cell ;
3838use std:: env;
3939use std:: sync:: Arc ;
4040
@@ -155,7 +155,7 @@ impl CodegenCx {
155155}
156156
157157pub struct CraneliftCodegenBackend {
158- pub config : RefCell < Option < BackendConfig > > ,
158+ pub config : Option < BackendConfig > ,
159159}
160160
161161impl CodegenBackend for CraneliftCodegenBackend {
@@ -177,13 +177,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
177177 sess. dcx ( )
178178 . fatal ( "`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift" ) ;
179179 }
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- }
187180 }
188181
189182 fn target_features ( & self , sess : & Session , _allow_unstable : bool ) -> Vec < rustc_span:: Symbol > {
@@ -221,7 +214,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
221214 need_metadata_module : bool ,
222215 ) -> Box < dyn Any > {
223216 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+ } ) ;
225221 match config. codegen_mode {
226222 CodegenMode :: Aot => driver:: aot:: run_aot ( tcx, metadata, need_metadata_module) ,
227223 CodegenMode :: Jit | CodegenMode :: JitLazy => {
@@ -369,5 +365,5 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
369365/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
370366#[ no_mangle]
371367pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
372- Box :: new ( CraneliftCodegenBackend { config : RefCell :: new ( None ) } )
368+ Box :: new ( CraneliftCodegenBackend { config : None } )
373369}
0 commit comments