Skip to content

Commit 20abc70

Browse files
oli-obkwesleywiser
authored andcommitted
Don't intern memory in const prop.
This isn't sound without validation. We don't want to report errors in case of failure to intern and validate, we just don't want to const prop. Interning and const prop is not built for this, let's not do it until we have a clearer picture on aggregate propagation.
1 parent a2fc33e commit 20abc70

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/librustc_mir/interpret/intern.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ pub enum InternKind {
294294
Static(hir::Mutability),
295295
Constant,
296296
Promoted,
297-
ConstProp,
298297
}
299298

300299
/// Intern `ret` and everything it references.
@@ -315,9 +314,7 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
315314
let base_intern_mode = match intern_kind {
316315
InternKind::Static(mutbl) => InternMode::Static(mutbl),
317316
// FIXME: what about array lengths, array initializers?
318-
InternKind::Constant | InternKind::ConstProp | InternKind::Promoted => {
319-
InternMode::ConstBase
320-
}
317+
InternKind::Constant | InternKind::Promoted => InternMode::ConstBase,
321318
};
322319

323320
// Type based interning.
@@ -359,7 +356,10 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
359356
Err(error) => {
360357
ecx.tcx.sess.delay_span_bug(
361358
ecx.tcx.span,
362-
"error during interning should later cause validation failure",
359+
&format!(
360+
"error during interning should later cause validation failure: {}",
361+
error
362+
),
363363
);
364364
// Some errors shouldn't come up because creating them causes
365365
// an allocation, which we should avoid. When that happens,
@@ -400,7 +400,7 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
400400
// immutability is so important.
401401
alloc.mutability = Mutability::Not;
402402
}
403-
InternKind::Constant | InternKind::ConstProp => {
403+
InternKind::Constant => {
404404
// If it's a constant, we should not have any "leftovers" as everything
405405
// is tracked by const-checking.
406406
// FIXME: downgrade this to a warning? It rejects some legitimate consts,

src/librustc_mir/transform/const_prop.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use rustc_trait_selection::traits;
2727

2828
use crate::const_eval::error_to_const_error;
2929
use crate::interpret::{
30-
self, compile_time_machine, intern_const_alloc_recursive, AllocId, Allocation, Frame, ImmTy,
31-
Immediate, InternKind, InterpCx, LocalState, LocalValue, Memory, MemoryKind, OpTy,
32-
Operand as InterpOperand, PlaceTy, Pointer, ScalarMaybeUninit, StackPopCleanup,
30+
self, compile_time_machine, AllocId, Allocation, Frame, ImmTy, Immediate, InterpCx, LocalState,
31+
LocalValue, Memory, MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Pointer,
32+
ScalarMaybeUninit, StackPopCleanup,
3333
};
3434
use crate::transform::{MirPass, MirSource};
3535

@@ -707,11 +707,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
707707
ScalarMaybeUninit::Scalar(l),
708708
ScalarMaybeUninit::Scalar(r),
709709
)) => l.is_bits() && r.is_bits(),
710-
interpret::Operand::Indirect(_) if mir_opt_level >= 2 => {
711-
let mplace = op.assert_mem_place(&self.ecx);
712-
intern_const_alloc_recursive(&mut self.ecx, InternKind::ConstProp, mplace, false);
713-
true
714-
}
710+
interpret::Operand::Indirect(_) if mir_opt_level >= 2 => true,
715711
_ => false,
716712
}
717713
}

0 commit comments

Comments
 (0)