Skip to content

Commit d6a7aba

Browse files
authored
Compiler: Fix global flow analysis (#1680)
It needs to take into account values flowing out of the toplevel function. PR #1556 added a workaround in the global deadcode analysis for this, but it's better to fix the issue at its root.
1 parent dbcf6a2 commit d6a7aba

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Toplevel: fix missing primitives with separate compilation
2525
* Compiler: fix link of packed modules with separate compilation
2626
* Compiler: Fixed the static evaluation of some equalities (#1659)
27+
* Compiler: fix global analysis bug (subsumes #1556)
2728

2829
# 5.8.2 (2024-05-26) - Luc
2930

compiler/lib/global_deadcode.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,6 @@ let liveness prog pure_funs (global_info : Global_flow.info) =
253253
| Stop | Branch _ | Poptrap _ | Pushtrap _ -> ()
254254
in
255255
Addr.Map.iter (fun _ block -> live_block block) prog.blocks;
256-
Code.traverse
257-
{ Code.fold = Code.fold_children }
258-
(fun pc () ->
259-
match Addr.Map.find pc prog.blocks with
260-
| { branch = Return x, _; _ } -> add_top x
261-
| _ -> ())
262-
prog.start
263-
prog.blocks
264-
();
265256
live_vars
266257

267258
(* Returns the set of variables given a table of variables. *)

compiler/lib/global_flow.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,16 @@ let expr_deps blocks st x e =
233233
cont_deps blocks st cont
234234
| Field (y, _, _) -> add_dep st x y
235235

236-
let program_deps st { blocks; _ } =
236+
let program_deps st { start; blocks; _ } =
237+
Code.traverse
238+
{ Code.fold = Code.fold_children }
239+
(fun pc () ->
240+
match Addr.Map.find pc blocks with
241+
| { branch = Return x, _; _ } -> do_escape st Escape x
242+
| _ -> ())
243+
start
244+
blocks
245+
();
237246
Addr.Map.iter
238247
(fun _ block ->
239248
List.iter block.body ~f:(fun (i, _) ->

0 commit comments

Comments
 (0)