From 32690b586d6bbe2541ec94adbdc7c226978332c5 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 14 Jan 2015 22:24:09 +1300 Subject: [PATCH] Tweek save-analysis treatment of impls --- src/librustc_trans/save/mod.rs | 33 +++++++++++++++++------------ src/librustc_trans/save/recorder.rs | 18 +++++++++++++--- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 1bd8e0181748..2cfe7940bbb5 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -392,8 +392,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { } fn process_trait_ref(&mut self, - trait_ref: &ast::TraitRef, - impl_id: Option) { + trait_ref: &ast::TraitRef) { match self.lookup_type_ref(trait_ref.ref_id) { Some(id) => { let sub_span = self.span.sub_span_for_type_name(trait_ref.path.span); @@ -402,14 +401,6 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { sub_span, id, self.cur_scope); - match impl_id { - Some(impl_id) => self.fmt.impl_str(trait_ref.path.span, - sub_span, - impl_id, - id, - self.cur_scope), - None => (), - } visit::walk_path(self, &trait_ref.path); }, None => () @@ -652,7 +643,9 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { trait_ref: &Option, typ: &ast::Ty, impl_items: &Vec) { + let trait_id = trait_ref.as_ref().and_then(|tr| self.lookup_type_ref(tr.ref_id)); match typ.node { + // Common case impl for a struct or something basic. ast::TyPath(ref path, id) => { match self.lookup_type_ref(id) { Some(id) => { @@ -665,17 +658,29 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.fmt.impl_str(path.span, sub_span, item.id, - id, + Some(id), + trait_id, self.cur_scope); }, None => () } }, - _ => self.visit_ty(&*typ), + _ => { + // Less useful case, impl for a compound type. + self.visit_ty(&*typ); + + let sub_span = self.span.sub_span_for_type_name(typ.span); + self.fmt.impl_str(typ.span, + sub_span, + item.id, + None, + trait_id, + self.cur_scope); + } } match *trait_ref { - Some(ref trait_ref) => self.process_trait_ref(trait_ref, Some(item.id)), + Some(ref trait_ref) => self.process_trait_ref(trait_ref), None => (), } @@ -1076,7 +1081,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { for param in generics.ty_params.iter() { for bound in param.bounds.iter() { if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { - self.process_trait_ref(&trait_ref.trait_ref, None); + self.process_trait_ref(&trait_ref.trait_ref); } } if let Some(ref ty) = param.default { diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 23598751c08d..5cd3b9f20b62 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -19,6 +19,8 @@ use syntax::ast; use syntax::ast::{NodeId,DefId}; use syntax::codemap::*; +const ZERO_DEF_ID: DefId = DefId { node: 0, krate: 0 }; + pub struct Recorder { // output file pub out: Box, @@ -121,7 +123,9 @@ impl<'a> FmtStrs<'a> { MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true), Struct => ("struct", vec!("id","ctor_id","qualname","scopeid","value"), true, true), Trait => ("trait", vec!("id","qualname","scopeid","value"), true, true), - Impl => ("impl", vec!("id","refid","refidcrate","scopeid"), true, true), + Impl => ("impl", + vec!("id","refid","refidcrate","traitid","traitidcrate","scopeid"), + true, true), Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false), UseAlias => ("use_alias", vec!("id","refid","refidcrate","name","scopeid"), @@ -444,12 +448,20 @@ impl<'a> FmtStrs<'a> { span: Span, sub_span: Option, id: NodeId, - ref_id: DefId, + ref_id: Option, + trait_id: Option, scope_id: NodeId) { + let ref_id = ref_id.unwrap_or(ZERO_DEF_ID); + let trait_id = trait_id.unwrap_or(ZERO_DEF_ID); self.check_and_record(Impl, span, sub_span, - svec!(id, ref_id.node, ref_id.krate, scope_id)); + svec!(id, + ref_id.node, + ref_id.krate, + trait_id.node, + trait_id.krate, + scope_id)); } pub fn mod_str(&mut self,