Skip to content

Commit

Permalink
Delete lint buffer from Session
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Nov 4, 2019
1 parent c0fdddc commit c68df7c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 68 deletions.
26 changes: 13 additions & 13 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::util::common::time;

use errors::DiagnosticBuilder;
use std::slice;
use std::default::Default as StdDefault;
use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter};
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
use syntax::ast;
Expand Down Expand Up @@ -584,12 +583,13 @@ impl<'a> EarlyContext<'a> {
lint_store: &'a LintStore,
krate: &'a ast::Crate,
buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> EarlyContext<'a> {
EarlyContext {
sess,
krate,
lint_store,
builder: LintLevelSets::builder(sess, lint_store),
builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
buffered,
}
}
Expand Down Expand Up @@ -1490,9 +1490,10 @@ fn early_lint_crate<T: EarlyLintPass>(
krate: &ast::Crate,
pass: T,
buffered: LintBuffer,
warn_about_weird_lints: bool,
) -> LintBuffer {
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,
};

Expand All @@ -1514,22 +1515,19 @@ pub fn check_ast_crate<T: EarlyLintPass>(
lint_store: &LintStore,
krate: &ast::Crate,
pre_expansion: bool,
lint_buffer: Option<LintBuffer>,
builtin_lints: T,
) {
let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion {
(
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
LintBuffer::default(),
)
let mut passes: Vec<_> = if pre_expansion {
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
} else {
(
lint_store.early_passes.iter().map(|p| (p)()).collect(),
sess.buffered_lints.borrow_mut().take().unwrap(),
)
lint_store.early_passes.iter().map(|p| (p)()).collect()
};
let mut buffered = lint_buffer.unwrap_or_default();

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() {
buffered = early_lint_crate(
Expand All @@ -1538,6 +1536,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
krate,
EarlyLintPassObjects { lints: &mut passes[..] },
buffered,
pre_expansion,
);
}
} else {
Expand All @@ -1549,6 +1548,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
krate,
EarlyLintPassObjects { lints: slice::from_mut(pass) },
buffered,
pre_expansion,
)
});
}
Expand Down
16 changes: 12 additions & 4 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ impl LintLevelSets {
return me
}

pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> {
LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store))
pub fn builder<'a>(
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) {
Expand Down Expand Up @@ -160,14 +164,18 @@ pub struct BuilderPush {
}

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);
LintLevelsBuilder {
sess,
sets,
cur: 0,
id_to_set: Default::default(),
warn_about_weird_lints: sess.buffered_lints.borrow().is_some(),
warn_about_weird_lints,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = &tcx.lint_store;
let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess, &store),
levels: LintLevelSets::builder(tcx.sess, false, &store),
tcx: tcx,
store: store,
};
Expand Down
40 changes: 0 additions & 40 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::hir::def_id::CrateNum;
use rustc_data_structures::fingerprint::Fingerprint;

use crate::lint;
use crate::lint::builtin::BuiltinLintDiagnostics;
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
use crate::session::search_paths::{PathKind, SearchPath};
use crate::util::nodemap::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -77,13 +76,6 @@ pub struct Session {
/// if the value stored here has been affected by path remapping.
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
/// (sub)diagnostics that have been set once, but should not be set again,
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
Expand Down Expand Up @@ -366,37 +358,6 @@ impl Session {
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 {
let id = self.next_node_id.get();

Expand Down Expand Up @@ -1220,7 +1181,6 @@ fn build_session_(
sysroot,
local_crate_source_file,
working_dir,
buffered_lints: Lock::new(Some(Default::default())),
one_time_diagnostics: Default::default(),
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
plugin_attributes: Lock::new(Vec::new()),
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,16 @@ fn configure_and_expand_inner<'a>(
lint_store,
&krate,
true,
None,
rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
});

let lint_buffer = lint::LintBuffer::default();
let mut resolver = Resolver::new(
sess,
&krate,
crate_name,
metadata_loader,
&resolver_arenas,
lint_buffer,
);
syntax_ext::register_builtin_macros(&mut resolver, sess.edition());

Expand All @@ -295,7 +294,7 @@ fn configure_and_expand_inner<'a>(
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(
&mut krate, &mut resolver, plugin_info.syntax_exts, sess.edition()
Expand Down Expand Up @@ -370,7 +369,7 @@ fn configure_and_expand_inner<'a>(
for span in missing_fragment_specifiers {
let lint = lint::builtin::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) {
env::set_var("PATH", &old_path);
Expand Down Expand Up @@ -399,7 +398,7 @@ fn configure_and_expand_inner<'a>(
}

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())
});


Expand Down Expand Up @@ -468,7 +467,7 @@ fn configure_and_expand_inner<'a>(
info!("{} parse sess buffered_lints", buffered_lints.len());
for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
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);
}
});

Expand Down Expand Up @@ -500,6 +499,7 @@ pub fn lower_to_hir(
lint_store,
&krate,
false,
Some(std::mem::take(resolver.lint_buffer())),
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
)
});
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ pub struct Resolver<'a> {
/// when visiting the correspondent variants.
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.
Expand Down Expand Up @@ -1094,8 +1094,7 @@ impl<'a> Resolver<'a> {
krate: &Crate,
crate_name: &str,
metadata_loader: &'a MetadataLoaderDyn,
arenas: &'a ResolverArenas<'a>,
lint_buffer: lint::LintBuffer)
arenas: &'a ResolverArenas<'a>)
-> Resolver<'a> {
let root_def_id = DefId::local(CRATE_DEF_INDEX);
let root_module_kind = ModuleKind::Def(
Expand Down Expand Up @@ -1235,10 +1234,14 @@ impl<'a> Resolver<'a> {
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
.collect(),
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> {
Default::default()
}
Expand Down

0 comments on commit c68df7c

Please sign in to comment.