Skip to content

Commit

Permalink
De-@ IdentInterner.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 28, 2014
1 parent 83c4e25 commit f65638e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 48 deletions.
7 changes: 4 additions & 3 deletions src/librustc/metadata/creader.rs
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/metadata/csearch.rs
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -118,27 +118,27 @@ 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,
def: ast::DefId)
-> (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,
Expand All @@ -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> {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/metadata/cstore.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
Expand Down
48 changes: 24 additions & 24 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -770,20 +770,20 @@ 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
});

rslt
}

/// 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();
Expand All @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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
});
Expand Down Expand Up @@ -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> > {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/metadata/loader.rs
Expand Up @@ -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;

Expand All @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -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>,
Expand Down

0 comments on commit f65638e

Please sign in to comment.