Skip to content

Commit

Permalink
Rollup merge of rust-lang#107740 - oli-obk:lock_tcx, r=petrochenkov
Browse files Browse the repository at this point in the history
Avoid locking the global context across the `after_expansion` callback

r? `@petrochenkov`

This was noticed in model-checking/kani#2184 (comment)

This didn't have a perf impact, as it's just an additional 2 or 3 RefCell locks being created.
  • Loading branch information
matthiaskrgr authored Feb 7, 2023
2 parents 401fe5c + 0ddf249 commit 8709e9b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,16 @@ fn run_compiler(
}
}

let mut gctxt = queries.global_ctxt()?;
// Make sure name resolution and macro expansion is run.
queries.global_ctxt()?;

if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
return early_exit();
}

// 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(()));
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));

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

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

drop(gctxt);

if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
return early_exit();
}
Expand Down

0 comments on commit 8709e9b

Please sign in to comment.