Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
47a443c
Duplicate lint specifications are always bug!
Mark-Simulacrum Sep 24, 2019
577d442
De-propagate optional session from lint registration
Mark-Simulacrum Sep 24, 2019
2121b04
Handle lints, not passes in push_lints
Mark-Simulacrum Sep 24, 2019
748eccd
Lints being from a plugin is dependent on the lint, not the registration
Mark-Simulacrum Oct 7, 2019
b060f3b
Split module and crate late pass registration
Mark-Simulacrum Oct 7, 2019
e1079c8
Split out just registration to separate function
Mark-Simulacrum Oct 7, 2019
68c07db
No longer implicitly register lints when registering passes
Mark-Simulacrum Oct 7, 2019
7fef397
Make get_lints be a static function
Mark-Simulacrum Oct 7, 2019
2454512
Take lint passes as constructor functions
Mark-Simulacrum Oct 7, 2019
aa4ee2c
Move to storing constructor functions inside LintStore
Mark-Simulacrum Oct 7, 2019
c1abc30
Make declare_lint take any amount of boolean fields
Mark-Simulacrum Oct 8, 2019
7abb1fa
Remove side table of future incompatibility info
Mark-Simulacrum Oct 9, 2019
c4475c7
Access future incompatibility information directly
Mark-Simulacrum Oct 9, 2019
da56d1d
Remove all borrows of lint store from Session from librustc
Mark-Simulacrum Oct 9, 2019
dab3bd6
Create lint store during plugin registration
Mark-Simulacrum Oct 9, 2019
b761367
Fix test fallout
Mark-Simulacrum Oct 9, 2019
6be0a70
Update API to be more compatible with plugin needs
Mark-Simulacrum Oct 10, 2019
4e8d1b2
Add some documentation
Mark-Simulacrum Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove all borrows of lint store from Session from librustc
Access through tcx is fine -- by that point, the lint store is frozen,
but direct access through Session will go away in future commits, as
lint store is still mutable in early stages of Session, and will be
removed completely.
  • Loading branch information
Mark-Simulacrum committed Oct 17, 2019
commit da56d1d20113355047f5e6e3d5686ea1c7589d99
21 changes: 13 additions & 8 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ pub struct EarlyContext<'a> {
builder: LintLevelsBuilder<'a>,

/// The store of registered lints and the lint levels.
lint_store: ReadGuard<'a, LintStore>,
lint_store: &'a LintStore,

buffered: LintBuffer,
}
Expand Down Expand Up @@ -569,14 +569,15 @@ pub trait LintContext: Sized {
impl<'a> EarlyContext<'a> {
fn new(
sess: &'a Session,
lint_store: &'a LintStore,
krate: &'a ast::Crate,
buffered: LintBuffer,
) -> EarlyContext<'a> {
EarlyContext {
sess,
krate,
lint_store: sess.lint_store.borrow(),
builder: LintLevelSets::builder(sess),
lint_store,
builder: LintLevelSets::builder(sess, lint_store),
buffered,
}
}
Expand Down Expand Up @@ -611,7 +612,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
f: F)
where F: FnOnce(&mut Self)
{
let push = self.context.builder.push(attrs);
let push = self.context.builder.push(attrs, &self.context.lint_store);
self.check_id(id);
self.enter_attrs(attrs);
f(self);
Expand Down Expand Up @@ -1473,12 +1474,13 @@ early_lint_methods!(early_lint_pass_impl, []);

fn early_lint_crate<T: EarlyLintPass>(
sess: &Session,
lint_store: &LintStore,
krate: &ast::Crate,
pass: T,
buffered: LintBuffer,
) -> LintBuffer {
let mut cx = EarlyContextAndPass {
context: EarlyContext::new(sess, krate, buffered),
context: EarlyContext::new(sess, lint_store, krate, buffered),
pass,
};

Expand All @@ -1497,28 +1499,30 @@ fn early_lint_crate<T: EarlyLintPass>(

pub fn check_ast_crate<T: EarlyLintPass>(
sess: &Session,
lint_store: &LintStore,
krate: &ast::Crate,
pre_expansion: bool,
builtin_lints: T,
) {
let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion {
(
sess.lint_store.borrow().pre_expansion_passes.iter().map(|p| (p)()).collect(),
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
LintBuffer::default(),
)
} else {
(
sess.lint_store.borrow().early_passes.iter().map(|p| (p)()).collect(),
lint_store.early_passes.iter().map(|p| (p)()).collect(),
sess.buffered_lints.borrow_mut().take().unwrap(),
)
};

if !sess.opts.debugging_opts.no_interleave_lints {
buffered = early_lint_crate(sess, krate, builtin_lints, buffered);
buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered);

if !passes.is_empty() {
buffered = early_lint_crate(
sess,
lint_store,
krate,
EarlyLintPassObjects { lints: &mut passes[..] },
buffered,
Expand All @@ -1529,6 +1533,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
buffered = time(sess, &format!("running lint: {}", pass.name()), || {
early_lint_crate(
sess,
lint_store,
krate,
EarlyLintPassObjects { lints: slice::from_mut(pass) },
buffered,
Expand Down
16 changes: 7 additions & 9 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp;
use crate::hir::HirId;
use crate::ich::StableHashingContext;
use crate::lint::builtin;
use crate::lint::context::CheckLintNameResult;
use crate::lint::context::{LintStore, CheckLintNameResult};
use crate::lint::{self, Lint, LintId, Level, LintSource};
use crate::session::Session;
use crate::util::nodemap::FxHashMap;
Expand Down Expand Up @@ -35,21 +35,20 @@ enum LintSet {
}

impl LintLevelSets {
pub fn new(sess: &Session) -> LintLevelSets {
pub fn new(sess: &Session, lint_store: &LintStore) -> LintLevelSets {
let mut me = LintLevelSets {
list: Vec::new(),
lint_cap: Level::Forbid,
};
me.process_command_line(sess);
me.process_command_line(sess, lint_store);
return me
}

pub fn builder(sess: &Session) -> LintLevelsBuilder<'_> {
LintLevelsBuilder::new(sess, LintLevelSets::new(sess))
pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> {
LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store))
}

fn process_command_line(&mut self, sess: &Session) {
let store = sess.lint_store.borrow();
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
let mut specs = FxHashMap::default();
self.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);

Expand Down Expand Up @@ -186,9 +185,8 @@ impl<'a> LintLevelsBuilder<'a> {
/// #[allow]
///
/// Don't forget to call `pop`!
pub fn push(&mut self, attrs: &[ast::Attribute]) -> BuilderPush {
pub fn push(&mut self, attrs: &[ast::Attribute], store: &LintStore) -> BuilderPush {
let mut specs = FxHashMap::default();
let store = self.sess.lint_store.borrow();
let sess = self.sess;
let bad_attr = |span| {
struct_span_err!(sess, span, E0452, "malformed lint attribute input")
Expand Down
15 changes: 9 additions & 6 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,15 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {

fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = tcx.sess.lint_store.borrow();
let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess),
levels: LintLevelSets::builder(tcx.sess, &store),
tcx: tcx,
store: &*store,
};
let krate = tcx.hir().krate();

let push = builder.levels.push(&krate.attrs);
let push = builder.levels.push(&krate.attrs, &store);
builder.levels.register_id(hir::CRATE_HIR_ID);
for macro_def in &krate.exported_macros {
builder.levels.register_id(macro_def.hir_id);
Expand All @@ -794,19 +796,20 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
tcx.arena.alloc(builder.levels.build_map())
}

struct LintLevelMapBuilder<'tcx> {
struct LintLevelMapBuilder<'a, 'tcx> {
levels: levels::LintLevelsBuilder<'tcx>,
tcx: TyCtxt<'tcx>,
store: &'a LintStore,
}

impl LintLevelMapBuilder<'tcx> {
impl LintLevelMapBuilder<'_, '_> {
fn with_lint_attrs<F>(&mut self,
id: hir::HirId,
attrs: &[ast::Attribute],
f: F)
where F: FnOnce(&mut Self)
{
let push = self.levels.push(attrs);
let push = self.levels.push(attrs, self.store);
if push.changed {
self.levels.register_id(id);
}
Expand All @@ -815,7 +818,7 @@ impl LintLevelMapBuilder<'tcx> {
}
}

impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> {
impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
intravisit::NestedVisitorMap::All(&self.tcx.hir())
}
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ fn configure_and_expand_inner<'a>(
time(sess, "pre-AST-expansion lint checks", || {
lint::check_ast_crate(
sess,
&*sess.lint_store.borrow(),
&krate,
true,
rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
Expand Down Expand Up @@ -556,7 +557,13 @@ pub fn lower_to_hir(
});

time(sess, "early lint checks", || {
lint::check_ast_crate(sess, &krate, false, rustc_lint::BuiltinCombinedEarlyLintPass::new())
lint::check_ast_crate(
sess,
&*sess.lint_store.borrow(),
&krate,
false,
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
)
});

// Discard hygiene data, which isn't required after lowering to HIR.
Expand Down