Skip to content

Commit 3c5e7e8

Browse files
committed
Simplify Config::track_state.
This is a callback used to track otherwise untracked state. It was added in rust-lang#116731 for Clippy. (It was originally named `hash_untracked_state`, and examples in the rustc-dev-guide still use that name.) The `StableHasher` argument is unused, and probably has never been used. There is a FIXME comment pointing this out, which was added more than a year ago. This commit removes the `StableHasher` callback argument. This also removes the need for `Options::untracked_state_hash`.
1 parent 913e4be commit 3c5e7e8

6 files changed

Lines changed: 8 additions & 21 deletions

File tree

compiler/rustc_interface/src/interface.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItemKind, token};
66
use rustc_codegen_ssa::traits::CodegenBackend;
77
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_data_structures::jobserver::{self, Proxy};
9-
use rustc_data_structures::stable_hasher::StableHasher;
109
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
1110
use rustc_lint::LintStore;
1211
use rustc_middle::ty;
@@ -339,11 +338,7 @@ pub struct Config {
339338
/// This is a callback to track otherwise untracked state used by the caller.
340339
///
341340
/// You can write to `sess.env_depinfo` and `sess.file_depinfo` to track env vars and files.
342-
/// To track any other state you can write to the given hasher. If the hash changes between
343-
/// runs the incremental cache will be cleared.
344-
///
345-
/// The hashing functionality has no known user. FIXME should this be removed?
346-
pub track_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>,
341+
pub track_state: Option<Box<dyn FnOnce(&Session) + Send>>,
347342

348343
/// This is a callback from the driver that is called when we're registering lints;
349344
/// it is called during lint loading when we have the LintStore in a non-shared state.
@@ -468,9 +463,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
468463
}
469464

470465
if let Some(track_state) = config.track_state {
471-
let mut hasher = StableHasher::new();
472-
track_state(&sess, &mut hasher);
473-
sess.opts.untracked_state_hash = hasher.finish()
466+
track_state(&sess);
474467
}
475468

476469
// Even though the session holds the lint store, we can't build the

compiler/rustc_session/src/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,6 @@ impl Default for Options {
14191419
target_triple: TargetTuple::from_tuple(host_tuple()),
14201420
test: false,
14211421
incremental: None,
1422-
untracked_state_hash: Default::default(),
14231422
unstable_opts,
14241423
prints: Vec::new(),
14251424
cg: Default::default(),
@@ -2770,7 +2769,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27702769
target_triple,
27712770
test,
27722771
incremental,
2773-
untracked_state_hash: Default::default(),
27742772
unstable_opts,
27752773
prints,
27762774
cg,

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@ top_level_options!(
332332
/// If `Some`, enable incremental compilation, using the given
333333
/// directory to store intermediate results.
334334
incremental: Option<PathBuf> [UNTRACKED],
335-
/// Set based on the result of the `Config::track_state` callback
336-
/// for custom drivers to invalidate the incremental cache.
337-
#[rustc_lint_opt_deny_field_access("should only be used via `Config::track_state`")]
338-
untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],
339335

340336
unstable_opts: UnstableOptions [SUBSTRUCT] { TARGET_MODIFIER: UnstableOptions(UnstableOptionsTargetModifiers) },
341337
prints: Vec<PrintRequest> [UNTRACKED],

src/doc/rustc-dev-guide/examples/rustc-interface-example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() {
5050
make_codegen_backend: None,
5151
expanded_args: Vec::new(),
5252
ice_file: None,
53-
hash_untracked_state: None,
53+
track_state: None,
5454
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
5555
};
5656
rustc_interface::run_compiler(config, |compiler| {
@@ -72,4 +72,4 @@ fn main() {
7272
}
7373
});
7474
});
75-
}
75+
}

src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn main() {
7878
make_codegen_backend: None,
7979
expanded_args: Vec::new(),
8080
ice_file: None,
81-
hash_untracked_state: None,
81+
track_state: None,
8282
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
8383
};
8484
rustc_interface::run_compiler(config, |compiler| {
@@ -97,4 +97,4 @@ fn main() {
9797
buffer.lock().unwrap().iter().for_each(|diagnostic| {
9898
println!("{diagnostic:#?}");
9999
});
100-
}
100+
}

src/tools/clippy/src/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct RustcCallbacks {
121121
impl rustc_driver::Callbacks for RustcCallbacks {
122122
fn config(&mut self, config: &mut interface::Config) {
123123
let clippy_args_var = self.clippy_args_var.take();
124-
config.track_state = Some(Box::new(move |sess, _hasher| {
124+
config.track_state = Some(Box::new(move |sess| {
125125
track_clippy_args(sess, clippy_args_var.as_deref());
126126
}));
127127
config.extra_symbols = sym::EXTRA_SYMBOLS.into();
@@ -138,7 +138,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
138138
let conf_path = clippy_config::lookup_conf_file();
139139
let previous = config.register_lints.take();
140140
let clippy_args_var = self.clippy_args_var.take();
141-
config.track_state = Some(Box::new(move |sess, _hasher| {
141+
config.track_state = Some(Box::new(move |sess| {
142142
track_clippy_args(sess, clippy_args_var.as_deref());
143143
track_files(sess);
144144

0 commit comments

Comments
 (0)