Skip to content

Commit 713efad

Browse files
Auto merge of #145980 - nnethercote:triomphe-basic, r=<try>
Use `triomphe::Arc` in `TokenStream`.
2 parents ef8d1d6 + 426c353 commit 713efad

File tree

9 files changed

+51
-8
lines changed

9 files changed

+51
-8
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,7 @@ dependencies = [
36153615
"tempfile",
36163616
"thin-vec",
36173617
"tracing",
3618+
"triomphe",
36183619
"windows 0.61.3",
36193620
]
36203621

@@ -4494,6 +4495,7 @@ dependencies = [
44944495
"smallvec",
44954496
"tempfile",
44964497
"thin-vec",
4498+
"triomphe",
44974499
]
44984500

44994501
[[package]]
@@ -5601,6 +5603,16 @@ dependencies = [
56015603
"tracing-subscriber",
56025604
]
56035605

5606+
[[package]]
5607+
name = "triomphe"
5608+
version = "0.1.14"
5609+
source = "registry+https://github.com/rust-lang/crates.io-index"
5610+
checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85"
5611+
dependencies = [
5612+
"serde",
5613+
"stable_deref_trait",
5614+
]
5615+
56045616
[[package]]
56055617
name = "twox-hash"
56065618
version = "1.6.3"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ memchr = "2.7.5"
6767
rustc-literal-escaper = "0.0.5"
6868
thin-vec = "0.2.14"
6969
tracing = "0.1.37"
70+
triomphe = "0.1.14"
7071
# tidy-alphabetical-end
7172

7273
[profile.release.package.rustc_thread_pool]

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::sync::Arc;
1919
use std::{cmp, fmt, iter, mem};
2020

2121
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22-
use rustc_data_structures::sync;
22+
use rustc_data_structures::sync::{self, TrArc};
2323
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
2424
use rustc_serialize::{Decodable, Encodable};
2525
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
@@ -558,7 +558,7 @@ pub struct AttrsTarget {
558558

559559
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
560560
#[derive(Clone, Debug, Default, Encodable, Decodable)]
561-
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
561+
pub struct TokenStream(pub(crate) TrArc<Vec<TokenTree>>);
562562

563563
/// Indicates whether a token can join with the following token to form a
564564
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
@@ -675,7 +675,7 @@ impl PartialEq<TokenStream> for TokenStream {
675675

676676
impl TokenStream {
677677
pub fn new(tts: Vec<TokenTree>) -> TokenStream {
678-
TokenStream(Arc::new(tts))
678+
TokenStream(TrArc::new(tts))
679679
}
680680

681681
pub fn is_empty(&self) -> bool {
@@ -728,7 +728,7 @@ impl TokenStream {
728728
/// Push `tt` onto the end of the stream, possibly gluing it to the last
729729
/// token. Uses `make_mut` to maximize efficiency.
730730
pub fn push_tree(&mut self, tt: TokenTree) {
731-
let vec_mut = Arc::make_mut(&mut self.0);
731+
let vec_mut = TrArc::make_mut(&mut self.0);
732732

733733
if Self::try_glue_to_last(vec_mut, &tt) {
734734
// nothing else to do
@@ -741,7 +741,7 @@ impl TokenStream {
741741
/// token tree to the last token. (No other token trees will be glued.)
742742
/// Uses `make_mut` to maximize efficiency.
743743
pub fn push_stream(&mut self, stream: TokenStream) {
744-
let vec_mut = Arc::make_mut(&mut self.0);
744+
let vec_mut = TrArc::make_mut(&mut self.0);
745745

746746
let stream_iter = stream.0.iter().cloned();
747747

@@ -761,7 +761,7 @@ impl TokenStream {
761761
}
762762

763763
/// Desugar doc comments like `/// foo` in the stream into `#[doc =
764-
/// r"foo"]`. Modifies the `TokenStream` via `Arc::make_mut`, but as little
764+
/// r"foo"]`. Modifies the `TokenStream` via `TrArc::make_mut`, but as little
765765
/// as possible.
766766
pub fn desugar_doc_comments(&mut self) {
767767
if let Some(desugared_stream) = desugar_inner(self.clone()) {
@@ -780,7 +780,7 @@ impl TokenStream {
780780
) => {
781781
let desugared = desugared_tts(attr_style, data, span);
782782
let desugared_len = desugared.len();
783-
Arc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
783+
TrArc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
784784
modified = true;
785785
i += desugared_len;
786786
}
@@ -791,7 +791,7 @@ impl TokenStream {
791791
if let Some(desugared_delim_stream) = desugar_inner(delim_stream.clone()) {
792792
let new_tt =
793793
TokenTree::Delimited(sp, spacing, delim, desugared_delim_stream);
794-
Arc::make_mut(&mut stream.0)[i] = new_tt;
794+
TrArc::make_mut(&mut stream.0)[i] = new_tt;
795795
modified = true;
796796
}
797797
i += 1;

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ stacker = "0.1.17"
2828
tempfile = "3.2"
2929
thin-vec.workspace = true
3030
tracing.workspace = true
31+
triomphe.workspace = true
3132
# tidy-alphabetical-end
3233

3334
[dependencies.hashbrown]

compiler/rustc_data_structures/src/marker.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ impl_dyn_send!(
7575
[std::sync::Mutex<T> where T: ?Sized+ DynSend]
7676
[std::sync::mpsc::Sender<T> where T: DynSend]
7777
[std::sync::Arc<T> where T: ?Sized + DynSync + DynSend]
78+
[crate::sync::TrArc<T> where T: ?Sized + DynSync + DynSend]
79+
[crate::sync::TrUniqueArc<T> where T: ?Sized + DynSync + DynSend]
80+
[crate::sync::TrThinArc<H, T> where H: DynSync + DynSend, T: DynSync + DynSend]
7881
[std::sync::LazyLock<T, F> where T: DynSend, F: DynSend]
7982
[std::collections::HashSet<K, S> where K: DynSend, S: DynSend]
8083
[std::collections::HashMap<K, V, S> where K: DynSend, V: DynSend, S: DynSend]
@@ -157,6 +160,9 @@ impl_dyn_sync!(
157160
[std::sync::OnceLock<T> where T: DynSend + DynSync]
158161
[std::sync::Mutex<T> where T: ?Sized + DynSend]
159162
[std::sync::Arc<T> where T: ?Sized + DynSync + DynSend]
163+
[crate::sync::TrArc<T> where T: ?Sized + DynSync + DynSend]
164+
[crate::sync::TrUniqueArc<T> where T: ?Sized + DynSync + DynSend]
165+
[crate::sync::TrThinArc<H, T> where H: DynSync + DynSend, T: DynSync + DynSend]
160166
[std::sync::LazyLock<T, F> where T: DynSend + DynSync, F: DynSend]
161167
[std::collections::HashSet<K, S> where K: DynSync, S: DynSync]
162168
[std::collections::HashMap<K, V, S> where K: DynSync, V: DynSync, S: DynSync]

compiler/rustc_data_structures/src/sync.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ mod mode {
105105
}
106106
}
107107

108+
/// Alternative form of `Arc` that lacks a weak ref count.
109+
pub type TrArc<T> = triomphe::Arc<T>;
110+
111+
/// Alternative form of `UniqueArc` that lacks a weak ref count.
112+
pub type TrUniqueArc<T> = triomphe::UniqueArc<T>;
113+
114+
/// Like `TrArc<(H, [T])>`, but with a thin pointer.
115+
pub type TrThinArc<H, T> = triomphe::ThinArc<H, T>;
116+
108117
// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
109118

110119
#[derive(Debug, Default)]

compiler/rustc_serialize/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ indexmap = "2.0.0"
99
rustc_hashes = { path = "../rustc_hashes" }
1010
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1111
thin-vec.workspace = true
12+
triomphe.workspace = true
1213
# tidy-alphabetical-end
1314

1415
[dev-dependencies]

compiler/rustc_serialize/src/serialize.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> {
509509
}
510510
}
511511

512+
impl<S: Encoder, T: Encodable<S>> Encodable<S> for triomphe::Arc<T> {
513+
fn encode(&self, s: &mut S) {
514+
(**self).encode(s);
515+
}
516+
}
517+
518+
impl<D: Decoder, T: Decodable<D>> Decodable<D> for triomphe::Arc<T> {
519+
fn decode(d: &mut D) -> triomphe::Arc<T> {
520+
triomphe::Arc::new(Decodable::decode(d))
521+
}
522+
}
523+
512524
impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> {
513525
fn encode(&self, s: &mut S) {
514526
(**self).encode(s)

src/tools/tidy/src/deps.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
393393
"tracing-log",
394394
"tracing-subscriber",
395395
"tracing-tree",
396+
"triomphe",
396397
"twox-hash",
397398
"type-map",
398399
"typenum",

0 commit comments

Comments
 (0)