Skip to content

Commit

Permalink
Compiler: fix toplevel with globaldeacode
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jan 21, 2024
1 parent 1f29da6 commit 0afbc3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Compiler: no longer rely on IIFE for scoping variable inside loops
* Lib: add ellipse to canvasRenderingContext2D (@FayCarsons, #1555)

## Bug fixes
* Compiler: fix global dead code elimination in a toplevel context

# 5.6.0 (2024-01-02) - Lille

## Features/Changes
Expand Down
9 changes: 9 additions & 0 deletions compiler/lib/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ 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
1 change: 1 addition & 0 deletions compiler/tests-toplevel/test_toplevel.reference
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
hello
- : int = 2
Line 4, characters 2-4:
Error: Syntax error
Line 5, characters 0-16:
Expand Down

0 comments on commit 0afbc3b

Please sign in to comment.