Add Config::hash_untracked_state
callback
This commit is contained in:
parent
34bc5716b5
commit
59f6f044f5
7 changed files with 28 additions and 7 deletions
|
@ -312,6 +312,7 @@ fn run_compiler(
|
|||
locale_resources: DEFAULT_LOCALE_RESOURCES,
|
||||
lint_caps: Default::default(),
|
||||
parse_sess_created: None,
|
||||
hash_untracked_state: None,
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
make_codegen_backend,
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -1047,6 +1047,7 @@ impl Default for Options {
|
|||
target_triple: TargetTriple::from_triple(host_triple()),
|
||||
test: false,
|
||||
incremental: None,
|
||||
untracked_state_hash: Default::default(),
|
||||
unstable_opts: Default::default(),
|
||||
prints: Vec::new(),
|
||||
cg: Default::default(),
|
||||
|
@ -2889,6 +2890,7 @@ pub fn build_session_options(
|
|||
target_triple,
|
||||
test,
|
||||
incremental,
|
||||
untracked_state_hash: Default::default(),
|
||||
unstable_opts,
|
||||
prints,
|
||||
cg,
|
||||
|
@ -3167,17 +3169,17 @@ impl PpMode {
|
|||
/// we have an opt-in scheme here, so one is hopefully forced to think about
|
||||
/// how the hash should be calculated when adding a new command-line argument.
|
||||
pub(crate) mod dep_tracking {
|
||||
use super::Polonius;
|
||||
use super::{
|
||||
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
|
||||
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
|
||||
LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes,
|
||||
LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Polonius,
|
||||
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
|
||||
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
|
||||
};
|
||||
use crate::lint;
|
||||
use crate::options::WasiExecModel;
|
||||
use crate::utils::{NativeLib, NativeLibKind};
|
||||
use crate::utils::NativeLib;
|
||||
use rustc_data_structures::stable_hasher::Hash64;
|
||||
use rustc_errors::LanguageIdentifier;
|
||||
use rustc_feature::UnstableFeatures;
|
||||
use rustc_span::edition::Edition;
|
||||
|
@ -3233,6 +3235,7 @@ pub(crate) mod dep_tracking {
|
|||
usize,
|
||||
NonZeroUsize,
|
||||
u64,
|
||||
Hash64,
|
||||
String,
|
||||
PathBuf,
|
||||
lint::Level,
|
||||
|
@ -3247,14 +3250,12 @@ pub(crate) mod dep_tracking {
|
|||
MergeFunctions,
|
||||
PanicStrategy,
|
||||
RelroLevel,
|
||||
Passes,
|
||||
OptLevel,
|
||||
LtoCli,
|
||||
DebugInfo,
|
||||
DebugInfoCompression,
|
||||
UnstableFeatures,
|
||||
NativeLib,
|
||||
NativeLibKind,
|
||||
SanitizerSet,
|
||||
CFGuard,
|
||||
CFProtection,
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::search_paths::SearchPath;
|
|||
use crate::utils::NativeLib;
|
||||
use crate::{lint, EarlyErrorHandler};
|
||||
use rustc_data_structures::profiling::TimePassesFormat;
|
||||
use rustc_data_structures::stable_hasher::Hash64;
|
||||
use rustc_errors::ColorConfig;
|
||||
use rustc_errors::{LanguageIdentifier, TerminalUrl};
|
||||
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, SanitizerSet};
|
||||
|
@ -158,6 +159,10 @@ top_level_options!(
|
|||
/// directory to store intermediate results.
|
||||
incremental: Option<PathBuf> [UNTRACKED],
|
||||
assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
|
||||
/// Set by the `Config::hash_untracked_state` callback for custom
|
||||
/// drivers to invalidate the incremental cache
|
||||
#[rustc_lint_opt_deny_field_access("should only be used via `Config::hash_untracked_state`")]
|
||||
untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],
|
||||
|
||||
unstable_opts: UnstableOptions [SUBSTRUCT],
|
||||
prints: Vec<PrintRequest> [UNTRACKED],
|
||||
|
|
|
@ -262,6 +262,7 @@ pub(crate) fn create_config(
|
|||
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
|
||||
lint_caps,
|
||||
parse_sess_created: None,
|
||||
hash_untracked_state: None,
|
||||
register_lints: Some(Box::new(crate::lint::register_lints)),
|
||||
override_queries: Some(|_sess, providers| {
|
||||
// We do not register late module lints, so this only runs `MissingDoc`.
|
||||
|
|
|
@ -104,6 +104,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
|
|||
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
|
||||
lint_caps,
|
||||
parse_sess_created: None,
|
||||
hash_untracked_state: None,
|
||||
register_lints: Some(Box::new(crate::lint::register_lints)),
|
||||
override_queries: None,
|
||||
make_codegen_backend: None,
|
||||
|
|
|
@ -57,6 +57,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
|||
locale_resources: &[],
|
||||
lint_caps: Default::default(),
|
||||
parse_sess_created: None,
|
||||
hash_untracked_state: None,
|
||||
register_lints: None,
|
||||
override_queries: None,
|
||||
make_codegen_backend: None,
|
||||
|
|
Loading…
Add table
Reference in a new issue