@@ -29,8 +29,8 @@ use std::num::NonZero;
2929use std:: ops:: Range ;
3030use std:: path:: PathBuf ;
3131use std:: str:: FromStr ;
32- use std:: sync:: Arc ;
33- use std:: sync:: atomic :: { AtomicBool , AtomicI32 , Ordering } ;
32+ use std:: sync:: atomic :: { AtomicI32 , Ordering } ;
33+ use std:: sync:: { Arc , Once } ;
3434
3535use miri:: {
3636 BacktraceStyle , BorrowTrackerMethod , MiriConfig , ProvenanceMode , RetagFields , ValidationMode ,
@@ -335,26 +335,24 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
335335
336336/// The global logger can only be set once per process, so track
337337/// whether that already happened.
338- static LOGGER_INITED : AtomicBool = AtomicBool :: new ( false ) ;
338+ static LOGGER_INITED : Once = Once :: new ( ) ;
339339
340340fn init_early_loggers ( early_dcx : & EarlyDiagCtxt ) {
341- // Now for rustc. We only initialize `rustc` if the env var is set (so the user asked for it).
341+ // We only initialize `rustc` if the env var is set (so the user asked for it).
342342 // If it is not set, we avoid initializing now so that we can initialize later with our custom
343- // settings, and *not* log anything for what happens before `miri` gets started .
343+ // settings, and *not* log anything for what happens before `miri` starts interpreting .
344344 if env:: var_os ( "RUSTC_LOG" ) . is_some ( ) {
345- rustc_driver:: init_logger ( early_dcx, rustc_logger_config ( ) ) ;
346- assert ! ( !LOGGER_INITED . swap( true , Ordering :: AcqRel ) ) ;
345+ LOGGER_INITED . call_once ( || {
346+ rustc_driver:: init_logger ( early_dcx, rustc_logger_config ( ) ) ;
347+ } ) ;
347348 }
348349}
349350
350351fn init_late_loggers ( early_dcx : & EarlyDiagCtxt , tcx : TyCtxt < ' _ > ) {
351352 // If the logger is not yet initialized, initialize it.
352- if ! LOGGER_INITED . swap ( true , Ordering :: AcqRel ) {
353+ LOGGER_INITED . call_once ( || {
353354 rustc_driver:: init_logger ( early_dcx, rustc_logger_config ( ) ) ;
354- }
355- // There's a little race condition here in many-seeds mode, where we don't wait for the thread
356- // that is doing the initializing. But if you want to debug things with extended logging you
357- // probably won't use many-seeds mode anyway.
355+ } ) ;
358356
359357 // If `MIRI_BACKTRACE` is set and `RUSTC_CTFE_BACKTRACE` is not, set `RUSTC_CTFE_BACKTRACE`.
360358 // Do this late, so we ideally only apply this to Miri's errors.
@@ -742,8 +740,9 @@ fn main() {
742740 if many_seeds. is_some ( ) && miri_config. seed . is_some ( ) {
743741 show_error ! ( "Only one of `-Zmiri-seed` and `-Zmiri-many-seeds can be set" ) ;
744742 }
743+
744+ // Ensure we have parallelism for many-seeds mode.
745745 if many_seeds. is_some ( ) && !rustc_args. iter ( ) . any ( |arg| arg. starts_with ( "-Zthreads=" ) ) {
746- // Ensure we have parallelism for many-seeds mode.
747746 rustc_args. push ( format ! (
748747 "-Zthreads={}" ,
749748 std:: thread:: available_parallelism( ) . map_or( 1 , |n| n. get( ) )
0 commit comments