Skip to content

Commit 62f98b4

Browse files
committed
Auto merge of #122627 - RalfJung:collector-stack-space, r=compiler-errors
collector: move ensure_sufficient_stack out of the loop According to the docs this call has some overhead to putting it inside the loop doesn't seem like a good idea. r? `@oli-obk`
2 parents eb45c84 + ee746fb commit 62f98b4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/rustc_monomorphize/src/collector.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ fn create_mono_items_for_default_impls<'tcx>(
14331433
}
14341434
}
14351435

1436-
/// Scans the CTFE alloc in order to find function calls, closures, and drop-glue.
1436+
/// Scans the CTFE alloc in order to find function pointers and statics that must be monomorphized.
14371437
fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoItems<'tcx>) {
14381438
match tcx.global_alloc(alloc_id) {
14391439
GlobalAlloc::Static(def_id) => {
@@ -1446,9 +1446,13 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
14461446
}
14471447
GlobalAlloc::Memory(alloc) => {
14481448
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
1449-
for &prov in alloc.inner().provenance().ptrs().values() {
1450-
rustc_data_structures::stack::ensure_sufficient_stack(|| {
1451-
collect_alloc(tcx, prov.alloc_id(), output);
1449+
let ptrs = alloc.inner().provenance().ptrs();
1450+
// avoid `ensure_sufficient_stack` in the common case of "no pointers"
1451+
if !ptrs.is_empty() {
1452+
rustc_data_structures::stack::ensure_sufficient_stack(move || {
1453+
for &prov in ptrs.values() {
1454+
collect_alloc(tcx, prov.alloc_id(), output);
1455+
}
14521456
});
14531457
}
14541458
}

0 commit comments

Comments
 (0)