-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Handle GlobalCtxt directly from librustc_interface query system #66791
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
Changes from 15 commits
266ede1
5098ba6
27513a2
becfe5c
18bb912
ea1b803
7d01b6c
8ffc944
9d5f721
68b1ac9
144d1c2
58a9c73
b99513b
7b71e9a
7e72b36
79e2324
e5ed101
77a4c85
e321ba9
1e12f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,120 +283,127 @@ pub fn run_compiler( | |
return sess.compile_status(); | ||
} | ||
|
||
compiler.parse()?; | ||
|
||
if let Some(ppm) = &sess.opts.pretty { | ||
if ppm.needs_ast_map() { | ||
compiler.global_ctxt()?.peek_mut().enter(|tcx| { | ||
let expanded_crate = compiler.expansion()?.take().0; | ||
pretty::print_after_hir_lowering( | ||
tcx, | ||
compiler.input(), | ||
&expanded_crate, | ||
let linker = compiler.enter(|queries| { | ||
let early_exit = || sess.compile_status().map(|_| None); | ||
queries.parse()?; | ||
|
||
if let Some(ppm) = &sess.opts.pretty { | ||
if ppm.needs_ast_map() { | ||
queries.global_ctxt()?.peek_mut().enter(|tcx| { | ||
let expanded_crate = queries.expansion()?.take().0; | ||
pretty::print_after_hir_lowering( | ||
tcx, | ||
compiler.input(), | ||
&expanded_crate, | ||
*ppm, | ||
compiler.output_file().as_ref().map(|p| &**p), | ||
); | ||
Ok(()) | ||
})?; | ||
} else { | ||
let krate = queries.parse()?.take(); | ||
pretty::print_after_parsing( | ||
sess, | ||
&compiler.input(), | ||
&krate, | ||
*ppm, | ||
compiler.output_file().as_ref().map(|p| &**p), | ||
); | ||
Ok(()) | ||
})?; | ||
} else { | ||
let krate = compiler.parse()?.take(); | ||
pretty::print_after_parsing( | ||
sess, | ||
&compiler.input(), | ||
&krate, | ||
*ppm, | ||
compiler.output_file().as_ref().map(|p| &**p), | ||
); | ||
} | ||
return early_exit(); | ||
} | ||
return sess.compile_status(); | ||
} | ||
|
||
if callbacks.after_parsing(compiler) == Compilation::Stop { | ||
return sess.compile_status(); | ||
} | ||
if callbacks.after_parsing(compiler) == Compilation::Stop { | ||
return early_exit(); | ||
} | ||
|
||
if sess.opts.debugging_opts.parse_only || | ||
sess.opts.debugging_opts.show_span.is_some() || | ||
sess.opts.debugging_opts.ast_json_noexpand { | ||
return sess.compile_status(); | ||
} | ||
if sess.opts.debugging_opts.parse_only || | ||
sess.opts.debugging_opts.show_span.is_some() || | ||
sess.opts.debugging_opts.ast_json_noexpand { | ||
return early_exit(); | ||
} | ||
|
||
{ | ||
let (_, lint_store) = &*compiler.register_plugins()?.peek(); | ||
{ | ||
let (_, lint_store) = &*queries.register_plugins()?.peek(); | ||
|
||
// Lint plugins are registered; now we can process command line flags. | ||
if sess.opts.describe_lints { | ||
describe_lints(&sess, &lint_store, true); | ||
return sess.compile_status(); | ||
// Lint plugins are registered; now we can process command line flags. | ||
if sess.opts.describe_lints { | ||
describe_lints(&sess, &lint_store, true); | ||
return early_exit(); | ||
} | ||
} | ||
} | ||
|
||
compiler.expansion()?; | ||
if callbacks.after_expansion(compiler) == Compilation::Stop { | ||
return sess.compile_status(); | ||
} | ||
queries.expansion()?; | ||
if callbacks.after_expansion(compiler) == Compilation::Stop { | ||
return early_exit(); | ||
} | ||
|
||
compiler.prepare_outputs()?; | ||
queries.prepare_outputs()?; | ||
|
||
if sess.opts.output_types.contains_key(&OutputType::DepInfo) | ||
&& sess.opts.output_types.len() == 1 | ||
{ | ||
return sess.compile_status(); | ||
} | ||
if sess.opts.output_types.contains_key(&OutputType::DepInfo) | ||
&& sess.opts.output_types.len() == 1 | ||
{ | ||
return early_exit(); | ||
} | ||
|
||
compiler.global_ctxt()?; | ||
queries.global_ctxt()?; | ||
|
||
if sess.opts.debugging_opts.no_analysis || | ||
sess.opts.debugging_opts.ast_json { | ||
return sess.compile_status(); | ||
} | ||
if sess.opts.debugging_opts.no_analysis || | ||
sess.opts.debugging_opts.ast_json { | ||
return early_exit(); | ||
} | ||
|
||
if sess.opts.debugging_opts.save_analysis { | ||
let expanded_crate = &compiler.expansion()?.peek().0; | ||
let crate_name = compiler.crate_name()?.peek().clone(); | ||
compiler.global_ctxt()?.peek_mut().enter(|tcx| { | ||
let result = tcx.analysis(LOCAL_CRATE); | ||
|
||
time(sess, "save analysis", || { | ||
save::process_crate( | ||
tcx, | ||
&expanded_crate, | ||
&crate_name, | ||
&compiler.input(), | ||
None, | ||
DumpHandler::new(compiler.output_dir().as_ref().map(|p| &**p), &crate_name) | ||
) | ||
}); | ||
|
||
result | ||
// AST will be dropped *after* the `after_analysis` callback | ||
// (needed by the RLS) | ||
})?; | ||
} else { | ||
// Drop AST after creating GlobalCtxt to free memory | ||
mem::drop(compiler.expansion()?.take()); | ||
} | ||
if sess.opts.debugging_opts.save_analysis { | ||
let expanded_crate = &queries.expansion()?.peek().0; | ||
let crate_name = queries.crate_name()?.peek().clone(); | ||
queries.global_ctxt()?.peek_mut().enter(|tcx| { | ||
let result = tcx.analysis(LOCAL_CRATE); | ||
|
||
time(sess, "save analysis", || { | ||
save::process_crate( | ||
tcx, | ||
&expanded_crate, | ||
&crate_name, | ||
&compiler.input(), | ||
None, | ||
DumpHandler::new( | ||
compiler.output_dir().as_ref().map(|p| &**p), &crate_name | ||
) | ||
) | ||
}); | ||
|
||
compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?; | ||
result | ||
// AST will be dropped *after* the `after_analysis` callback | ||
// (needed by the RLS) | ||
})?; | ||
} else { | ||
// Drop AST after creating GlobalCtxt to free memory | ||
mem::drop(queries.expansion()?.take()); | ||
} | ||
|
||
if callbacks.after_analysis(compiler) == Compilation::Stop { | ||
return sess.compile_status(); | ||
} | ||
queries.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?; | ||
|
||
if sess.opts.debugging_opts.save_analysis { | ||
mem::drop(compiler.expansion()?.take()); | ||
} | ||
if callbacks.after_analysis(compiler) == Compilation::Stop { | ||
return early_exit(); | ||
} | ||
Comment on lines
+386
to
+388
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it maybe a problem that now, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is indeed the problem. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should probably be an assertion to avoid calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prepared a PR at #66896 (and tested that this indeed is sufficient to fix Miri).
I didn't do that as I wouldn't know how. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay. Do you still need me to do something? |
||
|
||
compiler.ongoing_codegen()?; | ||
if sess.opts.debugging_opts.save_analysis { | ||
mem::drop(queries.expansion()?.take()); | ||
} | ||
|
||
// Drop GlobalCtxt after starting codegen to free memory | ||
mem::drop(compiler.global_ctxt()?.take()); | ||
queries.ongoing_codegen()?; | ||
|
||
if sess.opts.debugging_opts.print_type_sizes { | ||
sess.code_stats.print_type_sizes(); | ||
} | ||
if sess.opts.debugging_opts.print_type_sizes { | ||
sess.code_stats.print_type_sizes(); | ||
} | ||
|
||
compiler.link()?; | ||
let linker = queries.linker()?; | ||
Ok(Some(linker)) | ||
})?; | ||
|
||
if let Some(linker) = linker { | ||
linker.link()? | ||
} | ||
|
||
if sess.opts.debugging_opts.perf_stats { | ||
sess.print_perf_stats(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.