@@ -280,6 +280,7 @@ fn mir_const<'tcx>(
280280 tcx. alloc_steal_mir ( body)
281281}
282282
283+ /// Compute the main MIR body and the list of MIR bodies of the promoteds.
283284fn mir_promoted (
284285 tcx : TyCtxt < ' tcx > ,
285286 def : ty:: WithOptConstParam < LocalDefId > ,
@@ -321,6 +322,7 @@ fn mir_promoted(
321322 ( tcx. alloc_steal_mir ( body) , tcx. alloc_steal_promoted ( promoted) )
322323}
323324
325+ /// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
324326fn mir_for_ctfe < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> & ' tcx Body < ' tcx > {
325327 let did = def_id. expect_local ( ) ;
326328 if let Some ( def) = ty:: WithOptConstParam :: try_lookup ( did, tcx) {
@@ -330,6 +332,11 @@ fn mir_for_ctfe<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Body<'tcx> {
330332 }
331333}
332334
335+ /// Same as `mir_for_ctfe`, but used to get the MIR of a const generic parameter.
336+ /// The docs on `WithOptConstParam` explain this a bit more, but the TLDR is that
337+ /// we'd get cycle errors with `mir_for_ctfe`, because typeck would need to typeck
338+ /// the const parameter while type checking the main body, which in turn would try
339+ /// to type check the main body again.
333340fn mir_for_ctfe_of_const_arg < ' tcx > (
334341 tcx : TyCtxt < ' tcx > ,
335342 ( did, param_did) : ( LocalDefId , DefId ) ,
@@ -378,6 +385,9 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
378385 body
379386}
380387
388+ /// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
389+ /// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
390+ /// end up missing the source MIR due to stealing happening.
381391fn mir_drops_elaborated_and_const_checked < ' tcx > (
382392 tcx : TyCtxt < ' tcx > ,
383393 def : ty:: WithOptConstParam < LocalDefId > ,
@@ -515,6 +525,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
515525 ) ;
516526}
517527
528+ /// Optimize the MIR and prepare it for codegen.
518529fn optimized_mir < ' tcx > ( tcx : TyCtxt < ' tcx > , did : DefId ) -> & ' tcx Body < ' tcx > {
519530 let did = did. expect_local ( ) ;
520531 assert_eq ! ( ty:: WithOptConstParam :: try_lookup( did, tcx) , None ) ;
@@ -544,6 +555,8 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
544555 body
545556}
546557
558+ /// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for
559+ /// constant evaluation once all substitutions become known.
547560fn promoted_mir < ' tcx > (
548561 tcx : TyCtxt < ' tcx > ,
549562 def : ty:: WithOptConstParam < LocalDefId > ,
0 commit comments