mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Create format_args
as late as possible
This commit is contained in:
parent
66797fa54f
commit
4f593ce5d8
@ -73,7 +73,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
|
||||
// Replace all remaining regions with fresh inference variables.
|
||||
renumber::renumber_mir(infcx, body, promoted);
|
||||
|
||||
dump_mir(infcx.tcx, None, "renumber", &0, body, |_, _| Ok(()));
|
||||
dump_mir(infcx.tcx, false, "renumber", &0, body, |_, _| Ok(()));
|
||||
|
||||
universal_regions
|
||||
}
|
||||
@ -331,7 +331,7 @@ pub(super) fn dump_mir_results<'tcx>(
|
||||
return;
|
||||
}
|
||||
|
||||
dump_mir(infcx.tcx, None, "nll", &0, body, |pass_where, out| {
|
||||
dump_mir(infcx.tcx, false, "nll", &0, body, |pass_where, out| {
|
||||
match pass_where {
|
||||
// Before the CFG, dump out the values for each region variable.
|
||||
PassWhere::BeforeCFG => {
|
||||
@ -358,15 +358,13 @@ pub(super) fn dump_mir_results<'tcx>(
|
||||
|
||||
// Also dump the inference graph constraints as a graphviz file.
|
||||
let _: io::Result<()> = try {
|
||||
let mut file =
|
||||
create_dump_file(infcx.tcx, "regioncx.all.dot", None, "nll", &0, body.source)?;
|
||||
let mut file = create_dump_file(infcx.tcx, "regioncx.all.dot", false, "nll", &0, body)?;
|
||||
regioncx.dump_graphviz_raw_constraints(&mut file)?;
|
||||
};
|
||||
|
||||
// Also dump the inference graph constraints as a graphviz file.
|
||||
let _: io::Result<()> = try {
|
||||
let mut file =
|
||||
create_dump_file(infcx.tcx, "regioncx.scc.dot", None, "nll", &0, body.source)?;
|
||||
let mut file = create_dump_file(infcx.tcx, "regioncx.scc.dot", false, "nll", &0, body)?;
|
||||
regioncx.dump_graphviz_scc_constraints(&mut file)?;
|
||||
};
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ use rustc_middle::mir::interpret::{
|
||||
Pointer, Provenance,
|
||||
};
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::MirSource;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_target::abi::Size;
|
||||
@ -74,7 +73,7 @@ pub enum PassWhere {
|
||||
#[inline]
|
||||
pub fn dump_mir<'tcx, F>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pass_num: Option<&dyn Display>,
|
||||
pass_num: bool,
|
||||
pass_name: &str,
|
||||
disambiguator: &dyn Display,
|
||||
body: &Body<'tcx>,
|
||||
@ -111,7 +110,7 @@ pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) ->
|
||||
|
||||
fn dump_matched_mir_node<'tcx, F>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pass_num: Option<&dyn Display>,
|
||||
pass_num: bool,
|
||||
pass_name: &str,
|
||||
disambiguator: &dyn Display,
|
||||
body: &Body<'tcx>,
|
||||
@ -120,8 +119,7 @@ fn dump_matched_mir_node<'tcx, F>(
|
||||
F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
|
||||
{
|
||||
let _: io::Result<()> = try {
|
||||
let mut file =
|
||||
create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, body.source)?;
|
||||
let mut file = create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, body)?;
|
||||
// see notes on #41697 above
|
||||
let def_path =
|
||||
ty::print::with_forced_impl_filename_line!(tcx.def_path_str(body.source.def_id()));
|
||||
@ -143,16 +141,14 @@ fn dump_matched_mir_node<'tcx, F>(
|
||||
|
||||
if tcx.sess.opts.unstable_opts.dump_mir_graphviz {
|
||||
let _: io::Result<()> = try {
|
||||
let mut file =
|
||||
create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, body.source)?;
|
||||
let mut file = create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, body)?;
|
||||
write_mir_fn_graphviz(tcx, body, false, &mut file)?;
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(spanview) = tcx.sess.opts.unstable_opts.dump_mir_spanview {
|
||||
let _: io::Result<()> = try {
|
||||
let file_basename =
|
||||
dump_file_basename(tcx, pass_num, pass_name, disambiguator, body.source);
|
||||
let file_basename = dump_file_basename(tcx, pass_num, pass_name, disambiguator, body);
|
||||
let mut file = create_dump_file_with_basename(tcx, &file_basename, "html")?;
|
||||
if body.source.def_id().is_local() {
|
||||
write_mir_fn_spanview(tcx, body, spanview, &file_basename, &mut file)?;
|
||||
@ -165,11 +161,12 @@ fn dump_matched_mir_node<'tcx, F>(
|
||||
/// where we should dump a MIR representation output files.
|
||||
fn dump_file_basename<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pass_num: Option<&dyn Display>,
|
||||
pass_num: bool,
|
||||
pass_name: &str,
|
||||
disambiguator: &dyn Display,
|
||||
source: MirSource<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
) -> String {
|
||||
let source = body.source;
|
||||
let promotion_id = match source.promoted {
|
||||
Some(id) => format!("-{:?}", id),
|
||||
None => String::new(),
|
||||
@ -178,9 +175,10 @@ fn dump_file_basename<'tcx>(
|
||||
let pass_num = if tcx.sess.opts.unstable_opts.dump_mir_exclude_pass_number {
|
||||
String::new()
|
||||
} else {
|
||||
match pass_num {
|
||||
None => ".-------".to_string(),
|
||||
Some(pass_num) => format!(".{}", pass_num),
|
||||
if pass_num {
|
||||
format!(".{:03}-{:03}", body.phase.phase_index(), body.pass_count)
|
||||
} else {
|
||||
".-------".to_string()
|
||||
}
|
||||
};
|
||||
|
||||
@ -250,14 +248,14 @@ fn create_dump_file_with_basename(
|
||||
pub fn create_dump_file<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
extension: &str,
|
||||
pass_num: Option<&dyn Display>,
|
||||
pass_num: bool,
|
||||
pass_name: &str,
|
||||
disambiguator: &dyn Display,
|
||||
source: MirSource<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
) -> io::Result<io::BufWriter<fs::File>> {
|
||||
create_dump_file_with_basename(
|
||||
tcx,
|
||||
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, source),
|
||||
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
|
||||
extension,
|
||||
)
|
||||
}
|
||||
|
@ -294,14 +294,7 @@ where
|
||||
None if tcx.sess.opts.unstable_opts.dump_mir_dataflow
|
||||
&& dump_enabled(tcx, A::NAME, def_id) =>
|
||||
{
|
||||
create_dump_file(
|
||||
tcx,
|
||||
".dot",
|
||||
None,
|
||||
A::NAME,
|
||||
&pass_name.unwrap_or("-----"),
|
||||
body.source,
|
||||
)?
|
||||
create_dump_file(tcx, ".dot", false, A::NAME, &pass_name.unwrap_or("-----"), body)?
|
||||
}
|
||||
|
||||
_ => return Ok(()),
|
||||
|
@ -638,7 +638,7 @@ pub(super) fn dump_coverage_spanview<'tcx>(
|
||||
let def_id = mir_source.def_id();
|
||||
|
||||
let span_viewables = span_viewables(tcx, mir_body, basic_coverage_blocks, &coverage_spans);
|
||||
let mut file = create_dump_file(tcx, "html", None, pass_name, &0, mir_source)
|
||||
let mut file = create_dump_file(tcx, "html", false, pass_name, &0, mir_body)
|
||||
.expect("Unexpected error creating MIR spanview HTML file");
|
||||
let crate_name = tcx.crate_name(def_id.krate);
|
||||
let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate();
|
||||
@ -739,7 +739,7 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
|
||||
.join("\n ")
|
||||
));
|
||||
}
|
||||
let mut file = create_dump_file(tcx, "dot", None, pass_name, &0, mir_source)
|
||||
let mut file = create_dump_file(tcx, "dot", false, pass_name, &0, mir_body)
|
||||
.expect("Unexpected error creating BasicCoverageBlock graphviz DOT file");
|
||||
graphviz_writer
|
||||
.write_graphviz(tcx, &mut file)
|
||||
|
@ -787,7 +787,7 @@ fn dest_prop_mir_dump<'body, 'tcx>(
|
||||
round: usize,
|
||||
) {
|
||||
let mut reachable = None;
|
||||
dump_mir(tcx, None, "DestinationPropagation-dataflow", &round, body, |pass_where, w| {
|
||||
dump_mir(tcx, false, "DestinationPropagation-dataflow", &round, body, |pass_where, w| {
|
||||
let reachable = reachable.get_or_insert_with(|| traversal::reachable_as_bitset(body));
|
||||
|
||||
match pass_where {
|
||||
|
@ -1000,7 +1000,7 @@ fn create_generator_drop_shim<'tcx>(
|
||||
// unrelated code from the resume part of the function
|
||||
simplify::remove_dead_blocks(tcx, &mut body);
|
||||
|
||||
dump_mir(tcx, None, "generator_drop", &0, &body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_drop", &0, &body, |_, _| Ok(()));
|
||||
|
||||
body
|
||||
}
|
||||
@ -1171,7 +1171,7 @@ fn create_generator_resume_function<'tcx>(
|
||||
// unrelated code from the drop part of the function
|
||||
simplify::remove_dead_blocks(tcx, body);
|
||||
|
||||
dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_resume", &0, body, |_, _| Ok(()));
|
||||
}
|
||||
|
||||
fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
|
||||
@ -1394,14 +1394,14 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
// This is expanded to a drop ladder in `elaborate_generator_drops`.
|
||||
let drop_clean = insert_clean_drop(body);
|
||||
|
||||
dump_mir(tcx, None, "generator_pre-elab", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_pre-elab", &0, body, |_, _| Ok(()));
|
||||
|
||||
// Expand `drop(generator_struct)` to a drop ladder which destroys upvars.
|
||||
// If any upvars are moved out of, drop elaboration will handle upvar destruction.
|
||||
// However we need to also elaborate the code generated by `insert_clean_drop`.
|
||||
elaborate_generator_drops(tcx, body);
|
||||
|
||||
dump_mir(tcx, None, "generator_post-transform", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_post-transform", &0, body, |_, _| Ok(()));
|
||||
|
||||
// Create a copy of our MIR and use it to create the drop shim for the generator
|
||||
let drop_shim = create_generator_drop_shim(tcx, &transform, gen_ty, body, drop_clean);
|
||||
|
@ -160,11 +160,9 @@ pub fn dump_mir_for_pass<'tcx>(
|
||||
pass_name: &str,
|
||||
is_after: bool,
|
||||
) {
|
||||
let phase_index = body.phase.phase_index();
|
||||
|
||||
mir::dump_mir(
|
||||
tcx,
|
||||
Some(&format_args!("{:03}-{:03}", phase_index, body.pass_count)),
|
||||
true,
|
||||
pass_name,
|
||||
if is_after { &"after" } else { &"before" },
|
||||
body,
|
||||
@ -173,14 +171,5 @@ pub fn dump_mir_for_pass<'tcx>(
|
||||
}
|
||||
|
||||
pub fn dump_mir_for_phase_change<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||
let phase_index = body.phase.phase_index();
|
||||
|
||||
mir::dump_mir(
|
||||
tcx,
|
||||
Some(&format_args!("{:03}-000", phase_index)),
|
||||
body.phase.name(),
|
||||
&"after",
|
||||
body,
|
||||
|_, _| Ok(()),
|
||||
)
|
||||
mir::dump_mir(tcx, true, body.phase.name(), &"after", body, |_, _| Ok(()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user