Skip to content

Commit 00e2dcb

Browse files
authored
Rollup merge of #75517 - RalfJung:promo-intern-comments, r=oli-obk
Promotion and const interning comments I understood some things today which I felt should be put into comments. Cc @rust-lang/wg-const-eval
2 parents 83c0439 + d0d9048 commit 00e2dcb

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5757
ecx.run()?;
5858

5959
// Intern the result
60+
// FIXME: since the DefId of a promoted is the DefId of its owner, this
61+
// means that promoteds in statics are actually interned like statics!
62+
// However, this is also currently crucial because we promote mutable
63+
// non-empty slices in statics to extend their lifetime, and this
64+
// ensures that they are put into a mutable allocation.
65+
// For other kinds of promoteds in statics (like array initializers), this is rather silly.
6066
let intern_kind = match tcx.static_mutability(cid.instance.def_id()) {
6167
Some(m) => InternKind::Static(m),
6268
None if cid.promoted.is_some() => InternKind::Promoted,

src/librustc_mir/interpret/intern.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
312312
let tcx = ecx.tcx;
313313
let base_intern_mode = match intern_kind {
314314
InternKind::Static(mutbl) => InternMode::Static(mutbl),
315-
// FIXME: what about array lengths, array initializers?
315+
// `Constant` includes array lengths.
316+
// `Promoted` includes non-`Copy` array initializers and `rustc_args_required_const` arguments.
316317
InternKind::Constant | InternKind::Promoted => InternMode::ConstBase,
317318
};
318319

src/librustc_mir/transform/promote_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl TempState {
101101
/// of a larger candidate.
102102
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
103103
pub enum Candidate {
104-
/// Borrow of a constant temporary.
104+
/// Borrow of a constant temporary, candidate for lifetime extension.
105105
Ref(Location),
106106

107107
/// Promotion of the `x` in `[x; 32]`.

0 commit comments

Comments
 (0)