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
Clean up a bit more
  • Loading branch information
MarcusGrass committed Feb 26, 2024
commit eb78a340a0c377715d89e37bb140c947167f09a3
17 changes: 8 additions & 9 deletions src/emitter/files.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use super::*;
use crate::buf_println;
use std::fs;

#[derive(Default)]
pub(crate) struct FilesEmitter<'a> {
print_misformatted_file_names: Option<&'a Printer>,
pub(crate) struct FilesEmitter {
print_misformatted_file_names: bool,
}

impl<'a> FilesEmitter<'a> {
pub(crate) fn new(print_misformatted_file_names: Option<&'a Printer>) -> Self {
impl FilesEmitter {
pub(crate) fn new(print_misformatted_file_names: bool) -> Self {
Self {
print_misformatted_file_names,
}
}
}

impl<'a> Emitter for FilesEmitter<'a> {
impl Emitter for FilesEmitter {
fn emit_formatted_file(
&mut self,
_output: &mut dyn Write,
output: &mut dyn Write,
FormattedFile {
filename,
original_text,
Expand All @@ -29,8 +28,8 @@ impl<'a> Emitter for FilesEmitter<'a> {
let filename = ensure_real_path(filename);
if original_text != formatted_text {
fs::write(filename, formatted_text)?;
if let Some(printer) = self.print_misformatted_file_names {
buf_println!(printer, "{}", filename.display());
if self.print_misformatted_file_names {
writeln!(output, "{}", filename.display())?;
}
}
Ok(EmitterResult::default())
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ pub(crate) fn create_emitter<'a>(config: &Config, printer: &'a Printer) -> Box<d
Box::new(emitter::FilesWithBackupEmitter::default())
}
EmitMode::Files => Box::new(emitter::FilesEmitter::new(
config.print_misformatted_file_names().then_some(printer),
config.print_misformatted_file_names(),
)),
EmitMode::Stdout | EmitMode::Coverage => {
Box::new(emitter::IntoOutputEmitter::new(config.verbose()))
Expand Down
2 changes: 0 additions & 2 deletions src/parse/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ fn default_dcx(
ignore_path_set: Lrc<IgnorePathSet>,
can_reset: Lrc<AtomicBool>,
show_parse_errors: bool,
_color: Color,
printer: &Printer,
) -> DiagCtxt {
let emitter = if !show_parse_errors {
Expand Down Expand Up @@ -162,7 +161,6 @@ impl ParseSess {
Lrc::clone(&ignore_path_set),
Lrc::clone(&can_reset_errors),
config.show_parse_errors(),
config.color(),
printer,
);
let parse_sess = RawParseSess::with_dcx(dcx, source_map);
Expand Down