Skip to content

Commit 4751e45

Browse files
committed
Auto merge of rust-lang#33208 - nrc:save-json, r=pnkfelix
save-analysis: dump in JSON format cc rust-lang#18582
2 parents 0f9ba99 + 7ca2b94 commit 4751e45

File tree

12 files changed

+906
-281
lines changed

12 files changed

+906
-281
lines changed

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir
120120
log syntax serialize rustc_llvm rustc_platform_intrinsics \
121121
rustc_const_math rustc_const_eval rustc_incremental
122122
DEPS_rustc_incremental := rbml rustc serialize rustc_data_structures
123-
DEPS_rustc_save_analysis := rustc log syntax
123+
DEPS_rustc_save_analysis := rustc log syntax serialize
124124
DEPS_rustc_typeck := rustc syntax rustc_platform_intrinsics rustc_const_math \
125125
rustc_const_eval
126126

src/librustc/session/config.rs

+3-1
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,

src/librustc_driver/driver.rs

+14-4
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 {

src/librustc_driver/lib.rs

+18-2
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");

src/librustc_save_analysis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ crate-type = ["dylib"]
1212
log = { path = "../liblog" }
1313
rustc = { path = "../librustc" }
1414
syntax = { path = "../libsyntax" }
15+
serialize = { path = "../libserialize" }

0 commit comments

Comments
 (0)