@@ -572,6 +572,9 @@ pub struct MiriMachine<'tcx> {
572572 /// Invariant: the promised alignment will never be less than the native alignment of the
573573 /// allocation.
574574 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 > ,
575578}
576579
577580impl < ' tcx > MiriMachine < ' tcx > {
@@ -714,6 +717,7 @@ impl<'tcx> MiriMachine<'tcx> {
714717 allocation_spans : RefCell :: new ( FxHashMap :: default ( ) ) ,
715718 const_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
716719 symbolic_alignment : RefCell :: new ( FxHashMap :: default ( ) ) ,
720+ union_data_ranges : FxHashMap :: default ( ) ,
717721 }
718722 }
719723
@@ -826,6 +830,7 @@ impl VisitProvenance for MiriMachine<'_> {
826830 allocation_spans : _,
827831 const_cache : _,
828832 symbolic_alignment : _,
833+ union_data_ranges : _,
829834 } = self ;
830835
831836 threads. visit_provenance ( visit) ;
@@ -1627,4 +1632,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
16271632 ecx. machine . rng . borrow_mut ( ) . gen :: < usize > ( ) % ADDRS_PER_ANON_GLOBAL
16281633 }
16291634 }
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+ }
16301643}
0 commit comments