Skip to content

Commit 4bffac3

Browse files
committed
enrich function attribute
1 parent 07064e8 commit 4bffac3

File tree

9 files changed

+572
-508
lines changed

9 files changed

+572
-508
lines changed

jscomp/core/lam.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ type apply_status =
2929
| App_infer_full
3030
| App_uncurry
3131

32-
type function_attribute =
32+
33+
type inline_attribute =
3334
| Always_inline
3435
| Never_inline
3536
| Default_inline
3637

38+
type function_attribute = {
39+
inline : inline_attribute
40+
}
41+
42+
let default_fn_attr : function_attribute = {
43+
inline = Default_inline
44+
}
3745
module Types = struct
3846

3947
type lambda_switch =

jscomp/core/lam.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424

2525

2626

27-
type function_attribute =
27+
type inline_attribute =
2828
| Always_inline
2929
| Never_inline
3030
| Default_inline
3131

32+
type function_attribute = {
33+
inline : inline_attribute
34+
}
35+
36+
val default_fn_attr : function_attribute
37+
3238
type ident = Ident.t
3339

3440
type lambda_switch =

jscomp/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ let destruct_pattern (body : Lam.t) params args =
336336
let ok_to_inline_fun_when_app
337337
(m : Lam.lfunction)
338338
(args : Lam.t list) =
339-
match m.attr with
339+
match m.attr.inline with
340340
| Always_inline -> true
341341
| Never_inline -> false
342342
| Default_inline ->

jscomp/core/lam_convert.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
295295
[ Lam.const Const_js_false ;
296296
(* FIXME: arity 0 does not get proper supported*)
297297
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation
298-
~attr:Default_inline]
298+
~attr:Lam.default_fn_attr]
299299
loc
300300
] in
301301
prim ~primitive:(Pmakeblock (tag,lazy_block_info,Mutable)) ~args loc
@@ -441,11 +441,13 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
441441

442442

443443
let convert_fn_attribute (attr : Lambda.function_attribute) : Lam.function_attribute =
444+
let inline : Lam.inline_attribute =
444445
match attr.inline with
445446
| Always_inline -> Always_inline
446447
| Never_inline -> Never_inline
447448
| Unroll _
448-
| Default_inline -> Default_inline
449+
| Default_inline -> Default_inline in
450+
Lam.{inline}
449451

450452

451453

jscomp/core/lam_eta_conversion.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let transform_under_supply n loc status fn args =
6666
of an existing function which may cause inconsistency
6767
*)
6868
Lam.function_ ~arity:n ~params:extra_args
69-
~attr:Default_inline
69+
~attr:Lam.default_fn_attr
7070
~body:(Lam.apply fn (Ext_list.append args extra_lambdas)
7171
loc
7272
status
@@ -75,7 +75,7 @@ let transform_under_supply n loc status fn args =
7575

7676
let rest : Lam.t =
7777
Lam.function_ ~arity:n ~params:extra_args
78-
~attr:Default_inline
78+
~attr:Lam.default_fn_attr
7979
~body:(Lam.apply fn (Ext_list.append args extra_lambdas)
8080
loc
8181
status
@@ -133,7 +133,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
133133
match fn with
134134
| Lfunction{params = [param]; body} ->
135135
Lam.function_ ~arity:0
136-
~attr:Default_inline
136+
~attr:Lam.default_fn_attr
137137
~params:[]
138138
~body:(
139139
Lam.let_ Alias param Lam.unit body
@@ -153,7 +153,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
153153
Some partial_arg, Lam.var partial_arg in
154154

155155
let cont = Lam.function_
156-
~attr:Default_inline
156+
~attr:Lam.default_fn_attr
157157
~arity:0
158158
~params:[]
159159
~body:(
@@ -172,7 +172,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
172172
{[ fun x y -> f y ]}
173173
*)
174174
let extra_args = Ext_list.init (to_ - from) (fun _ -> Ident.create Literals.param) in
175-
Lam.function_ ~attr:Default_inline
175+
Lam.function_ ~attr:Lam.default_fn_attr
176176
~arity:to_
177177
~params:(Ext_list.append params extra_args )
178178
~body:(Lam.apply body (Ext_list.map extra_args Lam.var) loc App_na)
@@ -190,7 +190,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
190190
in
191191
let cont =
192192
Lam.function_
193-
~arity ~attr:Default_inline
193+
~arity ~attr:Lam.default_fn_attr
194194
195195
~params:extra_args
196196
~body:(
@@ -218,10 +218,10 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
218218
let extra_outer_args, extra_inner_args = Ext_list.split_at params arity in
219219
Lam.function_
220220
~arity
221-
~attr:Default_inline
221+
~attr:Lam.default_fn_attr
222222
~params:extra_outer_args
223223
~body:(
224-
Lam.function_ ~arity:(from - to_) ~attr:Default_inline
224+
Lam.function_ ~arity:(from - to_) ~attr:Lam.default_fn_attr
225225
~params:extra_inner_args ~body:body)
226226
| _
227227
->
@@ -238,12 +238,12 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
238238
Some partial_arg, Lam.var partial_arg
239239
in
240240
let cont =
241-
Lam.function_ ~arity:to_ ~params:extra_outer_args ~attr:Default_inline
241+
Lam.function_ ~arity:to_ ~params:extra_outer_args ~attr:Lam.default_fn_attr
242242
~body:(
243243
let arity = from - to_ in
244244
let extra_inner_args =
245245
Ext_list.init arity (fun _ -> Ident.create Literals.param ) in
246-
Lam.function_ ~arity ~params:extra_inner_args ~attr:Default_inline
246+
Lam.function_ ~arity ~params:extra_inner_args ~attr:Lam.default_fn_attr
247247
~body:(Lam.apply new_fn
248248
(Ext_list.map_append extra_outer_args
249249
(Ext_list.map extra_inner_args Lam.var)
@@ -269,7 +269,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
269269
let partial_arg = Ext_ident.create Literals.partial_arg in
270270
Some partial_arg, Lam.var partial_arg in
271271
272-
let cont = Lam.function_ ~attr:Default_inline
272+
let cont = Lam.function_ ~attr:Lam.default_fn_attr
273273
~arity:0
274274
~params:[]
275275
~body:(

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 111 additions & 111 deletions
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 143 additions & 127 deletions
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 143 additions & 127 deletions
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

Lines changed: 143 additions & 127 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)