Skip to content

Commit dd4eb5c

Browse files
Store promoted_fragments on the MIR instead of in the pass
1 parent 7fecc3a commit dd4eb5c

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_span::Span;
2323

2424
use rustc_index::vec::{Idx, IndexVec};
2525

26-
use std::cell::Cell;
2726
use std::{cmp, iter, mem};
2827

2928
use crate::transform::check_consts::{qualifs, ConstCx};
@@ -33,14 +32,12 @@ use crate::transform::check_consts::{qualifs, ConstCx};
3332
/// Promotion is the extraction of promotable temps into separate MIR bodies so they can have
3433
/// `'static` lifetime.
3534
///
36-
/// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each
35+
/// After this pass is run, `body.promoted_fragments` will hold the MIR body corresponding to each
3736
/// newly created `Constant`.
3837
#[derive(Default)]
39-
pub struct PromoteTemps<'tcx> {
40-
pub promoted_fragments: Cell<IndexVec<Promoted, Body<'tcx>>>,
41-
}
38+
pub struct PromoteTemps;
4239

43-
impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
40+
impl<'tcx> MirPass<'tcx> for PromoteTemps {
4441
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4542
// There's not really any point in promoting errorful MIR.
4643
//
@@ -61,7 +58,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6158
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
6259

6360
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
64-
self.promoted_fragments.set(promoted);
61+
body.promoted_fragments = promoted;
6562
}
6663
}
6764

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ pub struct Body<'tcx> {
263263
/// potentially allow things like `[u8; std::mem::size_of::<T>() * 0]` due to this.
264264
pub is_polymorphic: bool,
265265

266+
/// A list of MIR fragments for promotable temps inside this body.
267+
///
268+
/// This field is only populated during the `PromoteTemps` MIR pass and will be emptied
269+
/// immediately after.
270+
pub promoted_fragments: IndexVec<Promoted, Body<'tcx>>,
271+
266272
predecessor_cache: PredecessorCache,
267273
is_cyclic: GraphIsCyclicCache,
268274
}
@@ -311,6 +317,7 @@ impl<'tcx> Body<'tcx> {
311317
is_polymorphic: false,
312318
predecessor_cache: PredecessorCache::new(),
313319
is_cyclic: GraphIsCyclicCache::new(),
320+
promoted_fragments: Default::default(),
314321
};
315322
body.is_polymorphic = body.definitely_has_param_types_or_consts(tcx);
316323
body
@@ -338,6 +345,7 @@ impl<'tcx> Body<'tcx> {
338345
is_polymorphic: false,
339346
predecessor_cache: PredecessorCache::new(),
340347
is_cyclic: GraphIsCyclicCache::new(),
348+
promoted_fragments: Default::default(),
341349
}
342350
}
343351

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn mir_promoted(
328328

329329
run_passes(tcx, &mut body, MirPhase::ConstPromotion, &[promote, opt_coverage]);
330330

331-
let promoted = promote_pass.promoted_fragments.into_inner();
331+
let promoted = std::mem::take(&mut body.promoted_fragments);
332332
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
333333
}
334334

0 commit comments

Comments
 (0)