@@ -22,7 +22,6 @@ use rustc_session::parse::ParseSess;
2222use rustc_session:: { CompilerIO , EarlyDiagCtxt , Session , lint} ;
2323use rustc_span:: source_map:: { FileLoader , RealFileLoader , SourceMapInputs } ;
2424use rustc_span:: { FileName , sym} ;
25- use rustc_target:: spec:: Target ;
2625use tracing:: trace;
2726
2827use crate :: util;
@@ -337,11 +336,14 @@ pub struct Config {
337336 /// This is a callback from the driver that is called when [`ParseSess`] is created.
338337 pub psess_created : Option < Box < dyn FnOnce ( & mut ParseSess ) + Send > > ,
339338
340- /// This is a callback to hash otherwise untracked state used by the caller, if the
341- /// hash changes between runs the incremental cache will be cleared.
339+ /// This is a callback to track otherwise untracked state used by the caller.
342340 ///
343- /// e.g. used by Clippy to hash its config file
344- pub hash_untracked_state : Option < Box < dyn FnOnce ( & Session , & mut StableHasher ) + Send > > ,
341+ /// 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 > > ,
345347
346348 /// This is a callback from the driver that is called when we're registering lints;
347349 /// it is called during lint loading when we have the LintStore in a non-shared state.
@@ -364,8 +366,7 @@ pub struct Config {
364366 /// hotswapping branch of cg_clif" for "setting the codegen backend from a
365367 /// custom driver where the custom codegen backend has arbitrary data."
366368 /// (See #102759.)
367- pub make_codegen_backend :
368- Option < Box < dyn FnOnce ( & config:: Options , & Target ) -> Box < dyn CodegenBackend > + Send > > ,
369+ pub make_codegen_backend : Option < Box < dyn FnOnce ( & Session ) -> Box < dyn CodegenBackend > + Send > > ,
369370
370371 /// The inner atomic value is set to true when a feature marked as `internal` is
371372 /// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
@@ -419,20 +420,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
419420 // impl `Send`. Creating a new one is fine.
420421 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
421422
422- let codegen_backend = match config. make_codegen_backend {
423- None => util:: get_codegen_backend (
424- & early_dcx,
425- & config. opts . sysroot ,
426- config. opts . unstable_opts . codegen_backend . as_deref ( ) ,
427- & target,
428- ) ,
429- Some ( make_codegen_backend) => {
430- // N.B. `make_codegen_backend` takes precedence over
431- // `target.default_codegen_backend`, which is ignored in this case.
432- make_codegen_backend ( & config. opts , & target)
433- }
434- } ;
435-
436423 let temps_dir = config. opts . unstable_opts . temps_dir . as_deref ( ) . map ( PathBuf :: from) ;
437424
438425 let mut sess = rustc_session:: build_session (
@@ -450,6 +437,19 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
450437 config. using_internal_features ,
451438 ) ;
452439
440+ let codegen_backend = match config. make_codegen_backend {
441+ None => util:: get_codegen_backend (
442+ & early_dcx,
443+ & sess. opts . sysroot ,
444+ sess. opts . unstable_opts . codegen_backend . as_deref ( ) ,
445+ & sess. target ,
446+ ) ,
447+ Some ( make_codegen_backend) => {
448+ // N.B. `make_codegen_backend` takes precedence over
449+ // `target.default_codegen_backend`, which is ignored in this case.
450+ make_codegen_backend ( & sess)
451+ }
452+ } ;
453453 codegen_backend. init ( & sess) ;
454454 sess. replaced_intrinsics = FxHashSet :: from_iter ( codegen_backend. replaced_intrinsics ( ) ) ;
455455 sess. thin_lto_supported = codegen_backend. thin_lto_supported ( ) ;
@@ -467,9 +467,9 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
467467 psess_created ( & mut sess. psess ) ;
468468 }
469469
470- if let Some ( hash_untracked_state ) = config. hash_untracked_state {
470+ if let Some ( track_state ) = config. track_state {
471471 let mut hasher = StableHasher :: new ( ) ;
472- hash_untracked_state ( & sess, & mut hasher) ;
472+ track_state ( & sess, & mut hasher) ;
473473 sess. opts . untracked_state_hash = hasher. finish ( )
474474 }
475475
0 commit comments