From e03d1064f0d98961b83885ce951351ae57cc7aad Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 11 Jan 2020 09:59:14 +0100 Subject: [PATCH] syntax: move GLOBALS to attr module --- src/librustc_expand/expand.rs | 2 +- src/librustc_interface/interface.rs | 2 +- src/librustc_interface/util.rs | 2 +- src/librustdoc/test.rs | 2 +- src/libsyntax/attr/mod.rs | 37 ++++++++++++++++++++++++++--- src/libsyntax/lib.rs | 34 -------------------------- 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index ea459064b09..910a0e52e53 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -1671,7 +1671,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } let meta = attr::mk_list_item(Ident::with_dummy_span(sym::doc), items); - *at = attr::Attribute { + *at = ast::Attribute { kind: ast::AttrKind::Normal(AttrItem { path: meta.path, args: meta.kind.mac_args(meta.span), diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index 9cd9eb66cf6..f491d662f97 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -65,7 +65,7 @@ impl Compiler { /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`. pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option)> { - syntax::with_default_globals(move || { + syntax::attr::with_default_globals(move || { let cfg = cfgspecs .into_iter() .map(|s| { diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 00528eca923..6bda85ded2b 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -146,7 +146,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( crate::callbacks::setup_callbacks(); scoped_thread(cfg, || { - syntax::with_globals(edition, || { + syntax::attr::with_globals(edition, || { ty::tls::GCX_PTR.set(&Lock::new(0), || { if let Some(stderr) = stderr { io::set_panic(Some(box Sink(stderr.clone()))); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index d89dc2adafe..ba36e06fd37 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -18,7 +18,7 @@ use std::path::PathBuf; use std::process::{self, Command, Stdio}; use std::str; use syntax::ast; -use syntax::with_globals; +use syntax::attr::with_globals; use tempfile::Builder as TempFileBuilder; use testing; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index ec05dab451a..419297678d2 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -2,22 +2,24 @@ mod builtin; -pub use crate::ast::Attribute; pub use builtin::*; pub use IntType::*; pub use ReprAttr::*; pub use StabilityLevel::*; use crate::ast; -use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Ident, Name, Path, PathSegment}; +use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute}; use crate::ast::{Expr, GenericParam, Item, Lit, LitKind, Local, Stmt, StmtKind}; +use crate::ast::{Ident, Name, Path, PathSegment}; use crate::ast::{MacArgs, MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem}; use crate::mut_visit::visit_clobber; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint}; -use crate::GLOBALS; +use rustc_data_structures::sync::Lock; +use rustc_index::bit_set::GrowableBitSet; +use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::source_map::{BytePos, Spanned}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; @@ -26,6 +28,35 @@ use log::debug; use std::iter; use std::ops::DerefMut; +pub struct Globals { + used_attrs: Lock>, + known_attrs: Lock>, + rustc_span_globals: rustc_span::Globals, +} + +impl Globals { + fn new(edition: Edition) -> Globals { + Globals { + // We have no idea how many attributes there will be, so just + // initiate the vectors with 0 bits. We'll grow them as necessary. + used_attrs: Lock::new(GrowableBitSet::new_empty()), + known_attrs: Lock::new(GrowableBitSet::new_empty()), + rustc_span_globals: rustc_span::Globals::new(edition), + } + } +} + +pub fn with_globals(edition: Edition, f: impl FnOnce() -> R) -> R { + let globals = Globals::new(edition); + GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f)) +} + +pub fn with_default_globals(f: impl FnOnce() -> R) -> R { + with_globals(DEFAULT_EDITION, f) +} + +scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); + pub fn mark_used(attr: &Attribute) { debug!("marking {:?} as used", attr); GLOBALS.with(|globals| { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 6c88cd738f4..9fcc7a1dfa8 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -17,11 +17,6 @@ #![feature(unicode_internals)] #![recursion_limit = "256"] -use ast::AttrId; -use rustc_data_structures::sync::Lock; -use rustc_index::bit_set::GrowableBitSet; -use rustc_span::edition::{Edition, DEFAULT_EDITION}; - #[macro_export] macro_rules! unwrap_or { ($opt:expr, $default:expr) => { @@ -32,35 +27,6 @@ macro_rules! unwrap_or { }; } -pub struct Globals { - used_attrs: Lock>, - known_attrs: Lock>, - rustc_span_globals: rustc_span::Globals, -} - -impl Globals { - fn new(edition: Edition) -> Globals { - Globals { - // We have no idea how many attributes there will be, so just - // initiate the vectors with 0 bits. We'll grow them as necessary. - used_attrs: Lock::new(GrowableBitSet::new_empty()), - known_attrs: Lock::new(GrowableBitSet::new_empty()), - rustc_span_globals: rustc_span::Globals::new(edition), - } - } -} - -pub fn with_globals(edition: Edition, f: impl FnOnce() -> R) -> R { - let globals = Globals::new(edition); - GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f)) -} - -pub fn with_default_globals(f: impl FnOnce() -> R) -> R { - with_globals(DEFAULT_EDITION, f) -} - -scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); - pub mod util { pub mod classify; pub mod comments;