diff options
| author | Ralf Jung <post@ralfj.de> | 2024-03-17 09:56:58 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-03-17 15:17:00 +0100 |
| commit | ee746fb8ed64930d830fbd0d0918b702a1fe34a9 (patch) | |
| tree | ffb83cce47b35970bd27e0483f095522ca1add3f /compiler/rustc_monomorphize | |
| parent | 72d78970ec7cb5cdf210290835d9f71d4d6663e2 (diff) | |
| download | rust-ee746fb8ed64930d830fbd0d0918b702a1fe34a9.tar.gz rust-ee746fb8ed64930d830fbd0d0918b702a1fe34a9.zip | |
collector: move ensure_sufficient_stack out of the loop
Diffstat (limited to 'compiler/rustc_monomorphize')
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cd9eb4916ce..dd8cb6127be 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1433,7 +1433,7 @@ fn create_mono_items_for_default_impls<'tcx>( } } -/// Scans the CTFE alloc in order to find function calls, closures, and drop-glue. +/// Scans the CTFE alloc in order to find function pointers and statics that must be monomorphized. fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoItems<'tcx>) { match tcx.global_alloc(alloc_id) { GlobalAlloc::Static(def_id) => { @@ -1446,9 +1446,13 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt } GlobalAlloc::Memory(alloc) => { trace!("collecting {:?} with {:#?}", alloc_id, alloc); - for &prov in alloc.inner().provenance().ptrs().values() { - rustc_data_structures::stack::ensure_sufficient_stack(|| { - collect_alloc(tcx, prov.alloc_id(), output); + let ptrs = alloc.inner().provenance().ptrs(); + // avoid `ensure_sufficient_stack` in the common case of "no pointers" + if !ptrs.is_empty() { + rustc_data_structures::stack::ensure_sufficient_stack(move || { + for &prov in ptrs.values() { + collect_alloc(tcx, prov.alloc_id(), output); + } }); } } |
