diff options
| author | bors <bors@rust-lang.org> | 2023-10-16 16:33:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-16 16:33:42 +0000 |
| commit | 4af886f8ab94543caad689ee6bf6a93fa8bd4a98 (patch) | |
| tree | 08d36ed96e86164ed272ced966a8a2e6023fcd2f /compiler/rustc_interface | |
| parent | 98c1e3d95ba7f5d29915dac3f391a296648aa74c (diff) | |
| parent | 59f6f044f5228e039e1310b97f478c79aa745f35 (diff) | |
| download | rust-4af886f8ab94543caad689ee6bf6a93fa8bd4a98.tar.gz rust-4af886f8ab94543caad689ee6bf6a93fa8bd4a98.zip | |
Auto merge of #116731 - Alexendoo:hash-untracked-state, r=oli-obk
Add `Config::hash_untracked_state` callback For context, I'm looking to use [late module passes](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LintStore.html#structfield.late_module_passes) in Clippy which unlike regular late passes run incrementally per module However we have a config file which can change between runs, we need changes to that to invalidate the `lint_mod` query. This PR adds a side channel for us to hash some extra state into `Options` in order to do that This does not make any changes to Clippy, I plan to do that in a PR to the Clippy repo along with some other required changes An alternative implementation would be to add a new query to track this state and override the `lint_mod` query in Clippy to first call that cc `@rust-lang/clippy`
Diffstat (limited to 'compiler/rustc_interface')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 1c330c064ab..3e77a84bf9e 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -5,6 +5,7 @@ use rustc_ast::{self as ast, LitKind, MetaItemKind}; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::defer; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::Lrc; use rustc_errors::registry::Registry; use rustc_errors::{ErrorGuaranteed, Handler}; @@ -260,6 +261,12 @@ pub struct Config { /// This is a callback from the driver that is called when [`ParseSess`] is created. pub parse_sess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>, + /// This is a callback to hash otherwise untracked state used by the caller, if the + /// hash changes between runs the incremental cache will be cleared. + /// + /// e.g. used by Clippy to hash its config file + pub hash_untracked_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>, + /// 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. /// @@ -269,8 +276,6 @@ pub struct Config { /// This is a callback from the driver that is called just after we have populated /// the list of queries. - /// - /// The second parameter is local providers and the third parameter is external providers. pub override_queries: Option<fn(&Session, &mut Providers)>, /// This is a callback from the driver that is called to create a codegen backend. @@ -330,6 +335,12 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se parse_sess_created(&mut sess.parse_sess); } + if let Some(hash_untracked_state) = config.hash_untracked_state { + let mut hasher = StableHasher::new(); + hash_untracked_state(&sess, &mut hasher); + sess.opts.untracked_state_hash = hasher.finish() + } + let compiler = Compiler { sess: Lrc::new(sess), codegen_backend: Lrc::from(codegen_backend), |
