Skip to content

Commit 331c167

Browse files
authored
Reformat middle_end/flambda2/ (#230)
1 parent e6fd786 commit 331c167

File tree

573 files changed

+48505
-46407
lines changed

Some content is hidden

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

573 files changed

+48505
-46407
lines changed

middle_end/flambda2/backend_intf/flambda2_backend_impl.ml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ module Compilation_unit = struct
2525
let of_flambda1_compilation_unit comp_unit =
2626
let ident = Flambda1_compilation_unit.get_persistent_ident comp_unit in
2727
let linkage_name =
28-
comp_unit
29-
|> Flambda1_compilation_unit.get_linkage_name
28+
comp_unit |> Flambda1_compilation_unit.get_linkage_name
3029
|> Flambda1_linkage_name.to_string
3130
|> Flambda2_compilenv_deps.Linkage_name.create
3231
in
@@ -43,30 +42,28 @@ let symbol_for_module_block id =
4342
Compilenv.unit_for_global id
4443
|> Compilation_unit.of_flambda1_compilation_unit
4544
in
46-
Symbol.unsafe_create
47-
comp_unit
45+
Symbol.unsafe_create comp_unit
4846
(Linkage_name.create (Compilenv.symbol_for_global id))
4947

5048
let symbol_for_global' ?comp_unit id =
51-
if Ident.global id && not (Ident.is_predef id) then
52-
symbol_for_module_block id
49+
if Ident.global id && not (Ident.is_predef id)
50+
then symbol_for_module_block id
5351
else
5452
let comp_unit =
5553
match comp_unit with
5654
| Some comp_unit -> comp_unit
5755
| None ->
58-
if Ident.is_predef id then Compilation_unit.predefined_exception ()
56+
if Ident.is_predef id
57+
then Compilation_unit.predefined_exception ()
5958
else Compilation_unit.get_current_exn ()
6059
in
61-
Symbol.unsafe_create
62-
comp_unit
60+
Symbol.unsafe_create comp_unit
6361
(Linkage_name.create (Compilenv.symbol_for_global id))
6462

6563
let find_predef_exn name =
6664
let matches ident = String.equal (Ident.name ident) name in
6765
match List.find matches Predef.all_predef_exns with
68-
| exception Not_found ->
69-
Misc.fatal_errorf "Cannot find predef exn '%s'" name
66+
| exception Not_found -> Misc.fatal_errorf "Cannot find predef exn '%s'" name
7067
| ident -> ident
7168

7269
let division_by_zero =
@@ -82,8 +79,9 @@ let invalid_argument =
8279
let all_predefined_exception_symbols =
8380
Predef.all_predef_exns
8481
|> List.map (fun ident ->
85-
symbol_for_global' ~comp_unit:(Compilation_unit.predefined_exception ())
86-
ident)
82+
symbol_for_global'
83+
~comp_unit:(Compilation_unit.predefined_exception ())
84+
ident)
8785
|> Symbol.Set.of_list
8886

8987
let () =
@@ -93,34 +91,37 @@ let () =
9391
let symbol_for_global' id : Symbol.t = symbol_for_global' id
9492

9593
let size_int = Arch.size_int
94+
9695
let big_endian = Arch.big_endian
9796

98-
let max_sensible_number_of_arguments =
99-
Proc.max_arguments_for_tailcalls - 1
97+
let max_sensible_number_of_arguments = Proc.max_arguments_for_tailcalls - 1
10098

10199
let set_global_info info = Compilenv.flambda2_set_export_info info
102100

103101
let get_global_info comp_unit =
104-
(* The Flambda simplifier should have returned the typing information
105-
for the predefined exception compilation unit before getting here. *)
102+
(* The Flambda simplifier should have returned the typing information for the
103+
predefined exception compilation unit before getting here. *)
106104
assert (not (Compilation_unit.is_predefined_exception comp_unit));
107-
if Compilation_unit.is_external_symbols comp_unit then None
105+
if Compilation_unit.is_external_symbols comp_unit
106+
then None
108107
else
109108
let id =
110-
(* CR mshinwell: Unsure how to construct this properly. Also see CR
111-
in Closure_conversion about the linkage names of module blocks *)
109+
(* CR mshinwell: Unsure how to construct this properly. Also see CR in
110+
Closure_conversion about the linkage names of module blocks *)
112111
Compilation_unit.get_persistent_ident comp_unit
113112
in
114113
match Compilenv.get_global_info' id with
115114
| None | Some (Flambda2 None) -> None
116115
| Some (Flambda2 (Some info)) -> Some info
117116
| Some (Clambda _) ->
118-
(* CR mshinwell: This should be a user error, not a fatal error.
119-
Same below. *)
120-
Misc.fatal_errorf "The .cmx file for unit %a was compiled with \
121-
the Closure middle-end, not Flambda 2, and cannot be loaded"
117+
(* CR mshinwell: This should be a user error, not a fatal error. Same
118+
below. *)
119+
Misc.fatal_errorf
120+
"The .cmx file for unit %a was compiled with the Closure middle-end, \
121+
not Flambda 2, and cannot be loaded"
122122
Compilation_unit.print comp_unit
123123
| Some (Flambda1 _) ->
124-
Misc.fatal_errorf "The .cmx file for unit %a was compiled with \
125-
the Flambda 1 middle-end, not Flambda 2, and cannot be loaded"
124+
Misc.fatal_errorf
125+
"The .cmx file for unit %a was compiled with the Flambda 1 middle-end, \
126+
not Flambda 2, and cannot be loaded"
126127
Compilation_unit.print comp_unit

middle_end/flambda2/basic/closure_id.ml

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@
1616

1717
[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1818

19-
type t = {
20-
compilation_unit : Compilation_unit.t;
21-
name : string;
22-
name_stamp : int;
23-
(** [name_stamp]s are unique within any given compilation unit. *)
24-
}
19+
type t =
20+
{ compilation_unit : Compilation_unit.t;
21+
name : string;
22+
name_stamp : int
23+
(** [name_stamp]s are unique within any given compilation unit. *)
24+
}
2525

2626
module Self = Container_types.Make (struct
2727
type nonrec t = t
2828

2929
let compare t1 t2 =
30-
if t1 == t2 then 0
30+
if t1 == t2
31+
then 0
3132
else
3233
let c = t1.name_stamp - t2.name_stamp in
33-
if c <> 0 then c
34+
if c <> 0
35+
then c
3436
else Compilation_unit.compare t1.compilation_unit t2.compilation_unit
3537

36-
let equal t1 t2 = (compare t1 t2 = 0)
38+
let equal t1 t2 = compare t1 t2 = 0
3739

38-
let hash t = t.name_stamp lxor (Compilation_unit.hash t.compilation_unit)
40+
let hash t = t.name_stamp lxor Compilation_unit.hash t.compilation_unit
3941

4042
let [@ocamlformat "disable"] print ppf t =
4143
Format.fprintf ppf "@<0>%s" (Flambda_colours.closure_element ());
@@ -51,14 +53,14 @@ module Self = Container_types.Make (struct
5153
end;
5254
Format.fprintf ppf "@<0>%s" (Flambda_colours.normal ())
5355

54-
let output chan t =
55-
print (Format.formatter_of_out_channel chan) t
56+
let output chan t = print (Format.formatter_of_out_channel chan) t
5657
end)
5758

5859
include Self
5960

60-
module Lmap = Lmap.Make(struct
61+
module Lmap = Lmap.Make (struct
6162
type nonrec t = t
63+
6264
include Self
6365
end)
6466

@@ -69,26 +71,20 @@ let get_next_stamp () =
6971
incr next_stamp;
7072
stamp
7173

72-
let in_compilation_unit t cu =
73-
Compilation_unit.equal cu t.compilation_unit
74+
let in_compilation_unit t cu = Compilation_unit.equal cu t.compilation_unit
7475

7576
let get_compilation_unit t = t.compilation_unit
7677

77-
let to_string t =
78-
t.name ^ "_" ^ (string_of_int t.name_stamp)
78+
let to_string t = t.name ^ "_" ^ string_of_int t.name_stamp
7979

80-
let name t =
81-
t.name
80+
let name t = t.name
8281

83-
let rename t =
84-
{ t with
85-
name_stamp = get_next_stamp ();
86-
}
82+
let rename t = { t with name_stamp = get_next_stamp () }
8783

8884
let unwrap t = Variable.create (to_string t)
8985

9086
let wrap compilation_unit var =
9187
{ compilation_unit;
9288
name = Variable.raw_name var;
93-
name_stamp = get_next_stamp ();
89+
name_stamp = get_next_stamp ()
9490
}

middle_end/flambda2/basic/closure_id.mli

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1818

19-
(* CR lwhite: "Closure_id" is quite a generic name. I wonder
20-
whether something like "Closure_label" would better capture that it is
21-
the label of a projection. *)
19+
(* CR lwhite: "Closure_id" is quite a generic name. I wonder whether something
20+
like "Closure_label" would better capture that it is the label of a
21+
projection. *)
2222

2323
(* CR mshinwell: update comment *)
2424
(** An identifier, unique across the whole program (not just one compilation
25-
unit), that identifies a closure within a particular set of closures
26-
(viz. [Project_closure]). *)
25+
unit), that identifies a closure within a particular set of closures (viz.
26+
[Project_closure]). *)
2727

2828
include Container_types.S
2929

@@ -34,6 +34,7 @@ val wrap : Compilation_unit.t -> Variable.t -> t
3434
val unwrap : t -> Variable.t
3535

3636
val in_compilation_unit : t -> Compilation_unit.t -> bool
37+
3738
val get_compilation_unit : t -> Compilation_unit.t
3839

3940
val to_string : t -> string

middle_end/flambda2/basic/closure_origin.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
include Closure_id
2020

2121
let create t = t
22+
2223
let rename f t = f t

middle_end/flambda2/basic/closure_origin.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ include Container_types.S
1919
val create : Closure_id.t -> t
2020

2121
val get_compilation_unit : t -> Compilation_unit.t
22+
2223
val rename : (Closure_id.t -> Closure_id.t) -> t -> t

middle_end/flambda2/basic/code_id.ml

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
(* *)
1515
(**************************************************************************)
1616

17-
(* CR mshinwell: Move to Reg_width_things so we can then do
18-
Code_id_or_symbol for free *)
17+
(* CR mshinwell: Move to Reg_width_things so we can then do Code_id_or_symbol
18+
for free *)
1919

2020
[@@@ocaml.warning "+a-30-40-41-42"]
2121

2222
module Id = Table_by_int_id.Id
2323

2424
module Code_id_data = struct
25-
type t = {
26-
compilation_unit : Compilation_unit.t;
27-
name : string;
28-
linkage_name : Linkage_name.t;
29-
}
25+
type t =
26+
{ compilation_unit : Compilation_unit.t;
27+
name : string;
28+
linkage_name : Linkage_name.t
29+
}
3030

3131
let flags = 0
3232

@@ -40,34 +40,39 @@ module Code_id_data = struct
4040
name
4141
Linkage_name.print linkage_name
4242

43-
let hash { compilation_unit; name = _; linkage_name; } =
44-
Hashtbl.hash (Compilation_unit.hash compilation_unit,
45-
Linkage_name.hash linkage_name)
43+
let hash { compilation_unit; name = _; linkage_name } =
44+
Hashtbl.hash
45+
(Compilation_unit.hash compilation_unit, Linkage_name.hash linkage_name)
4646

4747
let equal
48-
{ compilation_unit = compilation_unit1; name = _;
49-
linkage_name = linkage_name1; }
50-
{ compilation_unit = compilation_unit2; name = _;
51-
linkage_name = linkage_name2; }
52-
=
48+
{ compilation_unit = compilation_unit1;
49+
name = _;
50+
linkage_name = linkage_name1
51+
}
52+
{ compilation_unit = compilation_unit2;
53+
name = _;
54+
linkage_name = linkage_name2
55+
} =
5356
Linkage_name.equal linkage_name1 linkage_name2
54-
&& Compilation_unit.equal compilation_unit1 compilation_unit2
57+
&& Compilation_unit.equal compilation_unit1 compilation_unit2
5558
end
5659

5760
type t = Id.t
5861

5962
type exported = Code_id_data.t
6063

6164
module Table = Table_by_int_id.Make (Code_id_data)
65+
6266
let grand_table_of_code_ids = ref (Table.create ())
6367

64-
let initialise () =
65-
grand_table_of_code_ids := Table.create ()
68+
let initialise () = grand_table_of_code_ids := Table.create ()
6669

6770
let find_data t = Table.find !grand_table_of_code_ids t
6871

6972
let get_compilation_unit t = (find_data t).compilation_unit
73+
7074
let linkage_name t = (find_data t).linkage_name
75+
7176
let name t = (find_data t).name
7277

7378
let previous_name_stamp = ref (-1)
@@ -86,12 +91,7 @@ let create ~name compilation_unit =
8691
in
8792
Linkage_name.create (unit_linkage_name ^ "__" ^ unique_name ^ "_code")
8893
in
89-
let data : Code_id_data.t =
90-
{ compilation_unit;
91-
name;
92-
linkage_name;
93-
}
94-
in
94+
let data : Code_id_data.t = { compilation_unit; name; linkage_name } in
9595
Table.add !grand_table_of_code_ids data
9696

9797
let rename t = create ~name:(name t) (Compilation_unit.get_current_exn ())
@@ -105,7 +105,9 @@ let code_symbol t =
105105

106106
module T0 = struct
107107
let compare = Id.compare
108+
108109
let equal = Id.equal
110+
109111
let hash = Id.hash
110112

111113
let [@ocamlformat "disable"] print ppf t =
@@ -118,27 +120,35 @@ module T0 = struct
118120
end
119121

120122
include T0
123+
121124
module T = struct
122125
type nonrec t = t
126+
123127
include T0
124128
end
125129

126-
module Set = Patricia_tree.Make_set (struct let print = print end)
127-
module Map = Patricia_tree.Make_map (struct let print = print end) (Set)
130+
module Set = Patricia_tree.Make_set (struct
131+
let print = print
132+
end)
133+
134+
module Map =
135+
Patricia_tree.Make_map
136+
(struct
137+
let print = print
138+
end)
139+
(Set)
140+
128141
module Tbl = Container_types.Make_tbl (Numeric_types.Int) (Map)
129-
module Lmap = Lmap.Make(T)
142+
module Lmap = Lmap.Make (T)
130143

131144
let invert_map map =
132-
Map.fold (fun older newer invert_map ->
133-
Map.add newer older invert_map)
134-
map
135-
Map.empty
145+
Map.fold
146+
(fun older newer invert_map -> Map.add newer older invert_map)
147+
map Map.empty
136148

137149
let export t = find_data t
138150

139-
let import (data : exported) =
140-
Table.add !grand_table_of_code_ids data
151+
let import (data : exported) = Table.add !grand_table_of_code_ids data
141152

142153
let map_compilation_unit f (data : exported) : exported =
143-
{ data with compilation_unit = f data.compilation_unit;
144-
}
154+
{ data with compilation_unit = f data.compilation_unit }

0 commit comments

Comments
 (0)