@@ -29,8 +29,8 @@ use std::num::NonZero;
29
29
use std:: ops:: Range ;
30
30
use std:: path:: PathBuf ;
31
31
use 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 } ;
34
34
35
35
use miri:: {
36
36
BacktraceStyle , BorrowTrackerMethod , MiriConfig , ProvenanceMode , RetagFields , ValidationMode ,
@@ -335,26 +335,24 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
335
335
336
336
/// The global logger can only be set once per process, so track
337
337
/// whether that already happened.
338
- static LOGGER_INITED : AtomicBool = AtomicBool :: new ( false ) ;
338
+ static LOGGER_INITED : Once = Once :: new ( ) ;
339
339
340
340
fn 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).
342
342
// 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 .
344
344
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
+ } ) ;
347
348
}
348
349
}
349
350
350
351
fn init_late_loggers ( early_dcx : & EarlyDiagCtxt , tcx : TyCtxt < ' _ > ) {
351
352
// If the logger is not yet initialized, initialize it.
352
- if ! LOGGER_INITED . swap ( true , Ordering :: AcqRel ) {
353
+ LOGGER_INITED . call_once ( || {
353
354
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
+ } ) ;
358
356
359
357
// If `MIRI_BACKTRACE` is set and `RUSTC_CTFE_BACKTRACE` is not, set `RUSTC_CTFE_BACKTRACE`.
360
358
// Do this late, so we ideally only apply this to Miri's errors.
@@ -742,8 +740,9 @@ fn main() {
742
740
if many_seeds. is_some ( ) && miri_config. seed . is_some ( ) {
743
741
show_error ! ( "Only one of `-Zmiri-seed` and `-Zmiri-many-seeds can be set" ) ;
744
742
}
743
+
744
+ // Ensure we have parallelism for many-seeds mode.
745
745
if many_seeds. is_some ( ) && !rustc_args. iter ( ) . any ( |arg| arg. starts_with ( "-Zthreads=" ) ) {
746
- // Ensure we have parallelism for many-seeds mode.
747
746
rustc_args. push ( format ! (
748
747
"-Zthreads={}" ,
749
748
std:: thread:: available_parallelism( ) . map_or( 1 , |n| n. get( ) )
0 commit comments