Skip to content

Commit

Permalink
Use non-recursive algorithm in non-parallel compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 12, 2021
1 parent 6bbb079 commit 91575f8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions compiler/rustc_middle/src/hir/map/mod.rs
Expand Up @@ -6,7 +6,6 @@ use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{self, par_iter};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
Expand Down Expand Up @@ -571,13 +570,20 @@ impl<'hir> Map<'hir> {
}
}

pub fn par_for_each_module(&self, f: impl Fn(LocalDefId) + sync::Sync) {
use rustc_data_structures::sync::ParallelIterator;
#[cfg(not(parallel_compiler))]
#[inline]
pub fn par_for_each_module(&self, f: impl Fn(LocalDefId)) {
self.for_each_module(f)
}

#[cfg(parallel_compiler)]
pub fn par_for_each_module(&self, f: impl Fn(LocalDefId) + Sync) {
use rustc_data_structures::sync::{par_iter, ParallelIterator};
par_iter_submodules(self.tcx, CRATE_DEF_ID, &f);

fn par_iter_submodules<F>(tcx: TyCtxt<'_>, module: LocalDefId, f: &F)
where
F: Fn(LocalDefId) + sync::Sync,
F: Fn(LocalDefId) + Sync,
{
(*f)(module);
let items = tcx.hir_module_items(module);
Expand Down

0 comments on commit 91575f8

Please sign in to comment.