@@ -572,6 +572,9 @@ pub struct MiriMachine<'tcx> {
572
572
/// Invariant: the promised alignment will never be less than the native alignment of the
573
573
/// allocation.
574
574
pub ( crate ) symbolic_alignment : RefCell < FxHashMap < AllocId , ( Size , Align ) > > ,
575
+
576
+ /// A cache of "data range" computations for unions (i.e., the offsets of non-padding bytes).
577
+ union_data_ranges : FxHashMap < Ty < ' tcx > , RangeSet > ,
575
578
}
576
579
577
580
impl < ' tcx > MiriMachine < ' tcx > {
@@ -714,6 +717,7 @@ impl<'tcx> MiriMachine<'tcx> {
714
717
allocation_spans : RefCell :: new ( FxHashMap :: default ( ) ) ,
715
718
const_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
716
719
symbolic_alignment : RefCell :: new ( FxHashMap :: default ( ) ) ,
720
+ union_data_ranges : FxHashMap :: default ( ) ,
717
721
}
718
722
}
719
723
@@ -826,6 +830,7 @@ impl VisitProvenance for MiriMachine<'_> {
826
830
allocation_spans : _,
827
831
const_cache : _,
828
832
symbolic_alignment : _,
833
+ union_data_ranges : _,
829
834
} = self ;
830
835
831
836
threads. visit_provenance ( visit) ;
@@ -1627,4 +1632,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
1627
1632
ecx. machine . rng . borrow_mut ( ) . gen :: < usize > ( ) % ADDRS_PER_ANON_GLOBAL
1628
1633
}
1629
1634
}
1635
+
1636
+ fn cached_union_data_range < ' e > (
1637
+ ecx : & ' e mut InterpCx < ' tcx , Self > ,
1638
+ ty : Ty < ' tcx > ,
1639
+ compute_range : impl FnOnce ( ) -> RangeSet ,
1640
+ ) -> Cow < ' e , RangeSet > {
1641
+ Cow :: Borrowed ( ecx. machine . union_data_ranges . entry ( ty) . or_insert_with ( compute_range) )
1642
+ }
1630
1643
}
0 commit comments