Skip to content

Commit d2497ac

Browse files
committed
Auto merge of rust-lang#136471 - safinaskar:parallel, r=SparrowLii
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` This is continuation of rust-lang#132282 . I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement. There are other possibilities, through. We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase. So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge. cc "Parallel Rustc Front-end" ( rust-lang#113349 ) r? SparrowLii `@rustbot` label WG-compiler-parallel
2 parents 4c11087 + 5884fd0 commit d2497ac

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

clippy_lints/src/attrs/mixed_attributes_style.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use std::sync::Arc;
12
use super::MIXED_ATTRIBUTES_STYLE;
23
use clippy_utils::diagnostics::span_lint;
34
use rustc_ast::{AttrKind, AttrStyle, Attribute};
45
use rustc_data_structures::fx::FxHashSet;
5-
use rustc_data_structures::sync::Lrc;
66
use rustc_lint::{EarlyContext, LintContext};
77
use rustc_span::source_map::SourceMap;
88
use rustc_span::{SourceFile, Span, Symbol};
@@ -79,7 +79,7 @@ fn lint_mixed_attrs(cx: &EarlyContext<'_>, attrs: &[Attribute]) {
7979
);
8080
}
8181

82-
fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc<SourceFile>, attr_span: Span) -> bool {
82+
fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc<SourceFile>, attr_span: Span) -> bool {
8383
let attr_src = source_map.lookup_source_file(attr_span.lo());
84-
Lrc::ptr_eq(item_src, &attr_src)
84+
Arc::ptr_eq(item_src, &attr_src)
8585
}

clippy_lints/src/doc/needless_doctest_main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::ops::Range;
22
use std::{io, thread};
3+
use std::sync::Arc;
34

45
use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST};
56
use clippy_utils::diagnostics::span_lint;
67
use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
7-
use rustc_data_structures::sync::Lrc;
88
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::{Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
@@ -46,8 +46,8 @@ pub fn check(
4646
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
4747
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);
4848
let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings();
49-
#[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx
50-
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
49+
#[expect(clippy::arc_with_non_send_sync)] // `Arc` is expected by with_dcx
50+
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
5151
let psess = ParseSess::with_dcx(dcx, sm);
5252

5353
let mut parser = match new_parser_from_source_str(&psess, filename, code) {

clippy_lints/src/undocumented_unsafe_blocks.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::sync::Arc;
12
use std::ops::ControlFlow;
23

34
use clippy_config::Conf;
@@ -6,7 +7,6 @@ use clippy_utils::is_lint_allowed;
67
use clippy_utils::source::walk_span_to_context;
78
use clippy_utils::visitors::{Descend, for_each_expr};
89
use hir::HirId;
9-
use rustc_data_structures::sync::Lrc;
1010
use rustc_hir as hir;
1111
use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource};
1212
use rustc_lexer::{TokenKind, tokenize};
@@ -480,7 +480,7 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf
480480
if let Some(comment_start) = comment_start
481481
&& let Ok(unsafe_line) = source_map.lookup_line(item.span.lo())
482482
&& let Ok(comment_start_line) = source_map.lookup_line(comment_start)
483-
&& Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf)
483+
&& Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf)
484484
&& let Some(src) = unsafe_line.sf.src.as_deref()
485485
{
486486
return if comment_start_line.line >= unsafe_line.line {
@@ -520,7 +520,7 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H
520520
if let Some(comment_start) = comment_start
521521
&& let Ok(unsafe_line) = source_map.lookup_line(span.lo())
522522
&& let Ok(comment_start_line) = source_map.lookup_line(comment_start)
523-
&& Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf)
523+
&& Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf)
524524
&& let Some(src) = unsafe_line.sf.src.as_deref()
525525
{
526526
return if comment_start_line.line >= unsafe_line.line {
@@ -580,7 +580,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
580580
// ^--------------------------------------------^
581581
if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
582582
&& let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo())
583-
&& Lrc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
583+
&& Arc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
584584
&& let Some(src) = unsafe_line.sf.src.as_deref()
585585
{
586586
if macro_line.line < unsafe_line.line {
@@ -641,7 +641,7 @@ fn span_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool {
641641
if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
642642
&& let Some(body_span) = walk_span_to_context(search_span, SyntaxContext::root())
643643
&& let Ok(body_line) = source_map.lookup_line(body_span.lo())
644-
&& Lrc::ptr_eq(&unsafe_line.sf, &body_line.sf)
644+
&& Arc::ptr_eq(&unsafe_line.sf, &body_line.sf)
645645
&& let Some(src) = unsafe_line.sf.src.as_deref()
646646
{
647647
// Get the text from the start of function body to the unsafe block.

clippy_lints/src/utils/attr_collector.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::mem;
2-
use std::sync::OnceLock;
2+
use std::sync::{Arc, OnceLock};
33

44
use rustc_ast::{Attribute, Crate};
5-
use rustc_data_structures::sync::Lrc;
65
use rustc_lint::{EarlyContext, EarlyLintPass};
76
use rustc_session::impl_lint_pass;
87
use rustc_span::Span;
98

109
#[derive(Clone, Default)]
11-
pub struct AttrStorage(pub Lrc<OnceLock<Vec<Span>>>);
10+
pub struct AttrStorage(pub Arc<OnceLock<Vec<Span>>>);
1211

1312
pub struct AttrCollector {
1413
storage: AttrStorage,

clippy_utils/src/consts.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
//! executable MIR bodies, so we have to do this instead.
55
#![allow(clippy::float_cmp)]
66

7+
use std::sync::Arc;
8+
79
use crate::source::{SpanRangeExt, walk_span_to_context};
810
use crate::{clip, is_direct_expn_of, sext, unsext};
911

1012
use rustc_apfloat::Float;
1113
use rustc_apfloat::ieee::{Half, Quad};
1214
use rustc_ast::ast::{self, LitFloatType, LitKind};
13-
use rustc_data_structures::sync::Lrc;
1415
use rustc_hir::def::{DefKind, Res};
1516
use rustc_hir::{
1617
BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, PatExpr, PatExprKind, QPath, UnOp,
@@ -37,7 +38,7 @@ pub enum Constant<'tcx> {
3738
/// A `String` (e.g., "abc").
3839
Str(String),
3940
/// A binary string (e.g., `b"abc"`).
40-
Binary(Lrc<[u8]>),
41+
Binary(Arc<[u8]>),
4142
/// A single `char` (e.g., `'a'`).
4243
Char(char),
4344
/// An integer's bit representation.
@@ -305,7 +306,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option<Ty<'tcx>>) -> Constan
305306
match *lit {
306307
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
307308
LitKind::Byte(b) => Constant::Int(u128::from(b)),
308-
LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
309+
LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Arc::clone(s)),
309310
LitKind::Char(c) => Constant::Char(c),
310311
LitKind::Int(n, _) => Constant::Int(n.get()),
311312
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {

clippy_utils/src/macros.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#![allow(clippy::similar_names)] // `expr` and `expn`
22

3+
use std::sync::Arc;
4+
35
use crate::get_unique_attr;
46
use crate::visitors::{Descend, for_each_expr_without_closures};
57

68
use arrayvec::ArrayVec;
79
use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder};
810
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_data_structures::sync::{Lrc, OnceLock};
11+
use rustc_data_structures::sync::OnceLock;
1012
use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath};
1113
use rustc_lint::{LateContext, LintContext};
1214
use rustc_span::def_id::DefId;
@@ -393,7 +395,7 @@ fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) ->
393395
/// Stores AST [`FormatArgs`] nodes for use in late lint passes, as they are in a desugared form in
394396
/// the HIR
395397
#[derive(Default, Clone)]
396-
pub struct FormatArgsStorage(Lrc<OnceLock<FxHashMap<Span, FormatArgs>>>);
398+
pub struct FormatArgsStorage(Arc<OnceLock<FxHashMap<Span, FormatArgs>>>);
397399

398400
impl FormatArgsStorage {
399401
/// Returns an AST [`FormatArgs`] node if a `format_args` expansion is found as a descendant of

clippy_utils/src/source.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
33
#![allow(clippy::module_name_repetitions)]
44

5+
use std::sync::Arc;
6+
57
use rustc_ast::{LitKind, StrStyle};
6-
use rustc_data_structures::sync::Lrc;
78
use rustc_errors::Applicability;
89
use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource};
910
use rustc_lint::{EarlyContext, LateContext};
@@ -204,7 +205,7 @@ impl fmt::Display for SourceText {
204205
fn get_source_range(sm: &SourceMap, sp: Range<BytePos>) -> Option<SourceFileRange> {
205206
let start = sm.lookup_byte_offset(sp.start);
206207
let end = sm.lookup_byte_offset(sp.end);
207-
if !Lrc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos {
208+
if !Arc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos {
208209
return None;
209210
}
210211
sm.ensure_source_file_source_present(&start.sf);
@@ -277,7 +278,7 @@ fn trim_start(sm: &SourceMap, sp: Range<BytePos>) -> Range<BytePos> {
277278
}
278279

279280
pub struct SourceFileRange {
280-
pub sf: Lrc<SourceFile>,
281+
pub sf: Arc<SourceFile>,
281282
pub range: Range<usize>,
282283
}
283284
impl SourceFileRange {

0 commit comments

Comments
 (0)