Auto merge of #150187 - RalfJung:visitor-in-mem-order, r=nnethercote
interpreter/visitor: always iterate in in-memory order Now that this is directly available in the type, there's no reason to ever iterate in any other order.
This commit is contained in:
commit
e1212ea79b
2 changed files with 1 additions and 23 deletions
|
|
@ -4,7 +4,6 @@
|
|||
use std::num::NonZero;
|
||||
|
||||
use rustc_abi::{FieldIdx, FieldsShape, VariantIdx, Variants};
|
||||
use rustc_index::{Idx as _, IndexVec};
|
||||
use rustc_middle::mir::interpret::InterpResult;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use tracing::trace;
|
||||
|
|
@ -24,20 +23,6 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
|
|||
self.ecx().read_discriminant(&v.to_op(self.ecx())?)
|
||||
}
|
||||
|
||||
/// 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 use
|
||||
/// `in_memory_order` to iterate in memory order.
|
||||
#[inline(always)]
|
||||
fn aggregate_field_iter(
|
||||
in_memory_order: &IndexVec<u32, FieldIdx>,
|
||||
) -> impl Iterator<Item = FieldIdx> {
|
||||
// Allow the optimizer to elide the bounds checking when creating each index.
|
||||
let _ = FieldIdx::new(in_memory_order.len());
|
||||
(0..in_memory_order.len()).map(FieldIdx::new)
|
||||
}
|
||||
|
||||
// Recursive actions, ready to be overloaded.
|
||||
/// Visits the given value, dispatching as appropriate to more specialized visitors.
|
||||
#[inline(always)]
|
||||
|
|
@ -171,7 +156,7 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
|
|||
self.visit_union(v, fields)?;
|
||||
}
|
||||
FieldsShape::Arbitrary { in_memory_order, .. } => {
|
||||
for idx in Self::aggregate_field_iter(in_memory_order) {
|
||||
for idx in in_memory_order.iter().copied() {
|
||||
let field = self.ecx().project_field(v, idx)?;
|
||||
self.visit_field(v, idx.as_usize(), &field)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use rustc_data_structures::fx::{FxBuildHasher, FxHashSet};
|
|||
use rustc_hir::Safety;
|
||||
use rustc_hir::def::{DefKind, Namespace};
|
||||
use rustc_hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
||||
|
|
@ -583,12 +582,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
self.ecx
|
||||
}
|
||||
|
||||
fn aggregate_field_iter(
|
||||
in_memory_order: &IndexVec<u32, FieldIdx>,
|
||||
) -> impl Iterator<Item = FieldIdx> {
|
||||
in_memory_order.iter().copied()
|
||||
}
|
||||
|
||||
// Hook to detect `UnsafeCell`.
|
||||
fn visit_value(&mut self, v: &MPlaceTy<'tcx>) -> InterpResult<'tcx> {
|
||||
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue