Skip to content

Commit 0afbc3b

Browse files
committed
Compiler: fix toplevel with globaldeacode
1 parent 1f29da6 commit 0afbc3b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Compiler: no longer rely on IIFE for scoping variable inside loops
66
* Lib: add ellipse to canvasRenderingContext2D (@FayCarsons, #1555)
77

8+
## Bug fixes
9+
* Compiler: fix global dead code elimination in a toplevel context
10+
811
# 5.6.0 (2024-01-02) - Lille
912

1013
## Features/Changes

compiler/lib/global_deadcode.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ let liveness prog pure_funs (global_info : Global_flow.info) =
246246
| Stop | Branch _ | Poptrap _ | Pushtrap _ -> ()
247247
in
248248
Addr.Map.iter (fun _ block -> live_block block) prog.blocks;
249+
Code.traverse
250+
{ Code.fold = Code.fold_children }
251+
(fun pc () ->
252+
match Addr.Map.find pc prog.blocks with
253+
| { branch = Return x, _; _ } -> add_top x
254+
| _ -> ())
255+
prog.start
256+
prog.blocks
257+
();
249258
live_vars
250259

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

compiler/tests-toplevel/test_toplevel.reference

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
hello
2+
- : int = 2
23
Line 4, characters 2-4:
34
Error: Syntax error
45
Line 5, characters 0-16:

0 commit comments

Comments
 (0)