@@ -38,10 +38,11 @@ import Data.Function
38
38
import Data.Bifunctor
39
39
import Data.Containers.ListUtils
40
40
41
- import qualified Data.Foldable as F
42
41
import qualified Data.IntMap.Strict as IM
43
42
import qualified Data.Set as S
44
43
44
+ import Data.Equality.Utils.SizedList
45
+
45
46
import Data.Equality.Graph.Internal
46
47
import Data.Equality.Graph.ReprUnionFind
47
48
import Data.Equality.Graph.Classes
@@ -83,7 +84,7 @@ add uncanon_e egr =
83
84
-- to the e-class parents the new e-node and its e-class id
84
85
--
85
86
-- And add new e-class to existing e-classes
86
- new_parents = (S. insert (new_eclass_id, new_en))
87
+ new_parents = ((new_eclass_id, new_en) |: )
87
88
new_classes = IM. insert new_eclass_id new_eclass $
88
89
foldr (IM. adjust ((_parents %~ new_parents)))
89
90
(classes egr)
@@ -152,7 +153,7 @@ merge a b egr0 =
152
153
153
154
-- Leader is the class with more parents
154
155
(leader, leader_class, sub, sub_class) =
155
- if S. size (class_a^. _parents) < S. size (class_b^. _parents)
156
+ if sizeSL (class_a^. _parents) < sizeSL (class_b^. _parents)
156
157
then (b', class_b, a', class_a) -- b is leader
157
158
else (a', class_a, b', class_b) -- a is leader
158
159
@@ -173,20 +174,18 @@ merge a b egr0 =
173
174
-- Add all subsumed parents to worklist We can do this instead of
174
175
-- adding the new e-class itself to the worklist because it would end
175
176
-- up adding its parents anyway
176
- new_worklist = F. toList (sub_class^. _parents) <> worklist egr0
177
+ new_worklist = toListSL (sub_class^. _parents) <> ( worklist egr0)
177
178
178
179
-- If the new_data is different from the classes, the parents of the
179
180
-- class whose data is different from the merged must be put on the
180
181
-- analysisWorklist
181
182
new_analysis_worklist =
182
- (
183
- (if new_data /= (sub_class^. _data)
184
- then sub_class^. _parents
185
- else mempty ) <>
186
- (if new_data /= (leader_class^. _data)
187
- then leader_class^. _parents
188
- else mempty )
189
- ) <>
183
+ (if new_data /= (sub_class^. _data)
184
+ then toListSL (sub_class^. _parents)
185
+ else mempty ) <>
186
+ (if new_data /= (leader_class^. _data)
187
+ then toListSL (leader_class^. _parents)
188
+ else mempty ) <>
190
189
(analysisWorklist egr0)
191
190
192
191
-- ROMES:TODO: The code that makes the -1 * cos test pass when some other things are tweaked
@@ -218,9 +217,9 @@ rebuild (EGraph uf cls mm wl awl) =
218
217
-- empty worklists
219
218
-- repair deduplicated e-classes
220
219
let
221
- emptiedEgr = EGraph uf cls mm mempty mempty
220
+ emptiedEgr = ( EGraph uf cls mm mempty mempty )
222
221
wl' = nubOrd $ bimap (`find` emptiedEgr) (`canonicalize` emptiedEgr) <$> wl
223
- awl' = S. map ( bimap (`find` emptiedEgr) (`canonicalize` emptiedEgr)) awl
222
+ awl' = nubOrd $ bimap (`find` emptiedEgr) (`canonicalize` emptiedEgr) <$> awl
224
223
egr' = foldr repair emptiedEgr wl'
225
224
egr'' = foldr repairAnal egr' awl'
226
225
in
@@ -256,7 +255,7 @@ repairAnal (repair_id, node) egr =
256
255
if c^. _data /= new_data
257
256
-- Merge result is different from original class data, update class
258
257
-- with new_data
259
- then egr { analysisWorklist = (c^. _parents) <> analysisWorklist egr
258
+ then egr { analysisWorklist = toListSL (c^. _parents) <> analysisWorklist egr
260
259
}
261
260
& _class repair_id. _data .~ new_data
262
261
& modifyA repair_id
0 commit comments