diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-11 09:59:14 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-01 18:54:55 +0100 |
| commit | e03d1064f0d98961b83885ce951351ae57cc7aad (patch) | |
| tree | 28a1df9cf7cf2709531328a68370bfd4d8f88035 /src/libsyntax/attr/mod.rs | |
| parent | 50f0e2e9e6e85c5ae15ffde79e34edfd284465fd (diff) | |
syntax: move GLOBALS to attr module
Diffstat (limited to 'src/libsyntax/attr/mod.rs')
| -rw-r--r-- | src/libsyntax/attr/mod.rs | 37 |
1 files changed, 34 insertions, 3 deletions
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<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| { |
