1
Fork 0

Rollup merge of #122811 - nnethercote:mv-SourceMap-init, r=WaffleLapkin

Move `SourceMap` initialization

So it happens at the same time as `SessionGlobals` initialization, rather than shortly afterward.

r? `@WaffleLapkin`
This commit is contained in:
Guillaume Gomez 2024-04-16 21:41:23 +02:00 committed by GitHub
commit 14496d561e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 175 additions and 175 deletions

View file

@ -1125,7 +1125,7 @@ impl Options {
|| self.unstable_opts.query_dep_graph
}
pub(crate) fn file_path_mapping(&self) -> FilePathMapping {
pub fn file_path_mapping(&self) -> FilePathMapping {
file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
}
@ -1162,6 +1162,16 @@ impl UnstableOptions {
track_diagnostics: self.track_diagnostics,
}
}
pub fn src_hash_algorithm(&self, target: &Target) -> SourceFileHashAlgorithm {
self.src_hash_algorithm.unwrap_or_else(|| {
if target.is_like_msvc {
SourceFileHashAlgorithm::Sha256
} else {
SourceFileHashAlgorithm::Md5
}
})
}
}
// The type of entry function, so users can have their own entry functions

View file

@ -28,9 +28,9 @@ use rustc_errors::{
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
use rustc_span::edition::Edition;
use rustc_span::source_map::{FileLoader, FilePathMapping, RealFileLoader, SourceMap};
use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::{FileNameDisplayPreference, RealFileName};
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
use rustc_span::{Span, Symbol};
use rustc_target::asm::InlineAsmArch;
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
use rustc_target::spec::{
@ -988,7 +988,6 @@ pub fn build_session(
registry: rustc_errors::registry::Registry,
fluent_resources: Vec<&'static str>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
target: Target,
sysroot: PathBuf,
cfg_version: &'static str,
@ -1015,24 +1014,11 @@ pub fn build_session(
early_dcx.early_warn(warning)
}
let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
let hash_kind = sopts.unstable_opts.src_hash_algorithm.unwrap_or_else(|| {
if target.is_like_msvc {
SourceFileHashAlgorithm::Sha256
} else {
SourceFileHashAlgorithm::Md5
}
});
let source_map = Lrc::new(SourceMap::with_file_loader_and_hash_kind(
loader,
sopts.file_path_mapping(),
hash_kind,
));
let fallback_bundle = fallback_fluent_bundle(
fluent_resources,
sopts.unstable_opts.translate_directionality_markers,
);
let source_map = rustc_span::source_map::get_source_map().unwrap();
let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle);
let mut dcx =
@ -1411,16 +1397,10 @@ impl EarlyDiagCtxt {
self.dcx.warn(msg)
}
pub fn initialize_checked_jobserver(&self) {
// initialize jobserver before getting `jobserver::client` and `build_session`.
jobserver::initialize_checked(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
self.dcx
.struct_warn(err)
.with_note("the build environment is likely misconfigured")
.emit()
});
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_struct_warn(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> {
self.dcx.struct_warn(msg)
}
}