Skip to content

Commit

Permalink
Rollup merge of rust-lang#68460 - sinkuu:emit_mir_buffered, r=Mark-Si…
Browse files Browse the repository at this point in the history
…mulacrum

Use BufWriter for emitting MIR

I noticed that `--emit=mir` takes long time on a large crate. rust-lang#64344 seem to have fixed `-Zdump-mir`, but not `--emit=mir`.
  • Loading branch information
Dylan-DPC authored Feb 1, 2020
2 parents 64184a3 + 482c761 commit aebd117
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/librustc_data_structures/obligation_forest/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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};
Expand Down Expand Up @@ -575,7 +575,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(" "))?;
}
Expand Down
34 changes: 27 additions & 7 deletions src/librustc_mir/borrow_check/facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)?;
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand All @@ -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])
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
5 changes: 3 additions & 2 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit aebd117

Please sign in to comment.