2020-01-05 15:46:44 +00:00
|
|
|
use crate::{shim, util};
|
2020-04-22 12:30:11 -03:00
|
|
|
use required_consts::RequiredConstsVisitor;
|
2020-04-18 12:58:53 +01:00
|
|
|
use rustc_data_structures::fx::FxHashSet;
|
2020-11-14 01:29:30 +01:00
|
|
|
use rustc_data_structures::steal::Steal;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
2020-04-18 12:58:53 +01:00
|
|
|
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
2020-01-07 18:12:06 +01:00
|
|
|
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc_index::vec::IndexVec;
|
2020-04-03 18:26:24 -03:00
|
|
|
use rustc_middle::mir::visit::Visitor as _;
|
2020-06-22 19:21:56 -07:00
|
|
|
use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted};
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::ty::query::Providers;
|
2020-10-04 11:01:13 -07:00
|
|
|
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
2020-04-19 13:00:18 +02:00
|
|
|
use rustc_span::{Span, Symbol};
|
2017-11-10 00:49:51 +02:00
|
|
|
use std::borrow::Cow;
|
2017-04-27 16:48:48 -04:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod add_call_guards;
|
2017-10-03 16:01:01 +02:00
|
|
|
pub mod add_moves_for_packed_drops;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod add_retag;
|
2020-08-10 07:16:30 -04:00
|
|
|
pub mod check_const_item_mutation;
|
2019-09-17 16:25:40 -07:00
|
|
|
pub mod check_consts;
|
2020-05-16 16:17:07 +02:00
|
|
|
pub mod check_packed_ref;
|
2017-09-19 16:20:02 +03:00
|
|
|
pub mod check_unsafety;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod cleanup_post_borrowck;
|
2020-05-30 15:02:32 -04:00
|
|
|
pub mod const_debuginfo;
|
2020-10-03 11:18:24 +02:00
|
|
|
pub mod const_goto;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod const_prop;
|
2020-10-23 00:45:07 -07:00
|
|
|
pub mod coverage;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod deaggregator;
|
2020-10-04 15:52:14 +02:00
|
|
|
pub mod deduplicate_blocks;
|
2020-05-24 18:22:04 +02:00
|
|
|
pub mod dest_prop;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod dump_mir;
|
2020-08-02 01:47:52 +02:00
|
|
|
pub mod early_otherwise_branch;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod elaborate_drops;
|
2020-10-21 17:19:21 -04:00
|
|
|
pub mod function_item_references;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod generator;
|
|
|
|
pub mod inline;
|
|
|
|
pub mod instcombine;
|
2020-11-14 00:00:00 +00:00
|
|
|
pub mod lower_intrinsics;
|
2020-08-10 23:11:05 +00:00
|
|
|
pub mod match_branches;
|
2020-10-01 10:06:37 +02:00
|
|
|
pub mod multiple_return_terminators;
|
2016-02-11 10:13:35 +02:00
|
|
|
pub mod no_landing_pads;
|
2020-05-14 10:11:15 -07:00
|
|
|
pub mod nrvo;
|
2016-05-07 19:14:28 +03:00
|
|
|
pub mod promote_consts;
|
2017-11-27 21:50:36 +02:00
|
|
|
pub mod remove_noop_landing_pads;
|
2021-01-13 00:00:00 +00:00
|
|
|
pub mod remove_storage_markers;
|
2020-09-13 16:04:45 +02:00
|
|
|
pub mod remove_unneeded_drops;
|
2020-04-22 11:16:06 -03:00
|
|
|
pub mod required_consts;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod rustc_peek;
|
|
|
|
pub mod simplify;
|
|
|
|
pub mod simplify_branches;
|
2020-08-10 20:27:41 +02:00
|
|
|
pub mod simplify_comparison_integral;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod simplify_try;
|
2019-10-20 23:48:31 -04:00
|
|
|
pub mod uninhabited_enum_branching;
|
2020-01-10 20:15:16 +01:00
|
|
|
pub mod unreachable_prop;
|
2020-05-24 00:55:44 +02:00
|
|
|
pub mod validate;
|
2017-04-27 16:48:48 -04:00
|
|
|
|
2020-10-04 11:01:13 -07:00
|
|
|
pub use rustc_middle::mir::MirSource;
|
|
|
|
|
2020-07-05 23:00:14 +03:00
|
|
|
pub(crate) fn provide(providers: &mut Providers) {
|
2017-09-19 16:20:02 +03:00
|
|
|
self::check_unsafety::provide(providers);
|
2017-04-27 16:48:48 -04:00
|
|
|
*providers = Providers {
|
2017-05-02 06:32:03 -04:00
|
|
|
mir_keys,
|
|
|
|
mir_const,
|
2020-07-16 19:36:18 +02:00
|
|
|
mir_const_qualif: |tcx, def_id| {
|
|
|
|
let def_id = def_id.expect_local();
|
2020-07-21 22:54:18 +02:00
|
|
|
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
2020-07-16 19:36:18 +02:00
|
|
|
tcx.mir_const_qualif_const_arg(def)
|
|
|
|
} else {
|
|
|
|
mir_const_qualif(tcx, ty::WithOptConstParam::unknown(def_id))
|
|
|
|
}
|
2020-07-06 23:49:53 +02:00
|
|
|
},
|
2020-07-08 01:03:19 +02:00
|
|
|
mir_const_qualif_const_arg: |tcx, (did, param_did)| {
|
2020-07-15 10:50:54 +02:00
|
|
|
mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
|
2020-07-06 23:49:53 +02:00
|
|
|
},
|
2020-08-14 18:01:14 +02:00
|
|
|
mir_promoted,
|
2020-05-02 21:16:17 -07:00
|
|
|
mir_drops_elaborated_and_const_checked,
|
2020-10-26 19:00:40 +00:00
|
|
|
mir_for_ctfe,
|
|
|
|
mir_for_ctfe_of_const_arg,
|
2017-05-02 06:32:03 -04:00
|
|
|
optimized_mir,
|
|
|
|
is_mir_available,
|
2020-10-28 13:12:49 +00:00
|
|
|
is_ctfe_mir_available: |tcx, did| is_mir_available(tcx, did),
|
2020-07-06 23:49:53 +02:00
|
|
|
promoted_mir: |tcx, def_id| {
|
2020-07-16 19:36:18 +02:00
|
|
|
let def_id = def_id.expect_local();
|
2020-07-21 22:54:18 +02:00
|
|
|
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
2020-07-16 19:36:18 +02:00
|
|
|
tcx.promoted_mir_of_const_arg(def)
|
|
|
|
} else {
|
|
|
|
promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id))
|
|
|
|
}
|
2020-07-06 23:49:53 +02:00
|
|
|
},
|
2020-07-08 10:35:58 +02:00
|
|
|
promoted_mir_of_const_arg: |tcx, (did, param_did)| {
|
2020-07-15 10:50:54 +02:00
|
|
|
promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
|
2020-07-06 23:49:53 +02:00
|
|
|
},
|
2017-04-27 16:48:48 -04:00
|
|
|
..*providers
|
|
|
|
};
|
2020-10-23 00:45:07 -07:00
|
|
|
coverage::query::provide(providers);
|
2017-04-27 16:48:48 -04:00
|
|
|
}
|
|
|
|
|
2019-06-21 18:12:39 +02:00
|
|
|
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
2020-04-18 12:58:53 +01:00
|
|
|
tcx.mir_keys(def_id.krate).contains(&def_id.expect_local())
|
2017-05-02 06:32:03 -04:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Finds the full set of `DefId`s within the current crate that have
|
2017-05-02 06:32:03 -04:00
|
|
|
/// MIR associated with them.
|
2020-03-27 18:46:25 +01:00
|
|
|
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> {
|
2017-05-02 06:32:03 -04:00
|
|
|
assert_eq!(krate, LOCAL_CRATE);
|
|
|
|
|
2020-04-18 12:58:53 +01:00
|
|
|
let mut set = FxHashSet::default();
|
2017-05-02 06:32:03 -04:00
|
|
|
|
|
|
|
// All body-owners have MIR associated with them.
|
2020-04-18 12:58:53 +01:00
|
|
|
set.extend(tcx.body_owners());
|
2017-05-02 06:32:03 -04:00
|
|
|
|
|
|
|
// Additionally, tuple struct/variant constructors have MIR, but
|
|
|
|
// they don't have a BodyId, so we need to build them separately.
|
2019-06-14 19:39:39 +03:00
|
|
|
struct GatherCtors<'a, 'tcx> {
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-04-18 12:58:53 +01:00
|
|
|
set: &'a mut FxHashSet<LocalDefId>,
|
2017-05-02 06:32:03 -04:00
|
|
|
}
|
|
|
|
impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> {
|
2019-12-22 17:42:04 -05:00
|
|
|
fn visit_variant_data(
|
|
|
|
&mut self,
|
|
|
|
v: &'tcx hir::VariantData<'tcx>,
|
2020-04-19 13:00:18 +02:00
|
|
|
_: Symbol,
|
2019-12-01 16:08:58 +01:00
|
|
|
_: &'tcx hir::Generics<'tcx>,
|
2019-12-22 17:42:04 -05:00
|
|
|
_: hir::HirId,
|
|
|
|
_: Span,
|
|
|
|
) {
|
2019-03-01 09:52:20 +01:00
|
|
|
if let hir::VariantData::Tuple(_, hir_id) = *v {
|
2020-04-18 12:58:53 +01:00
|
|
|
self.set.insert(self.tcx.hir().local_def_id(hir_id));
|
2017-05-02 06:32:03 -04:00
|
|
|
}
|
|
|
|
intravisit::walk_struct_def(self, v)
|
|
|
|
}
|
2020-03-11 12:05:32 +01:00
|
|
|
type Map = intravisit::ErasedMap<'tcx>;
|
2020-02-09 15:32:00 +01:00
|
|
|
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
2017-05-02 06:32:03 -04:00
|
|
|
NestedVisitorMap::None
|
|
|
|
}
|
|
|
|
}
|
2019-12-22 17:42:04 -05:00
|
|
|
tcx.hir()
|
|
|
|
.krate()
|
|
|
|
.visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set }.as_deep_visitor());
|
2017-05-02 06:32:03 -04:00
|
|
|
|
2020-03-27 18:46:25 +01:00
|
|
|
set
|
2017-05-02 06:32:03 -04:00
|
|
|
}
|
|
|
|
|
2017-11-10 00:49:51 +02:00
|
|
|
/// Generates a default name for the pass based on the name of the
|
|
|
|
/// type `T`.
|
|
|
|
pub fn default_name<T: ?Sized>() -> Cow<'static, str> {
|
2020-10-13 10:17:05 +02:00
|
|
|
let name = std::any::type_name::<T>();
|
2020-02-26 13:03:46 +01:00
|
|
|
if let Some(tail) = name.rfind(':') { Cow::from(&name[tail + 1..]) } else { Cow::from(name) }
|
2017-11-10 00:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A streamlined trait that you can implement to create a pass; the
|
|
|
|
/// pass will be named after the type, and it will consist of a main
|
|
|
|
/// loop that goes over each available MIR and applies `run_pass`.
|
2019-08-04 16:20:00 -04:00
|
|
|
pub trait MirPass<'tcx> {
|
2019-06-21 18:12:39 +02:00
|
|
|
fn name(&self) -> Cow<'_, str> {
|
2017-11-10 00:49:51 +02:00
|
|
|
default_name::<Self>()
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>);
|
2017-11-10 00:49:51 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 22:41:21 -04:00
|
|
|
pub fn run_passes(
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-04-12 10:31:00 -07:00
|
|
|
body: &mut Body<'tcx>,
|
2018-10-22 22:41:21 -04:00
|
|
|
mir_phase: MirPhase,
|
2020-03-17 08:18:32 -04:00
|
|
|
passes: &[&[&dyn MirPass<'tcx>]],
|
2018-10-25 08:35:53 -04:00
|
|
|
) {
|
2018-10-22 22:41:21 -04:00
|
|
|
let phase_index = mir_phase.phase_index();
|
2020-05-24 00:55:44 +02:00
|
|
|
let validate = tcx.sess.opts.debugging_opts.validate_mir;
|
2018-10-22 22:41:21 -04:00
|
|
|
|
2019-08-15 06:39:31 -04:00
|
|
|
if body.phase >= mir_phase {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-20 16:18:17 -04:00
|
|
|
|
2020-05-24 00:55:44 +02:00
|
|
|
if validate {
|
2020-08-14 18:01:14 +02:00
|
|
|
validate::Validator { when: format!("input to phase {:?}", mir_phase), mir_phase }
|
2020-10-04 11:01:38 -07:00
|
|
|
.run_pass(tcx, body);
|
2020-05-24 00:55:44 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:39:31 -04:00
|
|
|
let mut index = 0;
|
|
|
|
let mut run_pass = |pass: &dyn MirPass<'tcx>| {
|
|
|
|
let run_hooks = |body: &_, index, is_after| {
|
2019-12-22 17:42:04 -05:00
|
|
|
dump_mir::on_mir_pass(
|
|
|
|
tcx,
|
|
|
|
&format_args!("{:03}-{:03}", phase_index, index),
|
|
|
|
&pass.name(),
|
|
|
|
body,
|
|
|
|
is_after,
|
|
|
|
);
|
2017-11-10 13:58:06 +02:00
|
|
|
};
|
2019-08-15 06:39:31 -04:00
|
|
|
run_hooks(body, index, false);
|
2020-10-04 11:01:38 -07:00
|
|
|
pass.run_pass(tcx, body);
|
2019-08-15 06:39:31 -04:00
|
|
|
run_hooks(body, index, true);
|
2018-10-20 16:18:17 -04:00
|
|
|
|
2020-05-24 00:55:44 +02:00
|
|
|
if validate {
|
2020-08-14 18:01:14 +02:00
|
|
|
validate::Validator {
|
|
|
|
when: format!("after {} in phase {:?}", pass.name(), mir_phase),
|
|
|
|
mir_phase,
|
|
|
|
}
|
2020-10-04 11:01:38 -07:00
|
|
|
.run_pass(tcx, body);
|
2020-05-24 00:55:44 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:39:31 -04:00
|
|
|
index += 1;
|
2017-11-10 13:58:06 +02:00
|
|
|
};
|
2017-11-10 19:20:35 +02:00
|
|
|
|
2020-03-17 08:18:32 -04:00
|
|
|
for pass_group in passes {
|
|
|
|
for pass in *pass_group {
|
|
|
|
run_pass(*pass);
|
|
|
|
}
|
2019-08-15 06:39:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
body.phase = mir_phase;
|
2020-05-25 22:04:48 +02:00
|
|
|
|
2020-08-18 13:44:57 +02:00
|
|
|
if mir_phase == MirPhase::Optimization {
|
2020-08-14 18:01:14 +02:00
|
|
|
validate::Validator { when: format!("end of phase {:?}", mir_phase), mir_phase }
|
2020-10-04 11:01:38 -07:00
|
|
|
.run_pass(tcx, body);
|
2020-05-25 22:04:48 +02:00
|
|
|
}
|
2018-10-22 22:41:21 -04:00
|
|
|
}
|
2017-11-10 00:49:51 +02:00
|
|
|
|
2020-07-15 10:50:54 +02:00
|
|
|
fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> ConstQualifs {
|
2020-07-06 23:49:53 +02:00
|
|
|
let const_kind = tcx.hir().body_const_context(def.did);
|
2019-10-28 10:26:16 -07:00
|
|
|
|
|
|
|
// No need to const-check a non-const `fn`.
|
|
|
|
if const_kind.is_none() {
|
2019-11-14 09:15:23 -08:00
|
|
|
return Default::default();
|
2019-10-28 10:26:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// N.B., this `borrow()` is guaranteed to be valid (i.e., the value
|
2020-08-14 18:01:14 +02:00
|
|
|
// cannot yet be stolen), because `mir_promoted()`, which steals
|
2019-10-28 10:26:16 -07:00
|
|
|
// from `mir_const(), forces this query to execute before
|
|
|
|
// performing the steal.
|
2020-07-06 23:49:53 +02:00
|
|
|
let body = &tcx.mir_const(def).borrow();
|
2019-10-28 10:26:16 -07:00
|
|
|
|
|
|
|
if body.return_ty().references_error() {
|
|
|
|
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
|
2019-11-14 09:15:23 -08:00
|
|
|
return Default::default();
|
2019-10-28 10:26:16 -07:00
|
|
|
}
|
|
|
|
|
2020-10-04 15:22:23 -07:00
|
|
|
let ccx = check_consts::ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def.did) };
|
2019-10-28 10:26:16 -07:00
|
|
|
|
2020-03-23 14:02:58 +01:00
|
|
|
let mut validator = check_consts::validation::Validator::new(&ccx);
|
2019-10-28 10:26:16 -07:00
|
|
|
validator.check_body();
|
|
|
|
|
|
|
|
// We return the qualifs in the return place for every MIR body, even though it is only used
|
|
|
|
// when deciding to promote a reference to a `const` for now.
|
2020-02-25 18:10:34 +01:00
|
|
|
validator.qualifs_in_return_place()
|
2019-10-28 10:26:16 -07:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:17:07 +02:00
|
|
|
/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
|
2020-07-06 23:49:53 +02:00
|
|
|
fn mir_const<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-07-15 10:50:54 +02:00
|
|
|
def: ty::WithOptConstParam<LocalDefId>,
|
2020-07-06 23:49:53 +02:00
|
|
|
) -> &'tcx Steal<Body<'tcx>> {
|
2020-07-17 19:12:30 +02:00
|
|
|
if let Some(def) = def.try_upgrade(tcx) {
|
2020-07-16 19:36:18 +02:00
|
|
|
return tcx.mir_const(def);
|
2020-07-06 23:49:53 +02:00
|
|
|
}
|
2020-04-17 15:53:37 +01:00
|
|
|
|
2020-05-16 16:17:07 +02:00
|
|
|
// Unsafety check uses the raw mir, so make sure it is run.
|
2020-07-15 10:50:54 +02:00
|
|
|
if let Some(param_did) = def.const_param_did {
|
2020-07-15 11:26:26 +02:00
|
|
|
tcx.ensure().unsafety_check_result_for_const_arg((def.did, param_did));
|
2020-07-08 01:03:19 +02:00
|
|
|
} else {
|
|
|
|
tcx.ensure().unsafety_check_result(def.did);
|
|
|
|
}
|
2017-11-10 00:49:51 +02:00
|
|
|
|
2020-07-06 23:49:53 +02:00
|
|
|
let mut body = tcx.mir_built(def).steal();
|
2020-01-05 15:46:44 +00:00
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
util::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(()));
|
2020-01-05 15:46:44 +00:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
run_passes(
|
|
|
|
tcx,
|
|
|
|
&mut body,
|
|
|
|
MirPhase::Const,
|
2020-03-17 08:18:32 -04:00
|
|
|
&[&[
|
2020-05-16 16:17:07 +02:00
|
|
|
// MIR-level lints.
|
|
|
|
&check_packed_ref::CheckPackedRef,
|
2020-08-10 07:16:30 -04:00
|
|
|
&check_const_item_mutation::CheckConstItemMutation,
|
2020-10-21 17:19:21 -04:00
|
|
|
&function_item_references::FunctionItemReferences,
|
2019-12-22 17:42:04 -05:00
|
|
|
// What we need to do constant evaluation.
|
|
|
|
&simplify::SimplifyCfg::new("initial"),
|
|
|
|
&rustc_peek::SanityCheck,
|
2020-03-17 08:18:32 -04:00
|
|
|
]],
|
2019-12-22 17:42:04 -05:00
|
|
|
);
|
2019-11-06 12:00:46 -05:00
|
|
|
tcx.alloc_steal_mir(body)
|
2017-11-10 13:58:06 +02:00
|
|
|
}
|
2017-11-10 00:49:51 +02:00
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Compute the main MIR body and the list of MIR bodies of the promoteds.
|
2020-08-14 18:01:14 +02:00
|
|
|
fn mir_promoted(
|
2019-08-14 08:08:17 -04:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-07-15 10:50:54 +02:00
|
|
|
def: ty::WithOptConstParam<LocalDefId>,
|
2020-07-03 22:15:27 +02:00
|
|
|
) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) {
|
2020-07-17 19:12:30 +02:00
|
|
|
if let Some(def) = def.try_upgrade(tcx) {
|
2020-08-14 18:01:14 +02:00
|
|
|
return tcx.mir_promoted(def);
|
2020-07-06 23:49:53 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 21:25:51 -07:00
|
|
|
// Ensure that we compute the `mir_const_qualif` for constants at
|
|
|
|
// this point, before we steal the mir-const result.
|
2020-08-16 10:44:53 +02:00
|
|
|
// Also this means promotion can rely on all const checks having been done.
|
2020-07-08 01:03:19 +02:00
|
|
|
let _ = tcx.mir_const_qualif_opt_const_arg(def);
|
2020-10-05 08:49:21 +02:00
|
|
|
let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global());
|
2020-07-06 23:49:53 +02:00
|
|
|
let mut body = tcx.mir_const(def).steal();
|
2020-04-03 18:26:24 -03:00
|
|
|
|
2020-04-22 11:16:06 -03:00
|
|
|
let mut required_consts = Vec::new();
|
2020-04-22 12:30:11 -03:00
|
|
|
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
|
2020-04-03 18:26:24 -03:00
|
|
|
for (bb, bb_data) in traversal::reverse_postorder(&body) {
|
2020-04-22 11:16:06 -03:00
|
|
|
required_consts_visitor.visit_basic_block_data(bb, bb_data);
|
2020-04-03 18:26:24 -03:00
|
|
|
}
|
2020-04-22 11:16:06 -03:00
|
|
|
body.required_consts = required_consts;
|
2020-04-03 18:26:24 -03:00
|
|
|
|
2019-11-06 14:23:35 -08:00
|
|
|
let promote_pass = promote_consts::PromoteTemps::default();
|
2020-07-27 16:25:08 -07:00
|
|
|
let promote: &[&dyn MirPass<'tcx>] = &[
|
|
|
|
// What we need to run borrowck etc.
|
|
|
|
&promote_pass,
|
2020-08-16 10:44:53 +02:00
|
|
|
&simplify::SimplifyCfg::new("promote-consts"),
|
2020-07-27 16:25:08 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
let opt_coverage: &[&dyn MirPass<'tcx>] = if tcx.sess.opts.debugging_opts.instrument_coverage {
|
2020-10-23 00:45:07 -07:00
|
|
|
&[&coverage::InstrumentCoverage]
|
2020-07-27 16:25:08 -07:00
|
|
|
} else {
|
|
|
|
&[]
|
|
|
|
};
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
run_passes(tcx, &mut body, MirPhase::ConstPromotion, &[promote, opt_coverage]);
|
2019-10-07 16:08:57 -04:00
|
|
|
|
2019-11-06 14:23:35 -08:00
|
|
|
let promoted = promote_pass.promoted_fragments.into_inner();
|
2019-11-06 12:00:46 -05:00
|
|
|
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
|
2017-11-10 00:49:51 +02:00
|
|
|
}
|
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
|
2020-10-26 19:00:40 +00:00
|
|
|
fn mir_for_ctfe<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Body<'tcx> {
|
|
|
|
let did = def_id.expect_local();
|
|
|
|
if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
|
|
|
|
tcx.mir_for_ctfe_of_const_arg(def)
|
|
|
|
} else {
|
|
|
|
tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(did)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Same as `mir_for_ctfe`, but used to get the MIR of a const generic parameter.
|
|
|
|
/// The docs on `WithOptConstParam` explain this a bit more, but the TLDR is that
|
|
|
|
/// we'd get cycle errors with `mir_for_ctfe`, because typeck would need to typeck
|
|
|
|
/// the const parameter while type checking the main body, which in turn would try
|
|
|
|
/// to type check the main body again.
|
2020-10-26 19:00:40 +00:00
|
|
|
fn mir_for_ctfe_of_const_arg<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
(did, param_did): (LocalDefId, DefId),
|
|
|
|
) -> &'tcx Body<'tcx> {
|
|
|
|
tcx.arena.alloc(inner_mir_for_ctfe(
|
|
|
|
tcx,
|
|
|
|
ty::WithOptConstParam { did, const_param_did: Some(param_did) },
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_> {
|
|
|
|
// FIXME: don't duplicate this between the optimized_mir/mir_for_ctfe queries
|
|
|
|
if tcx.is_constructor(def.did.to_def_id()) {
|
|
|
|
// There's no reason to run all of the MIR passes on constructors when
|
|
|
|
// we can just output the MIR we want directly. This also saves const
|
|
|
|
// qualification and borrow checking the trouble of special casing
|
|
|
|
// constructors.
|
|
|
|
return shim::build_adt_ctor(tcx, def.did.to_def_id());
|
|
|
|
}
|
|
|
|
|
2021-01-04 19:05:51 +00:00
|
|
|
let context = tcx
|
|
|
|
.hir()
|
|
|
|
.body_const_context(def.did)
|
|
|
|
.expect("mir_for_ctfe should not be used for runtime functions");
|
2020-10-26 19:00:40 +00:00
|
|
|
|
|
|
|
let mut body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone();
|
|
|
|
|
2021-01-04 19:05:51 +00:00
|
|
|
match context {
|
|
|
|
// Do not const prop functions, either they get executed at runtime or exported to metadata,
|
|
|
|
// so we run const prop on them, or they don't, in which case we const evaluate some control
|
|
|
|
// flow paths of the function and any errors in those paths will get emitted as const eval
|
|
|
|
// errors.
|
|
|
|
hir::ConstContext::ConstFn => {}
|
|
|
|
// Static items always get evaluated, so we can just let const eval see if any erroneous
|
|
|
|
// control flow paths get executed.
|
|
|
|
hir::ConstContext::Static(_) => {}
|
|
|
|
// Associated constants get const prop run so we detect common failure situations in the
|
|
|
|
// crate that defined the constant.
|
|
|
|
// Technically we want to not run on regular const items, but oli-obk doesn't know how to
|
|
|
|
// conveniently detect that at this point without looking at the HIR.
|
|
|
|
hir::ConstContext::Const => {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let optimizations: &[&dyn MirPass<'_>] = &[
|
|
|
|
&const_prop::ConstProp,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
run_passes(
|
|
|
|
tcx,
|
|
|
|
&mut body,
|
|
|
|
MirPhase::Optimization,
|
|
|
|
&[
|
|
|
|
optimizations,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 19:00:40 +00:00
|
|
|
|
|
|
|
debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE");
|
|
|
|
|
|
|
|
body
|
|
|
|
}
|
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
|
|
|
|
/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
|
|
|
|
/// end up missing the source MIR due to stealing happening.
|
2020-05-02 21:16:17 -07:00
|
|
|
fn mir_drops_elaborated_and_const_checked<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-07-15 10:50:54 +02:00
|
|
|
def: ty::WithOptConstParam<LocalDefId>,
|
2020-07-03 22:15:27 +02:00
|
|
|
) -> &'tcx Steal<Body<'tcx>> {
|
2020-07-17 19:12:30 +02:00
|
|
|
if let Some(def) = def.try_upgrade(tcx) {
|
2020-07-16 19:36:18 +02:00
|
|
|
return tcx.mir_drops_elaborated_and_const_checked(def);
|
2020-07-03 22:15:27 +02:00
|
|
|
}
|
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
// (Mir-)Borrowck uses `mir_promoted`, so we have to force it to
|
2020-05-02 21:16:17 -07:00
|
|
|
// execute before we can steal.
|
2020-07-15 10:50:54 +02:00
|
|
|
if let Some(param_did) = def.const_param_did {
|
2020-07-08 01:03:19 +02:00
|
|
|
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
|
|
|
|
} else {
|
|
|
|
tcx.ensure().mir_borrowck(def.did);
|
|
|
|
}
|
2020-05-02 21:16:17 -07:00
|
|
|
|
2020-12-29 16:21:52 +00:00
|
|
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
|
|
|
use rustc_middle::hir::map::blocks::FnLikeNode;
|
|
|
|
let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some();
|
|
|
|
if is_fn_like {
|
|
|
|
let did = def.did.to_def_id();
|
|
|
|
let def = ty::WithOptConstParam::unknown(did);
|
2021-01-11 11:21:24 +00:00
|
|
|
|
|
|
|
// Do not compute the mir call graph without said call graph actually being used.
|
2021-02-21 00:00:00 +00:00
|
|
|
if inline::is_enabled(tcx) {
|
2021-01-11 11:21:24 +00:00
|
|
|
let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def));
|
|
|
|
}
|
2020-12-29 16:21:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
let (body, _) = tcx.mir_promoted(def);
|
2020-05-02 21:16:17 -07:00
|
|
|
let mut body = body.steal();
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
run_post_borrowck_cleanup_passes(tcx, &mut body);
|
2020-10-04 15:22:23 -07:00
|
|
|
check_consts::post_drop_elaboration::check_live_drops(tcx, &body);
|
2020-05-02 21:16:17 -07:00
|
|
|
tcx.alloc_steal_mir(body)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// After this series of passes, no lifetime analysis based on borrowing can be done.
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|
|
|
debug!("post_borrowck_cleanup({:?})", body.source.def_id());
|
2020-05-02 21:16:17 -07:00
|
|
|
|
2020-03-17 08:18:32 -04:00
|
|
|
let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[
|
|
|
|
// Remove all things only needed by analysis
|
2021-01-18 00:00:00 +00:00
|
|
|
&no_landing_pads::NoLandingPads,
|
2020-03-17 08:18:32 -04:00
|
|
|
&simplify_branches::SimplifyBranches::new("initial"),
|
|
|
|
&remove_noop_landing_pads::RemoveNoopLandingPads,
|
|
|
|
&cleanup_post_borrowck::CleanupNonCodegenStatements,
|
|
|
|
&simplify::SimplifyCfg::new("early-opt"),
|
|
|
|
// These next passes must be executed together
|
|
|
|
&add_call_guards::CriticalCallEdges,
|
|
|
|
&elaborate_drops::ElaborateDrops,
|
2021-01-18 00:00:00 +00:00
|
|
|
&no_landing_pads::NoLandingPads,
|
2020-03-17 08:18:32 -04:00
|
|
|
// AddMovesForPackedDrops needs to run after drop
|
|
|
|
// elaboration.
|
|
|
|
&add_moves_for_packed_drops::AddMovesForPackedDrops,
|
|
|
|
// `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late,
|
|
|
|
// but before optimizations begin.
|
|
|
|
&add_retag::AddRetag,
|
2020-12-15 00:00:00 +00:00
|
|
|
&lower_intrinsics::LowerIntrinsics,
|
2020-03-17 08:18:32 -04:00
|
|
|
&simplify::SimplifyCfg::new("elaborate-drops"),
|
2020-05-17 15:39:35 +02:00
|
|
|
// `Deaggregator` is conceptually part of MIR building, some backends rely on it happening
|
|
|
|
// and it can help optimizations.
|
|
|
|
&deaggregator::Deaggregator,
|
2020-03-17 08:18:32 -04:00
|
|
|
];
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
run_passes(tcx, body, MirPhase::DropLowering, &[post_borrowck_cleanup]);
|
2020-05-02 21:16:17 -07:00
|
|
|
}
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
2020-08-14 18:01:14 +02:00
|
|
|
let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level;
|
|
|
|
|
|
|
|
// Lowering generator control-flow and variables has to happen before we do anything else
|
|
|
|
// to them. We run some optimizations before that, because they may be harder to do on the state
|
|
|
|
// machine than on MIR with async primitives.
|
|
|
|
let optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[
|
2020-03-17 08:18:32 -04:00
|
|
|
&unreachable_prop::UnreachablePropagation,
|
|
|
|
&uninhabited_enum_branching::UninhabitedEnumBranching,
|
|
|
|
&simplify::SimplifyCfg::new("after-uninhabited-enum-branching"),
|
|
|
|
&inline::Inline,
|
|
|
|
&generator::StateTransform,
|
2020-08-14 18:01:14 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// Even if we don't do optimizations, we still have to lower generators for codegen.
|
|
|
|
let no_optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[&generator::StateTransform];
|
|
|
|
|
|
|
|
// The main optimizations that we do on MIR.
|
|
|
|
let optimizations: &[&dyn MirPass<'tcx>] = &[
|
2021-01-13 00:00:00 +00:00
|
|
|
&remove_storage_markers::RemoveStorageMarkers,
|
2020-10-03 11:18:24 +02:00
|
|
|
&const_goto::ConstGoto,
|
2020-09-19 13:52:55 +02:00
|
|
|
&remove_unneeded_drops::RemoveUnneededDrops,
|
2020-08-11 22:04:49 +00:00
|
|
|
&match_branches::MatchBranchSimplification,
|
2020-08-29 14:16:39 +02:00
|
|
|
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
|
2020-10-01 10:06:37 +02:00
|
|
|
&multiple_return_terminators::MultipleReturnTerminators,
|
2020-08-29 14:16:39 +02:00
|
|
|
&instcombine::InstCombine,
|
2020-03-17 08:18:32 -04:00
|
|
|
&const_prop::ConstProp,
|
|
|
|
&simplify_branches::SimplifyBranches::new("after-const-prop"),
|
2020-08-02 01:47:52 +02:00
|
|
|
&early_otherwise_branch::EarlyOtherwiseBranch,
|
2020-08-10 20:27:41 +02:00
|
|
|
&simplify_comparison_integral::SimplifyComparisonIntegral,
|
Modify SimplifyArmIdentity so it can trigger on mir-opt-level=1
I also added test cases to make sure the optimization can fire on all of
these cases:
```rust
fn case_1(o: Option<u8>) -> Option<u8> {
match o {
Some(u) => Some(u),
None => None,
}
}
fn case2(r: Result<u8, i32>) -> Result<u8, i32> {
match r {
Ok(u) => Ok(u),
Err(i) => Err(i),
}
}
fn case3(r: Result<u8, i32>) -> Result<u8, i32> {
let u = r?;
Ok(u)
}
```
Without MIR inlining, this still does not completely optimize away the
`?` operator because the `Try::into_result()`, `From::from()` and
`Try::from_error()` calls still exist. This does move us a bit closer to
that goal though because:
- We can now run the pass on mir-opt-level=1
- We no longer depend on the copy propagation pass running which is
unlikely to stabilize anytime soon.
2020-05-11 20:13:15 -04:00
|
|
|
&simplify_try::SimplifyArmIdentity,
|
|
|
|
&simplify_try::SimplifyBranchSame,
|
2020-05-24 18:22:04 +02:00
|
|
|
&dest_prop::DestinationPropagation,
|
2020-10-17 02:25:31 +02:00
|
|
|
&simplify_branches::SimplifyBranches::new("final"),
|
2020-03-17 08:18:32 -04:00
|
|
|
&remove_noop_landing_pads::RemoveNoopLandingPads,
|
|
|
|
&simplify::SimplifyCfg::new("final"),
|
2020-05-14 10:11:15 -07:00
|
|
|
&nrvo::RenameReturnPlace,
|
2020-05-30 15:02:32 -04:00
|
|
|
&const_debuginfo::ConstDebugInfo,
|
2020-03-17 08:18:32 -04:00
|
|
|
&simplify::SimplifyLocals,
|
2020-10-01 10:06:37 +02:00
|
|
|
&multiple_return_terminators::MultipleReturnTerminators,
|
2020-10-04 15:52:14 +02:00
|
|
|
&deduplicate_blocks::DeduplicateBlocks,
|
2020-03-17 08:18:32 -04:00
|
|
|
];
|
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
// Optimizations to run even if mir optimizations have been disabled.
|
2020-03-17 08:18:32 -04:00
|
|
|
let no_optimizations: &[&dyn MirPass<'tcx>] = &[
|
|
|
|
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
|
|
|
|
&const_prop::ConstProp,
|
|
|
|
];
|
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
// Some cleanup necessary at least for LLVM and potentially other codegen backends.
|
2020-03-17 08:18:32 -04:00
|
|
|
let pre_codegen_cleanup: &[&dyn MirPass<'tcx>] = &[
|
|
|
|
&add_call_guards::CriticalCallEdges,
|
|
|
|
// Dump the end result for testing and debugging purposes.
|
|
|
|
&dump_mir::Marker("PreCodegen"),
|
|
|
|
];
|
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
// End of pass declarations, now actually run the passes.
|
|
|
|
// Generator Lowering
|
|
|
|
#[rustfmt::skip]
|
|
|
|
run_passes(
|
|
|
|
tcx,
|
|
|
|
body,
|
|
|
|
MirPhase::GeneratorLowering,
|
|
|
|
&[
|
|
|
|
if mir_opt_level > 0 {
|
|
|
|
optimizations_with_generators
|
|
|
|
} else {
|
|
|
|
no_optimizations_with_generators
|
|
|
|
}
|
|
|
|
],
|
|
|
|
);
|
2020-03-17 08:18:32 -04:00
|
|
|
|
2020-08-14 18:01:14 +02:00
|
|
|
// Main optimization passes
|
2020-05-02 21:16:17 -07:00
|
|
|
#[rustfmt::skip]
|
2019-12-22 17:42:04 -05:00
|
|
|
run_passes(
|
|
|
|
tcx,
|
|
|
|
body,
|
2020-08-18 13:44:57 +02:00
|
|
|
MirPhase::Optimization,
|
2019-12-22 17:42:04 -05:00
|
|
|
&[
|
2020-03-17 08:18:32 -04:00
|
|
|
if mir_opt_level > 0 { optimizations } else { no_optimizations },
|
|
|
|
pre_codegen_cleanup,
|
2019-12-22 17:42:04 -05:00
|
|
|
],
|
|
|
|
);
|
2019-08-15 06:39:31 -04:00
|
|
|
}
|
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Optimize the MIR and prepare it for codegen.
|
2020-07-03 20:38:31 +02:00
|
|
|
fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> {
|
|
|
|
let did = did.expect_local();
|
2020-10-28 13:49:10 +00:00
|
|
|
assert_eq!(ty::WithOptConstParam::try_lookup(did, tcx), None);
|
|
|
|
tcx.arena.alloc(inner_optimized_mir(tcx, did))
|
2020-07-03 20:38:31 +02:00
|
|
|
}
|
|
|
|
|
2020-10-28 13:49:10 +00:00
|
|
|
fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
|
|
|
|
if tcx.is_constructor(did.to_def_id()) {
|
2019-08-15 06:39:31 -04:00
|
|
|
// There's no reason to run all of the MIR passes on constructors when
|
|
|
|
// we can just output the MIR we want directly. This also saves const
|
|
|
|
// qualification and borrow checking the trouble of special casing
|
|
|
|
// constructors.
|
2020-10-28 13:49:10 +00:00
|
|
|
return shim::build_adt_ctor(tcx, did.to_def_id());
|
2019-08-15 06:39:31 -04:00
|
|
|
}
|
|
|
|
|
2020-10-28 13:49:10 +00:00
|
|
|
match tcx.hir().body_const_context(did) {
|
2020-12-26 15:10:06 +00:00
|
|
|
// Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked`
|
|
|
|
// which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it
|
|
|
|
// computes and caches its result.
|
2020-10-28 13:49:10 +00:00
|
|
|
Some(hir::ConstContext::ConstFn) => tcx.ensure().mir_for_ctfe(did),
|
2020-10-26 19:00:40 +00:00
|
|
|
None => {}
|
|
|
|
Some(other) => panic!("do not use `optimized_mir` for constants: {:?}", other),
|
|
|
|
}
|
2020-10-28 13:49:10 +00:00
|
|
|
let mut body =
|
|
|
|
tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal();
|
2020-10-04 11:01:38 -07:00
|
|
|
run_optimization_passes(tcx, &mut body);
|
2020-03-19 11:40:38 +00:00
|
|
|
|
|
|
|
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");
|
|
|
|
|
2020-03-27 20:26:20 +01:00
|
|
|
body
|
2017-04-28 06:00:48 -04:00
|
|
|
}
|
2019-07-02 20:50:27 -04:00
|
|
|
|
2020-12-07 12:49:00 +00:00
|
|
|
/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for
|
|
|
|
/// constant evaluation once all substitutions become known.
|
2020-07-06 23:49:53 +02:00
|
|
|
fn promoted_mir<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-07-15 10:50:54 +02:00
|
|
|
def: ty::WithOptConstParam<LocalDefId>,
|
2020-07-06 23:49:53 +02:00
|
|
|
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
|
|
|
|
if tcx.is_constructor(def.did.to_def_id()) {
|
|
|
|
return tcx.arena.alloc(IndexVec::new());
|
|
|
|
}
|
2020-04-18 13:41:52 +01:00
|
|
|
|
2020-07-15 10:50:54 +02:00
|
|
|
if let Some(param_did) = def.const_param_did {
|
2020-07-08 01:03:19 +02:00
|
|
|
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
|
|
|
|
} else {
|
|
|
|
tcx.ensure().mir_borrowck(def.did);
|
|
|
|
}
|
2020-08-14 18:01:14 +02:00
|
|
|
let (_, promoted) = tcx.mir_promoted(def);
|
2019-08-04 16:20:21 -04:00
|
|
|
let mut promoted = promoted.steal();
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
for body in &mut promoted {
|
|
|
|
run_post_borrowck_cleanup_passes(tcx, body);
|
2019-08-04 16:20:21 -04:00
|
|
|
}
|
|
|
|
|
2020-03-19 11:40:38 +00:00
|
|
|
debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR");
|
|
|
|
|
2020-07-06 23:49:53 +02:00
|
|
|
tcx.arena.alloc(promoted)
|
2019-07-02 20:50:27 -04:00
|
|
|
}
|