diff options
| author | bors <bors@rust-lang.org> | 2018-03-14 12:44:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-14 12:44:17 +0000 |
| commit | d089fe974edc53fa34384e8e76eeb1eca0d89042 (patch) | |
| tree | 7c3e9927e9b2932fa4d888d5f85c0ecfa0581559 /src/libsyntax/lib.rs | |
| parent | 24e679c375da94b0f7db732c45c4c53724e8854d (diff) | |
| parent | cbdf4ec03e92ed36c162bb8c645993e48a1caa02 (diff) | |
| download | rust-d089fe974edc53fa34384e8e76eeb1eca0d89042.tar.gz rust-d089fe974edc53fa34384e8e76eeb1eca0d89042.zip | |
Auto merge of #48811 - Zoxc:syntax-globals, r=michaelwoerister
Remove syntax and syntax_pos thread locals This moves `syntax` and `syntax_pos` globals into a struct which are pointed to by thread locals. Most of the changes here are indentation changes in test. It would probably be a good idea to ignore whitespace changes while reviewing. Some indentation is unchanged to avoid merge conflicts. r? @michaelwoerister
Diffstat (limited to 'src/libsyntax/lib.rs')
| -rw-r--r-- | src/libsyntax/lib.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 50e94e5cba7..5f58b3bc3a0 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -39,9 +39,12 @@ extern crate std_unicode; pub extern crate rustc_errors as errors; extern crate syntax_pos; extern crate rustc_data_structures; +#[macro_use] extern crate scoped_tls; extern crate serialize as rustc_serialize; // used by deriving +use rustc_data_structures::sync::Lock; + // A variant of 'try!' that panics on an Err. This is used as a crutch on the // way towards a non-panic!-prone parser. It should be used for fatal parsing // errors; eventually we plan to convert all code using panictry to just use @@ -72,6 +75,33 @@ macro_rules! unwrap_or { } } +struct Globals { + used_attrs: Lock<Vec<u64>>, + known_attrs: Lock<Vec<u64>>, + syntax_pos_globals: syntax_pos::Globals, +} + +impl Globals { + fn new() -> Globals { + Globals { + used_attrs: Lock::new(Vec::new()), + known_attrs: Lock::new(Vec::new()), + syntax_pos_globals: syntax_pos::Globals::new(), + } + } +} + +pub fn with_globals<F, R>(f: F) -> R + where F: FnOnce() -> R +{ + let globals = Globals::new(); + GLOBALS.set(&globals, || { + syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f) + }) +} + +scoped_thread_local!(static GLOBALS: Globals); + #[macro_use] pub mod diagnostics { #[macro_use] |
