Skip to content

Commit efc617c

Browse files
committed
Fix global flow analysis
In fast mode, we don't track function arguments, so we should consider them as escaping.
1 parent 8cd97dc commit efc617c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Dev (2023-??-??) - ??
22

33
* Runtime: fix Dom_html.onIE (#1493)
4+
* Compiler: fix global flow analysis (#1494)
45

56
# 5.4.0 (2023-07-06) - Lille
67

compiler/lib/global_flow.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ let expr_deps blocks st x e =
215215
match st.defs.(Var.idx f) with
216216
| Expr (Closure (params, _)) when List.length args = List.length params ->
217217
Hashtbl.add st.applied_functions (x, f) ();
218-
if not st.fast then List.iter2 ~f:(fun p a -> add_assign_def st p a) params args;
218+
if st.fast
219+
then List.iter ~f:(fun a -> do_escape st Escape a) args
220+
else List.iter2 ~f:(fun p a -> add_assign_def st p a) params args;
219221
Var.Set.iter (fun y -> add_dep st x y) (Var.Map.find f st.return_values)
220222
| _ -> ())
221223
| Closure (l, cont) ->
@@ -470,8 +472,13 @@ let propagate st ~update approx x =
470472
if not (Hashtbl.mem st.applied_functions (x, g))
471473
then (
472474
Hashtbl.add st.applied_functions (x, g) ();
473-
if not st.fast
475+
if st.fast
474476
then
477+
List.iter
478+
~f:(fun y ->
479+
Domain.variable_escape ~update ~st ~approx Escape y)
480+
args
481+
else
475482
List.iter2
476483
~f:(fun p a ->
477484
add_assign_def st p a;
@@ -593,7 +600,7 @@ let f ~fast p =
593600
| Values { known; others } ->
594601
Format.fprintf
595602
f
596-
"{%a/%b} mut:%b vmut:%b esc:%s"
603+
"{%a/%b} mut:%b vmut:%b vesc:%s esc:%s"
597604
(Format.pp_print_list
598605
~pp_sep:(fun f () -> Format.fprintf f ", ")
599606
(fun f x ->
@@ -615,6 +622,10 @@ let f ~fast p =
615622
others
616623
st.possibly_mutable.(Var.idx x)
617624
st.variable_possibly_mutable.(Var.idx x)
625+
(match st.variable_may_escape.(Var.idx x) with
626+
| Escape -> "Y"
627+
| Escape_constant -> "y"
628+
| No -> "n")
618629
(match st.may_escape.(Var.idx x) with
619630
| Escape -> "Y"
620631
| Escape_constant -> "y"

0 commit comments

Comments
 (0)