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
Next Next commit
Emitters dont print
  • Loading branch information
MarcusGrass committed Feb 26, 2024
commit 4496f286849d4094cc245823cc07f8ef3a325d92
2 changes: 2 additions & 0 deletions src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) use self::stdout::*;
use crate::FileName;
use std::io::{self, Write};
use std::path::Path;
use crate::print::Printer;

mod checkstyle;
mod diff;
Expand All @@ -32,6 +33,7 @@ pub(crate) trait Emitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
printer: &Printer,
formatted_file: FormattedFile<'_>,
) -> Result<EmitterResult, io::Error>;

Expand Down
1 change: 1 addition & 0 deletions src/emitter/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl Emitter for CheckstyleEmitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
_printer: &Printer,
FormattedFile {
filename,
original_text,
Expand Down
2 changes: 2 additions & 0 deletions src/emitter/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl Emitter for DiffEmitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
printer: &Printer,
FormattedFile {
filename,
original_text,
Expand All @@ -34,6 +35,7 @@ impl Emitter for DiffEmitter {
mismatch,
|line_num| format!("Diff in {}:{}:", filename, line_num),
&self.config,
printer,
);
}
} else if original_text != formatted_text {
Expand Down
6 changes: 4 additions & 2 deletions src/emitter/files.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use std::fs;
use crate::buf_println;

#[derive(Debug, Default)]
pub(crate) struct FilesEmitter {
Expand All @@ -17,7 +18,8 @@ impl FilesEmitter {
impl Emitter for FilesEmitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
_output: &mut dyn Write,
printer: &Printer,
FormattedFile {
filename,
original_text,
Expand All @@ -29,7 +31,7 @@ impl Emitter for FilesEmitter {
if original_text != formatted_text {
fs::write(filename, formatted_text)?;
if self.print_misformatted_file_names {
writeln!(output, "{}", filename.display())?;
buf_println!(printer, "{}", filename.display());
}
}
Ok(EmitterResult::default())
Expand Down
1 change: 1 addition & 0 deletions src/emitter/files_with_backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl Emitter for FilesWithBackupEmitter {
fn emit_formatted_file(
&mut self,
_output: &mut dyn Write,
_printer: &Printer,
FormattedFile {
filename,
original_text,
Expand Down
1 change: 1 addition & 0 deletions src/emitter/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Emitter for JsonEmitter {
fn emit_formatted_file(
&mut self,
_output: &mut dyn Write,
_printer: &Printer,
FormattedFile {
filename,
original_text,
Expand Down
1 change: 1 addition & 0 deletions src/emitter/modified_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl Emitter for ModifiedLinesEmitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
_printer: &Printer,
FormattedFile {
original_text,
formatted_text,
Expand Down
8 changes: 5 additions & 3 deletions src/emitter/stdout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::buf_println;
use super::*;
use crate::config::Verbosity;

Expand All @@ -15,17 +16,18 @@ impl StdoutEmitter {
impl Emitter for StdoutEmitter {
fn emit_formatted_file(
&mut self,
output: &mut dyn Write,
_output: &mut dyn Write,
printer: &Printer,
FormattedFile {
filename,
formatted_text,
..
}: FormattedFile<'_>,
) -> Result<EmitterResult, io::Error> {
if self.verbosity != Verbosity::Quiet {
writeln!(output, "{filename}:\n")?;
buf_println!(printer, "{filename}:\n");
}
write!(output, "{formatted_text}")?;
buf_println!(printer, "{formatted_text}");
Ok(EmitterResult::default())
}
}
1 change: 1 addition & 0 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
out,
&mut *self.emitter,
self.config.newline_style(),
self.printer,
) {
Ok(ref result) if result.has_diff => report.add_diff(),
Err(e) => {
Expand Down
4 changes: 3 additions & 1 deletion src/source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::create_emitter;
use crate::formatting::FileRecord;

use rustc_data_structures::sync::Lrc;
use crate::print::Printer;

// Append a newline to the end of each file.
pub(crate) fn append_newline(s: &mut String) {
Expand Down Expand Up @@ -55,6 +56,7 @@ pub(crate) fn write_file<T>(
out: &mut T,
emitter: &mut dyn Emitter,
newline_style: NewlineStyle,
printer: &Printer,
) -> Result<emitter::EmitterResult, io::Error>
where
T: Write,
Expand Down Expand Up @@ -101,5 +103,5 @@ where
formatted_text,
};

emitter.emit_formatted_file(out, formatted_file)
emitter.emit_formatted_file(out, printer, formatted_file)
}