Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel formatting to increase speed #6095

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Comment, import, and minor code cleanup
  • Loading branch information
MarcusGrass committed Feb 26, 2024
commit de08ccd20e6b84cfcdad3915343ae689573611b9
2 changes: 1 addition & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn format(

let parallelism = std::thread::available_parallelism().unwrap_or(NonZeroUsize::MIN);
// Use a channel + map to get 'next-completed' thread, rather than
// waiting on the chronologically first handle to join, if there are more files
// waiting on the chronologically first handle to join, impactful if there are more files
// than available parallelism.
let (send, recv) = std::sync::mpsc::channel();
let mut handles: HashMap<i32, JoinHandle<_>> = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion src/emitter/files.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use std::fs;

#[derive(Default)]
#[derive(Debug, Default)]
pub(crate) struct FilesEmitter {
print_misformatted_file_names: bool,
}
Expand Down
5 changes: 3 additions & 2 deletions src/git-rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use std::str::FromStr;

use getopts::{Matches, Options};
use rustfmt_nightly as rustfmt;
use rustfmt_nightly::print::Printer;
use tracing_subscriber::EnvFilter;

use crate::rustfmt::{load_config, CliOptions, FormatReportFormatterBuilder, Input, Session};
use crate::rustfmt::{
load_config, print::Printer, CliOptions, FormatReportFormatterBuilder, Input, Session,
};

fn prune_files(files: Vec<&str>) -> Vec<&str> {
let prefixes: Vec<_> = files
Expand Down
31 changes: 16 additions & 15 deletions src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ impl Printer {
if inner.messages.is_empty() {
return Ok(());
}

// Stdout term, from diffs
let mut use_term_stdout =
term::stdout().filter(|t| inner.color_setting.use_colored_tty() && t.supports_color());

// `rustc_error` diagnostics, compilation errors.
let use_rustc_error_color = inner.color_setting.use_colored_tty()
&& term::stderr()
.map(|t| t.supports_color())
.unwrap_or_default();
let mut rustc_err_out =
use_rustc_error_color.then_some(StandardStream::stderr(ColorChoice::Always));
let (mut diff_term_stdout, mut rustc_term_stderr) = inner
.color_setting
.use_colored_tty()
.then(|| {
(
term::stdout().filter(|t| t.supports_color()),
term::stderr().and_then(|t| {
t.supports_color()
.then_some(StandardStream::stderr(ColorChoice::Always))
}),
)
})
.unwrap_or_default();
for msg in &inner.messages {
match msg {
PrintMessage::Stdout(out) => {
Expand All @@ -68,7 +69,7 @@ impl Printer {
stderr().write_all(err)?;
}
PrintMessage::Term(t_msg) => {
if let Some(t) = &mut use_term_stdout {
if let Some(t) = &mut diff_term_stdout {
if let Some(col) = t_msg.color {
t.fg(col).unwrap()
}
Expand All @@ -81,12 +82,12 @@ impl Printer {
}
}
PrintMessage::RustcErrTerm(msg) => {
if let Some(t) = &mut rustc_err_out {
if let Some(t) = &mut rustc_term_stderr {
if let Some(col) = msg.color.as_ref().map(rustc_colorspec_compat) {
t.set_color(&col)?;
}
t.write_all(&msg.message)?;
if msg.color.is_some() {
if msg.color.as_ref().map(|cs| cs.reset()).unwrap_or_default() {
t.reset().unwrap();
}
} else {
Expand Down
Loading