@@ -113,6 +113,7 @@ struct
113113 ) x
114114
115115 let should_join x y =
116+ (* TODO: GobList.for_all3 *)
116117 let rec zip3 lst1 lst2 lst3 = match lst1,lst2,lst3 with
117118 | [] ,_ , _ -> []
118119 | _ ,[] , _ -> []
@@ -175,26 +176,6 @@ struct
175176 in
176177 iter (uncurry side_one) @@ group_assoc_eq V. equal xs
177178
178- let do_assigns ctx assigns (xs :(int * Obj.t) list ) =
179- if List. is_empty assigns then xs (* nothing to do *)
180- else
181- let spec_assign n d : Obj.t =
182- (* spec of current analysis *)
183- let (module S :MCPSpec ) = spec n in
184- let assign_one d (lval , exp , name , ctx ) =
185- match name with
186- | Some x when x <> find_spec_name n -> obj d (* do nothing if current spec name is filtered out *)
187- | _ ->
188- let ctx' = {(obj ctx) with local = obj d} in
189- S. assign ctx' lval exp
190- in
191- let get_lval (lval , exp , name , ctx ) = lval in
192- (* group by assigns on the same lval -> only those must be joined *)
193- List. group (compareBy get_lval) assigns
194- |> List. fold_left (fun d xs -> List. map (assign_one d) xs |> List. reduce S.D. join |> repr) d
195- in
196- List. map (fun (n ,d ) -> n, spec_assign n d) xs
197-
198179 let rec do_splits ctx pv (xs :(int * (Obj.t * Events.t list) ) list ) =
199180 let split_one n (d ,emits ) =
200181 let nv = assoc_replace (n,d) pv in
@@ -218,25 +199,25 @@ struct
218199 let do_emit ctx = function
219200 | Events. SplitBranch (exp , tv ) ->
220201 ctx_with_local ctx (branch ctx exp tv)
202+ | Events. Assign {lval; exp} ->
203+ ctx_with_local ctx (assign ctx lval exp)
221204 | e ->
222205 let spawns = ref [] in
223206 let splits = ref [] in
224207 let sides = ref [] in (* why do we need to collect these instead of calling ctx.sideg directly? *)
225- let assigns = ref [] in
226208 let emits = ref [] in
227209 let ctx'' = outer_ctx " do_emits" ~spawns ~sides ~emits ctx in
228210 let octx'' = outer_ctx " do_emits" ~spawns ~sides ~emits octx in
229211 let f post_all (n ,(module S:MCPSpec ),(d ,od )) =
230- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " do_emits" ~splits ~assigns ~ post_all ctx'' n d in
231- let octx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " do_emits" ~splits ~assigns ~ post_all octx'' n d in
212+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " do_emits" ~splits ~post_all ctx'' n d in
213+ let octx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " do_emits" ~splits ~post_all octx'' n d in
232214 n, repr @@ S. event ctx' e octx'
233215 in
234216 let d, q = map_deadcode f @@ spec_list2 ctx.local octx.local in
235217 if M. tracing then M. tracel " event" " %a\n before: %a\n after:%a\n " Events. pretty e D. pretty ctx.local D. pretty d;
236218 do_sideg ctx ! sides;
237219 do_spawns ctx ! spawns;
238220 do_splits ctx d ! splits;
239- let d = do_assigns ctx ! assigns d in
240221 let d = do_emits ctx ! emits d in
241222 if q then raise Deadcode else ctx_with_local ctx d
242223 in
@@ -247,18 +228,16 @@ struct
247228 let spawns = ref [] in
248229 let splits = ref [] in
249230 let sides = ref [] in (* why do we need to collect these instead of calling ctx.sideg directly? *)
250- let assigns = ref [] in
251231 let emits = ref [] in
252232 let ctx'' = outer_ctx " branch" ~spawns ~sides ~emits ctx in
253233 let f post_all (n ,(module S:MCPSpec ),d ) =
254- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " branch" ~splits ~assigns ~ post_all ctx'' n d in
234+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " branch" ~splits ~post_all ctx'' n d in
255235 n, repr @@ S. branch ctx' e tv
256236 in
257237 let d, q = map_deadcode f @@ spec_list ctx.local in
258238 do_sideg ctx ! sides;
259239 do_spawns ctx ! spawns;
260240 do_splits ctx d ! splits;
261- let d = do_assigns ctx ! assigns d in
262241 let d = do_emits ctx ! emits d in
263242 if q then raise Deadcode else d
264243
@@ -343,7 +322,7 @@ struct
343322 }
344323
345324 (* Explicitly polymorphic type required here for recursive call in branch. *)
346- and inner_ctx: type d g c v. string -> ?splits:(int * (Obj. t * Events. t list )) list ref -> ?assigns:(lval * exp * string option * Obj. t) list ref -> ? post_all:(int * Obj. t) list -> (D. t, G. t, C. t, V. t) ctx -> int -> Obj. t -> (d, g, c, v) ctx = fun tfname ?splits ? assigns ?(post_all =[] ) ctx n d ->
325+ and inner_ctx: type d g c v. string -> ?splits:(int * (Obj. t * Events. t list )) list ref -> ?post_all:(int * Obj. t) list -> (D. t, G. t, C. t, V. t) ctx -> int -> Obj. t -> (d, g, c, v) ctx = fun tfname ?splits ?(post_all =[] ) ctx n d ->
347326 let split = match splits with
348327 | Some splits -> (fun d es -> splits := (n,(repr d,es)) :: ! splits)
349328 | None -> (fun _ _ -> failwith (" Cannot \" split\" in " ^ tfname ^ " context." ))
@@ -356,16 +335,11 @@ struct
356335 ; global = (fun v -> ctx.global (v_of n v) |> g_to n |> obj)
357336 ; split
358337 ; sideg = (fun v g -> ctx.sideg (v_of n v) (`Lifted (n, repr g)))
359- ; assign = (
360- match assigns with
361- | Some assigns -> (fun ?name v e -> assigns := (v,e,name, repr ctx')::! assigns)
362- | None -> (fun ?name _ -> failwith (" Cannot \" assign\" in " ^ tfname ^ " context." ))
363- )
364338 }
365339 in
366340 ctx'
367341
368- let assign (ctx :(D.t, G.t, C.t, V.t) ctx ) l e =
342+ and assign (ctx :(D.t, G.t, C.t, V.t) ctx ) l e =
369343 let spawns = ref [] in
370344 let splits = ref [] in
371345 let sides = ref [] in
@@ -404,113 +378,101 @@ struct
404378 let spawns = ref [] in
405379 let splits = ref [] in
406380 let sides = ref [] in
407- let assigns = ref [] in
408381 let emits = ref [] in
409382 let ctx'' = outer_ctx " body" ~spawns ~sides ~emits ctx in
410383 let f post_all (n ,(module S:MCPSpec ),d ) =
411- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " body" ~splits ~assigns ~ post_all ctx'' n d in
384+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " body" ~splits ~post_all ctx'' n d in
412385 n, repr @@ S. body ctx' f
413386 in
414387 let d, q = map_deadcode f @@ spec_list ctx.local in
415388 do_sideg ctx ! sides;
416389 do_spawns ctx ! spawns;
417390 do_splits ctx d ! splits;
418- let d = do_assigns ctx ! assigns d in
419391 let d = do_emits ctx ! emits d in
420392 if q then raise Deadcode else d
421393
422394 let return (ctx :(D.t, G.t, C.t, V.t) ctx ) e f =
423395 let spawns = ref [] in
424396 let splits = ref [] in
425397 let sides = ref [] in
426- let assigns = ref [] in
427398 let emits = ref [] in
428399 let ctx'' = outer_ctx " return" ~spawns ~sides ~emits ctx in
429400 let f post_all (n ,(module S:MCPSpec ),d ) =
430- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " return" ~splits ~assigns ~ post_all ctx'' n d in
401+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " return" ~splits ~post_all ctx'' n d in
431402 n, repr @@ S. return ctx' e f
432403 in
433404 let d, q = map_deadcode f @@ spec_list ctx.local in
434405 do_sideg ctx ! sides;
435406 do_spawns ctx ! spawns;
436407 do_splits ctx d ! splits;
437- let d = do_assigns ctx ! assigns d in
438408 let d = do_emits ctx ! emits d in
439409 if q then raise Deadcode else d
440410
441411 let intrpt (ctx :(D.t, G.t, C.t, V.t) ctx ) =
442412 let spawns = ref [] in
443413 let splits = ref [] in
444414 let sides = ref [] in
445- let assigns = ref [] in
446415 let emits = ref [] in
447416 let ctx'' = outer_ctx " interpt" ~spawns ~sides ~emits ctx in
448417 let f post_all (n ,(module S:MCPSpec ),d ) =
449- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " interpt" ~splits ~assigns ~ post_all ctx'' n d in
418+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " interpt" ~splits ~post_all ctx'' n d in
450419 n, repr @@ S. intrpt ctx'
451420 in
452421 let d, q = map_deadcode f @@ spec_list ctx.local in
453422 do_sideg ctx ! sides;
454423 do_spawns ctx ! spawns;
455424 do_splits ctx d ! splits;
456- let d = do_assigns ctx ! assigns d in
457425 let d = do_emits ctx ! emits d in
458426 if q then raise Deadcode else d
459427
460428 let asm (ctx :(D.t, G.t, C.t, V.t) ctx ) =
461429 let spawns = ref [] in
462430 let splits = ref [] in
463431 let sides = ref [] in
464- let assigns = ref [] in
465432 let emits = ref [] in
466433 let ctx'' = outer_ctx " asm" ~spawns ~sides ~emits ctx in
467434 let f post_all (n ,(module S:MCPSpec ),d ) =
468- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " asm" ~splits ~assigns ~ post_all ctx'' n d in
435+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " asm" ~splits ~post_all ctx'' n d in
469436 n, repr @@ S. asm ctx'
470437 in
471438 let d, q = map_deadcode f @@ spec_list ctx.local in
472439 do_sideg ctx ! sides;
473440 do_spawns ctx ! spawns;
474441 do_splits ctx d ! splits;
475- let d = do_assigns ctx ! assigns d in
476442 let d = do_emits ctx ! emits d in
477443 if q then raise Deadcode else d
478444
479445 let skip (ctx :(D.t, G.t, C.t, V.t) ctx ) =
480446 let spawns = ref [] in
481447 let splits = ref [] in
482448 let sides = ref [] in
483- let assigns = ref [] in
484449 let emits = ref [] in
485450 let ctx'' = outer_ctx " skip" ~spawns ~sides ~emits ctx in
486451 let f post_all (n ,(module S:MCPSpec ),d ) =
487- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " skip" ~splits ~assigns ~ post_all ctx'' n d in
452+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " skip" ~splits ~post_all ctx'' n d in
488453 n, repr @@ S. skip ctx'
489454 in
490455 let d, q = map_deadcode f @@ spec_list ctx.local in
491456 do_sideg ctx ! sides;
492457 do_spawns ctx ! spawns;
493458 do_splits ctx d ! splits;
494- let d = do_assigns ctx ! assigns d in
495459 let d = do_emits ctx ! emits d in
496460 if q then raise Deadcode else d
497461
498462 let special (ctx :(D.t, G.t, C.t, V.t) ctx ) r f a =
499463 let spawns = ref [] in
500464 let splits = ref [] in
501465 let sides = ref [] in
502- let assigns = ref [] in
503466 let emits = ref [] in
504467 let ctx'' = outer_ctx " special" ~spawns ~sides ~emits ctx in
505468 let f post_all (n ,(module S:MCPSpec ),d ) =
506- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " special" ~splits ~assigns ~ post_all ctx'' n d in
469+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " special" ~splits ~post_all ctx'' n d in
507470 n, repr @@ S. special ctx' r f a
508471 in
509472 let d, q = map_deadcode f @@ spec_list ctx.local in
510473 do_sideg ctx ! sides;
511474 do_spawns ctx ! spawns;
512475 do_splits ctx d ! splits;
513- let d = do_assigns ctx ! assigns d in
514476 let d = do_emits ctx ! emits d in
515477 if q then raise Deadcode else d
516478
@@ -547,7 +509,6 @@ struct
547509 let combine (ctx :(D.t, G.t, C.t, V.t) ctx ) r fe f a fc fd =
548510 let spawns = ref [] in
549511 let sides = ref [] in
550- let assigns = ref [] in
551512 let emits = ref [] in
552513 let ctx'' = outer_ctx " combine" ~spawns ~sides ~emits ctx in
553514 (* Like spec_list2 but for three lists. Tail recursion like map3_rev would have.
@@ -565,13 +526,12 @@ struct
565526 | _ , _ , _ -> invalid_arg " MCP.spec_list3_rev_acc"
566527 in
567528 let f post_all (n ,(module S:MCPSpec ),(d ,fc ,fd )) =
568- let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " combine" ~assigns ~ post_all ctx'' n d in
529+ let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx " combine" ~post_all ctx'' n d in
569530 n, repr @@ S. combine ctx' r fe f a (Option. map obj fc) (obj fd)
570531 in
571532 let d, q = map_deadcode f @@ List. rev @@ spec_list3_rev_acc [] ctx.local fc fd in
572533 do_sideg ctx ! sides;
573534 do_spawns ctx ! spawns;
574- let d = do_assigns ctx ! assigns d in
575535 let d = do_emits ctx ! emits d in
576536 if q then raise Deadcode else d
577537
0 commit comments