Skip to content

Commit c1d3b4f

Browse files
committed
Auto merge of #136471 - safinaskar:parallel, r=<try>
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` This is continuation of #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" ( #113349 ) r? SparrowLii `@rustbot` label WG-compiler-parallel
2 parents 8df89d1 + 0a21f1d commit c1d3b4f

File tree

77 files changed

+405
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+405
-395
lines changed

compiler/rustc_ast/src/ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
2121
use std::borrow::Cow;
22+
use std::sync::Arc;
2223
use std::{cmp, fmt};
2324

2425
pub use GenericArgs::*;
@@ -27,7 +28,6 @@ pub use rustc_ast_ir::{Movability, Mutability, Pinnedness};
2728
use rustc_data_structures::packed::Pu128;
2829
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2930
use rustc_data_structures::stack::ensure_sufficient_stack;
30-
use rustc_data_structures::sync::Lrc;
3131
use rustc_data_structures::tagged_ptr::Tag;
3232
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3333
pub use rustc_span::AttrId;
@@ -1611,7 +1611,7 @@ pub enum ExprKind {
16111611
/// Added for optimization purposes to avoid the need to escape
16121612
/// large binary blobs - should always behave like [`ExprKind::Lit`]
16131613
/// with a `ByteStr` literal.
1614-
IncludedBytes(Lrc<[u8]>),
1614+
IncludedBytes(Arc<[u8]>),
16151615

16161616
/// A `format_args!()` expression.
16171617
FormatArgs(P<FormatArgs>),
@@ -1904,9 +1904,9 @@ pub enum LitKind {
19041904
Str(Symbol, StrStyle),
19051905
/// A byte string (`b"foo"`). Not stored as a symbol because it might be
19061906
/// non-utf8, and symbols only allow utf8 strings.
1907-
ByteStr(Lrc<[u8]>, StrStyle),
1907+
ByteStr(Arc<[u8]>, StrStyle),
19081908
/// A C String (`c"foo"`). Guaranteed to only have `\0` at the end.
1909-
CStr(Lrc<[u8]>, StrStyle),
1909+
CStr(Arc<[u8]>, StrStyle),
19101910
/// A byte char (`b'f'`).
19111911
Byte(u8),
19121912
/// A character literal (`'a'`).

compiler/rustc_ast/src/mut_visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
1010
use std::ops::DerefMut;
1111
use std::panic;
12+
use std::sync::Arc;
1213

1314
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1415
use rustc_data_structures::stack::ensure_sufficient_stack;
15-
use rustc_data_structures::sync::Lrc;
1616
use rustc_span::source_map::Spanned;
1717
use rustc_span::{Ident, Span};
1818
use smallvec::{Array, SmallVec, smallvec};
@@ -789,14 +789,14 @@ fn visit_tt<T: MutVisitor>(vis: &mut T, tt: &mut TokenTree) {
789789
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
790790
fn visit_tts<T: MutVisitor>(vis: &mut T, TokenStream(tts): &mut TokenStream) {
791791
if T::VISIT_TOKENS && !tts.is_empty() {
792-
let tts = Lrc::make_mut(tts);
792+
let tts = Arc::make_mut(tts);
793793
visit_vec(tts, |tree| visit_tt(vis, tree));
794794
}
795795
}
796796

797797
fn visit_attr_tts<T: MutVisitor>(vis: &mut T, AttrTokenStream(tts): &mut AttrTokenStream) {
798798
if T::VISIT_TOKENS && !tts.is_empty() {
799-
let tts = Lrc::make_mut(tts);
799+
let tts = Arc::make_mut(tts);
800800
visit_vec(tts, |tree| visit_attr_tt(vis, tree));
801801
}
802802
}
@@ -836,7 +836,7 @@ pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
836836
vis.visit_ident(ident);
837837
}
838838
token::Interpolated(nt) => {
839-
let nt = Lrc::make_mut(nt);
839+
let nt = Arc::make_mut(nt);
840840
visit_nonterminal(vis, nt);
841841
}
842842
_ => {}

compiler/rustc_ast/src/token.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22
use std::fmt;
3+
use std::sync::Arc;
34

45
pub use BinOpToken::*;
56
pub use LitKind::*;
@@ -8,7 +9,6 @@ pub use NtExprKind::*;
89
pub use NtPatKind::*;
910
pub use TokenKind::*;
1011
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
11-
use rustc_data_structures::sync::Lrc;
1212
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1313
use rustc_span::edition::Edition;
1414
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym};
@@ -451,7 +451,7 @@ pub enum TokenKind {
451451
/// The span in the surrounding `Token` is that of the metavariable in the
452452
/// macro's RHS. The span within the Nonterminal is that of the fragment
453453
/// passed to the macro at the call site.
454-
Interpolated(Lrc<Nonterminal>),
454+
Interpolated(Arc<Nonterminal>),
455455

456456
/// A doc comment token.
457457
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -469,7 +469,7 @@ impl Clone for TokenKind {
469469
// a copy. This is faster than the `derive(Clone)` version which has a
470470
// separate path for every variant.
471471
match self {
472-
Interpolated(nt) => Interpolated(Lrc::clone(nt)),
472+
Interpolated(nt) => Interpolated(Arc::clone(nt)),
473473
_ => unsafe { std::ptr::read(self) },
474474
}
475475
}

compiler/rustc_ast/src/tokenstream.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
//! ownership of the original.
1515
1616
use std::borrow::Cow;
17+
use std::sync::Arc;
1718
use std::{cmp, fmt, iter};
1819

1920
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
20-
use rustc_data_structures::sync::{self, Lrc};
21+
use rustc_data_structures::sync;
2122
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2223
use rustc_serialize::{Decodable, Encodable};
2324
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
@@ -119,11 +120,11 @@ impl ToAttrTokenStream for AttrTokenStream {
119120
/// of an actual `TokenStream` until it is needed.
120121
/// `Box` is here only to reduce the structure size.
121122
#[derive(Clone)]
122-
pub struct LazyAttrTokenStream(Lrc<Box<dyn ToAttrTokenStream>>);
123+
pub struct LazyAttrTokenStream(Arc<Box<dyn ToAttrTokenStream>>);
123124

124125
impl LazyAttrTokenStream {
125126
pub fn new(inner: impl ToAttrTokenStream + 'static) -> LazyAttrTokenStream {
126-
LazyAttrTokenStream(Lrc::new(Box::new(inner)))
127+
LazyAttrTokenStream(Arc::new(Box::new(inner)))
127128
}
128129

129130
pub fn to_attr_token_stream(&self) -> AttrTokenStream {
@@ -160,7 +161,7 @@ impl<CTX> HashStable<CTX> for LazyAttrTokenStream {
160161
/// during expansion to perform early cfg-expansion, and to process attributes
161162
/// during proc-macro invocations.
162163
#[derive(Clone, Debug, Default, Encodable, Decodable)]
163-
pub struct AttrTokenStream(pub Lrc<Vec<AttrTokenTree>>);
164+
pub struct AttrTokenStream(pub Arc<Vec<AttrTokenTree>>);
164165

165166
/// Like `TokenTree`, but for `AttrTokenStream`.
166167
#[derive(Clone, Debug, Encodable, Decodable)]
@@ -175,7 +176,7 @@ pub enum AttrTokenTree {
175176

176177
impl AttrTokenStream {
177178
pub fn new(tokens: Vec<AttrTokenTree>) -> AttrTokenStream {
178-
AttrTokenStream(Lrc::new(tokens))
179+
AttrTokenStream(Arc::new(tokens))
179180
}
180181

181182
/// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`. During
@@ -293,7 +294,7 @@ pub struct AttrsTarget {
293294
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for
294295
/// backwards compatibility.
295296
#[derive(Clone, Debug, Default, Encodable, Decodable)]
296-
pub struct TokenStream(pub(crate) Lrc<Vec<TokenTree>>);
297+
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
297298

298299
/// Indicates whether a token can join with the following token to form a
299300
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
@@ -412,7 +413,7 @@ impl PartialEq<TokenStream> for TokenStream {
412413

413414
impl TokenStream {
414415
pub fn new(tts: Vec<TokenTree>) -> TokenStream {
415-
TokenStream(Lrc::new(tts))
416+
TokenStream(Arc::new(tts))
416417
}
417418

418419
pub fn is_empty(&self) -> bool {
@@ -544,7 +545,7 @@ impl TokenStream {
544545
/// Push `tt` onto the end of the stream, possibly gluing it to the last
545546
/// token. Uses `make_mut` to maximize efficiency.
546547
pub fn push_tree(&mut self, tt: TokenTree) {
547-
let vec_mut = Lrc::make_mut(&mut self.0);
548+
let vec_mut = Arc::make_mut(&mut self.0);
548549

549550
if Self::try_glue_to_last(vec_mut, &tt) {
550551
// nothing else to do
@@ -557,7 +558,7 @@ impl TokenStream {
557558
/// token tree to the last token. (No other token trees will be glued.)
558559
/// Uses `make_mut` to maximize efficiency.
559560
pub fn push_stream(&mut self, stream: TokenStream) {
560-
let vec_mut = Lrc::make_mut(&mut self.0);
561+
let vec_mut = Arc::make_mut(&mut self.0);
561562

562563
let stream_iter = stream.0.iter().cloned();
563564

@@ -577,7 +578,7 @@ impl TokenStream {
577578
}
578579

579580
/// Desugar doc comments like `/// foo` in the stream into `#[doc =
580-
/// r"foo"]`. Modifies the `TokenStream` via `Lrc::make_mut`, but as little
581+
/// r"foo"]`. Modifies the `TokenStream` via `Arc::make_mut`, but as little
581582
/// as possible.
582583
pub fn desugar_doc_comments(&mut self) {
583584
if let Some(desugared_stream) = desugar_inner(self.clone()) {
@@ -596,7 +597,7 @@ impl TokenStream {
596597
) => {
597598
let desugared = desugared_tts(attr_style, data, span);
598599
let desugared_len = desugared.len();
599-
Lrc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
600+
Arc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
600601
modified = true;
601602
i += desugared_len;
602603
}
@@ -607,7 +608,7 @@ impl TokenStream {
607608
if let Some(desugared_delim_stream) = desugar_inner(delim_stream.clone()) {
608609
let new_tt =
609610
TokenTree::Delimited(sp, spacing, delim, desugared_delim_stream);
610-
Lrc::make_mut(&mut stream.0)[i] = new_tt;
611+
Arc::make_mut(&mut stream.0)[i] = new_tt;
611612
modified = true;
612613
}
613614
i += 1;

compiler/rustc_ast/src/util/literal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl LitKind {
121121
}
122122
token::ByteStrRaw(n) => {
123123
// Raw strings have no escapes so we can convert the symbol
124-
// directly to a `Lrc<u8>`.
124+
// directly to a `Arc<u8>`.
125125
let buf = symbol.as_str().to_owned().into_bytes();
126126
LitKind::ByteStr(buf.into(), StrStyle::Raw(n))
127127
}
@@ -142,7 +142,7 @@ impl LitKind {
142142
}
143143
token::CStrRaw(n) => {
144144
// Raw strings have no escapes so we can convert the symbol
145-
// directly to a `Lrc<u8>` after appending the terminating NUL
145+
// directly to a `Arc<u8>` after appending the terminating NUL
146146
// char.
147147
let mut buf = symbol.as_str().to_owned().into_bytes();
148148
buf.push(0);

compiler/rustc_ast_lowering/src/expr.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::assert_matches::assert_matches;
22
use std::ops::ControlFlow;
3+
use std::sync::Arc;
34

45
use rustc_ast::ptr::P as AstP;
56
use rustc_ast::*;
67
use rustc_ast_pretty::pprust::expr_to_string;
78
use rustc_data_structures::stack::ensure_sufficient_stack;
8-
use rustc_data_structures::sync::Lrc;
99
use rustc_hir as hir;
1010
use rustc_hir::HirId;
1111
use rustc_hir::def::{DefKind, Res};
@@ -147,7 +147,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
147147
ExprKind::IncludedBytes(bytes) => {
148148
let lit = self.arena.alloc(respan(
149149
self.lower_span(e.span),
150-
LitKind::ByteStr(Lrc::clone(bytes), StrStyle::Cooked),
150+
LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked),
151151
));
152152
hir::ExprKind::Lit(lit)
153153
}
@@ -599,15 +599,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
599599
this.mark_span_with_reason(
600600
DesugaringKind::TryBlock,
601601
expr.span,
602-
Some(Lrc::clone(&this.allow_try_trait)),
602+
Some(Arc::clone(&this.allow_try_trait)),
603603
),
604604
expr,
605605
)
606606
} else {
607607
let try_span = this.mark_span_with_reason(
608608
DesugaringKind::TryBlock,
609609
this.tcx.sess.source_map().end_point(body.span),
610-
Some(Lrc::clone(&this.allow_try_trait)),
610+
Some(Arc::clone(&this.allow_try_trait)),
611611
);
612612

613613
(try_span, this.expr_unit(try_span))
@@ -716,7 +716,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
716716
let unstable_span = self.mark_span_with_reason(
717717
DesugaringKind::Async,
718718
self.lower_span(span),
719-
Some(Lrc::clone(&self.allow_gen_future)),
719+
Some(Arc::clone(&self.allow_gen_future)),
720720
);
721721
let resume_ty =
722722
self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span, None);
@@ -800,7 +800,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
800800
let unstable_span = self.mark_span_with_reason(
801801
DesugaringKind::Async,
802802
span,
803-
Some(Lrc::clone(&self.allow_gen_future)),
803+
Some(Arc::clone(&self.allow_gen_future)),
804804
);
805805
self.lower_attrs(inner_hir_id, &[Attribute {
806806
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
@@ -876,13 +876,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
876876

877877
let features = match await_kind {
878878
FutureKind::Future => None,
879-
FutureKind::AsyncIterator => Some(Lrc::clone(&self.allow_for_await)),
879+
FutureKind::AsyncIterator => Some(Arc::clone(&self.allow_for_await)),
880880
};
881881
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, features);
882882
let gen_future_span = self.mark_span_with_reason(
883883
DesugaringKind::Await,
884884
full_span,
885-
Some(Lrc::clone(&self.allow_gen_future)),
885+
Some(Arc::clone(&self.allow_gen_future)),
886886
);
887887
let expr_hir_id = expr.hir_id;
888888

@@ -1926,13 +1926,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
19261926
let unstable_span = self.mark_span_with_reason(
19271927
DesugaringKind::QuestionMark,
19281928
span,
1929-
Some(Lrc::clone(&self.allow_try_trait)),
1929+
Some(Arc::clone(&self.allow_try_trait)),
19301930
);
19311931
let try_span = self.tcx.sess.source_map().end_point(span);
19321932
let try_span = self.mark_span_with_reason(
19331933
DesugaringKind::QuestionMark,
19341934
try_span,
1935-
Some(Lrc::clone(&self.allow_try_trait)),
1935+
Some(Arc::clone(&self.allow_try_trait)),
19361936
);
19371937

19381938
// `Try::branch(<expr>)`
@@ -2026,7 +2026,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20262026
let unstable_span = self.mark_span_with_reason(
20272027
DesugaringKind::YeetExpr,
20282028
span,
2029-
Some(Lrc::clone(&self.allow_try_trait)),
2029+
Some(Arc::clone(&self.allow_try_trait)),
20302030
);
20312031

20322032
let from_yeet_expr = self.wrap_in_try_constructor(

compiler/rustc_ast_lowering/src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@
4141
#![warn(unreachable_pub)]
4242
// tidy-alphabetical-end
4343

44+
use std::sync::Arc;
45+
4446
use rustc_ast::node_id::NodeMap;
4547
use rustc_ast::{self as ast, *};
4648
use rustc_data_structures::captures::Captures;
4749
use rustc_data_structures::fingerprint::Fingerprint;
4850
use rustc_data_structures::sorted_map::SortedMap;
4951
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
50-
use rustc_data_structures::sync::Lrc;
5152
use rustc_data_structures::tagged_ptr::TaggedRef;
5253
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
5354
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
@@ -129,11 +130,11 @@ struct LoweringContext<'a, 'hir> {
129130
#[cfg(debug_assertions)]
130131
node_id_to_local_id: NodeMap<hir::ItemLocalId>,
131132

132-
allow_try_trait: Lrc<[Symbol]>,
133-
allow_gen_future: Lrc<[Symbol]>,
134-
allow_async_iterator: Lrc<[Symbol]>,
135-
allow_for_await: Lrc<[Symbol]>,
136-
allow_async_fn_traits: Lrc<[Symbol]>,
133+
allow_try_trait: Arc<[Symbol]>,
134+
allow_gen_future: Arc<[Symbol]>,
135+
allow_async_iterator: Arc<[Symbol]>,
136+
allow_for_await: Arc<[Symbol]>,
137+
allow_async_fn_traits: Arc<[Symbol]>,
137138
}
138139

139140
impl<'a, 'hir> LoweringContext<'a, 'hir> {
@@ -722,7 +723,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
722723
&self,
723724
reason: DesugaringKind,
724725
span: Span,
725-
allow_internal_unstable: Option<Lrc<[Symbol]>>,
726+
allow_internal_unstable: Option<Arc<[Symbol]>>,
726727
) -> Span {
727728
self.tcx.with_stable_hashing_context(|hcx| {
728729
span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
@@ -1666,7 +1667,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16661667
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
16671668
CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
16681669
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1669-
(return_impl_trait_id, Some(Lrc::clone(&self.allow_async_iterator)))
1670+
(return_impl_trait_id, Some(Arc::clone(&self.allow_async_iterator)))
16701671
}
16711672
};
16721673

0 commit comments

Comments
 (0)