@@ -70,7 +70,7 @@ impl IncCache {
7070 idx
7171 }
7272
73- fn revnode_as_explicit_fun < ' a , I > ( node : & IncNode , args : I ) -> IncNode
73+ fn revnode_as_explicit_fun < ' a , I > ( node : & mut IncNode , args : I )
7474 where
7575 I : DoubleEndedIterator < Item = & ' a Ident > ,
7676 {
@@ -85,16 +85,12 @@ impl IncCache {
8585 let as_function =
8686 args. rfold ( body, |built, id| RichTerm :: from ( Term :: Fun ( * id, built) ) ) ;
8787
88- IncNode :: new (
89- Closure {
90- body : as_function,
91- env,
92- } ,
93- node. kind ,
94- node. bty . clone ( ) ,
95- )
88+ node. orig = Closure {
89+ body : as_function,
90+ env,
91+ }
9692 }
97- _ => node . clone ( ) ,
93+ _ => ( ) ,
9894 }
9995 }
10096
@@ -131,6 +127,27 @@ impl IncCache {
131127 }
132128 }
133129
130+ fn propagate_dirty_vec ( & mut self , indices : Vec < CacheIndex > ) {
131+ let mut visited = HashSet :: new ( ) ;
132+ let mut stack = indices;
133+
134+ while !stack. is_empty ( ) {
135+ let i = stack. pop ( ) . unwrap ( ) ;
136+ visited. insert ( i) ;
137+ let mut current_node = self . store . get_mut ( i) . unwrap ( ) ;
138+ current_node. cached = None ;
139+ current_node. state = IncNodeState :: Suspended ;
140+ println ! ( "IDX: {:?} BLs: {:?}" , i, current_node. backlinks) ;
141+ stack. extend (
142+ current_node
143+ . backlinks
144+ . iter ( )
145+ . map ( |x| x. idx )
146+ . filter ( |x| !visited. contains ( & x) ) ,
147+ )
148+ }
149+ }
150+
134151 /* Do we need this when we can revert in place?
135152
136153 fn propagate_revert(&mut self, id: Ident, idx: CacheIndex) -> HashMap<Ident, CacheIndex> {
@@ -174,11 +191,30 @@ impl IncCache {
174191 let current_node = self . store . get_mut ( * i) . unwrap ( ) ;
175192
176193 for dep in current_node. backlinks . iter_mut ( ) {
177- dep. idx = * new_indices. get ( i) . unwrap ( ) ;
194+ dep. idx = if let Some ( idx) = new_indices. get ( & dep. idx ) {
195+ * idx
196+ } else {
197+ dep. idx
198+ }
178199 }
179200
201+ let mut to_be_updated = vec ! [ ] ;
202+
180203 for dep in current_node. fwdlinks . iter_mut ( ) {
181- dep. idx = * new_indices. get ( i) . unwrap ( ) ;
204+ dep. idx = if let Some ( idx) = new_indices. get ( & dep. idx ) {
205+ * idx
206+ } else {
207+ to_be_updated. push ( dep. clone ( ) ) ;
208+ dep. idx
209+ }
210+ }
211+
212+ for dep in to_be_updated {
213+ let target_node = self . store . get_mut ( dep. idx ) . unwrap ( ) ;
214+ target_node. backlinks . push ( DependencyLink {
215+ id : dep. id ,
216+ idx : * i,
217+ } ) ;
182218 }
183219 }
184220
@@ -345,7 +381,7 @@ impl Cache for IncCache {
345381 env : & mut Environment ,
346382 fields : I ,
347383 ) -> RichTerm {
348- let node = self . store . get ( idx) . unwrap ( ) ;
384+ let node = self . store . get_mut ( idx) . unwrap ( ) ;
349385
350386 let mut deps_filter: Box < dyn FnMut ( & & Ident ) -> bool > = match node. bty . clone ( ) {
351387 BindingType :: Revertible ( FieldDeps :: Known ( deps) ) => {
@@ -355,13 +391,10 @@ impl Cache for IncCache {
355391 BindingType :: Normal => Box :: new ( |_: & & Ident | false ) ,
356392 } ;
357393
358- let node_as_function = self . add_node ( IncCache :: revnode_as_explicit_fun (
359- node,
360- fields. clone ( ) . filter ( & mut deps_filter) ,
361- ) ) ;
394+ IncCache :: revnode_as_explicit_fun ( node, fields. clone ( ) . filter ( & mut deps_filter) ) ;
362395
363396 let fresh_var = Ident :: fresh ( ) ;
364- env. insert ( fresh_var, node_as_function ) ;
397+ env. insert ( fresh_var, idx ) ;
365398
366399 let as_function_closurized = RichTerm :: from ( Term :: Var ( fresh_var) ) ;
367400 let args = fields. filter_map ( |id| deps_filter ( & id) . then ( || RichTerm :: from ( Term :: Var ( * id) ) ) ) ;
@@ -370,4 +403,12 @@ impl Cache for IncCache {
370403 RichTerm :: from ( Term :: App ( partial_app, arg) )
371404 } )
372405 }
406+
407+ fn smart_clone ( & mut self , v : Vec < CacheIndex > ) -> HashMap < CacheIndex , CacheIndex > {
408+ self . smart_clone ( v)
409+ }
410+
411+ fn propagate_dirty ( & mut self , indices : Vec < CacheIndex > ) {
412+ self . propagate_dirty_vec ( indices) ;
413+ }
373414}
0 commit comments