diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-23 22:19:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-23 22:19:10 +0200 |
| commit | 7c043e284a9a3e71ee2e5d34be8e40abf1daa49e (patch) | |
| tree | cb01ad8e8d25608e0626c6596097108098606cf2 /src/librustc_interface/interface.rs | |
| parent | 4b9fbfbc29dbf0192dc0a9ed2bf6d61f2e7b971b (diff) | |
| parent | 4e8d1b229217c7c83ce96b44410ccae9470db973 (diff) | |
| download | rust-7c043e284a9a3e71ee2e5d34be8e40abf1daa49e.tar.gz rust-7c043e284a9a3e71ee2e5d34be8e40abf1daa49e.zip | |
Rollup merge of #65193 - Mark-Simulacrum:lockless-lintstore, r=nikomatsakis
Lockless LintStore
This removes mutability from the lint store after registration. Each commit stands alone, for the most part, though they don't make sense out of sequence.
The intent here is to move LintStore to a more parallel-friendly architecture, although also just a cleaner one from an implementation perspective. Specifically, this has the following changes:
* We no longer implicitly register lints when registering lint passes
* For the most part this means that registration calls now likely want to call something like:
`lint_store.register_lints(&Pass::get_lints())` as well as `register_*_pass`.
* In theory this is a simplification as it's much easier for folks to just register lints and then have passes that implement whichever lint however they want, rather than necessarily tying passes to lints.
* Lint passes still have a list of associated lints, but a followup PR could plausibly change that
* This list must be known for a given pass type, not instance, i.e., `fn get_lints()` is the signature instead of `fn get_lints(&self)` as before.
* We do not store pass objects, instead storing constructor functions. This means we always get new passes when running lints (this happens approximately once though for a given compiler session, so no behavior change is expected).
* Registration API is _much_ simpler: generally all functions are just taking `Fn() -> PassObject` rather than several different `bool`s.
Diffstat (limited to 'src/librustc_interface/interface.rs')
| -rw-r--r-- | src/librustc_interface/interface.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index 5e1ad3e61dd..24ea0fc8bf6 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -39,6 +39,7 @@ pub struct Compiler { pub(crate) queries: Queries, pub(crate) cstore: Lrc<CStore>, pub(crate) crate_name: Option<String>, + pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>, } impl Compiler { @@ -137,6 +138,13 @@ pub struct Config { pub crate_name: Option<String>, pub lint_caps: FxHashMap<lint::LintId, lint::Level>, + + /// This is a callback from the driver that is called when we're registering lints; + /// it is called during plugin registration when we have the LintStore in a non-shared state. + /// + /// Note that if you find a Some here you probably want to call that function in the new + /// function being registered. + pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>, } pub fn run_compiler_in_existing_thread_pool<F, R>(config: Config, f: F) -> R @@ -165,6 +173,7 @@ where output_file: config.output_file, queries: Default::default(), crate_name: config.crate_name, + register_lints: config.register_lints, }; let _sess_abort_error = OnDrop(|| { |
