Skip to content

Commit db9bdfd

Browse files
committed
Rename cps_calls into trampolined_calls for clarity
1 parent ee13805 commit db9bdfd

File tree

5 files changed

+41
-37
lines changed

5 files changed

+41
-37
lines changed

compiler/lib/driver.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ let effects p =
9595
then (
9696
if debug () then Format.eprintf "Effects...@.";
9797
p |> Deadcode.f +> Effects.f +> map_fst Lambda_lifting.f)
98-
else p, (Code.Var.Set.empty : Effects.cps_calls), (Code.Var.Set.empty : Effects.in_cps)
98+
else
99+
( p
100+
, (Code.Var.Set.empty : Effects.trampolined_calls)
101+
, (Code.Var.Set.empty : Effects.in_cps) )
99102

100103
let exact_calls profile p =
101104
if not (Config.Flag.effects ())
@@ -179,14 +182,14 @@ let generate
179182
~exported_runtime
180183
~wrap_with_fun
181184
~warn_on_unhandled_effect
182-
((p, live_vars), cps_calls, _) =
185+
((p, live_vars), trampolined_calls, _) =
183186
if times () then Format.eprintf "Start Generation...@.";
184187
let should_export = should_export wrap_with_fun in
185188
Generate.f
186189
p
187190
~exported_runtime
188191
~live_vars
189-
~cps_calls
192+
~trampolined_calls
190193
~should_export
191194
~warn_on_unhandled_effect
192195
d

compiler/lib/effects.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ let jump_closures blocks_to_transform idom : jump_closures =
247247
idom
248248
{ closure_of_jump = Addr.Map.empty; closures_of_alloc_site = Addr.Map.empty }
249249

250-
type cps_calls = Var.Set.t
250+
type trampolined_calls = Var.Set.t
251251

252252
type in_cps = Var.Set.t
253253

@@ -265,7 +265,7 @@ type st =
265265
; block_order : (Addr.t, int) Hashtbl.t
266266
; live_vars : Deadcode.variable_uses
267267
; flow_info : Global_flow.info
268-
; cps_calls : cps_calls ref
268+
; trampolined_calls : trampolined_calls ref
269269
; in_cps : in_cps ref
270270
}
271271

@@ -286,7 +286,7 @@ let allocate_closure ~st ~params ~body ~branch loc =
286286
let tail_call ~st ?(instrs = []) ~exact ~in_cps ~check ~f args loc =
287287
assert (exact || check);
288288
let ret = Var.fresh () in
289-
if check then st.cps_calls := Var.Set.add ret !(st.cps_calls);
289+
if check then st.trampolined_calls := Var.Set.add ret !(st.trampolined_calls);
290290
if in_cps then st.in_cps := Var.Set.add ret !(st.in_cps);
291291
instrs @ [ Let (ret, Apply { f; args; exact }), loc ], (Return ret, loc)
292292

@@ -615,7 +615,7 @@ let cps_block ~st ~k pc block =
615615

616616
let cps_transform ~live_vars ~flow_info ~cps_needed p =
617617
let closure_info = Hashtbl.create 16 in
618-
let cps_calls = ref Var.Set.empty in
618+
let trampolined_calls = ref Var.Set.empty in
619619
let in_cps = ref Var.Set.empty in
620620
let p =
621621
Code.fold_closures_innermost_first
@@ -675,7 +675,7 @@ let cps_transform ~live_vars ~flow_info ~cps_needed p =
675675
; block_order = cfg.block_order
676676
; flow_info
677677
; live_vars
678-
; cps_calls
678+
; trampolined_calls
679679
; in_cps
680680
}
681681
in
@@ -753,7 +753,7 @@ let cps_transform ~live_vars ~flow_info ~cps_needed p =
753753
in
754754
{ start = new_start; blocks; free_pc = new_start + 1 }
755755
in
756-
p, !cps_calls, !in_cps
756+
p, !trampolined_calls, !in_cps
757757

758758
(****)
759759

@@ -947,6 +947,6 @@ let f (p, live_vars) =
947947
let cps_needed = Partial_cps_analysis.f p flow_info in
948948
let p, cps_needed = rewrite_toplevel ~cps_needed p in
949949
let p = split_blocks ~cps_needed p in
950-
let p, cps_calls, in_cps = cps_transform ~live_vars ~flow_info ~cps_needed p in
950+
let p, trampolined_calls, in_cps = cps_transform ~live_vars ~flow_info ~cps_needed p in
951951
if Debug.find "times" () then Format.eprintf " effects: %a@." Timer.print t;
952-
p, cps_calls, in_cps
952+
p, trampolined_calls, in_cps

compiler/lib/effects.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717
*)
1818

19-
type cps_calls = Code.Var.Set.t
19+
type trampolined_calls = Code.Var.Set.t
2020

2121
type in_cps = Code.Var.Set.t
2222

23-
val f : Code.program * Deadcode.variable_uses -> Code.program * cps_calls * in_cps
23+
val f : Code.program * Deadcode.variable_uses -> Code.program * trampolined_calls * in_cps

compiler/lib/generate.ml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let list_group f g l =
6666
type application_description =
6767
{ arity : int
6868
; exact : bool
69-
; cps : bool
69+
; trampolined : bool
7070
}
7171

7272
module Share = struct
@@ -144,7 +144,7 @@ module Share = struct
144144
| _ -> t)
145145

146146
let get
147-
~cps_calls
147+
~trampolined_calls
148148
?alias_strings
149149
?(alias_prims = false)
150150
?(alias_apply = true)
@@ -161,9 +161,9 @@ module Share = struct
161161
match i with
162162
| Let (_, Constant c) -> get_constant c share
163163
| Let (x, Apply { args; exact; _ }) ->
164-
let cps = Var.Set.mem x cps_calls in
165-
if (not exact) || cps
166-
then add_apply { arity = List.length args; exact; cps } share
164+
let trampolined = Var.Set.mem x trampolined_calls in
165+
if (not exact) || trampolined
166+
then add_apply { arity = List.length args; exact; trampolined } share
167167
else share
168168
| Let (_, Special (Alias_prim name)) ->
169169
let name = Primitive.resolve name in
@@ -255,11 +255,11 @@ module Share = struct
255255
try J.EVar (AppMap.find desc t.vars.applies)
256256
with Not_found ->
257257
let x =
258-
let { arity; exact; cps } = desc in
258+
let { arity; exact; trampolined } = desc in
259259
Var.fresh_n
260260
(Printf.sprintf
261261
"caml_%scall%d"
262-
(match exact, cps with
262+
(match exact, trampolined with
263263
| true, false -> assert false
264264
| true, true -> "cps_exact_"
265265
| false, false -> ""
@@ -280,7 +280,7 @@ module Ctx = struct
280280
; exported_runtime : (Code.Var.t * bool ref) option
281281
; should_export : bool
282282
; effect_warning : bool ref
283-
; cps_calls : Effects.cps_calls
283+
; trampolined_calls : Effects.trampolined_calls
284284
}
285285

286286
let initial
@@ -289,7 +289,7 @@ module Ctx = struct
289289
~should_export
290290
blocks
291291
live
292-
cps_calls
292+
trampolined_calls
293293
share
294294
debug =
295295
{ blocks
@@ -299,7 +299,7 @@ module Ctx = struct
299299
; exported_runtime
300300
; should_export
301301
; effect_warning = ref (not warn_on_unhandled_effect)
302-
; cps_calls
302+
; trampolined_calls
303303
}
304304
end
305305

@@ -950,7 +950,7 @@ let parallel_renaming params args continuation queue =
950950

951951
(****)
952952

953-
let apply_fun_raw ctx f params exact cps =
953+
let apply_fun_raw ctx f params exact trampolined =
954954
let n = List.length params in
955955
let apply_directly =
956956
(* Make sure we are performing a regular call, not a (slower)
@@ -979,7 +979,7 @@ let apply_fun_raw ctx f params exact cps =
979979
, apply_directly
980980
, J.call (runtime_fun ctx "caml_call_gen") [ f; J.array params ] J.N )
981981
in
982-
if cps
982+
if trampolined
983983
then (
984984
assert (Config.Flag.effects ());
985985
(* When supporting effect, we systematically perform tailcall
@@ -992,7 +992,7 @@ let apply_fun_raw ctx f params exact cps =
992992
, J.call (runtime_fun ctx "caml_trampoline_return") [ f; J.array params ] J.N ))
993993
else apply
994994

995-
let generate_apply_fun ctx { arity; exact; cps } =
995+
let generate_apply_fun ctx { arity; exact; trampolined } =
996996
let f' = Var.fresh_n "f" in
997997
let f = J.V f' in
998998
let params =
@@ -1007,23 +1007,24 @@ let generate_apply_fun ctx { arity; exact; cps } =
10071007
( None
10081008
, J.fun_
10091009
(f :: params)
1010-
[ J.Return_statement (Some (apply_fun_raw ctx f' params' exact cps)), J.N ]
1010+
[ J.Return_statement (Some (apply_fun_raw ctx f' params' exact trampolined)), J.N
1011+
]
10111012
J.N )
10121013

1013-
let apply_fun ctx f params exact cps loc =
1014+
let apply_fun ctx f params exact trampolined loc =
10141015
(* We always go through an intermediate function when doing CPS
10151016
calls. This function first checks the stack depth to prevent
10161017
a stack overflow. This makes the code smaller than inlining
10171018
the test, and we expect the performance impact to be low
10181019
since the function should get inlined by the JavaScript
10191020
engines. *)
1020-
if Config.Flag.inline_callgen () || (exact && not cps)
1021-
then apply_fun_raw ctx f params exact cps
1021+
if Config.Flag.inline_callgen () || (exact && not trampolined)
1022+
then apply_fun_raw ctx f params exact trampolined
10221023
else
10231024
let y =
10241025
Share.get_apply
10251026
(generate_apply_fun ctx)
1026-
{ arity = List.length params; exact; cps }
1027+
{ arity = List.length params; exact; trampolined }
10271028
ctx.Ctx.share
10281029
in
10291030
J.call y (f :: params) loc
@@ -1209,7 +1210,7 @@ let throw_statement ctx cx k loc =
12091210
let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
12101211
match e with
12111212
| Apply { f; args; exact } ->
1212-
let cps = Var.Set.mem x ctx.Ctx.cps_calls in
1213+
let trampolined = Var.Set.mem x ctx.Ctx.trampolined_calls in
12131214
let args, prop, queue =
12141215
List.fold_right
12151216
~f:(fun x (args, prop, queue) ->
@@ -1220,7 +1221,7 @@ let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
12201221
in
12211222
let (prop', f), queue = access_queue queue f in
12221223
let prop = or_p prop prop' in
1223-
let e = apply_fun ctx f args exact cps loc in
1224+
let e = apply_fun ctx f args exact trampolined loc in
12241225
(e, prop, queue), []
12251226
| Block (tag, a, array_or_not, _mut) ->
12261227
let contents, prop, queue =
@@ -2121,12 +2122,12 @@ let f
21212122
(p : Code.program)
21222123
~exported_runtime
21232124
~live_vars
2124-
~cps_calls
2125+
~trampolined_calls
21252126
~should_export
21262127
~warn_on_unhandled_effect
21272128
debug =
21282129
let t' = Timer.make () in
2129-
let share = Share.get ~cps_calls ~alias_prims:exported_runtime p in
2130+
let share = Share.get ~trampolined_calls ~alias_prims:exported_runtime p in
21302131
let exported_runtime =
21312132
if exported_runtime then Some (Code.Var.fresh_n "runtime", ref false) else None
21322133
in
@@ -2137,7 +2138,7 @@ let f
21372138
~should_export
21382139
p.blocks
21392140
live_vars
2140-
cps_calls
2141+
trampolined_calls
21412142
share
21422143
debug
21432144
in

compiler/lib/generate.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ val f :
2222
Code.program
2323
-> exported_runtime:bool
2424
-> live_vars:Deadcode.variable_uses
25-
-> cps_calls:Effects.cps_calls
25+
-> trampolined_calls:Effects.trampolined_calls
2626
-> should_export:bool
2727
-> warn_on_unhandled_effect:bool
2828
-> Parse_bytecode.Debug.t

0 commit comments

Comments
 (0)