Skip to content

Commit

Permalink
driver: factor out continue_parse_after_error so it can be controll…
Browse files Browse the repository at this point in the history
…ed via driver API
  • Loading branch information
nrc committed Aug 9, 2017
1 parent 8d8876c commit a9a181d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/librustc_driver/driver.rs
Expand Up @@ -89,7 +89,7 @@ pub fn compile_input(sess: &Session,
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
let (outputs, trans) = {
let krate = match phase_1_parse_input(sess, input) {
let krate = match phase_1_parse_input(control, sess, input) {
Ok(krate) => krate,
Err(mut parse_error) => {
parse_error.emit();
Expand Down Expand Up @@ -296,9 +296,13 @@ pub struct CompileController<'a> {
pub after_llvm: PhaseController<'a>,
pub compilation_done: PhaseController<'a>,

// FIXME we probably want to group the below options together and offer a
// better API, rather than this ad-hoc approach.
pub make_glob_map: MakeGlobMap,
// Whether the compiler should keep the ast beyond parsing.
pub keep_ast: bool,
// -Zcontinue-parse-after-error
pub continue_parse_after_error: bool,
}

impl<'a> CompileController<'a> {
Expand All @@ -312,6 +316,7 @@ impl<'a> CompileController<'a> {
compilation_done: PhaseController::basic(),
make_glob_map: MakeGlobMap::No,
keep_ast: false,
continue_parse_after_error: false,
}
}
}
Expand Down Expand Up @@ -484,20 +489,22 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
}

fn state_when_compilation_done(input: &'a Input,
session: &'tcx Session,
out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>)
-> Self {
session: &'tcx Session,
out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>)
-> Self {
CompileState {
out_file: out_file.as_ref().map(|s| &**s),
..CompileState::empty(input, session, out_dir)
}
}
}

pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
sess.diagnostic().set_continue_after_error(continue_after_error);
pub fn phase_1_parse_input<'a>(control: &CompileController,
sess: &'a Session,
input: &Input)
-> PResult<'a, ast::Crate> {
sess.diagnostic().set_continue_after_error(control.continue_parse_after_error);

let krate = time(sess.time_passes(), "parsing", || {
match *input {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/lib.rs
Expand Up @@ -519,6 +519,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
let mut control = CompileController::basic();

control.keep_ast = sess.opts.debugging_opts.keep_ast;
control.continue_parse_after_error = sess.opts.debugging_opts.continue_parse_after_error;

if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) {
if ppm.needs_ast_map(&opt_uii) {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_driver/test.rs
Expand Up @@ -119,7 +119,9 @@ fn test_env<F>(source_string: &str,
name: driver::anon_src(),
input: source_string.to_string(),
};
let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
let krate = driver::phase_1_parse_input(&driver::CompileController::basic(),
&sess,
&input).unwrap();
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
driver::phase_2_configure_and_expand(&sess,
&cstore,
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/core.rs
Expand Up @@ -155,7 +155,9 @@ pub fn run_core(search_paths: SearchPaths,
target_features::add_configuration(&mut cfg, &sess);
sess.parse_sess.config = cfg;

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

let name = link::find_crate_name(Some(&sess), &krate.attrs, &input);

Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/test.rs
Expand Up @@ -91,7 +91,9 @@ pub fn run(input: &str,
sess.parse_sess.config =
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));

let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
let krate = panictry!(driver::phase_1_parse_input(&driver::CompileController::basic(),
&sess,
&input));
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
phase_2_configure_and_expand(
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
Expand Down

0 comments on commit a9a181d

Please sign in to comment.