Skip to content

Commit 410d15e

Browse files
committed
refine recursive function information
1 parent 3a60c0e commit 410d15e

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

jscomp/core/lam_analysis.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ let destruct_pattern (body : Lam.t) params args =
377377
| _ -> false
378378

379379
(** Hints to inlining *)
380-
let ok_to_inline_fun_when_app ~body params args =
380+
let ok_to_inline_fun_when_app
381+
~(body : Lam.t)
382+
(params : Ident.t list)
383+
(args : Lam.t list) =
381384
let s = size body in
382385
s < small_inline_size ||
383386
(destruct_pattern body params args) ||

jscomp/core/lam_coercion.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ let handle_exports (meta : Lam_stats.t)
144144
(FunctionId{arity ; lambda =
145145
match lam with
146146
| Lfunction _ ->
147-
Some (lam, Non_rec)
147+
Some (lam, Lam_non_rec)
148148
| _ -> None })
149149
);
150150
{ acc with

jscomp/core/lam_id_kind.ml

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828

2929

3030
type rec_flag =
31-
| Rec
32-
| Non_rec
31+
| Lam_rec
32+
| Lam_non_rec
33+
| Lam_self_rec
34+
(* only a
35+
single mutual
36+
recursive function
37+
*)
3338

3439

3540
type function_id = {

jscomp/core/lam_id_kind.mli

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424

2525

2626
type rec_flag =
27-
| Rec
28-
| Non_rec
27+
| Lam_rec
28+
| Lam_non_rec
2929

3030
(* TODO: This may contain some closure environment,
3131
check how it will interact with dead code elimination
3232
*)
33+
| Lam_self_rec
34+
(* not inlining in this case *)
3335
type function_id = {
3436
mutable arity : Lam_arity.t;
3537
lambda : (Lam.t * rec_flag) option ;

jscomp/core/lam_pass_collect.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ let collect_helper (meta : Lam_stats.t) (lam : Lam.t) =
143143
List.iter (fun p -> Ident_hashtbl.add meta.ident_tbl p Parameter ) params;
144144
collect l
145145
| Llet (kind,ident,arg,body) ->
146-
collect_bind Non_rec kind ident arg ; collect body
146+
collect_bind Lam_non_rec kind ident arg ; collect body
147147
| Lletrec (bindings, body) ->
148-
List.iter (fun (ident,arg) -> collect_bind Rec Strict ident arg ) bindings;
148+
(match bindings with
149+
| [ident, arg] -> collect_bind Lam_self_rec Strict ident arg
150+
| _ ->
151+
Ext_list.iter bindings
152+
(fun (ident,arg) -> collect_bind Lam_rec Strict ident arg )) ;
149153
collect body
150154
| Lglobal_module _ -> ()
151155
| Lprim {args; _} -> List.iter collect args

jscomp/core/lam_pass_remove_alias.ml

+8-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ let simplify_alias
234234
match is_export_id, param_map with
235235
| false, (_, param_map)
236236
| true, (true, param_map) ->
237-
if rec_flag = Rec then
238-
Lam_beta_reduce.propogate_beta_reduce_with_map meta param_map params body args
239-
else
240-
simpl (Lam_beta_reduce.propogate_beta_reduce_with_map meta param_map params body args)
237+
begin match rec_flag with
238+
| Lam_self_rec
239+
| Lam_rec -> Lam_beta_reduce.propogate_beta_reduce_with_map meta param_map params body args
240+
241+
| Lam_non_rec ->
242+
simpl
243+
(Lam_beta_reduce.propogate_beta_reduce_with_map meta param_map params body args)
244+
end
241245
| _ -> normal ()
242246
else
243247
normal ()

0 commit comments

Comments
 (0)