Skip to content

Short circuit Send and Sync impls for TokenTree #60967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2019
Merged
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
22 changes: 22 additions & 0 deletions src/libsyntax/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ pub enum TokenTree {
Delimited(DelimSpan, DelimToken, TokenStream),
}

// Ensure all fields of `TokenTree` is `Send` and `Sync`.
#[cfg(parallel_compiler)]
fn _dummy()
where
Span: Send + Sync,
token::Token: Send + Sync,
DelimSpan: Send + Sync,
DelimToken: Send + Sync,
TokenStream: Send + Sync,
{}

// These are safe since we ensure that they hold for all fields in the `_dummy` function.
//
// These impls are only here because the compiler takes forever to compute the Send and Sync
// bounds without them.
// FIXME: Remove these impls when the compiler can compute the bounds quickly again.
// See https://github.com/rust-lang/rust/issues/60846
#[cfg(parallel_compiler)]
unsafe impl Send for TokenTree {}
#[cfg(parallel_compiler)]
unsafe impl Sync for TokenTree {}

impl TokenTree {
/// Use this token tree as a matcher to parse given tts.
pub fn parse(cx: &base::ExtCtxt<'_>, mtch: &[quoted::TokenTree], tts: TokenStream)
Expand Down