diff options
| author | bors <bors@rust-lang.org> | 2017-02-15 13:48:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-02-15 13:48:09 +0000 |
| commit | 62eb6056d332be09206dc664f2e949ae64341e64 (patch) | |
| tree | 0db817c037c3cbb38c6fcdb573abcdbfcacae9ec | |
| parent | e0044bd3896456afb346d06e91a97ac515930ccf (diff) | |
| parent | 530d09c5d6782d4329b21661a2adacdc11806082 (diff) | |
Auto merge of #39781 - nrc:save-impls, r=nikomatsakis
save-analysis: emit info about impls and super-traits in JSON
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 17 | ||||
| -rw-r--r-- | src/librustc_save_analysis/json_api_dumper.rs | 47 | ||||
| -rw-r--r-- | src/librustc_save_analysis/json_dumper.rs | 49 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 4 |
4 files changed, 97 insertions, 20 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 41f91a1d2ac..292f1eb1366 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -747,21 +747,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { 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 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { }.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)); } diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index 342c33af2f8..277535f9e65 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -74,6 +74,15 @@ impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> { 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 @@ impl Analysis { prelude: None, imports: vec![], defs: vec![], + relations: vec![], refs: vec![], macro_refs: vec![], } @@ -428,6 +439,42 @@ impl From<VariableData> for 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, text: String, diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 16c06a556df..09752994290 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -112,9 +112,14 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> { 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 @@ impl Analysis { defs: vec![], refs: vec![], macro_refs: vec![], + relations: vec![], } } } @@ -509,6 +516,42 @@ impl From<MacroUseData> for 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, text: String, diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index ebb33a12c87..ddc60fe5f81 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -239,7 +239,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { 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 { |
