about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-11-21 12:48:12 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-11-21 12:48:12 +0000
commit5d5cd2a22b2ac93dc53a982285fbe31eed341fc8 (patch)
tree75091ce96ad291eb6b61286d3f8967d663b431e3 /src
parentbd209edb7df38bffcea8ab3f3b417ae1ff2d83b1 (diff)
downloadrust-5d5cd2a22b2ac93dc53a982285fbe31eed341fc8.tar.gz
rust-5d5cd2a22b2ac93dc53a982285fbe31eed341fc8.zip
Avoid RefCell in CodegenBackend
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f00a568cfed..66c154ff654 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -34,7 +34,7 @@ extern crate rustc_target;
 extern crate rustc_driver;
 
 use std::any::Any;
-use std::cell::{Cell, RefCell};
+use std::cell::Cell;
 use std::env;
 use std::sync::Arc;
 
@@ -155,7 +155,7 @@ impl CodegenCx {
 }
 
 pub struct CraneliftCodegenBackend {
-    pub config: RefCell<Option<BackendConfig>>,
+    pub config: Option<BackendConfig>,
 }
 
 impl CodegenBackend for CraneliftCodegenBackend {
@@ -177,13 +177,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
             sess.dcx()
                 .fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
         }
-
-        let mut config = self.config.borrow_mut();
-        if config.is_none() {
-            let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args)
-                .unwrap_or_else(|err| sess.dcx().fatal(err));
-            *config = Some(new_config);
-        }
     }
 
     fn target_features(&self, sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
@@ -221,7 +214,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
         need_metadata_module: bool,
     ) -> Box<dyn Any> {
         tcx.dcx().abort_if_errors();
-        let config = self.config.borrow().clone().unwrap();
+        let config = self.config.clone().unwrap_or_else(|| {
+            BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args)
+                .unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
+        });
         match config.codegen_mode {
             CodegenMode::Aot => driver::aot::run_aot(tcx, metadata, need_metadata_module),
             CodegenMode::Jit | CodegenMode::JitLazy => {
@@ -369,5 +365,5 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
 /// This is the entrypoint for a hot plugged rustc_codegen_cranelift
 #[no_mangle]
 pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
-    Box::new(CraneliftCodegenBackend { config: RefCell::new(None) })
+    Box::new(CraneliftCodegenBackend { config: None })
 }