Skip to content

Commit

Permalink
Auto merge of #31631 - jonas-schievink:agoraphobia, r=nrc
Browse files Browse the repository at this point in the history
[breaking-batch] Move more uses of `panictry!` out of libsyntax
  • Loading branch information
bors committed Mar 9, 2016
2 parents 4b86841 + 11e0ba4 commit cbbd3d9
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 119 deletions.
27 changes: 17 additions & 10 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use syntax::ast::{self, NodeIdAssigner};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::attr::{self, AttrMetaMethods};
use syntax::diagnostics;
use syntax::fold::Folder;
use syntax::parse;
use syntax::parse::token;
use syntax::parse::{self, PResult, token};
use syntax::util::node_count::NodeCounter;
use syntax::visit;
use syntax;
Expand Down Expand Up @@ -86,7 +84,13 @@ pub fn compile_input(sess: &Session,
// possible to keep the peak memory usage low
let (outputs, trans) = {
let (outputs, expanded_crate, id) = {
let krate = phase_1_parse_input(sess, cfg, input);
let krate = match phase_1_parse_input(sess, cfg, input) {
Ok(krate) => krate,
Err(mut parse_error) => {
parse_error.emit();
return Err(1);
}
};

controller_entry_point!(after_parse,
sess,
Expand Down Expand Up @@ -415,17 +419,20 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
}
}

pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) -> ast::Crate {
pub fn phase_1_parse_input<'a>(sess: &'a Session,
cfg: ast::CrateConfig,
input: &Input)
-> PResult<'a, ast::Crate> {
// These may be left in an incoherent state after a previous compile.
// `clear_tables` and `get_ident_interner().clear()` can be used to free
// memory, but they do not restore the initial state.
syntax::ext::mtwt::reset_tables();
token::reset_ident_interner();

let krate = time(sess.time_passes(), "parsing", || {
let krate = try!(time(sess.time_passes(), "parsing", || {
match *input {
Input::File(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
parse::parse_crate_from_file(file, cfg.clone(), &sess.parse_sess)
}
Input::Str(ref src) => {
parse::parse_crate_from_source_str(anon_src().to_string(),
Expand All @@ -434,7 +441,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
&sess.parse_sess)
}
}
});
}));

if sess.opts.debugging_opts.ast_json_noexpand {
println!("{}", json::as_json(&krate));
Expand All @@ -449,7 +456,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
syntax::show_span::run(sess.diagnostic(), s, &krate);
}

krate
Ok(krate)
}

fn count_nodes(krate: &ast::Crate) -> usize {
Expand Down
23 changes: 17 additions & 6 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use std::thread;
use rustc::session::{early_error, early_warn};

use syntax::ast;
use syntax::parse;
use syntax::parse::{self, PResult};
use syntax::errors;
use syntax::errors::emitter::Emitter;
use syntax::diagnostics;
Expand Down Expand Up @@ -531,7 +531,19 @@ impl RustcDefaultCalls {
return Compilation::Continue;
}

let attrs = input.map(|input| parse_crate_attrs(sess, input));
let attrs = match input {
None => None,
Some(input) => {
let result = parse_crate_attrs(sess, input);
match result {
Ok(attrs) => Some(attrs),
Err(mut parse_error) => {
parse_error.emit();
return Compilation::Stop;
}
}
}
};
for req in &sess.opts.prints {
match *req {
PrintRequest::TargetList => {
Expand Down Expand Up @@ -977,8 +989,8 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
Some(matches)
}

fn parse_crate_attrs(sess: &Session, input: &Input) -> Vec<ast::Attribute> {
let result = match *input {
fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<ast::Attribute>> {
match *input {
Input::File(ref ifile) => {
parse::parse_crate_attrs_from_file(ifile, Vec::new(), &sess.parse_sess)
}
Expand All @@ -988,8 +1000,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) -> Vec<ast::Attribute> {
Vec::new(),
&sess.parse_sess)
}
};
result.into_iter().collect()
}
}

/// Run a procedure which will detect panics in the compiler and print nicer
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ pub fn pretty_print_input(sess: Session,
ppm: PpMode,
opt_uii: Option<UserIdentifiedItem>,
ofile: Option<PathBuf>) {
let krate = driver::phase_1_parse_input(&sess, cfg, input);
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, input));

let krate = if let PpmSource(PpmEveryBodyLoops) = ppm {
let mut fold = ReplaceBodyWithLoop::new();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn test_env<F>(source_string: &str,
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let krate_config = Vec::new();
let input = config::Input::Str(source_string.to_string());
let krate = driver::phase_1_parse_input(&sess, krate_config, &input);
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None)
.expect("phase 2 aborted");

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let mut cfg = config::build_configuration(&sess);
target_features::add_configuration(&mut cfg, &sess);

let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));

let name = link::find_crate_name(Some(&sess), &krate.attrs,
&input);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern crate rustc_back;
extern crate rustc_front;
extern crate rustc_metadata;
extern crate serialize;
extern crate syntax;
#[macro_use] extern crate syntax;
extern crate test as testing;
extern crate rustc_unicode;
#[macro_use] extern crate log;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn run(input: &str,

let mut cfg = config::build_configuration(&sess);
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
"rustdoc-test", None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ pub struct WhereEqPredicate {

/// The set of MetaItems that define the compilation environment of the crate,
/// used to drive conditional compilation
pub type CrateConfig = Vec<P<MetaItem>> ;
pub type CrateConfig = Vec<P<MetaItem>>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Crate {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ mod tests {
let crate_ast = parse::parse_crate_from_source_str(
"<test>".to_string(),
src,
Vec::new(), &sess);
Vec::new(), &sess).unwrap();
// should fail:
let mut gated_cfgs = vec![];
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
Expand All @@ -1535,7 +1535,7 @@ mod tests {
let crate_ast = parse::parse_crate_from_source_str(
"<test>".to_string(),
src,
Vec::new(), &sess);
Vec::new(), &sess).unwrap();
let mut gated_cfgs = vec![];
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
expand_crate(ecx, vec![], vec![], crate_ast);
Expand All @@ -1549,7 +1549,7 @@ mod tests {
let crate_ast = parse::parse_crate_from_source_str(
"<test>".to_string(),
src,
Vec::new(), &sess);
Vec::new(), &sess).unwrap();
let mut gated_cfgs = vec![];
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
expand_crate(ecx, vec![], vec![], crate_ast);
Expand Down
42 changes: 22 additions & 20 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use parse::token::*;
use parse::token;
use ptr::P;

/// Quasiquoting works via token trees.
/// Quasiquoting works via token trees.
///
/// This is registered as a set of expression syntax extension called quote!
/// that lifts its argument token-tree to an AST representing the
/// construction of the same token tree, with token::SubstNt interpreted
/// as antiquotes (splices).
/// This is registered as a set of expression syntax extension called quote!
/// that lifts its argument token-tree to an AST representing the
/// construction of the same token tree, with token::SubstNt interpreted
/// as antiquotes (splices).
pub mod rt {
use ast;
Expand Down Expand Up @@ -319,34 +319,36 @@ pub mod rt {
}

impl<'a> ExtParseUtils for ExtCtxt<'a> {

fn parse_item(&self, s: String) -> P<ast::Item> {
parse::parse_item_from_source_str(
panictry!(parse::parse_item_from_source_str(
"<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess()).expect("parse error")
self.parse_sess())).expect("parse error")
}

fn parse_stmt(&self, s: String) -> ast::Stmt {
parse::parse_stmt_from_source_str("<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess()).expect("parse error")
panictry!(parse::parse_stmt_from_source_str(
"<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess())).expect("parse error")
}

fn parse_expr(&self, s: String) -> P<ast::Expr> {
parse::parse_expr_from_source_str("<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess())
panictry!(parse::parse_expr_from_source_str(
"<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess()))
}

fn parse_tts(&self, s: String) -> Vec<TokenTree> {
parse::parse_tts_from_source_str("<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess())
panictry!(parse::parse_tts_from_source_str(
"<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess()))
}
}
}
Expand Down
Loading

0 comments on commit cbbd3d9

Please sign in to comment.