Skip to content

Commit da13935

Browse files
committed
remove enforce_number_init machine hook that Miri no longer needs
1 parent 9d604f3 commit da13935

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
132132
/// Whether to enforce the validity invariant
133133
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
134134

135-
/// Whether to enforce integers and floats being initialized.
136-
fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
137-
138135
/// Whether function calls should be [ABI](CallAbi)-checked.
139136
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
140137
true
@@ -442,11 +439,6 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
442439
false
443440
}
444441

445-
#[inline(always)]
446-
fn enforce_number_init(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
447-
true
448-
}
449-
450442
#[inline(always)]
451443
fn checked_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
452444
true

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
509509
let value = self.read_scalar(value)?;
510510
// NOTE: Keep this in sync with the array optimization for int/float
511511
// types below!
512-
if M::enforce_number_init(self.ecx) {
513-
try_validation!(
514-
value.check_init(),
515-
self.path,
516-
err_ub!(InvalidUninitBytes(..)) =>
517-
{ "{:x}", value } expected { "initialized bytes" }
518-
);
519-
}
512+
try_validation!(
513+
value.check_init(),
514+
self.path,
515+
err_ub!(InvalidUninitBytes(..)) =>
516+
{ "{:x}", value } expected { "initialized bytes" }
517+
);
520518
// As a special exception we *do* match on a `Scalar` here, since we truly want
521519
// to know its underlying representation (and *not* cast it to an integer).
522520
let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..)));
@@ -621,13 +619,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
621619
// i.e. that we go over the `check_init` below.
622620
let size = scalar_layout.size(self.ecx);
623621
let is_full_range = match scalar_layout {
624-
ScalarAbi::Initialized { .. } => {
625-
if M::enforce_number_init(self.ecx) {
626-
false // not "full" since uninit is not accepted
627-
} else {
628-
scalar_layout.is_always_valid(self.ecx)
629-
}
630-
}
622+
ScalarAbi::Initialized { .. } => false, // not "full" since uninit is not valid
631623
ScalarAbi::Union { .. } => true,
632624
};
633625
if is_full_range {
@@ -903,7 +895,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
903895

904896
match alloc.check_bytes(
905897
alloc_range(Size::ZERO, size),
906-
/*allow_uninit*/ !M::enforce_number_init(self.ecx),
898+
/*allow_uninit*/ false,
907899
/*allow_ptr*/ false,
908900
) {
909901
// In the happy case, we needn't check anything else.

0 commit comments

Comments
 (0)