diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2014-02-14 07:07:09 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2014-02-14 08:43:29 +0200 |
| commit | a02b10a0621adfe36eb3cc2e46f45fc7ccdb7ea2 (patch) | |
| tree | 86fe8ac57360a232b07c4303547194646129561a /src/librustc/metadata | |
| parent | 22c34f3c4cddea33b916eb92f8d7286b02b865a7 (diff) | |
Refactored ast_map and friends, mainly to have Paths without storing them.
Diffstat (limited to 'src/librustc/metadata')
| -rw-r--r-- | src/librustc/metadata/common.rs | 226 | ||||
| -rw-r--r-- | src/librustc/metadata/creader.rs | 28 | ||||
| -rw-r--r-- | src/librustc/metadata/csearch.rs | 11 | ||||
| -rw-r--r-- | src/librustc/metadata/decoder.rs | 111 | ||||
| -rw-r--r-- | src/librustc/metadata/encoder.rs | 375 | ||||
| -rw-r--r-- | src/librustc/metadata/loader.rs | 13 | ||||
| -rw-r--r-- | src/librustc/metadata/tydecode.rs | 10 | ||||
| -rw-r--r-- | src/librustc/metadata/tyencode.rs | 7 |
8 files changed, 335 insertions, 446 deletions
diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 85a6677d188..48ec199ed00 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -13,88 +13,88 @@ use syntax::crateid::CrateId; // EBML enum definitions and utils shared by the encoder and decoder -pub static tag_items: uint = 0x02u; +pub static tag_items: uint = 0x00; -pub static tag_paths_data_name: uint = 0x04u; +pub static tag_paths_data_name: uint = 0x01; -pub static tag_def_id: uint = 0x07u; +pub static tag_def_id: uint = 0x02; -pub static tag_items_data: uint = 0x08u; +pub static tag_items_data: uint = 0x03; -pub static tag_items_data_item: uint = 0x09u; +pub static tag_items_data_item: uint = 0x04; -pub static tag_items_data_item_family: uint = 0x0au; +pub static tag_items_data_item_family: uint = 0x05; -pub static tag_items_data_item_ty_param_bounds: uint = 0x0bu; +pub static tag_items_data_item_ty_param_bounds: uint = 0x06; -pub static tag_items_data_item_type: uint = 0x0cu; +pub static tag_items_data_item_type: uint = 0x07; -pub static tag_items_data_item_symbol: uint = 0x0du; +pub static tag_items_data_item_symbol: uint = 0x08; -pub static tag_items_data_item_variant: uint = 0x0eu; +pub static tag_items_data_item_variant: uint = 0x09; -pub static tag_items_data_parent_item: uint = 0x0fu; +pub static tag_items_data_parent_item: uint = 0x0a; -pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x10u; +pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x0b; -pub static tag_index: uint = 0x11u; +pub static tag_index: uint = 0x0c; -pub static tag_index_buckets: uint = 0x12u; +pub static tag_index_buckets: uint = 0x0d; -pub static tag_index_buckets_bucket: uint = 0x13u; +pub static tag_index_buckets_bucket: uint = 0x0e; -pub static tag_index_buckets_bucket_elt: uint = 0x14u; +pub static tag_index_buckets_bucket_elt: uint = 0x0f; -pub static tag_index_table: uint = 0x15u; +pub static tag_index_table: uint = 0x10; -pub static tag_meta_item_name_value: uint = 0x18u; +pub static tag_meta_item_name_value: uint = 0x11; -pub static tag_meta_item_name: uint = 0x19u; +pub static tag_meta_item_name: uint = 0x12; -pub static tag_meta_item_value: uint = 0x20u; +pub static tag_meta_item_value: uint = 0x13; -pub static tag_attributes: uint = 0x21u; +pub static tag_attributes: uint = 0x14; -pub static tag_attribute: uint = 0x22u; +pub static tag_attribute: uint = 0x15; -pub static tag_meta_item_word: uint = 0x23u; +pub static tag_meta_item_word: uint = 0x16; -pub static tag_meta_item_list: uint = 0x24u; +pub static tag_meta_item_list: uint = 0x17; // The list of crates that this crate depends on -pub static tag_crate_deps: uint = 0x25u; +pub static tag_crate_deps: uint = 0x18; // A single crate dependency -pub static tag_crate_dep: uint = 0x26u; +pub static tag_crate_dep: uint = 0x19; -pub static tag_crate_hash: uint = 0x28u; +pub static tag_crate_hash: uint = 0x1a; -pub static tag_parent_item: uint = 0x29u; +pub static tag_parent_item: uint = 0x1b; -pub static tag_crate_dep_name: uint = 0x2au; -pub static tag_crate_dep_hash: uint = 0x2bu; -pub static tag_crate_dep_vers: uint = 0x2cu; +pub static tag_crate_dep_name: uint = 0x1c; +pub static tag_crate_dep_hash: uint = 0x1d; +pub static tag_crate_dep_vers: uint = 0x1e; -pub static tag_mod_impl: uint = 0x30u; +pub static tag_mod_impl: uint = 0x1f; -pub static tag_item_trait_method: uint = 0x31u; +pub static tag_item_trait_method: uint = 0x20; -pub static tag_item_trait_ref: uint = 0x32u; -pub static tag_item_super_trait_ref: uint = 0x33u; +pub static tag_item_trait_ref: uint = 0x21; +pub static tag_item_super_trait_ref: uint = 0x22; // discriminator value for variants -pub static tag_disr_val: uint = 0x34u; - -// used to encode ast_map::Path and ast_map::PathElem -pub static tag_path: uint = 0x40u; -pub static tag_path_len: uint = 0x41u; -pub static tag_path_elem_mod: uint = 0x42u; -pub static tag_path_elem_name: uint = 0x43u; -pub static tag_item_field: uint = 0x44u; -pub static tag_struct_mut: uint = 0x45u; - -pub static tag_item_variances: uint = 0x46; -pub static tag_mod_impl_trait: uint = 0x47u; +pub static tag_disr_val: uint = 0x23; + +// used to encode ast_map::PathElem +pub static tag_path: uint = 0x24; +pub static tag_path_len: uint = 0x25; +pub static tag_path_elem_mod: uint = 0x26; +pub static tag_path_elem_name: uint = 0x27; +pub static tag_item_field: uint = 0x28; +pub static tag_struct_mut: uint = 0x29; + +pub static tag_item_variances: uint = 0x2a; +pub static tag_mod_impl_trait: uint = 0x2b; /* trait items contain tag_item_trait_method elements, impl items contain tag_item_impl_method elements, and classes @@ -103,47 +103,47 @@ pub static tag_mod_impl_trait: uint = 0x47u; both, tag_item_trait_method and tag_item_impl_method have to be two different tags. */ -pub static tag_item_impl_method: uint = 0x48u; -pub static tag_item_trait_method_explicit_self: uint = 0x4b; -pub static tag_item_trait_method_self_ty_region: uint = 0x4c; +pub static tag_item_impl_method: uint = 0x2c; +pub static tag_item_trait_method_explicit_self: uint = 0x2d; +pub static tag_item_trait_method_self_ty_region: uint = 0x2e; // Reexports are found within module tags. Each reexport contains def_ids // and names. -pub static tag_items_data_item_reexport: uint = 0x4d; -pub static tag_items_data_item_reexport_def_id: uint = 0x4e; -pub static tag_items_data_item_reexport_name: uint = 0x4f; +pub static tag_items_data_item_reexport: uint = 0x2f; +pub static tag_items_data_item_reexport_def_id: uint = 0x30; +pub static tag_items_data_item_reexport_name: uint = 0x31; // used to encode crate_ctxt side tables #[deriving(Eq)] #[repr(uint)] -pub enum astencode_tag { // Reserves 0x50 -- 0x6f - tag_ast = 0x50, - - tag_tree = 0x51, - - tag_id_range = 0x52, - - tag_table = 0x53, - tag_table_id = 0x54, - tag_table_val = 0x55, - tag_table_def = 0x56, - tag_table_node_type = 0x57, - tag_table_node_type_subst = 0x58, - tag_table_freevars = 0x59, - tag_table_tcache = 0x5a, - tag_table_param_defs = 0x5b, - tag_table_mutbl = 0x5d, - tag_table_last_use = 0x5e, - tag_table_spill = 0x5f, - tag_table_method_map = 0x60, - tag_table_vtable_map = 0x61, - tag_table_adjustments = 0x62, - tag_table_moves_map = 0x63, - tag_table_capture_map = 0x64 +pub enum astencode_tag { // Reserves 0x32 -- 0x45 + tag_ast = 0x32, + + tag_tree = 0x33, + + tag_id_range = 0x34, + + tag_table = 0x35, + tag_table_id = 0x36, + tag_table_val = 0x37, + tag_table_def = 0x38, + tag_table_node_type = 0x39, + tag_table_node_type_subst = 0x3a, + tag_table_freevars = 0x3b, + tag_table_tcache = 0x3c, + tag_table_param_defs = 0x3d, + tag_table_mutbl = 0x3e, + tag_table_last_use = 0x3f, + tag_table_spill = 0x40, + tag_table_method_map = 0x41, + tag_table_vtable_map = 0x42, + tag_table_adjustments = 0x43, + tag_table_moves_map = 0x44, + tag_table_capture_map = 0x45 } -static first_astencode_tag : uint = tag_ast as uint; -static last_astencode_tag : uint = tag_table_capture_map as uint; +static first_astencode_tag: uint = tag_ast as uint; +static last_astencode_tag: uint = tag_table_capture_map as uint; impl astencode_tag { pub fn from_uint(value : uint) -> Option<astencode_tag> { let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag; @@ -153,9 +153,9 @@ impl astencode_tag { } } -pub static tag_item_trait_method_sort: uint = 0x70; +pub static tag_item_trait_method_sort: uint = 0x46; -pub static tag_item_impl_type_basename: uint = 0x71; +pub static tag_item_impl_type_basename: uint = 0x47; // Language items are a top-level directory (for speed). Hierarchy: // @@ -164,50 +164,46 @@ pub static tag_item_impl_type_basename: uint = 0x71; // - tag_lang_items_item_id: u32 // - tag_lang_items_item_node_id: u32 -pub static tag_lang_items: uint = 0x72; -pub static tag_lang_items_item: uint = 0x73; -pub static tag_lang_items_item_id: uint = 0x74; -pub static tag_lang_items_item_node_id: uint = 0x75; +pub static tag_lang_items: uint = 0x48; +pub static tag_lang_items_item: uint = 0x49; +pub static tag_lang_items_item_id: uint = 0x4a; +pub static tag_lang_items_item_node_id: uint = 0x4b; -pub static tag_item_unnamed_field: uint = 0x76; -pub static tag_items_data_item_struct_ctor: uint = 0x77; -pub static tag_items_data_item_visibility: uint = 0x78; +pub static tag_item_unnamed_field: uint = 0x4c; +pub static tag_items_data_item_struct_ctor: uint = 0x4d; +pub static tag_items_data_item_visibility: uint = 0x4e; -pub static tag_link_args: uint = 0x79; -pub static tag_link_args_arg: uint = 0x7a; +pub static tag_link_args: uint = 0x4f; +pub static tag_link_args_arg: uint = 0x50; -pub static tag_item_method_tps: uint = 0x7b; -pub static tag_item_method_fty: uint = 0x7c; +pub static tag_item_method_tps: uint = 0x51; +pub static tag_item_method_fty: uint = 0x52; -pub static tag_mod_child: uint = 0x7d; -pub static tag_misc_info: uint = 0x7e; -pub static tag_misc_info_crate_items: uint = 0x7f; +pub static tag_mod_child: uint = 0x53; +pub static tag_misc_info: uint = 0x54; +pub static tag_misc_info_crate_items: uint = 0x55; -pub static tag_item_method_provided_source: uint = 0x80; -pub static tag_item_impl_vtables: uint = 0x81; +pub static tag_item_method_provided_source: uint = 0x56; +pub static tag_item_impl_vtables: uint = 0x57; -pub static tag_impls: uint = 0x82; -pub static tag_impls_impl: uint = 0x83; +pub static tag_impls: uint = 0x58; +pub static tag_impls_impl: uint = 0x59; -pub static tag_items_data_item_inherent_impl: uint = 0x84; -pub static tag_items_data_item_extension_impl: uint = 0x85; +pub static tag_items_data_item_inherent_impl: uint = 0x5a; +pub static tag_items_data_item_extension_impl: uint = 0x5b; -pub static tag_path_elem_pretty_name: uint = 0x86; -pub static tag_path_elem_pretty_name_ident: uint = 0x87; -pub static tag_path_elem_pretty_name_extra: uint = 0x88; +pub static tag_region_param_def: uint = 0x5c; +pub static tag_region_param_def_ident: uint = 0x5d; +pub static tag_region_param_def_def_id: uint = 0x5e; -pub static tag_region_param_def: uint = 0x100; -pub static tag_region_param_def_ident: uint = 0x101; -pub static tag_region_param_def_def_id: uint = 0x102; +pub static tag_native_libraries: uint = 0x5f; +pub static tag_native_libraries_lib: uint = 0x60; +pub static tag_native_libraries_name: uint = 0x61; +pub static tag_native_libraries_kind: uint = 0x62; -pub static tag_native_libraries: uint = 0x103; -pub static tag_native_libraries_lib: uint = 0x104; -pub static tag_native_libraries_name: uint = 0x105; -pub static tag_native_libraries_kind: uint = 0x106; - -pub static tag_macro_registrar_fn: uint = 0x110; -pub static tag_exported_macros: uint = 0x111; -pub static tag_macro_def: uint = 0x112; +pub static tag_macro_registrar_fn: uint = 0x63; +pub static tag_exported_macros: uint = 0x64; +pub static tag_macro_def: uint = 0x65; #[deriving(Clone)] pub struct LinkMeta { diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index e62ae091daf..a80ac38e8ae 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -167,10 +167,10 @@ struct CrateInfo { fn extract_crate_info(i: &ast::ViewItem) -> Option<CrateInfo> { match i.node { - ast::ViewItemExternMod(ref ident, ref path_opt, id) => { - let ident = token::get_ident(ident.name); + ast::ViewItemExternMod(ident, ref path_opt, id) => { + let ident = token::get_ident(ident); debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}", - ident.get(), path_opt); + ident, path_opt); let (name, version) = match *path_opt { Some((ref path_str, _)) => { let crateid: Option<CrateId> = from_str(path_str.get()); @@ -282,16 +282,16 @@ fn visit_item(e: &Env, i: &ast::Item) { } } -fn existing_match(e: &Env, name: ~str, version: ~str, hash: &str) -> Option<ast::CrateNum> { +fn existing_match(e: &Env, name: &str, version: &str, hash: &str) -> Option<ast::CrateNum> { let crate_cache = e.crate_cache.borrow(); for c in crate_cache.get().iter() { let crateid_version = match c.crateid.version { None => ~"0.0", Some(ref ver) => ver.to_str(), }; - if (name.is_empty() || c.crateid.name == name) && - (version.is_empty() || crateid_version == version) && - (hash.is_empty() || c.hash.as_slice() == hash) { + if (name.is_empty() || name == c.crateid.name) && + (version.is_empty() || version == crateid_version) && + (hash.is_empty() || hash == c.hash) { return Some(c.cnum); } } @@ -305,13 +305,13 @@ fn resolve_crate(e: &mut Env, hash: ~str, span: Span) -> ast::CrateNum { - match existing_match(e, name.clone(), version.clone(), hash.clone()) { + match existing_match(e, name, version, hash) { None => { let load_ctxt = loader::Context { sess: e.sess, span: span, ident: ident, - name: name.clone(), + name: name, version: version, hash: hash, os: e.os, @@ -342,7 +342,7 @@ fn resolve_crate(e: &mut Env, let cnum_map = resolve_crate_deps(e, metadata.as_slice()); let cmeta = @cstore::crate_metadata { - name: name, + name: load_ctxt.name, data: metadata, cnum_map: cnum_map, cnum: cnum @@ -372,13 +372,13 @@ fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map { let r = decoder::get_crate_deps(cdata); for dep in r.iter() { let extrn_cnum = dep.cnum; - let cname_str = token::get_ident(dep.name.name); + let cname_str = token::get_ident(dep.name); debug!("resolving dep crate {} ver: {} hash: {}", cname_str, dep.vers, dep.hash); match existing_match(e, - cname_str.get().to_str(), - dep.vers.clone(), - dep.hash.clone()) { + cname_str.get(), + dep.vers, + dep.hash) { Some(local_cnum) => { debug!("already have it"); // We've already seen this crate diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 43694415d8d..7b0c900fcea 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -23,6 +23,7 @@ use std::rc::Rc; use syntax::ast; use syntax::ast_map; use syntax::diagnostic::expect; +use syntax::parse::token; pub struct StaticMethodInfo { ident: ast::Ident, @@ -84,15 +85,14 @@ pub fn each_top_level_item_of_crate(cstore: @cstore::CStore, callback) } -pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ast_map::Path { +pub fn get_item_path(tcx: ty::ctxt, def: ast::DefId) -> ~[ast_map::PathElem] { let cstore = tcx.cstore; let cdata = cstore.get_crate_data(def.krate); let path = decoder::get_item_path(cdata, def.node); // FIXME #1920: This path is not always correct if the crate is not linked // into the root namespace. - vec::append(~[ast_map::PathMod(tcx.sess.ident_of( - cdata.name))], path) + vec::append(~[ast_map::PathMod(token::intern(cdata.name))], path) } pub enum found_ast { @@ -105,12 +105,11 @@ pub enum found_ast { // not marked for inlining, then the AST will not be present and hence none // will be returned. pub fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::DefId, - decode_inlined_item: decoder::decode_inlined_item) + decode_inlined_item: decoder::DecodeInlinedItem) -> found_ast { let cstore = tcx.cstore; let cdata = cstore.get_crate_data(def.krate); - decoder::maybe_get_item_ast(cdata, tcx, def.node, - decode_inlined_item) + decoder::maybe_get_item_ast(cdata, tcx, def.node, decode_inlined_item) } pub fn get_enum_variants(tcx: ty::ctxt, def: ast::DefId) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index cfc2bb502dc..44aa9c84101 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -37,10 +37,10 @@ use serialize::Decodable; use syntax::ast_map; use syntax::attr; use syntax::parse::token::{IdentInterner, special_idents}; +use syntax::parse::token; use syntax::print::pprust; use syntax::ast; use syntax::codemap; -use syntax::parse::token; type Cmd = @crate_metadata; @@ -96,7 +96,7 @@ fn find_item<'a>(item_id: ast::NodeId, items: ebml::Doc<'a>) -> ebml::Doc<'a> { // Looks up an item in the given metadata and returns an ebml doc pointing // to the item data. -pub fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> { +fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> ebml::Doc<'a> { let items = reader::get_doc(reader::Doc(data), tag_items); find_item(item_id, items) } @@ -258,15 +258,13 @@ fn item_ty_param_defs(item: ebml::Doc, Rc::new(bounds) } -fn item_region_param_defs(item_doc: ebml::Doc, - tcx: ty::ctxt, - cdata: Cmd) +fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd) -> Rc<~[ty::RegionParameterDef]> { let mut v = ~[]; 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(tcx.sess.intr(), 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); @@ -296,7 +294,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] { return ids; } -pub fn item_path(item_doc: ebml::Doc) -> ast_map::Path { +fn item_path(item_doc: ebml::Doc) -> ~[ast_map::PathElem] { let path_doc = reader::get_doc(item_doc, tag_path); let len_doc = reader::get_doc(path_doc, tag_path_len); @@ -305,30 +303,21 @@ pub fn item_path(item_doc: ebml::Doc) -> ast_map::Path { let mut result = vec::with_capacity(len); reader::docs(path_doc, |tag, elt_doc| { if tag == tag_path_elem_mod { - let str = elt_doc.as_str_slice(); - result.push(ast_map::PathMod(token::str_to_ident(str))); + let s = elt_doc.as_str_slice(); + result.push(ast_map::PathMod(token::intern(s))); } else if tag == tag_path_elem_name { - let str = elt_doc.as_str_slice(); - result.push(ast_map::PathName(token::str_to_ident(str))); - } else if tag == tag_path_elem_pretty_name { - let name_doc = reader::get_doc(elt_doc, - tag_path_elem_pretty_name_ident); - let extra_doc = reader::get_doc(elt_doc, - tag_path_elem_pretty_name_extra); - let str = name_doc.as_str_slice(); - let extra = reader::doc_as_u64(extra_doc); - result.push(ast_map::PathPrettyName(token::str_to_ident(str), - extra)); + let s = elt_doc.as_str_slice(); + result.push(ast_map::PathName(token::intern(s))); } else { // ignore tag_path_len element } true }); - return result; + result } -fn item_name(intr: @IdentInterner, item: ebml::Doc) -> ast::Ident { +fn item_name(intr: &IdentInterner, item: ebml::Doc) -> ast::Ident { let name = reader::get_doc(item, tag_paths_data_name); let string = name.as_str_slice(); match intr.find_equiv(&string) { @@ -337,7 +326,7 @@ fn item_name(intr: @IdentInterner, item: ebml::Doc) -> ast::Ident { } } -pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum) +fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum) -> DefLike { let fam = item_family(item); match fam { @@ -383,14 +372,6 @@ pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum) } } -pub fn lookup_def(cnum: ast::CrateNum, data: &[u8], did_: ast::DefId) -> - ast::Def { - let item = lookup_item(did_.node, data); - let did = ast::DefId { krate: cnum, node: did_.node }; - // We treat references to enums as references to types. - return def_like_to_def(item_to_def_like(item, did, cnum)); -} - pub fn get_trait_def(cdata: Cmd, item_id: ast::NodeId, tcx: ty::ctxt) -> ty::TraitDef @@ -398,7 +379,7 @@ pub fn get_trait_def(cdata: Cmd, let item_doc = lookup_item(item_id, cdata.data()); let tp_defs = item_ty_param_defs(item_doc, tcx, cdata, tag_items_data_item_ty_param_bounds); - let rp_defs = item_region_param_defs(item_doc, tcx, cdata); + let rp_defs = item_region_param_defs(item_doc, cdata); let mut bounds = ty::EmptyBuiltinBounds(); // Collect the builtin bounds from the encoded supertraits. // FIXME(#8559): They should be encoded directly. @@ -427,7 +408,7 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt) cdata); let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds); - let rp_defs = item_region_param_defs(item, tcx, cdata); + let rp_defs = item_region_param_defs(item, cdata); ty::ty_param_bounds_and_ty { generics: ty::Generics {type_param_defs: tp_defs, @@ -682,41 +663,37 @@ pub fn each_top_level_item_of_crate(intr: @IdentInterner, callback) } -pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ast_map::Path { +pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> ~[ast_map::PathElem] { item_path(lookup_item(id, cdata.data())) } -pub type decode_inlined_item<'a> = 'a |cdata: @cstore::crate_metadata, - tcx: ty::ctxt, - path: ast_map::Path, - par_doc: ebml::Doc| - -> Option<ast::InlinedItem>; +pub type DecodeInlinedItem<'a> = 'a |cdata: @cstore::crate_metadata, + tcx: ty::ctxt, + path: ~[ast_map::PathElem], + par_doc: ebml::Doc| + -> Result<ast::InlinedItem, ~[ast_map::PathElem]>; -pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt, - id: ast::NodeId, - decode_inlined_item: decode_inlined_item) - -> csearch::found_ast { +pub fn maybe_get_item_ast(cdata: Cmd, tcx: ty::ctxt, id: ast::NodeId, + decode_inlined_item: DecodeInlinedItem) + -> csearch::found_ast { debug!("Looking up item: {}", id); let item_doc = lookup_item(id, cdata.data()); - let path = { - let item_path = item_path(item_doc); - item_path.init().to_owned() - }; - match decode_inlined_item(cdata, tcx, /*bad*/path.clone(), item_doc) { - Some(ref ii) => csearch::found(*ii), - None => { - match item_parent_item(item_doc) { - Some(did) => { - let did = translate_def_id(cdata, did); - let parent_item = lookup_item(did.node, cdata.data()); - match decode_inlined_item(cdata, tcx, path, parent_item) { - Some(ref ii) => csearch::found_parent(did, *ii), - None => csearch::not_found + let path = item_path(item_doc).init().to_owned(); + match decode_inlined_item(cdata, tcx, path, item_doc) { + Ok(ref ii) => csearch::found(*ii), + Err(path) => { + match item_parent_item(item_doc) { + Some(did) => { + let did = translate_def_id(cdata, did); + let parent_item = lookup_item(did.node, cdata.data()); + match decode_inlined_item(cdata, tcx, path, parent_item) { + Ok(ref ii) => csearch::found_parent(did, *ii), + Err(_) => csearch::not_found + } + } + None => csearch::not_found } - } - None => csearch::not_found } - } } } @@ -835,7 +812,7 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId, 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, tcx, cdata); + let rp_defs = item_region_param_defs(method_doc, cdata); let fty = doc_method_fty(method_doc, tcx, cdata); let vis = item_visibility(method_doc); let explicit_self = get_explicit_self(method_doc); @@ -1109,13 +1086,13 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] { return attrs; } -fn list_crate_attributes(intr: @IdentInterner, md: ebml::Doc, hash: &str, +fn list_crate_attributes(md: ebml::Doc, hash: &str, out: &mut io::Writer) -> io::IoResult<()> { if_ok!(write!(out, "=Crate Attributes ({})=\n", hash)); let r = get_attributes(md); for attr in r.iter() { - if_ok!(write!(out, "{}\n", pprust::attribute_to_str(attr, intr))); + if_ok!(write!(out, "{}\n", pprust::attribute_to_str(attr))); } write!(out, "\n\n") @@ -1158,11 +1135,10 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> { let r = get_crate_deps(data); for dep in r.iter() { - let string = token::get_ident(dep.name.name); if_ok!(write!(out, "{} {}-{}-{}\n", dep.cnum, - string.get(), + token::get_ident(dep.name), dep.hash, dep.vers)); } @@ -1185,11 +1161,10 @@ pub fn get_crate_vers(data: &[u8]) -> ~str { } } -pub fn list_crate_metadata(intr: @IdentInterner, bytes: &[u8], - out: &mut io::Writer) -> io::IoResult<()> { +pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> { let hash = get_crate_hash(bytes); let md = reader::Doc(bytes); - if_ok!(list_crate_attributes(intr, md, hash, out)); + if_ok!(list_crate_attributes(md, hash, out)); list_crate_deps(bytes, out) } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index b5fef36607f..5fb3f48bd6e 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -28,10 +28,10 @@ use std::cell::{Cell, RefCell}; use std::hashmap::{HashMap, HashSet}; use std::io::MemWriter; use std::str; -use std::vec; use syntax::abi::AbiSet; use syntax::ast::*; use syntax::ast; +use syntax::ast_map::{PathElem, PathElems}; use syntax::ast_map; use syntax::ast_util::*; use syntax::ast_util; @@ -57,10 +57,9 @@ pub enum InlinedItemRef<'a> { IIForeignRef(&'a ast::ForeignItem) } -pub type encode_inlined_item<'a> = 'a |ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - path: &[ast_map::PathElem], - ii: InlinedItemRef|; +pub type EncodeInlinedItem<'a> = 'a |ecx: &EncodeContext, + ebml_w: &mut writer::Encoder, + ii: InlinedItemRef|; pub struct EncodeParams<'a> { diag: @SpanHandler, @@ -70,7 +69,7 @@ pub struct EncodeParams<'a> { non_inlineable_statics: &'a RefCell<HashSet<ast::NodeId>>, link_meta: &'a LinkMeta, cstore: @cstore::CStore, - encode_inlined_item: encode_inlined_item<'a>, + encode_inlined_item: EncodeInlinedItem<'a>, reachable: @RefCell<HashSet<ast::NodeId>>, codemap: @codemap::CodeMap, } @@ -100,7 +99,7 @@ pub struct EncodeContext<'a> { non_inlineable_statics: &'a RefCell<HashSet<ast::NodeId>>, link_meta: &'a LinkMeta, cstore: &'a cstore::CStore, - encode_inlined_item: encode_inlined_item<'a>, + encode_inlined_item: EncodeInlinedItem<'a>, type_abbrevs: abbrev_map, reachable: @RefCell<HashSet<ast::NodeId>>, codemap: @codemap::CodeMap, @@ -111,17 +110,12 @@ pub fn reachable(ecx: &EncodeContext, id: NodeId) -> bool { reachable.get().contains(&id) } -fn encode_name(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - name: Ident) { - ebml_w.wr_tagged_str(tag_paths_data_name, ecx.tcx.sess.str_of(name)); +fn encode_name(ebml_w: &mut writer::Encoder, name: Ident) { + ebml_w.wr_tagged_str(tag_paths_data_name, token::get_ident(name).get()); } -fn encode_impl_type_basename(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - name: Ident) { - ebml_w.wr_tagged_str(tag_item_impl_type_basename, - ecx.tcx.sess.str_of(name)); +fn encode_impl_type_basename(ebml_w: &mut writer::Encoder, name: Ident) { + ebml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get()); } pub fn encode_def_id(ebml_w: &mut writer::Encoder, id: DefId) { @@ -188,13 +182,12 @@ fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder, } fn encode_region_param_defs(ebml_w: &mut writer::Encoder, - ecx: &EncodeContext, params: &[ty::RegionParameterDef]) { for param in params.iter() { ebml_w.start_tag(tag_region_param_def); ebml_w.start_tag(tag_region_param_def_ident); - encode_name(ecx, ebml_w, param.ident); + encode_name(ebml_w, param.ident); ebml_w.end_tag(); ebml_w.wr_tagged_str(tag_region_param_def_def_id, @@ -218,7 +211,7 @@ fn encode_bounds_and_type(ebml_w: &mut writer::Encoder, tpt: &ty::ty_param_bounds_and_ty) { encode_ty_type_param_defs(ebml_w, ecx, tpt.generics.type_param_defs(), tag_items_data_item_ty_param_bounds); - encode_region_param_defs(ebml_w, ecx, tpt.generics.region_param_defs()); + encode_region_param_defs(ebml_w, tpt.generics.region_param_defs()); encode_type(ecx, ebml_w, tpt.ty); } @@ -311,15 +304,14 @@ fn encode_parent_item(ebml_w: &mut writer::Encoder, id: DefId) { ebml_w.end_tag(); } -fn encode_struct_fields(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - def: @StructDef) { +fn encode_struct_fields(ebml_w: &mut writer::Encoder, + def: @StructDef) { for f in def.fields.iter() { match f.node.kind { NamedField(ident, vis) => { ebml_w.start_tag(tag_item_field); encode_struct_field_family(ebml_w, vis); - encode_name(ecx, ebml_w, ident); + encode_name(ebml_w, ident); encode_def_id(ebml_w, local_def(f.node.id)); ebml_w.end_tag(); } @@ -336,7 +328,6 @@ fn encode_enum_variant_info(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, id: NodeId, variants: &[P<Variant>], - path: &[ast_map::PathElem], index: @RefCell<~[entry<i64>]>, generics: &ast::Generics) { debug!("encode_enum_variant_info(id={:?})", id); @@ -360,7 +351,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext, ast::TupleVariantKind(_) => encode_family(ebml_w, 'v'), ast::StructVariantKind(_) => encode_family(ebml_w, 'V') } - encode_name(ecx, ebml_w, variant.node.name); + encode_name(ebml_w, variant.node.name); encode_parent_item(ebml_w, local_def(id)); encode_visibility(ebml_w, variant.node.vis); encode_attributes(ebml_w, variant.node.attrs); @@ -371,9 +362,8 @@ fn encode_enum_variant_info(ecx: &EncodeContext, } ast::TupleVariantKind(_) => {}, ast::StructVariantKind(def) => { - let idx = encode_info_for_struct(ecx, ebml_w, path, - def.fields, index); - encode_struct_fields(ecx, ebml_w, def); + let idx = encode_info_for_struct(ecx, ebml_w, def.fields, index); + encode_struct_fields(ebml_w, def); let bkts = create_index(idx); encode_index(ebml_w, bkts, write_i64); } @@ -384,60 +374,40 @@ fn encode_enum_variant_info(ecx: &EncodeContext, } encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(ecx.tcx, def_id)); - encode_path(ecx, ebml_w, path, - ast_map::PathName(variant.node.name)); + + ecx.tcx.map.with_path(variant.node.id, |path| encode_path(ebml_w, path)); ebml_w.end_tag(); disr_val += 1; i += 1; } } -fn encode_path(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - path: &[ast_map::PathElem], - name: ast_map::PathElem) { - fn encode_path_elem(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - elt: ast_map::PathElem) { - match elt { - ast_map::PathMod(n) => { - ebml_w.wr_tagged_str(tag_path_elem_mod, ecx.tcx.sess.str_of(n)); - } - ast_map::PathName(n) => { - ebml_w.wr_tagged_str(tag_path_elem_name, ecx.tcx.sess.str_of(n)); - } - ast_map::PathPrettyName(n, extra) => { - ebml_w.start_tag(tag_path_elem_pretty_name); - ebml_w.wr_tagged_str(tag_path_elem_pretty_name_ident, - ecx.tcx.sess.str_of(n)); - ebml_w.wr_tagged_u64(tag_path_elem_pretty_name_extra, extra); - ebml_w.end_tag(); - } - } - } - +fn encode_path<PI: Iterator<PathElem> + Clone>(ebml_w: &mut writer::Encoder, + mut path: PI) { ebml_w.start_tag(tag_path); - ebml_w.wr_tagged_u32(tag_path_len, (path.len() + 1) as u32); - for pe in path.iter() { - encode_path_elem(ecx, ebml_w, *pe); + ebml_w.wr_tagged_u32(tag_path_len, path.clone().len() as u32); + for pe in path { + let tag = match pe { + ast_map::PathMod(_) => tag_path_elem_mod, + ast_map::PathName(_) => tag_path_elem_name + }; + ebml_w.wr_tagged_str(tag, token::get_name(pe.name()).get()); } - encode_path_elem(ecx, ebml_w, name); ebml_w.end_tag(); } -fn encode_reexported_static_method(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, +fn encode_reexported_static_method(ebml_w: &mut writer::Encoder, exp: &middle::resolve::Export2, method_def_id: DefId, method_ident: Ident) { debug!("(encode reexported static method) {}::{}", - exp.name, ecx.tcx.sess.str_of(method_ident)); + exp.name, token::get_ident(method_ident)); ebml_w.start_tag(tag_items_data_item_reexport); ebml_w.start_tag(tag_items_data_item_reexport_def_id); ebml_w.wr_str(def_to_str(method_def_id)); ebml_w.end_tag(); ebml_w.start_tag(tag_items_data_item_reexport_name); - ebml_w.wr_str(format!("{}::{}", exp.name, ecx.tcx.sess.str_of(method_ident))); + ebml_w.wr_str(format!("{}::{}", exp.name, token::get_ident(method_ident))); ebml_w.end_tag(); ebml_w.end_tag(); } @@ -453,8 +423,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, for &base_impl in implementations.get().iter() { for &m in base_impl.methods.iter() { if m.explicit_self == ast::SelfStatic { - encode_reexported_static_method(ecx, ebml_w, exp, - m.def_id, m.ident); + encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident); } } } @@ -474,8 +443,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext, Some(methods) => { for &m in methods.iter() { if m.explicit_self == ast::SelfStatic { - encode_reexported_static_method(ecx, ebml_w, exp, - m.def_id, m.ident); + encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident); } } @@ -487,11 +455,22 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext, fn encode_reexported_static_methods(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, - mod_path: &[ast_map::PathElem], + mod_path: PathElems, exp: &middle::resolve::Export2) { - match ecx.tcx.items.find(exp.def_id.node) { - Some(ast_map::NodeItem(item, path)) => { - let original_name = token::get_ident(item.ident.name); + match ecx.tcx.map.find(exp.def_id.node) { + Some(ast_map::NodeItem(item)) => { + let original_name = token::get_ident(item.ident); + + let path_differs = ecx.tcx.map.with_path(exp.def_id.node, |path| { + let (mut a, mut b) = (path, mod_path.clone()); + loop { + match (a.next(), b.next()) { + (None, None) => return true, + (None, _) | (_, None) => return false, + (Some(x), Some(y)) => if x != y { return false }, + } + } + }); // // We don't need to reexport static methods on items @@ -503,7 +482,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, // encoded metadata for static methods relative to Bar, // but not yet for Foo. // - if mod_path != *path || original_name.get() != exp.name { + if path_differs || original_name.get() != exp.name { if !encode_reexported_static_base_methods(ecx, ebml_w, exp) { if encode_reexported_static_trait_methods(ecx, ebml_w, exp) { debug!("(encode reexported static methods) {} \ @@ -558,7 +537,7 @@ fn each_auxiliary_node_id(item: @Item, callback: |NodeId| -> bool) -> bool { fn encode_reexports(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, id: NodeId, - path: &[ast_map::PathElem]) { + path: PathElems) { debug!("(encoding info for module) encoding reexports for {}", id); let reexports2 = ecx.reexports2.borrow(); match reexports2.get().find(&id) { @@ -579,7 +558,7 @@ fn encode_reexports(ecx: &EncodeContext, ebml_w.wr_str(exp.name); ebml_w.end_tag(); ebml_w.end_tag(); - encode_reexported_static_methods(ecx, ebml_w, path, exp); + encode_reexported_static_methods(ecx, ebml_w, path.clone(), exp); } } None => { @@ -593,13 +572,13 @@ fn encode_info_for_mod(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, md: &Mod, id: NodeId, - path: &[ast_map::PathElem], + path: PathElems, name: Ident, vis: Visibility) { ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(id)); encode_family(ebml_w, 'm'); - encode_name(ecx, ebml_w, name); + encode_name(ebml_w, name); debug!("(encoding info for module) encoding info for module ID {}", id); // Encode info about all the module children. @@ -620,9 +599,8 @@ fn encode_info_for_mod(ecx: &EncodeContext, let (ident, did) = (item.ident, item.id); debug!("(encoding info for module) ... encoding impl {} \ ({:?}/{:?})", - ecx.tcx.sess.str_of(ident), - did, - ast_map::node_id_to_str(ecx.tcx.items, did, token::get_ident_interner())); + token::get_ident(ident), + did, ecx.tcx.map.node_to_str(did)); ebml_w.start_tag(tag_mod_impl); ebml_w.wr_str(def_to_str(local_def(did))); @@ -632,7 +610,7 @@ fn encode_info_for_mod(ecx: &EncodeContext, } } - encode_path(ecx, ebml_w, path, ast_map::PathMod(name)); + encode_path(ebml_w, path.clone()); encode_visibility(ebml_w, vis); // Encode the reexports of this module, if this module is public. @@ -709,7 +687,6 @@ fn encode_provided_source(ebml_w: &mut writer::Encoder, /* Returns an index of items in this class */ fn encode_info_for_struct(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, - path: &[ast_map::PathElem], fields: &[StructField], global_index: @RefCell<~[entry<i64>]>) -> ~[entry<i64>] { @@ -736,10 +713,9 @@ fn encode_info_for_struct(ecx: &EncodeContext, } ebml_w.start_tag(tag_items_data_item); debug!("encode_info_for_struct: doing {} {}", - tcx.sess.str_of(nm), id); + token::get_ident(nm), id); encode_struct_field_family(ebml_w, vis); - encode_name(ecx, ebml_w, nm); - encode_path(ecx, ebml_w, path, ast_map::PathName(nm)); + encode_name(ebml_w, nm); encode_type(ecx, ebml_w, node_id_to_type(tcx, id)); encode_def_id(ebml_w, local_def(id)); ebml_w.end_tag(); @@ -749,7 +725,6 @@ fn encode_info_for_struct(ecx: &EncodeContext, fn encode_info_for_struct_ctor(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, - path: &[ast_map::PathElem], name: ast::Ident, ctor_id: NodeId, index: @RefCell<~[entry<i64>]>, @@ -767,9 +742,9 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext, encode_family(ebml_w, 'f'); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(ecx.tcx, local_def(ctor_id))); - encode_name(ecx, ebml_w, name); + encode_name(ebml_w, name); encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id)); - encode_path(ecx, ebml_w, path, ast_map::PathName(name)); + ecx.tcx.map.with_path(ctor_id, |path| encode_path(ebml_w, path)); encode_parent_item(ebml_w, local_def(struct_id)); let item_symbols = ecx.item_symbols.borrow(); @@ -790,7 +765,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, method_ty: &ty::Method) { encode_def_id(ebml_w, method_ty.def_id); - encode_name(ecx, ebml_w, method_ty.ident); + encode_name(ebml_w, method_ty.ident); encode_ty_type_param_defs(ebml_w, ecx, method_ty.generics.type_param_defs(), tag_item_method_tps); @@ -810,13 +785,13 @@ fn encode_method_ty_fields(ecx: &EncodeContext, fn encode_info_for_method(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, m: &ty::Method, - impl_path: &[ast_map::PathElem], + impl_path: PathElems, is_default_impl: bool, parent_id: NodeId, ast_method_opt: Option<@Method>) { debug!("encode_info_for_method: {:?} {}", m.def_id, - ecx.tcx.sess.str_of(m.ident)); + token::get_ident(m.ident)); ebml_w.start_tag(tag_items_data_item); encode_method_ty_fields(ecx, ebml_w, m); @@ -826,7 +801,8 @@ fn encode_info_for_method(ecx: &EncodeContext, let tpt = lookup_item_type(ecx.tcx, m.def_id); encode_bounds_and_type(ebml_w, ecx, &tpt); - encode_path(ecx, ebml_w, impl_path, ast_map::PathName(m.ident)); + let elem = ast_map::PathName(m.ident.name); + encode_path(ebml_w, impl_path.chain(Some(elem).move_iter())); match ast_method_opt { Some(ast_method) => encode_attributes(ebml_w, ast_method.attrs), None => () @@ -834,11 +810,9 @@ fn encode_info_for_method(ecx: &EncodeContext, for &ast_method in ast_method_opt.iter() { let num_params = tpt.generics.type_param_defs().len(); - if num_params > 0u || is_default_impl - || should_inline(ast_method.attrs) { + if num_params > 0u || is_default_impl || should_inline(ast_method.attrs) { (ecx.encode_inlined_item)( - ecx, ebml_w, impl_path, - IIMethodRef(local_def(parent_id), false, ast_method)); + ecx, ebml_w, IIMethodRef(local_def(parent_id), false, ast_method)); } else { encode_symbol(ecx, ebml_w, m.def_id.node); } @@ -912,7 +886,7 @@ fn encode_info_for_item(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, item: &Item, index: @RefCell<~[entry<i64>]>, - path: &[ast_map::PathElem], + path: PathElems, vis: ast::Visibility) { let tcx = ecx.tcx; @@ -941,18 +915,13 @@ fn encode_info_for_item(ecx: &EncodeContext, } encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_symbol(ecx, ebml_w, item.id); - encode_name(ecx, ebml_w, item.ident); - let elt = ast_map::PathPrettyName(item.ident, item.id as u64); - encode_path(ecx, ebml_w, path, elt); + encode_name(ebml_w, item.ident); + encode_path(ebml_w, path); - let non_inlineable; - { - let non_inlineable_statics = ecx.non_inlineable_statics.borrow(); - non_inlineable = non_inlineable_statics.get().contains(&item.id); - } + let inlineable = !ecx.non_inlineable_statics.borrow().get().contains(&item.id); - if !non_inlineable { - (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item)); + if inlineable { + (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); } encode_visibility(ebml_w, vis); ebml_w.end_tag(); @@ -964,11 +933,11 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_family(ebml_w, purity_fn_family(purity)); let tps_len = generics.ty_params.len(); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ecx, ebml_w, item.ident); - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + encode_name(ebml_w, item.ident); + encode_path(ebml_w, path); encode_attributes(ebml_w, item.attrs); if tps_len > 0u || should_inline(item.attrs) { - (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item)); + (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); } else { encode_symbol(ecx, ebml_w, item.id); } @@ -990,8 +959,8 @@ fn encode_info_for_item(ecx: &EncodeContext, ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, def_id); encode_family(ebml_w, 'n'); - encode_name(ecx, ebml_w, item.ident); - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + encode_name(ebml_w, item.ident); + encode_path(ebml_w, path); // Encode all the items in this module. for foreign_item in fm.items.iter() { @@ -1008,8 +977,8 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_def_id(ebml_w, def_id); encode_family(ebml_w, 'y'); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ecx, ebml_w, item.ident); - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + encode_name(ebml_w, item.ident); + encode_path(ebml_w, path); encode_visibility(ebml_w, vis); ebml_w.end_tag(); } @@ -1021,13 +990,13 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_family(ebml_w, 't'); encode_item_variances(ebml_w, ecx, item.id); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ecx, ebml_w, item.ident); + encode_name(ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); for v in (*enum_definition).variants.iter() { encode_variant_id(ebml_w, local_def(v.node.id)); } - (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item)); - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); + encode_path(ebml_w, path); // Encode inherent implementations for this enumeration. encode_inherent_implementations(ecx, ebml_w, def_id); @@ -1039,7 +1008,6 @@ fn encode_info_for_item(ecx: &EncodeContext, ebml_w, item.id, (*enum_definition).variants, - path, index, generics); } @@ -1048,7 +1016,7 @@ fn encode_info_for_item(ecx: &EncodeContext, These come first because we need to write them to make the index, and the index needs to be in the item for the class itself */ - let idx = encode_info_for_struct(ecx, ebml_w, path, + let idx = encode_info_for_struct(ecx, ebml_w, struct_def.fields, index); /* Index the class*/ @@ -1061,17 +1029,17 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); encode_item_variances(ebml_w, ecx, item.id); - encode_name(ecx, ebml_w, item.ident); + encode_name(ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + encode_path(ebml_w, path.clone()); encode_visibility(ebml_w, vis); /* Encode def_ids for each field and method for methods, write all the stuff get_trait_method needs to know*/ - encode_struct_fields(ecx, ebml_w, struct_def); + encode_struct_fields(ebml_w, struct_def); - (ecx.encode_inlined_item)(ecx, ebml_w, path, IIItemRef(item)); + (ecx.encode_inlined_item)(ecx, ebml_w, IIItemRef(item)); // Encode inherent implementations for this structure. encode_inherent_implementations(ecx, ebml_w, def_id); @@ -1081,22 +1049,13 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_index(ebml_w, bkts, write_i64); ebml_w.end_tag(); - // If this is a tuple- or enum-like struct, encode the type of the - // constructor. - if struct_def.fields.len() > 0 && - struct_def.fields[0].node.kind == ast::UnnamedField { - let ctor_id = match struct_def.ctor_id { - Some(ctor_id) => ctor_id, - None => ecx.tcx.sess.bug("struct def didn't have ctor id"), - }; - - encode_info_for_struct_ctor(ecx, - ebml_w, - path, - item.ident, - ctor_id, - index, - def_id.node); + // If this is a tuple-like struct, encode the type of the constructor. + match struct_def.ctor_id { + Some(ctor_id) => { + encode_info_for_struct_ctor(ecx, ebml_w, item.ident, + ctor_id, index, def_id.node); + } + None => {} } } ItemImpl(_, ref opt_trait, ty, ref ast_methods) => { @@ -1110,14 +1069,13 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_def_id(ebml_w, def_id); encode_family(ebml_w, 'i'); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id)); - encode_name(ecx, ebml_w, item.ident); + encode_name(ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); match ty.node { ast::TyPath(ref path, ref bounds, _) if path.segments .len() == 1 => { assert!(bounds.is_none()); - encode_impl_type_basename(ecx, ebml_w, - ast_util::path_to_ident(path)); + encode_impl_type_basename(ebml_w, ast_util::path_to_ident(path)); } _ => {} } @@ -1134,14 +1092,9 @@ fn encode_info_for_item(ecx: &EncodeContext, let impl_vtables = ty::lookup_impl_vtables(tcx, def_id); encode_impl_vtables(ebml_w, ecx, &impl_vtables); } - let elt = ast_map::impl_pretty_name(opt_trait, ty); - encode_path(ecx, ebml_w, path, elt); + encode_path(ebml_w, path.clone()); ebml_w.end_tag(); - // >:-< - let mut impl_path = vec::append(~[], path); - impl_path.push(elt); - // Iterate down the methods, emitting them. We rely on the // assumption that all of the actually implemented methods // appear first in the impl structure, in the same order they do @@ -1162,7 +1115,7 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_info_for_method(ecx, ebml_w, *m, - impl_path, + path.clone(), false, item.id, ast_method) @@ -1178,10 +1131,9 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_ty_type_param_defs(ebml_w, ecx, trait_def.generics.type_param_defs(), tag_items_data_item_ty_param_bounds); - encode_region_param_defs(ebml_w, ecx, - trait_def.generics.region_param_defs()); + encode_region_param_defs(ebml_w, trait_def.generics.region_param_defs()); encode_trait_ref(ebml_w, ecx, trait_def.trait_ref, tag_item_trait_ref); - encode_name(ecx, ebml_w, item.ident); + encode_name(ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); encode_visibility(ebml_w, vis); for &method_def_id in ty::trait_method_def_ids(tcx, def_id).iter() { @@ -1193,7 +1145,7 @@ fn encode_info_for_item(ecx: &EncodeContext, ebml_w.wr_str(def_to_str(method_def_id)); ebml_w.end_tag(); } - encode_path(ecx, ebml_w, path, ast_map::PathName(item.ident)); + encode_path(ebml_w, path.clone()); // FIXME(#8559): This should use the tcx's supertrait cache instead of // reading the AST's list, because the former has already filtered out // the builtin-kinds-as-supertraits. See corresponding fixme in decoder. @@ -1228,9 +1180,8 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_parent_item(ebml_w, def_id); - let mut trait_path = vec::append(~[], path); - trait_path.push(ast_map::PathName(item.ident)); - encode_path(ecx, ebml_w, trait_path, ast_map::PathName(method_ty.ident)); + let elem = ast_map::PathName(method_ty.ident.name); + encode_path(ebml_w, path.clone().chain(Some(elem).move_iter())); match method_ty.explicit_self { SelfStatic => { @@ -1266,8 +1217,7 @@ fn encode_info_for_item(ecx: &EncodeContext, } encode_method_sort(ebml_w, 'p'); (ecx.encode_inlined_item)( - ecx, ebml_w, path, - IIMethodRef(def_id, true, m)); + ecx, ebml_w, IIMethodRef(def_id, true, m)); } } @@ -1287,7 +1237,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, ebml_w: &mut writer::Encoder, nitem: &ForeignItem, index: @RefCell<~[entry<i64>]>, - path: &ast_map::Path, + path: PathElems, abi: AbiSet) { { let mut index = index.borrow_mut(); @@ -1298,22 +1248,20 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, } ebml_w.start_tag(tag_items_data_item); + encode_def_id(ebml_w, local_def(nitem.id)); match nitem.node { ForeignItemFn(..) => { - encode_def_id(ebml_w, local_def(nitem.id)); encode_family(ebml_w, purity_fn_family(ImpureFn)); encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(ecx.tcx,local_def(nitem.id))); - encode_name(ecx, ebml_w, nitem.ident); + encode_name(ebml_w, nitem.ident); if abi.is_intrinsic() { - (ecx.encode_inlined_item)(ecx, ebml_w, *path, IIForeignRef(nitem)); + (ecx.encode_inlined_item)(ecx, ebml_w, IIForeignRef(nitem)); } else { encode_symbol(ecx, ebml_w, nitem.id); } - encode_path(ecx, ebml_w, *path, ast_map::PathName(nitem.ident)); } ForeignItemStatic(_, mutbl) => { - encode_def_id(ebml_w, local_def(nitem.id)); if mutbl { encode_family(ebml_w, 'b'); } else { @@ -1321,66 +1269,51 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, } encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id)); encode_symbol(ecx, ebml_w, nitem.id); - encode_name(ecx, ebml_w, nitem.ident); - encode_path(ecx, ebml_w, *path, ast_map::PathName(nitem.ident)); + encode_name(ebml_w, nitem.ident); } } + encode_path(ebml_w, path); ebml_w.end_tag(); } fn my_visit_expr(_e: &Expr) { } fn my_visit_item(i: &Item, - items: ast_map::Map, ebml_w: &mut writer::Encoder, ecx_ptr: *int, index: @RefCell<~[entry<i64>]>) { - match items.get(i.id) { - ast_map::NodeItem(_, pt) => { - let mut ebml_w = unsafe { - ebml_w.unsafe_clone() - }; - // See above - let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; - encode_info_for_item(ecx, &mut ebml_w, i, index, *pt, i.vis); - } - _ => fail!("bad item") - } + let mut ebml_w = unsafe { ebml_w.unsafe_clone() }; + // See above + let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; + ecx.tcx.map.with_path(i.id, |path| { + encode_info_for_item(ecx, &mut ebml_w, i, index, path, i.vis); + }); } fn my_visit_foreign_item(ni: &ForeignItem, - items: ast_map::Map, ebml_w: &mut writer::Encoder, ecx_ptr:*int, index: @RefCell<~[entry<i64>]>) { - match items.get(ni.id) { - ast_map::NodeForeignItem(_, abi, _, pt) => { - let string = token::get_ident(ni.ident.name); - debug!("writing foreign item {}::{}", - ast_map::path_to_str(*pt, token::get_ident_interner()), - string.get()); - - let mut ebml_w = unsafe { - ebml_w.unsafe_clone() - }; - // See above - let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; - encode_info_for_foreign_item(ecx, - &mut ebml_w, - ni, - index, - pt, - abi); - } - // case for separate item and foreign-item tables - _ => fail!("bad foreign item") - } + // See above + let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) }; + debug!("writing foreign item {}::{}", + ecx.tcx.map.path_to_str(ni.id), + token::get_ident(ni.ident)); + + let mut ebml_w = unsafe { + ebml_w.unsafe_clone() + }; + let abis = ecx.tcx.map.get_foreign_abis(ni.id); + ecx.tcx.map.with_path(ni.id, |path| { + encode_info_for_foreign_item(ecx, &mut ebml_w, + ni, index, + path, abis); + }); } struct EncodeVisitor<'a,'b> { ebml_w_for_visit_item: &'a mut writer::Encoder<'b>, ecx_ptr:*int, - items: ast_map::Map, index: @RefCell<~[entry<i64>]>, } @@ -1392,7 +1325,6 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> { fn visit_item(&mut self, i: &Item, _: ()) { visit::walk_item(self, i, ()); my_visit_item(i, - self.items, self.ebml_w_for_visit_item, self.ecx_ptr, self.index); @@ -1400,7 +1332,6 @@ impl<'a,'b> visit::Visitor<()> for EncodeVisitor<'a,'b> { fn visit_foreign_item(&mut self, ni: &ForeignItem, _: ()) { visit::walk_foreign_item(self, ni, ()); my_visit_foreign_item(ni, - self.items, self.ebml_w_for_visit_item, self.ecx_ptr, self.index); @@ -1424,17 +1355,15 @@ fn encode_info_for_items(ecx: &EncodeContext, ebml_w, &krate.module, CRATE_NODE_ID, - [], + ast_map::Values([].iter()).chain(None), syntax::parse::token::special_idents::invalid, Public); - let items = ecx.tcx.items; // See comment in `encode_side_tables_for_ii` in astencode - let ecx_ptr : *int = unsafe { cast::transmute(ecx) }; + let ecx_ptr: *int = unsafe { cast::transmute(ecx) }; { let mut visitor = EncodeVisitor { index: index, - items: items, ecx_ptr: ecx_ptr, ebml_w_for_visit_item: &mut *ebml_w, }; @@ -1581,20 +1510,17 @@ fn synthesize_crate_attrs(ecx: &EncodeContext, attrs } -fn encode_crate_deps(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, - cstore: &cstore::CStore) { - fn get_ordered_deps(ecx: &EncodeContext, cstore: &cstore::CStore) - -> ~[decoder::CrateDep] { - type numdep = decoder::CrateDep; - +fn encode_crate_deps(ebml_w: &mut writer::Encoder, cstore: &cstore::CStore) { + fn get_ordered_deps(cstore: &cstore::CStore) -> ~[decoder::CrateDep] { // Pull the cnums and name,vers,hash out of cstore let mut deps = ~[]; cstore.iter_crate_data(|key, val| { - let dep = decoder::CrateDep {cnum: key, - name: ecx.tcx.sess.ident_of(val.name), - vers: decoder::get_crate_vers(val.data()), - hash: decoder::get_crate_hash(val.data())}; + let dep = decoder::CrateDep { + cnum: key, + name: token::str_to_ident(val.name), + vers: decoder::get_crate_vers(val.data()), + hash: decoder::get_crate_hash(val.data()) + }; deps.push(dep); }); @@ -1616,9 +1542,9 @@ fn encode_crate_deps(ecx: &EncodeContext, // FIXME (#2166): This is not nearly enough to support correct versioning // but is enough to get transitive crate dependencies working. ebml_w.start_tag(tag_crate_deps); - let r = get_ordered_deps(ecx, cstore); + let r = get_ordered_deps(cstore); for dep in r.iter() { - encode_crate_dep(ecx, ebml_w, (*dep).clone()); + encode_crate_dep(ebml_w, (*dep).clone()); } ebml_w.end_tag(); } @@ -1801,19 +1727,18 @@ fn encode_misc_info(ecx: &EncodeContext, } // Encode reexports for the root module. - encode_reexports(ecx, ebml_w, 0, []); + encode_reexports(ecx, ebml_w, 0, ast_map::Values([].iter()).chain(None)); ebml_w.end_tag(); ebml_w.end_tag(); } -fn encode_crate_dep(ecx: &EncodeContext, - ebml_w: &mut writer::Encoder, +fn encode_crate_dep(ebml_w: &mut writer::Encoder, dep: decoder::CrateDep) { ebml_w.start_tag(tag_crate_dep); ebml_w.start_tag(tag_crate_dep_name); - let s = ecx.tcx.sess.str_of(dep.name); - ebml_w.writer.write(s.as_bytes()); + let s = token::get_ident(dep.name); + ebml_w.writer.write(s.get().as_bytes()); ebml_w.end_tag(); ebml_w.start_tag(tag_crate_dep_vers); ebml_w.writer.write(dep.vers.as_bytes()); @@ -1900,7 +1825,7 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) ecx.stats.attr_bytes.set(ebml_w.writer.tell().unwrap() - i); i = ebml_w.writer.tell().unwrap(); - encode_crate_deps(&ecx, &mut ebml_w, ecx.cstore); + encode_crate_deps(&mut ebml_w, ecx.cstore); ecx.stats.dep_bytes.set(ebml_w.writer.tell().unwrap() - i); // Encode the language items. diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 8e704aa14da..8a7964fcf6b 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -28,7 +28,6 @@ use std::c_str::ToCStr; use std::cast; use std::cmp; use std::io; -use std::option; use std::os::consts::{macos, freebsd, linux, android, win32}; use std::str; use std::vec; @@ -377,16 +376,10 @@ pub fn read_meta_section_name(os: Os) -> &'static str { } // A diagnostic function for dumping crate metadata to an output stream -pub fn list_file_metadata(intr: @IdentInterner, - os: Os, - path: &Path, +pub fn list_file_metadata(os: Os, path: &Path, out: &mut io::Writer) -> io::IoResult<()> { match get_metadata_section(os, path) { - option::Some(bytes) => decoder::list_crate_metadata(intr, - bytes.as_slice(), - out), - option::None => { - write!(out, "could not find metadata in {}.\n", path.display()) - } + Some(bytes) => decoder::list_crate_metadata(bytes.as_slice(), out), + None => write!(out, "could not find metadata in {}.\n", path.display()) } } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 5c3fb8bebb0..ca1aabb74f4 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -24,6 +24,7 @@ use syntax::abi; use syntax::ast; use syntax::ast::*; use syntax::opt_vec; +use syntax::parse::token; // Compact string representation for ty::t values. API ty_str & // parse_from_str. Extra parameters are for converting to/from def_ids in the @@ -96,10 +97,9 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident { } fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident { - let tcx = st.tcx; scan(st, is_last, |bytes| { - tcx.sess.ident_of(str::from_utf8(bytes).unwrap()) - }) + token::str_to_ident(str::from_utf8(bytes).unwrap()) + }) } pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum, @@ -212,7 +212,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion { } '[' => { let def = parse_def(st, RegionParameter, |x,y| conv(x,y)); - let ident = st.tcx.sess.ident_of(parse_str(st, ']')); + let ident = token::str_to_ident(parse_str(st, ']')); ty::BrNamed(def, ident) } 'f' => { @@ -240,7 +240,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region { assert_eq!(next(st), '|'); let index = parse_uint(st); assert_eq!(next(st), '|'); - let nm = st.tcx.sess.ident_of(parse_str(st, ']')); + let nm = token::str_to_ident(parse_str(st, ']')); ty::ReEarlyBound(node_id, index, nm) } 'f' => { diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 0f4a1899368..d6245f13245 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -26,6 +26,7 @@ use syntax::abi::AbiSet; use syntax::ast; use syntax::ast::*; use syntax::diagnostic::SpanHandler; +use syntax::parse::token; use syntax::print::pprust::*; macro_rules! mywrite( ($wr:expr, $($arg:tt)*) => ( @@ -177,7 +178,7 @@ fn enc_region(w: &mut MemWriter, cx: @ctxt, r: ty::Region) { mywrite!(w, "B[{}|{}|{}]", node_id, index, - cx.tcx.sess.str_of(ident)); + token::get_ident(ident)); } ty::ReFree(ref fr) => { mywrite!(w, "f[{}|", fr.scope_id); @@ -208,7 +209,7 @@ fn enc_bound_region(w: &mut MemWriter, cx: @ctxt, br: ty::BoundRegion) { ty::BrNamed(d, s) => { mywrite!(w, "[{}|{}]", (cx.ds)(d), - cx.tcx.sess.str_of(s)); + token::get_ident(s)); } ty::BrFresh(id) => { mywrite!(w, "f{}|", id); @@ -420,7 +421,7 @@ fn enc_bounds(w: &mut MemWriter, cx: @ctxt, bs: &ty::ParamBounds) { } pub fn enc_type_param_def(w: &mut MemWriter, cx: @ctxt, v: &ty::TypeParameterDef) { - mywrite!(w, "{}:{}|", cx.tcx.sess.str_of(v.ident), (cx.ds)(v.def_id)); + mywrite!(w, "{}:{}|", token::get_ident(v.ident), (cx.ds)(v.def_id)); enc_bounds(w, cx, v.bounds); enc_opt(w, v.default, |w, t| enc_ty(w, cx, t)); } |
