Skip to content

Commit 5b5e076

Browse files
committed
generalize the traversal part of validation to a ValueVisitor
1 parent 0117b42 commit 5b5e076

File tree

6 files changed

+424
-305
lines changed

6 files changed

+424
-305
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,14 @@ fn validate_const<'a, 'tcx>(
535535
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
536536
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
537537
let cid = key.value;
538-
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
538+
let mut ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
539539
let val = (|| {
540540
let op = ecx.const_to_op(constant)?;
541541
let mut ref_tracking = RefTracking::new(op);
542-
while let Some((op, mut path)) = ref_tracking.todo.pop() {
542+
while let Some((op, path)) = ref_tracking.todo.pop() {
543543
ecx.validate_operand(
544544
op,
545-
&mut path,
545+
path,
546546
Some(&mut ref_tracking),
547547
/* const_mode */ true,
548548
)?;

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
521521
// return place is always a local and then this cannot happen.
522522
self.validate_operand(
523523
self.place_to_op(return_place)?,
524-
&mut vec![],
524+
vec![],
525525
None,
526526
/*const_mode*/false,
527527
)?;

src/librustc_mir/interpret/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod terminator;
2323
mod traits;
2424
mod validity;
2525
mod intrinsics;
26+
mod visitor;
2627

2728
pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here
2829

@@ -38,4 +39,6 @@ pub use self::machine::{Machine, AllocMap, MayLeak};
3839

3940
pub use self::operand::{ScalarMaybeUndef, Immediate, ImmTy, Operand, OpTy};
4041

42+
pub use self::visitor::ValueVisitor;
43+
4144
pub use self::validity::RefTracking;

src/librustc_mir/interpret/place.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ where
489489

490490
/// Get the place of a field inside the place, and also the field's type.
491491
/// Just a convenience function, but used quite a bit.
492+
/// This is the only projection that might have a side-effect: We cannot project
493+
/// into the field of a local `ScalarPair`, we have to first allocate it.
492494
pub fn place_field(
493495
&mut self,
494496
base: PlaceTy<'tcx, M::PointerTag>,
@@ -501,7 +503,7 @@ where
501503
}
502504

503505
pub fn place_downcast(
504-
&mut self,
506+
&self,
505507
base: PlaceTy<'tcx, M::PointerTag>,
506508
variant: usize,
507509
) -> EvalResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
@@ -643,7 +645,7 @@ where
643645

644646
if M::enforce_validity(self) {
645647
// Data got changed, better make sure it matches the type!
646-
self.validate_operand(self.place_to_op(dest)?, &mut vec![], None, /*const_mode*/false)?;
648+
self.validate_operand(self.place_to_op(dest)?, vec![], None, /*const_mode*/false)?;
647649
}
648650

649651
Ok(())
@@ -765,7 +767,7 @@ where
765767

766768
if M::enforce_validity(self) {
767769
// Data got changed, better make sure it matches the type!
768-
self.validate_operand(self.place_to_op(dest)?, &mut vec![], None, /*const_mode*/false)?;
770+
self.validate_operand(self.place_to_op(dest)?, vec![], None, /*const_mode*/false)?;
769771
}
770772

771773
Ok(())
@@ -843,7 +845,7 @@ where
843845

844846
if M::enforce_validity(self) {
845847
// Data got changed, better make sure it matches the type!
846-
self.validate_operand(dest.into(), &mut vec![], None, /*const_mode*/false)?;
848+
self.validate_operand(dest.into(), vec![], None, /*const_mode*/false)?;
847849
}
848850

849851
Ok(())

0 commit comments

Comments
 (0)