Trait rustc_const_eval::interpret::visitor::ValueVisitor
source · pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
type V: Projectable<'tcx, M::Provenance> + From<MPlaceTy<'tcx, M::Provenance>>;
// Required method
fn ecx(&self) -> &InterpCx<'tcx, M>;
// Provided methods
fn read_discriminant(
&mut self,
v: &Self::V,
) -> InterpResult<'tcx, VariantIdx> { ... }
fn aggregate_field_iter(
memory_index: &IndexVec<FieldIdx, u32>,
) -> impl Iterator<Item = FieldIdx> + 'static { ... }
fn visit_value(&mut self, v: &Self::V) -> InterpResult<'tcx> { ... }
fn visit_union(
&mut self,
_v: &Self::V,
_fields: NonZero<usize>,
) -> InterpResult<'tcx> { ... }
fn visit_box(
&mut self,
_box_ty: Ty<'tcx>,
_v: &Self::V,
) -> InterpResult<'tcx> { ... }
fn visit_field(
&mut self,
_old_val: &Self::V,
_field: usize,
new_val: &Self::V,
) -> InterpResult<'tcx> { ... }
fn visit_variant(
&mut self,
_old_val: &Self::V,
_variant: VariantIdx,
new_val: &Self::V,
) -> InterpResult<'tcx> { ... }
fn walk_value(&mut self, v: &Self::V) -> InterpResult<'tcx> { ... }
}
Expand description
How to traverse a value and what to do when we are at the leaves.
Required Associated Types§
type V: Projectable<'tcx, M::Provenance> + From<MPlaceTy<'tcx, M::Provenance>>
Required Methods§
Provided Methods§
sourcefn read_discriminant(&mut self, v: &Self::V) -> InterpResult<'tcx, VariantIdx>
fn read_discriminant(&mut self, v: &Self::V) -> InterpResult<'tcx, VariantIdx>
read_discriminant
can be hooked for better error messages.
sourcefn aggregate_field_iter(
memory_index: &IndexVec<FieldIdx, u32>,
) -> impl Iterator<Item = FieldIdx> + 'static
fn aggregate_field_iter( memory_index: &IndexVec<FieldIdx, u32>, ) -> impl Iterator<Item = FieldIdx> + 'static
This function provides the chance to reorder the order in which fields are visited for
FieldsShape::Aggregate
.
The default means we iterate in source declaration order; alternatively this can do some
work with memory_index
to iterate in memory order.
sourcefn visit_value(&mut self, v: &Self::V) -> InterpResult<'tcx>
fn visit_value(&mut self, v: &Self::V) -> InterpResult<'tcx>
Visits the given value, dispatching as appropriate to more specialized visitors.
sourcefn visit_union(
&mut self,
_v: &Self::V,
_fields: NonZero<usize>,
) -> InterpResult<'tcx>
fn visit_union( &mut self, _v: &Self::V, _fields: NonZero<usize>, ) -> InterpResult<'tcx>
Visits the given value as a union. No automatic recursion can happen here.
sourcefn visit_box(&mut self, _box_ty: Ty<'tcx>, _v: &Self::V) -> InterpResult<'tcx>
fn visit_box(&mut self, _box_ty: Ty<'tcx>, _v: &Self::V) -> InterpResult<'tcx>
Visits the given value as the pointer of a Box
. There is nothing to recurse into.
The type of v
will be a raw pointer to T
, but this is a field of Box<T>
and the
pointee type is the actual T
. box_ty
provides the full type of the Box
itself.
sourcefn visit_field(
&mut self,
_old_val: &Self::V,
_field: usize,
new_val: &Self::V,
) -> InterpResult<'tcx>
fn visit_field( &mut self, _old_val: &Self::V, _field: usize, new_val: &Self::V, ) -> InterpResult<'tcx>
Called each time we recurse down to a field of a “product-like” aggregate (structs, tuples, arrays and the like, but not enums), passing in old (outer) and new (inner) value. This gives the visitor the chance to track the stack of nested fields that we are descending through.
sourcefn visit_variant(
&mut self,
_old_val: &Self::V,
_variant: VariantIdx,
new_val: &Self::V,
) -> InterpResult<'tcx>
fn visit_variant( &mut self, _old_val: &Self::V, _variant: VariantIdx, new_val: &Self::V, ) -> InterpResult<'tcx>
Called when recursing into an enum variant. This gives the visitor the chance to track the stack of nested fields that we are descending through.