Skip to content

Commit bd209ed

Browse files
committed
Remove disable_incr_cache from BackendConfig
1 parent 1cc1079 commit bd209ed

File tree

3 files changed

+11
-30
lines changed

3 files changed

+11
-30
lines changed

src/config.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use std::env;
21
use std::str::FromStr;
32

4-
fn bool_env_var(key: &str) -> bool {
5-
env::var(key).as_deref() == Ok("1")
6-
}
7-
83
/// The mode to use for compilation.
94
#[derive(Copy, Clone, Debug)]
105
pub enum CodegenMode {
@@ -41,14 +36,6 @@ pub struct BackendConfig {
4136
///
4237
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
4338
pub jit_args: Vec<String>,
44-
45-
/// Don't cache object files in the incremental cache. Useful during development of cg_clif
46-
/// to make it possible to use incremental mode for all analyses performed by rustc without
47-
/// caching object files when their content should have been changed by a change to cg_clif.
48-
///
49-
/// Defaults to true when the `CG_CLIF_DISABLE_INCR_CACHE` env var is set to 1 or false
50-
/// otherwise. Can be set using `-Cllvm-args=disable_incr_cache=...`.
51-
pub disable_incr_cache: bool,
5239
}
5340

5441
impl Default for BackendConfig {
@@ -64,18 +51,13 @@ impl Default for BackendConfig {
6451
}
6552
}
6653
},
67-
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
6854
}
6955
}
7056
}
7157

7258
impl BackendConfig {
7359
/// Parse the configuration passed in using `-Cllvm-args`.
7460
pub fn from_opts(opts: &[String]) -> Result<Self, String> {
75-
fn parse_bool(name: &str, value: &str) -> Result<bool, String> {
76-
value.parse().map_err(|_| format!("failed to parse value `{}` for {}", value, name))
77-
}
78-
7961
let mut config = BackendConfig::default();
8062
for opt in opts {
8163
if opt.starts_with("-import-instr-limit") {
@@ -86,7 +68,6 @@ impl BackendConfig {
8668
if let Some((name, value)) = opt.split_once('=') {
8769
match name {
8870
"mode" => config.codegen_mode = value.parse()?,
89-
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
9071
_ => return Err(format!("Unknown option `{}`", name)),
9172
}
9273
} else {

src/driver/aot.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
22
//! standalone executable.
33
4+
use std::env;
45
use std::fs::{self, File};
56
use std::io::BufWriter;
67
use std::path::{Path, PathBuf};
@@ -25,13 +26,16 @@ use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
2526
use rustc_session::Session;
2627
use rustc_session::config::{DebugInfo, OutFileName, OutputFilenames, OutputType};
2728

28-
use crate::BackendConfig;
2929
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
3030
use crate::debuginfo::TypeDebugContext;
3131
use crate::global_asm::GlobalAsmConfig;
3232
use crate::prelude::*;
3333
use crate::unwind_module::UnwindModule;
3434

35+
fn disable_incr_cache() -> bool {
36+
env::var("CG_CLIF_DISABLE_INCR_CACHE").as_deref() == Ok("1")
37+
}
38+
3539
struct ModuleCodegenResult {
3640
module_regular: CompiledModule,
3741
module_global_asm: Option<CompiledModule>,
@@ -63,10 +67,10 @@ impl OngoingCodegen {
6367
self,
6468
sess: &Session,
6569
outputs: &OutputFilenames,
66-
backend_config: &BackendConfig,
6770
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
6871
let mut work_products = FxIndexMap::default();
6972
let mut modules = vec![];
73+
let disable_incr_cache = disable_incr_cache();
7074

7175
for module_codegen in self.modules {
7276
let module_codegen_result = match module_codegen {
@@ -87,7 +91,7 @@ impl OngoingCodegen {
8791
if let Some((work_product_id, work_product)) = existing_work_product {
8892
work_products.insert(work_product_id, work_product);
8993
} else {
90-
let work_product = if backend_config.disable_incr_cache {
94+
let work_product = if disable_incr_cache {
9195
None
9296
} else if let Some(module_global_asm) = &module_global_asm {
9397
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
@@ -580,7 +584,6 @@ fn module_codegen(
580584

581585
pub(crate) fn run_aot(
582586
tcx: TyCtxt<'_>,
583-
backend_config: BackendConfig,
584587
metadata: EncodedMetadata,
585588
need_metadata_module: bool,
586589
) -> Box<OngoingCodegen> {
@@ -626,9 +629,10 @@ pub(crate) fn run_aot(
626629

627630
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
628631

632+
let disable_incr_cache = disable_incr_cache();
629633
let (todo_cgus, done_cgus) =
630634
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
631-
_ if backend_config.disable_incr_cache => true,
635+
_ if disable_incr_cache => true,
632636
CguReuse::No => true,
633637
CguReuse::PreLto | CguReuse::PostLto => false,
634638
});

src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
223223
tcx.dcx().abort_if_errors();
224224
let config = self.config.borrow().clone().unwrap();
225225
match config.codegen_mode {
226-
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),
226+
CodegenMode::Aot => driver::aot::run_aot(tcx, metadata, need_metadata_module),
227227
CodegenMode::Jit | CodegenMode::JitLazy => {
228228
#[cfg(feature = "jit")]
229229
driver::jit::run_jit(tcx, config);
@@ -242,11 +242,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
242242
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
243243
let _timer = sess.timer("finish_ongoing_codegen");
244244

245-
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(
246-
sess,
247-
outputs,
248-
self.config.borrow().as_ref().unwrap(),
249-
)
245+
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(sess, outputs)
250246
}
251247
}
252248

0 commit comments

Comments
 (0)