Skip to content

Commit

Permalink
Auto merge of rust-lang#88530 - bjorn3:shrink_session, r=cjgillot
Browse files Browse the repository at this point in the history
Shrink Session a bit

Remove a couple of unnecessary fields from `Session` and remove a `Lock<T>` for a field that is never mutated anyway.
  • Loading branch information
bors committed Sep 2, 2021
2 parents 6492931 + 74c7f12 commit fcce644
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ fn reuse_workproduct_for_cgu(
cgu: &CodegenUnit<'_>,
work_products: &mut FxHashMap<WorkProductId, WorkProduct>,
) -> 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 {}: {}",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
17 changes: 5 additions & 12 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,9 @@ 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<String>,

/// Tracks fuel info if `-zfuel=crate=n` is specified.
optimization_fuel: Lock<OptimizationFuel>,

// The next two are public because the driver needs to read them.
/// If `-zprint-fuel=crate`, `Some(crate)`.
pub print_fuel_crate: Option<String>,
/// Always set to zero and incremented so that we can print fuel expended by a crate.
pub print_fuel: AtomicU64,

Expand All @@ -196,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<CtfeBacktrace>,

/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
Expand Down Expand Up @@ -890,7 +887,7 @@ impl Session {
/// This expends fuel if applicable, and records fuel if applicable.
pub fn consider_optimizing<T: Fn() -> 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();
Expand All @@ -903,7 +900,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);
Expand Down Expand Up @@ -1261,12 +1258,10 @@ 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,
});
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 {
Expand Down Expand Up @@ -1314,9 +1309,7 @@ pub fn build_session(
normalize_projection_ty: AtomicUsize::new(0),
},
code_stats: Default::default(),
optimization_fuel_crate,
optimization_fuel,
print_fuel_crate,
print_fuel,
jobserver: jobserver::client(),
driver_lint_caps,
Expand Down

0 comments on commit fcce644

Please sign in to comment.