@@ -34,7 +34,6 @@ use serde::Serialize;
3434use std:: {
3535 borrow:: Cow ,
3636 collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
37- mem,
3837 sync:: Arc ,
3938} ;
4039use transcript:: BasicTranscript as Transcript ;
@@ -102,6 +101,7 @@ pub struct EmulationResult<'a> {
102101}
103102
104103pub struct RAMRecord {
104+ pub ram_type : RAMType ,
105105 pub id : u64 ,
106106 pub addr : WordAddr ,
107107 pub prev_cycle : Cycle ,
@@ -115,14 +115,10 @@ pub struct ShardContext<'a> {
115115 max_num_shards : usize ,
116116 max_cycle : Cycle ,
117117 addr_future_accesses : Cow < ' a , HashMap < ( WordAddr , Cycle ) , Cycle > > ,
118- read_thread_based_record_storage : Either <
119- Vec < [ BTreeMap < WordAddr , RAMRecord > ; mem:: variant_count :: < RAMType > ( ) ] > ,
120- & ' a mut [ BTreeMap < WordAddr , RAMRecord > ; mem:: variant_count :: < RAMType > ( ) ] ,
121- > ,
122- write_thread_based_record_storage : Either <
123- Vec < [ BTreeMap < WordAddr , RAMRecord > ; mem:: variant_count :: < RAMType > ( ) ] > ,
124- & ' a mut [ BTreeMap < WordAddr , RAMRecord > ; mem:: variant_count :: < RAMType > ( ) ] ,
125- > ,
118+ read_thread_based_record_storage :
119+ Either < Vec < BTreeMap < WordAddr , RAMRecord > > , & ' a mut BTreeMap < WordAddr , RAMRecord > > ,
120+ write_thread_based_record_storage :
121+ Either < Vec < BTreeMap < WordAddr , RAMRecord > > , & ' a mut BTreeMap < WordAddr , RAMRecord > > ,
126122 pub cur_shard_cycle_range : std:: ops:: Range < usize > ,
127123}
128124
@@ -137,13 +133,13 @@ impl<'a> Default for ShardContext<'a> {
137133 read_thread_based_record_storage : Either :: Left (
138134 ( 0 ..max_threads)
139135 . into_par_iter ( )
140- . map ( |_| std :: array :: from_fn ( |_| BTreeMap :: new ( ) ) )
136+ . map ( |_| BTreeMap :: new ( ) )
141137 . collect :: < Vec < _ > > ( ) ,
142138 ) ,
143139 write_thread_based_record_storage : Either :: Left (
144140 ( 0 ..max_threads)
145141 . into_par_iter ( )
146- . map ( |_| std :: array :: from_fn ( |_| BTreeMap :: new ( ) ) )
142+ . map ( |_| BTreeMap :: new ( ) )
147143 . collect :: < Vec < _ > > ( ) ,
148144 ) ,
149145 cur_shard_cycle_range : 0 ..usize:: MAX ,
@@ -181,14 +177,14 @@ impl<'a> ShardContext<'a> {
181177 read_thread_based_record_storage : Either :: Left (
182178 ( 0 ..max_threads)
183179 . into_par_iter ( )
184- . map ( |_| std :: array :: from_fn ( |_| BTreeMap :: new ( ) ) )
180+ . map ( |_| BTreeMap :: new ( ) )
185181 . collect :: < Vec < _ > > ( ) ,
186182 ) ,
187183 // TODO with_capacity optimisation
188184 write_thread_based_record_storage : Either :: Left (
189185 ( 0 ..max_threads)
190186 . into_par_iter ( )
191- . map ( |_| std :: array :: from_fn ( |_| BTreeMap :: new ( ) ) )
187+ . map ( |_| BTreeMap :: new ( ) )
192188 . collect :: < Vec < _ > > ( ) ,
193189 ) ,
194190 cur_shard_cycle_range,
@@ -220,6 +216,20 @@ impl<'a> ShardContext<'a> {
220216 }
221217 }
222218
219+ pub fn read_records ( & self ) -> & [ BTreeMap < WordAddr , RAMRecord > ] {
220+ match & self . read_thread_based_record_storage {
221+ Either :: Left ( m) => m,
222+ Either :: Right ( _) => panic ! ( "undefined behaviour" ) ,
223+ }
224+ }
225+
226+ pub fn write_records ( & self ) -> & [ BTreeMap < WordAddr , RAMRecord > ] {
227+ match & self . write_thread_based_record_storage {
228+ Either :: Left ( m) => m,
229+ Either :: Right ( _) => panic ! ( "undefined behaviour" ) ,
230+ }
231+ }
232+
223233 #[ inline( always) ]
224234 pub fn is_first_shard ( & self ) -> bool {
225235 self . shard_id == 0
@@ -269,9 +279,10 @@ impl<'a> ShardContext<'a> {
269279 . as_mut ( )
270280 . right ( )
271281 . expect ( "illegal type" ) ;
272- ram_record[ ram_type as usize ] . insert (
282+ ram_record. insert (
273283 addr,
274284 RAMRecord {
285+ ram_type,
275286 id,
276287 addr,
277288 prev_cycle,
@@ -291,9 +302,10 @@ impl<'a> ShardContext<'a> {
291302 . as_mut ( )
292303 . right ( )
293304 . expect ( "illegal type" ) ;
294- ram_record[ ram_type as usize ] . insert (
305+ ram_record. insert (
295306 addr,
296307 RAMRecord {
308+ ram_type,
297309 id,
298310 addr,
299311 prev_cycle,
0 commit comments