@@ -21,7 +21,7 @@ use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileN
2121use rustc_session:: filesearch:: { self , sysroot_candidates} ;
2222use rustc_session:: parse:: ParseSess ;
2323use rustc_session:: { lint, CompilerIO , EarlyDiagCtxt , Session } ;
24- use rustc_span:: source_map:: FileLoader ;
24+ use rustc_span:: source_map:: { FileLoader , RealFileLoader , SourceMapInputs } ;
2525use rustc_span:: symbol:: sym;
2626use rustc_span:: FileName ;
2727use std:: path:: PathBuf ;
@@ -336,18 +336,23 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
336336 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
337337 early_dcx. initialize_checked_jobserver ( ) ;
338338
339+ crate :: callbacks:: setup_callbacks ( ) ;
340+
341+ let sysroot = filesearch:: materialize_sysroot ( config. opts . maybe_sysroot . clone ( ) ) ;
342+ let target = config:: build_target_config ( & early_dcx, & config. opts , & sysroot) ;
343+ let file_loader = config. file_loader . unwrap_or_else ( || Box :: new ( RealFileLoader ) ) ;
344+ let path_mapping = config. opts . file_path_mapping ( ) ;
345+ let hash_kind = config. opts . unstable_opts . src_hash_algorithm ( & target) ;
346+
339347 util:: run_in_thread_pool_with_globals (
340348 config. opts . edition ,
341349 config. opts . unstable_opts . threads ,
350+ SourceMapInputs { file_loader, path_mapping, hash_kind } ,
342351 |current_gcx| {
343- crate :: callbacks :: setup_callbacks ( ) ;
344-
352+ // The previous `early_dcx` can't be reused here because it doesn't
353+ // impl `Send`. Creating a new one is fine.
345354 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
346355
347- let sysroot = filesearch:: materialize_sysroot ( config. opts . maybe_sysroot . clone ( ) ) ;
348-
349- let target = config:: build_target_config ( & early_dcx, & config. opts , & sysroot) ;
350-
351356 let codegen_backend = match config. make_codegen_backend {
352357 None => util:: get_codegen_backend (
353358 & early_dcx,
@@ -372,9 +377,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
372377 config. opts . unstable_opts . translate_directionality_markers ,
373378 ) {
374379 Ok ( bundle) => bundle,
375- Err ( e) => {
376- early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ;
377- }
380+ Err ( e) => early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ,
378381 } ;
379382
380383 let mut locale_resources = Vec :: from ( config. locale_resources ) ;
@@ -393,7 +396,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
393396 config. registry . clone ( ) ,
394397 locale_resources,
395398 config. lint_caps ,
396- config. file_loader ,
397399 target,
398400 sysroot,
399401 util:: rustc_version_str ( ) . unwrap_or ( "unknown" ) ,
@@ -440,45 +442,43 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
440442 current_gcx,
441443 } ;
442444
443- rustc_span:: set_source_map ( compiler. sess . psess . clone_source_map ( ) , move || {
444- // There are two paths out of `f`.
445- // - Normal exit.
446- // - Panic, e.g. triggered by `abort_if_errors`.
447- //
448- // We must run `finish_diagnostics` in both cases.
449- let res = {
450- // If `f` panics, `finish_diagnostics` will run during
451- // unwinding because of the `defer`.
452- let mut guar = None ;
453- let sess_abort_guard = defer ( || {
454- guar = compiler. sess . finish_diagnostics ( & config. registry ) ;
455- } ) ;
456-
457- let res = f ( & compiler) ;
458-
459- // If `f` doesn't panic, `finish_diagnostics` will run
460- // normally when `sess_abort_guard` is dropped.
461- drop ( sess_abort_guard) ;
462-
463- // If `finish_diagnostics` emits errors (e.g. stashed
464- // errors) we can't return an error directly, because the
465- // return type of this function is `R`, not `Result<R, E>`.
466- // But we need to communicate the errors' existence to the
467- // caller, otherwise the caller might mistakenly think that
468- // no errors occurred and return a zero exit code. So we
469- // abort (panic) instead, similar to if `f` had panicked.
470- if guar. is_some ( ) {
471- compiler. sess . dcx ( ) . abort_if_errors ( ) ;
472- }
445+ // There are two paths out of `f`.
446+ // - Normal exit.
447+ // - Panic, e.g. triggered by `abort_if_errors`.
448+ //
449+ // We must run `finish_diagnostics` in both cases.
450+ let res = {
451+ // If `f` panics, `finish_diagnostics` will run during
452+ // unwinding because of the `defer`.
453+ let mut guar = None ;
454+ let sess_abort_guard = defer ( || {
455+ guar = compiler. sess . finish_diagnostics ( & config. registry ) ;
456+ } ) ;
457+
458+ let res = f ( & compiler) ;
459+
460+ // If `f` doesn't panic, `finish_diagnostics` will run
461+ // normally when `sess_abort_guard` is dropped.
462+ drop ( sess_abort_guard) ;
463+
464+ // If `finish_diagnostics` emits errors (e.g. stashed
465+ // errors) we can't return an error directly, because the
466+ // return type of this function is `R`, not `Result<R, E>`.
467+ // But we need to communicate the errors' existence to the
468+ // caller, otherwise the caller might mistakenly think that
469+ // no errors occurred and return a zero exit code. So we
470+ // abort (panic) instead, similar to if `f` had panicked.
471+ if guar. is_some ( ) {
472+ compiler. sess . dcx ( ) . abort_if_errors ( ) ;
473+ }
473474
474- res
475- } ;
475+ res
476+ } ;
476477
477- let prof = compiler. sess . prof . clone ( ) ;
478- prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
478+ let prof = compiler. sess . prof . clone ( ) ;
479+ prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
479480
480- res
481- } )
481+ res
482482 } ,
483483 )
484484}
0 commit comments