Skip to content

Commit 0e5d0f0

Browse files
committed
Clarify compiler cleanup documentation
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent 9ba9438 commit 0e5d0f0

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

compiler/core/lam_pass_count.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ let absorb_info (x : used_info) (y : used_info) =
3636
x.times <- x0 + y0;
3737
if captured then x.captured <- true
3838

39-
(* The global table [occ] associates each let-bound identifier with its number
40-
of uses. A use under a lambda or within a loop is treated as multiple uses,
41-
since neither case is suitable for inlining. The local table [bv] tracks
42-
locally let-bound variables and is reset when crossing lambdas and loops. *)
39+
(* The global table [occ] records each let-bound identifier's number of uses and
40+
whether it is captured by a function or loop. The local table [bv] tracks
41+
locally let-bound variables and is reset when crossing functions and loops,
42+
so uses of outer bindings are marked as captured. The optimizer uses the
43+
captured flag to restrict inlining without inflating the occurrence count. *)
4344
let collect_occurs lam : occ_tbl =
4445
let occ : occ_tbl = Hash_ident.create 83 in
4546

@@ -63,8 +64,8 @@ let collect_occurs lam : occ_tbl =
6364
| Some r -> r.times <- r.times + 1
6465
| None -> (
6566
(* ident is not locally bound, therefore this is a use under a lambda
66-
or within a loop. Increase use count by 2 -- enough so
67-
that single-use optimizations will not apply. *)
67+
or within a loop. Mark it as captured so that single-use
68+
optimizations only apply when moving the value is safe. *)
6869
match Hash_ident.find_opt occ ident with
6970
| Some r -> absorb_info r {times = 1; captured = true}
7071
| None ->
@@ -82,8 +83,8 @@ let collect_occurs lam : occ_tbl =
8283
| Some r -> absorb_info r n
8384
| None -> (
8485
(* ident is not locally bound, therefore this is a use under a lambda
85-
or within a loop. Increase use count by 2 -- enough so
86-
that single-use optimizations will not apply. *)
86+
or within a loop. Mark it as captured so that single-use
87+
optimizations only apply when moving the value is safe. *)
8788
match Hash_ident.find_opt occ ident with
8889
| Some r -> absorb_info r {n with captured = true}
8990
| None ->

compiler/syntax/src/res_doc.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ val equal : t
4242
val trailing_comma : t
4343

4444
val will_break : t -> bool
45-
(** [will_break doc] checks whether [doc] contains forced line breaks.
45+
(** [will_break doc] checks whether [doc] contains forced line breaks. For each
46+
[custom_layout], it only inspects the first alternative.
4647
47-
Forced breaks are not propagated through [customLayout], because doing so
48+
Forced breaks are not propagated through [custom_layout], because doing so
4849
would always select the last layout the algorithm tries. Consumers can use
4950
[will_break] to detect a forced break in a custom layout and explicitly add
50-
[breakParent] to propagate it to the parent document. *)
51+
[break_parent] to propagate it to the parent document. *)
5152

5253
val to_string : width:int -> t -> string
5354
val debug : t -> unit [@@live]

0 commit comments

Comments
 (0)