Skip to content

Commit 1ba2153

Browse files
Auto merge of #150187 - RalfJung:visitor-in-mem-order, r=<try>
interpreter/visitor: always iterate in in-memory order
2 parents 838a912 + 889ad15 commit 1ba2153

File tree

2 files changed

+1
-23
lines changed

2 files changed

+1
-23
lines changed

compiler/rustc_const_eval/src/interpret/visitor.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::num::NonZero;
55

66
use rustc_abi::{FieldIdx, FieldsShape, VariantIdx, Variants};
7-
use rustc_index::{Idx as _, IndexVec};
87
use rustc_middle::mir::interpret::InterpResult;
98
use rustc_middle::ty::{self, Ty};
109
use tracing::trace;
@@ -24,20 +23,6 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
2423
self.ecx().read_discriminant(&v.to_op(self.ecx())?)
2524
}
2625

27-
/// This function provides the chance to reorder the order in which fields are visited for
28-
/// `FieldsShape::Aggregate`.
29-
///
30-
/// The default means we iterate in source declaration order; alternatively this can use
31-
/// `in_memory_order` to iterate in memory order.
32-
#[inline(always)]
33-
fn aggregate_field_iter(
34-
in_memory_order: &IndexVec<u32, FieldIdx>,
35-
) -> impl Iterator<Item = FieldIdx> {
36-
// Allow the optimizer to elide the bounds checking when creating each index.
37-
let _ = FieldIdx::new(in_memory_order.len());
38-
(0..in_memory_order.len()).map(FieldIdx::new)
39-
}
40-
4126
// Recursive actions, ready to be overloaded.
4227
/// Visits the given value, dispatching as appropriate to more specialized visitors.
4328
#[inline(always)]
@@ -171,7 +156,7 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
171156
self.visit_union(v, fields)?;
172157
}
173158
FieldsShape::Arbitrary { in_memory_order, .. } => {
174-
for idx in Self::aggregate_field_iter(in_memory_order) {
159+
for idx in in_memory_order.iter().copied() {
175160
let field = self.ecx().project_field(v, idx)?;
176161
self.visit_field(v, idx.as_usize(), &field)?;
177162
}

src/tools/miri/src/helpers.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_data_structures::fx::{FxBuildHasher, FxHashSet};
1010
use rustc_hir::Safety;
1111
use rustc_hir::def::{DefKind, Namespace};
1212
use rustc_hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefId, LOCAL_CRATE};
13-
use rustc_index::IndexVec;
1413
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1514
use rustc_middle::middle::dependency_format::Linkage;
1615
use rustc_middle::middle::exported_symbols::ExportedSymbol;
@@ -583,12 +582,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
583582
self.ecx
584583
}
585584

586-
fn aggregate_field_iter(
587-
in_memory_order: &IndexVec<u32, FieldIdx>,
588-
) -> impl Iterator<Item = FieldIdx> {
589-
in_memory_order.iter().copied()
590-
}
591-
592585
// Hook to detect `UnsafeCell`.
593586
fn visit_value(&mut self, v: &MPlaceTy<'tcx>) -> InterpResult<'tcx> {
594587
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);

0 commit comments

Comments
 (0)