@@ -27,7 +27,7 @@ use crate::parse_execution::{EndExecutionReason, ParseExecutionContext};
27
27
use crate :: parse_tree:: { parse_source, ParsedSourceRef } ;
28
28
use crate :: proc:: { job_reap, JobGroupRef , JobList , JobRef , ProcStatus } ;
29
29
use crate :: signal:: { signal_check_cancel, signal_clear_cancel, Signal } ;
30
- use crate :: threads:: assert_is_main_thread;
30
+ use crate :: threads:: { assert_is_main_thread, MainThread } ;
31
31
use crate :: util:: get_time;
32
32
use crate :: wait_handle:: WaitHandleStore ;
33
33
use crate :: wchar:: { wstr, WString , L } ;
@@ -414,19 +414,11 @@ impl Parser {
414
414
false
415
415
}
416
416
417
- /// Get the "principal" parser, whatever that is.
417
+ /// Get the "principal" parser, whatever that is. Can only be called by the main thread.
418
418
pub fn principal_parser ( ) -> & ' static Parser {
419
- // XXX: We use `static mut` as a hack to work around the fact that Parser doesn't implement
420
- // Sync! Even though we are wrapping it in Lazy<> and it compiles without an error, that
421
- // doesn't mean this is safe to access across threads!
422
- static mut PRINCIPAL : Lazy < ParserRef > =
423
- Lazy :: new ( || Parser :: new ( EnvStack :: principal ( ) . clone ( ) , true ) ) ;
424
- // XXX: Creating and using multiple (read or write!) references to the same mutable static
425
- // is undefined behavior!
426
- unsafe {
427
- PRINCIPAL . assert_can_execute ( ) ;
428
- & PRINCIPAL
429
- }
419
+ static PRINCIPAL : Lazy < MainThread < ParserRef > > =
420
+ Lazy :: new ( || MainThread :: new ( Parser :: new ( EnvStack :: principal ( ) . clone ( ) , true ) ) ) ;
421
+ PRINCIPAL . get ( )
430
422
}
431
423
432
424
/// Assert that this parser is allowed to execute on the current thread.
0 commit comments