diff options
| author | oli <github35764891676564198441@oli-obk.de> | 2020-12-07 12:38:26 +0000 |
|---|---|---|
| committer | oli <github35764891676564198441@oli-obk.de> | 2021-01-04 21:40:38 +0000 |
| commit | db90150b91c1b3402e1a1419f857031c94fb074e (patch) | |
| tree | 76363cc6ec689f7a9aefbe9530b438cb88cc0e8b | |
| parent | eb4e94b2e5f479ac44bf8d4094cdcb73d5941b22 (diff) | |
| download | rust-db90150b91c1b3402e1a1419f857031c94fb074e.tar.gz rust-db90150b91c1b3402e1a1419f857031c94fb074e.zip | |
Polymorphization should look at the runtime MIR of `const fn`
| -rw-r--r-- | compiler/rustc_mir/src/monomorphize/polymorphize.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index d4185c063ef..e51c9314595 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -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(); } @@ -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 }; |
