@@ -280,6 +280,7 @@ fn mir_const<'tcx>(
280
280
tcx. alloc_steal_mir ( body)
281
281
}
282
282
283
+ /// Compute the main MIR body and the list of MIR bodies of the promoteds.
283
284
fn mir_promoted (
284
285
tcx : TyCtxt < ' tcx > ,
285
286
def : ty:: WithOptConstParam < LocalDefId > ,
@@ -321,6 +322,7 @@ fn mir_promoted(
321
322
( tcx. alloc_steal_mir ( body) , tcx. alloc_steal_promoted ( promoted) )
322
323
}
323
324
325
+ /// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
324
326
fn mir_for_ctfe < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> & ' tcx Body < ' tcx > {
325
327
let did = def_id. expect_local ( ) ;
326
328
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> {
330
332
}
331
333
}
332
334
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.
333
340
fn mir_for_ctfe_of_const_arg < ' tcx > (
334
341
tcx : TyCtxt < ' tcx > ,
335
342
( did, param_did) : ( LocalDefId , DefId ) ,
@@ -378,6 +385,9 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
378
385
body
379
386
}
380
387
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.
381
391
fn mir_drops_elaborated_and_const_checked < ' tcx > (
382
392
tcx : TyCtxt < ' tcx > ,
383
393
def : ty:: WithOptConstParam < LocalDefId > ,
@@ -515,6 +525,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
515
525
) ;
516
526
}
517
527
528
+ /// Optimize the MIR and prepare it for codegen.
518
529
fn optimized_mir < ' tcx > ( tcx : TyCtxt < ' tcx > , did : DefId ) -> & ' tcx Body < ' tcx > {
519
530
let did = did. expect_local ( ) ;
520
531
assert_eq ! ( ty:: WithOptConstParam :: try_lookup( did, tcx) , None ) ;
@@ -544,6 +555,8 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
544
555
body
545
556
}
546
557
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.
547
560
fn promoted_mir < ' tcx > (
548
561
tcx : TyCtxt < ' tcx > ,
549
562
def : ty:: WithOptConstParam < LocalDefId > ,
0 commit comments