@@ -19,7 +19,7 @@ use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileN
1919use rustc_session:: filesearch:: { self , sysroot_candidates} ;
2020use rustc_session:: parse:: ParseSess ;
2121use rustc_session:: { lint, CompilerIO , EarlyDiagCtxt , Session } ;
22- use rustc_span:: source_map:: FileLoader ;
22+ use rustc_span:: source_map:: { FileLoader , RealFileLoader , SourceMapInputs } ;
2323use rustc_span:: symbol:: sym;
2424use rustc_span:: FileName ;
2525use std:: path:: PathBuf ;
@@ -331,18 +331,23 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
331331 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
332332 early_dcx. initialize_checked_jobserver ( ) ;
333333
334+ crate :: callbacks:: setup_callbacks ( ) ;
335+
336+ let sysroot = filesearch:: materialize_sysroot ( config. opts . maybe_sysroot . clone ( ) ) ;
337+ let target = config:: build_target_config ( & early_dcx, & config. opts , & sysroot) ;
338+ let file_loader = config. file_loader . unwrap_or_else ( || Box :: new ( RealFileLoader ) ) ;
339+ let path_mapping = config. opts . file_path_mapping ( ) ;
340+ let hash_kind = config. opts . unstable_opts . src_hash_algorithm ( & target) ;
341+
334342 util:: run_in_thread_pool_with_globals (
335343 config. opts . edition ,
336344 config. opts . unstable_opts . threads ,
345+ SourceMapInputs { file_loader, path_mapping, hash_kind } ,
337346 || {
338- crate :: callbacks :: setup_callbacks ( ) ;
339-
347+ // The previous `early_dcx` can't be reused here because it doesn't
348+ // impl `Send`. Creating a new one is fine.
340349 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
341350
342- let sysroot = filesearch:: materialize_sysroot ( config. opts . maybe_sysroot . clone ( ) ) ;
343-
344- let target = config:: build_target_config ( & early_dcx, & config. opts , & sysroot) ;
345-
346351 let codegen_backend = match config. make_codegen_backend {
347352 None => util:: get_codegen_backend (
348353 & early_dcx,
@@ -367,9 +372,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
367372 config. opts . unstable_opts . translate_directionality_markers ,
368373 ) {
369374 Ok ( bundle) => bundle,
370- Err ( e) => {
371- early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ;
372- }
375+ Err ( e) => early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ,
373376 } ;
374377
375378 let mut locale_resources = Vec :: from ( config. locale_resources ) ;
@@ -388,7 +391,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
388391 config. registry . clone ( ) ,
389392 locale_resources,
390393 config. lint_caps ,
391- config. file_loader ,
392394 target,
393395 sysroot,
394396 util:: rustc_version_str ( ) . unwrap_or ( "unknown" ) ,
@@ -431,45 +433,43 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
431433 let compiler =
432434 Compiler { sess, codegen_backend, override_queries : config. override_queries } ;
433435
434- rustc_span:: set_source_map ( compiler. sess . psess . clone_source_map ( ) , move || {
435- // There are two paths out of `f`.
436- // - Normal exit.
437- // - Panic, e.g. triggered by `abort_if_errors`.
438- //
439- // We must run `finish_diagnostics` in both cases.
440- let res = {
441- // If `f` panics, `finish_diagnostics` will run during
442- // unwinding because of the `defer`.
443- let mut guar = None ;
444- let sess_abort_guard = defer ( || {
445- guar = compiler. sess . finish_diagnostics ( & config. registry ) ;
446- } ) ;
447-
448- let res = f ( & compiler) ;
449-
450- // If `f` doesn't panic, `finish_diagnostics` will run
451- // normally when `sess_abort_guard` is dropped.
452- drop ( sess_abort_guard) ;
453-
454- // If `finish_diagnostics` emits errors (e.g. stashed
455- // errors) we can't return an error directly, because the
456- // return type of this function is `R`, not `Result<R, E>`.
457- // But we need to communicate the errors' existence to the
458- // caller, otherwise the caller might mistakenly think that
459- // no errors occurred and return a zero exit code. So we
460- // abort (panic) instead, similar to if `f` had panicked.
461- if guar. is_some ( ) {
462- compiler. sess . dcx ( ) . abort_if_errors ( ) ;
463- }
436+ // There are two paths out of `f`.
437+ // - Normal exit.
438+ // - Panic, e.g. triggered by `abort_if_errors`.
439+ //
440+ // We must run `finish_diagnostics` in both cases.
441+ let res = {
442+ // If `f` panics, `finish_diagnostics` will run during
443+ // unwinding because of the `defer`.
444+ let mut guar = None ;
445+ let sess_abort_guard = defer ( || {
446+ guar = compiler. sess . finish_diagnostics ( & config. registry ) ;
447+ } ) ;
448+
449+ let res = f ( & compiler) ;
450+
451+ // If `f` doesn't panic, `finish_diagnostics` will run
452+ // normally when `sess_abort_guard` is dropped.
453+ drop ( sess_abort_guard) ;
454+
455+ // If `finish_diagnostics` emits errors (e.g. stashed
456+ // errors) we can't return an error directly, because the
457+ // return type of this function is `R`, not `Result<R, E>`.
458+ // But we need to communicate the errors' existence to the
459+ // caller, otherwise the caller might mistakenly think that
460+ // no errors occurred and return a zero exit code. So we
461+ // abort (panic) instead, similar to if `f` had panicked.
462+ if guar. is_some ( ) {
463+ compiler. sess . dcx ( ) . abort_if_errors ( ) ;
464+ }
464465
465- res
466- } ;
466+ res
467+ } ;
467468
468- let prof = compiler. sess . prof . clone ( ) ;
469- prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
469+ let prof = compiler. sess . prof . clone ( ) ;
470+ prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
470471
471- res
472- } )
472+ res
473473 } ,
474474 )
475475}
0 commit comments