Skip to content

Commit aebd117

Browse files
authored
Rollup merge of rust-lang#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. rust-lang#64344 seem to have fixed `-Zdump-mir`, but not `--emit=mir`.
2 parents 64184a3 + 482c761 commit aebd117

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

src/librustc_data_structures/obligation_forest/graphviz.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest};
22
use graphviz as dot;
33
use std::env::var_os;
44
use std::fs::File;
5+
use std::io::BufWriter;
56
use std::path::Path;
67
use std::sync::atomic::AtomicUsize;
78
use std::sync::atomic::Ordering;
@@ -31,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {
3132

3233
let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
3334

34-
let mut gv_file = File::create(file_path).unwrap();
35+
let mut gv_file = BufWriter::new(File::create(file_path).unwrap());
3536

3637
dot::render(&self, &mut gv_file).unwrap();
3738
}

src/librustc_incremental/assert_dep_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use syntax::ast;
4949

5050
use std::env;
5151
use std::fs::{self, File};
52-
use std::io::Write;
52+
use std::io::{BufWriter, Write};
5353

5454
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
5555
tcx.dep_graph.with_ignore(|| {
@@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) {
235235
{
236236
// dump a .txt file with just the edges:
237237
let txt_path = format!("{}.txt", path);
238-
let mut file = File::create(&txt_path).unwrap();
238+
let mut file = BufWriter::new(File::create(&txt_path).unwrap());
239239
for &(ref source, ref target) in &edges {
240240
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
241241
}

src/librustc_interface/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use tempfile::Builder as TempFileBuilder;
4949
use std::any::Any;
5050
use std::cell::RefCell;
5151
use std::ffi::OsString;
52-
use std::io::{self, Write};
52+
use std::io::{self, BufWriter, Write};
5353
use std::path::PathBuf;
5454
use std::rc::Rc;
5555
use std::{env, fs, iter, mem};
@@ -575,7 +575,7 @@ fn write_out_deps(
575575
});
576576
}
577577

578-
let mut file = fs::File::create(&deps_filename)?;
578+
let mut file = BufWriter::new(fs::File::create(&deps_filename)?);
579579
for path in out_filenames {
580580
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
581581
}

src/librustc_mir/borrow_check/facts.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_index::vec::Idx;
88
use std::error::Error;
99
use std::fmt::Debug;
1010
use std::fs::{self, File};
11-
use std::io::Write;
11+
use std::io::{BufWriter, Write};
1212
use std::path::Path;
1313

1414
#[derive(Copy, Clone, Debug)]
@@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> {
117117
T: FactRow,
118118
{
119119
let file = &self.dir.join(file_name);
120-
let mut file = File::create(file)?;
120+
let mut file = BufWriter::new(File::create(file)?);
121121
for row in rows {
122122
row.write(&mut file, self.location_table)?;
123123
}
@@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> {
126126
}
127127

128128
trait FactRow {
129-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>>;
129+
fn write(
130+
&self,
131+
out: &mut dyn Write,
132+
location_table: &LocationTable,
133+
) -> Result<(), Box<dyn Error>>;
130134
}
131135

132136
impl FactRow for RegionVid {
133-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
137+
fn write(
138+
&self,
139+
out: &mut dyn Write,
140+
location_table: &LocationTable,
141+
) -> Result<(), Box<dyn Error>> {
134142
write_row(out, location_table, &[self])
135143
}
136144
}
@@ -140,7 +148,11 @@ where
140148
A: FactCell,
141149
B: FactCell,
142150
{
143-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
151+
fn write(
152+
&self,
153+
out: &mut dyn Write,
154+
location_table: &LocationTable,
155+
) -> Result<(), Box<dyn Error>> {
144156
write_row(out, location_table, &[&self.0, &self.1])
145157
}
146158
}
@@ -151,7 +163,11 @@ where
151163
B: FactCell,
152164
C: FactCell,
153165
{
154-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
166+
fn write(
167+
&self,
168+
out: &mut dyn Write,
169+
location_table: &LocationTable,
170+
) -> Result<(), Box<dyn Error>> {
155171
write_row(out, location_table, &[&self.0, &self.1, &self.2])
156172
}
157173
}
@@ -163,7 +179,11 @@ where
163179
C: FactCell,
164180
D: FactCell,
165181
{
166-
fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box<dyn Error>> {
182+
fn write(
183+
&self,
184+
out: &mut dyn Write,
185+
location_table: &LocationTable,
186+
) -> Result<(), Box<dyn Error>> {
167187
write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3])
168188
}
169189
}

src/librustc_mir/transform/dump_mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>(
6161

6262
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
6363
let path = outputs.path(OutputType::Mir);
64-
let mut f = File::create(&path)?;
64+
let mut f = io::BufWriter::new(File::create(&path)?);
6565
mir_util::write_mir_pretty(tcx, None, &mut f)?;
6666
Ok(())
6767
}

src/librustc_mir/util/liveness.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue;
3636
use rustc_index::bit_set::BitSet;
3737
use rustc_index::vec::{Idx, IndexVec};
3838
use std::fs;
39-
use std::io::{self, Write};
39+
use std::io::{self, BufWriter, Write};
4040
use std::path::{Path, PathBuf};
4141

4242
pub type LiveVarSet = BitSet<Local>;
@@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>(
288288
let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
289289
let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name);
290290
file_path.push(&file_name);
291-
let _ = fs::File::create(&file_path).and_then(|mut file| {
291+
let _ = fs::File::create(&file_path).and_then(|file| {
292+
let mut file = BufWriter::new(file);
292293
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
293294
writeln!(file, "// source = {:?}", source)?;
294295
writeln!(file, "// pass_name = {}", pass_name)?;

0 commit comments

Comments
 (0)