Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3687,6 +3687,7 @@ dependencies = [
"tempfile",
"thin-vec",
"tracing",
"triomphe",
"windows 0.61.3",
]

Expand Down Expand Up @@ -4567,6 +4568,7 @@ dependencies = [
"smallvec",
"tempfile",
"thin-vec",
"triomphe",
]

[[package]]
Expand Down Expand Up @@ -5684,6 +5686,16 @@ dependencies = [
"tracing-subscriber",
]

[[package]]
name = "triomphe"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85"
dependencies = [
"serde",
"stable_deref_trait",
]

[[package]]
name = "twox-hash"
version = "1.6.3"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ memchr = "2.7.5"
rustc-literal-escaper = "0.0.5"
thin-vec = "0.2.14"
tracing = "0.1.37"
triomphe = "0.1.14"
# tidy-alphabetical-end

[profile.release.package.rustc_thread_pool]
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::Arc;
use std::{cmp, fmt, iter, mem};

use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync;
use rustc_data_structures::sync::{self, TrArc};
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
use rustc_serialize::{Decodable, Encodable};
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
Expand Down Expand Up @@ -558,7 +558,7 @@ pub struct AttrsTarget {

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

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

impl TokenStream {
pub fn new(tts: Vec<TokenTree>) -> TokenStream {
TokenStream(Arc::new(tts))
TokenStream(TrArc::new(tts))
}

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

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

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

Expand All @@ -761,7 +761,7 @@ impl TokenStream {
}

/// Desugar doc comments like `/// foo` in the stream into `#[doc =
/// r"foo"]`. Modifies the `TokenStream` via `Arc::make_mut`, but as little
/// r"foo"]`. Modifies the `TokenStream` via `TrArc::make_mut`, but as little
/// as possible.
pub fn desugar_doc_comments(&mut self) {
if let Some(desugared_stream) = desugar_inner(self.clone()) {
Expand All @@ -780,7 +780,7 @@ impl TokenStream {
) => {
let desugared = desugared_tts(attr_style, data, span);
let desugared_len = desugared.len();
Arc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
TrArc::make_mut(&mut stream.0).splice(i..i + 1, desugared);
modified = true;
i += desugared_len;
}
Expand All @@ -791,7 +791,7 @@ impl TokenStream {
if let Some(desugared_delim_stream) = desugar_inner(delim_stream.clone()) {
let new_tt =
TokenTree::Delimited(sp, spacing, delim, desugared_delim_stream);
Arc::make_mut(&mut stream.0)[i] = new_tt;
TrArc::make_mut(&mut stream.0)[i] = new_tt;
modified = true;
}
i += 1;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ stacker = "0.1.17"
tempfile = "3.2"
thin-vec.workspace = true
tracing.workspace = true
triomphe.workspace = true
# tidy-alphabetical-end

[dependencies.hashbrown]
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_data_structures/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ impl_dyn_send!(
[std::sync::Mutex<T> where T: ?Sized+ DynSend]
[std::sync::mpsc::Sender<T> where T: DynSend]
[std::sync::Arc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrArc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrUniqueArc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrThinArc<H, T> where H: DynSync + DynSend, T: DynSync + DynSend]
[std::sync::LazyLock<T, F> where T: DynSend, F: DynSend]
[std::collections::HashSet<K, S> where K: DynSend, S: DynSend]
[std::collections::HashMap<K, V, S> where K: DynSend, V: DynSend, S: DynSend]
Expand Down Expand Up @@ -157,6 +160,9 @@ impl_dyn_sync!(
[std::sync::OnceLock<T> where T: DynSend + DynSync]
[std::sync::Mutex<T> where T: ?Sized + DynSend]
[std::sync::Arc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrArc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrUniqueArc<T> where T: ?Sized + DynSync + DynSend]
[crate::sync::TrThinArc<H, T> where H: DynSync + DynSend, T: DynSync + DynSend]
[std::sync::LazyLock<T, F> where T: DynSend + DynSync, F: DynSend]
[std::collections::HashSet<K, S> where K: DynSync, S: DynSync]
[std::collections::HashMap<K, V, S> where K: DynSync, V: DynSync, S: DynSync]
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ mod mode {
}
}

/// Alternative form of `Arc` that lacks a weak ref count.
pub type TrArc<T> = triomphe::Arc<T>;

/// Alternative form of `UniqueArc` that lacks a weak ref count.
pub type TrUniqueArc<T> = triomphe::UniqueArc<T>;

/// Like `TrArc<(H, [T])>`, but with a thin pointer.
pub type TrThinArc<H, T> = triomphe::ThinArc<H, T>;

// FIXME(parallel_compiler): Get rid of these aliases across the compiler.

#[derive(Debug, Default)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ indexmap = "2.0.0"
rustc_hashes = { path = "../rustc_hashes" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec.workspace = true
triomphe.workspace = true
# tidy-alphabetical-end

[dev-dependencies]
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_serialize/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,18 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> {
}
}

impl<S: Encoder, T: Encodable<S>> Encodable<S> for triomphe::Arc<T> {
fn encode(&self, s: &mut S) {
(**self).encode(s);
}
}

impl<D: Decoder, T: Decodable<D>> Decodable<D> for triomphe::Arc<T> {
fn decode(d: &mut D) -> triomphe::Arc<T> {
triomphe::Arc::new(Decodable::decode(d))
}
}

impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> {
fn encode(&self, s: &mut S) {
(**self).encode(s)
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"tracing-log",
"tracing-subscriber",
"tracing-tree",
"triomphe",
"twox-hash",
"type-map",
"typenum",
Expand Down
Loading