Skip to content

Commit ed93b15

Browse files
committed
Compiler: use shapes to compute arity
This reverts commit 9c0692f8af4d6fafdf0fc428f820cc9753897cc4.
1 parent c16d90d commit ed93b15

File tree

4 files changed

+1914
-2181
lines changed

4 files changed

+1914
-2181
lines changed

compiler/lib/driver.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ let inline profile p =
6565

6666
let specialize_1 (p, info) =
6767
if debug () then Format.eprintf "Specialize...@.";
68-
Specialize.f ~function_arity:(fun f -> Specialize.function_arity info f) p
68+
let return_values = Code.Var.Map.empty in
69+
Specialize.f
70+
~function_arity:(fun f -> Specialize.function_arity ~return_values info f)
71+
p
6972

7073
let specialize_js (p, info) =
7174
if debug () then Format.eprintf "Specialize js...@.";

compiler/lib/specialize.ml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,17 @@
1919
*)
2020
open! Stdlib
2121
open Code
22-
open Flow
2322

2423
let times = Debug.find "times"
2524

2625
let stats = Debug.find "stats"
2726

2827
let debug_stats = Debug.find "stats-debug"
2928

30-
let function_arity info x =
31-
let rec arity info x acc =
32-
get_approx
33-
info
34-
(fun x ->
35-
match Flow.Info.def info x with
36-
| Some (Closure (l, _, _)) -> Some (List.length l)
37-
| Some (Special (Alias_prim prim)) -> (
38-
try Some (Primitive.arity prim) with Not_found -> None)
39-
| Some (Apply { f; args; _ }) -> (
40-
if List.mem ~eq:Var.equal f acc
41-
then None
42-
else
43-
match arity info f (f :: acc) with
44-
| Some n ->
45-
let diff = n - List.length args in
46-
if diff > 0 then Some diff else None
47-
| None -> None)
48-
| _ -> None)
49-
None
50-
(fun u v ->
51-
match u, v with
52-
| Some n, Some m when n = m -> u
53-
| _ -> None)
54-
x
55-
in
56-
arity info x []
29+
let function_arity ~return_values info x =
30+
match Flow.the_shape_of ~return_values ~pure:Pure_fun.empty info x with
31+
| Top | Block _ -> None
32+
| Function { arity; _ } -> Some arity
5733

5834
let add_event loc instrs =
5935
match loc with

compiler/lib/specialize.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1919
*)
2020

21-
val function_arity : Flow.Info.t -> Code.Var.t -> int option
21+
val function_arity :
22+
return_values:Code.Var.Set.t Code.Var.Map.t -> Flow.Info.t -> Code.Var.t -> int option
2223

2324
val f : function_arity:(Code.Var.t -> int option) -> Code.program -> Code.program
2425

0 commit comments

Comments
 (0)