Skip to content

Commit 5d5cd2a

Browse files
committed
Avoid RefCell in CodegenBackend
1 parent bd209ed commit 5d5cd2a

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern crate rustc_target;
3434
extern crate rustc_driver;
3535

3636
use std::any::Any;
37-
use std::cell::{Cell, RefCell};
37+
use std::cell::Cell;
3838
use std::env;
3939
use std::sync::Arc;
4040

@@ -155,7 +155,7 @@ impl CodegenCx {
155155
}
156156

157157
pub struct CraneliftCodegenBackend {
158-
pub config: RefCell<Option<BackendConfig>>,
158+
pub config: Option<BackendConfig>,
159159
}
160160

161161
impl 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]
371367
pub 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

Comments
 (0)