From 5464b2e713d5366b3aec5c6eebbe1b84a782c51e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 30 Aug 2021 14:36:24 +0200 Subject: [PATCH 1/4] Remove optimization_fuel_crate from Session --- compiler/rustc_session/src/session.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 18b9339558797..89fa0d6dd994c 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -170,9 +170,6 @@ pub struct Session { /// Data about code being compiled, gathered during compilation. pub code_stats: CodeStats, - /// If `-zfuel=crate=n` is specified, `Some(crate)`. - optimization_fuel_crate: Option, - /// Tracks fuel info if `-zfuel=crate=n` is specified. optimization_fuel: Lock, @@ -890,7 +887,7 @@ impl Session { /// This expends fuel if applicable, and records fuel if applicable. pub fn consider_optimizing String>(&self, crate_name: &str, msg: T) -> bool { let mut ret = true; - if let Some(ref c) = self.optimization_fuel_crate { + if let Some(c) = self.opts.debugging_opts.fuel.as_ref().map(|i| &i.0) { if c == crate_name { assert_eq!(self.threads(), 1); let mut fuel = self.optimization_fuel.lock(); @@ -1261,7 +1258,6 @@ pub fn build_session( let local_crate_source_file = local_crate_source_file.map(|path| file_path_mapping.map_prefix(path).0); - let optimization_fuel_crate = sopts.debugging_opts.fuel.as_ref().map(|i| i.0.clone()); let optimization_fuel = Lock::new(OptimizationFuel { remaining: sopts.debugging_opts.fuel.as_ref().map_or(0, |i| i.1), out_of_fuel: false, @@ -1314,7 +1310,6 @@ pub fn build_session( normalize_projection_ty: AtomicUsize::new(0), }, code_stats: Default::default(), - optimization_fuel_crate, optimization_fuel, print_fuel_crate, print_fuel, From c9abc7e2bbed4afca2e7c8de7c7334d0a3724bb8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 30 Aug 2021 14:41:09 +0200 Subject: [PATCH 2/4] Remove print_fuel_crate field of Session --- compiler/rustc_driver/src/lib.rs | 4 ++-- compiler/rustc_session/src/session.rs | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index fcc70b2e4c5ff..53053327d0dab 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -423,10 +423,10 @@ fn run_compiler( sess.print_perf_stats(); } - if sess.print_fuel_crate.is_some() { + if sess.opts.debugging_opts.print_fuel.is_some() { eprintln!( "Fuel used by {}: {}", - sess.print_fuel_crate.as_ref().unwrap(), + sess.opts.debugging_opts.print_fuel.as_ref().unwrap(), sess.print_fuel.load(SeqCst) ); } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 89fa0d6dd994c..f29275bffc40f 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -173,9 +173,6 @@ pub struct Session { /// Tracks fuel info if `-zfuel=crate=n` is specified. optimization_fuel: Lock, - // The next two are public because the driver needs to read them. - /// If `-zprint-fuel=crate`, `Some(crate)`. - pub print_fuel_crate: Option, /// Always set to zero and incremented so that we can print fuel expended by a crate. pub print_fuel: AtomicU64, @@ -900,7 +897,7 @@ impl Session { } } } - if let Some(ref c) = self.print_fuel_crate { + if let Some(ref c) = self.opts.debugging_opts.print_fuel { if c == crate_name { assert_eq!(self.threads(), 1); self.print_fuel.fetch_add(1, SeqCst); @@ -1262,7 +1259,6 @@ pub fn build_session( remaining: sopts.debugging_opts.fuel.as_ref().map_or(0, |i| i.1), out_of_fuel: false, }); - let print_fuel_crate = sopts.debugging_opts.print_fuel.clone(); let print_fuel = AtomicU64::new(0); let cgu_reuse_tracker = if sopts.debugging_opts.query_dep_graph { @@ -1311,7 +1307,6 @@ pub fn build_session( }, code_stats: Default::default(), optimization_fuel, - print_fuel_crate, print_fuel, jobserver: jobserver::client(), driver_lint_caps, From b86a2ee03686905afb7ae90fd092af037da5906d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 30 Aug 2021 15:06:56 +0200 Subject: [PATCH 3/4] Use in_incr_comp_dir_sess in cg_clif --- compiler/rustc_codegen_cranelift/src/driver/aot.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index a8b802f449437..3de706ed6d7af 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -68,14 +68,13 @@ fn reuse_workproduct_for_cgu( cgu: &CodegenUnit<'_>, work_products: &mut FxHashMap, ) -> CompiledModule { - let incr_comp_session_dir = tcx.sess.incr_comp_session_dir(); let mut object = None; let work_product = cgu.work_product(tcx); if let Some(saved_file) = &work_product.saved_file { let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&cgu.name().as_str())); object = Some(obj_out.clone()); - let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file); + let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file); if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { tcx.sess.err(&format!( "unable to copy {} to {}: {}", From 74c7f1267b2afe17332ba3aa6b00eb9452404cf3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 31 Aug 2021 15:06:59 +0200 Subject: [PATCH 4/4] Add explanation for ctfe_backtrace lock --- compiler/rustc_session/src/session.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index f29275bffc40f..0f7db69fefefc 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -190,6 +190,9 @@ pub struct Session { /// Tracks the current behavior of the CTFE engine when an error occurs. /// Options range from returning the error without a backtrace to returning an error /// and immediately printing the backtrace to stderr. + /// The `Lock` is only used by miri to allow setting `ctfe_backtrace` after analysis when + /// `MIRI_BACKTRACE` is set. This makes it only apply to miri's errors and not to all CTFE + /// errors. pub ctfe_backtrace: Lock, /// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a