Rollup merge of #68460 - sinkuu:emit_mir_buffered, r=Mark-Simulacrum
Use BufWriter for emitting MIR I noticed that `--emit=mir` takes long time on a large crate. https://github.com/rust-lang/rust/pull/64344 seem to have fixed `-Zdump-mir`, but not `--emit=mir`.
This commit is contained in:
commit
bf68a057b3
@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
|
|||||||
use graphviz as dot;
|
use graphviz as dot;
|
||||||
use std::env::var_os;
|
use std::env::var_os;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::BufWriter;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
@ -31,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {
|
|||||||
|
|
||||||
let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
|
let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
|
||||||
|
|
||||||
let mut gv_file = File::create(file_path).unwrap();
|
let mut gv_file = BufWriter::new(File::create(file_path).unwrap());
|
||||||
|
|
||||||
dot::render(&self, &mut gv_file).unwrap();
|
dot::render(&self, &mut gv_file).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ use syntax::ast;
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::{BufWriter, Write};
|
||||||
|
|
||||||
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
|
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
|
||||||
tcx.dep_graph.with_ignore(|| {
|
tcx.dep_graph.with_ignore(|| {
|
||||||
@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
|
|||||||
{
|
{
|
||||||
// dump a .txt file with just the edges:
|
// dump a .txt file with just the edges:
|
||||||
let txt_path = format!("{}.txt", path);
|
let txt_path = format!("{}.txt", path);
|
||||||
let mut file = File::create(&txt_path).unwrap();
|
let mut file = BufWriter::new(File::create(&txt_path).unwrap());
|
||||||
for &(ref source, ref target) in &edges {
|
for &(ref source, ref target) in &edges {
|
||||||
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
|
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ use tempfile::Builder as TempFileBuilder;
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, BufWriter, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{env, fs, iter, mem};
|
use std::{env, fs, iter, mem};
|
||||||
@ -574,7 +574,7 @@ fn write_out_deps(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = fs::File::create(&deps_filename)?;
|
let mut file = BufWriter::new(fs::File::create(&deps_filename)?);
|
||||||
for path in out_filenames {
|
for path in out_filenames {
|
||||||
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
|
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::{BufWriter, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
|
|||||||
T: FactRow,
|
T: FactRow,
|
||||||
{
|
{
|
||||||
let file = &self.dir.join(file_name);
|
let file = &self.dir.join(file_name);
|
||||||
let mut file = File::create(file)?;
|
let mut file = BufWriter::new(File::create(file)?);
|
||||||
for row in rows {
|
for row in rows {
|
||||||
row.write(&mut file, self.location_table)?;
|
row.write(&mut file, self.location_table)?;
|
||||||
}
|
}
|
||||||
@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait FactRow {
|
trait FactRow {
|
||||||
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>>;
|
fn write(
|
||||||
|
&self,
|
||||||
|
out: &mut dyn Write,
|
||||||
|
location_table: &LocationTable,
|
||||||
|
) -> Result<(), Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FactRow for RegionVid {
|
impl FactRow for RegionVid {
|
||||||
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
|
fn write(
|
||||||
|
&self,
|
||||||
|
out: &mut dyn Write,
|
||||||
|
location_table: &LocationTable,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
write_row(out, location_table, &[self])
|
write_row(out, location_table, &[self])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +148,11 @@ where
|
|||||||
A: FactCell,
|
A: FactCell,
|
||||||
B: FactCell,
|
B: FactCell,
|
||||||
{
|
{
|
||||||
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
|
fn write(
|
||||||
|
&self,
|
||||||
|
out: &mut dyn Write,
|
||||||
|
location_table: &LocationTable,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
write_row(out, location_table, &[&self.0, &self.1])
|
write_row(out, location_table, &[&self.0, &self.1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +163,11 @@ where
|
|||||||
B: FactCell,
|
B: FactCell,
|
||||||
C: FactCell,
|
C: FactCell,
|
||||||
{
|
{
|
||||||
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
|
fn write(
|
||||||
|
&self,
|
||||||
|
out: &mut dyn Write,
|
||||||
|
location_table: &LocationTable,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
write_row(out, location_table, &[&self.0, &self.1, &self.2])
|
write_row(out, location_table, &[&self.0, &self.1, &self.2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +179,11 @@ where
|
|||||||
C: FactCell,
|
C: FactCell,
|
||||||
D: FactCell,
|
D: FactCell,
|
||||||
{
|
{
|
||||||
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
|
fn write(
|
||||||
|
&self,
|
||||||
|
out: &mut dyn Write,
|
||||||
|
location_table: &LocationTable,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
|
write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(
|
|||||||
|
|
||||||
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
|
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
|
||||||
let path = outputs.path(OutputType::Mir);
|
let path = outputs.path(OutputType::Mir);
|
||||||
let mut f = File::create(&path)?;
|
let mut f = io::BufWriter::new(File::create(&path)?);
|
||||||
mir_util::write_mir_pretty(tcx, None, &mut f)?;
|
mir_util::write_mir_pretty(tcx, None, &mut f)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
|
|||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, BufWriter, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub type LiveVarSet = BitSet<Local>;
|
pub type LiveVarSet = BitSet<Local>;
|
||||||
@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>(
|
|||||||
let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
|
let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
|
||||||
let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
|
let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
|
||||||
file_path.push(&file_name);
|
file_path.push(&file_name);
|
||||||
let _ = fs::File::create(&file_path).and_then(|mut file| {
|
let _ = fs::File::create(&file_path).and_then(|file| {
|
||||||
|
let mut file = BufWriter::new(file);
|
||||||
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
|
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
|
||||||
writeln!(file, "// source = {:?}", source)?;
|
writeln!(file, "// source = {:?}", source)?;
|
||||||
writeln!(file, "// pass_name = {}", pass_name)?;
|
writeln!(file, "// pass_name = {}", pass_name)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user