@@ -122,11 +122,17 @@ let fixpoint t ~init ~f =
122
122
| G. Has_loop conts ->
123
123
let q = Queue. create () in
124
124
List. iter (fun k -> Queue. add k q) conts;
125
- let q_s = ref (Continuation.Set. of_list conts) in
125
+ (* We enforce the invariant that [q] contains no duplicates, and that
126
+ [!q_s] precisely contains the continuations in [conts] that are not
127
+ in [q]. Besides ensuring we don't add the same element twice to
128
+ [q], this enforces as well that only continuations in the current
129
+ strongly-connected component, that is, the continuations in
130
+ [conts], can ever be in [q]. *)
131
+ let q_s = ref Continuation.Set. empty in
126
132
let cur = ref res in
127
133
while not (Queue. is_empty q) do
128
134
let callee = Queue. pop q in
129
- q_s := Continuation.Set. remove callee ! q_s;
135
+ q_s := Continuation.Set. add callee ! q_s;
130
136
let callee_set = Continuation.Map. find callee ! cur in
131
137
let callers =
132
138
match Continuation.Map. find callee t.callers with
@@ -144,10 +150,10 @@ let fixpoint t ~init ~f =
144
150
if not (Variable.Set. equal caller_set caller_new_set)
145
151
then (
146
152
cur := Continuation.Map. add caller caller_new_set ! cur;
147
- if not ( Continuation.Set. mem caller ! q_s)
153
+ if Continuation.Set. mem caller ! q_s
148
154
then (
149
155
Queue. add caller q;
150
- q_s := Continuation.Set. add caller ! q_s)))
156
+ q_s := Continuation.Set. remove caller ! q_s)))
151
157
callers
152
158
done ;
153
159
! cur)
0 commit comments