Skip to content

Commit 54bcba1

Browse files
committed
Follow-up to binding renaming
1 parent 16911fc commit 54bcba1

File tree

7 files changed

+30
-33
lines changed

7 files changed

+30
-33
lines changed

src/provider.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ module Handler = struct
7878
aux
7979
;;
8080

81-
let make (type a) (implementations : a Binding.t list) : (a, _) t =
82-
let implementations =
83-
implementations
81+
let make (type a) (bindings : a Binding.t list) : (a, _) t =
82+
let bindings =
83+
bindings
8484
|> List.stable_sort ~compare:Binding.compare_by_uid
8585
|> dedup_sorted_keep_last ~compare:Binding.compare_by_uid
8686
in
87-
match implementations with
87+
match bindings with
8888
| [] -> [||]
8989
| hd :: _ ->
9090
(* We initialize the cache arbitrarily with the left most trait. *)
91-
Array.of_list (hd :: implementations)
91+
Array.of_list (hd :: bindings)
9292
;;
9393

9494
let same_trait_uids : type a b tags1 tags2. (a, tags1) t -> (b, tags2) t -> bool =
@@ -104,13 +104,13 @@ module Handler = struct
104104
let is_empty t = Array.length t = 0
105105
let cache t = if Array.length t = 0 then None else Some (Binding.uid t.(0))
106106

107-
let implementations t =
107+
let bindings t =
108108
match Array.to_list t with
109109
| [] -> []
110110
| _ :: tl -> tl
111111
;;
112112

113-
let extend t ~with_ = make (implementations t @ with_)
113+
let extend t ~with_ = make (bindings t @ with_)
114114

115115
let rec binary_search
116116
: type a implementation tags b.

src/provider.mli

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,21 @@ module Handler : sig
140140

141141
(** {1 Building handlers} *)
142142

143-
(** [make implementations] create a new handler from a list of bindings. It
144-
only keeps the last implementation supplied for each Trait, from left to
143+
(** [make bindings] create a new handler from a list of bindings. It only
144+
keeps the last implementation supplied for each Trait, from left to
145145
right. This means that the resulting handler will not contain any
146-
duplicate Traits, and the order of the implementations in the input list
147-
can affect its contents. *)
146+
duplicate Traits, and the order of the bindings in the input list can
147+
affect its contents. *)
148148
val make : 't Binding.t list -> ('t, _) t
149149

150-
(** [implementations t] returns a list of Trait implementations that the
151-
handler [t] supports. See also {!extend}. *)
152-
val implementations : ('t, _) t -> 't Binding.t list
150+
(** [bindings t] returns a list of bindings with the Traits that the handler
151+
[t] supports. See also {!extend}. *)
152+
val bindings : ('t, _) t -> 't Binding.t list
153153

154-
(** [extend t ~with_] extends the handler [t] and returns a new handler
155-
that includes both the original and additional implementations. The
156-
resulting handler only contains the last occurrence of each Trait,
157-
prioritizing the rightmost elements in the combined list
158-
[implementations t @ with_]. *)
154+
(** [extend t ~with_] extends the handler [t] and returns a new handler that
155+
includes both the original and additional bindings. The resulting
156+
handler only contains the last occurrence of each Trait, prioritizing
157+
the rightmost elements in the combined list [bindings t @ with_]. *)
159158
val extend : ('t, _) t -> with_:'t Binding.t list -> ('t, _) t
160159

161160
(** {1 Lookup}

test/providers/num_printer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ let handler : (unit, [ `Int_printer | `Float_printer ]) Provider.Handler.t =
1111
Provider.Handler.make
1212
(List.concat
1313
[ Interface.Int_printer.Provider_interface.make (module Impl)
14-
|> Provider.Handler.implementations
14+
|> Provider.Handler.bindings
1515
; Interface.Float_printer.Provider_interface.make (module Impl)
16-
|> Provider.Handler.implementations
16+
|> Provider.Handler.bindings
1717
])
1818
;;
1919

test/test__introspection.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
let print_implemented_traits (Provider.T { t = _; handler }) =
77
let info =
8-
List.map (Provider.Handler.implementations handler) ~f:(fun implementation ->
9-
[%sexp (Provider.Binding.info implementation : Provider.Trait.Info.t)])
8+
List.map (Provider.Handler.bindings handler) ~f:(fun binding ->
9+
[%sexp (Provider.Binding.info binding : Provider.Trait.Info.t)])
1010
in
1111
print_s [%sexp (info : Sexp.t list)]
1212
;;

test/test__lookup.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let provider () : _ t =
113113

114114
let%expect_test "lookup" =
115115
let (Provider.T { t = _; handler } as t) = provider () in
116-
print_s [%sexp (List.length (Provider.Handler.implementations handler) : int)];
116+
print_s [%sexp (List.length (Provider.Handler.bindings handler) : int)];
117117
[%expect {| 6 |}];
118118
List.iter Tag.all ~f:(fun tag -> print_tag t ~tag);
119119
[%expect {|
@@ -150,7 +150,7 @@ end
150150

151151
let uids (Provider.T { t = _; handler }) =
152152
handler
153-
|> Provider.Handler.implementations
153+
|> Provider.Handler.bindings
154154
|> List.map ~f:Provider.Binding.uid
155155
|> Set.of_list (module Uid)
156156
;;

test/test__make_interface.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let%expect_test "make interface" =
1313
let eio1 =
1414
Interface.Directory_reader.Provider_interface.make (module Providers.Eio_reader.Impl)
1515
in
16-
(match trait1, List.hd_exn (Provider.Handler.implementations eio1) with
16+
(match trait1, List.hd_exn (Provider.Handler.bindings eio1) with
1717
| T t, T t' ->
1818
require [%here] (Provider.Trait.same t.trait t'.trait);
1919
[%expect {||}];
@@ -42,7 +42,7 @@ let%expect_test "make interface" =
4242
require [%here] (not (Provider.Trait.same t1.trait t2.trait));
4343
[%expect {||}];
4444
());
45-
(match Provider.Handler.implementations eio1 with
45+
(match Provider.Handler.bindings eio1 with
4646
| [ c1 ] ->
4747
require_equal
4848
[%here]
@@ -53,15 +53,13 @@ let%expect_test "make interface" =
5353
| _ -> assert false);
5454
let empty = Provider.Handler.make [] in
5555
require [%here] (Provider.Handler.is_empty empty);
56-
require [%here] (List.is_empty (Provider.Handler.implementations empty));
56+
require [%here] (List.is_empty (Provider.Handler.bindings empty));
5757
let eio2 = Provider.Handler.make [ trait2 ] in
5858
require [%here] (not (Provider.Handler.is_empty eio2));
5959
require [%here] (not (Provider.Private.Handler.same_trait_uids empty eio2));
6060
[%expect {||}];
6161
let eio3 = Provider.Handler.make [ trait1; trait2 ] in
62-
let eio4 =
63-
Provider.Handler.extend eio1 ~with_:(Provider.Handler.implementations eio2)
64-
in
62+
let eio4 = Provider.Handler.extend eio1 ~with_:(Provider.Handler.bindings eio2) in
6563
require [%here] (Provider.Private.Handler.same_trait_uids eio3 eio4);
6664
[%expect {||}];
6765
()

test/test__override.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ end
2525
let%expect_test "override" =
2626
let print_implemented_traits (Provider.T { t = _; handler }) =
2727
let info =
28-
List.map (Provider.Handler.implementations handler) ~f:(fun implementation ->
29-
[%sexp (Provider.Binding.info implementation : Provider.Trait.Info.t)])
28+
List.map (Provider.Handler.bindings handler) ~f:(fun binding ->
29+
[%sexp (Provider.Binding.info binding : Provider.Trait.Info.t)])
3030
in
3131
print_s [%sexp (info : Sexp.t list)]
3232
in

0 commit comments

Comments
 (0)