mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Simplify Config::track_state.
This is a callback used to track otherwise untracked state. It was added in #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`.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::jobserver::{self, Proxy};
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
|
||||
use rustc_lint::LintStore;
|
||||
use rustc_middle::ty;
|
||||
@@ -339,11 +338,7 @@ pub struct Config {
|
||||
/// This is a callback to track otherwise untracked state used by the caller.
|
||||
///
|
||||
/// You can write to `sess.env_depinfo` and `sess.file_depinfo` to track env vars and files.
|
||||
/// To track any other state you can write to the given hasher. If the hash changes between
|
||||
/// runs the incremental cache will be cleared.
|
||||
///
|
||||
/// The hashing functionality has no known user. FIXME should this be removed?
|
||||
pub track_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>,
|
||||
pub track_state: Option<Box<dyn FnOnce(&Session) + Send>>,
|
||||
|
||||
/// This is a callback from the driver that is called when we're registering lints;
|
||||
/// 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
|
||||
}
|
||||
|
||||
if let Some(track_state) = config.track_state {
|
||||
let mut hasher = StableHasher::new();
|
||||
track_state(&sess, &mut hasher);
|
||||
sess.opts.untracked_state_hash = hasher.finish()
|
||||
track_state(&sess);
|
||||
}
|
||||
|
||||
// Even though the session holds the lint store, we can't build the
|
||||
|
||||
@@ -1419,7 +1419,6 @@ fn default() -> Options {
|
||||
target_triple: TargetTuple::from_tuple(host_tuple()),
|
||||
test: false,
|
||||
incremental: None,
|
||||
untracked_state_hash: Default::default(),
|
||||
unstable_opts,
|
||||
prints: Vec::new(),
|
||||
cg: Default::default(),
|
||||
@@ -2770,7 +2769,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||
target_triple,
|
||||
test,
|
||||
incremental,
|
||||
untracked_state_hash: Default::default(),
|
||||
unstable_opts,
|
||||
prints,
|
||||
cg,
|
||||
|
||||
@@ -332,10 +332,6 @@ pub struct Options {
|
||||
/// If `Some`, enable incremental compilation, using the given
|
||||
/// directory to store intermediate results.
|
||||
incremental: Option<PathBuf> [UNTRACKED],
|
||||
/// Set based on the result of the `Config::track_state` callback
|
||||
/// for custom drivers to invalidate the incremental cache.
|
||||
#[rustc_lint_opt_deny_field_access("should only be used via `Config::track_state`")]
|
||||
untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],
|
||||
|
||||
unstable_opts: UnstableOptions [SUBSTRUCT] { TARGET_MODIFIER: UnstableOptions(UnstableOptionsTargetModifiers) },
|
||||
prints: Vec<PrintRequest> [UNTRACKED],
|
||||
|
||||
@@ -50,7 +50,7 @@ fn main() {
|
||||
make_codegen_backend: None,
|
||||
expanded_args: Vec::new(),
|
||||
ice_file: None,
|
||||
hash_untracked_state: None,
|
||||
track_state: None,
|
||||
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
|
||||
};
|
||||
rustc_interface::run_compiler(config, |compiler| {
|
||||
@@ -72,4 +72,4 @@ fn main() {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ fn main() {
|
||||
make_codegen_backend: None,
|
||||
expanded_args: Vec::new(),
|
||||
ice_file: None,
|
||||
hash_untracked_state: None,
|
||||
track_state: None,
|
||||
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
|
||||
};
|
||||
rustc_interface::run_compiler(config, |compiler| {
|
||||
@@ -97,4 +97,4 @@ fn main() {
|
||||
buffer.lock().unwrap().iter().for_each(|diagnostic| {
|
||||
println!("{diagnostic:#?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ struct RustcCallbacks {
|
||||
impl rustc_driver::Callbacks for RustcCallbacks {
|
||||
fn config(&mut self, config: &mut interface::Config) {
|
||||
let clippy_args_var = self.clippy_args_var.take();
|
||||
config.track_state = Some(Box::new(move |sess, _hasher| {
|
||||
config.track_state = Some(Box::new(move |sess| {
|
||||
track_clippy_args(sess, clippy_args_var.as_deref());
|
||||
}));
|
||||
config.extra_symbols = sym::EXTRA_SYMBOLS.into();
|
||||
@@ -138,7 +138,7 @@ fn config(&mut self, config: &mut interface::Config) {
|
||||
let conf_path = clippy_config::lookup_conf_file();
|
||||
let previous = config.register_lints.take();
|
||||
let clippy_args_var = self.clippy_args_var.take();
|
||||
config.track_state = Some(Box::new(move |sess, _hasher| {
|
||||
config.track_state = Some(Box::new(move |sess| {
|
||||
track_clippy_args(sess, clippy_args_var.as_deref());
|
||||
track_files(sess);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user