File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ impl ActiveQuery {
8989 // Mark all tracked structs from the previous iteration as active.
9090 self . tracked_struct_ids
9191 . mark_all_active ( active_tracked_ids. iter ( ) . copied ( ) ) ;
92+ self . disambiguator_map
93+ . seed ( active_tracked_ids. iter ( ) . map ( |( id, _) | id) ) ;
9294 }
9395
9496 pub ( super ) fn take_cycle_heads ( & mut self ) -> CycleHeads {
Original file line number Diff line number Diff line change @@ -172,7 +172,6 @@ where
172172 // This is different from `opt_old_memo` which might be from a different revision.
173173 let mut last_provisional_memo_opt: Option < & Memo < ' db , C > > = None ;
174174
175- // TODO: Can we seed those somehow?
176175 let mut last_stale_tracked_ids: Vec < ( Identity , Id ) > = Vec :: new ( ) ;
177176 let mut iteration_count = IterationCount :: initial ( ) ;
178177
Original file line number Diff line number Diff line change @@ -461,11 +461,20 @@ impl DisambiguatorMap {
461461 result
462462 }
463463
464- pub fn clear ( & mut self ) {
464+ pub ( crate ) fn seed < ' a > ( & mut self , identities : impl Iterator < Item = & ' a Identity > ) {
465+ for identity in identities {
466+ self . disambiguate ( IdentityHash {
467+ ingredient_index : identity. ingredient_index ,
468+ hash : identity. hash ,
469+ } ) ;
470+ }
471+ }
472+
473+ pub ( crate ) fn clear ( & mut self ) {
465474 self . map . clear ( )
466475 }
467476
468- pub fn is_empty ( & self ) -> bool {
477+ pub ( crate ) fn is_empty ( & self ) -> bool {
469478 self . map . is_empty ( )
470479 }
471480}
Original file line number Diff line number Diff line change @@ -302,3 +302,36 @@ fn test_cycle_with_fixpoint_structs() {
302302 "DidDiscard { key: IterationNode(Id(402)) }",
303303 ]"# ] ] ) ;
304304}
305+
306+ #[ salsa:: tracked( debug) ]
307+ struct NameWithOffset < ' db > {
308+ name : String ,
309+
310+ #[ tracked]
311+ offset : u32 ,
312+ }
313+
314+ #[ test]
315+ fn cycle_tracked_struct_with_tracked_field ( ) {
316+ #[ salsa:: tracked( cycle_initial=|_, _| 0 ) ]
317+ fn query_a ( db : & dyn salsa:: Database ) -> u32 {
318+ let offset = query_b ( db) ;
319+
320+ let tracked = NameWithOffset :: new ( db, "test" . to_string ( ) , offset) ;
321+
322+ tracked. offset ( db)
323+ }
324+
325+ #[ salsa:: tracked]
326+ fn query_b ( db : & dyn salsa:: Database ) -> u32 {
327+ let base_offset = query_a ( db) ;
328+
329+ ( base_offset + 1 ) . min ( 5 )
330+ }
331+
332+ let db = salsa:: DatabaseImpl :: default ( ) ;
333+
334+ let result = query_a ( & db) ;
335+
336+ assert_eq ! ( result, 5 ) ;
337+ }
You can’t perform that action at this time.
0 commit comments