@@ -21,7 +21,7 @@ use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileN
21
21
use rustc_session:: filesearch:: { self , sysroot_candidates} ;
22
22
use rustc_session:: parse:: ParseSess ;
23
23
use rustc_session:: { lint, CompilerIO , EarlyDiagCtxt , Session } ;
24
- use rustc_span:: source_map:: FileLoader ;
24
+ use rustc_span:: source_map:: { FileLoader , RealFileLoader , SourceMapInputs } ;
25
25
use rustc_span:: symbol:: sym;
26
26
use rustc_span:: FileName ;
27
27
use std:: path:: PathBuf ;
@@ -336,18 +336,23 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
336
336
let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
337
337
early_dcx. initialize_checked_jobserver ( ) ;
338
338
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
+
339
347
util:: run_in_thread_pool_with_globals (
340
348
config. opts . edition ,
341
349
config. opts . unstable_opts . threads ,
350
+ SourceMapInputs { file_loader, path_mapping, hash_kind } ,
342
351
|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.
345
354
let early_dcx = EarlyDiagCtxt :: new ( config. opts . error_format ) ;
346
355
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
-
351
356
let codegen_backend = match config. make_codegen_backend {
352
357
None => util:: get_codegen_backend (
353
358
& early_dcx,
@@ -372,9 +377,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
372
377
config. opts . unstable_opts . translate_directionality_markers ,
373
378
) {
374
379
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}" ) ) ,
378
381
} ;
379
382
380
383
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
393
396
config. registry . clone ( ) ,
394
397
locale_resources,
395
398
config. lint_caps ,
396
- config. file_loader ,
397
399
target,
398
400
sysroot,
399
401
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
440
442
current_gcx,
441
443
} ;
442
444
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
+ }
473
474
474
- res
475
- } ;
475
+ res
476
+ } ;
476
477
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) ) ;
479
480
480
- res
481
- } )
481
+ res
482
482
} ,
483
483
)
484
484
}
0 commit comments