From 6e11329b54c2fc4e3ed73f84c1bce13f253cfed7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Aug 2020 11:17:03 +0200 Subject: [PATCH 1/3] mention 'lifetime extension' in promotion doc comments --- src/librustc_mir/transform/promote_consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index c056410570157..94637bae44a78 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -101,7 +101,7 @@ impl TempState { /// of a larger candidate. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum Candidate { - /// Borrow of a constant temporary. + /// Borrow of a constant temporary, candidate for lifetime extension. Ref(Location), /// Promotion of the `x` in `[x; 32]`. From 7805c200d982f11ab6dc3ead72bca89e9be4d294 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Aug 2020 11:18:55 +0200 Subject: [PATCH 2/3] answer an old question re: intern kinds --- src/librustc_mir/interpret/intern.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index dffbc969c21b8..6c8ee72bc66c2 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -312,7 +312,8 @@ pub fn intern_const_alloc_recursive>( let tcx = ecx.tcx; let base_intern_mode = match intern_kind { 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, }; From d0d9048d6ced47e95d90c0213dc3b35f979bbb40 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Aug 2020 13:23:26 +0200 Subject: [PATCH 3/3] add a FIXME concerning interning of promoteds --- src/librustc_mir/const_eval/eval_queries.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 7fbe5c409d3ce..4101f70b8206d 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -57,6 +57,12 @@ fn eval_body_using_ecx<'mir, 'tcx>( ecx.run()?; // 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()) { Some(m) => InternKind::Static(m), None if cid.promoted.is_some() => InternKind::Promoted,