Skip to content

Commit 817b5d3

Browse files
committed
tweak
1 parent da119b5 commit 817b5d3

File tree

7 files changed

+60
-60
lines changed

7 files changed

+60
-60
lines changed

jscomp/core/js_output.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let output_of_expression
6262
make [ S.define_variable ~kind n exp]
6363
| Assign n ->
6464
make [S.assign n exp ]
65-
| EffectCall (Maybe_tail _) ->
65+
| EffectCall (Maybe_tail_is_return _) ->
6666
make [S.return_stmt exp] ~output_finished:True
6767
| NeedValue _ ->
6868
{block = []; value = Some exp; output_finished = False }
@@ -73,7 +73,7 @@ let output_of_block_and_expression
7373
(block : J.block) exp : t =
7474
match continuation with
7575
| EffectCall Not_tail -> make block ~value:exp
76-
| EffectCall (Maybe_tail _) ->
76+
| EffectCall (Maybe_tail_is_return _) ->
7777
make (Ext_list.append_one block (S.return_stmt exp)) ~output_finished:True
7878
| Declare (kind,n) ->
7979
make (Ext_list.append_one block (S.define_variable ~kind n exp))

jscomp/core/lam_compile.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ let change_tail_type_in_try
3232
(x : Lam_compile_context.tail_type)
3333
: Lam_compile_context.tail_type =
3434
match x with
35-
| Maybe_tail (Tail_with_name _ | Tail_no_name_lambda) ->
36-
Maybe_tail Tail_in_try
37-
| Not_tail | Maybe_tail Tail_in_try
35+
| Maybe_tail_is_return (Tail_with_name _ ) ->
36+
Maybe_tail_is_return Tail_in_try
37+
| Not_tail | Maybe_tail_is_return Tail_in_try
3838
-> x
3939

4040
(* assume outer is [Lstaticcatch] *)
@@ -262,7 +262,7 @@ and compile_recursive_let ~all_bindings
262262
let output =
263263
compile_lambda
264264
{ cxt with
265-
continuation = EffectCall (Maybe_tail (Tail_with_name ret ));
265+
continuation = EffectCall (Maybe_tail_is_return (Tail_with_name (Some ret )));
266266
jmp_table = Lam_compile_context.empty_handler_map} body in
267267
let result =
268268
if ret.triggered then
@@ -1203,7 +1203,7 @@ and compile_ifthenelse
12031203
(Js_output.output_as_block (
12041204
compile_lambda lambda_cxt t_branch))
12051205
?else_))
1206-
| Maybe_tail _, {block = []; value = Some out1},
1206+
| Maybe_tail_is_return _, {block = []; value = Some out1},
12071207
{block = []; value = Some out2} ->
12081208
Js_output.make
12091209
(Ext_list.append_one b (S.return_stmt (E.econd e out1 out2)))
@@ -1256,7 +1256,7 @@ and compile_apply
12561256
) in
12571257
match fn, lambda_cxt.continuation with
12581258
| (Lvar fn_id,
1259-
(EffectCall (Maybe_tail (Tail_with_name ret)) | NeedValue (Maybe_tail (Tail_with_name ret))))
1259+
(EffectCall (Maybe_tail_is_return (Tail_with_name (Some ret))) | NeedValue (Maybe_tail_is_return (Tail_with_name (Some ret)))))
12601260
when Ident.same ret.id fn_id ->
12611261
ret.triggered <- true;
12621262
(* Here we mark [finished] true, since the continuation
@@ -1439,7 +1439,7 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
14391439
*)
14401440
(Js_output.output_as_block
14411441
( compile_lambda
1442-
{ lambda_cxt with continuation = EffectCall ( Maybe_tail Tail_no_name_lambda);
1442+
{ lambda_cxt with continuation = EffectCall ( Maybe_tail_is_return (Tail_with_name None));
14431443
jmp_table = Lam_compile_context.empty_handler_map}
14441444
body)))
14451445
| _ -> assert false)
@@ -1492,7 +1492,7 @@ and compile_lambda
14921492
(Js_output.output_as_block
14931493
( compile_lambda
14941494
{ lambda_cxt with
1495-
continuation = EffectCall (Maybe_tail Tail_no_name_lambda);
1495+
continuation = EffectCall (Maybe_tail_is_return (Tail_with_name None));
14961496
jmp_table = Lam_compile_context.empty_handler_map}
14971497
body)))
14981498
| Lapply appinfo ->

jscomp/core/lam_compile_context.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ type return_label = {
4848

4949
type maybe_tail =
5050
| Tail_in_try
51-
| Tail_no_name_lambda
52-
| Tail_with_name of return_label
51+
| Tail_with_name of return_label option
5352

5453
type tail_type =
5554
| Not_tail
56-
| Maybe_tail of maybe_tail
55+
| Maybe_tail_is_return of maybe_tail
5756
(* Note [return] does indicate it is a tail position in most cases
5857
however, in an exception handler, return may not be in tail position
59-
to fix #1701 we play a trick that (Maybe_tail None)
58+
to fix #1701 we play a trick that (Maybe_tail_is_return None)
6059
would never trigger tailcall, however, it preserves [return]
6160
semantics
6261
*)
@@ -75,7 +74,7 @@ type jmp_table = value HandlerMap.t
7574

7675
let continuation_is_return ( x : continuation) =
7776
match x with
78-
| EffectCall (Maybe_tail _) | NeedValue (Maybe_tail _)
77+
| EffectCall (Maybe_tail_is_return _) | NeedValue (Maybe_tail_is_return _)
7978
-> true
8079
| EffectCall Not_tail | NeedValue Not_tail
8180
| Declare _ | Assign _

jscomp/core/lam_compile_context.mli

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ type value = {
5858
type let_kind = Lam_compat.let_kind
5959

6060
type maybe_tail =
61-
| Tail_in_try
62-
| Tail_no_name_lambda
63-
| Tail_with_name of return_label
61+
| Tail_in_try
62+
| Tail_with_name of return_label option
6463

6564
type tail_type =
6665
| Not_tail
67-
| Maybe_tail of maybe_tail
66+
| Maybe_tail_is_return of maybe_tail
6867
(* anonoymous function does not have identifier *)
6968

7069
(* delegate to the callee to generate expression
@@ -87,6 +86,8 @@ type jmp_table
8786
val continuation_is_return:
8887
continuation ->
8988
bool
89+
90+
9091
type t = {
9192
continuation : continuation ;
9293
jmp_table : jmp_table;

jscomp/core/lam_compile_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module E = Js_exp_make
3636
*)
3737
let ensure_value_unit (st : Lam_compile_context.continuation) e : E.t =
3838
match st with
39-
| EffectCall (Maybe_tail _ ) | NeedValue (Maybe_tail _)
39+
| EffectCall (Maybe_tail_is_return _ ) | NeedValue (Maybe_tail_is_return _)
4040
| Assign _ | Declare _ | NeedValue _ -> E.seq e E.unit
4141
| EffectCall Not_tail -> e
4242
(* NeedValue should return a meaningful expression*)

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98133,13 +98133,12 @@ type value = {
9813398133
type let_kind = Lam_compat.let_kind
9813498134

9813598135
type maybe_tail =
98136-
| Tail_in_try
98137-
| Tail_no_name_lambda
98138-
| Tail_with_name of return_label
98136+
| Tail_in_try
98137+
| Tail_with_name of return_label option
9813998138

9814098139
type tail_type =
9814198140
| Not_tail
98142-
| Maybe_tail of maybe_tail
98141+
| Maybe_tail_is_return of maybe_tail
9814398142
(* anonoymous function does not have identifier *)
9814498143

9814598144
(* delegate to the callee to generate expression
@@ -98162,6 +98161,8 @@ type jmp_table
9816298161
val continuation_is_return:
9816398162
continuation ->
9816498163
bool
98164+
98165+
9816598166
type t = {
9816698167
continuation : continuation ;
9816798168
jmp_table : jmp_table;
@@ -98239,15 +98240,14 @@ type return_label = {
9823998240

9824098241
type maybe_tail =
9824198242
| Tail_in_try
98242-
| Tail_no_name_lambda
98243-
| Tail_with_name of return_label
98243+
| Tail_with_name of return_label option
9824498244

9824598245
type tail_type =
9824698246
| Not_tail
98247-
| Maybe_tail of maybe_tail
98247+
| Maybe_tail_is_return of maybe_tail
9824898248
(* Note [return] does indicate it is a tail position in most cases
9824998249
however, in an exception handler, return may not be in tail position
98250-
to fix #1701 we play a trick that (Maybe_tail None)
98250+
to fix #1701 we play a trick that (Maybe_tail_is_return None)
9825198251
would never trigger tailcall, however, it preserves [return]
9825298252
semantics
9825398253
*)
@@ -98266,7 +98266,7 @@ type jmp_table = value HandlerMap.t
9826698266

9826798267
let continuation_is_return ( x : continuation) =
9826898268
match x with
98269-
| EffectCall (Maybe_tail _) | NeedValue (Maybe_tail _)
98269+
| EffectCall (Maybe_tail_is_return _) | NeedValue (Maybe_tail_is_return _)
9827098270
-> true
9827198271
| EffectCall Not_tail | NeedValue Not_tail
9827298272
| Declare _ | Assign _
@@ -98488,7 +98488,7 @@ let output_of_expression
9848898488
make [ S.define_variable ~kind n exp]
9848998489
| Assign n ->
9849098490
make [S.assign n exp ]
98491-
| EffectCall (Maybe_tail _) ->
98491+
| EffectCall (Maybe_tail_is_return _) ->
9849298492
make [S.return_stmt exp] ~output_finished:True
9849398493
| NeedValue _ ->
9849498494
{block = []; value = Some exp; output_finished = False }
@@ -98499,7 +98499,7 @@ let output_of_block_and_expression
9849998499
(block : J.block) exp : t =
9850098500
match continuation with
9850198501
| EffectCall Not_tail -> make block ~value:exp
98502-
| EffectCall (Maybe_tail _) ->
98502+
| EffectCall (Maybe_tail_is_return _) ->
9850398503
make (Ext_list.append_one block (S.return_stmt exp)) ~output_finished:True
9850498504
| Declare (kind,n) ->
9850598505
make (Ext_list.append_one block (S.define_variable ~kind n exp))
@@ -107203,7 +107203,7 @@ module E = Js_exp_make
107203107203
*)
107204107204
let ensure_value_unit (st : Lam_compile_context.continuation) e : E.t =
107205107205
match st with
107206-
| EffectCall (Maybe_tail _ ) | NeedValue (Maybe_tail _)
107206+
| EffectCall (Maybe_tail_is_return _ ) | NeedValue (Maybe_tail_is_return _)
107207107207
| Assign _ | Declare _ | NeedValue _ -> E.seq e E.unit
107208107208
| EffectCall Not_tail -> e
107209107209
(* NeedValue should return a meaningful expression*)
@@ -110733,9 +110733,9 @@ let change_tail_type_in_try
110733110733
(x : Lam_compile_context.tail_type)
110734110734
: Lam_compile_context.tail_type =
110735110735
match x with
110736-
| Maybe_tail (Tail_with_name _ | Tail_no_name_lambda) ->
110737-
Maybe_tail Tail_in_try
110738-
| Not_tail | Maybe_tail Tail_in_try
110736+
| Maybe_tail_is_return (Tail_with_name _ ) ->
110737+
Maybe_tail_is_return Tail_in_try
110738+
| Not_tail | Maybe_tail_is_return Tail_in_try
110739110739
-> x
110740110740

110741110741
(* assume outer is [Lstaticcatch] *)
@@ -110963,7 +110963,7 @@ and compile_recursive_let ~all_bindings
110963110963
let output =
110964110964
compile_lambda
110965110965
{ cxt with
110966-
continuation = EffectCall (Maybe_tail (Tail_with_name ret ));
110966+
continuation = EffectCall (Maybe_tail_is_return (Tail_with_name (Some ret )));
110967110967
jmp_table = Lam_compile_context.empty_handler_map} body in
110968110968
let result =
110969110969
if ret.triggered then
@@ -111900,7 +111900,7 @@ and compile_ifthenelse
111900111900
(Js_output.output_as_block (
111901111901
compile_lambda lambda_cxt t_branch))
111902111902
?else_))
111903-
| Maybe_tail _, {block = []; value = Some out1},
111903+
| Maybe_tail_is_return _, {block = []; value = Some out1},
111904111904
{block = []; value = Some out2} ->
111905111905
Js_output.make
111906111906
(Ext_list.append_one b (S.return_stmt (E.econd e out1 out2)))
@@ -111953,7 +111953,7 @@ and compile_apply
111953111953
) in
111954111954
match fn, lambda_cxt.continuation with
111955111955
| (Lvar fn_id,
111956-
(EffectCall (Maybe_tail (Tail_with_name ret)) | NeedValue (Maybe_tail (Tail_with_name ret))))
111956+
(EffectCall (Maybe_tail_is_return (Tail_with_name (Some ret))) | NeedValue (Maybe_tail_is_return (Tail_with_name (Some ret)))))
111957111957
when Ident.same ret.id fn_id ->
111958111958
ret.triggered <- true;
111959111959
(* Here we mark [finished] true, since the continuation
@@ -112136,7 +112136,7 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
112136112136
*)
112137112137
(Js_output.output_as_block
112138112138
( compile_lambda
112139-
{ lambda_cxt with continuation = EffectCall ( Maybe_tail Tail_no_name_lambda);
112139+
{ lambda_cxt with continuation = EffectCall ( Maybe_tail_is_return (Tail_with_name None));
112140112140
jmp_table = Lam_compile_context.empty_handler_map}
112141112141
body)))
112142112142
| _ -> assert false)
@@ -112189,7 +112189,7 @@ and compile_lambda
112189112189
(Js_output.output_as_block
112190112190
( compile_lambda
112191112191
{ lambda_cxt with
112192-
continuation = EffectCall (Maybe_tail Tail_no_name_lambda);
112192+
continuation = EffectCall (Maybe_tail_is_return (Tail_with_name None));
112193112193
jmp_table = Lam_compile_context.empty_handler_map}
112194112194
body)))
112195112195
| Lapply appinfo ->

0 commit comments

Comments
 (0)