Skip to content

Commit 5682fff

Browse files
authored
Merge pull request #1570 from stan-dev/ocamlformat-version
Update `ocamlformat` to 0.28
2 parents 4f8977e + f46a118 commit 5682fff

File tree

102 files changed

+1556
-1749
lines changed

Some content is hidden

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

102 files changed

+1556
-1749
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# usage: git config blame.ignoreRevsFile .git-blame-ignore-revs
22
# generated with: git log --grep "[fF]ormat.*ocamlformat" --format="format:%H # %s"
33

4+
e34fdeb4050139946d0409b09489cf91f5502ad7 # Format with ocamlformat 0.28.1
45
2030298f84a95a78953866bf46bc6564f9faee1b # Migrate to Core and format with ocamlformat 0.26.1
56
845f34e165e16c95596fd48da67bb987bbbe2446 # Format with ocamlformat 0.19.0
67
9c75bd01015157bae5a133417acf1f7e8af71887 # reformatting using ocamlformat 0.9

.ocamlformat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
version=0.26.1
1+
version=0.28.1
2+
ocaml-version=4.14
23
# loosely re-creates the now-removed "compact" profile
34
break-separators=before
45
break-before-in=auto
@@ -11,3 +12,5 @@ space-around-lists=false
1112
space-around-records=false
1213
space-around-variants=false
1314
sequence-blank-line=compact
15+
parse-docstrings=true
16+
wrap-comments=true

docs/dependencies.mld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ build requirements) with [scripts/setup_dev_env.sh]. Versioning of these depende
3535
strict, though some (like ocamlformat) are used to ensure a standard format across developers
3636
and must use the same version.
3737

38-
- ocamlformat 0.26.1
38+
- ocamlformat 0.28.1
3939
- merlin
4040
- ocaml-lsp-server
4141
- utop

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
(ocamlformat
3030
(and
3131
:with-test
32-
(= 0.26.1)))
32+
(= 0.28.1)))
3333
(bisect_ppx :with-test)
3434
(merlin :with-test)
3535
(utop :with-test)

scripts/install_dev_deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

33
# Merlin, utop, ocp-indent, ocamlformat, and patdiff are all for developer assistance
4-
opam pin -y ocamlformat 0.26.1 --no-action
5-
opam install -y ocamlformat.0.26.1 bisect_ppx landmarks-ppx merlin ocaml-lsp-server utop ocp-indent patdiff odoc
4+
opam pin -y ocamlformat 0.28.1 --no-action
5+
opam install -y ocamlformat.0.28.1 bisect_ppx landmarks-ppx merlin ocaml-lsp-server utop ocp-indent patdiff odoc

src/analysis_and_optimization/Dataflow_types.ml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,20 @@ open Core
44
(* Basic datatypes *)
55
(***********************************)
66

7-
(**
8-
A label is a unique identifier for a node in the dataflow/dependency graph, and
9-
often corresponds to one node in the Mir.
10-
*)
7+
(** A label is a unique identifier for a node in the dataflow/dependency graph,
8+
and often corresponds to one node in the Mir. *)
119
type label = int [@@deriving sexp]
1210

13-
(**
14-
Representation of an expression that can be assigned to. This should also be able to
15-
represent indexed variables, but we don't support that yet.
16-
*)
11+
(** Representation of an expression that can be assigned to. This should also be
12+
able to represent indexed variables, but we don't support that yet. *)
1713
type vexpr = VVar of string [@@deriving sexp]
1814

19-
(**
20-
A 'reaching definition' (or reaching_defn or RD) statement (v, l) says that the variable
21-
v could have been affected at the label l.
22-
*)
15+
(** A 'reaching definition' (or reaching_defn or RD) statement (v, l) says that
16+
the variable v could have been affected at the label l. *)
2317
type reaching_defn = vexpr * label [@@deriving sexp]
2418

2519
(** The most recently nested control flow (block start, if/then, or loop)
2620
27-
This isn't included in the traversal_state because it only flows downward through the
28-
tree, not across and up like everything else
29-
*)
21+
This isn't included in the traversal_state because it only flows downward
22+
through the tree, not across and up like everything else *)
3023
type cf_state = label

src/analysis_and_optimization/Dataflow_utils.ml

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ let union_maps_left (m1 : ('a, 'b) Map.Poly.t) (m2 : ('a, 'b) Map.Poly.t) :
1313
| `Both (v1, _) -> Some v1 in
1414
Map.Poly.merge m1 m2 ~f
1515

16-
(**
17-
Merge two maps whose values are sets, and union the sets when there's a collision.
18-
*)
16+
(** Merge two maps whose values are sets, and union the sets when there's a
17+
collision. *)
1918
let merge_set_maps m1 m2 =
2019
let merge_map_elems ~key:_ es =
2120
match es with
@@ -24,10 +23,8 @@ let merge_set_maps m1 m2 =
2423
| `Both (e1, e2) -> Some (Set.union e1 e2) in
2524
Map.Poly.merge ~f:merge_map_elems m1 m2
2625

27-
(**
28-
Like a forward traversal, but branches accumulate two different states that are
29-
recombined with join.
30-
*)
26+
(** Like a forward traversal, but branches accumulate two different states that
27+
are recombined with join. *)
3128
let branching_traverse_statement stmt ~join ~init ~f =
3229
Stmt.Pattern.(
3330
match stmt with
@@ -40,15 +37,12 @@ let branching_traverse_statement stmt ~join ~init ~f =
4037
(join s' s'', IfElse (pred, c, Some c')))
4138
| _ as s -> fwd_traverse_statement s ~init ~f)
4239

43-
(** Like a branching traversal, but doesn't return an updated statement.
44-
*)
40+
(** Like a branching traversal, but doesn't return an updated statement. *)
4541
let branching_fold_statement stmt ~join ~init ~f =
4642
fst
4743
(branching_traverse_statement stmt ~join ~init ~f:(fun s a -> (f s a, ())))
4844

49-
(**
50-
See interface file
51-
*)
45+
(** See interface file *)
5246
let build_statement_map extract metadata stmt =
5347
let rec build_statement_map_rec next_label map stmt =
5448
let this_label = next_label in
@@ -66,38 +60,37 @@ let build_statement_map extract metadata stmt =
6660
(* TODO: this currently does not seem to be labelling inside function bodies.
6761
Could we also do that? *)
6862

69-
(**
70-
See interface file
71-
*)
63+
(** See interface file *)
7264
let rec build_recursive_statement rebuild statement_map label =
7365
let stmt_ints, meta = Map.Poly.find_exn statement_map label in
7466
let build_stmt = build_recursive_statement rebuild statement_map in
7567
let stmt = Stmt.Pattern.map Fn.id build_stmt stmt_ints in
7668
rebuild stmt meta
7769

78-
(** Represents the state required to build control flow information during an MIR
79-
traversal, where
80-
* breaks is the set of Breaks seen since the beginning of their loop
81-
* continues is the set of Continues seen since the beginning of their loop
82-
* returns is the set of Returns seen since the beginning of their function definition
83-
* exits is the set of nodes that could have been the last one to execute before this
84-
node
85-
*)
70+
(** Represents the state required to build control flow information during an
71+
MIR traversal, where
72+
- breaks is the set of Breaks seen since the beginning of their loop
73+
- continues is the set of Continues seen since the beginning of their loop
74+
- returns is the set of Returns seen since the beginning of their function
75+
definition
76+
- exits is the set of nodes that could have been the last one to execute
77+
before this node *)
8678
type cf_state =
8779
{ breaks: label Set.Poly.t
8880
; continues: label Set.Poly.t
8981
; returns: label Set.Poly.t
9082
; exits: label Set.Poly.t }
9183

92-
(** Represents the control flow information at each node in the control graph, where
93-
* predecessors points to the nodes which could have executed before this node
94-
* parents points to the adjacent nodes which directly influence the execution of this
95-
node
96-
*)
84+
(** Represents the control flow information at each node in the control graph,
85+
where
86+
- predecessors points to the nodes which could have executed before this
87+
node
88+
- parents points to the adjacent nodes which directly influence the
89+
execution of this node *)
9790
type cf_edges = {predecessors: label Set.Poly.t; parents: label Set.Poly.t}
9891

99-
(** Join the state of a controlflow traversal across different branches of execution such
100-
as over if/else branch. *)
92+
(** Join the state of a controlflow traversal across different branches of
93+
execution such as over if/else branch. *)
10194
let join_cf_states (state1 : cf_state) (state2 : cf_state) : cf_state =
10295
{ breaks= Set.union state1.breaks state2.breaks
10396
; continues= Set.union state1.continues state2.continues
@@ -112,11 +105,10 @@ let is_ctrl_flow pattern =
112105
| For _ -> true
113106
| _ -> false
114107

115-
(**
116-
Simultaneously builds the controlflow parent graph, the predecessor graph and the exit
117-
set of a statement. It's advantageous to build them together because they both rely on
118-
some of the same Break, Continue and Return bookkeeping.
119-
*)
108+
(** Simultaneously builds the controlflow parent graph, the predecessor graph
109+
and the exit set of a statement. It's advantageous to build them together
110+
because they both rely on some of the same Break, Continue and Return
111+
bookkeeping. *)
120112
let build_cf_graphs ?(flatten_loops = false) ?(blocks_after_body = true)
121113
statement_map =
122114
let rec build_cf_graph_rec (cf_parent : label option)
@@ -138,28 +130,31 @@ let build_cf_graphs ?(flatten_loops = false) ?(blocks_after_body = true)
138130
branching_fold_statement stmt ~join
139131
~init:({in_state with exits= substmt_preds}, in_map)
140132
~f:(build_cf_graph_rec child_cf) in
141-
(* If the statement is a loop, we need to include the loop body exits as predecessors
142-
of the loop *)
133+
(* If the statement is a loop, we need to include the loop body exits as
134+
predecessors of the loop *)
143135
let substmt_state, predecessors =
144136
match stmt with
145137
| For _ | While _ ->
146138
(* Loop statements are preceded by:
139+
147140
1. The statements that come before the loop
141+
148142
2. The natural exit points of the loop body
149-
3. Continue statements in the loop body
150-
This comment mangling brought to you by the autoformatter
151-
*)
143+
144+
3. Continue statements in the loop body This comment mangling
145+
brought to you by the autoformatter *)
152146
let loop_predecessors =
153147
Set.Poly.union_list
154148
[ (*1*) in_state.exits; (*2*) substmt_state_unlooped.exits; (*3*)
155149
Set.diff substmt_state_unlooped.continues in_state.continues ]
156150
in
157151
(* Loop exits are:
158-
1. The loop node itself, since the last action of a typical loop execution is
159-
to check if there are any iterations remaining
160-
2. Break statements in the loop body, since broken loops don't execute the
161-
loop statement
162-
*)
152+
153+
1. The loop node itself, since the last action of a typical loop
154+
execution is to check if there are any iterations remaining
155+
156+
2. Break statements in the loop body, since broken loops don't
157+
execute the loop statement *)
163158
let loop_exits =
164159
if flatten_loops then substmt_state_unlooped.exits
165160
else
@@ -168,16 +163,16 @@ let build_cf_graphs ?(flatten_loops = false) ?(blocks_after_body = true)
168163
Set.diff substmt_state_unlooped.breaks in_state.breaks ] in
169164
({substmt_state_unlooped with exits= loop_exits}, loop_predecessors)
170165
| (Block _ | Profile _) when blocks_after_body ->
171-
(* Block statements are preceded by the natural exit points of the block
172-
body *)
166+
(* Block statements are preceded by the natural exit points of the
167+
block body *)
173168
let block_predecessors = substmt_state_unlooped.exits in
174169
(* Block exits are just the block node *)
175170
let block_exits = Set.Poly.singleton label in
176171
({substmt_state_unlooped with exits= block_exits}, block_predecessors)
177172
| _ -> (substmt_state_unlooped, in_state.exits) in
178-
(* Some statements interact with the break/return/continue states
179-
E.g., loops nullify breaks and continues in their body, but are still affected by
180-
breaks and input continues*)
173+
(* Some statements interact with the break/return/continue states E.g.,
174+
loops nullify breaks and continues in their body, but are still affected
175+
by breaks and input continues *)
181176
let breaks_out, returns_out, continues_out, extra_cf_deps =
182177
match stmt with
183178
| Break ->

src/analysis_and_optimization/Dataflow_utils.mli

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,45 @@ val build_cf_graphs :
1313
-> label Set.Poly.t
1414
* (label, label Set.Poly.t) Map.Poly.t
1515
* (label, label Set.Poly.t) Map.Poly.t
16-
(**
17-
Simultaneously builds the controlflow parent graph, the predecessor graph and the exit
18-
set of a statement. It's advantageous to build them together because they both rely on
19-
some of the same Break, Continue and Return bookkeeping.
16+
(** Simultaneously builds the controlflow parent graph, the predecessor graph
17+
and the exit set of a statement. It's advantageous to build them together
18+
because they both rely on some of the same Break, Continue and Return
19+
bookkeeping.
2020
21-
Takes a statement map and returns the triple:
22-
(exit set, predecessor graph, controlflow parent graph)
23-
where
24-
* (exit set, predecessor graph) is the return value of build_predecessor_graph
25-
* (controlflow parent graph) is the return value of build_cf_graph
26-
*)
21+
Takes a statement map and returns the triple: (exit set, predecessor graph,
22+
controlflow parent graph) where
23+
- (exit set, predecessor graph) is the return value of
24+
build_predecessor_graph
25+
- (controlflow parent graph) is the return value of build_cf_graph *)
2726

2827
val build_cf_graph :
2928
(label, (Expr.Typed.t, label) Stmt.Pattern.t * 'm) Map.Poly.t
3029
-> (label, label Set.Poly.t) Map.Poly.t
31-
(**
32-
Building the controlflow graph requires a traversal with state that includes continues,
33-
breaks, returns and the controlflow graph accumulator. The traversal should be a
34-
branching traversal with set unions rather than a forward traversal because continue
35-
and return statements shouldn't affect other branches of execution.
36-
*)
30+
(** Building the controlflow graph requires a traversal with state that includes
31+
continues, breaks, returns and the controlflow graph accumulator. The
32+
traversal should be a branching traversal with set unions rather than a
33+
forward traversal because continue and return statements shouldn't affect
34+
other branches of execution. *)
3735

3836
val build_predecessor_graph :
3937
?flatten_loops:bool
4038
-> ?blocks_after_body:bool
4139
-> (label, (Expr.Typed.t, label) Stmt.Pattern.t * 'm) Map.Poly.t
4240
-> label Set.Poly.t * (label, label Set.Poly.t) Map.Poly.t
43-
(**
44-
Building the predecessor graph requires a traversal with state that includes the
45-
current previous nodes and the predecessor graph accumulator. Special cases are made
46-
for loops, because they should include the body exits as predecessors to the body, and
47-
they should include loop predecessors in their exit sets. I'm not sure if the single
48-
re-traversal of the loop body is sufficient or this requires finding a fixed-point.
49-
*)
41+
(** Building the predecessor graph requires a traversal with state that includes
42+
the current previous nodes and the predecessor graph accumulator. Special
43+
cases are made for loops, because they should include the body exits as
44+
predecessors to the body, and they should include loop predecessors in their
45+
exit sets. I'm not sure if the single re-traversal of the loop body is
46+
sufficient or this requires finding a fixed-point. *)
5047

5148
val build_recursive_statement :
5249
(('e, 's) Stmt.Pattern.t -> 'm -> 's)
5350
-> (label, ('e, label) Stmt.Pattern.t * 'm) Map.Poly.t
5451
-> label
5552
-> 's
56-
(**
57-
Build a fixed-point data type representation of a statement given a label-map
58-
representation.
59-
*)
53+
(** Build a fixed-point data type representation of a statement given a
54+
label-map representation. *)
6055

6156
val is_ctrl_flow : ('a, 'b) Stmt.Pattern.t -> bool
6257
(** Check if the statement controls the execution of its substatements. *)
@@ -65,18 +60,16 @@ val merge_set_maps :
6560
('a, 'b Set.Poly.t) Map.Poly.t
6661
-> ('a, 'b Set.Poly.t) Map.Poly.t
6762
-> ('a, 'b Set.Poly.t) Map.Poly.t
68-
(**
69-
Merge two maps whose values are sets, and union the sets when there's a collision.
70-
*)
63+
(** Merge two maps whose values are sets, and union the sets when there's a
64+
collision. *)
7165

7266
val build_statement_map :
7367
('s -> ('e, 's) Stmt.Pattern.t)
7468
-> ('s -> 'm)
7569
-> 's
7670
-> (label, ('e, label) Stmt.Pattern.t * 'm) Map.Poly.t
77-
(**
78-
The statement map is built by traversing substatements recursively to replace
79-
substatements with their labels while building up the substatements' statement maps.
80-
Then, the result is the union of the substatement maps with this statement's singleton
81-
pair, which is expressed in terms of the new label-containing statement.
82-
*)
71+
(** The statement map is built by traversing substatements recursively to
72+
replace substatements with their labels while building up the substatements'
73+
statement maps. Then, the result is the union of the substatement maps with
74+
this statement's singleton pair, which is expressed in terms of the new
75+
label-containing statement. *)

src/analysis_and_optimization/Debug_data_generation.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ let gen_corr_cholesky_unwrapped n =
195195

196196
let gen_corr_cholesky n = wrap_real_mat (gen_corr_cholesky_unwrapped n)
197197

198-
(* let gen_identity_matrix m n =
199-
let id_mat = gen_diag_mat (List.init ~f:(fun _ -> 1.) n) in
200-
if m <= n then wrap_real_mat id_mat else pad_mat id_mat m n *)
201-
202198
let gen_cov_matrix n =
203199
let cov = gen_cov_unwrapped n in
204200
wrap_real_mat cov
@@ -327,7 +323,7 @@ let json_to_mir (decls : (Expr.Typed.t SizedType.t * 'a * string) list)
327323
| `Assoc l, UTuple ts ->
328324
l
329325
|> List.sort ~compare:(fun (x, _) (y, _) ->
330-
Int.compare (int_of_string x) (int_of_string y))
326+
Int.compare (int_of_string x) (int_of_string y))
331327
|> List.map2_exn ~f:(fun typ_ (_, json) -> create_expr typ_ json) ts
332328
|> Option.all
333329
|> Option.map ~f:(fun l -> Expr.Helpers.tuple_expr l)
@@ -339,7 +335,7 @@ let json_to_mir (decls : (Expr.Typed.t SizedType.t * 'a * string) list)
339335
List.filter_map decls ~f:(fun (st, _, name) ->
340336
Map.find map name
341337
|> Option.bind ~f:(fun value ->
342-
create_expr (SizedType.to_unsized st) value)
338+
create_expr (SizedType.to_unsized st) value)
343339
|> Option.map ~f:(fun value -> (name, value)))
344340
|> Map.Poly.of_alist_reduce ~f:Fn.const
345341

0 commit comments

Comments
 (0)