Skip to content

Commit 52e9f20

Browse files
committed
Use config::pub_only rather than a spearate api mode
1 parent 4d81e8b commit 52e9f20

File tree

6 files changed

+51
-161
lines changed

6 files changed

+51
-161
lines changed

src/librustc/session/config.rs

Lines changed: 0 additions & 5 deletions
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/lib.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
579579
state.analysis.unwrap(),
580580
state.crate_name.unwrap(),
581581
None,
582-
DumpHandler::new(save_analysis_format(state.session),
583-
state.out_dir,
582+
DumpHandler::new(state.out_dir,
584583
state.crate_name.unwrap()))
585584
});
586585
};
@@ -603,18 +602,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
603602
}
604603

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

620608
impl RustcDefaultCalls {

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 10 additions & 9 deletions
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, 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) {
@@ -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.

src/librustc_save_analysis/json_api_dumper.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/librustc_save_analysis/json_dumper.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use rustc_serialize::json::as_json;
1414

1515
use rls_data::{self, Analysis, Import, Def, DefKind, Ref, RefKind, MacroRef,
1616
Relation, CratePreludeData};
17+
use rls_data::config::Config;
1718
use rls_span::{Column, Row};
1819

19-
use Dump;
20-
2120
pub struct JsonDumper<O: DumpOutput> {
2221
result: Analysis,
22+
config: Config,
2323
output: O,
2424
}
2525

@@ -50,14 +50,14 @@ impl<'b> DumpOutput for CallbackOutput<'b> {
5050
}
5151

5252
impl<'b, W: Write> JsonDumper<WriteOutput<'b, W>> {
53-
pub fn new(writer: &'b mut W) -> JsonDumper<WriteOutput<'b, W>> {
54-
JsonDumper { output: WriteOutput { output: writer }, result: Analysis::new() }
53+
pub fn new(writer: &'b mut W, config: Config) -> JsonDumper<WriteOutput<'b, W>> {
54+
JsonDumper { output: WriteOutput { output: writer }, config, result: Analysis::new() }
5555
}
5656
}
5757

5858
impl<'b> JsonDumper<CallbackOutput<'b>> {
59-
pub fn with_callback(callback: &'b mut FnMut(&Analysis)) -> JsonDumper<CallbackOutput<'b>> {
60-
JsonDumper { output: CallbackOutput { callback: callback }, result: Analysis::new() }
59+
pub fn with_callback(callback: &'b mut FnMut(&Analysis), config: Config) -> JsonDumper<CallbackOutput<'b>> {
60+
JsonDumper { output: CallbackOutput { callback: callback }, config, result: Analysis::new() }
6161
}
6262
}
6363

@@ -67,23 +67,36 @@ impl<O: DumpOutput> Drop for JsonDumper<O> {
6767
}
6868
}
6969

70-
impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
71-
fn crate_prelude(&mut self, data: CratePreludeData) {
70+
impl<'b, O: DumpOutput + 'b> JsonDumper<O> {
71+
pub fn crate_prelude(&mut self, data: CratePreludeData) {
7272
self.result.prelude = Some(data)
7373
}
7474

75-
fn macro_use(&mut self, data: MacroRef) {
75+
pub fn macro_use(&mut self, data: MacroRef) {
76+
if self.config.pub_only {
77+
return;
78+
}
7679
self.result.macro_refs.push(data);
7780
}
7881

79-
fn import(&mut self, _: bool, import: Import) {
82+
pub fn import(&mut self, public: bool, import: Import) {
83+
if !public && self.config.pub_only {
84+
return;
85+
}
8086
self.result.imports.push(import);
8187
}
8288

83-
fn dump_ref(&mut self, data: Ref) {
89+
pub fn dump_ref(&mut self, data: Ref) {
90+
if self.config.pub_only {
91+
return;
92+
}
8493
self.result.refs.push(data);
8594
}
86-
fn dump_def(&mut self, _: bool, mut data: Def) {
95+
96+
pub fn dump_def(&mut self, public: bool, mut data: Def) {
97+
if !public && self.config.pub_only {
98+
return;
99+
}
87100
if data.kind == DefKind::Mod && data.span.file_name.to_str().unwrap() != data.value {
88101
// If the module is an out-of-line defintion, then we'll make the
89102
// defintion the first character in the module's file and turn the
@@ -107,7 +120,7 @@ impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
107120
self.result.defs.push(data);
108121
}
109122

110-
fn dump_relation(&mut self, data: Relation) {
123+
pub fn dump_relation(&mut self, data: Relation) {
111124
self.result.relations.push(data);
112125
}
113126
}

0 commit comments

Comments
 (0)