Skip to content

Commit

Permalink
Make syntax_pos interners globals
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Dec 8, 2017
1 parent 6e573cb commit 3bb008d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/libsyntax_pos/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {BytePos, SpanData};
use hygiene::SyntaxContext;

use rustc_data_structures::fx::FxHashMap;
use std::cell::RefCell;
use rustc_data_structures::sync::Lock;

/// A compressed span.
/// Contains either fields of `SpanData` inline if they are small, or index into span interner.
Expand Down Expand Up @@ -135,11 +135,11 @@ 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())
rustc_global!(static INTERNER: Lock<SpanInterner> = {
Lock::new(SpanInterner::default())
});
INTERNER.with(|interner| f(&mut *interner.borrow_mut()))
rustc_access_global!(INTERNER, |interner| f(&mut *interner.lock()))
}
12 changes: 7 additions & 5 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use hygiene::SyntaxContext;

use rustc_data_structures::sync::Lock;
use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;

Expand Down Expand Up @@ -326,12 +326,14 @@ declare_keywords! {
(60, Union, "union")
}

// 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_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
thread_local!(static INTERNER: RefCell<Interner> = {
RefCell::new(Interner::fresh())
rustc_global!(static INTERNER: Lock<Interner> = {
Lock::new(Interner::fresh())
});
INTERNER.with(|interner| f(&mut *interner.borrow_mut()))
rustc_access_global!(INTERNER, |interner| f(&mut *interner.lock()))
}

/// Represents a string stored in the thread-local interner. Because the
Expand Down

0 comments on commit 3bb008d

Please sign in to comment.