Skip to content

Commit bbedad2

Browse files
committed
Error when combining check mode and jit mode
1 parent 022bb60 commit bbedad2

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Configuration of cg_clif as passed in through `-Cllvm-args` and various env vars.
2-
#[derive(Clone, Debug)]
2+
#[derive(Debug)]
33
pub struct BackendConfig {
44
/// Should the crate be AOT compiled or JIT executed.
55
///

src/driver/jit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, Option<DebugC
3333
}
3434

3535
pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
36-
// FIXME error on check mode or crate types other than bin in CodegenBackend::init()
37-
3836
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
3937
tcx.dcx().fatal("can't jit non-executable crate");
4038
}

src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern crate rustc_target;
3939
extern crate rustc_driver;
4040

4141
use std::any::Any;
42+
use std::cell::OnceCell;
4243
use std::env;
4344
use std::sync::Arc;
4445

@@ -124,7 +125,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
124125
}
125126

126127
pub struct CraneliftCodegenBackend {
127-
pub config: Option<BackendConfig>,
128+
pub config: OnceCell<BackendConfig>,
128129
}
129130

130131
impl CodegenBackend for CraneliftCodegenBackend {
@@ -150,6 +151,15 @@ impl CodegenBackend for CraneliftCodegenBackend {
150151
sess.dcx()
151152
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
152153
}
154+
155+
let config = self.config.get_or_init(|| {
156+
BackendConfig::from_opts(&sess.opts.cg.llvm_args)
157+
.unwrap_or_else(|err| sess.dcx().fatal(err))
158+
});
159+
160+
if config.jit_mode && !sess.opts.output_types.should_codegen() {
161+
sess.dcx().fatal("JIT mode doesn't work with `cargo check`");
162+
}
153163
}
154164

155165
fn target_config(&self, sess: &Session) -> TargetConfig {
@@ -211,13 +221,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
211221

212222
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
213223
info!("codegen crate {}", tcx.crate_name(LOCAL_CRATE));
214-
let config = self.config.clone().unwrap_or_else(|| {
215-
BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args)
216-
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
217-
});
224+
let config = self.config.get().unwrap();
218225
if config.jit_mode {
219226
#[cfg(feature = "jit")]
220-
driver::jit::run_jit(tcx, config.jit_args);
227+
driver::jit::run_jit(tcx, config.jit_args.clone());
221228

222229
#[cfg(not(feature = "jit"))]
223230
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
@@ -363,5 +370,5 @@ fn build_isa(sess: &Session, jit: bool) -> Arc<dyn TargetIsa + 'static> {
363370
/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
364371
#[unsafe(no_mangle)]
365372
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
366-
Box::new(CraneliftCodegenBackend { config: None })
373+
Box::new(CraneliftCodegenBackend { config: OnceCell::new() })
367374
}

0 commit comments

Comments
 (0)