Polymorphization should look at the runtime MIR of const fn

This commit is contained in:
oli 2020-12-07 12:38:26 +00:00
parent eb4e94b2e5
commit db90150b91

View File

@ -56,7 +56,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
// Exit early when there is no MIR available. // Exit early when there is no MIR available.
let context = tcx.hir().body_const_context(def_id.expect_local()); let context = tcx.hir().body_const_context(def_id.expect_local());
match context { match context {
None if !tcx.is_mir_available(def_id) => { Some(ConstContext::Fn) | None if !tcx.is_mir_available(def_id) => {
debug!("unused_generic_params: (no mir available) def_id={:?}", def_id); debug!("unused_generic_params: (no mir available) def_id={:?}", def_id);
return FiniteBitSet::new_empty(); return FiniteBitSet::new_empty();
} }
@ -78,10 +78,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
// Visit MIR and accumululate used generic parameters. // Visit MIR and accumululate used generic parameters.
let body = match context { let body = match context {
None => tcx.optimized_mir(def_id), // Const functions are actually called and should thus be considered for polymorphization
// FIXME(oli-obk): since this is solely used for codegen (I think?), should we keep using // via their runtime MIR
// the optimized MIR for `const fn`? Need to adjust the above `is_mir_available` check Some(ConstContext::Fn) | None => tcx.optimized_mir(def_id),
// in that case.
Some(_) => tcx.mir_for_ctfe(def_id), Some(_) => tcx.mir_for_ctfe(def_id),
}; };
let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters }; let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters };