diff --git a/compiler/lib/flow.ml b/compiler/lib/flow.ml index a60c682254..138622b4f7 100644 --- a/compiler/lib/flow.ml +++ b/compiler/lib/flow.ml @@ -192,10 +192,13 @@ let rec block_escape st x = if not (Code.Var.ISet.mem st.may_escape y) then ( Code.Var.ISet.add st.may_escape y; - Code.Var.ISet.add st.possibly_mutable y; match st.defs.(Var.idx y) with - | Expr (Block (_, l, _, _)) -> Array.iter l ~f:(fun z -> block_escape st z) - | _ -> ())) + | Expr (Block (_, l, _, mut)) -> + (match mut with + | Immutable -> () + | Maybe_mutable -> Code.Var.ISet.add st.possibly_mutable y); + Array.iter l ~f:(fun z -> block_escape st z) + | _ -> Code.Var.ISet.add st.possibly_mutable y)) (Var.Tbl.get st.known_origins x) let expr_escape st _x e = diff --git a/compiler/lib/global_flow.ml b/compiler/lib/global_flow.ml index afd647d265..8cc7368aca 100644 --- a/compiler/lib/global_flow.ml +++ b/compiler/lib/global_flow.ml @@ -331,13 +331,13 @@ module Domain = struct then ( st.may_escape.(idx) <- s; match st.defs.(idx) with - | Expr (Block (_, a, _, _)) -> ( + | Expr (Block (_, a, _, mut)) -> ( Array.iter ~f:(fun y -> variable_escape ~update ~st ~approx s y) a; - match s with - | Escape -> + match s, mut with + | Escape, Maybe_mutable -> Var.ISet.add st.possibly_mutable x; update ~children:true x - | Escape_constant | No -> ()) + | (Escape_constant | No), _ | Escape, Immutable -> ()) | Expr (Closure (params, _)) -> List.iter ~f:(fun y -> @@ -386,10 +386,14 @@ module Domain = struct | Values { known; _ } -> Var.Set.iter (fun x -> - if not (Var.ISet.mem st.possibly_mutable x) - then ( - Var.ISet.add st.possibly_mutable x; - update ~children:true x)) + match st.defs.(Var.idx x) with + | Expr (Block (_, _, _, Maybe_mutable)) -> + if not (Var.ISet.mem st.possibly_mutable x) + then ( + Var.ISet.add st.possibly_mutable x; + update ~children:true x) + | Expr (Block (_, _, _, Immutable)) | Expr (Closure _) -> () + | Phi _ | Expr _ -> assert false) known end