@@ -116,6 +116,8 @@ pub struct SddManager {
116
116
rotating : RefCell < bool > ,
117
117
118
118
gc_stats : RefCell < GCStatistics > ,
119
+
120
+ apply_level : RefCell < u32 > ,
119
121
}
120
122
121
123
// True and false SDDs have indicies 0 and 1 throughout the whole computation.
@@ -164,6 +166,7 @@ impl SddManager {
164
166
vtree_manager : RefCell :: new ( VTreeManager :: new ( options. vtree_strategy , & variables) ) ,
165
167
literal_manager : RefCell :: new ( LiteralManager :: new ( ) ) ,
166
168
rotating : RefCell :: new ( false ) ,
169
+ apply_level : RefCell :: new ( 0 ) ,
167
170
gc_stats : RefCell :: new ( GCStatistics {
168
171
nodes_collected : 0 ,
169
172
gc_triggered : 0 ,
@@ -246,13 +249,6 @@ impl SddManager {
246
249
) ?;
247
250
tracing:: info!( sdd_id = sdd. id( ) . 0 , size = sdd. size( ) , "after minimizing" ) ;
248
251
}
249
-
250
- // TODO: Remove this once garbage is collected from within
251
- // top-level apply.
252
- if self . should_collect_garbage ( ) {
253
- self . collect_garbage ( ) ;
254
- }
255
-
256
252
i += 1 ;
257
253
}
258
254
}
@@ -867,7 +863,7 @@ impl SddManager {
867
863
matches ! (
868
864
self . options. garbage_collection,
869
865
GarbageCollection :: Automatic
870
- )
866
+ ) && * self . apply_level . borrow ( ) == 0
871
867
}
872
868
873
869
#[ instrument( skip_all, level = tracing:: Level :: DEBUG ) ]
@@ -1073,6 +1069,8 @@ impl SddManager {
1073
1069
. borrow ( )
1074
1070
. least_common_ancestor ( fst. vtree ( ) . unwrap ( ) . index ( ) , snd. vtree ( ) . unwrap ( ) . index ( ) ) ;
1075
1071
1072
+ * self . apply_level . borrow_mut ( ) += 1 ;
1073
+
1076
1074
let elements = match order {
1077
1075
VTreeOrder :: Equal => self . _apply_eq ( fst, snd, op) ,
1078
1076
VTreeOrder :: Inequal => self . _apply_ineq ( fst, snd, op) ,
@@ -1088,7 +1086,11 @@ impl SddManager {
1088
1086
self . insert_node ( & sdd) ;
1089
1087
self . cache_operation ( & CachedOperation :: BinOp ( fst. id ( ) , op, snd. id ( ) ) , sdd. id ( ) ) ;
1090
1088
1091
- // TODO: collect garbage for top-level apply if conditions are met.
1089
+ * self . apply_level . borrow_mut ( ) -= 1 ;
1090
+
1091
+ if self . should_collect_garbage ( ) {
1092
+ self . collect_garbage ( ) ;
1093
+ }
1092
1094
1093
1095
sdd
1094
1096
}
0 commit comments