]> git.lizzy.rs Git - rust.git/commitdiff
save-analysis: emit info about impls and super-traits in JSON
authorNick Cameron <ncameron@mozilla.com>
Mon, 13 Feb 2017 04:50:58 +0000 (17:50 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 13 Feb 2017 04:50:58 +0000 (17:50 +1300)
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/json_api_dumper.rs
src/librustc_save_analysis/json_dumper.rs
src/librustc_save_analysis/lib.rs

index 41f91a1d2acc17ac234f00824cd88655868bde26..292f1eb13663b9b36a330a614b4e0fabc111b006 100644 (file)
@@ -747,21 +747,8 @@ fn process_impl(&mut self,
                     trait_ref: &'l Option<ast::TraitRef>,
                     typ: &'l ast::Ty,
                     impl_items: &'l [ast::ImplItem]) {
-        let mut has_self_ref = false;
         if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
             down_cast_data!(impl_data, ImplData, item.span);
-            if let Some(ref self_ref) = impl_data.self_ref {
-                has_self_ref = true;
-                if !self.span.filter_generated(Some(self_ref.span), item.span) {
-                    self.dumper.type_ref(self_ref.clone().lower(self.tcx));
-                }
-            }
-            if let Some(ref trait_ref_data) = impl_data.trait_ref {
-                if !self.span.filter_generated(Some(trait_ref_data.span), item.span) {
-                    self.dumper.type_ref(trait_ref_data.clone().lower(self.tcx));
-                }
-            }
-
             if !self.span.filter_generated(Some(impl_data.span), item.span) {
                 self.dumper.impl_data(ImplData {
                     id: impl_data.id,
@@ -772,9 +759,7 @@ fn process_impl(&mut self,
                 }.lower(self.tcx));
             }
         }
-        if !has_self_ref {
-            self.visit_ty(&typ);
-        }
+        self.visit_ty(&typ);
         if let &Some(ref trait_ref) = trait_ref {
             self.process_path(trait_ref.ref_id, &trait_ref.path, Some(recorder::TypeRef));
         }
index 342c33af2f8963854b65a15e5a60e6c0e76c78a9..277535f9e651373318c162830e7c3889a2451bf7 100644 (file)
@@ -74,6 +74,15 @@ fn crate_prelude(&mut self, data: CratePreludeData) {
     impl_fn!(mod_data, ModData, defs);
     impl_fn!(typedef, TypeDefData, defs);
     impl_fn!(variable, VariableData, defs);
+
+    fn impl_data(&mut self, data: ImplData) {
+        if data.self_ref.is_some() {
+            self.result.relations.push(From::from(data));
+        }
+    }
+    fn inheritance(&mut self, data: InheritanceData) {
+        self.result.relations.push(From::from(data));
+    }
 }
 
 // FIXME methods. The defs have information about possible overriding and the
@@ -87,6 +96,7 @@ struct Analysis {
     prelude: Option<CratePreludeData>,
     imports: Vec<Import>,
     defs: Vec<Def>,
+    relations: Vec<Relation>,
     // These two fields are dummies so that clients can parse the two kinds of
     // JSON data in the same way.
     refs: Vec<()>,
@@ -100,6 +110,7 @@ fn new() -> Analysis {
             prelude: None,
             imports: vec![],
             defs: vec![],
+            relations: vec![],
             refs: vec![],
             macro_refs: vec![],
         }
@@ -427,6 +438,42 @@ fn from(data: VariableData) -> Option<Def> {
     }
 }
 
+#[derive(Debug, RustcEncodable)]
+struct Relation {
+    span: SpanData,
+    kind: RelationKind,
+    from: Id,
+    to: Id,
+}
+
+#[derive(Debug, RustcEncodable)]
+enum RelationKind {
+    Impl,
+    SuperTrait,
+}
+
+impl From<ImplData> for Relation {
+    fn from(data: ImplData) -> Relation {
+        Relation {
+            span: data.span,
+            kind: RelationKind::Impl,
+            from: From::from(data.self_ref.unwrap_or(null_def_id())),
+            to: From::from(data.trait_ref.unwrap_or(null_def_id())),
+        }
+    }
+}
+
+impl From<InheritanceData> for Relation {
+    fn from(data: InheritanceData) -> Relation {
+        Relation {
+            span: data.span,
+            kind: RelationKind::SuperTrait,
+            from: From::from(data.base_id),
+            to: From::from(data.deriv_id),
+        }
+    }
+}
+
 #[derive(Debug, RustcEncodable)]
 pub struct JsonSignature {
     span: SpanData,
index 16c06a556df0e74932559e5e2dddbe1140a78bb9..09752994290c9c3490ec0ec4f1a4397c98740992 100644 (file)
@@ -112,9 +112,14 @@ fn mod_data(&mut self, data: ModData) {
         self.result.defs.push(def);
     }
 
-    // FIXME store this instead of throwing it away.
-    fn impl_data(&mut self, _data: ImplData) {}
-    fn inheritance(&mut self, _data: InheritanceData) {}
+    fn impl_data(&mut self, data: ImplData) {
+        if data.self_ref.is_some() {
+            self.result.relations.push(From::from(data));
+        }
+    }
+    fn inheritance(&mut self, data: InheritanceData) {
+        self.result.relations.push(From::from(data));
+    }
 }
 
 // FIXME do we want to change ExternalData to this mode? It will break DXR.
@@ -131,6 +136,7 @@ struct Analysis {
     defs: Vec<Def>,
     refs: Vec<Ref>,
     macro_refs: Vec<MacroRef>,
+    relations: Vec<Relation>,
 }
 
 impl Analysis {
@@ -142,6 +148,7 @@ fn new() -> Analysis {
             defs: vec![],
             refs: vec![],
             macro_refs: vec![],
+            relations: vec![],
         }
     }
 }
@@ -508,6 +515,42 @@ fn from(data: MacroUseData) -> MacroRef {
     }
 }
 
+#[derive(Debug, RustcEncodable)]
+struct Relation {
+    span: SpanData,
+    kind: RelationKind,
+    from: Id,
+    to: Id,
+}
+
+#[derive(Debug, RustcEncodable)]
+enum RelationKind {
+    Impl,
+    SuperTrait,
+}
+
+impl From<ImplData> for Relation {
+    fn from(data: ImplData) -> Relation {
+        Relation {
+            span: data.span,
+            kind: RelationKind::Impl,
+            from: From::from(data.self_ref.unwrap_or(null_def_id())),
+            to: From::from(data.trait_ref.unwrap_or(null_def_id())),
+        }
+    }
+}
+
+impl From<InheritanceData> for Relation {
+    fn from(data: InheritanceData) -> Relation {
+        Relation {
+            span: data.span,
+            kind: RelationKind::SuperTrait,
+            from: From::from(data.base_id),
+            to: From::from(data.deriv_id),
+        }
+    }
+}
+
 #[derive(Debug, RustcEncodable)]
 pub struct JsonSignature {
     span: SpanData,
index ebb33a12c870397fe2dbd2331cb95de79cd0f67d..ddc60fe5f81d85bfd054e2b94c2dfbe9914e1074 100644 (file)
@@ -239,7 +239,9 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
                 match typ.node {
                     // Common case impl for a struct or something basic.
                     ast::TyKind::Path(None, ref path) => {
-                        filter!(self.span_utils, None, path.span, None);
+                        if generated_code(path.span) {
+                            return None;
+                        }
                         sub_span = self.span_utils.sub_span_for_type_name(path.span);
                         type_data = self.lookup_ref_id(typ.id).map(|id| {
                             TypeRefData {