From 91575f89ccf6111f27ae8a65612e5a14ebd54900 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 8 Sep 2021 17:24:03 +0200 Subject: [PATCH] Use non-recursive algorithm in non-parallel compiler. --- compiler/rustc_middle/src/hir/map/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index ef46771cd0f..fa186f4a931 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -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}; @@ -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(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);