Remove syntax and syntax_pos thread locals

This commit is contained in:
John Kåre Alsaker 2018-03-07 02:44:10 +01:00
parent fab632f975
commit cbdf4ec03e
29 changed files with 1212 additions and 998 deletions

View file

@ -14,11 +14,11 @@
// The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd.
// See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
use GLOBALS;
use {BytePos, SpanData};
use hygiene::SyntaxContext;
use rustc_data_structures::fx::FxHashMap;
use std::cell::RefCell;
use std::hash::{Hash, Hasher};
/// A compressed span.
@ -133,7 +133,7 @@ fn decode(span: Span) -> SpanData {
}
#[derive(Default)]
struct SpanInterner {
pub struct SpanInterner {
spans: FxHashMap<SpanData, u32>,
span_data: Vec<SpanData>,
}
@ -156,11 +156,8 @@ impl SpanInterner {
}
}
// If an interner exists in TLS, return it. Otherwise, prepare a fresh one.
// If an interner exists, return it. Otherwise, prepare a fresh one.
#[inline]
fn with_span_interner<T, F: FnOnce(&mut SpanInterner) -> T>(f: F) -> T {
thread_local!(static INTERNER: RefCell<SpanInterner> = {
RefCell::new(SpanInterner::default())
});
INTERNER.with(|interner| f(&mut *interner.borrow_mut()))
GLOBALS.with(|globals| f(&mut *globals.span_interner.lock()))
}