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:
Yuki Okushi 2020-02-02 08:30:09 +09:00 committed by GitHub
commit bf68a057b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 15 deletions

View File

@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
use graphviz as dot;
use std::env::var_os;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
use std::sync::atomic::AtomicUsize;
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 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();
}

View File

@ -49,7 +49,7 @@ use syntax::ast;
use std::env;
use std::fs::{self, File};
use std::io::Write;
use std::io::{BufWriter, Write};
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
tcx.dep_graph.with_ignore(|| {
@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
{
// dump a .txt file with just the edges:
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 {
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
}

View File

@ -48,7 +48,7 @@ use tempfile::Builder as TempFileBuilder;
use std::any::Any;
use std::cell::RefCell;
use std::ffi::OsString;
use std::io::{self, Write};
use std::io::{self, BufWriter, Write};
use std::path::PathBuf;
use std::rc::Rc;
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 {
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
}

View File

@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
use std::error::Error;
use std::fmt::Debug;
use std::fs::{self, File};
use std::io::Write;
use std::io::{BufWriter, Write};
use std::path::Path;
#[derive(Copy, Clone, Debug)]
@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
T: FactRow,
{
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 {
row.write(&mut file, self.location_table)?;
}
@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
}
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 {
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])
}
}
@ -140,7 +148,11 @@ where
A: 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])
}
}
@ -151,7 +163,11 @@ where
B: 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])
}
}
@ -163,7 +179,11 @@ where
C: 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])
}
}

View File

@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
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)?;
Ok(())
}

View File

@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use std::fs;
use std::io::{self, Write};
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
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 file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_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, "// source = {:?}", source)?;
writeln!(file, "// pass_name = {}", pass_name)?;