Skip to content

Commit

Permalink
Store the gctxt instead of fetching it twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 23, 2023
1 parent 3ddb54f commit 261bbd7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,14 @@ fn run_compiler(
}
}

queries.global_ctxt()?;
let mut gctxt = queries.global_ctxt()?;
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
return early_exit();
}

queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
// Make sure the `output_filenames` query is run for its side
// effects of writing the dep-info and reporting errors.
gctxt.enter(|tcx| tcx.output_filenames(()));

if sess.opts.output_types.contains_key(&OutputType::DepInfo)
&& sess.opts.output_types.len() == 1
Expand All @@ -344,7 +346,7 @@ fn run_compiler(
return early_exit();
}

queries.global_ctxt()?.enter(|tcx| {
gctxt.enter(|tcx| {
let result = tcx.analysis(());
if sess.opts.unstable_opts.save_analysis {
let crate_name = tcx.crate_name(LOCAL_CRATE);
Expand All @@ -361,6 +363,8 @@ fn run_compiler(
result
})?;

drop(gctxt);

if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
return early_exit();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a, T> std::ops::DerefMut for QueryResult<'a, T> {
}

impl<'a, 'tcx> QueryResult<'a, QueryContext<'tcx>> {
pub fn enter<T>(mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
pub fn enter<T>(&mut self, f: impl FnOnce(TyCtxt<'tcx>) -> T) -> T {
(*self.0).get_mut().enter(f)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ fn main_args(at_args: &[String]) -> MainResult {
sess.fatal("Compilation failed, aborting rustdoc");
}

let global_ctxt = abort_on_err(queries.global_ctxt(), sess);
let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess);

global_ctxt.enter(|tcx| {
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
Expand Down

0 comments on commit 261bbd7

Please sign in to comment.