syntax: move GLOBALS to attr module

This commit is contained in:
Mazdak Farrokhzad 2020-01-11 09:59:14 +01:00
parent 50f0e2e9e6
commit e03d1064f0
6 changed files with 38 additions and 41 deletions

View File

@ -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),

View File

@ -65,7 +65,7 @@ impl Compiler {
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_default_globals(move || {
syntax::attr::with_default_globals(move || {
let cfg = cfgspecs
.into_iter()
.map(|s| {

View File

@ -146,7 +146,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> 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())));

View File

@ -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;

View File

@ -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<GrowableBitSet<AttrId>>,
known_attrs: Lock<GrowableBitSet<AttrId>>,
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<R>(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<R>(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| {

View File

@ -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<GrowableBitSet<AttrId>>,
known_attrs: Lock<GrowableBitSet<AttrId>>,
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<R>(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<R>(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;