# Parallel compiler audit meeting: LintStore
###### tags: `parallel-compiler`
## TODO
- remove interior locks on LintStore, via storing builders
- document lack of borrow_mut after registration
- explore moving LintStore to TyCtxt
## Task: Session.lint_store (LintStore)
- `git remote add sim git@github.com:Mark-Simulacrum/rust.git`
- `git fetch sim no-lock-lint`
- `git checkout no-lock-lint`
- https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/session/mod.rs#L81-L87
Background information:
- lints are run via pass objects
- some preliminary cleanup work has been done (links below lead to no-lock-lint branch)
- there is a mapping of `pass -> [lints]`
- used solely for discovery of lint names, etc.
- Session has a [`pub RwLock<LintStore>`](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/session/mod.rs#L81-L87)
- [`LintStore`](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/lint/context.rs#L50)
- Lints are registered via `LintStore::register_*passes*`
- Lints are done registering after [`register_plugins`](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc_interface/passes.rs#L296)
Preliminary audit conclusions:
- public field on Session made this hard
- code is lock-correct, we only borrow_mut the entire store for short, well-defined, periods during registration, otherwise just steal fields
## Locations of interest:
Registration:
- Calls into &mut self [methods](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/lint/context.rs#L186) on LintStore
- occurs in ~3 places:
- No lock, [building session](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc_interface/util.rs#L111-L115), calls https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc_lint/lib.rs#L199
- plugin registration
- https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc_interface/passes.rs#L296
- also in individual plugins' registar, which has access to Session. Plugins bypass the "Registrar" to register directly on session via borrow_mut().
Lint pass running:
- we register already created passes
- later, take the vector of passes out and run, with `&mut Pass` access.
- we have several sets of passes, run in a few locations:
- [late_module_passses](https://github.com/Mark-Simulacrum/rust/blob/no-lint-lock/src/librustc/lint/context.rs#L1407) are generated via `fresh_late_module_passes`
- [late_passes](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/lint/context.rs#L1447) are just take() out
- [pre-expansion and early passes](https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc/lint/context.rs#L1562-L1567) also just taken
CLI printing/info of details:
- queries the lints to print things out: https://github.com/Mark-Simulacrum/rust/blob/no-lock-lint/src/librustc_driver/lib.rs#L207
- a few other places for similar cases:
src/librustc/lint/mod.rs:650: let lints = sess.lint_store.borrow();
src/librustc/lint/mod.rs:756: let store = tcx.sess.lint_store.borrow();
src/librustc/lint/context.rs:1558: let store = sess.lint_store.borrow();
src/librustc/lint/context.rs:1627: match tcx.sess.lint_store.borrow().find_lints(&s) {