Skip to content

Commit 2f0c4df

Browse files
authored
Merge pull request #4606 from BuckleScript/fix_3961
fix #3961
2 parents 07064e8 + 0a10865 commit 2f0c4df

16 files changed

+655
-876
lines changed

jscomp/core/lam.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,26 @@ 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 is_a_functor =
39+
| Functor_yes
40+
| Functor_no
41+
| Functor_na
42+
43+
type function_attribute = {
44+
inline : inline_attribute;
45+
is_a_functor : is_a_functor
46+
}
47+
48+
let default_fn_attr : function_attribute = {
49+
inline = Default_inline;
50+
is_a_functor = Functor_na
51+
}
3752
module Types = struct
3853

3954
type lambda_switch =

jscomp/core/lam.mli

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

2525

2626

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

32+
type is_a_functor =
33+
| Functor_yes
34+
| Functor_no
35+
| Functor_na
36+
37+
type function_attribute = {
38+
inline : inline_attribute;
39+
is_a_functor : is_a_functor
40+
}
41+
42+
val default_fn_attr : function_attribute
43+
3244
type ident = Ident.t
3345

3446
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: 6 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,15 @@ 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+
let is_a_functor =
451+
if attr.is_a_functor then Lam.Functor_yes else Functor_no in
452+
Lam.{inline; is_a_functor}
449453

450454

451455

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/core/lam_inline_util.ml

Lines changed: 0 additions & 45 deletions
This file was deleted.

jscomp/core/lam_inline_util.mli

Lines changed: 0 additions & 36 deletions
This file was deleted.

jscomp/core/lam_pass_remove_alias.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ let simplify_alias
155155
let normal () = Lam.apply ( simpl fn) (Ext_list.map args simpl) loc status in
156156
begin
157157
match Hash_ident.find_opt meta.ident_tbl v with
158-
| Some (FunctionId {lambda = Some(Lfunction ({params; body} as m),
158+
| Some (FunctionId {lambda = Some(Lfunction ({params; body; attr = {is_a_functor}} as m),
159159
rec_flag)
160160
})
161161
->
162162

163163
if Ext_list.same_length args params (* && false *)
164164
then
165-
if Lam_inline_util.maybe_functor v.name
165+
if is_a_functor = Functor_yes
166166
(* && (Set_ident.mem v meta.export_idents) && false *)
167167
then
168168
(* TODO: check l1 if it is exported,

jscomp/core/lam_stats_export.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ let values_of_export
7474
only truly immutable values can be inlined
7575
*)
7676
then
77-
if Lam_inline_util.should_be_functor x.name lambda (* can also be submodule *)
78-
then
77+
match lambda with
78+
| Lfunction {attr = {is_a_functor = Functor_yes}} ->
7979
if Lam_closure.is_closed lambda (* TODO: seriealize more*)
8080
then Some lambda
8181
else None
82-
else
82+
| _ ->
8383
let lam_size = Lam_analysis.size lambda in
8484
(* TODO:
8585
1. global need re-assocate when do the beta reduction

0 commit comments

Comments
 (0)