Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit db90150

Browse files
committed
Polymorphization should look at the runtime MIR of const fn
1 parent eb4e94b commit db90150

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/rustc_mir/src/monomorphize/polymorphize.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
5656
// Exit early when there is no MIR available.
5757
let context = tcx.hir().body_const_context(def_id.expect_local());
5858
match context {
59-
None if !tcx.is_mir_available(def_id) => {
59+
Some(ConstContext::Fn) | None if !tcx.is_mir_available(def_id) => {
6060
debug!("unused_generic_params: (no mir available) def_id={:?}", def_id);
6161
return FiniteBitSet::new_empty();
6262
}
@@ -78,10 +78,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
7878

7979
// Visit MIR and accumululate used generic parameters.
8080
let body = match context {
81-
None => tcx.optimized_mir(def_id),
82-
// FIXME(oli-obk): since this is solely used for codegen (I think?), should we keep using
83-
// the optimized MIR for `const fn`? Need to adjust the above `is_mir_available` check
84-
// in that case.
81+
// Const functions are actually called and should thus be considered for polymorphization
82+
// via their runtime MIR
83+
Some(ConstContext::Fn) | None => tcx.optimized_mir(def_id),
8584
Some(_) => tcx.mir_for_ctfe(def_id),
8685
};
8786
let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters };

0 commit comments

Comments
 (0)