Put in -Z continue-parse-after-error
This works by adding a boolean flag, `continue_after_error`, to `syntax::errors::Handler` that can be imperatively set to `true` or `false` via a new `fn set_continue_after_error`. The flag starts off true (since we generally try to recover from compiler errors, and `Handler` is shared across all phases). Then, during the `phase_1_parse_input`, we consult the setting of the `-Z continue-parse-after-error` debug flag to determine whether we should leave the flag set to `true` or should change it to `false`. ---- (We might consider adding a debugflag to do such aborts in other places where we are currently attempting recovery, such as resolve, but I think the parser is the really important case to handle in the face of #31994 and the parser bugs of varying degrees that were injected by parse error recovery.)
This commit is contained in:
parent
40deb279a8
commit
2646663b5a
3 changed files with 19 additions and 0 deletions
|
@ -138,6 +138,7 @@ pub struct Options {
|
||||||
pub no_trans: bool,
|
pub no_trans: bool,
|
||||||
pub error_format: ErrorOutputType,
|
pub error_format: ErrorOutputType,
|
||||||
pub treat_err_as_bug: bool,
|
pub treat_err_as_bug: bool,
|
||||||
|
pub continue_parse_after_error: bool,
|
||||||
pub mir_opt_level: usize,
|
pub mir_opt_level: usize,
|
||||||
|
|
||||||
/// if true, build up the dep-graph
|
/// if true, build up the dep-graph
|
||||||
|
@ -259,6 +260,7 @@ pub fn basic_options() -> Options {
|
||||||
parse_only: false,
|
parse_only: false,
|
||||||
no_trans: false,
|
no_trans: false,
|
||||||
treat_err_as_bug: false,
|
treat_err_as_bug: false,
|
||||||
|
continue_parse_after_error: false,
|
||||||
mir_opt_level: 1,
|
mir_opt_level: 1,
|
||||||
build_dep_graph: false,
|
build_dep_graph: false,
|
||||||
dump_dep_graph: false,
|
dump_dep_graph: false,
|
||||||
|
@ -633,6 +635,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||||
"run all passes except translation; no output"),
|
"run all passes except translation; no output"),
|
||||||
treat_err_as_bug: bool = (false, parse_bool,
|
treat_err_as_bug: bool = (false, parse_bool,
|
||||||
"treat all errors that occur as bugs"),
|
"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,
|
incr_comp: bool = (false, parse_bool,
|
||||||
"enable incremental compilation (experimental)"),
|
"enable incremental compilation (experimental)"),
|
||||||
dump_dep_graph: bool = (false, parse_bool,
|
dump_dep_graph: bool = (false, parse_bool,
|
||||||
|
@ -1045,6 +1049,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
let parse_only = debugging_opts.parse_only;
|
let parse_only = debugging_opts.parse_only;
|
||||||
let no_trans = debugging_opts.no_trans;
|
let no_trans = debugging_opts.no_trans;
|
||||||
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
|
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 mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
|
||||||
let incremental_compilation = debugging_opts.incr_comp;
|
let incremental_compilation = debugging_opts.incr_comp;
|
||||||
let dump_dep_graph = debugging_opts.dump_dep_graph;
|
let dump_dep_graph = debugging_opts.dump_dep_graph;
|
||||||
|
@ -1228,6 +1233,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
parse_only: parse_only,
|
parse_only: parse_only,
|
||||||
no_trans: no_trans,
|
no_trans: no_trans,
|
||||||
treat_err_as_bug: treat_err_as_bug,
|
treat_err_as_bug: treat_err_as_bug,
|
||||||
|
continue_parse_after_error: continue_parse_after_error,
|
||||||
mir_opt_level: mir_opt_level,
|
mir_opt_level: mir_opt_level,
|
||||||
build_dep_graph: incremental_compilation || dump_dep_graph,
|
build_dep_graph: incremental_compilation || dump_dep_graph,
|
||||||
dump_dep_graph: dump_dep_graph,
|
dump_dep_graph: dump_dep_graph,
|
||||||
|
|
|
@ -427,6 +427,8 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session,
|
||||||
// memory, but they do not restore the initial state.
|
// memory, but they do not restore the initial state.
|
||||||
syntax::ext::mtwt::reset_tables();
|
syntax::ext::mtwt::reset_tables();
|
||||||
token::reset_ident_interner();
|
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", || {
|
let krate = time(sess.time_passes(), "parsing", || {
|
||||||
match *input {
|
match *input {
|
||||||
|
@ -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 {
|
if sess.opts.debugging_opts.ast_json_noexpand {
|
||||||
println!("{}", json::as_json(&krate));
|
println!("{}", json::as_json(&krate));
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,7 @@ pub struct Handler {
|
||||||
emit: RefCell<Box<Emitter>>,
|
emit: RefCell<Box<Emitter>>,
|
||||||
pub can_emit_warnings: bool,
|
pub can_emit_warnings: bool,
|
||||||
treat_err_as_bug: bool,
|
treat_err_as_bug: bool,
|
||||||
|
continue_after_error: Cell<bool>,
|
||||||
delayed_span_bug: RefCell<Option<(MultiSpan, String)>>,
|
delayed_span_bug: RefCell<Option<(MultiSpan, String)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,10 +393,15 @@ impl Handler {
|
||||||
emit: RefCell::new(e),
|
emit: RefCell::new(e),
|
||||||
can_emit_warnings: can_emit_warnings,
|
can_emit_warnings: can_emit_warnings,
|
||||||
treat_err_as_bug: treat_err_as_bug,
|
treat_err_as_bug: treat_err_as_bug,
|
||||||
|
continue_after_error: Cell::new(true),
|
||||||
delayed_span_bug: RefCell::new(None),
|
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> {
|
pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
|
||||||
DiagnosticBuilder::new(&self.emit, Level::Cancelled, "")
|
DiagnosticBuilder::new(&self.emit, Level::Cancelled, "")
|
||||||
}
|
}
|
||||||
|
@ -612,6 +618,7 @@ impl Handler {
|
||||||
lvl: Level) {
|
lvl: Level) {
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
if lvl == Warning && !self.can_emit_warnings { return }
|
||||||
self.emit.borrow_mut().emit(msp, msg, None, lvl);
|
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,
|
pub fn emit_with_code(&self,
|
||||||
msp: Option<&MultiSpan>,
|
msp: Option<&MultiSpan>,
|
||||||
|
@ -620,10 +627,12 @@ impl Handler {
|
||||||
lvl: Level) {
|
lvl: Level) {
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
if lvl == Warning && !self.can_emit_warnings { return }
|
||||||
self.emit.borrow_mut().emit(msp, msg, Some(code), lvl);
|
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) {
|
pub fn custom_emit(&self, rsp: RenderSpan, msg: &str, lvl: Level) {
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
if lvl == Warning && !self.can_emit_warnings { return }
|
||||||
self.emit.borrow_mut().custom_emit(&rsp, msg, lvl);
|
self.emit.borrow_mut().custom_emit(&rsp, msg, lvl);
|
||||||
|
if !self.continue_after_error.get() { self.abort_if_errors(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue