Skip to content

Commit ddefa46

Browse files
committed
keep inline attribute
1 parent 178ef22 commit ddefa46

12 files changed

+167
-144
lines changed

jscomp/core/lam.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type apply_status =
2929
| App_infer_full
3030
| App_uncurry
3131

32+
type function_attribute =
33+
| Always_inline
34+
| Never_inline
35+
| Default_inline
3236

3337
module Types = struct
3438

@@ -88,7 +92,8 @@ module Types = struct
8892
| Lapply of apply_info
8993
| Lfunction of { arity : int ;
9094
params : ident list ;
91-
body : t
95+
body : t;
96+
attr : function_attribute
9297
}
9398
| Llet of Lam_compat.let_kind * ident * t * t
9499
| Lletrec of (ident * t) list * t
@@ -141,7 +146,8 @@ module X = struct
141146
| Lapply of apply_info
142147
| Lfunction of { arity : int ;
143148
params : ident list ;
144-
body : t
149+
body : t;
150+
attr : function_attribute
145151
}
146152
| Llet of Lam_compat.let_kind * ident * t * t
147153
| Lletrec of (ident * t) list * t
@@ -175,9 +181,9 @@ let inner_map
175181
let ap_func = f ap_func in
176182
let ap_args = Ext_list.map ap_args f in
177183
Lapply { ap_func ; ap_args; ap_loc; ap_status }
178-
| Lfunction({body; arity; params } ) ->
184+
| Lfunction({body; arity; params ; attr } ) ->
179185
let body = f body in
180-
Lfunction {body; arity; params}
186+
Lfunction {body; arity; params; attr}
181187
| Llet(str, id, arg, body) ->
182188
let arg = f arg in let body = f body in
183189
Llet(str,id,arg,body)
@@ -428,8 +434,8 @@ let rec seq (a : t) b : t =
428434
let var id : t = Lvar id
429435
let global_module id = Lglobal_module id
430436
let const ct : t = Lconst ct
431-
let function_ ~arity ~params ~body : t =
432-
Lfunction { arity; params ; body}
437+
let function_ ~attr ~arity ~params ~body : t =
438+
Lfunction { arity; params ; body; attr}
433439

434440
let let_ kind id e body : t
435441
= Llet (kind,id,e,body)

jscomp/core/lam.mli

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424

2525

2626

27-
27+
type function_attribute =
28+
| Always_inline
29+
| Never_inline
30+
| Default_inline
2831

2932
type ident = Ident.t
3033

@@ -58,7 +61,8 @@ and t = private
5861
| Lapply of apply_info
5962
| Lfunction of { arity : int ;
6063
params : ident list ;
61-
body : t
64+
body : t ;
65+
attr : function_attribute;
6266
}
6367
| Llet of Lam_compat.let_kind * ident * t * t
6468
| Lletrec of (ident * t) list * t
@@ -102,6 +106,7 @@ val const : Lam_constant.t -> t
102106

103107
val apply : t -> t list -> Location.t -> apply_status -> t
104108
val function_ :
109+
attr:function_attribute ->
105110
arity:int ->
106111
params:ident list ->
107112
body:t -> t

jscomp/core/lam_bounded_vars.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ let rewrite (map : _ Hash_ident.t)
9191
let bindings = Ext_list.map2 vars bindings (fun var (_,l) -> var, aux l) in
9292
let body = aux body in
9393
Lam.letrec bindings body
94-
| Lfunction{arity; params; body} ->
94+
| Lfunction{arity; params; body; attr} ->
9595
let params = Ext_list.map params rebind in
9696
let body = aux body in
97-
Lam.function_ ~arity ~params ~body
97+
Lam.function_ ~arity ~params ~body ~attr
9898
| Lstaticcatch(l1, (i,xs), l2) ->
9999
let l1 = aux l1 in
100100
let xs = Ext_list.map xs rebind in

jscomp/core/lam_convert.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
294294
let args =
295295
[ Lam.const Const_js_false ;
296296
(* FIXME: arity 0 does not get proper supported*)
297-
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation]
297+
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation
298+
~attr:Default_inline]
298299
loc
299300
] in
300301
prim ~primitive:(Pmakeblock (tag,lazy_block_info,Mutable)) ~args loc
@@ -439,6 +440,12 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
439440
(* Does not exist since we compile array in js backend unlike native backend *)
440441

441442

443+
let convert_fn_attribute (attr : Lambda.function_attribute) : Lam.function_attribute =
444+
match attr.inline with
445+
| Always_inline -> Always_inline
446+
| Never_inline -> Never_inline
447+
| Unroll _
448+
| Default_inline -> Default_inline
442449

443450

444451

@@ -624,17 +631,18 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
624631
(** we need do this eargly in case [aux fn] add some wrapper *)
625632
Lam.apply (convert_aux fn) (Ext_list.map args convert_aux ) loc App_na
626633
| Lfunction
627-
{kind; params; body }
634+
{kind; params; body ; attr }
628635
->
629636
assert (kind = Curried);
630637
let new_map,body = rename_optional_parameters Map_ident.empty params body in
638+
let attr = convert_fn_attribute attr in
631639
if Map_ident.is_empty new_map then
632-
Lam.function_
640+
Lam.function_ ~attr
633641
~arity:(List.length params) ~params
634642
~body:(convert_aux body)
635643
else
636644
let params = Ext_list.map params (fun x -> Map_ident.find_default new_map x x) in
637-
Lam.function_
645+
Lam.function_ ~attr
638646
~arity:(List.length params) ~params
639647
~body:(convert_aux body)
640648

jscomp/core/lam_eta_conversion.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +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
6970
~body:(Lam.apply fn (Ext_list.append args extra_lambdas)
7071
loc
7172
status
@@ -74,6 +75,7 @@ let transform_under_supply n loc status fn args =
7475

7576
let rest : Lam.t =
7677
Lam.function_ ~arity:n ~params:extra_args
78+
~attr:Default_inline
7779
~body:(Lam.apply fn (Ext_list.append args extra_lambdas)
7880
loc
7981
status
@@ -131,6 +133,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
131133
match fn with
132134
| Lfunction{params = [param]; body} ->
133135
Lam.function_ ~arity:0
136+
~attr:Default_inline
134137
~params:[]
135138
~body:(
136139
Lam.let_ Alias param Lam.unit body
@@ -150,6 +153,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
150153
Some partial_arg, Lam.var partial_arg in
151154

152155
let cont = Lam.function_
156+
~attr:Default_inline
153157
~arity:0
154158
~params:[]
155159
~body:(
@@ -168,7 +172,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
168172
{[ fun x y -> f y ]}
169173
*)
170174
let extra_args = Ext_list.init (to_ - from) (fun _ -> Ident.create Literals.param) in
171-
Lam.function_
175+
Lam.function_ ~attr:Default_inline
172176
~arity:to_
173177
~params:(Ext_list.append params extra_args )
174178
~body:(Lam.apply body (Ext_list.map extra_args Lam.var) loc App_na)
@@ -186,7 +190,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
186190
in
187191
let cont =
188192
Lam.function_
189-
~arity
193+
~arity ~attr:Default_inline
190194
191195
~params:extra_args
192196
~body:(
@@ -214,10 +218,10 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
214218
let extra_outer_args, extra_inner_args = Ext_list.split_at params arity in
215219
Lam.function_
216220
~arity
217-
221+
~attr:Default_inline
218222
~params:extra_outer_args
219223
~body:(
220-
Lam.function_ ~arity:(from - to_)
224+
Lam.function_ ~arity:(from - to_) ~attr:Default_inline
221225
~params:extra_inner_args ~body:body)
222226
| _
223227
->
@@ -234,12 +238,12 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
234238
Some partial_arg, Lam.var partial_arg
235239
in
236240
let cont =
237-
Lam.function_ ~arity:to_ ~params:extra_outer_args
241+
Lam.function_ ~arity:to_ ~params:extra_outer_args ~attr:Default_inline
238242
~body:(
239243
let arity = from - to_ in
240244
let extra_inner_args =
241245
Ext_list.init arity (fun _ -> Ident.create Literals.param ) in
242-
Lam.function_ ~arity ~params:extra_inner_args
246+
Lam.function_ ~arity ~params:extra_inner_args ~attr:Default_inline
243247
~body:(Lam.apply new_fn
244248
(Ext_list.map_append extra_outer_args
245249
(Ext_list.map extra_inner_args Lam.var)
@@ -265,7 +269,7 @@ let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : La
265269
let partial_arg = Ext_ident.create Literals.partial_arg in
266270
Some partial_arg, Lam.var partial_arg in
267271
268-
let cont = Lam.function_
272+
let cont = Lam.function_ ~attr:Default_inline
269273
~arity:0
270274
~params:[]
271275
~body:(

jscomp/core/lam_pass_alpha_conversion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
8686
end
8787
| Lprim {primitive; args ; loc} ->
8888
Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc
89-
| Lfunction {arity; params; body = l} ->
89+
| Lfunction {arity; params; body; attr} ->
9090
(* Lam_mk.lfunction kind params (simpl l) *)
91-
Lam.function_ ~arity ~params ~body:(simpl l)
91+
Lam.function_ ~arity ~params ~body:(simpl body) ~attr
9292
| Lswitch (l, {sw_failaction;
9393
sw_consts;
9494
sw_blocks;

jscomp/core/lam_pass_deep_flatten.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ let deep_flatten
262262
let args = Ext_list.map args aux in
263263
Lam.prim ~primitive ~args loc
264264

265-
| Lfunction{arity; params; body = l} ->
266-
Lam.function_ ~arity ~params ~body:(aux l)
265+
| Lfunction{arity; params; body; attr} ->
266+
Lam.function_ ~arity ~params ~body:(aux body) ~attr
267267
| Lswitch(l, {sw_failaction;
268268
sw_consts;
269269
sw_blocks;

jscomp/core/lam_pass_exits.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ let subst_helper (subst : subst_tbl) (query : int -> int) (lam : Lam.t) : Lam.t
217217
| Lvar _|Lconst _ -> lam
218218
| Lapply {ap_func; ap_args; ap_loc; ap_status } ->
219219
Lam.apply (simplif ap_func) (Ext_list.map ap_args simplif) ap_loc ap_status
220-
| Lfunction {arity; params; body} ->
221-
Lam.function_ ~arity ~params ~body:(simplif body)
220+
| Lfunction {arity; params; body; attr} ->
221+
Lam.function_ ~arity ~params ~body:(simplif body) ~attr
222222
| Llet (kind, v, l1, l2) ->
223223
Lam.let_ kind v (simplif l1) (simplif l2)
224224
| Lletrec (bindings, body) ->

jscomp/core/lam_pass_lets_dce.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
159159

160160
| Lapply{ap_func = l1; ap_args = ll; ap_loc = loc; ap_status = status} ->
161161
Lam.apply (simplif l1) (Ext_list.map ll simplif) loc status
162-
| Lfunction{arity; params; body = l} ->
163-
Lam.function_ ~arity ~params ~body:(simplif l)
162+
| Lfunction{arity; params; body; attr} ->
163+
Lam.function_ ~arity ~params ~body:(simplif body) ~attr
164164
| Lconst _ -> lam
165165
| Lletrec(bindings, body) ->
166166
Lam.letrec

jscomp/core/lam_pass_remove_alias.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ let simplify_alias
223223

224224
| Lapply { ap_func = l1; ap_args = ll; ap_loc = loc; ap_status = status} ->
225225
Lam.apply (simpl l1) (Ext_list.map ll simpl) loc status
226-
| Lfunction {arity; params; body = l}
227-
-> Lam.function_ ~arity ~params ~body:(simpl l)
226+
| Lfunction {arity; params; body; attr}
227+
-> Lam.function_ ~arity ~params ~body:(simpl body) ~attr
228228
| Lswitch (l, {sw_failaction;
229229
sw_consts;
230230
sw_blocks;

0 commit comments

Comments
 (0)