Skip to content

Use a config struct for save-analysis #43327

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

Merged
merged 8 commits into from
Jul 24, 2017
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
268 changes: 185 additions & 83 deletions src/Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ fn main() {

// Emit save-analysis info.
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
cmd.arg("-Zsave-analysis-api");
cmd.arg("-Zsave-analysis");
cmd.env("RUST_SAVE_ANALYSIS_CONFIG",
"{\"output_file\": null,\"full_docs\": false,\"pub_only\": true,\
\"signatures\": false,\"borrow_data\": false}");
}

// Dealing with rpath here is a little special, so let's go into some
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
save_analysis: bool = (false, parse_bool, [UNTRACKED],
"write syntax and type analysis (in JSON format) information, in \
addition to normal output"),
save_analysis_api: bool = (false, parse_bool, [UNTRACKED],
"write syntax and type analysis information for opaque libraries (in JSON format), \
in addition to normal output"),
print_move_fragments: bool = (false, parse_bool, [UNTRACKED],
"print out move-fragment data for every fn"),
flowgraph_print_loans: bool = (false, parse_bool, [UNTRACKED],
Expand Down Expand Up @@ -2527,8 +2524,6 @@ mod tests {
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.save_analysis = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.save_analysis_api = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.print_move_fragments = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.flowgraph_print_loans = true;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn compile_input(sess: &Session,
hir::check_attr::check_crate(sess, &expanded_crate);
});

let opt_crate = if keep_ast(sess) {
let opt_crate = if control.keep_ast {
Some(&expanded_crate)
} else {
drop(expanded_crate);
Expand Down Expand Up @@ -263,9 +263,6 @@ fn keep_hygiene_data(sess: &Session) -> bool {
sess.opts.debugging_opts.keep_hygiene_data
}

fn keep_ast(sess: &Session) -> bool {
sess.opts.debugging_opts.keep_ast || ::save_analysis(sess)
}

/// The name used for source code that doesn't originate in a file
/// (e.g. source from stdin or a string)
Expand Down Expand Up @@ -304,6 +301,8 @@ pub struct CompileController<'a> {
pub compilation_done: PhaseController<'a>,

pub make_glob_map: MakeGlobMap,
// Whether the compiler should keep the ast beyond parsing.
pub keep_ast: bool,
}

impl<'a> CompileController<'a> {
Expand All @@ -316,6 +315,7 @@ impl<'a> CompileController<'a> {
after_llvm: PhaseController::basic(),
compilation_done: PhaseController::basic(),
make_glob_map: MakeGlobMap::No,
keep_ast: false,
}
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
-> CompileController<'a> {
let mut control = CompileController::basic();

control.keep_ast = sess.opts.debugging_opts.keep_ast || save_analysis(sess);

if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) {
if ppm.needs_ast_map(&opt_uii) {
control.after_hir_lowering.stop = Compilation::Stop;
Expand Down Expand Up @@ -578,8 +580,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
state.expanded_crate.unwrap(),
state.analysis.unwrap(),
state.crate_name.unwrap(),
DumpHandler::new(save_analysis_format(state.session),
state.out_dir,
None,
DumpHandler::new(state.out_dir,
state.crate_name.unwrap()))
});
};
Expand All @@ -602,18 +604,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
}

fn save_analysis(sess: &Session) -> bool {
sess.opts.debugging_opts.save_analysis ||
sess.opts.debugging_opts.save_analysis_api
}

fn save_analysis_format(sess: &Session) -> save::Format {
if sess.opts.debugging_opts.save_analysis {
save::Format::Json
} else if sess.opts.debugging_opts.save_analysis_api {
save::Format::JsonApi
} else {
unreachable!();
}
sess.opts.debugging_opts.save_analysis
}

impl RustcDefaultCalls {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rustc = { path = "../librustc" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.7"
rls-data = "0.9"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
39 changes: 20 additions & 19 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ use syntax::ptr::P;
use syntax::codemap::Spanned;
use syntax_pos::*;

use {escape, generated_code, SaveContext, PathCollector, docs_for_attrs, lower_attributes, Dump};
use {escape, generated_code, SaveContext, PathCollector, lower_attributes};
use json_dumper::{JsonDumper, DumpOutput};
use span_utils::SpanUtils;
use sig;

Expand All @@ -58,11 +59,11 @@ macro_rules! down_cast_data {
};
}

pub struct DumpVisitor<'l, 'tcx: 'l, 'll, D: 'll> {
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
save_ctxt: SaveContext<'l, 'tcx>,
sess: &'l Session,
tcx: TyCtxt<'l, 'tcx, 'tcx>,
dumper: &'ll mut D,
dumper: &'ll mut JsonDumper<O>,

span: SpanUtils<'l>,

Expand All @@ -75,10 +76,10 @@ pub struct DumpVisitor<'l, 'tcx: 'l, 'll, D: 'll> {
// mac_defs: HashSet<Span>,
}

impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
pub fn new(save_ctxt: SaveContext<'l, 'tcx>,
dumper: &'ll mut D)
-> DumpVisitor<'l, 'tcx, 'll, D> {
dumper: &'ll mut JsonDumper<O>)
-> DumpVisitor<'l, 'tcx, 'll, O> {
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
DumpVisitor {
sess: &save_ctxt.tcx.sess,
Expand All @@ -92,7 +93,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
}

fn nest_scope<F>(&mut self, scope_id: NodeId, f: F)
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>)
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>)
{
let parent_scope = self.cur_scope;
self.cur_scope = scope_id;
Expand All @@ -101,7 +102,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
}

fn nest_tables<F>(&mut self, item_id: NodeId, f: F)
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>)
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>)
{
let item_def_id = self.tcx.hir.local_def_id(item_id);
if self.tcx.has_typeck_tables(item_def_id) {
Expand Down Expand Up @@ -531,7 +532,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: Some(::id_from_def_id(parent_id)),
children: vec![],
decl_id: None,
docs: docs_for_attrs(attrs),
docs: self.save_ctxt.docs_for_attrs(attrs),
sig,
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
});
Expand Down Expand Up @@ -580,7 +581,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: None,
children: fields,
decl_id: None,
docs: docs_for_attrs(&item.attrs),
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
});
Expand Down Expand Up @@ -637,7 +638,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent,
children: vec![],
decl_id: None,
docs: docs_for_attrs(&variant.node.attrs),
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
sig: sig::variant_signature(variant, &self.save_ctxt),
attributes: lower_attributes(variant.node.attrs.clone(),
&self.save_ctxt),
Expand Down Expand Up @@ -671,7 +672,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent,
children: vec![],
decl_id: None,
docs: docs_for_attrs(&variant.node.attrs),
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
sig: sig::variant_signature(variant, &self.save_ctxt),
attributes: lower_attributes(variant.node.attrs.clone(),
&self.save_ctxt),
Expand Down Expand Up @@ -742,7 +743,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: None,
children,
decl_id: None,
docs: docs_for_attrs(&item.attrs),
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
});
Expand Down Expand Up @@ -1039,7 +1040,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
parent: Some(::id_from_def_id(trait_id)),
children: vec![],
decl_id: None,
docs: docs_for_attrs(&trait_item.attrs),
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
sig: sig::assoc_type_signature(trait_item.id,
trait_item.ident,
Some(bounds),
Expand Down Expand Up @@ -1089,7 +1090,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
}
}

impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> {
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], id: NodeId) {
// Since we handle explicit modules ourselves in visit_item, this should
// only get called for the root module of a crate.
Expand All @@ -1113,7 +1114,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
children,
parent: None,
decl_id: None,
docs: docs_for_attrs(attrs),
docs: self.save_ctxt.docs_for_attrs(attrs),
sig: None,
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
});
Expand Down Expand Up @@ -1250,7 +1251,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
parent: None,
children: vec![],
decl_id: None,
docs: docs_for_attrs(&item.attrs),
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
});
Expand Down Expand Up @@ -1314,8 +1315,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
let hir_expr = self.save_ctxt.tcx.hir.expect_expr(ex.id);
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
Some(ty) => ty.ty_adt_def().unwrap(),
None => {
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
_ => {
visit::walk_expr(self, ex);
return;
}
Expand Down
66 changes: 0 additions & 66 deletions src/librustc_save_analysis/json_api_dumper.rs

This file was deleted.

Loading