Skip to content

Commit

Permalink
Fix global flow analysis
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vouillon committed Sep 23, 2024
1 parent dbcf6a2 commit 0d8e9a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Toplevel: fix missing primitives with separate compilation
* Compiler: fix link of packed modules with separate compilation
* Compiler: Fixed the static evaluation of some equalities (#1659)
* Compiler: fix global analysis bug (subsumes #1556)

# 5.8.2 (2024-05-26) - Luc

Expand Down
9 changes: 0 additions & 9 deletions compiler/lib/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ let liveness prog pure_funs (global_info : Global_flow.info) =
| Stop | Branch _ | Poptrap _ | Pushtrap _ -> ()
in
Addr.Map.iter (fun _ block -> live_block block) prog.blocks;
Code.traverse
{ Code.fold = Code.fold_children }
(fun pc () ->
match Addr.Map.find pc prog.blocks with
| { branch = Return x, _; _ } -> add_top x
| _ -> ())
prog.start
prog.blocks
();
live_vars

(* Returns the set of variables given a table of variables. *)
Expand Down
11 changes: 10 additions & 1 deletion compiler/lib/global_flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,16 @@ let expr_deps blocks st x e =
cont_deps blocks st cont
| Field (y, _, _) -> add_dep st x y

let program_deps st { blocks; _ } =
let program_deps st { start; blocks; _ } =
Code.traverse
{ Code.fold = Code.fold_children }
(fun pc () ->
match Addr.Map.find pc blocks with
| { branch = Return x, _; _ } -> do_escape st Escape x
| _ -> ())
start
blocks
();
Addr.Map.iter
(fun _ block ->
List.iter block.body ~f:(fun (i, _) ->
Expand Down

0 comments on commit 0d8e9a5

Please sign in to comment.