Refactor get_ident_interner
-> with_ident_interner
.
This commit is contained in:
parent
70e2845230
commit
752d4419a0
4 changed files with 19 additions and 19 deletions
|
@ -211,7 +211,7 @@ pub fn compile_input(sess: &Session,
|
|||
}
|
||||
|
||||
// Discard interned strings as they are no longer required.
|
||||
token::get_ident_interner().clear();
|
||||
token::clear_ident_interner();
|
||||
|
||||
Ok((outputs, trans))
|
||||
})??
|
||||
|
@ -480,7 +480,7 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
|
|||
input: &Input)
|
||||
-> PResult<'a, ast::Crate> {
|
||||
// These may be left in an incoherent state after a previous compile.
|
||||
// `clear_tables` and `get_ident_interner().clear()` can be used to free
|
||||
// `clear_tables` and `clear_ident_interner` can be used to free
|
||||
// memory, but they do not restore the initial state.
|
||||
syntax::ext::mtwt::reset_tables();
|
||||
token::reset_ident_interner();
|
||||
|
|
|
@ -442,7 +442,7 @@ pub fn get_adt_def<'a, 'tcx>(cdata: Cmd,
|
|||
struct_field_family_to_visibility(ff))
|
||||
}).chain(reader::tagged_docs(doc, tag_item_unnamed_field).map(|f| {
|
||||
let ff = item_family(f);
|
||||
let name = token::get_ident_interner().intern(index.to_string());
|
||||
let name = token::with_ident_interner(|interner| interner.intern(index.to_string()));
|
||||
index += 1;
|
||||
ty::FieldDefData::new(item_def_id(f, cdata), name,
|
||||
struct_field_family_to_visibility(ff))
|
||||
|
@ -1147,7 +1147,7 @@ pub fn get_struct_field_names(cdata: Cmd, id: DefIndex) -> Vec<ast::Name> {
|
|||
reader::tagged_docs(item, tag_item_field).map(|an_item| {
|
||||
item_name(an_item)
|
||||
}).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|_| {
|
||||
let name = token::get_ident_interner().intern(index.to_string());
|
||||
let name = token::with_ident_interner(|interner| interner.intern(index.to_string()));
|
||||
index += 1;
|
||||
name
|
||||
})).collect()
|
||||
|
|
|
@ -31,7 +31,6 @@ use rustc::ty::subst;
|
|||
use std::hash::{Hash, Hasher};
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::{attr,errors};
|
||||
use syntax::parse::token;
|
||||
use type_of;
|
||||
use glue;
|
||||
use abi::{Abi, FnType};
|
||||
|
@ -562,8 +561,8 @@ fn push_type_params<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
|
||||
for projection in projections {
|
||||
let projection = projection.skip_binder();
|
||||
let name = token::get_ident_interner().get(projection.projection_ty.item_name);
|
||||
output.push_str(&name[..]);
|
||||
let name = &projection.projection_ty.item_name.as_str();
|
||||
output.push_str(name);
|
||||
output.push_str("=");
|
||||
push_unique_type_name(tcx, projection.ty, output);
|
||||
output.push_str(", ");
|
||||
|
|
|
@ -477,17 +477,20 @@ pub type IdentInterner = Interner;
|
|||
// if an interner exists in TLS, return it. Otherwise, prepare a
|
||||
// fresh one.
|
||||
// FIXME(eddyb) #8726 This should probably use a thread-local reference.
|
||||
pub fn get_ident_interner() -> Rc<IdentInterner> {
|
||||
thread_local!(static KEY: Rc<::parse::token::IdentInterner> = {
|
||||
Rc::new(mk_fresh_ident_interner())
|
||||
pub fn with_ident_interner<T, F: FnOnce(&IdentInterner) -> T>(f: F) -> T {
|
||||
thread_local!(static KEY: IdentInterner = {
|
||||
mk_fresh_ident_interner()
|
||||
});
|
||||
KEY.with(|k| k.clone())
|
||||
KEY.with(f)
|
||||
}
|
||||
|
||||
/// Reset the ident interner to its initial state.
|
||||
pub fn reset_ident_interner() {
|
||||
let interner = get_ident_interner();
|
||||
interner.reset(mk_fresh_ident_interner());
|
||||
with_ident_interner(|interner| interner.reset(mk_fresh_ident_interner()));
|
||||
}
|
||||
|
||||
pub fn clear_ident_interner() {
|
||||
with_ident_interner(|interner| interner.clear());
|
||||
}
|
||||
|
||||
/// Represents a string stored in the thread-local interner. Because the
|
||||
|
@ -521,8 +524,7 @@ impl InternedString {
|
|||
|
||||
#[inline]
|
||||
pub fn new_from_name(name: ast::Name) -> InternedString {
|
||||
let interner = get_ident_interner();
|
||||
InternedString::new_from_rc_str(interner.get(name))
|
||||
with_ident_interner(|interner| InternedString::new_from_rc_str(interner.get(name)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -610,13 +612,13 @@ pub fn intern_and_get_ident(s: &str) -> InternedString {
|
|||
/// Maps a string to its interned representation.
|
||||
#[inline]
|
||||
pub fn intern(s: &str) -> ast::Name {
|
||||
get_ident_interner().intern(s)
|
||||
with_ident_interner(|interner| interner.intern(s))
|
||||
}
|
||||
|
||||
/// gensym's a new usize, using the current interner.
|
||||
#[inline]
|
||||
pub fn gensym(s: &str) -> ast::Name {
|
||||
get_ident_interner().gensym(s)
|
||||
with_ident_interner(|interner| interner.gensym(s))
|
||||
}
|
||||
|
||||
/// Maps a string to an identifier with an empty syntax context.
|
||||
|
@ -635,8 +637,7 @@ pub fn gensym_ident(s: &str) -> ast::Ident {
|
|||
// note that this guarantees that str_ptr_eq(ident_to_string(src),interner_get(fresh_name(src)));
|
||||
// that is, that the new name and the old one are connected to ptr_eq strings.
|
||||
pub fn fresh_name(src: ast::Ident) -> ast::Name {
|
||||
let interner = get_ident_interner();
|
||||
interner.gensym_copy(src.name)
|
||||
with_ident_interner(|interner| interner.gensym_copy(src.name))
|
||||
// following: debug version. Could work in final except that it's incompatible with
|
||||
// good error messages and uses of struct names in ambiguous could-be-binding
|
||||
// locations. Also definitely destroys the guarantee given above about ptr_eq.
|
||||
|
|
Loading…
Add table
Reference in a new issue