Skip to content

Commit 35fbe11

Browse files
committed
Make USED_ATTRS and KNOWN_ATTRS into globals
1 parent 1155689 commit 35fbe11

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/libsyntax/attr.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use ptr::P;
3030
use symbol::Symbol;
3131
use tokenstream::{TokenStream, TokenTree, Delimited};
3232
use util::ThinVec;
33+
use rustc_data_structures::sync::Lock;
3334

34-
use std::cell::{RefCell, Cell};
3535
use std::iter;
3636

37-
thread_local! {
38-
static USED_ATTRS: RefCell<Vec<u64>> = RefCell::new(Vec::new());
39-
static KNOWN_ATTRS: RefCell<Vec<u64>> = RefCell::new(Vec::new());
37+
rustc_global! {
38+
static USED_ATTRS: Lock<Vec<u64>> = Lock::new(Vec::new());
39+
static KNOWN_ATTRS: Lock<Vec<u64>> = Lock::new(Vec::new());
4040
}
4141

4242
enum AttrError {
@@ -65,45 +65,49 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
6565
pub fn mark_used(attr: &Attribute) {
6666
debug!("Marking {:?} as used.", attr);
6767
let AttrId(id) = attr.id;
68-
USED_ATTRS.with(|slot| {
68+
rustc_access_global!(USED_ATTRS, |slot| {
69+
let mut slot = slot.lock();
6970
let idx = (id / 64) as usize;
7071
let shift = id % 64;
71-
if slot.borrow().len() <= idx {
72-
slot.borrow_mut().resize(idx + 1, 0);
72+
if slot.len() <= idx {
73+
slot.resize(idx + 1, 0);
7374
}
74-
slot.borrow_mut()[idx] |= 1 << shift;
75+
slot[idx] |= 1 << shift;
7576
});
7677
}
7778

7879
pub fn is_used(attr: &Attribute) -> bool {
7980
let AttrId(id) = attr.id;
80-
USED_ATTRS.with(|slot| {
81+
rustc_access_global!(USED_ATTRS, |slot| {
82+
let slot = slot.lock();
8183
let idx = (id / 64) as usize;
8284
let shift = id % 64;
83-
slot.borrow().get(idx).map(|bits| bits & (1 << shift) != 0)
85+
slot.get(idx).map(|bits| bits & (1 << shift) != 0)
8486
.unwrap_or(false)
8587
})
8688
}
8789

8890
pub fn mark_known(attr: &Attribute) {
8991
debug!("Marking {:?} as known.", attr);
9092
let AttrId(id) = attr.id;
91-
KNOWN_ATTRS.with(|slot| {
93+
rustc_access_global!(KNOWN_ATTRS, |slot| {
94+
let mut slot = slot.lock();
9295
let idx = (id / 64) as usize;
9396
let shift = id % 64;
94-
if slot.borrow().len() <= idx {
95-
slot.borrow_mut().resize(idx + 1, 0);
97+
if slot.len() <= idx {
98+
slot.resize(idx + 1, 0);
9699
}
97-
slot.borrow_mut()[idx] |= 1 << shift;
100+
slot[idx] |= 1 << shift;
98101
});
99102
}
100103

101104
pub fn is_known(attr: &Attribute) -> bool {
102105
let AttrId(id) = attr.id;
103-
KNOWN_ATTRS.with(|slot| {
106+
rustc_access_global!(KNOWN_ATTRS, |slot| {
107+
let slot = slot.lock();
104108
let idx = (id / 64) as usize;
105109
let shift = id % 64;
106-
slot.borrow().get(idx).map(|bits| bits & (1 << shift) != 0)
110+
slot.get(idx).map(|bits| bits & (1 << shift) != 0)
107111
.unwrap_or(false)
108112
})
109113
}

0 commit comments

Comments
 (0)