@@ -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,22 @@ 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 loader = config. file_loader . unwrap_or_else ( || Box :: new ( RealFileLoader ) ) ;
337+ let sysroot = filesearch:: materialize_sysroot ( config. opts . maybe_sysroot . clone ( ) ) ;
338+ let target = config:: build_target_config ( & early_dcx, & config. opts , & sysroot) ;
339+ let hash_kind = config. opts . unstable_opts . src_hash_algorithm ( & target) ;
340+
334341 util:: run_in_thread_pool_with_globals (
335342 config. opts . edition ,
336343 config. opts . unstable_opts . threads ,
344+ SourceMapInputs ( loader, config. opts . file_path_mapping ( ) , hash_kind) ,
337345 || {
338- crate :: callbacks :: setup_callbacks ( ) ;
339-
346+ // The previous `early_dcx` can't be reused here because it doesn't
347+ // impl `Send`. Creating a new one is fine.
340348 let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
341349
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-
346350 let codegen_backend = match config. make_codegen_backend {
347351 None => util:: get_codegen_backend (
348352 & early_dcx,
@@ -367,9 +371,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
367371 config. opts . unstable_opts . translate_directionality_markers ,
368372 ) {
369373 Ok ( bundle) => bundle,
370- Err ( e) => {
371- early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ;
372- }
374+ Err ( e) => early_dcx. early_fatal ( format ! ( "failed to load fluent bundle: {e}" ) ) ,
373375 } ;
374376
375377 let mut locale_resources = Vec :: from ( config. locale_resources ) ;
@@ -388,7 +390,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
388390 config. registry . clone ( ) ,
389391 locale_resources,
390392 config. lint_caps ,
391- config. file_loader ,
392393 target,
393394 sysroot,
394395 util:: rustc_version_str ( ) . unwrap_or ( "unknown" ) ,
@@ -431,45 +432,43 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
431432 let compiler =
432433 Compiler { sess, codegen_backend, override_queries : config. override_queries } ;
433434
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- }
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+ }
464464
465- res
466- } ;
465+ res
466+ } ;
467467
468- let prof = compiler. sess . prof . clone ( ) ;
469- prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
468+ let prof = compiler. sess . prof . clone ( ) ;
469+ prof. generic_activity ( "drop_compiler" ) . run ( move || drop ( compiler) ) ;
470470
471- res
472- } )
471+ res
473472 } ,
474473 )
475474}
0 commit comments