Skip to content

Commit 47afe17

Browse files
committed
Compiler: fix inlining 2106
1 parent eaea1a1 commit 47afe17

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

compiler/lib/duplicate.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ let rec blocks_to_rename p pc lst =
6060
p.blocks
6161
lst
6262

63-
let closure p ~f ~params ~cont =
64-
let s = Subst.from_map (bound_variables p ~f ~params ~cont) in
63+
let closure p ~f ~params ~cont live_vars =
64+
let s =
65+
let map = bound_variables p ~f ~params ~cont in
66+
fun x ->
67+
try Var.Map.find x map
68+
with Not_found ->
69+
live_vars.(Var.idx x) <- live_vars.(Var.idx x) + 1;
70+
x
71+
in
6572
let pc, args = cont in
6673
let blocks = blocks_to_rename p pc [] in
6774
let free_pc, m =

compiler/lib/duplicate.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ val closure :
2121
-> f:Code.Var.t
2222
-> params:Code.Var.t list
2323
-> cont:int * Code.Var.t list
24+
-> int Array.t
2425
-> Code.program * Code.Var.t * Code.Var.t list * (int * Code.Var.t list)
2526
(** Given a program and a closure [f] -- defined by its name,
2627
parameters, and its continuation --, return a program with a copy

compiler/lib/inline.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ and inline_function ~context i x f args rem state =
643643
let p, params, cont =
644644
if context.live_vars.(Var.idx f) > 0
645645
then (
646-
let p, _f, params, cont = Duplicate.closure p ~f ~params ~cont in
646+
let p, _f, params, cont =
647+
Duplicate.closure p ~f ~params ~cont context.live_vars
648+
in
647649
(* It's ok to ignore the [_f] because the function is not recursive *)
648650
assert (not info.recursive);
649651
p, params, cont)

0 commit comments

Comments
 (0)