@@ -19,7 +19,7 @@ use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileN
19
19
use rustc_session:: filesearch:: { self , sysroot_candidates} ;
20
20
use rustc_session:: parse:: ParseSess ;
21
21
use rustc_session:: { lint, CompilerIO , EarlyDiagCtxt , Session } ;
22
- use rustc_span:: source_map:: FileLoader ;
22
+ use rustc_span:: source_map:: { FileLoader , RealFileLoader , SourceMapInputs } ;
23
23
use rustc_span:: symbol:: sym;
24
24
use rustc_span:: FileName ;
25
25
use std:: path:: PathBuf ;
@@ -331,18 +331,22 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
331
331
let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
332
332
early_dcx. initialize_checked_jobserver ( ) ;
333
333
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
+
334
341
util:: run_in_thread_pool_with_globals (
335
342
config. opts . edition ,
336
343
config. opts . unstable_opts . threads ,
344
+ SourceMapInputs ( loader, config. opts . file_path_mapping ( ) , hash_kind) ,
337
345
|| {
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.
340
348
let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
341
349
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
-
346
350
let codegen_backend = match config. make_codegen_backend {
347
351
None => util:: get_codegen_backend (
348
352
& early_dcx,
@@ -367,9 +371,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
367
371
config. opts . unstable_opts . translate_directionality_markers ,
368
372
) {
369
373
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}" ) ) ,
373
375
} ;
374
376
375
377
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
388
390
config. registry . clone ( ) ,
389
391
locale_resources,
390
392
config. lint_caps ,
391
- config. file_loader ,
392
393
target,
393
394
sysroot,
394
395
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
431
432
let compiler =
432
433
Compiler { sess, codegen_backend, override_queries : config. override_queries } ;
433
434
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
+ }
464
464
465
- res
466
- } ;
465
+ res
466
+ } ;
467
467
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) ) ;
470
470
471
- res
472
- } )
471
+ res
473
472
} ,
474
473
)
475
474
}
0 commit comments