De-@ IdentInterner.
This commit is contained in:
parent
83c4e25d93
commit
f65638e669
8 changed files with 53 additions and 48 deletions
|
@ -23,6 +23,7 @@ use metadata::loader;
|
|||
use metadata::loader::Os;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use collections::HashMap;
|
||||
use syntax::ast;
|
||||
use syntax::abi;
|
||||
|
@ -41,7 +42,7 @@ use syntax::visit;
|
|||
pub fn read_crates(sess: &Session,
|
||||
krate: &ast::Crate,
|
||||
os: loader::Os,
|
||||
intr: @IdentInterner) {
|
||||
intr: Rc<IdentInterner>) {
|
||||
let mut e = Env {
|
||||
sess: sess,
|
||||
os: os,
|
||||
|
@ -114,7 +115,7 @@ struct Env<'a> {
|
|||
os: loader::Os,
|
||||
crate_cache: @RefCell<Vec<cache_entry>>,
|
||||
next_crate_num: ast::CrateNum,
|
||||
intr: @IdentInterner
|
||||
intr: Rc<IdentInterner>
|
||||
}
|
||||
|
||||
fn visit_crate(e: &Env, c: &ast::Crate) {
|
||||
|
@ -295,7 +296,7 @@ fn resolve_crate(e: &mut Env,
|
|||
id_hash: id_hash,
|
||||
hash: hash.map(|a| &*a),
|
||||
os: e.os,
|
||||
intr: e.intr,
|
||||
intr: e.intr.clone(),
|
||||
rejected_via_hash: false,
|
||||
};
|
||||
let loader::Library {
|
||||
|
|
|
@ -63,7 +63,7 @@ pub fn each_child_of_item(cstore: &cstore::CStore,
|
|||
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
|
||||
cstore.get_crate_data(cnum)
|
||||
};
|
||||
decoder::each_child_of_item(cstore.intr,
|
||||
decoder::each_child_of_item(cstore.intr.clone(),
|
||||
crate_data,
|
||||
def_id.node,
|
||||
get_crate_data,
|
||||
|
@ -80,7 +80,7 @@ pub fn each_top_level_item_of_crate(cstore: &cstore::CStore,
|
|||
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
|
||||
cstore.get_crate_data(cnum)
|
||||
};
|
||||
decoder::each_top_level_item_of_crate(cstore.intr,
|
||||
decoder::each_top_level_item_of_crate(cstore.intr.clone(),
|
||||
crate_data,
|
||||
get_crate_data,
|
||||
callback)
|
||||
|
@ -118,19 +118,19 @@ pub fn get_enum_variants(tcx: &ty::ctxt, def: ast::DefId)
|
|||
-> Vec<@ty::VariantInfo> {
|
||||
let cstore = &tcx.sess.cstore;
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx)
|
||||
return decoder::get_enum_variants(cstore.intr.clone(), cdata, def.node, tcx)
|
||||
}
|
||||
|
||||
/// Returns information about the given implementation.
|
||||
pub fn get_impl(tcx: &ty::ctxt, impl_def_id: ast::DefId)
|
||||
-> ty::Impl {
|
||||
let cdata = tcx.sess.cstore.get_crate_data(impl_def_id.krate);
|
||||
decoder::get_impl(tcx.sess.cstore.intr, cdata, impl_def_id.node, tcx)
|
||||
decoder::get_impl(tcx.sess.cstore.intr.clone(), cdata, impl_def_id.node, tcx)
|
||||
}
|
||||
|
||||
pub fn get_method(tcx: &ty::ctxt, def: ast::DefId) -> ty::Method {
|
||||
let cdata = tcx.sess.cstore.get_crate_data(def.krate);
|
||||
decoder::get_method(tcx.sess.cstore.intr, cdata, def.node, tcx)
|
||||
decoder::get_method(tcx.sess.cstore.intr.clone(), cdata, def.node, tcx)
|
||||
}
|
||||
|
||||
pub fn get_method_name_and_explicit_self(cstore: &cstore::CStore,
|
||||
|
@ -138,7 +138,7 @@ pub fn get_method_name_and_explicit_self(cstore: &cstore::CStore,
|
|||
-> (ast::Ident, ast::ExplicitSelf_)
|
||||
{
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
|
||||
decoder::get_method_name_and_explicit_self(cstore.intr.clone(), cdata, def.node)
|
||||
}
|
||||
|
||||
pub fn get_trait_method_def_ids(cstore: &cstore::CStore,
|
||||
|
@ -158,7 +158,7 @@ pub fn get_provided_trait_methods(tcx: &ty::ctxt,
|
|||
-> Vec<@ty::Method> {
|
||||
let cstore = &tcx.sess.cstore;
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
|
||||
decoder::get_provided_trait_methods(cstore.intr.clone(), cdata, def.node, tcx)
|
||||
}
|
||||
|
||||
pub fn get_supertraits(tcx: &ty::ctxt, def: ast::DefId) -> Vec<@ty::TraitRef> {
|
||||
|
@ -177,7 +177,7 @@ pub fn get_static_methods_if_impl(cstore: &cstore::CStore,
|
|||
def: ast::DefId)
|
||||
-> Option<Vec<StaticMethodInfo> > {
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node)
|
||||
decoder::get_static_methods_if_impl(cstore.intr.clone(), cdata, def.node)
|
||||
}
|
||||
|
||||
pub fn get_item_attrs(cstore: &cstore::CStore,
|
||||
|
@ -191,7 +191,7 @@ pub fn get_struct_fields(cstore: &cstore::CStore,
|
|||
def: ast::DefId)
|
||||
-> Vec<ty::field_ty> {
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_struct_fields(cstore.intr, cdata, def.node)
|
||||
decoder::get_struct_fields(cstore.intr.clone(), cdata, def.node)
|
||||
}
|
||||
|
||||
pub fn get_type(tcx: &ty::ctxt,
|
||||
|
@ -251,7 +251,7 @@ pub fn get_impl_method(cstore: &cstore::CStore,
|
|||
mname: ast::Ident)
|
||||
-> Option<ast::DefId> {
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
|
||||
decoder::get_impl_method(cstore.intr.clone(), cdata, def.node, mname)
|
||||
}
|
||||
|
||||
pub fn get_item_visibility(cstore: &cstore::CStore,
|
||||
|
|
|
@ -19,6 +19,7 @@ use metadata::loader;
|
|||
|
||||
use std::cell::RefCell;
|
||||
use std::c_vec::CVec;
|
||||
use std::rc::Rc;
|
||||
use collections::HashMap;
|
||||
use syntax::ast;
|
||||
use syntax::parse::token::IdentInterner;
|
||||
|
@ -70,14 +71,14 @@ pub struct CStore {
|
|||
priv used_crate_sources: RefCell<Vec<CrateSource> >,
|
||||
priv used_libraries: RefCell<Vec<(~str, NativeLibaryKind)> >,
|
||||
priv used_link_args: RefCell<Vec<~str> >,
|
||||
intr: @IdentInterner
|
||||
intr: Rc<IdentInterner>
|
||||
}
|
||||
|
||||
// Map from NodeId's of local extern crate statements to crate numbers
|
||||
type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>;
|
||||
|
||||
impl CStore {
|
||||
pub fn new(intr: @IdentInterner) -> CStore {
|
||||
pub fn new(intr: Rc<IdentInterner>) -> CStore {
|
||||
CStore {
|
||||
metas: RefCell::new(HashMap::new()),
|
||||
extern_mod_crate_map: RefCell::new(HashMap::new()),
|
||||
|
|
|
@ -278,7 +278,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
|
|||
reader::tagged_docs(item_doc, tag_region_param_def, |rp_doc| {
|
||||
let ident_str_doc = reader::get_doc(rp_doc,
|
||||
tag_region_param_def_ident);
|
||||
let ident = item_name(token::get_ident_interner(), ident_str_doc);
|
||||
let ident = item_name(&*token::get_ident_interner(), ident_str_doc);
|
||||
let def_id_doc = reader::get_doc(rp_doc,
|
||||
tag_region_param_def_def_id);
|
||||
let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
|
||||
|
@ -460,13 +460,13 @@ pub fn get_impl_vtables(cdata: Cmd,
|
|||
}
|
||||
|
||||
|
||||
pub fn get_impl_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
|
||||
pub fn get_impl_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||
name: ast::Ident) -> Option<ast::DefId> {
|
||||
let items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
|
||||
let mut found = None;
|
||||
reader::tagged_docs(find_item(id, items), tag_item_impl_method, |mid| {
|
||||
let m_did = reader::with_doc_data(mid, parse_def_id);
|
||||
if item_name(intr, find_item(m_did.node, items)) == name {
|
||||
if item_name(&*intr, find_item(m_did.node, items)) == name {
|
||||
found = Some(translate_def_id(cdata, m_did));
|
||||
}
|
||||
true
|
||||
|
@ -509,7 +509,7 @@ pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
fn each_child_of_item_or_crate(intr: @IdentInterner,
|
||||
fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
item_doc: ebml::Doc,
|
||||
get_crate_data: GetCrateDataCb,
|
||||
|
@ -536,7 +536,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
|
|||
None => {}
|
||||
Some(child_item_doc) => {
|
||||
// Hand off the item to the callback.
|
||||
let child_name = item_name(intr, child_item_doc);
|
||||
let child_name = item_name(&*intr, child_item_doc);
|
||||
let def_like = item_to_def_like(child_item_doc,
|
||||
child_def_id,
|
||||
cdata.cnum);
|
||||
|
@ -577,7 +577,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
|
|||
// Hand off the static method
|
||||
// to the callback.
|
||||
let static_method_name =
|
||||
item_name(intr, impl_method_doc);
|
||||
item_name(&*intr, impl_method_doc);
|
||||
let static_method_def_like =
|
||||
item_to_def_like(impl_method_doc,
|
||||
impl_method_def_id,
|
||||
|
@ -638,7 +638,7 @@ fn each_child_of_item_or_crate(intr: @IdentInterner,
|
|||
}
|
||||
|
||||
/// Iterates over each child of the given item.
|
||||
pub fn each_child_of_item(intr: @IdentInterner,
|
||||
pub fn each_child_of_item(intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
id: ast::NodeId,
|
||||
get_crate_data: GetCrateDataCb,
|
||||
|
@ -659,7 +659,7 @@ pub fn each_child_of_item(intr: @IdentInterner,
|
|||
}
|
||||
|
||||
/// Iterates over all the top-level crate items.
|
||||
pub fn each_top_level_item_of_crate(intr: @IdentInterner,
|
||||
pub fn each_top_level_item_of_crate(intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
get_crate_data: GetCrateDataCb,
|
||||
callback: |DefLike,
|
||||
|
@ -711,7 +711,7 @@ pub fn maybe_get_item_ast(cdata: Cmd, tcx: &ty::ctxt, id: ast::NodeId,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
|
||||
pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||
tcx: &ty::ctxt) -> Vec<@ty::VariantInfo> {
|
||||
let data = cdata.data();
|
||||
let items = reader::get_doc(reader::Doc(data), tag_items);
|
||||
|
@ -723,7 +723,7 @@ pub fn get_enum_variants(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
|
|||
let item = find_item(did.node, items);
|
||||
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
|
||||
item, tcx, cdata);
|
||||
let name = item_name(intr, item);
|
||||
let name = item_name(&*intr, item);
|
||||
let arg_tys = match ty::get(ctor_ty).sty {
|
||||
ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
|
||||
_ => Vec::new(), // Nullary enum variant.
|
||||
|
@ -770,12 +770,12 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
|
|||
}
|
||||
}
|
||||
|
||||
fn item_impl_methods(intr: @IdentInterner, cdata: Cmd, item: ebml::Doc,
|
||||
fn item_impl_methods(intr: Rc<IdentInterner>, cdata: Cmd, item: ebml::Doc,
|
||||
tcx: &ty::ctxt) -> Vec<@ty::Method> {
|
||||
let mut rslt = Vec::new();
|
||||
reader::tagged_docs(item, tag_item_impl_method, |doc| {
|
||||
let m_did = reader::with_doc_data(doc, parse_def_id);
|
||||
rslt.push(@get_method(intr, cdata, m_did.node, tcx));
|
||||
rslt.push(@get_method(intr.clone(), cdata, m_did.node, tcx));
|
||||
true
|
||||
});
|
||||
|
||||
|
@ -783,7 +783,7 @@ fn item_impl_methods(intr: @IdentInterner, cdata: Cmd, item: ebml::Doc,
|
|||
}
|
||||
|
||||
/// Returns information about the given implementation.
|
||||
pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
|
||||
pub fn get_impl(intr: Rc<IdentInterner>, cdata: Cmd, impl_id: ast::NodeId,
|
||||
tcx: &ty::ctxt)
|
||||
-> ty::Impl {
|
||||
let data = cdata.data();
|
||||
|
@ -793,23 +793,23 @@ pub fn get_impl(intr: @IdentInterner, cdata: Cmd, impl_id: ast::NodeId,
|
|||
krate: cdata.cnum,
|
||||
node: impl_id,
|
||||
},
|
||||
ident: item_name(intr, impl_item),
|
||||
ident: item_name(&*intr, impl_item),
|
||||
methods: item_impl_methods(intr, cdata, impl_item, tcx),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_method_name_and_explicit_self(
|
||||
intr: @IdentInterner,
|
||||
intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
id: ast::NodeId) -> (ast::Ident, ast::ExplicitSelf_)
|
||||
{
|
||||
let method_doc = lookup_item(id, cdata.data());
|
||||
let name = item_name(intr, method_doc);
|
||||
let name = item_name(&*intr, method_doc);
|
||||
let explicit_self = get_explicit_self(method_doc);
|
||||
(name, explicit_self)
|
||||
}
|
||||
|
||||
pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
|
||||
pub fn get_method(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
|
||||
tcx: &ty::ctxt) -> ty::Method
|
||||
{
|
||||
let method_doc = lookup_item(id, cdata.data());
|
||||
|
@ -823,7 +823,7 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
|
|||
_ => ImplContainer(container_id),
|
||||
};
|
||||
|
||||
let name = item_name(intr, method_doc);
|
||||
let name = item_name(&*intr, method_doc);
|
||||
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
|
||||
tag_item_method_tps);
|
||||
let rp_defs = item_region_param_defs(method_doc, cdata);
|
||||
|
@ -867,7 +867,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
|
|||
unwrap_(Decodable::decode(&mut decoder))
|
||||
}
|
||||
|
||||
pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
|
||||
pub fn get_provided_trait_methods(intr: Rc<IdentInterner>, cdata: Cmd,
|
||||
id: ast::NodeId, tcx: &ty::ctxt) ->
|
||||
Vec<@ty::Method> {
|
||||
let data = cdata.data();
|
||||
|
@ -879,7 +879,7 @@ pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
|
|||
let mth = lookup_item(did.node, data);
|
||||
|
||||
if item_method_sort(mth) == 'p' {
|
||||
result.push(@get_method(intr, cdata, did.node, tcx));
|
||||
result.push(@get_method(intr.clone(), cdata, did.node, tcx));
|
||||
}
|
||||
true
|
||||
});
|
||||
|
@ -921,7 +921,7 @@ pub fn get_type_name_if_impl(cdata: Cmd,
|
|||
ret
|
||||
}
|
||||
|
||||
pub fn get_static_methods_if_impl(intr: @IdentInterner,
|
||||
pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
|
||||
cdata: Cmd,
|
||||
node_id: ast::NodeId)
|
||||
-> Option<Vec<StaticMethodInfo> > {
|
||||
|
@ -957,7 +957,7 @@ pub fn get_static_methods_if_impl(intr: @IdentInterner,
|
|||
}
|
||||
|
||||
static_impl_methods.push(StaticMethodInfo {
|
||||
ident: item_name(intr, impl_method_doc),
|
||||
ident: item_name(&*intr, impl_method_doc),
|
||||
def_id: item_def_id(impl_method_doc, cdata),
|
||||
purity: purity,
|
||||
vis: item_visibility(impl_method_doc),
|
||||
|
@ -1009,7 +1009,7 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
|
||||
pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
|
||||
-> Vec<ty::field_ty> {
|
||||
let data = cdata.data();
|
||||
let item = lookup_item(id, data);
|
||||
|
@ -1018,7 +1018,7 @@ pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
|
|||
let f = item_family(an_item);
|
||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||
// FIXME #6993: name should be of type Name, not Ident
|
||||
let name = item_name(intr, an_item);
|
||||
let name = item_name(&*intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
result.push(ty::field_ty {
|
||||
name: name.name,
|
||||
|
|
|
@ -29,6 +29,7 @@ use std::cast;
|
|||
use std::cmp;
|
||||
use std::io;
|
||||
use std::os::consts::{macos, freebsd, linux, android, win32};
|
||||
use std::rc::Rc;
|
||||
use std::str;
|
||||
use std::slice;
|
||||
|
||||
|
@ -52,7 +53,7 @@ pub struct Context<'a> {
|
|||
id_hash: &'a str,
|
||||
hash: Option<&'a Svh>,
|
||||
os: Os,
|
||||
intr: @IdentInterner,
|
||||
intr: Rc<IdentInterner>,
|
||||
rejected_via_hash: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ pub struct Parser<'a> {
|
|||
restriction: restriction,
|
||||
quote_depth: uint, // not (yet) related to the quasiquoter
|
||||
reader: ~Reader:,
|
||||
interner: @token::IdentInterner,
|
||||
interner: Rc<token::IdentInterner>,
|
||||
/// The set of seen errors about obsolete syntax. Used to suppress
|
||||
/// extra detail when the same error is seen twice
|
||||
obsolete_set: HashSet<ObsoleteSyntax>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use std::char;
|
|||
use std::fmt;
|
||||
use std::local_data;
|
||||
use std::path::BytesContainer;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[deriving(Clone, Encodable, Decodable, Eq, TotalEq, Hash, Show)]
|
||||
|
@ -531,13 +532,14 @@ pub type IdentInterner = StrInterner;
|
|||
|
||||
// if an interner exists in TLS, return it. Otherwise, prepare a
|
||||
// fresh one.
|
||||
pub fn get_ident_interner() -> @IdentInterner {
|
||||
local_data_key!(key: @::parse::token::IdentInterner)
|
||||
match local_data::get(key, |k| k.map(|k| *k)) {
|
||||
// FIXME(eddyb) #8726 This should probably use a task-local reference.
|
||||
pub fn get_ident_interner() -> Rc<IdentInterner> {
|
||||
local_data_key!(key: Rc<::parse::token::IdentInterner>)
|
||||
match local_data::get(key, |k| k.map(|k| k.clone())) {
|
||||
Some(interner) => interner,
|
||||
None => {
|
||||
let interner = @mk_fresh_ident_interner();
|
||||
local_data::set(key, interner);
|
||||
let interner = Rc::new(mk_fresh_ident_interner());
|
||||
local_data::set(key, interner.clone());
|
||||
interner
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ use std::char;
|
|||
use std::str;
|
||||
use std::io;
|
||||
use std::io::{IoResult, MemWriter};
|
||||
use std::rc::Rc;
|
||||
|
||||
// The &mut State is stored here to prevent recursive type.
|
||||
pub enum AnnNode<'a> {
|
||||
NodeBlock(&'a ast::Block),
|
||||
NodeItem(&'a ast::Item),
|
||||
|
@ -57,7 +57,7 @@ pub struct CurrentCommentAndLiteral {
|
|||
pub struct State<'a> {
|
||||
s: pp::Printer,
|
||||
cm: Option<&'a CodeMap>,
|
||||
intr: @token::IdentInterner,
|
||||
intr: Rc<token::IdentInterner>,
|
||||
comments: Option<Vec<comments::Comment> >,
|
||||
literals: Option<Vec<comments::Literal> >,
|
||||
cur_cmnt_and_lit: CurrentCommentAndLiteral,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue