diff options
| author | bors <bors@rust-lang.org> | 2017-08-10 11:20:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-10 11:20:15 +0000 |
| commit | 2400ebfe76225745d1591c8a63c54570174ab22c (patch) | |
| tree | c4b7b845fa0ca8ed21de3c3d6ab2b1718bf2e1f2 /src/librustc_driver | |
| parent | d21ec9b4efd1da012979b050bc0a0426fe45fcdf (diff) | |
| parent | 0374e6aab7ef60b523872556ae4aca33c59fbfc9 (diff) | |
| download | rust-2400ebfe76225745d1591c8a63c54570174ab22c.tar.gz rust-2400ebfe76225745d1591c8a63c54570174ab22c.zip | |
Auto merge of #43522 - alexcrichton:rewrite-lints, r=michaelwoerister
rustc: Rearchitect lints to be emitted more eagerly In preparation for incremental compilation this commit refactors the lint handling infrastructure in the compiler to be more "eager" and overall more incremental-friendly. Many passes of the compiler can emit lints at various points but before this commit all lints were buffered in a table to be emitted at the very end of compilation. This commit changes these lints to be emitted immediately during compilation using pre-calculated lint level-related data structures. Linting today is split into two phases, one set of "early" lints run on the `syntax::ast` and a "late" set of lints run on the HIR. This commit moves the "early" lints to running as late as possible in compilation, just before HIR lowering. This notably means that we're catching resolve-related lints just before HIR lowering. The early linting remains a pass very similar to how it was before, maintaining context of the current lint level as it walks the tree. Post-HIR, however, linting is structured as a method on the `TyCtxt` which transitively executes a query to calculate lint levels. Each request to lint on a `TyCtxt` will query the entire crate's 'lint level data structure' and then go from there about whether the lint should be emitted or not. The query depends on the entire HIR crate but should be very quick to calculate (just a quick walk of the HIR) and the red-green system should notice that the lint level data structure rarely changes, and should hopefully preserve incrementality. Overall this resulted in a pretty big change to the test suite now that lints are emitted much earlier in compilation (on-demand vs only at the end). This in turn necessitated the addition of many `#![allow(warnings)]` directives throughout the compile-fail test suite and a number of updates to the UI test suite. Closes https://github.com/rust-lang/rust/issues/42511
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/driver.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 22f98454f6c..c689b3d241c 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -645,7 +645,6 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session, super::describe_lints(&sess.lint_store.borrow(), true); return Err(CompileIncomplete::Stopped); } - sess.track_errors(|| sess.lint_store.borrow_mut().process_command_line(sess))?; // Currently, we ignore the name resolution data structures for the purposes of dependency // tracking. Instead we will run name resolution and include its output in the hash of each @@ -715,8 +714,8 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session, missing_fragment_specifiers.sort(); for span in missing_fragment_specifiers { let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER; - let msg = "missing fragment specifier".to_string(); - sess.add_lint(lint, ast::CRATE_NODE_ID, span, msg); + let msg = "missing fragment specifier"; + sess.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg); } if ecx.parse_sess.span_diagnostic.err_count() - ecx.resolve_err_count > err_count { ecx.parse_sess.span_diagnostic.abort_if_errors(); @@ -780,10 +779,6 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session, || no_asm::check_crate(sess, &krate)); time(time_passes, - "early lint checks", - || lint::check_ast_crate(sess, &krate)); - - time(time_passes, "AST validation", || ast_validation::check_crate(sess, &krate)); @@ -807,6 +802,10 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session, }) })?; + time(time_passes, + "early lint checks", + || lint::check_ast_crate(sess, &krate)); + // Lower ast -> hir. let hir_forest = time(time_passes, "lowering ast -> hir", || { let hir_crate = lower_crate(sess, &krate, &mut resolver); @@ -915,6 +914,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, rustc_const_eval::provide(&mut local_providers); middle::region::provide(&mut local_providers); cstore::provide_local(&mut local_providers); + lint::provide(&mut local_providers); let mut extern_providers = ty::maps::Providers::default(); cstore::provide(&mut extern_providers); @@ -1201,10 +1201,10 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c } Some(ref n) if *n == "bin" => Some(config::CrateTypeExecutable), Some(_) => { - session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPES, - ast::CRATE_NODE_ID, - a.span, - "invalid `crate_type` value".to_string()); + session.buffer_lint(lint::builtin::UNKNOWN_CRATE_TYPES, + ast::CRATE_NODE_ID, + a.span, + "invalid `crate_type` value"); None } _ => { |
