Skip to content

Add JSON AST dumping #12387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use middle;
use util::common::time;
use util::ppaux;

use extra::json;
use serialize::Encodable;

use std::cell::{Cell, RefCell};
use std::hashmap::{HashMap,HashSet};
use std::io;
Expand Down Expand Up @@ -154,7 +157,7 @@ pub enum Input {

pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
time(sess.time_passes(), "parsing", (), |_| {
let krate = time(sess.time_passes(), "parsing", (), |_| {
match *input {
FileInput(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
Expand All @@ -166,7 +169,15 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
sess.parse_sess)
}
}
})
});

if sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0 {
let mut stdout = io::stdout();
let mut json = json::PrettyEncoder::new(&mut stdout);
krate.encode(&mut json);
}

krate
}

// For continuing compilation after a parsed crate has been
Expand Down Expand Up @@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

time(time_passes, "assinging node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));

if sess.opts.debugging_opts & session::AST_JSON != 0 {
let mut stdout = io::stdout();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be buffered? (Otherwise every single write, including each and every : separator, will be a syscall.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't stdout line buffered by default?

On Wed, Feb 19, 2014 at 7:39 PM, Huon Wilson notifications@github.comwrote:

In src/librustc/driver/driver.rs:

@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

  • time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
    
  • let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
    
  • if sess.opts.debugging_opts & session::AST_JSON != 0 {
  •    let mut stdout = io::stdout();
    

Shouldn't this be buffered? (Otherwise every single write, including each
and every : separator will be a syscall.)


Reply to this email directly or view it on GitHubhttps://github.com//pull/12387/files#r9890950
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task-local stdout handle is line-buffered by default, but those created through io::stdout() are not buffered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feh.

On Wed, Feb 19, 2014 at 7:55 PM, Alex Crichton notifications@github.comwrote:

In src/librustc/driver/driver.rs:

@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

  • time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
    
  • let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
    
  • if sess.opts.debugging_opts & session::AST_JSON != 0 {
  •    let mut stdout = io::stdout();
    

The task-local stdout handle is line-buffered by default, but those
created through io::stdout() are not buffered.


Reply to this email directly or view it on GitHubhttps://github.com//pull/12387/files#r9891396
.

let mut json = json::PrettyEncoder::new(&mut stdout);
krate.encode(&mut json);
}

(krate, map)
}

pub struct CrateAnalysis {
Expand Down Expand Up @@ -428,15 +447,15 @@ pub fn stop_after_phase_1(sess: Session) -> bool {
debug!("invoked with --parse-only, returning early from compile_input");
return true;
}
return false;
return sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0;
}

pub fn stop_after_phase_2(sess: Session) -> bool {
if sess.opts.no_analysis {
debug!("invoked with --no-analysis, returning early from compile_input");
return true;
}
return false;
return sess.opts.debugging_opts & session::AST_JSON != 0;
}

pub fn stop_after_phase_5(sess: Session) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ debugging_opts!(
GC,
PRINT_LINK_ARGS,
PRINT_LLVM_PASSES,
LTO
LTO,
AST_JSON,
AST_JSON_NOEXPAND
]
0
)
Expand Down Expand Up @@ -97,6 +99,8 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
"Prints the llvm optimization passes being run",
PRINT_LLVM_PASSES),
("lto", "Perform LLVM link-time optimizations", LTO),
("ast-json", "Print the AST as JSON and halt", AST_JSON),
("ast-json-noexpand", "Print the pre-expansion AST as JSON and halt", AST_JSON_NOEXPAND),
]
}

Expand Down