Skip to content

Commit

Permalink
Rollup merge of rust-lang#58233 - taiki-e:librustc_save_analysis-2018…
Browse files Browse the repository at this point in the history
…, r=Centril

librustc_save_analysis => 2018

Transitions `librustc_save_analysis` to Rust 2018; cc rust-lang#58099

r? @Centril
  • Loading branch information
Centril authored Feb 8, 2019
2 parents 5b4cf9b + ba0fbd7 commit 2b8ed1e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 82 deletions.
1 change: 1 addition & 0 deletions src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_save_analysis"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_save_analysis"
Expand Down
73 changes: 39 additions & 34 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use rustc::hir::def::Def as HirDef;
use rustc::hir::def_id::DefId;
use rustc::session::config::Input;
use rustc::span_bug;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashSet;

Expand All @@ -32,16 +33,20 @@ use syntax::print::pprust::{
};
use syntax::ptr::P;
use syntax::source_map::{Spanned, DUMMY_SP, respan};
use syntax::walk_list;
use syntax_pos::*;

use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
use json_dumper::{Access, DumpOutput, JsonDumper};
use span_utils::SpanUtils;
use sig;
use crate::{escape, generated_code, id_from_def_id, id_from_node_id, lower_attributes,
PathCollector, SaveContext};
use crate::json_dumper::{Access, DumpOutput, JsonDumper};
use crate::span_utils::SpanUtils;
use crate::sig;

use rls_data::{CompilationOptions, CratePreludeData, Def, DefKind, GlobalCrateId, Import,
ImportKind, Ref, RefKind, Relation, RelationKind, SpanData};

use log::{debug, error};

macro_rules! down_cast_data {
($id:ident, $kind:ident, $sp:expr) => {
let $id = if let super::Data::$kind(data) = $id {
Expand All @@ -68,7 +73,7 @@ macro_rules! access_from {
};
}

pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput> {
save_ctxt: SaveContext<'l, 'tcx>,
tcx: TyCtxt<'l, 'tcx, 'tcx>,
dumper: &'ll mut JsonDumper<O>,
Expand Down Expand Up @@ -245,7 +250,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
None => continue,
};
if !self.span.filter_generated(ident.span) {
let id = ::id_from_node_id(id, &self.save_ctxt);
let id = id_from_node_id(id, &self.save_ctxt);
let span = self.span_from_span(ident.span);

self.dumper.dump_def(
Expand Down Expand Up @@ -286,7 +291,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
debug!("process_method: {}:{}", id, ident);

if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident, span) {
let sig_str = ::make_signature(&sig.decl, &generics);
let sig_str = crate::make_signature(&sig.decl, &generics);
if body.is_some() {
self.nest_tables(
id,
Expand Down Expand Up @@ -339,7 +344,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// Append $id to name to make sure each one is unique.
let qualname = format!("{}::{}${}", prefix, name, id);
if !self.span.filter_generated(param_ss) {
let id = ::id_from_node_id(param.id, &self.save_ctxt);
let id = id_from_node_id(param.id, &self.save_ctxt);
let span = self.span_from_span(param_ss);

self.dumper.dump_def(
Expand Down Expand Up @@ -434,12 +439,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
&access_from!(self.save_ctxt, vis, id),
Def {
kind: DefKind::Const,
id: ::id_from_node_id(id, &self.save_ctxt),
id: id_from_node_id(id, &self.save_ctxt),
span,
name: ident.name.to_string(),
qualname,
value: ty_to_string(&typ),
parent: Some(::id_from_def_id(parent_id)),
parent: Some(id_from_def_id(parent_id)),
children: vec![],
decl_id: None,
docs: self.save_ctxt.docs_for_attrs(attrs),
Expand Down Expand Up @@ -496,7 +501,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
value,
fields
.iter()
.map(|f| ::id_from_node_id(f.id, &self.save_ctxt))
.map(|f| id_from_node_id(f.id, &self.save_ctxt))
.collect(),
)
}
Expand All @@ -509,7 +514,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
&access_from!(self.save_ctxt, item),
Def {
kind,
id: ::id_from_node_id(item.id, &self.save_ctxt),
id: id_from_node_id(item.id, &self.save_ctxt),
span,
name,
qualname: qualname.clone(),
Expand Down Expand Up @@ -565,8 +570,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt);
let parent = Some(id_from_node_id(item.id, &self.save_ctxt));

self.dumper.dump_def(
&access,
Expand Down Expand Up @@ -603,8 +608,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
}
if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span);
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt);
let parent = Some(id_from_node_id(item.id, &self.save_ctxt));

self.dumper.dump_def(
&access,
Expand Down Expand Up @@ -687,11 +692,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
val.push_str(&bounds_to_string(trait_refs));
}
if !self.span.filter_generated(item.ident.span) {
let id = ::id_from_node_id(item.id, &self.save_ctxt);
let id = id_from_node_id(item.id, &self.save_ctxt);
let span = self.span_from_span(item.ident.span);
let children = methods
.iter()
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
.collect();
self.dumper.dump_def(
&access_from!(self.save_ctxt, item),
Expand Down Expand Up @@ -727,14 +732,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
self.dumper.dump_ref(Ref {
kind: RefKind::Type,
span: span.clone(),
ref_id: ::id_from_def_id(id),
ref_id: id_from_def_id(id),
});

self.dumper.dump_relation(Relation {
kind: RelationKind::SuperTrait,
span,
from: ::id_from_def_id(id),
to: ::id_from_node_id(item.id, &self.save_ctxt),
from: id_from_def_id(id),
to: id_from_node_id(item.id, &self.save_ctxt),
});
}
}
Expand Down Expand Up @@ -874,7 +879,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
self.dumper.dump_ref(Ref {
kind: RefKind::Variable,
span,
ref_id: ::id_from_def_id(variant.fields[index].did),
ref_id: id_from_def_id(variant.fields[index].did),
});
}
}
Expand Down Expand Up @@ -913,7 +918,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {

if !self.span.filter_generated(ident.span) {
let qualname = format!("{}${}", ident.to_string(), id);
let id = ::id_from_node_id(id, &self.save_ctxt);
let id = id_from_node_id(id, &self.save_ctxt);
let span = self.span_from_span(ident.span);

self.dumper.dump_def(
Expand Down Expand Up @@ -989,7 +994,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// Rust uses the id of the pattern for var lookups, so we'll use it too.
if !self.span.filter_generated(ident.span) {
let qualname = format!("{}${}", ident.to_string(), id);
let id = ::id_from_node_id(id, &self.save_ctxt);
let id = id_from_node_id(id, &self.save_ctxt);
let span = self.span_from_span(ident.span);

self.dumper.dump_def(
Expand Down Expand Up @@ -1092,7 +1097,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {

if !self.span.filter_generated(trait_item.ident.span) {
let span = self.span_from_span(trait_item.ident.span);
let id = ::id_from_node_id(trait_item.id, &self.save_ctxt);
let id = id_from_node_id(trait_item.id, &self.save_ctxt);

self.dumper.dump_def(
&Access {
Expand All @@ -1106,7 +1111,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
name,
qualname,
value: self.span.snippet(trait_item.span),
parent: Some(::id_from_def_id(trait_id)),
parent: Some(id_from_def_id(trait_id)),
children: vec![],
decl_id: None,
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
Expand Down Expand Up @@ -1197,7 +1202,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// The parent def id of a given use tree is always the enclosing item.
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id)
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
.map(::id_from_def_id);
.map(id_from_def_id);

match use_tree.kind {
ast::UseTreeKind::Simple(alias, ..) => {
Expand All @@ -1213,7 +1218,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {

let sub_span = path.segments.last().unwrap().ident.span;
if !self.span.filter_generated(sub_span) {
let ref_id = self.lookup_def_id(id).map(|id| ::id_from_def_id(id));
let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id));
let alias_span = alias.map(|i| self.span_from_span(i.span));
let span = self.span_from_span(sub_span);
self.dumper.import(&access, Import {
Expand Down Expand Up @@ -1299,10 +1304,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc

let cm = self.tcx.sess.source_map();
let filename = cm.span_to_filename(span);
let data_id = ::id_from_node_id(id, &self.save_ctxt);
let data_id = id_from_node_id(id, &self.save_ctxt);
let children = m.items
.iter()
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
.collect();
let span = self.span_from_span(span);

Expand Down Expand Up @@ -1346,7 +1351,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
let span = self.span_from_span(name_span);
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(item.id)
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
.map(::id_from_def_id);
.map(id_from_def_id);
self.dumper.import(
&Access {
public: false,
Expand Down Expand Up @@ -1388,7 +1393,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
let value = ty_to_string(&ty);
if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
let id = ::id_from_node_id(item.id, &self.save_ctxt);
let id = id_from_node_id(item.id, &self.save_ctxt);

self.dumper.dump_def(
&access_from!(self.save_ctxt, item),
Expand Down Expand Up @@ -1418,7 +1423,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
let value = String::new();
if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
let id = ::id_from_node_id(item.id, &self.save_ctxt);
let id = id_from_node_id(item.id, &self.save_ctxt);

self.dumper.dump_def(
&access_from!(self.save_ctxt, item),
Expand Down Expand Up @@ -1484,7 +1489,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
self.dumper.dump_ref(Ref {
kind: RefKind::Type,
span,
ref_id: ::id_from_def_id(id),
ref_id: id_from_def_id(id),
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_save_analysis/json_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKin
MacroRef, Ref, RefKind, Relation};
use rls_span::{Column, Row};

use log::error;

#[derive(Debug)]
pub struct Access {
pub reachable: bool,
Expand All @@ -23,7 +25,7 @@ pub trait DumpOutput {
fn dump(&mut self, result: &Analysis);
}

pub struct WriteOutput<'b, W: Write + 'b> {
pub struct WriteOutput<'b, W: Write> {
output: &'b mut W,
}

Expand Down
30 changes: 8 additions & 22 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(custom_attribute)]
#![feature(nll)]
#![deny(rust_2018_idioms)]
#![allow(unused_attributes)]

#![recursion_limit="256"]

#[macro_use]
extern crate rustc;

#[macro_use]
extern crate log;
extern crate rustc_data_structures;
extern crate rustc_codegen_utils;
extern crate rustc_serialize;
extern crate rustc_target;
extern crate rustc_typeck;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;

extern crate rls_data;
extern crate rls_span;


mod json_dumper;
mod dump_visitor;
Expand All @@ -37,6 +20,7 @@ use rustc::middle::privacy::AccessLevels;
use rustc::middle::cstore::ExternCrate;
use rustc::session::config::{CrateType, Input, OutputType};
use rustc::ty::{self, TyCtxt};
use rustc::{bug, span_bug};
use rustc_typeck::hir_ty_to_ty;
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -64,6 +48,8 @@ use rls_data::{Def, DefKind, ExternalCrateData, GlobalCrateId, MacroRef, Ref, Re
RelationKind, SpanData, Impl, ImplKind};
use rls_data::config::Config;

use log::{debug, error, info};


pub struct SaveContext<'l, 'tcx: 'l> {
tcx: TyCtxt<'l, 'tcx, 'tcx>,
Expand Down Expand Up @@ -170,7 +156,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
ast::ForeignItemKind::Static(ref ty, _) => {
filter!(self.span_utils, item.ident.span);

let id = ::id_from_node_id(item.id, self);
let id = id_from_node_id(item.id, self);
let span = self.span_from_span(item.ident.span);

Some(Data::DefData(Def {
Expand Down Expand Up @@ -1034,7 +1020,7 @@ impl<'a> DumpHandler<'a> {
}
}

fn output_file(&self, ctx: &SaveContext) -> File {
fn output_file(&self, ctx: &SaveContext<'_, '_>) -> File {
let sess = &ctx.tcx.sess;
let file_name = match ctx.config.output_file {
Some(ref s) => PathBuf::from(s),
Expand Down Expand Up @@ -1185,7 +1171,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
}
}

fn id_from_node_id(id: NodeId, scx: &SaveContext) -> rls_data::Id {
fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
let def_id = scx.tcx.hir().opt_local_def_id(id);
def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| {
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
Expand All @@ -1205,7 +1191,7 @@ fn null_id() -> rls_data::Id {
}
}

fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext) -> Vec<rls_data::Attribute> {
fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext<'_, '_>) -> Vec<rls_data::Attribute> {
attrs.into_iter()
// Only retain real attributes. Doc comments are lowered separately.
.filter(|attr| attr.path != "doc")
Expand Down
Loading

0 comments on commit 2b8ed1e

Please sign in to comment.