Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink Session a bit #88530

Merged
merged 4 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is something keeping the handling of the incr-comp session directory from being removed from Session?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be stored somewhere. TyCtxt won't easily work as cg_ssa and cg_llvm require sess.incr_comp_session_dir() at a place where TyCtxt is not available. It is probably possible to refactor this away from Session and I was already looking into it a bit, but then I got distracted by refactorings to the crate loader.

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>,
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved

/// 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