Skip to content

Commit 2bf7b68

Browse files
authored
Rollup merge of #129751 - RalfJung:interpret-visit-field-order, r=compiler-errors
interpret/visitor: make memory order iteration slightly more efficient Finally I know enough about RPIT to write this iterator signature correctly. :D This means memory-order iteration now needs an allocation, but it avoids quadratic complexity (where it has to do a linear scan n times to find the n-th field in memory order), so that seems like a win overall. The changed code only affects Miri; the rustc changes are NOPs.
2 parents 3d3563f + d210c7f commit 2bf7b68

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/helpers.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
630630
self.ecx
631631
}
632632

633-
fn aggregate_field_order(memory_index: &IndexVec<FieldIdx, u32>, idx: usize) -> usize {
634-
// We need to do an *inverse* lookup: find the field that has position `idx` in memory order.
635-
for (src_field, &mem_pos) in memory_index.iter_enumerated() {
636-
if mem_pos as usize == idx {
637-
return src_field.as_usize();
638-
}
639-
}
640-
panic!("invalid `memory_index`, could not find {}-th field in memory order", idx);
633+
fn aggregate_field_iter(
634+
memory_index: &IndexVec<FieldIdx, u32>,
635+
) -> impl Iterator<Item = FieldIdx> + 'static {
636+
let inverse_memory_index = memory_index.invert_bijective_mapping();
637+
inverse_memory_index.into_iter()
641638
}
642639

643640
// Hook to detect `UnsafeCell`.

0 commit comments

Comments
 (0)