mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #129667 - dev-ardi:rustc_driver-cleanup, r=michaelwoerister
Rustc driver cleanup This adds a few comments to the driver to clarify a bit what's happening and does some cleanup.
This commit is contained in:
commit
472c9645fb
@ -393,13 +393,17 @@ fn run_compiler(
|
|||||||
|
|
||||||
let linker = compiler.enter(|queries| {
|
let linker = compiler.enter(|queries| {
|
||||||
let early_exit = || early_exit().map(|_| None);
|
let early_exit = || early_exit().map(|_| None);
|
||||||
|
|
||||||
|
// Parse the crate root source code (doesn't parse submodules yet)
|
||||||
|
// Everything else is parsed during macro expansion.
|
||||||
queries.parse()?;
|
queries.parse()?;
|
||||||
|
|
||||||
if let Some(ppm) = &sess.opts.pretty {
|
// If pretty printing is requested: Figure out the representation, print it and exit
|
||||||
if ppm.needs_ast_map() {
|
if let Some(pp_mode) = sess.opts.pretty {
|
||||||
|
if pp_mode.needs_ast_map() {
|
||||||
queries.global_ctxt()?.enter(|tcx| {
|
queries.global_ctxt()?.enter(|tcx| {
|
||||||
tcx.ensure().early_lint_checks(());
|
tcx.ensure().early_lint_checks(());
|
||||||
pretty::print(sess, *ppm, pretty::PrintExtra::NeedsAstMap { tcx });
|
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -410,7 +414,7 @@ fn run_compiler(
|
|||||||
let krate = queries.parse()?;
|
let krate = queries.parse()?;
|
||||||
pretty::print(
|
pretty::print(
|
||||||
sess,
|
sess,
|
||||||
*ppm,
|
pp_mode,
|
||||||
pretty::PrintExtra::AfterParsing { krate: &*krate.borrow() },
|
pretty::PrintExtra::AfterParsing { krate: &*krate.borrow() },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -465,12 +469,8 @@ fn run_compiler(
|
|||||||
linker.link(sess, codegen_backend)?
|
linker.link(sess, codegen_backend)?
|
||||||
}
|
}
|
||||||
|
|
||||||
if sess.opts.unstable_opts.print_fuel.is_some() {
|
if let Some(fuel) = sess.opts.unstable_opts.print_fuel.as_deref() {
|
||||||
eprintln!(
|
eprintln!("Fuel used by {}: {}", fuel, sess.print_fuel.load(Ordering::SeqCst));
|
||||||
"Fuel used by {}: {}",
|
|
||||||
sess.opts.unstable_opts.print_fuel.as_ref().unwrap(),
|
|
||||||
sess.print_fuel.load(Ordering::SeqCst)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -487,36 +487,43 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileNa
|
|||||||
(odir, ofile)
|
(odir, ofile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract input (string or file and optional path) from matches.
|
/// Extract input (string or file and optional path) from matches.
|
||||||
|
/// This handles reading from stdin if `-` is provided.
|
||||||
fn make_input(
|
fn make_input(
|
||||||
early_dcx: &EarlyDiagCtxt,
|
early_dcx: &EarlyDiagCtxt,
|
||||||
free_matches: &[String],
|
free_matches: &[String],
|
||||||
) -> Result<Option<Input>, ErrorGuaranteed> {
|
) -> Result<Option<Input>, ErrorGuaranteed> {
|
||||||
let [ifile] = free_matches else { return Ok(None) };
|
let [input_file] = free_matches else { return Ok(None) };
|
||||||
if ifile == "-" {
|
|
||||||
let mut src = String::new();
|
if input_file != "-" {
|
||||||
if io::stdin().read_to_string(&mut src).is_err() {
|
// Normal `Input::File`
|
||||||
// Immediately stop compilation if there was an issue reading
|
return Ok(Some(Input::File(PathBuf::from(input_file))));
|
||||||
// the input (for example if the input stream is not UTF-8).
|
}
|
||||||
let reported =
|
|
||||||
early_dcx.early_err("couldn't read from stdin, as it did not contain valid UTF-8");
|
// read from stdin as `Input::Str`
|
||||||
return Err(reported);
|
let mut input = String::new();
|
||||||
}
|
if io::stdin().read_to_string(&mut input).is_err() {
|
||||||
if let Ok(path) = env::var("UNSTABLE_RUSTDOC_TEST_PATH") {
|
// Immediately stop compilation if there was an issue reading
|
||||||
|
// the input (for example if the input stream is not UTF-8).
|
||||||
|
let reported =
|
||||||
|
early_dcx.early_err("couldn't read from stdin, as it did not contain valid UTF-8");
|
||||||
|
return Err(reported);
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = match env::var("UNSTABLE_RUSTDOC_TEST_PATH") {
|
||||||
|
Ok(path) => {
|
||||||
let line = env::var("UNSTABLE_RUSTDOC_TEST_LINE").expect(
|
let line = env::var("UNSTABLE_RUSTDOC_TEST_LINE").expect(
|
||||||
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
|
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
|
||||||
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
|
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
|
||||||
);
|
);
|
||||||
let line = isize::from_str_radix(&line, 10)
|
let line = isize::from_str_radix(&line, 10)
|
||||||
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
|
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
|
||||||
let file_name = FileName::doc_test_source_code(PathBuf::from(path), line);
|
FileName::doc_test_source_code(PathBuf::from(path), line)
|
||||||
Ok(Some(Input::Str { name: file_name, input: src }))
|
|
||||||
} else {
|
|
||||||
Ok(Some(Input::Str { name: FileName::anon_source_code(&src), input: src }))
|
|
||||||
}
|
}
|
||||||
} else {
|
Err(_) => FileName::anon_source_code(&input),
|
||||||
Ok(Some(Input::File(PathBuf::from(ifile))))
|
};
|
||||||
}
|
|
||||||
|
Ok(Some(Input::Str { name, input }))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether to stop or continue compilation.
|
/// Whether to stop or continue compilation.
|
||||||
|
@ -51,7 +51,9 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the contents of a module (inner attributes followed by module items).
|
/// Parses the contents of a module (inner attributes followed by module items).
|
||||||
/// We exit once we hit `term`
|
/// We exit once we hit `term` which can be either
|
||||||
|
/// - EOF (for files)
|
||||||
|
/// - `}` for mod items
|
||||||
pub fn parse_mod(
|
pub fn parse_mod(
|
||||||
&mut self,
|
&mut self,
|
||||||
term: &TokenKind,
|
term: &TokenKind,
|
||||||
|
@ -2893,6 +2893,7 @@ pub enum PpHirMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
|
/// Pretty print mode
|
||||||
pub enum PpMode {
|
pub enum PpMode {
|
||||||
/// Options that print the source code, i.e.
|
/// Options that print the source code, i.e.
|
||||||
/// `-Zunpretty=normal` and `-Zunpretty=expanded`
|
/// `-Zunpretty=normal` and `-Zunpretty=expanded`
|
||||||
|
Loading…
Reference in New Issue
Block a user