Skip to content

Commit ffe3e43

Browse files
committed
more shapes
1 parent df5ec74 commit ffe3e43

File tree

4 files changed

+200
-388
lines changed

4 files changed

+200
-388
lines changed

compiler/lib/flow.ml

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ let rec the_shape_of info x =
407407
match info.info_defs.(Var.idx x) with
408408
| Expr (Block (_, a, _, Immutable)) ->
409409
Shape.Block (List.map ~f:(the_shape_of info) (Array.to_list a))
410+
| Expr (Block (_, a, _, _)) when not (Var.ISet.mem info.info_possibly_mutable x)
411+
-> Shape.Block (List.map ~f:(the_shape_of info) (Array.to_list a))
410412
| Expr (Closure (l, _)) ->
411413
Shape.Function { arity = List.length l; pure = false; res = Top "unk" }
412414
| Expr (Special (Alias_prim name)) -> (

compiler/lib/specialize.ml

+31-25
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,37 @@ let function_arity info x =
2828
match shape with
2929
| Function { arity; _ } -> Some arity
3030
| Block _ | Top _ -> None)
31-
| None ->
32-
get_approx
33-
info
34-
(fun x ->
35-
match 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 f ~set: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-
| Some _ -> None
49-
| None -> None)
50-
None
51-
(fun u v ->
52-
match u, v with
53-
| Some n, Some m when n = m -> u
54-
| _ -> None)
55-
x
31+
| None -> (
32+
match Shape.get x with
33+
| Some shape -> (
34+
match shape with
35+
| Function { arity; _ } -> Some arity
36+
| Block _ | Top _ -> None)
37+
| None ->
38+
get_approx
39+
info
40+
(fun x ->
41+
match Info.def info x with
42+
| Some (Closure (l, _)) -> Some (List.length l)
43+
| Some (Special (Alias_prim prim)) -> (
44+
try Some (Primitive.arity prim) with Not_found -> None)
45+
| Some (Apply { f; args; _ }) -> (
46+
if List.mem f ~set:acc
47+
then None
48+
else
49+
match arity info f (f :: acc) with
50+
| Some n ->
51+
let diff = n - List.length args in
52+
if diff > 0 then Some diff else None
53+
| None -> None)
54+
| Some _ -> None
55+
| None -> None)
56+
None
57+
(fun u v ->
58+
match u, v with
59+
| Some n, Some m when n = m -> u
60+
| _ -> None)
61+
x)
5662
in
5763
arity info x []
5864

compiler/tests-compiler/gh747.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ end
227227
1:
228228
2: //# unitInfo: Provides: Test
229229
3: //# unitInfo: Requires: Stdlib__Printf
230-
4: //# shape: Test:[N,N,[N],N,N,N,N,N,N,N,N,N,N,F(2),F(2),[F(4)]]
230+
4: //# shape: Test:[N,N,[N],N,N,N,N,N,N,N,N,N,[N,N],F(2),F(2),[F(4)]]
231231
5: (function
232232
6: (globalThis){
233233
7: "use strict";

0 commit comments

Comments
 (0)