Skip to content

Commit 059d0b4

Browse files
xclerclukemaurer
authored andcommitted
Rec_info part 1: aliases.
1 parent 45cca8d commit 059d0b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1736
-546
lines changed

.depend

+71-64
Large diffs are not rendered by default.

compilerlibs/Makefile.compilerlibs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ MIDDLE_END_FLAMBDA_COMPILENV_DEPS=\
189189
middle_end/flambda/compilenv_deps/flambda_colours.cmo \
190190
middle_end/flambda/compilenv_deps/compilation_unit.cmo \
191191
middle_end/flambda/compilenv_deps/rec_info.cmo \
192+
middle_end/flambda/compilenv_deps/coercion.cmo \
192193
middle_end/flambda/compilenv_deps/reg_width_things.cmo \
193194
middle_end/flambda/compilenv_deps/symbol.cmo \
194195
middle_end/flambda/compilenv_deps/variable.cmo \

middle_end/flambda/basic/simple.ml

+14-14
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ let pattern_match' t ~var ~symbol ~const =
5353

5454
let const_from_descr descr = const (RWC.of_descr descr)
5555

56-
let without_rec_info t = pattern_match t ~name ~const
56+
let without_coercion t = pattern_match t ~name ~const
5757

58-
let merge_rec_info t ~newer_rec_info =
58+
let compose_coercion t ~newer_coercion =
5959
if is_const t then None
6060
else
61-
match newer_rec_info with
61+
match newer_coercion with
6262
| None -> Some t
63-
| Some newer_rec_info ->
64-
let rec_info =
65-
match rec_info t with
66-
| None -> newer_rec_info
67-
| Some older_rec_info ->
68-
Rec_info.merge older_rec_info ~newer:newer_rec_info
63+
| Some newer_coercion ->
64+
let coercion =
65+
match coercion t with
66+
| None -> newer_coercion
67+
| Some older_coercion ->
68+
Coercion.compose older_coercion ~newer:newer_coercion
6969
in
70-
Some (with_rec_info (without_rec_info t) rec_info)
70+
Some (with_coercion (without_coercion t) coercion)
7171

7272
(* CR mshinwell: Make naming consistent with [Name] re. the option type *)
7373

74-
(* CR mshinwell: Careful that Rec_info doesn't get dropped using the
74+
(* CR mshinwell: Careful that Coercion doesn't get dropped using the
7575
following *)
7676

7777
let [@inline always] must_be_var t =
@@ -86,7 +86,7 @@ let [@inline always] must_be_name t =
8686
let to_name t =
8787
match must_be_name t with
8888
| None -> None
89-
| Some name -> Some (rec_info t, name)
89+
| Some name -> Some (coercion t, name)
9090

9191
let map_name t ~f =
9292
match must_be_name t with
@@ -118,9 +118,9 @@ let apply_name_permutation t perm =
118118
let new_name = Name_permutation.apply_name perm old_name in
119119
if old_name == new_name then t
120120
else
121-
match rec_info t with
121+
match coercion t with
122122
| None -> name new_name
123-
| Some rec_info -> with_rec_info (name new_name) rec_info
123+
| Some coercion -> with_coercion (name new_name) coercion
124124
in
125125
pattern_match t ~const:(fun _ -> t) ~name
126126

middle_end/flambda/basic/simple.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ include module type of struct include Reg_width_things.Simple end
2323

2424
include Contains_names.S with type t := t
2525

26-
val merge_rec_info : t -> newer_rec_info:Rec_info.t option -> t option
26+
val compose_coercion : t -> newer_coercion:Coercion.t option -> t option
2727

28-
val without_rec_info : t -> t
28+
val without_coercion : t -> t
2929

3030
val must_be_var : t -> Variable.t option
3131

@@ -64,7 +64,7 @@ val const_from_descr : Reg_width_const.Descr.t -> t
6464

6565
val map_name : t -> f:(Name.t -> Name.t) -> t
6666

67-
val to_name : t -> (Rec_info.t option * Name.t) option
67+
val to_name : t -> (Coercion.t option * Name.t) option
6868

6969
(* CR mshinwell: remove these next two? *)
7070
val map_var : t -> f:(Variable.t -> Variable.t) -> t

middle_end/flambda/cmx/ids_for_export.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let add_name t name =
7474

7575
let add_simple t simple =
7676
let simples =
77-
match Simple.rec_info simple with
77+
match Simple.coercion simple with
7878
| None -> t.simples
7979
| Some _ -> Simple.Set.add simple t.simples
8080
in
@@ -91,7 +91,7 @@ let add_continuation t continuation =
9191

9292
let from_simple simple =
9393
let simples =
94-
match Simple.rec_info simple with
94+
match Simple.coercion simple with
9595
| None ->
9696
(* This simple will not be in the grand_table_of_simples *)
9797
Simple.Set.empty
@@ -199,12 +199,12 @@ module Import_map = struct
199199
match Simple.Map.find simple t.simples with
200200
| simple -> simple
201201
| exception Not_found ->
202-
begin match Simple.rec_info simple with
202+
begin match Simple.coercion simple with
203203
| None ->
204204
Simple.pattern_match simple
205205
~name:(fun n -> Simple.name (name t n))
206206
~const:(fun c -> Simple.const (const t c))
207-
| Some _rec_info -> simple
207+
| Some _coercion -> simple
208208
end
209209

210210
let closure_var_is_used t var =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Mark Shinwell, Jane Street Europe *)
6+
(* *)
7+
(* Copyright 2019 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
type t = unit
16+
17+
let id = ()
18+
let is_id () = true
19+
let inverse () = ()
20+
let compose () ~newer:() = ()
21+
let print ppf () = Format.fprintf ppf "id"
22+
let equal () () = true
23+
let hash () = 0
24+
25+
let unroll_to () = None
26+
let depth () = 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Mark Shinwell, Jane Street Europe *)
6+
(* *)
7+
(* Copyright 2019 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
[@@@ocaml.warning "+a-4-30-40-41-42"]
16+
17+
type t
18+
19+
val id : t
20+
val is_id : t -> bool
21+
val inverse : t -> t
22+
val compose : t -> newer:t -> t
23+
val print : Format.formatter -> t -> unit
24+
val equal : t -> t -> bool
25+
val hash : t -> int
26+
27+
val unroll_to : t -> int option
28+
val depth : t -> int

middle_end/flambda/compilenv_deps/flambda_colours.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let continuation_annotation () = (C.fg_256 202) ^ (C.bg_256 237)
5555

5656
let name_abstraction () = C.fg_256 172
5757

58-
let rec_info () = C.fg_256 243
58+
let coercion () = C.fg_256 243
5959

6060
let error () = C.fg_256 160
6161

middle_end/flambda/compilenv_deps/flambda_colours.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ val continuation_annotation : unit -> string
5353

5454
val name_abstraction : unit -> string
5555

56-
val rec_info : unit -> string
56+
val coercion : unit -> string
5757

5858
val elide : unit -> string
5959

middle_end/flambda/compilenv_deps/rec_info.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(**************************************************************************)
1414

1515
[@@@ocaml.warning "+a-4-30-40-41-42"]
16-
16+
(*
1717
type t = {
1818
depth : int;
1919
unroll_to : int option;
@@ -64,3 +64,4 @@ let merge { depth = depth1; unroll_to = older_unroll_to; } ~newer =
6464
let initial = create ~depth:0 ~unroll_to:None
6565
6666
let is_initial t = equal t initial
67+
*)

middle_end/flambda/compilenv_deps/rec_info.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(**************************************************************************)
1414

1515
[@@@ocaml.warning "+a-4-30-40-41-42"]
16-
16+
(*
1717
type t
1818
1919
include Identifiable.S with type t := t
@@ -29,3 +29,4 @@ val merge : t -> newer:t -> t
2929
val initial : t
3030
3131
val is_initial : t -> bool
32+
*)

middle_end/flambda/compilenv_deps/reg_width_things.ml

+23-23
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,28 @@ end
221221

222222
module Simple_data = struct
223223
type t = {
224-
simple : Id.t; (* always without [Rec_info] *)
225-
rec_info : Rec_info.t;
224+
simple : Id.t; (* always without [Coercion] *)
225+
coercion : Coercion.t;
226226
}
227227

228228
let flags = simple_flags
229229

230-
let print ppf { simple = _; rec_info; } =
230+
let print ppf { simple = _; coercion; } =
231231
Format.fprintf ppf "@[<hov 1>\
232-
@[<hov 1>(rec_info@ %a)@]\
232+
@[<hov 1>(coercion@ %a)@]\
233233
@]"
234-
Rec_info.print rec_info
234+
Coercion.print coercion
235235

236-
let hash { simple; rec_info; } =
237-
Hashtbl.hash (Id.hash simple, Rec_info.hash rec_info)
236+
let hash { simple; coercion; } =
237+
Hashtbl.hash (Id.hash simple, Coercion.hash coercion)
238238

239239
let equal t1 t2 =
240240
if t1 == t2 then true
241241
else
242-
let { simple = simple1; rec_info = rec_info1; } = t1 in
243-
let { simple = simple2; rec_info = rec_info2; } = t2 in
242+
let { simple = simple1; coercion = coercion1; } = t1 in
243+
let { simple = simple2; coercion = coercion2; } = t2 in
244244
Id.equal simple1 simple2
245-
&& Rec_info.equal rec_info1 rec_info2
245+
&& Coercion.equal coercion1 coercion2
246246
end
247247

248248
module Const = struct
@@ -547,9 +547,9 @@ module Simple = struct
547547
in
548548
pattern_match t1 ~name ~const
549549

550-
let [@inline always] rec_info t =
550+
let [@inline always] coercion t =
551551
let flags = Id.flags t in
552-
if flags = simple_flags then Some ((find_data t).rec_info)
552+
if flags = simple_flags then Some ((find_data t).coercion)
553553
else None
554554

555555
module T0 = struct
@@ -563,15 +563,15 @@ module Simple = struct
563563
~name:(fun name -> Name.print ppf name)
564564
~const:(fun cst -> Const.print ppf cst)
565565
in
566-
match rec_info t with
566+
match coercion t with
567567
| None -> print ppf t
568-
| Some rec_info ->
568+
| Some coercion ->
569569
Format.fprintf ppf "@[<hov 1>\
570570
@[<hov 1>(simple@ %a)@] \
571-
@[<hov 1>(rec_info@ %a)@]\
571+
@[<hov 1>(coercion@ %a)@]\
572572
@]"
573573
print t
574-
Rec_info.print rec_info
574+
Coercion.print coercion
575575

576576
let output chan t =
577577
print (Format.formatter_of_out_channel chan) t
@@ -583,16 +583,16 @@ module Simple = struct
583583
include T0
584584
end
585585

586-
let with_rec_info t new_rec_info =
587-
if Rec_info.is_initial new_rec_info then t
586+
let with_coercion t new_coercion =
587+
if Coercion.is_id new_coercion then t
588588
else
589-
match rec_info t with
589+
match coercion t with
590590
| None ->
591-
let data : Simple_data.t = { simple = t; rec_info = new_rec_info; } in
591+
let data : Simple_data.t = { simple = t; coercion = new_coercion; } in
592592
Table.add !grand_table_of_simples data
593593
| Some _ ->
594-
Misc.fatal_errorf "Cannot add [Rec_info] to [Simple] %a that already \
595-
has [Rec_info]"
594+
Misc.fatal_errorf "Cannot add [Coercion] to [Simple] %a that already \
595+
has [Coercion]"
596596
print t
597597

598598
module Set = Patricia_tree.Make_set (struct let print = print end)
@@ -604,7 +604,7 @@ module Simple = struct
604604
let import map (data : exported) =
605605
let simple = map data.simple in
606606
let data : Simple_data.t =
607-
{ simple; rec_info = data.rec_info; }
607+
{ simple; coercion = data.coercion; }
608608
in
609609
Table.add !grand_table_of_simples data
610610

middle_end/flambda/compilenv_deps/reg_width_things.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ module Simple : sig
154154

155155
val const : Const.t -> t
156156

157-
val rec_info : t -> Rec_info.t option
157+
val coercion : t -> Coercion.t option
158158

159-
val with_rec_info : t -> Rec_info.t -> t
159+
val with_coercion : t -> Coercion.t -> t
160160

161161
val pattern_match
162162
: t
@@ -165,7 +165,7 @@ module Simple : sig
165165
-> 'a
166166

167167
(* [same s1 s2] returns true iff they represent the same name or const
168-
i.e. [same s (with_rec_info s rec_info)] returns true *)
168+
i.e. [same s (with_coercion s coercion)] returns true *)
169169
val same : t -> t -> bool
170170

171171
val export : t -> exported

middle_end/flambda/inlining/inlining_decision.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ end
218218
(* CR mshinwell: This parameter needs to be configurable *)
219219
let max_rec_depth = 1
220220

221-
let make_decision_for_call_site denv ~function_decl_rec_info
221+
let make_decision_for_call_site denv ~function_decl_coercion
222222
~apply_inlining_state (inline : Inline_attribute.t)
223223
: Call_site_decision.t =
224224
if (not (DE.can_inline denv)) then
@@ -227,9 +227,9 @@ let make_decision_for_call_site denv ~function_decl_rec_info
227227
match inline with
228228
| Never_inline -> Never_inline_attribute
229229
| Default_inline | Unroll _ | Always_inline | Hint_inline ->
230-
match Rec_info.unroll_to function_decl_rec_info with
230+
match Coercion.unroll_to function_decl_coercion with
231231
| Some unroll_to ->
232-
if Rec_info.depth function_decl_rec_info >= unroll_to then
232+
if Coercion.depth function_decl_coercion >= unroll_to then
233233
Unrolling_depth_exceeded
234234
else
235235
Inline { attribute = None; unroll_to = None; }
@@ -241,13 +241,13 @@ let make_decision_for_call_site denv ~function_decl_rec_info
241241
match inline with
242242
| Never_inline -> assert false
243243
| Default_inline ->
244-
if Rec_info.depth function_decl_rec_info >= max_rec_depth then
244+
if Coercion.depth function_decl_coercion >= max_rec_depth then
245245
Recursion_depth_exceeded
246246
else
247247
Inline { attribute = None; unroll_to = None; }
248248
| Unroll unroll_to ->
249249
let unroll_to =
250-
Rec_info.depth function_decl_rec_info + unroll_to
250+
Coercion.depth function_decl_coercion + unroll_to
251251
in
252252
Inline { attribute = Some Unroll; unroll_to = Some unroll_to; }
253253
| Always_inline | Hint_inline ->

middle_end/flambda/inlining/inlining_decision.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ end
6767

6868
val make_decision_for_call_site
6969
: Downwards_env.t
70-
-> function_decl_rec_info:Rec_info.t
70+
-> function_decl_coercion:Coercion.t
7171
-> apply_inlining_state:Inlining_state.t
7272
-> Inline_attribute.t
7373
-> Call_site_decision.t

0 commit comments

Comments
 (0)