Skip to content

Commit

Permalink
tree-wide: parallel: Fully removed all Lrc, replaced with Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
safinaskar committed Feb 3, 2025
1 parent 0eadd99 commit 58ba360
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
use itertools::Itertools;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::{cmp, fmt, iter, str};

use rustc_data_structures::sync::Lrc;
use rustc_span::SourceFile;
use serde::{Deserialize, Deserializer, Serialize, Serializer, ser};
use serde_json as json;
use thiserror::Error;

/// A range of lines in a file, inclusive of both ends.
pub struct LineRange {
pub(crate) file: Lrc<SourceFile>,
pub(crate) file: Arc<SourceFile>,
pub(crate) lo: usize,
pub(crate) hi: usize,
}
Expand Down
97 changes: 49 additions & 48 deletions src/parse/session.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::Path;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_data_structures::sync::IntoDynSyncSend;
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter, SilentEmitter, stderr_destination};
use rustc_errors::registry::Registry;
use rustc_errors::translation::Translate;
Expand All @@ -25,17 +26,17 @@ use crate::{Config, ErrorKind, FileName};
/// ParseSess holds structs necessary for constructing a parser.
pub(crate) struct ParseSess {
raw_psess: RawParseSess,
ignore_path_set: Lrc<IgnorePathSet>,
can_reset_errors: Lrc<AtomicBool>,
ignore_path_set: Arc<IgnorePathSet>,
can_reset_errors: Arc<AtomicBool>,
}

/// Emit errors against every files expect ones specified in the `ignore_path_set`.
struct SilentOnIgnoredFilesEmitter {
ignore_path_set: IntoDynSyncSend<Lrc<IgnorePathSet>>,
source_map: Lrc<SourceMap>,
ignore_path_set: IntoDynSyncSend<Arc<IgnorePathSet>>,
source_map: Arc<SourceMap>,
emitter: Box<DynEmitter>,
has_non_ignorable_parser_errors: bool,
can_reset: Lrc<AtomicBool>,
can_reset: Arc<AtomicBool>,
}

impl SilentOnIgnoredFilesEmitter {
Expand Down Expand Up @@ -96,9 +97,9 @@ impl From<Color> for ColorConfig {
}

fn default_dcx(
source_map: Lrc<SourceMap>,
ignore_path_set: Lrc<IgnorePathSet>,
can_reset: Lrc<AtomicBool>,
source_map: Arc<SourceMap>,
ignore_path_set: Arc<IgnorePathSet>,
can_reset: Arc<AtomicBool>,
show_parse_errors: bool,
color: Color,
) -> DiagCtxt {
Expand Down Expand Up @@ -139,16 +140,16 @@ fn default_dcx(
impl ParseSess {
pub(crate) fn new(config: &Config) -> Result<ParseSess, ErrorKind> {
let ignore_path_set = match IgnorePathSet::from_ignore_list(&config.ignore()) {
Ok(ignore_path_set) => Lrc::new(ignore_path_set),
Ok(ignore_path_set) => Arc::new(ignore_path_set),
Err(e) => return Err(ErrorKind::InvalidGlobPattern(e)),
};
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let can_reset_errors = Lrc::new(AtomicBool::new(false));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let can_reset_errors = Arc::new(AtomicBool::new(false));

let dcx = default_dcx(
Lrc::clone(&source_map),
Lrc::clone(&ignore_path_set),
Lrc::clone(&can_reset_errors),
Arc::clone(&source_map),
Arc::clone(&ignore_path_set),
Arc::clone(&can_reset_errors),
config.show_parse_errors(),
config.color(),
);
Expand Down Expand Up @@ -211,7 +212,7 @@ impl ParseSess {
self.raw_psess.source_map().span_to_filename(span).into()
}

pub(crate) fn span_to_file_contents(&self, span: Span) -> Lrc<rustc_span::SourceFile> {
pub(crate) fn span_to_file_contents(&self, span: Span) -> Arc<rustc_span::SourceFile> {
self.raw_psess
.source_map()
.lookup_source_file(span.data().lo)
Expand Down Expand Up @@ -255,11 +256,11 @@ impl ParseSess {
SnippetProvider::new(
source_file.start_pos,
source_file.end_position(),
Lrc::clone(source_file.src.as_ref().unwrap()),
Arc::clone(source_file.src.as_ref().unwrap()),
)
}

pub(crate) fn get_original_snippet(&self, file_name: &FileName) -> Option<Lrc<String>> {
pub(crate) fn get_original_snippet(&self, file_name: &FileName) -> Option<Arc<String>> {
self.raw_psess
.source_map()
.get_source_file(&file_name.into())
Expand Down Expand Up @@ -331,7 +332,7 @@ mod tests {
use std::sync::atomic::AtomicU32;

struct TestEmitter {
num_emitted_errors: Lrc<AtomicU32>,
num_emitted_errors: Arc<AtomicU32>,
}

impl Translate for TestEmitter {
Expand Down Expand Up @@ -365,15 +366,15 @@ mod tests {
}

fn build_emitter(
num_emitted_errors: Lrc<AtomicU32>,
can_reset: Lrc<AtomicBool>,
source_map: Option<Lrc<SourceMap>>,
num_emitted_errors: Arc<AtomicU32>,
can_reset: Arc<AtomicBool>,
source_map: Option<Arc<SourceMap>>,
ignore_list: Option<IgnoreList>,
) -> SilentOnIgnoredFilesEmitter {
let emitter_writer = TestEmitter { num_emitted_errors };
let source_map =
source_map.unwrap_or_else(|| Lrc::new(SourceMap::new(FilePathMapping::empty())));
let ignore_path_set = Lrc::new(
source_map.unwrap_or_else(|| Arc::new(SourceMap::new(FilePathMapping::empty())));
let ignore_path_set = Arc::new(
IgnorePathSet::from_ignore_list(&ignore_list.unwrap_or_default()).unwrap(),
);
SilentOnIgnoredFilesEmitter {
Expand All @@ -393,10 +394,10 @@ mod tests {

#[test]
fn handles_fatal_parse_error_in_ignored_file() {
let num_emitted_errors = Lrc::new(AtomicU32::new(0));
let can_reset_errors = Lrc::new(AtomicBool::new(false));
let num_emitted_errors = Arc::new(AtomicU32::new(0));
let can_reset_errors = Arc::new(AtomicBool::new(false));
let ignore_list = get_ignore_list(r#"ignore = ["foo.rs"]"#);
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let source =
String::from(r#"extern "system" fn jni_symbol!( funcName ) ( ... ) -> {} "#);
source_map.new_source_file(
Expand All @@ -405,9 +406,9 @@ mod tests {
);
let registry = Registry::new(&[]);
let mut emitter = build_emitter(
Lrc::clone(&num_emitted_errors),
Lrc::clone(&can_reset_errors),
Some(Lrc::clone(&source_map)),
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
Some(Arc::clone(&source_map)),
Some(ignore_list),
);
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
Expand All @@ -420,20 +421,20 @@ mod tests {
#[nightly_only_test]
#[test]
fn handles_recoverable_parse_error_in_ignored_file() {
let num_emitted_errors = Lrc::new(AtomicU32::new(0));
let can_reset_errors = Lrc::new(AtomicBool::new(false));
let num_emitted_errors = Arc::new(AtomicU32::new(0));
let can_reset_errors = Arc::new(AtomicBool::new(false));
let ignore_list = get_ignore_list(r#"ignore = ["foo.rs"]"#);
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let source = String::from(r#"pub fn bar() { 1x; }"#);
source_map.new_source_file(
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
source,
);
let registry = Registry::new(&[]);
let mut emitter = build_emitter(
Lrc::clone(&num_emitted_errors),
Lrc::clone(&can_reset_errors),
Some(Lrc::clone(&source_map)),
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
Some(Arc::clone(&source_map)),
Some(ignore_list),
);
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
Expand All @@ -446,19 +447,19 @@ mod tests {
#[nightly_only_test]
#[test]
fn handles_recoverable_parse_error_in_non_ignored_file() {
let num_emitted_errors = Lrc::new(AtomicU32::new(0));
let can_reset_errors = Lrc::new(AtomicBool::new(false));
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let num_emitted_errors = Arc::new(AtomicU32::new(0));
let can_reset_errors = Arc::new(AtomicBool::new(false));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let source = String::from(r#"pub fn bar() { 1x; }"#);
source_map.new_source_file(
SourceMapFileName::Real(RealFileName::LocalPath(PathBuf::from("foo.rs"))),
source,
);
let registry = Registry::new(&[]);
let mut emitter = build_emitter(
Lrc::clone(&num_emitted_errors),
Lrc::clone(&can_reset_errors),
Some(Lrc::clone(&source_map)),
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
Some(Arc::clone(&source_map)),
None,
);
let span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
Expand All @@ -471,9 +472,9 @@ mod tests {
#[nightly_only_test]
#[test]
fn handles_mix_of_recoverable_parse_error() {
let num_emitted_errors = Lrc::new(AtomicU32::new(0));
let can_reset_errors = Lrc::new(AtomicBool::new(false));
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let num_emitted_errors = Arc::new(AtomicU32::new(0));
let can_reset_errors = Arc::new(AtomicBool::new(false));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let ignore_list = get_ignore_list(r#"ignore = ["foo.rs"]"#);
let bar_source = String::from(r#"pub fn bar() { 1x; }"#);
let foo_source = String::from(r#"pub fn foo() { 1x; }"#);
Expand All @@ -493,9 +494,9 @@ mod tests {
);
let registry = Registry::new(&[]);
let mut emitter = build_emitter(
Lrc::clone(&num_emitted_errors),
Lrc::clone(&can_reset_errors),
Some(Lrc::clone(&source_map)),
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
Some(Arc::clone(&source_map)),
Some(ignore_list),
);
let bar_span = MultiSpan::from_span(mk_sp(BytePos(0), BytePos(1)));
Expand Down
7 changes: 3 additions & 4 deletions src/source_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;
use std::io::{self, Write};
use std::path::Path;
use std::sync::Arc;

use crate::NewlineStyle;
use crate::config::FileName;
Expand All @@ -14,8 +15,6 @@ use crate::create_emitter;
#[cfg(test)]
use crate::formatting::FileRecord;

use rustc_data_structures::sync::Lrc;

// Append a newline to the end of each file.
pub(crate) fn append_newline(s: &mut String) {
s.push('\n');
Expand Down Expand Up @@ -88,11 +87,11 @@ where
// source map instead of hitting the file system. This also supports getting
// original text for `FileName::Stdin`.
let original_text = if newline_style != NewlineStyle::Auto && *filename != FileName::Stdin {
Lrc::new(fs::read_to_string(ensure_real_path(filename))?)
Arc::new(fs::read_to_string(ensure_real_path(filename))?)
} else {
match psess.and_then(|psess| psess.get_original_snippet(filename)) {
Some(ori) => ori,
None => Lrc::new(fs::read_to_string(ensure_real_path(filename))?),
None => Arc::new(fs::read_to_string(ensure_real_path(filename))?),
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::sync::Arc;

use rustc_ast::{ast, token::Delimiter, visit};
use rustc_data_structures::sync::Lrc;
use rustc_span::{BytePos, Pos, Span, symbol};
use tracing::debug;

Expand Down Expand Up @@ -32,7 +32,7 @@ use crate::{ErrorKind, FormatReport, FormattingError};
/// Creates a string slice corresponding to the specified span.
pub(crate) struct SnippetProvider {
/// A pointer to the content of the file we are formatting.
big_snippet: Lrc<String>,
big_snippet: Arc<String>,
/// A position of the start of `big_snippet`, used as an offset.
start_pos: usize,
/// An end position of the file that this snippet lives.
Expand All @@ -46,7 +46,7 @@ impl SnippetProvider {
Some(&self.big_snippet[start_index..end_index])
}

pub(crate) fn new(start_pos: BytePos, end_pos: BytePos, big_snippet: Lrc<String>) -> Self {
pub(crate) fn new(start_pos: BytePos, end_pos: BytePos, big_snippet: Arc<String>) -> Self {
let start_pos = start_pos.to_usize();
let end_pos = end_pos.to_usize();
SnippetProvider {
Expand Down

0 comments on commit 58ba360

Please sign in to comment.