Auto merge of #39781 - nrc:save-impls, r=nikomatsakis

save-analysis: emit info about impls and super-traits in JSON
This commit is contained in:
bors 2017-02-15 13:48:09 +00:00
commit 62eb6056d3
4 changed files with 97 additions and 20 deletions

View File

@ -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));
}

View File

@ -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![],
}
@ -427,6 +438,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,

View File

@ -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![],
}
}
}
@ -508,6 +515,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,

View File

@ -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 {