diff options
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/tests.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 36 |
5 files changed, 35 insertions, 31 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index d62bf7f85e0..c46e879b976 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -18,7 +18,6 @@ use rustc_parse::parser::attr::AllowLeadingUnsafe; use rustc_query_impl::QueryCtxt; use rustc_query_system::query::print_query_stack; use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName}; -use rustc_session::filesearch::sysroot_with_fallback; use rustc_session::parse::ParseSess; use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint}; use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMapInputs}; @@ -405,8 +404,11 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se crate::callbacks::setup_callbacks(); - let sysroot = config.opts.sysroot.clone(); - let target = config::build_target_config(&early_dcx, &config.opts.target_triple, &sysroot); + let target = config::build_target_config( + &early_dcx, + &config.opts.target_triple, + config.opts.sysroot.path(), + ); let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader)); let path_mapping = config.opts.file_path_mapping(); let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target); @@ -426,7 +428,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se let codegen_backend = match config.make_codegen_backend { None => util::get_codegen_backend( &early_dcx, - &sysroot, + &config.opts.sysroot, config.opts.unstable_opts.codegen_backend.as_deref(), &target, ), @@ -440,7 +442,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from); let bundle = match rustc_errors::fluent_bundle( - sysroot_with_fallback(&config.opts.sysroot), + &config.opts.sysroot.all_paths().collect::<Vec<_>>(), config.opts.unstable_opts.translate_lang.clone(), config.opts.unstable_opts.translate_additional_ftl.as_deref(), config.opts.unstable_opts.translate_directionality_markers, @@ -469,7 +471,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se locale_resources, config.lint_caps, target, - sysroot, util::rustc_version_str().unwrap_or("unknown"), config.ice_file, config.using_internal_features, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 201b7e2b940..e8c23ef997c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -11,6 +11,7 @@ use rustc_data_structures::jobserver::Proxy; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal}; use rustc_data_structures::{parallel, thousands}; +use rustc_errors::timings::TimingSection; use rustc_expand::base::{ExtCtxt, LintStoreExpand}; use rustc_feature::Features; use rustc_fs_util::try_canonicalize; @@ -370,7 +371,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { let mut lint_buffer = resolver.lint_buffer.steal(); if sess.opts.unstable_opts.input_stats { - input_stats::print_ast_stats(krate, "POST EXPANSION AST STATS", "ast-stats"); + input_stats::print_ast_stats(tcx, krate); } // Needs to go *after* expansion to be able to check the results of macro expansion. @@ -1176,6 +1177,8 @@ pub(crate) fn start_codegen<'tcx>( codegen_backend: &dyn CodegenBackend, tcx: TyCtxt<'tcx>, ) -> (Box<dyn Any>, EncodedMetadata) { + tcx.sess.timings.start_section(tcx.sess.dcx(), TimingSection::Codegen); + // Hook for tests. if let Some((def_id, _)) = tcx.entry_fn(()) && tcx.has_attr(def_id, sym::rustc_delayed_bug_from_inside_query) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 877440ec7d2..2bc30fa7cb0 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -48,6 +48,7 @@ impl Linker { let (codegen_results, work_products) = sess.time("finish_ongoing_codegen", || { codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames) }); + sess.timings.end_section(sess.dcx(), TimingSection::Codegen); sess.dcx().abort_if_errors(); @@ -89,7 +90,7 @@ impl Linker { } let _timer = sess.prof.verbose_generic_activity("link_crate"); - let _timing = sess.timings.start_section(sess.dcx(), TimingSection::Linking); + let _timing = sess.timings.section_guard(sess.dcx(), TimingSection::Linking); codegen_backend.link(sess, codegen_results, self.metadata, &self.output_filenames) } } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index a0012b04c4f..360b5629e9d 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -41,9 +41,11 @@ where let matches = optgroups().parse(args).unwrap(); let sessopts = build_session_options(&mut early_dcx, &matches); - let sysroot = sessopts.sysroot.clone(); - let target = - rustc_session::config::build_target_config(&early_dcx, &sessopts.target_triple, &sysroot); + let target = rustc_session::config::build_target_config( + &early_dcx, + &sessopts.target_triple, + sessopts.sysroot.path(), + ); let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target); let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm(); let sm_inputs = Some(SourceMapInputs { @@ -72,7 +74,6 @@ where vec![], Default::default(), target, - sysroot, "", None, &USING_INTERNAL_FEATURES, diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 8a7d6117265..0ca4fcc66ca 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -11,7 +11,7 @@ use rustc_data_structures::sync; use rustc_metadata::{DylibError, load_symbol_from_dylib}; use rustc_middle::ty::CurrentGcx; use rustc_parse::validate_attr; -use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_tuple}; +use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple}; use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer}; use rustc_session::output::{CRATE_TYPES, categorize_crate_type}; use rustc_session::{EarlyDiagCtxt, Session, filesearch}; @@ -305,7 +305,7 @@ fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBacken /// A name of `None` indicates that the default backend should be used. pub fn get_codegen_backend( early_dcx: &EarlyDiagCtxt, - sysroot: &Path, + sysroot: &Sysroot, backend_name: Option<&str>, target: &Target, ) -> Box<dyn CodegenBackend> { @@ -336,25 +336,24 @@ pub fn get_codegen_backend( // This is used for rustdoc, but it uses similar machinery to codegen backend // loading, so we leave the code here. It is potentially useful for other tools // that want to invoke the rustc binary while linking to rustc as well. -pub fn rustc_path<'a>() -> Option<&'a Path> { +pub fn rustc_path<'a>(sysroot: &Sysroot) -> Option<&'a Path> { static RUSTC_PATH: OnceLock<Option<PathBuf>> = OnceLock::new(); - const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR"); - - RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_deref() -} - -fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> { - let candidate = filesearch::get_or_default_sysroot() - .join(bin_path) - .join(if cfg!(target_os = "windows") { "rustc.exe" } else { "rustc" }); - candidate.exists().then_some(candidate) + RUSTC_PATH + .get_or_init(|| { + let candidate = sysroot + .default + .join(env!("RUSTC_INSTALL_BINDIR")) + .join(if cfg!(target_os = "windows") { "rustc.exe" } else { "rustc" }); + candidate.exists().then_some(candidate) + }) + .as_deref() } #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable fn get_codegen_sysroot( early_dcx: &EarlyDiagCtxt, - sysroot: &Path, + sysroot: &Sysroot, backend_name: &str, ) -> MakeBackendFn { // For now we only allow this function to be called once as it'll dlopen a @@ -369,10 +368,9 @@ fn get_codegen_sysroot( ); let target = host_tuple(); - let sysroot_candidates = filesearch::sysroot_with_fallback(&sysroot); - let sysroot = sysroot_candidates - .iter() + let sysroot = sysroot + .all_paths() .map(|sysroot| { filesearch::make_target_lib_path(sysroot, target).with_file_name("codegen-backends") }) @@ -381,8 +379,8 @@ fn get_codegen_sysroot( f.exists() }) .unwrap_or_else(|| { - let candidates = sysroot_candidates - .iter() + let candidates = sysroot + .all_paths() .map(|p| p.display().to_string()) .collect::<Vec<_>>() .join("\n* "); |
