Skip to content

Commit 97e6f09

Browse files
committed
Upgrade to ocamlformat 0.27.0
1 parent 2d68931 commit 97e6f09

16 files changed

+139
-135
lines changed

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
profile = default
2-
version = 0.26.2
2+
version = 0.27.0
33

44
exp-grouping=preserve

src/kcas/kcas.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ type 'a state = {
149149
}
150150

151151
(** Tagged GADT for representing both the state of MCAS operations and of the
152-
transaction log or splay [tree]. Different subsets of this GADT are used in
153-
different contexts. See the [root], [tree], and [which] existentials. *)
152+
transaction log or splay [tree]. Different subsets of this GADT are used in
153+
different contexts. See the [root], [tree], and [which] existentials. *)
154154
and _ tdt =
155155
| Before : [> `Before ] tdt
156156
(** The result has been determined to be the [before] value.
@@ -164,15 +164,15 @@ and _ tdt =
164164
mutable rot : rot;
165165
(** [rot] is for Root or Tree.
166166
167-
This field must be first, see [root_as_atomic] and
168-
[tree_as_ref]. *)
167+
This field must be first, see [root_as_atomic] and [tree_as_ref].
168+
*)
169169
timeout : [ `Set | `Unset ] Timeout.t;
170170
mutable mode : Mode.t;
171171
mutable validate_counter : int;
172172
mutable post_commit : Action.t;
173173
}
174174
-> [> `Xt ] tdt
175-
(** The result might not yet have been determined. The [root] either says
175+
(** The result might not yet have been determined. The [root] either says
176176
which it is or points to the root of the transaction log or [tree].
177177
178178
Note that if/when local/stack allocation mode becomes available in

src/kcas/kcas.mli

Lines changed: 63 additions & 66 deletions
Large diffs are not rendered by default.

src/kcas_data/accumulator_intf.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module type Ops = sig
33
type ('x, 'fn) fn
44

55
val add : ('x, t -> int -> unit) fn
6-
(** [add a n] increments the value of the accumulator [a] by [n]. [add]
6+
(** [add a n] increments the value of the accumulator [a] by [n]. [add]
77
operations can be performed scalably in parallel. *)
88

99
val incr : ('x, t -> unit) fn

src/kcas_data/bits.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ val max_0 : int -> int
22
(** [max_0 n] is equivalent to [Int.max 0 n]. *)
33

44
val is_pow_2 : int -> bool
5-
(** [is_pow_2 n] determines [n] is zero or of the form [1 lsl i] for some
6-
[i]. *)
5+
(** [is_pow_2 n] determines [n] is zero or of the form [1 lsl i] for some [i].
6+
*)
77

88
val ceil_pow_2_minus_1 : int -> int
99
val ceil_pow_2 : int -> int

src/kcas_data/dllist.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ open Kcas
1212
- The [length] operation is not provided.
1313
- The [set] operation is not provided.
1414
15-
A non-compositional {!take_all} operation is added for {{:
16-
https://en.wikipedia.org/wiki/Privatization_(computer_programming)}privatization}
15+
A non-compositional {!take_all} operation is added for
16+
{{:https://en.wikipedia.org/wiki/Privatization_(computer_programming)}privatization}
1717
as well as conversions to a list of nodes ({!to_nodes_l} and {!to_nodes_r})
1818
and to a list of values ({!to_list_l} and {!to_list_r}).
1919
@@ -46,7 +46,7 @@ val create : unit -> 'a t
4646

4747
val create_node : 'a -> 'a node
4848
(** [create_node value] creates a new doubly-linked list node that is not in any
49-
list. The node can then e.g. be added to a list using {!move_l} or
49+
list. The node can then e.g. be added to a list using {!move_l} or
5050
{!move_r}. *)
5151

5252
val get : 'a node -> 'a

src/kcas_data/dllist_intf.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ module type Ops = sig
5555
(** {3 Moving all nodes between lists} *)
5656

5757
val swap : ('x, 'a t -> 'a t -> unit) fn
58-
(** [swap l1 l2] exchanges the nodes of the doubly-linked lists [l1] and
59-
[l2]. *)
58+
(** [swap l1 l2] exchanges the nodes of the doubly-linked lists [l1] and [l2].
59+
*)
6060

6161
val transfer_l : ('x, 'a t -> 'a t -> unit) fn
6262
(** [transfer_l l1 l2] removes all nodes of [l1] and adds them to the left of

src/kcas_data/hashtbl.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ let filter_map_inplace fn t =
495495
Kcas.Xt.commit { tx };
496496
Kcas.Xt.commit { tx = Xt.perform_pending t } |> ignore;
497497
(* Fenceless is safe as commit above has fences. *)
498-
match Loc.fenceless_get raised with Done -> () | exn -> raise exn
498+
match Loc.fenceless_get raised with
499+
| Done -> ()
500+
| exn -> raise exn
499501

500502
let stats t =
501503
let length = ref 0 in

src/kcas_data/hashtbl.mli

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ open Kcas
55
The interface provides a subset of the OCaml [Stdlib.Hashtbl] module with
66
some changes:
77
8-
- The functorial interface of the [Stdlib.Hashtbl] is not provided.
9-
Instead the constructor functions, {!create}, {!of_seq}, and {!rebuild},
10-
take an optional [HashedType] module as an argument. By default {!create}
11-
returns a randomized hash table.
8+
- The functorial interface of the [Stdlib.Hashtbl] is not provided. Instead
9+
the constructor functions, {!create}, {!of_seq}, and {!rebuild}, take an
10+
optional [HashedType] module as an argument. By default {!create} returns
11+
a randomized hash table.
1212
- The [add_seq] and [replace_seq] operations are not provided at all.
1313
- Non-instance specific operations related to randomization (e.g.
1414
[randomize], [is_randomized]) are not provided.
@@ -20,13 +20,13 @@ open Kcas
2020
{!fold}, and {!stats} are not provided.
2121
2222
Please note that the design is intentionally based on [Stdlib.Hashtbl] and
23-
copies its semantics as accurately as possible. Some of the operations come
23+
copies its semantics as accurately as possible. Some of the operations come
2424
with warnings.
2525
26-
The hash table implementation is designed to avoid starvation. Read-only
27-
accesses can generally proceed in parallel without interference. Write
26+
The hash table implementation is designed to avoid starvation. Read-only
27+
accesses can generally proceed in parallel without interference. Write
2828
accesses that do not change the number of bindings can proceed in parallel
29-
as long as they hit different internal buckets. Write accesses that change
29+
as long as they hit different internal buckets. Write accesses that change
3030
the number of bindings use a scalable {!Accumulator} and only make
3131
infrequent random checks to determine whether the hash table should be
3232
resized. *)
@@ -80,10 +80,10 @@ val of_seq :
8080
('k * 'v) Seq.t ->
8181
('k, 'v) t
8282
(** [of_seq assoc] creates a new hash table from the given association sequence
83-
[assoc]. The associations are added in the same order as they appear in the
83+
[assoc]. The associations are added in the same order as they appear in the
8484
sequence, using {!replace}, which means that if two pairs have the same key,
85-
only the latest one will appear in the table. See {!create} for the
86-
optional arguments.
85+
only the latest one will appear in the table. See {!create} for the optional
86+
arguments.
8787
8888
⚠️ [of_seq (to_seq t)] does not necessarily copy the bindings of a hash table
8989
correctly. *)
@@ -109,7 +109,7 @@ val find : ('k, 'v) t -> 'k -> 'v
109109

110110
val to_seq : ('k, 'v) t -> ('k * 'v) Seq.t
111111
(** [to_seq t] takes a snapshot of the keys and values in the hash table and
112-
returns them as an association sequence. Bindings of each individual key
112+
returns them as an association sequence. Bindings of each individual key
113113
appear in the sequence in reverse order of their introduction.
114114
115115
⚠️ [of_seq (to_seq t)] does not necessarily copy the bindings of a hash table
@@ -134,12 +134,12 @@ val rebuild :
134134
(** [rebuild t] returns a copy of the given hash table [t] optionally rehashing
135135
all of the bindings.
136136
137-
See {!create} for descriptions of the optional arguments. Unlike {!create},
137+
See {!create} for descriptions of the optional arguments. Unlike {!create},
138138
[rebuild] uses the given hash table [t] as a template to get defaults for
139139
the optional arguments. *)
140140

141141
val copy : ('k, 'v) t -> ('k, 'v) t
142-
(** [copy t] is equivalent to [rebuild t]. In other words, the returned hash
142+
(** [copy t] is equivalent to [rebuild t]. In other words, the returned hash
143143
table uses the same {!hashed_type} (and other parameters) as the given hash
144144
table [t]. *)
145145

@@ -148,15 +148,16 @@ val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit
148148

149149
val filter_map_inplace : ('k -> 'v -> 'v option) -> ('k, 'v) t -> unit
150150
(** [filter_map_inplace f t] applies [f] to all bindings in the hash table [t]
151-
and updates each binding depending on the result of [f]. If [f] returns
152-
[None], the binding is discarded. If [f] returns [Some new_value], the
151+
and updates each binding depending on the result of [f]. If [f] returns
152+
[None], the binding is discarded. If [f] returns [Some new_value], the
153153
binding is updated to associate the key to the [new_value].
154154
155155
⚠️ The given [f] may be called multiple times for the same bindings from
156156
multiple domains in parallel. *)
157157

158158
val fold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
159-
(** [fold f t a] is equivalent to [Seq.fold_left (fun a (k, v) -> f k v a) a (to_seq t)]. *)
159+
(** [fold f t a] is equivalent to
160+
[Seq.fold_left (fun a (k, v) -> f k v a) a (to_seq t)]. *)
160161

161162
val stats : ('a, 'b) t -> Stdlib.Hashtbl.statistics
162163
(** [stats t] returns statistics about the hash table [t]. *)

src/kcas_data/kcas_data.mli

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
explicitly documented.
2323
2424
The main feature of these data structure implementations is their
25-
compositionality. If your application does not need compositionality, then
25+
compositionality. If your application does not need compositionality, then
2626
other concurrency and parallelism safe data structure libraries may
2727
potentially offer better performance.
2828
2929
But why should you care about composability?
3030
3131
As an example, consider the implementation of a least-recently-used (LRU)
32-
cache or a bounded associative map, but first, let's open the libraries
33-
for convenience:
32+
cache or a bounded associative map, but first, let's open the libraries for
33+
convenience:
3434
3535
{[
3636
open Kcas
@@ -41,35 +41,38 @@
4141
and a doubly-linked list and keep track of the amount of space in the cache:
4242
4343
{[
44-
type ('k, 'v) cache =
45-
{ space: int Loc.t;
46-
table: ('k, 'k Dllist.node * 'v) Hashtbl.t;
47-
order: 'k Dllist.t }
44+
type ('k, 'v) cache = {
45+
space : int Loc.t;
46+
table : ('k, 'k Dllist.node * 'v) Hashtbl.t;
47+
order : 'k Dllist.t;
48+
}
4849
]}
4950
5051
On a cache lookup the doubly-linked list node corresponding to the accessed
5152
key is moved to the left end of the list:
5253
5354
{[
54-
let get_opt {table; order; _} key =
55+
let get_opt { table; order; _ } key =
5556
Hashtbl.find_opt table key
5657
|> Option.map @@ fun (node, datum) ->
57-
Dllist.move_l node order; datum
58+
Dllist.move_l node order;
59+
datum
5860
]}
5961
6062
On a cache update, in case of overflow, the association corresponding to the
6163
node on the right end of the list is dropped:
6264
6365
{[
64-
let set {table; order; space; _} key datum =
66+
let set { table; order; space; _ } key datum =
6567
let node =
6668
match Hashtbl.find_opt table key with
6769
| None ->
68-
if 0 = Loc.update space (fun n -> max 0 (n-1))
69-
then Dllist.take_opt_r order
70-
|> Option.iter (Hashtbl.remove table);
71-
Dllist.add_l key order
72-
| Some (node, _) -> Dllist.move_l node order; node
70+
if 0 = Loc.update space (fun n -> max 0 (n - 1)) then
71+
Dllist.take_opt_r order |> Option.iter (Hashtbl.remove table);
72+
Dllist.add_l key order
73+
| Some (node, _) ->
74+
Dllist.move_l node order;
75+
node
7376
in
7477
Hashtbl.replace table key (node, datum)
7578
]}
@@ -98,33 +101,34 @@
98101
operations. For the [get_opt] operation we end up with
99102
100103
{[
101-
let get_opt ~xt {table; order; _} key =
104+
let get_opt ~xt { table; order; _ } key =
102105
Hashtbl.Xt.find_opt ~xt table key
103106
|> Option.map @@ fun (node, datum) ->
104-
Dllist.Xt.move_l ~xt node order; datum
107+
Dllist.Xt.move_l ~xt node order;
108+
datum
105109
]}
106110
107111
and the [set] operation is just as easy to convert to a transactional
108-
version. One way to think about transactions is that they give us back the
112+
version. One way to think about transactions is that they give us back the
109113
ability to compose programs such as the above. *)
110114

111115
(** {1 [Stdlib] style data structures}
112116
113117
The data structures in this section are designed to closely mimic the
114-
corresponding unsynchronized data structures in the OCaml [Stdlib]. Each of
118+
corresponding unsynchronized data structures in the OCaml [Stdlib]. Each of
115119
these provide a non-compositional, but concurrency and parallelism safe,
116-
interface that is close to the [Stdlib] equivalent. Additionally,
120+
interface that is close to the [Stdlib] equivalent. Additionally,
117121
compositional transactional interfaces are provided for some operations.
118122
119123
These implementations will use more space than the corresponding [Stdlib]
120-
data structures. Performance, when accessed concurrently, should be
124+
data structures. Performance, when accessed concurrently, should be
121125
competitive or superior compared to naïve locking. *)
122126

123127
module Hashtbl = Hashtbl
124128
module Queue = Queue
125129
module Stack = Stack
126130

127-
(** {1 Communication and synchronization primitives} *)
131+
(** {1 Communication and synchronization primitives} *)
128132

129133
module Mvar = Mvar
130134
module Promise = Promise

src/kcas_data/mvar.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ open Kcas
66
with blocking semantics on both {!take} and {!put}.
77
88
{b NOTE}: The current implementation is not guaranteed to be fair or
9-
scalable. In other words, when multiple producers block on {!put} or
9+
scalable. In other words, when multiple producers block on {!put} or
1010
multiple consumers block on {!take} the operations are not queued and it is
1111
possible for a particular producer or consumer to starve. *)
1212

1313
(** {1 Common interface} *)
1414

1515
type !'a t
16-
(** The type of a synchronizing variable that may contain a value of type
17-
['a]. *)
16+
(** The type of a synchronizing variable that may contain a value of type ['a].
17+
*)
1818

1919
val create : 'a option -> 'a t
2020
(** [create x_opt] returns a new synchronizing variable that will either be

src/kcas_data/promise.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Kcas
1818
(** {1 Common interface} *)
1919

2020
type !+'a t
21-
(** The type of a promise of a value of type ['a]. *)
21+
(** The type of a promise of a value of type ['a]. *)
2222

2323
type !-'a u
2424
(** The type of a resolver of a value of type ['a]. *)

src/kcas_data/promise_intf.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module type Ops = sig
77

88
val resolve : ('x, 'a u -> 'a -> unit) fn
99
(** [resolve u v] resolves the promise corresponding to the resolver [u] to
10-
the value [v]. Any awaiters of the corresponding promise are then
10+
the value [v]. Any awaiters of the corresponding promise are then
1111
unblocked. *)
1212

1313
val await : ('x, 'a t -> 'a) blocking_fn
@@ -25,7 +25,8 @@ module type Ops = sig
2525
(** {2 Result promises} *)
2626

2727
val await_exn : ('x, 'a or_exn -> 'a) blocking_fn
28-
(** [await_exn t] is equivalent to [match await t with v -> v | exception e -> raise e]. *)
28+
(** [await_exn t] is equivalent to
29+
[match await t with v -> v | exception e -> raise e]. *)
2930

3031
val resolve_ok : ('x, ('a, 'b) result u -> 'a -> unit) fn
3132
(** [resolve_ok u v] is equivalent to [resolve u (Ok v)]. *)

src/kcas_data/queue.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ open Kcas
33
(** First-In First-Out (FIFO) queue.
44
55
The interface provides a subset of the OCaml [Stdlib.Queue] module.
6-
[transfer] and [add_seq] are not provided at all. Compositional versions of
6+
[transfer] and [add_seq] are not provided at all. Compositional versions of
77
{!iter}, {!fold}, {!peek}, {!top}, and {!take} are not provided.
88
99
The queue implementation is designed to avoid contention between a producer
10-
and a consumer operating concurrently. The implementation is also designed
11-
to avoid starvation. Performance in most concurrent use cases should be
10+
and a consumer operating concurrently. The implementation is also designed
11+
to avoid starvation. Performance in most concurrent use cases should be
1212
superior to what can be achieved with one or two locks. *)
1313

1414
(** {1 Common interface} *)

src/kcas_data/stack.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Kcas
33
(** Last-In First-Out (LIFO) stack.
44
55
The interface provides a subset of the OCaml [Stdlib.Stack] module.
6-
[add_seq] is not provided at all. Compositional versions of {!iter},
6+
[add_seq] is not provided at all. Compositional versions of {!iter},
77
{!fold}, {!pop}, and {!top} are not provided.
88
99
The implementation is essentially a

test/kcas_data/linearizable_chaining_example.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
(** This demonstrates an approach to composing non-blocking linearizable data
22
structures inspired by the paper
33
4-
Concurrent Size
5-
by Gal Sela and Erez Petrank
6-
https://arxiv.org/pdf/2209.07100.pdf
4+
Concurrent Size by Gal Sela and Erez Petrank
5+
https://arxiv.org/pdf/2209.07100.pdf
76
87
First a [Hashtbl] is implemented that allows [idempotent_add] and
9-
[idempotent_remove] operations to be specified. The hash table makes sure
8+
[idempotent_remove] operations to be specified. The hash table makes sure
109
that any operations that might witness the addition or the removal of a key
1110
will perform those operations before returning.
1211
1312
Then a [Hashtbl_with_order] is implemented on top of the [Hashtbl] by
1413
specifying the [idempotent_add] and [idempotent_remove] operation such that
1514
they update a lock-free doubly-linked list to maintain a list of the keys in
16-
the hash table in insertion [order]. In other words, we composed a hash
15+
the hash table in insertion [order]. In other words, we composed a hash
1716
table with a doubly-linked list, both lock-free and linearizable, resulting
1817
in a lock-free linearizable hash table that maintains the insertion order.
1918

0 commit comments

Comments
 (0)