about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_metadata/astencode.rs16
-rw-r--r--src/librustc_metadata/decoder.rs9
-rw-r--r--src/librustc_metadata/def_key.rs104
-rw-r--r--src/librustc_metadata/encoder.rs22
-rw-r--r--src/librustc_metadata/lib.rs3
5 files changed, 132 insertions, 22 deletions
diff --git a/src/librustc_metadata/astencode.rs b/src/librustc_metadata/astencode.rs
index 6fd9f27f0fb..49512a5018e 100644
--- a/src/librustc_metadata/astencode.rs
+++ b/src/librustc_metadata/astencode.rs
@@ -49,9 +49,9 @@ use std::fmt::Debug;
 use rbml::reader;
 use rbml::writer::Encoder;
 use rbml;
-use serialize;
-use serialize::{Decodable, Decoder, DecoderHelpers, Encodable};
-use serialize::EncoderHelpers;
+use rustc_serialize as serialize;
+use rustc_serialize::{Decodable, Decoder, DecoderHelpers};
+use rustc_serialize::{Encodable, EncoderHelpers};
 
 #[cfg(test)] use std::io::Cursor;
 #[cfg(test)] use syntax::parse;
@@ -445,7 +445,7 @@ fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>,
                                   rbml_w: &mut Encoder,
                                   autoderef: u32,
                                   method: &ty::MethodCallee<'tcx>) {
-    use serialize::Encoder;
+    use rustc_serialize::Encoder;
 
     rbml_w.emit_struct("MethodCallee", 4, |rbml_w| {
         rbml_w.emit_struct_field("autoderef", 0, |rbml_w| {
@@ -561,7 +561,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
     }
 
     fn emit_upvar_capture(&mut self, ecx: &e::EncodeContext, capture: &ty::UpvarCapture) {
-        use serialize::Encoder;
+        use rustc_serialize::Encoder;
 
         self.emit_enum("UpvarCapture", |this| {
             match *capture {
@@ -589,7 +589,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
 
     fn emit_auto_adjustment<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
                                 adj: &adjustment::AutoAdjustment<'tcx>) {
-        use serialize::Encoder;
+        use rustc_serialize::Encoder;
 
         self.emit_enum("AutoAdjustment", |this| {
             match *adj {
@@ -621,7 +621,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
 
     fn emit_autoref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
                         autoref: &adjustment::AutoRef<'tcx>) {
-        use serialize::Encoder;
+        use rustc_serialize::Encoder;
 
         self.emit_enum("AutoRef", |this| {
             match autoref {
@@ -643,7 +643,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
 
     fn emit_auto_deref_ref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
                                auto_deref_ref: &adjustment::AutoDerefRef<'tcx>) {
-        use serialize::Encoder;
+        use rustc_serialize::Encoder;
 
         self.emit_struct("AutoDerefRef", 2, |this| {
             this.emit_struct_field("autoderefs", 0, |this| auto_deref_ref.autoderefs.encode(this));
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 6a634d061fa..b5b27586a7f 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -17,6 +17,7 @@ use self::Family::*;
 use astencode::decode_inlined_item;
 use cstore::{self, crate_metadata};
 use common::*;
+use def_key;
 use encoder::def_to_u64;
 use index;
 use tls_context;
@@ -49,7 +50,7 @@ use std::str;
 
 use rbml::reader;
 use rbml;
-use serialize::Decodable;
+use rustc_serialize::Decodable;
 use syntax::attr;
 use syntax::parse::token::{self, IdentInterner};
 use syntax::ast;
@@ -1739,7 +1740,11 @@ pub fn def_key(cdata: Cmd, id: DefIndex) -> hir_map::DefKey {
     match reader::maybe_get_doc(item_doc, tag_def_key) {
         Some(def_key_doc) => {
             let mut decoder = reader::Decoder::new(def_key_doc);
-            hir_map::DefKey::decode(&mut decoder).unwrap()
+            let simple_key = def_key::DefKey::decode(&mut decoder).unwrap();
+            let name = reader::maybe_get_doc(item_doc, tag_paths_data_name).map(|name| {
+                token::intern(name.as_str_slice())
+            });
+            def_key::recover_def_key(simple_key, name)
         }
         None => {
             bug!("failed to find block with tag {:?} for item with family {:?}",
diff --git a/src/librustc_metadata/def_key.rs b/src/librustc_metadata/def_key.rs
new file mode 100644
index 00000000000..95fc932f8e1
--- /dev/null
+++ b/src/librustc_metadata/def_key.rs
@@ -0,0 +1,104 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use rustc::hir::def_id::DefIndex;
+use rustc::hir::map as hir_map;
+use syntax::ast::Name;
+
+#[derive(RustcEncodable, RustcDecodable)]
+pub struct DefKey {
+    pub parent: Option<DefIndex>,
+    pub disambiguated_data: DisambiguatedDefPathData,
+}
+
+#[derive(RustcEncodable, RustcDecodable)]
+pub struct DisambiguatedDefPathData {
+    pub data: DefPathData,
+    pub disambiguator: u32,
+}
+
+#[derive(RustcEncodable, RustcDecodable)]
+pub enum DefPathData {
+    CrateRoot,
+    Misc,
+    Impl,
+    TypeNs,
+    ValueNs,
+    MacroDef,
+    ClosureExpr,
+    TypeParam,
+    LifetimeDef,
+    EnumVariant,
+    Field,
+    StructCtor,
+    Initializer,
+    Binding,
+}
+
+pub fn simplify_def_key(key: hir_map::DefKey) -> DefKey {
+    let data = DisambiguatedDefPathData {
+        data: simplify_def_path_data(key.disambiguated_data.data),
+        disambiguator: key.disambiguated_data.disambiguator,
+    };
+    DefKey {
+        parent: key.parent,
+        disambiguated_data: data,
+    }
+}
+
+fn simplify_def_path_data(data: hir_map::DefPathData) -> DefPathData {
+    match data {
+        hir_map::DefPathData::CrateRoot => DefPathData::CrateRoot,
+        hir_map::DefPathData::InlinedRoot(_) => bug!("unexpected DefPathData"),
+        hir_map::DefPathData::Misc => DefPathData::Misc,
+        hir_map::DefPathData::Impl => DefPathData::Impl,
+        hir_map::DefPathData::TypeNs(_) => DefPathData::TypeNs,
+        hir_map::DefPathData::ValueNs(_) => DefPathData::ValueNs,
+        hir_map::DefPathData::MacroDef(_) => DefPathData::MacroDef,
+        hir_map::DefPathData::ClosureExpr => DefPathData::ClosureExpr,
+        hir_map::DefPathData::TypeParam(_) => DefPathData::TypeParam,
+        hir_map::DefPathData::LifetimeDef(_) => DefPathData::LifetimeDef,
+        hir_map::DefPathData::EnumVariant(_) => DefPathData::EnumVariant,
+        hir_map::DefPathData::Field(_) => DefPathData::Field,
+        hir_map::DefPathData::StructCtor => DefPathData::StructCtor,
+        hir_map::DefPathData::Initializer => DefPathData::Initializer,
+        hir_map::DefPathData::Binding(_) => DefPathData::Binding,
+    }
+}
+
+pub fn recover_def_key(key: DefKey, name: Option<Name>) -> hir_map::DefKey {
+    let data = hir_map::DisambiguatedDefPathData {
+        data: recover_def_path_data(key.disambiguated_data.data, name),
+        disambiguator: key.disambiguated_data.disambiguator,
+    };
+    hir_map::DefKey {
+        parent: key.parent,
+        disambiguated_data: data,
+    }
+}
+
+fn recover_def_path_data(data: DefPathData, name: Option<Name>) -> hir_map::DefPathData {
+    match data {
+        DefPathData::CrateRoot => hir_map::DefPathData::CrateRoot,
+        DefPathData::Misc => hir_map::DefPathData::Misc,
+        DefPathData::Impl => hir_map::DefPathData::Impl,
+        DefPathData::TypeNs => hir_map::DefPathData::TypeNs(name.unwrap()),
+        DefPathData::ValueNs => hir_map::DefPathData::ValueNs(name.unwrap()),
+        DefPathData::MacroDef => hir_map::DefPathData::MacroDef(name.unwrap()),
+        DefPathData::ClosureExpr => hir_map::DefPathData::ClosureExpr,
+        DefPathData::TypeParam => hir_map::DefPathData::TypeParam(name.unwrap()),
+        DefPathData::LifetimeDef => hir_map::DefPathData::LifetimeDef(name.unwrap()),
+        DefPathData::EnumVariant => hir_map::DefPathData::EnumVariant(name.unwrap()),
+        DefPathData::Field => hir_map::DefPathData::Field(name.unwrap()),
+        DefPathData::StructCtor => hir_map::DefPathData::StructCtor,
+        DefPathData::Initializer => hir_map::DefPathData::Initializer,
+        DefPathData::Binding => hir_map::DefPathData::Binding(name.unwrap()),
+    }
+}
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 69f61cf97c0..40a7f91154f 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -17,6 +17,7 @@ use astencode::encode_inlined_item;
 use common::*;
 use cstore;
 use decoder;
+use def_key;
 use tyencode;
 use index::{self, IndexData};
 
@@ -35,7 +36,7 @@ use rustc::mir::mir_map::MirMap;
 use rustc::session::config;
 use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
 
-use serialize::Encodable;
+use rustc_serialize::Encodable;
 use std::cell::RefCell;
 use std::io::prelude::*;
 use std::io::{Cursor, SeekFrom};
@@ -53,6 +54,7 @@ use rbml::writer::Encoder;
 use rustc::hir::{self, PatKind};
 use rustc::hir::intravisit::Visitor;
 use rustc::hir::intravisit;
+use rustc::hir::map::DefKey;
 
 pub struct EncodeContext<'a, 'tcx: 'a> {
     pub diag: &'a Handler,
@@ -101,6 +103,13 @@ fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
     rbml_w.wr_tagged_u64(tag_def_id, def_to_u64(id));
 }
 
+fn encode_def_key(rbml_w: &mut Encoder, key: DefKey) {
+    let simple_key = def_key::simplify_def_key(key);
+    rbml_w.start_tag(tag_def_key);
+    simple_key.encode(rbml_w);
+    rbml_w.end_tag();
+}
+
 /// For every DefId that we create a metadata item for, we include a
 /// serialized copy of its DefKey, which allows us to recreate a path.
 fn encode_def_id_and_key(ecx: &EncodeContext,
@@ -108,17 +117,8 @@ fn encode_def_id_and_key(ecx: &EncodeContext,
                          def_id: DefId)
 {
     encode_def_id(rbml_w, def_id);
-    encode_def_key(ecx, rbml_w, def_id);
-}
-
-fn encode_def_key(ecx: &EncodeContext,
-                  rbml_w: &mut Encoder,
-                  def_id: DefId)
-{
-    rbml_w.start_tag(tag_def_key);
     let def_key = ecx.tcx.map.def_key(def_id);
-    def_key.encode(rbml_w);
-    rbml_w.end_tag();
+    encode_def_key(rbml_w, def_key);
 }
 
 fn encode_trait_ref<'a, 'tcx>(rbml_w: &mut Encoder,
diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs
index 139462d41bf..f7ea60c4078 100644
--- a/src/librustc_metadata/lib.rs
+++ b/src/librustc_metadata/lib.rs
@@ -31,7 +31,7 @@
 
 extern crate flate;
 extern crate rbml;
-extern crate serialize;
+extern crate serialize as rustc_serialize; // used by deriving
 
 #[macro_use]
 extern crate rustc;
@@ -48,6 +48,7 @@ pub mod diagnostics;
 
 pub mod astencode;
 pub mod common;
+pub mod def_key;
 pub mod tyencode;
 pub mod tydecode;
 pub mod encoder;