diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-08-15 16:03:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-15 16:03:58 +0200 |
| commit | 30c967ddba14400003f3cac3112bcaa25a78ce7f (patch) | |
| tree | 6fda2627fed7d69b7dc3564c25949a24084f332e /compiler | |
| parent | 0734cbda19fcef3958ec6399683973538070fe1d (diff) | |
| parent | fd5b7373db2093be7e1c906d8f92627689cc1eed (diff) | |
| download | rust-30c967ddba14400003f3cac3112bcaa25a78ce7f.tar.gz rust-30c967ddba14400003f3cac3112bcaa25a78ce7f.zip | |
Rollup merge of #145408 - Kobzol:deduplicate-search-paths, r=petrochenkov
Deduplicate -L search paths For each -L passed to the compiler, we eagerly scan the whole directory. If it has a lot of files, that results in a lot of allocations. So it's needless to do this if some -L paths are actually duplicated (which can happen e.g. in the situation in the linked issue). This PR both deduplicates the args, and also teaches rustdoc not to pass duplicated args to merged doctests. Fixes: https://github.com/rust-lang/rust/issues/145375
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 57c797fa153..9793d8091e2 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2847,16 +2847,27 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M // This is the location used by the `rustc-dev` `rustup` component. real_source_base_dir("lib/rustlib/rustc-src/rust", "compiler/rustc/src/main.rs"); - let mut search_paths = vec![]; - for s in &matches.opt_strs("L") { - search_paths.push(SearchPath::from_cli_opt( - sysroot.path(), - &target_triple, - early_dcx, - s, - unstable_opts.unstable_options, - )); - } + // We eagerly scan all files in each passed -L path. If the same directory is passed multiple + // times, and the directory contains a lot of files, this can take a lot of time. + // So we remove -L paths that were passed multiple times, and keep only the first occurrence. + // We still have to keep the original order of the -L arguments. + let search_paths: Vec<SearchPath> = { + let mut seen_search_paths = FxHashSet::default(); + let search_path_matches: Vec<String> = matches.opt_strs("L"); + search_path_matches + .iter() + .filter(|p| seen_search_paths.insert(*p)) + .map(|path| { + SearchPath::from_cli_opt( + sysroot.path(), + &target_triple, + early_dcx, + &path, + unstable_opts.unstable_options, + ) + }) + .collect() + }; let working_dir = std::env::current_dir().unwrap_or_else(|e| { early_dcx.early_fatal(format!("Current directory is invalid: {e}")); |
