diff options
| author | Michael Goulet <michael@errs.io> | 2025-01-10 01:27:01 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-01-10 01:27:13 +0000 |
| commit | 6431504e47b0ca024f0f219e5da3330481f0f458 (patch) | |
| tree | 0c877e6f74062d2abc0e1e17280d7b4d36aede52 /compiler/rustc_monomorphize | |
| parent | 824759493246ee383beb9cd5ceffa0e15deb9fa4 (diff) | |
Eagerly collect mono items for non-generic closures
Diffstat (limited to 'compiler/rustc_monomorphize')
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 00aae03704f..6774b162ef5 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1368,6 +1368,10 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionStrategy) -> Vec<MonoI collector.process_impl_item(id); } + for id in crate_items.nested_bodies() { + collector.process_nested_body(id); + } + collector.push_extra_entry_roots(); } @@ -1450,6 +1454,33 @@ impl<'v> RootCollector<'_, 'v> { } } + fn process_nested_body(&mut self, def_id: LocalDefId) { + match self.tcx.def_kind(def_id) { + DefKind::Closure => { + if self.strategy == MonoItemCollectionStrategy::Eager + && !self + .tcx + .generics_of(self.tcx.typeck_root_def_id(def_id.to_def_id())) + .requires_monomorphization(self.tcx) + { + let instance = match *self.tcx.type_of(def_id).instantiate_identity().kind() { + ty::Closure(def_id, args) + | ty::Coroutine(def_id, args) + | ty::CoroutineClosure(def_id, args) => { + Instance::new(def_id, self.tcx.erase_regions(args)) + } + _ => unreachable!(), + }; + let mono_item = create_fn_mono_item(self.tcx, instance, DUMMY_SP); + if mono_item.node.is_instantiable(self.tcx) { + self.output.push(mono_item); + } + } + } + _ => {} + } + } + fn is_root(&self, def_id: LocalDefId) -> bool { !self.tcx.generics_of(def_id).requires_monomorphization(self.tcx) && match self.strategy { |
