Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Polymorphization should look at the runtime MIR of const fn
  • Loading branch information
oli-obk committed Jan 4, 2021
commit db90150b91c1b3402e1a1419f857031c94fb074e
9 changes: 4 additions & 5 deletions compiler/rustc_mir/src/monomorphize/polymorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
// Exit early when there is no MIR available.
let context = tcx.hir().body_const_context(def_id.expect_local());
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);
return FiniteBitSet::new_empty();
}
Expand All @@ -78,10 +78,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {

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