Skip to content

Commit 5f3e61f

Browse files
committed
---
yaml --- r: 277431 b: refs/heads/try c: 5065f0c h: refs/heads/master i: 277429: 39fc3fb 277427: ee58206 277423: ee2a435
1 parent c4813a3 commit 5f3e61f

File tree

6 files changed

+93
-20
lines changed

6 files changed

+93
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: 91b5ed5ce38e3833e985c2cf023e1902891f30e2
4+
refs/heads/try: 5065f0c2a2a37ad160268a214523f45402502be2
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/session/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
618618
ls: bool = (false, parse_bool,
619619
"list the symbols defined by a library crate"),
620620
save_analysis: bool = (false, parse_bool,
621-
"write syntax and type analysis information in addition to normal output"),
621+
"write syntax and type analysis (in JSON format) information in addition to normal output"),
622+
save_analysis_csv: bool = (false, parse_bool,
623+
"write syntax and type analysis (in CSV format) information in addition to normal output"),
622624
print_move_fragments: bool = (false, parse_bool,
623625
"print out move-fragment data for every fn"),
624626
flowgraph_print_loans: bool = (false, parse_bool,

branches/try/src/librustc_driver/driver.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ pub fn compile_input(sess: &Session,
141141
dep_graph));
142142

143143
// Discard MTWT tables that aren't required past lowering to HIR.
144-
if !sess.opts.debugging_opts.keep_mtwt_tables &&
145-
!sess.opts.debugging_opts.save_analysis {
144+
if !keep_mtwt_tables(sess) {
146145
syntax::ext::mtwt::clear_tables();
147146
}
148147

@@ -179,8 +178,7 @@ pub fn compile_input(sess: &Session,
179178
"early lint checks",
180179
|| lint::check_ast_crate(sess, &expanded_crate));
181180

182-
let opt_crate = if sess.opts.debugging_opts.keep_ast ||
183-
sess.opts.debugging_opts.save_analysis {
181+
let opt_crate = if keep_ast(sess) {
184182
Some(&expanded_crate)
185183
} else {
186184
drop(expanded_crate);
@@ -249,6 +247,18 @@ pub fn compile_input(sess: &Session,
249247
Ok(())
250248
}
251249

250+
fn keep_mtwt_tables(sess: &Session) -> bool {
251+
sess.opts.debugging_opts.keep_mtwt_tables ||
252+
sess.opts.debugging_opts.save_analysis ||
253+
sess.opts.debugging_opts.save_analysis_csv
254+
}
255+
256+
fn keep_ast(sess: &Session) -> bool {
257+
sess.opts.debugging_opts.keep_ast ||
258+
sess.opts.debugging_opts.save_analysis ||
259+
sess.opts.debugging_opts.save_analysis_csv
260+
}
261+
252262
/// The name used for source code that doesn't originate in a file
253263
/// (e.g. source from stdin or a string)
254264
pub fn anon_src() -> String {

branches/try/src/librustc_driver/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,16 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
483483
control.after_llvm.stop = Compilation::Stop;
484484
}
485485

486-
if sess.opts.debugging_opts.save_analysis {
486+
if save_analysis(sess) {
487487
control.after_analysis.callback = box |state| {
488488
time(state.session.time_passes(), "save analysis", || {
489489
save::process_crate(state.tcx.unwrap(),
490490
state.lcx.unwrap(),
491491
state.krate.unwrap(),
492492
state.analysis.unwrap(),
493493
state.crate_name.unwrap(),
494-
state.out_dir)
494+
state.out_dir,
495+
save_analysis_format(state.session))
495496
});
496497
};
497498
control.after_analysis.run_callback_on_error = true;
@@ -502,6 +503,21 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
502503
}
503504
}
504505

506+
fn save_analysis(sess: &Session) -> bool {
507+
sess.opts.debugging_opts.save_analysis ||
508+
sess.opts.debugging_opts.save_analysis_csv
509+
}
510+
511+
fn save_analysis_format(sess: &Session) -> save::Format {
512+
if sess.opts.debugging_opts.save_analysis {
513+
save::Format::Json
514+
} else if sess.opts.debugging_opts.save_analysis_csv {
515+
save::Format::Csv
516+
} else {
517+
unreachable!();
518+
}
519+
}
520+
505521
impl RustcDefaultCalls {
506522
pub fn list_metadata(sess: &Session, matches: &getopts::Matches, input: &Input) -> Compilation {
507523
let r = matches.opt_strs("Z");

branches/try/src/librustc_save_analysis/json_dumper.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,39 @@ use syntax::ast::{CrateNum, NodeId};
1919
use super::data::{self, SpanData};
2020
use super::dump::Dump;
2121

22-
pub struct JsonDumper<'a, 'b, W: 'b> {
22+
pub struct JsonDumper<'a, 'b, W: Write + 'b> {
2323
output: &'b mut W,
2424
codemap: &'a CodeMap,
25+
first: bool,
2526
}
2627

2728
impl<'a, 'b, W: Write> JsonDumper<'a, 'b, W> {
2829
pub fn new(writer: &'b mut W, codemap: &'a CodeMap) -> JsonDumper<'a, 'b, W> {
29-
JsonDumper { output: writer, codemap:codemap }
30+
if let Err(_) = write!(writer, "[") {
31+
error!("Error writing output");
32+
}
33+
JsonDumper { output: writer, codemap:codemap, first: true }
34+
}
35+
}
36+
37+
impl<'a, 'b, W: Write> Drop for JsonDumper<'a, 'b, W> {
38+
fn drop(&mut self) {
39+
if let Err(_) = write!(self.output, "]") {
40+
error!("Error writing output");
41+
}
3042
}
3143
}
3244

3345
macro_rules! impl_fn {
3446
($fn_name: ident, $data_type: ident) => {
3547
fn $fn_name(&mut self, data: data::$data_type) {
48+
if self.first {
49+
self.first = false;
50+
} else {
51+
if let Err(_) = write!(self.output, ",") {
52+
error!("Error writing output");
53+
}
54+
}
3655
let data = data.lower(self.codemap);
3756
if let Err(_) = write!(self.output, "{}", as_json(&data)) {
3857
error!("Error writing output '{}'", as_json(&data));

branches/try/src/librustc_save_analysis/lib.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -688,24 +688,40 @@ impl<'v> Visitor<'v> for PathCollector {
688688
}
689689
}
690690

691+
#[derive(Clone, Copy, Debug)]
692+
pub enum Format {
693+
Csv,
694+
Json,
695+
}
696+
697+
impl Format {
698+
fn extension(&self) -> &'static str {
699+
match *self {
700+
Format::Csv => ".csv",
701+
Format::Json => ".json",
702+
}
703+
}
704+
}
705+
691706
pub fn process_crate<'l, 'tcx>(tcx: &'l TyCtxt<'tcx>,
692707
lcx: &'l lowering::LoweringContext<'l>,
693708
krate: &ast::Crate,
694709
analysis: &'l ty::CrateAnalysis<'l>,
695710
cratename: &str,
696-
odir: Option<&Path>) {
711+
odir: Option<&Path>,
712+
format: Format) {
697713
let _ignore = tcx.dep_graph.in_ignore();
698714

699715
assert!(analysis.glob_map.is_some());
700716

701717
info!("Dumping crate {}", cratename);
702718

703719
// find a path to dump our data to
704-
let mut root_path = match env::var_os("DXR_RUST_TEMP_FOLDER") {
720+
let mut root_path = match env::var_os("RUST_SAVE_ANALYSIS_FOLDER") {
705721
Some(val) => PathBuf::from(val),
706722
None => match odir {
707-
Some(val) => val.join("dxr"),
708-
None => PathBuf::from("dxr-temp"),
723+
Some(val) => val.join("save-analysis"),
724+
None => PathBuf::from("save-analysis-temp"),
709725
},
710726
};
711727

@@ -729,22 +745,32 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l TyCtxt<'tcx>,
729745
};
730746
out_name.push_str(&cratename);
731747
out_name.push_str(&tcx.sess.opts.cg.extra_filename);
732-
out_name.push_str(".csv");
748+
out_name.push_str(format.extension());
733749
root_path.push(&out_name);
734750
let mut output_file = File::create(&root_path).unwrap_or_else(|e| {
735751
let disp = root_path.display();
736752
tcx.sess.fatal(&format!("Could not open {}: {}", disp, e));
737753
});
738754
root_path.pop();
755+
let output = &mut output_file;
739756

740757
let utils: SpanUtils<'tcx> = SpanUtils::new(&tcx.sess);
741758
let save_ctxt = SaveContext::new(tcx, lcx);
742-
let mut dumper = CsvDumper::new(&mut output_file, utils);
743-
let mut visitor = DumpVisitor::new(tcx, save_ctxt, analysis, &mut dumper);
744-
// FIXME: we don't write anything!
745759

746-
visitor.dump_crate_info(cratename, krate);
747-
visit::walk_crate(&mut visitor, krate);
760+
macro_rules! dump {
761+
($new_dumper: expr) => {{
762+
let mut dumper = $new_dumper;
763+
let mut visitor = DumpVisitor::new(tcx, save_ctxt, analysis, &mut dumper);
764+
765+
visitor.dump_crate_info(cratename, krate);
766+
visit::walk_crate(&mut visitor, krate);
767+
}}
768+
}
769+
770+
match format {
771+
Format::Csv => dump!(CsvDumper::new(output, utils)),
772+
Format::Json => dump!(JsonDumper::new(output, utils.sess.codemap())),
773+
}
748774
}
749775

750776
// Utility functions for the module.

0 commit comments

Comments
 (0)