Skip to content

Commit

Permalink
Auto merge of #33208 - nrc:save-json, r=pnkfelix
Browse files Browse the repository at this point in the history
save-analysis: dump in JSON format

cc #18582
  • Loading branch information
bors committed Apr 28, 2016
2 parents 0f9ba99 + 7ca2b94 commit 4751e45
Show file tree
Hide file tree
Showing 12 changed files with 906 additions and 281 deletions.
2 changes: 1 addition & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir
log syntax serialize rustc_llvm rustc_platform_intrinsics \
rustc_const_math rustc_const_eval rustc_incremental
DEPS_rustc_incremental := rbml rustc serialize rustc_data_structures
DEPS_rustc_save_analysis := rustc log syntax
DEPS_rustc_save_analysis := rustc log syntax serialize
DEPS_rustc_typeck := rustc syntax rustc_platform_intrinsics rustc_const_math \
rustc_const_eval

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
ls: bool = (false, parse_bool,
"list the symbols defined by a library crate"),
save_analysis: bool = (false, parse_bool,
"write syntax and type analysis information in addition to normal output"),
"write syntax and type analysis (in JSON format) information in addition to normal output"),
save_analysis_csv: bool = (false, parse_bool,
"write syntax and type analysis (in CSV format) information in addition to normal output"),
print_move_fragments: bool = (false, parse_bool,
"print out move-fragment data for every fn"),
flowgraph_print_loans: bool = (false, parse_bool,
Expand Down
18 changes: 14 additions & 4 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ pub fn compile_input(sess: &Session,
dep_graph));

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

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

let opt_crate = if sess.opts.debugging_opts.keep_ast ||
sess.opts.debugging_opts.save_analysis {
let opt_crate = if keep_ast(sess) {
Some(&expanded_crate)
} else {
drop(expanded_crate);
Expand Down Expand Up @@ -249,6 +247,18 @@ pub fn compile_input(sess: &Session,
Ok(())
}

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

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

/// The name used for source code that doesn't originate in a file
/// (e.g. source from stdin or a string)
pub fn anon_src() -> String {
Expand Down
20 changes: 18 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,16 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
control.after_llvm.stop = Compilation::Stop;
}

if sess.opts.debugging_opts.save_analysis {
if save_analysis(sess) {
control.after_analysis.callback = box |state| {
time(state.session.time_passes(), "save analysis", || {
save::process_crate(state.tcx.unwrap(),
state.lcx.unwrap(),
state.krate.unwrap(),
state.analysis.unwrap(),
state.crate_name.unwrap(),
state.out_dir)
state.out_dir,
save_analysis_format(state.session))
});
};
control.after_analysis.run_callback_on_error = true;
Expand All @@ -502,6 +503,21 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
}
}

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

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_csv {
save::Format::Csv
} else {
unreachable!();
}
}

impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session, matches: &getopts::Matches, input: &Input) -> Compilation {
let r = matches.opt_strs("Z");
Expand Down
1 change: 1 addition & 0 deletions src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ crate-type = ["dylib"]
log = { path = "../liblog" }
rustc = { path = "../librustc" }
syntax = { path = "../libsyntax" }
serialize = { path = "../libserialize" }
Loading

0 comments on commit 4751e45

Please sign in to comment.