1
Fork 0

Delete lint buffer from Session

This commit is contained in:
Mark Rousskov 2019-10-25 13:41:51 -04:00
parent c0fdddcb60
commit c68df7c503
6 changed files with 39 additions and 68 deletions

View file

@ -34,7 +34,6 @@ use crate::util::common::time;
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
use std::slice; use std::slice;
use std::default::Default as StdDefault;
use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter}; use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter};
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable}; use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
use syntax::ast; use syntax::ast;
@ -584,12 +583,13 @@ impl<'a> EarlyContext<'a> {
lint_store: &'a LintStore, lint_store: &'a LintStore,
krate: &'a ast::Crate, krate: &'a ast::Crate,
buffered: LintBuffer, buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> EarlyContext<'a> { ) -> EarlyContext<'a> {
EarlyContext { EarlyContext {
sess, sess,
krate, krate,
lint_store, lint_store,
builder: LintLevelSets::builder(sess, lint_store), builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
buffered, buffered,
} }
} }
@ -1490,9 +1490,10 @@ fn early_lint_crate<T: EarlyLintPass>(
krate: &ast::Crate, krate: &ast::Crate,
pass: T, pass: T,
buffered: LintBuffer, buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> LintBuffer { ) -> LintBuffer {
let mut cx = EarlyContextAndPass { let mut cx = EarlyContextAndPass {
context: EarlyContext::new(sess, lint_store, krate, buffered), context: EarlyContext::new(sess, lint_store, krate, buffered, warn_about_weird_lints),
pass, pass,
}; };
@ -1514,22 +1515,19 @@ pub fn check_ast_crate<T: EarlyLintPass>(
lint_store: &LintStore, lint_store: &LintStore,
krate: &ast::Crate, krate: &ast::Crate,
pre_expansion: bool, pre_expansion: bool,
lint_buffer: Option<LintBuffer>,
builtin_lints: T, builtin_lints: T,
) { ) {
let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion { let mut passes: Vec<_> = if pre_expansion {
( lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
LintBuffer::default(),
)
} else { } else {
( lint_store.early_passes.iter().map(|p| (p)()).collect()
lint_store.early_passes.iter().map(|p| (p)()).collect(),
sess.buffered_lints.borrow_mut().take().unwrap(),
)
}; };
let mut buffered = lint_buffer.unwrap_or_default();
if !sess.opts.debugging_opts.no_interleave_lints { if !sess.opts.debugging_opts.no_interleave_lints {
buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered); buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered,
pre_expansion);
if !passes.is_empty() { if !passes.is_empty() {
buffered = early_lint_crate( buffered = early_lint_crate(
@ -1538,6 +1536,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
krate, krate,
EarlyLintPassObjects { lints: &mut passes[..] }, EarlyLintPassObjects { lints: &mut passes[..] },
buffered, buffered,
pre_expansion,
); );
} }
} else { } else {
@ -1549,6 +1548,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
krate, krate,
EarlyLintPassObjects { lints: slice::from_mut(pass) }, EarlyLintPassObjects { lints: slice::from_mut(pass) },
buffered, buffered,
pre_expansion,
) )
}); });
} }

View file

@ -44,8 +44,12 @@ impl LintLevelSets {
return me return me
} }
pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> { pub fn builder<'a>(
LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store)) sess: &'a Session,
warn_about_weird_lints: bool,
store: &LintStore,
) -> LintLevelsBuilder<'a> {
LintLevelsBuilder::new(sess, warn_about_weird_lints, LintLevelSets::new(sess, store))
} }
fn process_command_line(&mut self, sess: &Session, store: &LintStore) { fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
@ -160,14 +164,18 @@ pub struct BuilderPush {
} }
impl<'a> LintLevelsBuilder<'a> { impl<'a> LintLevelsBuilder<'a> {
pub fn new(sess: &'a Session, sets: LintLevelSets) -> LintLevelsBuilder<'a> { pub fn new(
sess: &'a Session,
warn_about_weird_lints: bool,
sets: LintLevelSets,
) -> LintLevelsBuilder<'a> {
assert_eq!(sets.list.len(), 1); assert_eq!(sets.list.len(), 1);
LintLevelsBuilder { LintLevelsBuilder {
sess, sess,
sets, sets,
cur: 0, cur: 0,
id_to_set: Default::default(), id_to_set: Default::default(),
warn_about_weird_lints: sess.buffered_lints.borrow().is_some(), warn_about_weird_lints,
} }
} }

View file

@ -795,7 +795,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
let store = &tcx.lint_store; let store = &tcx.lint_store;
let mut builder = LintLevelMapBuilder { let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess, &store), levels: LintLevelSets::builder(tcx.sess, false, &store),
tcx: tcx, tcx: tcx,
store: store, store: store,
}; };

View file

@ -6,7 +6,6 @@ use crate::hir::def_id::CrateNum;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use crate::lint; use crate::lint;
use crate::lint::builtin::BuiltinLintDiagnostics;
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
use crate::session::search_paths::{PathKind, SearchPath}; use crate::session::search_paths::{PathKind, SearchPath};
use crate::util::nodemap::{FxHashMap, FxHashSet}; use crate::util::nodemap::{FxHashMap, FxHashSet};
@ -77,13 +76,6 @@ pub struct Session {
/// if the value stored here has been affected by path remapping. /// if the value stored here has been affected by path remapping.
pub working_dir: (PathBuf, bool), pub working_dir: (PathBuf, bool),
/// This is intended to be used from a single thread.
///
/// FIXME: there was a previous comment about this not being thread safe,
/// but it's not clear how or why that's the case. The LintBuffer itself is certainly thread
/// safe at least from a "Rust safety" standpoint.
pub buffered_lints: Lock<Option<lint::LintBuffer>>,
/// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking /// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking
/// (sub)diagnostics that have been set once, but should not be set again, /// (sub)diagnostics that have been set once, but should not be set again,
/// in order to avoid redundantly verbose output (Issue #24690, #44953). /// in order to avoid redundantly verbose output (Issue #24690, #44953).
@ -366,37 +358,6 @@ impl Session {
self.diagnostic().span_note_without_error(sp, msg) self.diagnostic().span_note_without_error(sp, msg)
} }
pub fn buffer_lint_late<S: Into<MultiSpan>>(
&self,
lint: &'static lint::Lint,
id: ast::NodeId,
sp: S,
msg: &str,
) {
match *self.buffered_lints.borrow_mut() {
Some(ref mut buffer) => {
buffer.buffer_lint(lint, id, sp, msg);
}
None => bug!("can't buffer lints after HIR lowering"),
}
}
pub fn buffer_lint_with_diagnostic_late<S: Into<MultiSpan>>(
&self,
lint: &'static lint::Lint,
id: ast::NodeId,
sp: S,
msg: &str,
diagnostic: BuiltinLintDiagnostics,
) {
match *self.buffered_lints.borrow_mut() {
Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic(
lint, id, sp.into(), msg, diagnostic,
),
None => bug!("can't buffer lints after HIR lowering"),
}
}
pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId { pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
let id = self.next_node_id.get(); let id = self.next_node_id.get();
@ -1220,7 +1181,6 @@ fn build_session_(
sysroot, sysroot,
local_crate_source_file, local_crate_source_file,
working_dir, working_dir,
buffered_lints: Lock::new(Some(Default::default())),
one_time_diagnostics: Default::default(), one_time_diagnostics: Default::default(),
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())), plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
plugin_attributes: Lock::new(Vec::new()), plugin_attributes: Lock::new(Vec::new()),

View file

@ -267,17 +267,16 @@ fn configure_and_expand_inner<'a>(
lint_store, lint_store,
&krate, &krate,
true, true,
None,
rustc_lint::BuiltinCombinedPreExpansionLintPass::new()); rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
}); });
let lint_buffer = lint::LintBuffer::default();
let mut resolver = Resolver::new( let mut resolver = Resolver::new(
sess, sess,
&krate, &krate,
crate_name, crate_name,
metadata_loader, metadata_loader,
&resolver_arenas, &resolver_arenas,
lint_buffer,
); );
syntax_ext::register_builtin_macros(&mut resolver, sess.edition()); syntax_ext::register_builtin_macros(&mut resolver, sess.edition());
@ -295,7 +294,7 @@ fn configure_and_expand_inner<'a>(
krate krate
}); });
util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer); util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer());
syntax_ext::plugin_macro_defs::inject( syntax_ext::plugin_macro_defs::inject(
&mut krate, &mut resolver, plugin_info.syntax_exts, sess.edition() &mut krate, &mut resolver, plugin_info.syntax_exts, sess.edition()
@ -370,7 +369,7 @@ fn configure_and_expand_inner<'a>(
for span in missing_fragment_specifiers { for span in missing_fragment_specifiers {
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER; let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
let msg = "missing fragment specifier"; let msg = "missing fragment specifier";
resolver.lint_buffer.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg); resolver.lint_buffer().buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
} }
if cfg!(windows) { if cfg!(windows) {
env::set_var("PATH", &old_path); env::set_var("PATH", &old_path);
@ -399,7 +398,7 @@ fn configure_and_expand_inner<'a>(
} }
let has_proc_macro_decls = time(sess, "AST validation", || { let has_proc_macro_decls = time(sess, "AST validation", || {
ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer) ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer())
}); });
@ -468,7 +467,7 @@ fn configure_and_expand_inner<'a>(
info!("{} parse sess buffered_lints", buffered_lints.len()); info!("{} parse sess buffered_lints", buffered_lints.len());
for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) { for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
let lint = lint::Lint::from_parser_lint_id(lint_id); let lint = lint::Lint::from_parser_lint_id(lint_id);
resolver.lint_buffer.buffer_lint(lint, id, span, &msg); resolver.lint_buffer().buffer_lint(lint, id, span, &msg);
} }
}); });
@ -500,6 +499,7 @@ pub fn lower_to_hir(
lint_store, lint_store,
&krate, &krate,
false, false,
Some(std::mem::take(resolver.lint_buffer())),
rustc_lint::BuiltinCombinedEarlyLintPass::new(), rustc_lint::BuiltinCombinedEarlyLintPass::new(),
) )
}); });

View file

@ -963,7 +963,7 @@ pub struct Resolver<'a> {
/// when visiting the correspondent variants. /// when visiting the correspondent variants.
variant_vis: DefIdMap<ty::Visibility>, variant_vis: DefIdMap<ty::Visibility>,
pub lint_buffer: lint::LintBuffer, lint_buffer: lint::LintBuffer,
} }
/// Nothing really interesting here; it just provides memory for the rest of the crate. /// Nothing really interesting here; it just provides memory for the rest of the crate.
@ -1094,8 +1094,7 @@ impl<'a> Resolver<'a> {
krate: &Crate, krate: &Crate,
crate_name: &str, crate_name: &str,
metadata_loader: &'a MetadataLoaderDyn, metadata_loader: &'a MetadataLoaderDyn,
arenas: &'a ResolverArenas<'a>, arenas: &'a ResolverArenas<'a>)
lint_buffer: lint::LintBuffer)
-> Resolver<'a> { -> Resolver<'a> {
let root_def_id = DefId::local(CRATE_DEF_INDEX); let root_def_id = DefId::local(CRATE_DEF_INDEX);
let root_module_kind = ModuleKind::Def( let root_module_kind = ModuleKind::Def(
@ -1235,10 +1234,14 @@ impl<'a> Resolver<'a> {
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat)) .chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
.collect(), .collect(),
variant_vis: Default::default(), variant_vis: Default::default(),
lint_buffer, lint_buffer: lint::LintBuffer::default(),
} }
} }
pub fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
&mut self.lint_buffer
}
pub fn arenas() -> ResolverArenas<'a> { pub fn arenas() -> ResolverArenas<'a> {
Default::default() Default::default()
} }