Skip to content

Commit da119b5

Browse files
committed
tweak names/params
1 parent ec88aa5 commit da119b5

File tree

5 files changed

+84
-51
lines changed

5 files changed

+84
-51
lines changed

jscomp/core/lam_compile.ml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module S = Js_stmt_make
2828

2929
let method_cache_id = ref 1 (*TODO: move to js runtime for re-entrant *)
3030

31-
let change_return_type_in_try
31+
let change_tail_type_in_try
3232
(x : Lam_compile_context.tail_type)
3333
: Lam_compile_context.tail_type =
3434
match x with
@@ -38,16 +38,17 @@ let change_return_type_in_try
3838
-> x
3939

4040
(* assume outer is [Lstaticcatch] *)
41-
let rec flat_catches (acc : Lam_compile_context.handler list) (x : Lam.t)
41+
let rec flat_catches
42+
(acc : Lam_compile_context.handler list) (x : Lam.t)
4243
: Lam_compile_context.handler list * Lam.t =
4344
match x with
44-
| Lstaticcatch(l, (code, bindings), handler)
45+
| Lstaticcatch(l, (label, bindings), handler)
4546
when
4647
acc = [] ||
47-
(not @@ Lam_exit_code.has_exit_code handler
48-
(fun exit -> Ext_list.exists acc (fun { label } -> label = exit) ) )
48+
(not ( Lam_exit_code.has_exit_code handler
49+
(fun exit -> Ext_list.exists acc (fun x -> x.label = exit) ) ))
4950
-> (* #1698 should not crush exit code here without checking *)
50-
flat_catches ( {label = code; handler; bindings} ::acc) l
51+
flat_catches ( {label ; handler; bindings} ::acc) l
5152
| _ -> acc, x
5253

5354
let flatten_nested_caches (x : Lam.t)
@@ -641,7 +642,7 @@ and compile_stringswitch l cases default (lambda_cxt : Lam_compile_context.t) =
641642
*)
642643
and compile_staticraise i (largs : Lam.t list) lambda_cxt =
643644
(* [i] is the jump table, [largs] is the arguments passed to [Lstaticcatch]*)
644-
match Lam_compile_context.find_exn i lambda_cxt with
645+
match Lam_compile_context.find_exn lambda_cxt i with
645646
| {exit_id; bindings ; order_id} ->
646647
Ext_list.fold_right2 largs bindings
647648
(Js_output.make [S.assign exit_id (E.small_int order_id)]
@@ -691,8 +692,8 @@ and compile_staticraise i (largs : Lam.t list) lambda_cxt =
691692
692693
]}
693694
*)
694-
and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
695-
let code_table, body = flatten_nested_caches cur_lam in
695+
and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
696+
let code_table, body = flatten_nested_caches lam in
696697
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
697698
let exit_expr = E.var exit_id in
698699
let jmp_table, handlers =
@@ -727,7 +728,13 @@ and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
727728
(* place holder -- tell the compiler that
728729
we don't know if it's complete
729730
*)
730-
| EffectCall _ | Assign _ ->
731+
| EffectCall tail_type ->
732+
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
733+
let lbody = compile_lambda new_cxt body in
734+
Js_output.append_output (Js_output.make declares)
735+
(Js_output.append_output lbody
736+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete)))
737+
| Assign _ ->
731738
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
732739
let lbody = compile_lambda new_cxt body in
733740
Js_output.append_output (Js_output.make declares)
@@ -968,7 +975,7 @@ and compile_trywith lam id catch (lambda_cxt : Lam_compile_context.t) =
968975
Js_output.make (S.declare_variable ~kind:Variable v ::
969976
aux context context) ~value:(E.var v )
970977
| EffectCall return_type ->
971-
let new_return_type = change_return_type_in_try return_type in
978+
let new_return_type = change_tail_type_in_try return_type in
972979
if new_return_type == return_type then
973980
Js_output.make (aux lambda_cxt lambda_cxt)
974981
else

jscomp/core/lam_compile_context.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ let add_jmps
114114
map, List.rev handlers
115115

116116

117-
let find_exn i cxt =
117+
let find_exn cxt i =
118118
Int_map.find_exn cxt.jmp_table i

jscomp/core/lam_compile_context.mli

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ type handler = {
102102
}
103103

104104
val add_jmps :
105-
jmp_table ->
106-
Ident.t ->
107-
handler list ->
108-
jmp_table * (jbl_label * Lam.t) list
105+
jmp_table ->
106+
Ident.t ->
107+
handler list ->
108+
jmp_table * (jbl_label * Lam.t) list
109109

110-
val find_exn : jbl_label -> t -> value
110+
111+
val find_exn :
112+
t ->
113+
jbl_label ->
114+
value

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98177,12 +98177,16 @@ type handler = {
9817798177
}
9817898178

9817998179
val add_jmps :
98180-
jmp_table ->
98181-
Ident.t ->
98182-
handler list ->
98183-
jmp_table * (jbl_label * Lam.t) list
98180+
jmp_table ->
98181+
Ident.t ->
98182+
handler list ->
98183+
jmp_table * (jbl_label * Lam.t) list
98184+
9818498185

98185-
val find_exn : jbl_label -> t -> value
98186+
val find_exn :
98187+
t ->
98188+
jbl_label ->
98189+
value
9818698190
end = struct
9818798191
#1 "lam_compile_context.ml"
9818898192
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -98301,7 +98305,7 @@ let add_jmps
9830198305
map, List.rev handlers
9830298306

9830398307

98304-
let find_exn i cxt =
98308+
let find_exn cxt i =
9830598309
Int_map.find_exn cxt.jmp_table i
9830698310
end
9830798311
module Js_output : sig
@@ -110725,7 +110729,7 @@ module S = Js_stmt_make
110725110729

110726110730
let method_cache_id = ref 1 (*TODO: move to js runtime for re-entrant *)
110727110731

110728-
let change_return_type_in_try
110732+
let change_tail_type_in_try
110729110733
(x : Lam_compile_context.tail_type)
110730110734
: Lam_compile_context.tail_type =
110731110735
match x with
@@ -110735,16 +110739,17 @@ let change_return_type_in_try
110735110739
-> x
110736110740

110737110741
(* assume outer is [Lstaticcatch] *)
110738-
let rec flat_catches (acc : Lam_compile_context.handler list) (x : Lam.t)
110742+
let rec flat_catches
110743+
(acc : Lam_compile_context.handler list) (x : Lam.t)
110739110744
: Lam_compile_context.handler list * Lam.t =
110740110745
match x with
110741-
| Lstaticcatch(l, (code, bindings), handler)
110746+
| Lstaticcatch(l, (label, bindings), handler)
110742110747
when
110743110748
acc = [] ||
110744-
(not @@ Lam_exit_code.has_exit_code handler
110745-
(fun exit -> Ext_list.exists acc (fun { label } -> label = exit) ) )
110749+
(not ( Lam_exit_code.has_exit_code handler
110750+
(fun exit -> Ext_list.exists acc (fun x -> x.label = exit) ) ))
110746110751
-> (* #1698 should not crush exit code here without checking *)
110747-
flat_catches ( {label = code; handler; bindings} ::acc) l
110752+
flat_catches ( {label ; handler; bindings} ::acc) l
110748110753
| _ -> acc, x
110749110754

110750110755
let flatten_nested_caches (x : Lam.t)
@@ -111338,7 +111343,7 @@ and compile_stringswitch l cases default (lambda_cxt : Lam_compile_context.t) =
111338111343
*)
111339111344
and compile_staticraise i (largs : Lam.t list) lambda_cxt =
111340111345
(* [i] is the jump table, [largs] is the arguments passed to [Lstaticcatch]*)
111341-
match Lam_compile_context.find_exn i lambda_cxt with
111346+
match Lam_compile_context.find_exn lambda_cxt i with
111342111347
| {exit_id; bindings ; order_id} ->
111343111348
Ext_list.fold_right2 largs bindings
111344111349
(Js_output.make [S.assign exit_id (E.small_int order_id)]
@@ -111384,8 +111389,8 @@ and compile_staticraise i (largs : Lam.t list) lambda_cxt =
111384111389

111385111390
]}
111386111391
*)
111387-
and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
111388-
let code_table, body = flatten_nested_caches cur_lam in
111392+
and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
111393+
let code_table, body = flatten_nested_caches lam in
111389111394
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
111390111395
let exit_expr = E.var exit_id in
111391111396
let jmp_table, handlers =
@@ -111420,7 +111425,13 @@ and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
111420111425
(* place holder -- tell the compiler that
111421111426
we don't know if it's complete
111422111427
*)
111423-
| EffectCall _ | Assign _ ->
111428+
| EffectCall tail_type ->
111429+
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
111430+
let lbody = compile_lambda new_cxt body in
111431+
Js_output.append_output (Js_output.make declares)
111432+
(Js_output.append_output lbody
111433+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete)))
111434+
| Assign _ ->
111424111435
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
111425111436
let lbody = compile_lambda new_cxt body in
111426111437
Js_output.append_output (Js_output.make declares)
@@ -111661,7 +111672,7 @@ and compile_trywith lam id catch (lambda_cxt : Lam_compile_context.t) =
111661111672
Js_output.make (S.declare_variable ~kind:Variable v ::
111662111673
aux context context) ~value:(E.var v )
111663111674
| EffectCall return_type ->
111664-
let new_return_type = change_return_type_in_try return_type in
111675+
let new_return_type = change_tail_type_in_try return_type in
111665111676
if new_return_type == return_type then
111666111677
Js_output.make (aux lambda_cxt lambda_cxt)
111667111678
else

lib/4.02.3/whole_compiler.ml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88797,12 +88797,16 @@ type handler = {
8879788797
}
8879888798

8879988799
val add_jmps :
88800-
jmp_table ->
88801-
Ident.t ->
88802-
handler list ->
88803-
jmp_table * (jbl_label * Lam.t) list
88800+
jmp_table ->
88801+
Ident.t ->
88802+
handler list ->
88803+
jmp_table * (jbl_label * Lam.t) list
88804+
8880488805

88805-
val find_exn : jbl_label -> t -> value
88806+
val find_exn :
88807+
t ->
88808+
jbl_label ->
88809+
value
8880688810
end = struct
8880788811
#1 "lam_compile_context.ml"
8880888812
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -88921,7 +88925,7 @@ let add_jmps
8892188925
map, List.rev handlers
8892288926

8892388927

88924-
let find_exn i cxt =
88928+
let find_exn cxt i =
8892588929
Int_map.find_exn cxt.jmp_table i
8892688930
end
8892788931
module Js_output : sig
@@ -101830,7 +101834,7 @@ module S = Js_stmt_make
101830101834

101831101835
let method_cache_id = ref 1 (*TODO: move to js runtime for re-entrant *)
101832101836

101833-
let change_return_type_in_try
101837+
let change_tail_type_in_try
101834101838
(x : Lam_compile_context.tail_type)
101835101839
: Lam_compile_context.tail_type =
101836101840
match x with
@@ -101840,16 +101844,17 @@ let change_return_type_in_try
101840101844
-> x
101841101845

101842101846
(* assume outer is [Lstaticcatch] *)
101843-
let rec flat_catches (acc : Lam_compile_context.handler list) (x : Lam.t)
101847+
let rec flat_catches
101848+
(acc : Lam_compile_context.handler list) (x : Lam.t)
101844101849
: Lam_compile_context.handler list * Lam.t =
101845101850
match x with
101846-
| Lstaticcatch(l, (code, bindings), handler)
101851+
| Lstaticcatch(l, (label, bindings), handler)
101847101852
when
101848101853
acc = [] ||
101849-
(not @@ Lam_exit_code.has_exit_code handler
101850-
(fun exit -> Ext_list.exists acc (fun { label } -> label = exit) ) )
101854+
(not ( Lam_exit_code.has_exit_code handler
101855+
(fun exit -> Ext_list.exists acc (fun x -> x.label = exit) ) ))
101851101856
-> (* #1698 should not crush exit code here without checking *)
101852-
flat_catches ( {label = code; handler; bindings} ::acc) l
101857+
flat_catches ( {label ; handler; bindings} ::acc) l
101853101858
| _ -> acc, x
101854101859

101855101860
let flatten_nested_caches (x : Lam.t)
@@ -102443,7 +102448,7 @@ and compile_stringswitch l cases default (lambda_cxt : Lam_compile_context.t) =
102443102448
*)
102444102449
and compile_staticraise i (largs : Lam.t list) lambda_cxt =
102445102450
(* [i] is the jump table, [largs] is the arguments passed to [Lstaticcatch]*)
102446-
match Lam_compile_context.find_exn i lambda_cxt with
102451+
match Lam_compile_context.find_exn lambda_cxt i with
102447102452
| {exit_id; bindings ; order_id} ->
102448102453
Ext_list.fold_right2 largs bindings
102449102454
(Js_output.make [S.assign exit_id (E.small_int order_id)]
@@ -102489,8 +102494,8 @@ and compile_staticraise i (largs : Lam.t list) lambda_cxt =
102489102494

102490102495
]}
102491102496
*)
102492-
and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
102493-
let code_table, body = flatten_nested_caches cur_lam in
102497+
and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
102498+
let code_table, body = flatten_nested_caches lam in
102494102499
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
102495102500
let exit_expr = E.var exit_id in
102496102501
let jmp_table, handlers =
@@ -102525,7 +102530,13 @@ and compile_staticcatch (cur_lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
102525102530
(* place holder -- tell the compiler that
102526102531
we don't know if it's complete
102527102532
*)
102528-
| EffectCall _ | Assign _ ->
102533+
| EffectCall tail_type ->
102534+
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
102535+
let lbody = compile_lambda new_cxt body in
102536+
Js_output.append_output (Js_output.make declares)
102537+
(Js_output.append_output lbody
102538+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete)))
102539+
| Assign _ ->
102529102540
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
102530102541
let lbody = compile_lambda new_cxt body in
102531102542
Js_output.append_output (Js_output.make declares)
@@ -102766,7 +102777,7 @@ and compile_trywith lam id catch (lambda_cxt : Lam_compile_context.t) =
102766102777
Js_output.make (S.declare_variable ~kind:Variable v ::
102767102778
aux context context) ~value:(E.var v )
102768102779
| EffectCall return_type ->
102769-
let new_return_type = change_return_type_in_try return_type in
102780+
let new_return_type = change_tail_type_in_try return_type in
102770102781
if new_return_type == return_type then
102771102782
Js_output.make (aux lambda_cxt lambda_cxt)
102772102783
else

0 commit comments

Comments
 (0)