Skip to content

Gate parser recovery via debugflag #32494

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 2 commits into from
Mar 31, 2016
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
6 changes: 6 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub struct Options {
pub no_trans: bool,
pub error_format: ErrorOutputType,
pub treat_err_as_bug: bool,
pub continue_parse_after_error: bool,
pub mir_opt_level: usize,

/// if true, build up the dep-graph
Expand Down Expand Up @@ -259,6 +260,7 @@ pub fn basic_options() -> Options {
parse_only: false,
no_trans: false,
treat_err_as_bug: false,
continue_parse_after_error: false,
mir_opt_level: 1,
build_dep_graph: false,
dump_dep_graph: false,
Expand Down Expand Up @@ -633,6 +635,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"run all passes except translation; no output"),
treat_err_as_bug: bool = (false, parse_bool,
"treat all errors that occur as bugs"),
continue_parse_after_error: bool = (false, parse_bool,
"attempt to recover from parse errors (experimental)"),
incr_comp: bool = (false, parse_bool,
"enable incremental compilation (experimental)"),
dump_dep_graph: bool = (false, parse_bool,
Expand Down Expand Up @@ -1045,6 +1049,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let parse_only = debugging_opts.parse_only;
let no_trans = debugging_opts.no_trans;
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
let continue_parse_after_error = debugging_opts.continue_parse_after_error;
let mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
let incremental_compilation = debugging_opts.incr_comp;
let dump_dep_graph = debugging_opts.dump_dep_graph;
Expand Down Expand Up @@ -1228,6 +1233,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
parse_only: parse_only,
no_trans: no_trans,
treat_err_as_bug: treat_err_as_bug,
continue_parse_after_error: continue_parse_after_error,
mir_opt_level: mir_opt_level,
build_dep_graph: incremental_compilation || dump_dep_graph,
dump_dep_graph: dump_dep_graph,
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
// memory, but they do not restore the initial state.
syntax::ext::mtwt::reset_tables();
token::reset_ident_interner();
let continue_after_error = sess.opts.continue_parse_after_error;
sess.diagnostic().set_continue_after_error(continue_after_error);

let krate = time(sess.time_passes(), "parsing", || {
match *input {
Expand All @@ -442,6 +444,8 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
}
})?;

sess.diagnostic().set_continue_after_error(true);

if sess.opts.debugging_opts.ast_json_noexpand {
println!("{}", json::as_json(&krate));
}
Expand Down
9 changes: 9 additions & 0 deletions src/libsyntax/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ pub struct Handler {
emit: RefCell<Box<Emitter>>,
pub can_emit_warnings: bool,
treat_err_as_bug: bool,
continue_after_error: Cell<bool>,
delayed_span_bug: RefCell<Option<(MultiSpan, String)>>,
}

Expand All @@ -392,10 +393,15 @@ impl Handler {
emit: RefCell::new(e),
can_emit_warnings: can_emit_warnings,
treat_err_as_bug: treat_err_as_bug,
continue_after_error: Cell::new(true),
delayed_span_bug: RefCell::new(None),
}
}

pub fn set_continue_after_error(&self, continue_after_error: bool) {
self.continue_after_error.set(continue_after_error);
}

pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
DiagnosticBuilder::new(&self.emit, Level::Cancelled, "")
}
Expand Down Expand Up @@ -612,6 +618,7 @@ impl Handler {
lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(msp, msg, None, lvl);
if !self.continue_after_error.get() { self.abort_if_errors(); }
}
pub fn emit_with_code(&self,
msp: Option<&MultiSpan>,
Expand All @@ -620,10 +627,12 @@ impl Handler {
lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().emit(msp, msg, Some(code), lvl);
if !self.continue_after_error.get() { self.abort_if_errors(); }
}
pub fn custom_emit(&self, rsp: RenderSpan, msg: &str, lvl: Level) {
if lvl == Warning && !self.can_emit_warnings { return }
self.emit.borrow_mut().custom_emit(&rsp, msg, lvl);
if !self.continue_after_error.get() { self.abort_if_errors(); }
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-12560-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

// For style and consistency reasons, non-parametrized enum variants must
// be used simply as `ident` instead of `ident ()`.
// This test-case covers enum matching.
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-28433.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

enum bird {
pub duck,
//~^ ERROR: expected identifier, found keyword `pub`
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-30715.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

macro_rules! parallel {
(
// If future has `pred`/`moelarry` fragments (where "pred" is
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/macro-incomplete-parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

macro_rules! ignored_item {
() => {
fn foo() {}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/parse-error-correct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

// Test that the parser is error correcting missing idents. Despite a parsing
// error (or two), we still run type checking (and don't get extra errors there).

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/parser-recovery-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

// Test that we can recover from missing braces in the parser.

trait Foo {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/parser-recovery-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

// Test that we can recover from mismatched braces in the parser.

trait Foo {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/self_type_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z continue-parse-after-error

Copy link
Contributor

Choose a reason for hiding this comment

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

why do these tests need the flag when they didn't before?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the commit message answers this Q?

Update: that is, without the flag, the parsing bails out on the first error, so all the subsequent error messages are never emitted, and the test fails.

struct Self;
//~^ ERROR expected identifier, found keyword `Self`

Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/ascii-only-character-escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

fn main() {
let x = "\x80"; //~ ERROR may only be used
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/bad-char-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

// ignore-tidy-cr
// ignore-tidy-tab
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/bad-lit-suffixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error


extern
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/byte-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error


// ignore-tidy-tab
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/byte-string-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error


// ignore-tidy-tab
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/issue-10412.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error


trait Serializable<'self, T> { //~ ERROR no longer a special lifetime
Expand Down
2 changes: 2 additions & 0 deletions src/test/parse-fail/issue-23620-invalid-escapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only -Z continue-parse-after-error

fn main() {
let _ = b"\u{a66e}";
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
Expand Down
2 changes: 2 additions & 0 deletions src/test/parse-fail/lex-bad-binary-literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only -Z continue-parse-after-error

fn main() {
0b121; //~ ERROR invalid digit for a base 2 literal
0b10_10301; //~ ERROR invalid digit for a base 2 literal
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/lex-bad-char-literals-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error
static c3: char =
'\x1' //~ ERROR: numeric character escape is too short
;
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/lex-bad-numeric-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

fn main() {
0o1.0; //~ ERROR: octal float literal is not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

// ignore-tidy-cr

Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/new-unicode-escapes-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

pub fn main() {
let s = "\u{lol}";
Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/no-unsafe-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

trait A {
fn foo(*mut self); //~ ERROR cannot pass self by raw pointer
Expand Down