Skip to content

Commit 65ad759

Browse files
authored
Rollup merge of rust-lang#39781 - nrc:save-impls, r=nikomatsakis
save-analysis: emit info about impls and super-traits in JSON
2 parents 3d64480 + 530d09c commit 65ad759

File tree

4 files changed

+97
-20
lines changed

4 files changed

+97
-20
lines changed

src/librustc_save_analysis/dump_visitor.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -747,21 +747,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
747747
trait_ref: &'l Option<ast::TraitRef>,
748748
typ: &'l ast::Ty,
749749
impl_items: &'l [ast::ImplItem]) {
750-
let mut has_self_ref = false;
751750
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
752751
down_cast_data!(impl_data, ImplData, item.span);
753-
if let Some(ref self_ref) = impl_data.self_ref {
754-
has_self_ref = true;
755-
if !self.span.filter_generated(Some(self_ref.span), item.span) {
756-
self.dumper.type_ref(self_ref.clone().lower(self.tcx));
757-
}
758-
}
759-
if let Some(ref trait_ref_data) = impl_data.trait_ref {
760-
if !self.span.filter_generated(Some(trait_ref_data.span), item.span) {
761-
self.dumper.type_ref(trait_ref_data.clone().lower(self.tcx));
762-
}
763-
}
764-
765752
if !self.span.filter_generated(Some(impl_data.span), item.span) {
766753
self.dumper.impl_data(ImplData {
767754
id: impl_data.id,
@@ -772,9 +759,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
772759
}.lower(self.tcx));
773760
}
774761
}
775-
if !has_self_ref {
776-
self.visit_ty(&typ);
777-
}
762+
self.visit_ty(&typ);
778763
if let &Some(ref trait_ref) = trait_ref {
779764
self.process_path(trait_ref.ref_id, &trait_ref.path, Some(recorder::TypeRef));
780765
}

src/librustc_save_analysis/json_api_dumper.rs

+47
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> {
7474
impl_fn!(mod_data, ModData, defs);
7575
impl_fn!(typedef, TypeDefData, defs);
7676
impl_fn!(variable, VariableData, defs);
77+
78+
fn impl_data(&mut self, data: ImplData) {
79+
if data.self_ref.is_some() {
80+
self.result.relations.push(From::from(data));
81+
}
82+
}
83+
fn inheritance(&mut self, data: InheritanceData) {
84+
self.result.relations.push(From::from(data));
85+
}
7786
}
7887

7988
// FIXME methods. The defs have information about possible overriding and the
@@ -87,6 +96,7 @@ struct Analysis {
8796
prelude: Option<CratePreludeData>,
8897
imports: Vec<Import>,
8998
defs: Vec<Def>,
99+
relations: Vec<Relation>,
90100
// These two fields are dummies so that clients can parse the two kinds of
91101
// JSON data in the same way.
92102
refs: Vec<()>,
@@ -100,6 +110,7 @@ impl Analysis {
100110
prelude: None,
101111
imports: vec![],
102112
defs: vec![],
113+
relations: vec![],
103114
refs: vec![],
104115
macro_refs: vec![],
105116
}
@@ -427,6 +438,42 @@ impl From<VariableData> for Option<Def> {
427438
}
428439
}
429440

441+
#[derive(Debug, RustcEncodable)]
442+
struct Relation {
443+
span: SpanData,
444+
kind: RelationKind,
445+
from: Id,
446+
to: Id,
447+
}
448+
449+
#[derive(Debug, RustcEncodable)]
450+
enum RelationKind {
451+
Impl,
452+
SuperTrait,
453+
}
454+
455+
impl From<ImplData> for Relation {
456+
fn from(data: ImplData) -> Relation {
457+
Relation {
458+
span: data.span,
459+
kind: RelationKind::Impl,
460+
from: From::from(data.self_ref.unwrap_or(null_def_id())),
461+
to: From::from(data.trait_ref.unwrap_or(null_def_id())),
462+
}
463+
}
464+
}
465+
466+
impl From<InheritanceData> for Relation {
467+
fn from(data: InheritanceData) -> Relation {
468+
Relation {
469+
span: data.span,
470+
kind: RelationKind::SuperTrait,
471+
from: From::from(data.base_id),
472+
to: From::from(data.deriv_id),
473+
}
474+
}
475+
}
476+
430477
#[derive(Debug, RustcEncodable)]
431478
pub struct JsonSignature {
432479
span: SpanData,

src/librustc_save_analysis/json_dumper.rs

+46-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> {
112112
self.result.defs.push(def);
113113
}
114114

115-
// FIXME store this instead of throwing it away.
116-
fn impl_data(&mut self, _data: ImplData) {}
117-
fn inheritance(&mut self, _data: InheritanceData) {}
115+
fn impl_data(&mut self, data: ImplData) {
116+
if data.self_ref.is_some() {
117+
self.result.relations.push(From::from(data));
118+
}
119+
}
120+
fn inheritance(&mut self, data: InheritanceData) {
121+
self.result.relations.push(From::from(data));
122+
}
118123
}
119124

120125
// FIXME do we want to change ExternalData to this mode? It will break DXR.
@@ -131,6 +136,7 @@ struct Analysis {
131136
defs: Vec<Def>,
132137
refs: Vec<Ref>,
133138
macro_refs: Vec<MacroRef>,
139+
relations: Vec<Relation>,
134140
}
135141

136142
impl Analysis {
@@ -142,6 +148,7 @@ impl Analysis {
142148
defs: vec![],
143149
refs: vec![],
144150
macro_refs: vec![],
151+
relations: vec![],
145152
}
146153
}
147154
}
@@ -508,6 +515,42 @@ impl From<MacroUseData> for MacroRef {
508515
}
509516
}
510517

518+
#[derive(Debug, RustcEncodable)]
519+
struct Relation {
520+
span: SpanData,
521+
kind: RelationKind,
522+
from: Id,
523+
to: Id,
524+
}
525+
526+
#[derive(Debug, RustcEncodable)]
527+
enum RelationKind {
528+
Impl,
529+
SuperTrait,
530+
}
531+
532+
impl From<ImplData> for Relation {
533+
fn from(data: ImplData) -> Relation {
534+
Relation {
535+
span: data.span,
536+
kind: RelationKind::Impl,
537+
from: From::from(data.self_ref.unwrap_or(null_def_id())),
538+
to: From::from(data.trait_ref.unwrap_or(null_def_id())),
539+
}
540+
}
541+
}
542+
543+
impl From<InheritanceData> for Relation {
544+
fn from(data: InheritanceData) -> Relation {
545+
Relation {
546+
span: data.span,
547+
kind: RelationKind::SuperTrait,
548+
from: From::from(data.base_id),
549+
to: From::from(data.deriv_id),
550+
}
551+
}
552+
}
553+
511554
#[derive(Debug, RustcEncodable)]
512555
pub struct JsonSignature {
513556
span: SpanData,

src/librustc_save_analysis/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
239239
match typ.node {
240240
// Common case impl for a struct or something basic.
241241
ast::TyKind::Path(None, ref path) => {
242-
filter!(self.span_utils, None, path.span, None);
242+
if generated_code(path.span) {
243+
return None;
244+
}
243245
sub_span = self.span_utils.sub_span_for_type_name(path.span);
244246
type_data = self.lookup_ref_id(typ.id).map(|id| {
245247
TypeRefData {

0 commit comments

Comments
 (0)