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
This commit is contained in:
commit
00e2dcbcda
3 changed files with 9 additions and 2 deletions
|
@ -57,6 +57,12 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|
||||||
ecx.run()?;
|
ecx.run()?;
|
||||||
|
|
||||||
// Intern the result
|
// Intern the result
|
||||||
|
// FIXME: since the DefId of a promoted is the DefId of its owner, this
|
||||||
|
// means that promoteds in statics are actually interned like statics!
|
||||||
|
// However, this is also currently crucial because we promote mutable
|
||||||
|
// non-empty slices in statics to extend their lifetime, and this
|
||||||
|
// ensures that they are put into a mutable allocation.
|
||||||
|
// For other kinds of promoteds in statics (like array initializers), this is rather silly.
|
||||||
let intern_kind = match tcx.static_mutability(cid.instance.def_id()) {
|
let intern_kind = match tcx.static_mutability(cid.instance.def_id()) {
|
||||||
Some(m) => InternKind::Static(m),
|
Some(m) => InternKind::Static(m),
|
||||||
None if cid.promoted.is_some() => InternKind::Promoted,
|
None if cid.promoted.is_some() => InternKind::Promoted,
|
||||||
|
|
|
@ -312,7 +312,8 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
|
||||||
let tcx = ecx.tcx;
|
let tcx = ecx.tcx;
|
||||||
let base_intern_mode = match intern_kind {
|
let base_intern_mode = match intern_kind {
|
||||||
InternKind::Static(mutbl) => InternMode::Static(mutbl),
|
InternKind::Static(mutbl) => InternMode::Static(mutbl),
|
||||||
// FIXME: what about array lengths, array initializers?
|
// `Constant` includes array lengths.
|
||||||
|
// `Promoted` includes non-`Copy` array initializers and `rustc_args_required_const` arguments.
|
||||||
InternKind::Constant | InternKind::Promoted => InternMode::ConstBase,
|
InternKind::Constant | InternKind::Promoted => InternMode::ConstBase,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ impl TempState {
|
||||||
/// of a larger candidate.
|
/// of a larger candidate.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum Candidate {
|
pub enum Candidate {
|
||||||
/// Borrow of a constant temporary.
|
/// Borrow of a constant temporary, candidate for lifetime extension.
|
||||||
Ref(Location),
|
Ref(Location),
|
||||||
|
|
||||||
/// Promotion of the `x` in `[x; 32]`.
|
/// Promotion of the `x` in `[x; 32]`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue