Skip to content

Commit

Permalink
Fix global flow analysis
Browse files Browse the repository at this point in the history
In fast mode, we don't track function arguments, so we should consider them as escaping.
  • Loading branch information
vouillon committed Jul 26, 2023
1 parent 8cd97dc commit efc617c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Dev (2023-??-??) - ??

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

# 5.4.0 (2023-07-06) - Lille

Expand Down
17 changes: 14 additions & 3 deletions compiler/lib/global_flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ let expr_deps blocks st x e =
match st.defs.(Var.idx f) with
| Expr (Closure (params, _)) when List.length args = List.length params ->
Hashtbl.add st.applied_functions (x, f) ();
if not st.fast then List.iter2 ~f:(fun p a -> add_assign_def st p a) params args;
if st.fast
then List.iter ~f:(fun a -> do_escape st Escape a) args
else List.iter2 ~f:(fun p a -> add_assign_def st p a) params args;
Var.Set.iter (fun y -> add_dep st x y) (Var.Map.find f st.return_values)
| _ -> ())
| Closure (l, cont) ->
Expand Down Expand Up @@ -470,8 +472,13 @@ let propagate st ~update approx x =
if not (Hashtbl.mem st.applied_functions (x, g))
then (
Hashtbl.add st.applied_functions (x, g) ();
if not st.fast
if st.fast
then
List.iter
~f:(fun y ->
Domain.variable_escape ~update ~st ~approx Escape y)
args
else
List.iter2
~f:(fun p a ->
add_assign_def st p a;
Expand Down Expand Up @@ -593,7 +600,7 @@ let f ~fast p =
| Values { known; others } ->
Format.fprintf
f
"{%a/%b} mut:%b vmut:%b esc:%s"
"{%a/%b} mut:%b vmut:%b vesc:%s esc:%s"
(Format.pp_print_list
~pp_sep:(fun f () -> Format.fprintf f ", ")
(fun f x ->
Expand All @@ -615,6 +622,10 @@ let f ~fast p =
others
st.possibly_mutable.(Var.idx x)
st.variable_possibly_mutable.(Var.idx x)
(match st.variable_may_escape.(Var.idx x) with
| Escape -> "Y"
| Escape_constant -> "y"
| No -> "n")
(match st.may_escape.(Var.idx x) with
| Escape -> "Y"
| Escape_constant -> "y"
Expand Down

0 comments on commit efc617c

Please sign in to comment.