Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: fix toplevel with globaldeacode #1556

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 5 additions & 4 deletions compiler/tests-toplevel/test_toplevel.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let () =
let content = {|
let () = print_endline "hello";;
1+1;;
1+;;
Missing_module.f;;
|} in
Expand All @@ -12,10 +13,10 @@ Missing_module.f;;
try
Location.reset ();
let phr = !Toploop.parse_toplevel_phrase lexbuf in
if not (Toploop.execute_phrase true Format.std_formatter phr) then raise Exit
let res = Toploop.execute_phrase true Format.std_formatter phr in
flush_all ();
if not res then raise Exit
with
| End_of_file ->
flush_all ();
exit 0
| End_of_file -> exit 0
| x -> Location.report_exception Format.std_formatter x
done
5 changes: 3 additions & 2 deletions compiler/tests-toplevel/test_toplevel.reference
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
hello
Line 3, characters 2-4:
- : int = 2
Line 4, characters 2-4:
Error: Syntax error
Line 4, characters 0-16:
Line 5, characters 0-16:
Error: Unbound module Missing_module
Loading