Skip to content

Commit 513906c

Browse files
committed
Auto merge of rust-lang#43327 - nrc:rls-config, r=eddyb
Use a config struct for save-analysis Replaces some existing customisation options, including removing the -Zsave-analysis-api flag r? @eddyb
2 parents 9a70c3a + 587a35d commit 513906c

File tree

13 files changed

+370
-320
lines changed

13 files changed

+370
-320
lines changed

src/Cargo.lock

+185-83
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/bin/rustc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ fn main() {
185185

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

191194
// Dealing with rpath here is a little special, so let's go into some

src/librustc/session/config.rs

-5
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
960960
save_analysis: bool = (false, parse_bool, [UNTRACKED],
961961
"write syntax and type analysis (in JSON format) information, in \
962962
addition to normal output"),
963-
save_analysis_api: bool = (false, parse_bool, [UNTRACKED],
964-
"write syntax and type analysis information for opaque libraries (in JSON format), \
965-
in addition to normal output"),
966963
print_move_fragments: bool = (false, parse_bool, [UNTRACKED],
967964
"print out move-fragment data for every fn"),
968965
flowgraph_print_loans: bool = (false, parse_bool, [UNTRACKED],
@@ -2527,8 +2524,6 @@ mod tests {
25272524
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
25282525
opts.debugging_opts.save_analysis = true;
25292526
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2530-
opts.debugging_opts.save_analysis_api = true;
2531-
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
25322527
opts.debugging_opts.print_move_fragments = true;
25332528
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
25342529
opts.debugging_opts.flowgraph_print_loans = true;

src/librustc_driver/driver.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn compile_input(sess: &Session,
167167
hir::check_attr::check_crate(sess, &expanded_crate);
168168
});
169169

170-
let opt_crate = if keep_ast(sess) {
170+
let opt_crate = if control.keep_ast {
171171
Some(&expanded_crate)
172172
} else {
173173
drop(expanded_crate);
@@ -263,9 +263,6 @@ fn keep_hygiene_data(sess: &Session) -> bool {
263263
sess.opts.debugging_opts.keep_hygiene_data
264264
}
265265

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

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

306303
pub make_glob_map: MakeGlobMap,
304+
// Whether the compiler should keep the ast beyond parsing.
305+
pub keep_ast: bool,
307306
}
308307

309308
impl<'a> CompileController<'a> {
@@ -316,6 +315,7 @@ impl<'a> CompileController<'a> {
316315
after_llvm: PhaseController::basic(),
317316
compilation_done: PhaseController::basic(),
318317
make_glob_map: MakeGlobMap::No,
318+
keep_ast: false,
319319
}
320320
}
321321
}

src/librustc_driver/lib.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
518518
-> CompileController<'a> {
519519
let mut control = CompileController::basic();
520520

521+
control.keep_ast = sess.opts.debugging_opts.keep_ast || save_analysis(sess);
522+
521523
if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) {
522524
if ppm.needs_ast_map(&opt_uii) {
523525
control.after_hir_lowering.stop = Compilation::Stop;
@@ -578,8 +580,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
578580
state.expanded_crate.unwrap(),
579581
state.analysis.unwrap(),
580582
state.crate_name.unwrap(),
581-
DumpHandler::new(save_analysis_format(state.session),
582-
state.out_dir,
583+
None,
584+
DumpHandler::new(state.out_dir,
583585
state.crate_name.unwrap()))
584586
});
585587
};
@@ -602,18 +604,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
602604
}
603605

604606
fn save_analysis(sess: &Session) -> bool {
605-
sess.opts.debugging_opts.save_analysis ||
606-
sess.opts.debugging_opts.save_analysis_api
607-
}
608-
609-
fn save_analysis_format(sess: &Session) -> save::Format {
610-
if sess.opts.debugging_opts.save_analysis {
611-
save::Format::Json
612-
} else if sess.opts.debugging_opts.save_analysis_api {
613-
save::Format::JsonApi
614-
} else {
615-
unreachable!();
616-
}
607+
sess.opts.debugging_opts.save_analysis
617608
}
618609

619610
impl RustcDefaultCalls {

src/librustc_save_analysis/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rustc = { path = "../librustc" }
1414
rustc_typeck = { path = "../librustc_typeck" }
1515
syntax = { path = "../libsyntax" }
1616
syntax_pos = { path = "../libsyntax_pos" }
17-
rls-data = "0.7"
17+
rls-data = "0.9"
1818
rls-span = "0.4"
1919
# FIXME(#40527) should move rustc serialize out of tree
2020
rustc-serialize = "0.3"

src/librustc_save_analysis/dump_visitor.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use syntax::ptr::P;
4141
use syntax::codemap::Spanned;
4242
use syntax_pos::*;
4343

44-
use {escape, generated_code, SaveContext, PathCollector, docs_for_attrs, lower_attributes, Dump};
44+
use {escape, generated_code, SaveContext, PathCollector, lower_attributes};
45+
use json_dumper::{JsonDumper, DumpOutput};
4546
use span_utils::SpanUtils;
4647
use sig;
4748

@@ -58,11 +59,11 @@ macro_rules! down_cast_data {
5859
};
5960
}
6061

61-
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, D: 'll> {
62+
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
6263
save_ctxt: SaveContext<'l, 'tcx>,
6364
sess: &'l Session,
6465
tcx: TyCtxt<'l, 'tcx, 'tcx>,
65-
dumper: &'ll mut D,
66+
dumper: &'ll mut JsonDumper<O>,
6667

6768
span: SpanUtils<'l>,
6869

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

78-
impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
79+
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
7980
pub fn new(save_ctxt: SaveContext<'l, 'tcx>,
80-
dumper: &'ll mut D)
81-
-> DumpVisitor<'l, 'tcx, 'll, D> {
81+
dumper: &'ll mut JsonDumper<O>)
82+
-> DumpVisitor<'l, 'tcx, 'll, O> {
8283
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
8384
DumpVisitor {
8485
sess: &save_ctxt.tcx.sess,
@@ -92,7 +93,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
9293
}
9394

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

103104
fn nest_tables<F>(&mut self, item_id: NodeId, f: F)
104-
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>)
105+
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>)
105106
{
106107
let item_def_id = self.tcx.hir.local_def_id(item_id);
107108
if self.tcx.has_typeck_tables(item_def_id) {
@@ -531,7 +532,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
531532
parent: Some(::id_from_def_id(parent_id)),
532533
children: vec![],
533534
decl_id: None,
534-
docs: docs_for_attrs(attrs),
535+
docs: self.save_ctxt.docs_for_attrs(attrs),
535536
sig,
536537
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
537538
});
@@ -580,7 +581,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
580581
parent: None,
581582
children: fields,
582583
decl_id: None,
583-
docs: docs_for_attrs(&item.attrs),
584+
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
584585
sig: sig::item_signature(item, &self.save_ctxt),
585586
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
586587
});
@@ -637,7 +638,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
637638
parent,
638639
children: vec![],
639640
decl_id: None,
640-
docs: docs_for_attrs(&variant.node.attrs),
641+
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
641642
sig: sig::variant_signature(variant, &self.save_ctxt),
642643
attributes: lower_attributes(variant.node.attrs.clone(),
643644
&self.save_ctxt),
@@ -671,7 +672,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
671672
parent,
672673
children: vec![],
673674
decl_id: None,
674-
docs: docs_for_attrs(&variant.node.attrs),
675+
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
675676
sig: sig::variant_signature(variant, &self.save_ctxt),
676677
attributes: lower_attributes(variant.node.attrs.clone(),
677678
&self.save_ctxt),
@@ -742,7 +743,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
742743
parent: None,
743744
children,
744745
decl_id: None,
745-
docs: docs_for_attrs(&item.attrs),
746+
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
746747
sig: sig::item_signature(item, &self.save_ctxt),
747748
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
748749
});
@@ -1039,7 +1040,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
10391040
parent: Some(::id_from_def_id(trait_id)),
10401041
children: vec![],
10411042
decl_id: None,
1042-
docs: docs_for_attrs(&trait_item.attrs),
1043+
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
10431044
sig: sig::assoc_type_signature(trait_item.id,
10441045
trait_item.ident,
10451046
Some(bounds),
@@ -1089,7 +1090,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
10891090
}
10901091
}
10911092

1092-
impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> {
1093+
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> {
10931094
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], id: NodeId) {
10941095
// Since we handle explicit modules ourselves in visit_item, this should
10951096
// only get called for the root module of a crate.
@@ -1113,7 +1114,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
11131114
children,
11141115
parent: None,
11151116
decl_id: None,
1116-
docs: docs_for_attrs(attrs),
1117+
docs: self.save_ctxt.docs_for_attrs(attrs),
11171118
sig: None,
11181119
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
11191120
});
@@ -1250,7 +1251,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
12501251
parent: None,
12511252
children: vec![],
12521253
decl_id: None,
1253-
docs: docs_for_attrs(&item.attrs),
1254+
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
12541255
sig: sig::item_signature(item, &self.save_ctxt),
12551256
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
12561257
});
@@ -1314,8 +1315,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
13141315
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
13151316
let hir_expr = self.save_ctxt.tcx.hir.expect_expr(ex.id);
13161317
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
1317-
Some(ty) => ty.ty_adt_def().unwrap(),
1318-
None => {
1318+
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
1319+
_ => {
13191320
visit::walk_expr(self, ex);
13201321
return;
13211322
}

src/librustc_save_analysis/json_api_dumper.rs

-66
This file was deleted.

0 commit comments

Comments
 (0)