Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit data::Impl in save-analysis #47657

Merged
merged 1 commit into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.14"
rls-data = "0.15"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
8 changes: 6 additions & 2 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
impl_items: &'l [ast::ImplItem],
) {
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
down_cast_data!(impl_data, RelationData, item.span);
self.dumper.dump_relation(impl_data);
if let super::Data::RelationData(rel, imp) = impl_data {
self.dumper.dump_relation(rel);
self.dumper.dump_impl(imp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the cast macro rather than if let here is preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrc but the cast macro is written for super::Data enclosing one value. Since this is the only data emitting two values, I though it cleaner make this an exeption rather than changing the macro to handle a tuple as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

} else {
span_bug!(item.span, "unexpected data kind: {:?}", impl_data);
}
}
self.visit_ty(&typ);
if let &Some(ref trait_ref) = trait_ref {
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_save_analysis/json_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::io::Write;
use rustc_serialize::json::as_json;

use rls_data::{self, Analysis, CratePreludeData, Def, DefKind, Import, MacroRef, Ref, RefKind,
Relation};
Relation, Impl};
use rls_data::config::Config;
use rls_span::{Column, Row};

Expand Down Expand Up @@ -142,4 +142,8 @@ impl<'b, O: DumpOutput + 'b> JsonDumper<O> {
pub fn dump_relation(&mut self, data: Relation) {
self.result.relations.push(data);
}

pub fn dump_impl(&mut self, data: Impl) {
self.result.impls.push(data);
}
}
41 changes: 36 additions & 5 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use rustc::session::config::CrateType::CrateTypeExecutable;
use rustc::ty::{self, TyCtxt};
use rustc_typeck::hir_ty_to_ty;

use std::cell::Cell;
use std::default::Default;
use std::env;
use std::fs::File;
Expand All @@ -65,7 +66,7 @@ use dump_visitor::DumpVisitor;
use span_utils::SpanUtils;

use rls_data::{Def, DefKind, ExternalCrateData, GlobalCrateId, MacroRef, Ref, RefKind, Relation,
RelationKind, SpanData};
RelationKind, SpanData, Impl, ImplKind};
use rls_data::config::Config;


Expand All @@ -75,13 +76,14 @@ pub struct SaveContext<'l, 'tcx: 'l> {
analysis: &'l ty::CrateAnalysis,
span_utils: SpanUtils<'tcx>,
config: Config,
impl_counter: Cell<u32>,
}

#[derive(Debug)]
pub enum Data {
RefData(Ref),
DefData(Def),
RelationData(Relation),
RelationData(Relation, Impl),
}

impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
Expand Down Expand Up @@ -315,7 +317,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
attributes: lower_attributes(item.attrs.to_owned(), self),
}))
}
ast::ItemKind::Impl(.., ref trait_ref, ref typ, _) => {
ast::ItemKind::Impl(.., ref trait_ref, ref typ, ref impls) => {
if let ast::TyKind::Path(None, ref path) = typ.node {
// Common case impl for a struct or something basic.
if generated_code(path.span) {
Expand All @@ -324,17 +326,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let sub_span = self.span_utils.sub_span_for_type_name(path.span);
filter!(self.span_utils, sub_span, typ.span, None);

let impl_id = self.next_impl_id();
let span = self.span_from_span(sub_span.unwrap());

let type_data = self.lookup_ref_id(typ.id);
type_data.map(|type_data| {
Data::RelationData(Relation {
kind: RelationKind::Impl,
span: self.span_from_span(sub_span.unwrap()),
kind: RelationKind::Impl {
id: impl_id,
},
span: span.clone(),
from: id_from_def_id(type_data),
to: trait_ref
.as_ref()
.and_then(|t| self.lookup_ref_id(t.ref_id))
.map(id_from_def_id)
.unwrap_or(null_id()),
},
Impl {
id: impl_id,
kind: match *trait_ref {
Some(_) => ImplKind::Direct,
None => ImplKind::Inherent,
},
span: span,
value: String::new(),
parent: None,
children: impls
.iter()
.map(|i| id_from_node_id(i.id, self))
.collect(),
docs: String::new(),
sig: None,
attributes: vec![],
})
})
} else {
Expand Down Expand Up @@ -893,6 +917,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {

result
}

fn next_impl_id(&self) -> u32 {
let next = self.impl_counter.get();
self.impl_counter.set(next + 1);
next
}
}

fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
Expand Down Expand Up @@ -1099,6 +1129,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
analysis,
span_utils: SpanUtils::new(&tcx.sess),
config: find_config(config),
impl_counter: Cell::new(0),
};

handler.save(save_ctxt, krate, cratename)
Expand Down