Skip to content

Commit 49ba24e

Browse files
authored
Merge pull request #3965 from BuckleScript/refactor_meta_data_collection
More precise on the inline size
2 parents ed7f803 + ab84d50 commit 49ba24e

22 files changed

+1135
-1363
lines changed

jscomp/core/lam.ml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,30 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
647647
| _ -> default ()
648648
end
649649

650-
| _ -> default ()
650+
| _ ->
651+
652+
#if 0 then
653+
match prim with
654+
| Pmakeblock(size,Blk_module fields,_)->
655+
let rec aux fields args (var : Ident.t) =
656+
match fields, args with
657+
| [], [] -> true
658+
| f :: fields, Lprim {primitive = Pfield (_, Fld_module f1); args = [Lglobal_module v1 | Lvar v1]} :: args
659+
-> f = f1 && Ident.same var v1 && aux fields args var
660+
| _, _ -> false in
661+
begin match fields, args with
662+
| field1 :: rest,
663+
Lprim{primitive = Pfield (_, Fld_module f1); args = [Lglobal_module v1 | Lvar v1 as lam]} :: args1
664+
->
665+
if field1 = f1 && aux rest args1 v1 then
666+
lam
667+
else
668+
default ()
669+
| _ -> default ()
670+
end
671+
| _ ->
672+
#end
673+
default ()
651674

652675
let not_ loc x : t =
653676
prim ~primitive:Pnot ~args:[x] loc

jscomp/core/lam_analysis.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ let rec size (lam : Lam.t) =
276276
| Lconst c -> size_constant c
277277
| Llet(_, _, l1, l2) -> 1 + size l1 + size l2
278278
| Lletrec _ -> really_big ()
279-
| Lprim{primitive = Pfield _;
280-
args = [ Lglobal_module _]
279+
| Lprim{primitive = Pfield (_, Fld_module _);
280+
args = [ Lglobal_module _ | Lvar _ ]
281281
; _}
282282
-> 1
283283
| Lprim {primitive = Praise | Pis_not_none ; args = [l ]; _}
284284
-> size l
285-
| Lam.Lglobal_module _ -> 1
285+
| Lglobal_module _ -> 1
286286
| Lprim {primitive =
287287
Praw_js_code_stmt _
288288
| Praw_js_function _

jscomp/core/lam_check.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ let check file lam =
5353
Ext_list.iter_snd xs (fun x -> check_staticfails x cxt)
5454
and check_staticfails (l : Lam.t) (cxt : Set_int.t)=
5555
match l with
56-
| Lvar _ -> ()
57-
| Lconst _ -> ()
56+
| Lvar _
57+
| Lconst _
5858
| Lglobal_module _ -> ()
5959
| Lprim {args; _} ->
6060
check_list args cxt

jscomp/core/lam_eta_conversion.ml

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -113,71 +113,6 @@ let transform_under_supply n loc status fn args =
113113
{[\ x y -> (\a b c -> g a b c) x y]}
114114
{[ \a b -> \c -> g a b c ]}
115115
*)
116-
(** if arity = 0 then
117-
begin match fn with
118-
| Lfunction {params = [_]; body}
119-
->
120-
compile_lambda cxt
121-
(Lam.function_
122-
~arity:0
123-
~kind:Curried
124-
~params:[]
125-
~body)
126-
| _ ->
127-
let wrapper, new_fn =
128-
match fn with
129-
| Lvar _
130-
| Lprim {primitive = Pfield _ ; args = [Lglobal_module _]; _} ->
131-
None, fn
132-
| _ ->
133-
let partial_arg = Ext_ident.create Literals.partial_arg in
134-
Some partial_arg, Lam.var partial_arg
135-
in
136-
let cont =
137-
(Lam.function_ ~arity:0
138-
~kind:Curried ~params:[]
139-
~body:(
140-
Lam.apply new_fn
141-
[Lam.unit]
142-
Location.none App_na
143-
)) in
144-
begin match wrapper with
145-
| None ->
146-
compile_lambda cxt cont
147-
| Some partial_arg
148-
->
149-
compile_lambda cxt (Lam.let_ Strict partial_arg fn cont )
150-
end
151-
end
152-
else
153-
begin match fn with
154-
| Lam.Lfunction{arity = len; kind; params = args; body}
155-
->
156-
if len = arity then
157-
compile_lambda cxt fn
158-
else if len > arity then
159-
let params, rest = Ext_list.split_at arity args in
160-
compile_lambda cxt
161-
(Lam.function_
162-
~arity
163-
~kind ~params
164-
~body:(Lam.function_ ~arity:(len - arity)
165-
~kind ~params:rest ~body)
166-
)
167-
else (* len < arity *)
168-
compile_lambda cxt
169-
(Lam_eta_conversion.transform_under_supply arity
170-
Location.none App_na
171-
fn [] )
172-
(* let extra_args = Ext_list.init (arity - len) (fun _ -> (Ident.create Literals.param)) in *)
173-
(* let extra_lambdas = Ext_list.map (fun x -> Lam.var x) extra_args in *)
174-
(* Lam.Lfunction (kind, Ext_list.append extra_args args , body ) *)
175-
176-
| _ ->
177-
compile_lambda cxt
178-
(Lam_eta_conversion.transform_under_supply arity
179-
Location.none App_na fn [] )
180-
end *)
181116

182117

183118
(** Unsafe function, we are changing arity here, it should be applied
@@ -207,7 +142,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
207142
let wrapper, new_fn =
208143
match fn with
209144
| Lvar _
210-
| Lprim{primitive = Pfield _ ; args = [Lglobal_module _]; _ }
145+
| Lprim{primitive = Pfield (_,Fld_module _) ; args = [Lglobal_module _ | Lvar _]; _ }
211146
->
212147
None, fn
213148
| _ ->
@@ -243,7 +178,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
243178
let wrapper, new_fn =
244179
match fn with
245180
| Lvar _
246-
| Lprim {primitive = Pfield _ ; args = [ Lglobal_module _] ; _} ->
181+
| Lprim {primitive = Pfield (_,Fld_module _) ; args = [ Lglobal_module _ | Lvar _] ; _} ->
247182
None, fn
248183
| _ ->
249184
let partial_arg = Ext_ident.create Literals.partial_arg in
@@ -292,7 +227,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
292227
let wrapper, new_fn =
293228
match fn with
294229
| Lvar _
295-
| Lprim {primitive = Pfield _ ; args = [ Lglobal_module _] ; _} ->
230+
| Lprim {primitive = Pfield (_, Fld_module _) ; args = [ Lglobal_module _ | Lvar _] ; _} ->
296231
None, fn
297232
| _ ->
298233
let partial_arg = Ext_ident.create Literals.partial_arg in
@@ -323,7 +258,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
323258
let wrapper, new_fn =
324259
match fn with
325260
| Lvar _
326-
| Lprim{primitive = Pfield _ ; args = [Lglobal_module _]; _ }
261+
| Lprim{primitive = Pfield (_, Fld_module _) ; args = [Lglobal_module _ | Lvar _]; _ }
327262
->
328263
None, fn
329264
| _ ->

jscomp/core/lam_pass_eliminate_ref.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ let rec eliminate_ref id (lam : Lam.t) =
6767
Lam.letrec
6868
(Ext_list.map idel (fun (v, e) -> (v, eliminate_ref id e)))
6969
(eliminate_ref id e2)
70-
| Lam.Lglobal_module _ -> lam
70+
| Lglobal_module _ -> lam
7171
| Lprim {primitive ; args ; loc} ->
7272
Lam.prim ~primitive ~args:(Ext_list.map args (eliminate_ref id)) loc
7373
| Lswitch(e, sw) ->

jscomp/core/lam_print.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ let lambda ppf v =
403403
let rec lam ppf (l : Lam.t) = match l with
404404
| Lvar id ->
405405
Ident.print ppf id
406-
| Lam.Lglobal_module id ->
406+
| Lglobal_module id ->
407407
fprintf ppf "global %a" Ident.print id
408408
| Lconst cst ->
409409
struct_const ppf cst

jscomp/core/lam_subst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Lam.letrec (Ext_list.map decl subst_decl ) (subst_aux body)
4848
| Lprim { primitive ; args; loc} ->
4949
Lam.prim ~primitive ~args:(Ext_list.map args subst_aux ) loc
50-
| Lam.Lglobal_module _ -> x
50+
| Lglobal_module _ -> x
5151
| Lswitch(arg, sw) ->
5252
Lam.switch (subst_aux arg)
5353
{sw with sw_consts = Ext_list.map sw.sw_consts subst_case ;

jscomp/core/lam_util.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ let refine_let
8282
Lam.apply fn [arg] loc status
8383
| (Strict | StrictOpt ),
8484
( Lvar _ | Lconst _ |
85-
Lprim {primitive = Pfield _ ;
86-
args = [ Lglobal_module _ ]; _}) , _ ->
85+
Lprim {primitive = Pfield (_ , Fld_module _) ;
86+
args = [ Lglobal_module _ | Lvar _ ]; _}) , _ ->
8787
(* (match arg with *)
8888
(* | Lconst _ -> *)
8989
(* Ext_log.err "@[%a %s@]@." *)
@@ -171,8 +171,8 @@ let element_of_lambda (lam : Lam.t) : Lam_id_kind.element =
171171
match lam with
172172
| Lvar _
173173
| Lconst _
174-
| Lprim {primitive = Pfield _ ;
175-
args = [ Lglobal_module _ ];
174+
| Lprim {primitive = Pfield (_, Fld_module _) ;
175+
args = [ Lglobal_module _ | Lvar _ ];
176176
_} -> SimpleForm lam
177177
(* | Lfunction _ *)
178178
| _ -> NA

jscomp/test/bs_hashmap_test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Belt_HashMap = require("../../lib/js/belt_HashMap.js");
88
var Belt_SortArray = require("../../lib/js/belt_SortArray.js");
99
var Caml_primitive = require("../../lib/js/caml_primitive.js");
1010
var Array_data_util = require("./array_data_util.js");
11+
var Belt_internalBucketsType = require("../../lib/js/belt_internalBucketsType.js");
1112

1213
var suites = {
1314
contents: /* [] */0
@@ -35,7 +36,7 @@ var cmp = Caml_primitive.caml_int_compare;
3536

3637
var Y = Belt_Id.hashable(hash, eq);
3738

38-
var empty = Belt_HashMap.make(30, Y);
39+
var empty = Belt_internalBucketsType.make(Y.hash, Y.eq, 30);
3940

4041
function add(prim, prim$1) {
4142
return prim + prim$1 | 0;
@@ -76,7 +77,7 @@ eqx("File \"bs_hashmap_test.ml\", line 42, characters 6-13", Belt_SortArray.stab
7677

7778
var u$1 = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100));
7879

79-
var v$1 = Belt_HashMap.make(40, Y);
80+
var v$1 = Belt_internalBucketsType.make(Y.hash, Y.eq, 40);
8081

8182
Belt_HashMap.mergeMany(v$1, Belt_Array.zip(u$1, u$1));
8283

jscomp/test/bs_hashtbl_string_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var Int = Belt_Id.hashable(Hashtbl.hash, (function (x, y) {
4545
return x === y;
4646
}));
4747

48-
var empty = Belt_HashMap.make(500000, Int);
48+
var empty = Belt_internalBucketsType.make(Int.hash, Int.eq, 500000);
4949

5050
function bench(param) {
5151
for(var i = 0; i <= 1000000; ++i){
@@ -68,7 +68,7 @@ function bench(param) {
6868
}
6969

7070
function bench2(m) {
71-
var empty = Belt_HashMap.make(1000000, m);
71+
var empty = Belt_internalBucketsType.make(m.hash, m.eq, 1000000);
7272
for(var i = 0; i <= 1000000; ++i){
7373
Belt_HashMap.set(empty, String(i), i);
7474
}
@@ -180,7 +180,7 @@ function bench4(param) {
180180
}
181181

182182
function bench5(param) {
183-
var table = Belt_HashMap.make(1000000, Int);
183+
var table = Belt_internalBucketsType.make(Int.hash, Int.eq, 1000000);
184184
console.time("test/bs_hashtbl_string_test.ml 133");
185185
for(var i = 0; i <= 1000000; ++i){
186186
Belt_HashMap.set(table, i, i);

0 commit comments

Comments
 (0)