forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_recursive_functions.ml
34 lines (32 loc) · 1.84 KB
/
find_recursive_functions.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Pierre Chambart, OCamlPro *)
(* Mark Shinwell and Leo White, Jane Street Europe *)
(* *)
(* Copyright 2013--2016 OCamlPro SAS *)
(* Copyright 2014--2016 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
[@@@ocaml.warning "+a-4-9-30-40-41-42-66"]
open! Int_replace_polymorphic_compare
let in_function_declarations (function_decls : Flambda.function_declarations)
~backend =
let module VCC = Strongly_connected_components.Make (Variable) in
let directed_graph =
let module B = (val backend : Backend_intf.S) in
Flambda_utils.fun_vars_referenced_in_decls function_decls
~closure_symbol:B.closure_symbol
in
let connected_components =
VCC.connected_components_sorted_from_roots_to_leaf directed_graph
in
Array.fold_left (fun rec_fun -> function
| VCC.No_loop _ -> rec_fun
| VCC.Has_loop elts -> List.fold_right Variable.Set.add elts rec_fun)
Variable.Set.empty connected_components