Skip to content

Commit cb99b8b

Browse files
v0.18~preview.130.04+450
1 parent b6ea401 commit cb99b8b

File tree

107 files changed

+9085
-9117
lines changed

Some content is hidden

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

107 files changed

+9085
-9117
lines changed

composition_infix/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A single-module library for defining infix composition operators `<<`
2+
and `>>`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let ( >> ) f g x = g (f x)
2+
let ( << ) f g x = f (g x)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(** Infix composition operators.
2+
3+
- [ a |> (f >> g) = a |> f |> g ]
4+
- [ (f << g) a = f (g a) ] *)
5+
6+
val ( >> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
7+
val ( << ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c

composition_infix/src/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(library
2+
(name composition_infix)
3+
(public_name base.composition_infix)
4+
(preprocess no_preprocessing)
5+
(libraries))

lint/ppx_base_lint.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ let () =
181181
| { pstr_loc = loc; _ } :: _ as st ->
182182
(check (module_of_loc loc))#structure st;
183183
st)
184-
~intf:(function
185-
| [] -> []
186-
| { psig_loc = loc; _ } :: _ as sg ->
184+
~intf:(fun sg ->
185+
match sg.psg_items with
186+
| [] -> sg
187+
| { psig_loc = loc; _ } :: _ ->
187188
(check (module_of_loc loc))#signature sg;
188189
sg)
189190
;;

ppx/src/ppx_base_internal.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Ppxlib
33

44
module Specialize_polymorphic_compare = struct
55
let signature ~loc =
6-
[%sig:
6+
[%sigil:
77
[@@@ocaml.ppwarning "ppx_base_internal: intended only for use inside Base"]
88

99
external ( = ) : (t[@local_opt]) -> (t[@local_opt]) -> bool = "%equal"

src/array.mli

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
open! Import
44

5-
type 'a t = 'a array [@@deriving_inline compare ~localize, globalize, sexp, sexp_grammar]
5+
type 'a t = 'a array
6+
[@@deriving_inline compare ~localize, equal ~localize, globalize, sexp, sexp_grammar]
67

78
include Ppx_compare_lib.Comparable.S1 with type 'a t := 'a t
89
include Ppx_compare_lib.Comparable.S_local1 with type 'a t := 'a t
10+
include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
11+
include Ppx_compare_lib.Equal.S_local1 with type 'a t := 'a t
912

1013
val globalize : (local_ 'a -> 'a) -> local_ 'a t -> 'a t
1114

12-
include Sexplib0.Sexpable.S1 with type 'a t := 'a t
15+
include Sexplib0.Sexpable.S_any1 with type 'a t := 'a t
1316

1417
val t_sexp_grammar : 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t
1518

@@ -270,8 +273,6 @@ val sorted_copy : local_ 'a t -> compare:local_ ('a -> 'a -> int) -> 'a t
270273

271274
val last : 'a t -> 'a [@@deprecated "[since 2024-07] This was renamed to [last_exn]"]
272275
val last_exn : 'a t -> 'a
273-
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
274-
val equal__local : (local_ 'a -> local_ 'a -> bool) -> local_ 'a t -> local_ 'a t -> bool
275276

276277
(** The input array is copied internally so that future modifications of it do not change
277278
the sequence. *)

src/base.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,5 +758,3 @@ exception Not_found_s = Not_found_s
758758
program refers to at least one value directly in [Base]; referring to values in
759759
[Base.Bool], for example, is not sufficient. *)
760760
let () = Backtrace.initialize_module ()
761-
762-
module Caml = struct end [@@deprecated "[since 2023-01] use Stdlib instead of Caml"]

src/bool.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include Ppx_enumerate_lib.Enumerable.S with type t := t
99

1010
val globalize : local_ t -> t
1111

12-
include Sexplib0.Sexpable.S with type t := t
12+
include Sexplib0.Sexpable.S_any with type t := t
1313

1414
val t_sexp_grammar : t Sexplib0.Sexp_grammar.t
1515

src/bytes_intf.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module type Bytes = sig
2222

2323
val globalize : local_ t -> t
2424

25-
include Sexplib0.Sexpable.S with type t := t
25+
include Sexplib0.Sexpable.S_any with type t := t
2626

2727
val t_sexp_grammar : t Sexplib0.Sexp_grammar.t
2828

src/char.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include Ppx_enumerate_lib.Enumerable.S with type t := t
99

1010
val globalize : local_ t -> t
1111

12-
include Sexplib0.Sexpable.S with type t := t
12+
include Sexplib0.Sexpable.S_any with type t := t
1313

1414
val t_sexp_grammar : t Sexplib0.Sexp_grammar.t
1515

@@ -95,7 +95,7 @@ module Caseless : sig
9595
type nonrec t = t [@@deriving_inline hash, sexp, sexp_grammar]
9696

9797
include Ppx_hash_lib.Hashable.S with type t := t
98-
include Sexplib0.Sexpable.S with type t := t
98+
include Sexplib0.Sexpable.S_any with type t := t
9999

100100
val t_sexp_grammar : t Sexplib0.Sexp_grammar.t
101101

src/dictionary_immutable_intf.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ module Definitions = struct
299299
, 'phantom )
300300
transformer
301301

302+
(** Like [update]. Returns the new value. *)
303+
val update_and_return
304+
: ( ('key, 'data, 'phantom) t
305+
-> 'key key
306+
-> f:local_ ('data option -> 'data)
307+
-> 'data * ('key, 'data, 'phantom) t
308+
, 'key
309+
, 'data
310+
, 'phantom )
311+
transformer
312+
302313
(** Adds [data] to the existing key/value pair for [key]. Interprets a missing key as
303314
having an empty list. *)
304315
val add_multi

src/dictionary_mutable_intf.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ module Definitions = struct
393393
-> ('key, 'c, 'phantom) t * ('key, 'd, 'phantom) t
394394

395395
(** Merges two dictionaries by fully traversing both. Not suitable for efficiently
396-
merging lists of dictionaries. See [merge_into] instead. *)
396+
merging lists of dictionaries. See [merge_into] instead.
397+
398+
If the two dictionaries differ in their implementations, e.g. of [hash] or
399+
[compare] functions, those from the first argument are preferred. *)
397400
val merge
398401
: ( ('key, 'data1, 'phantom) t
399402
-> ('key, 'data2, 'phantom) t

src/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(foreign_stubs
1818
(language c)
1919
(names bytes_stubs exn_stubs float_stubs int_math_stubs hash_stubs
20-
obj_stubs am_testing)
20+
obj_stubs string_stubs am_testing)
2121
(flags
2222
:standard
2323
-D_LARGEFILE64_SOURCE

src/either.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let equal eq1 eq2 t1 t2 =
4444
| First _, Second _ | Second _, First _ -> false
4545
;;
4646

47-
let local_equal eq1 eq2 t1 t2 =
47+
let equal__local eq1 eq2 t1 t2 =
4848
match t1, t2 with
4949
| First x, First y -> eq1 x y
5050
| Second x, Second y -> eq2 x y

src/either_intf.ml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ module type Either = sig
3434
type ('f, 's) t = ('f, 's) Either0.t =
3535
| First of 'f
3636
| Second of 's
37-
[@@deriving_inline compare ~localize, hash, sexp, sexp_grammar]
37+
[@@deriving_inline compare ~localize, equal ~localize, hash, sexp, sexp_grammar]
3838

3939
include Ppx_compare_lib.Comparable.S2 with type ('f, 's) t := ('f, 's) t
4040
include Ppx_compare_lib.Comparable.S_local2 with type ('f, 's) t := ('f, 's) t
41+
include Ppx_compare_lib.Equal.S2 with type ('f, 's) t := ('f, 's) t
42+
include Ppx_compare_lib.Equal.S_local2 with type ('f, 's) t := ('f, 's) t
4143
include Ppx_hash_lib.Hashable.S2 with type ('f, 's) t := ('f, 's) t
4244
include Sexplib0.Sexpable.S2 with type ('f, 's) t := ('f, 's) t
4345

@@ -61,15 +63,6 @@ module type Either = sig
6163
-> second:local_ ('b -> 'd)
6264
-> ('c, 'd) t
6365

64-
val equal : ('f -> 'f -> bool) -> ('s -> 's -> bool) -> ('f, 's) t -> ('f, 's) t -> bool
65-
66-
val local_equal
67-
: (local_ 'f -> local_ 'f -> bool)
68-
-> (local_ 's -> local_ 's -> bool)
69-
-> local_ ('f, 's) t
70-
-> local_ ('f, 's) t
71-
-> bool
72-
7366
module type Focused = Focused
7467

7568
module First : Focused with type ('a, 'b) t = ('a, 'b) t

src/exn.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let () =
3434

3535
[@@@end]
3636

37-
exception Sexp of Sexp.t
37+
exception Sexp of Sexp.t Lazy.t
3838

3939
(* We install a custom exn-converter rather than use:
4040
@@ -47,13 +47,14 @@ exception Sexp of Sexp.t
4747
to eliminate the extra wrapping of [(Sexp ...)]. *)
4848
let () =
4949
Sexplib0.Sexp_conv.Exn_converter.add [%extension_constructor Sexp] (function
50-
| Sexp t -> t
50+
| Sexp t -> Lazy.force t
5151
| _ ->
5252
(* Reaching this branch indicates a bug in sexplib. *)
5353
assert false)
5454
;;
5555

56-
let create_s sexp = Sexp sexp
56+
let create_s sexp = Sexp (Lazy.from_val sexp)
57+
let create_s_lazy lazy_sexp = Sexp lazy_sexp
5758

5859
let raise_with_original_backtrace t backtrace =
5960
Stdlib.Printexc.raise_with_backtrace t backtrace

src/exn.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ exception Reraised of string * t
2727
particular exn constructor doesn't matter. *)
2828
val create_s : Sexp.t -> t
2929

30+
(** [create_s_lazy lazy_sexp] is like [create_s], but takes a lazily generated sexp. *)
31+
val create_s_lazy : Sexp.t Lazy.t -> t
32+
3033
(** Same as [raise], except that the backtrace is not recorded. *)
3134
val raise_without_backtrace : t -> _
3235

src/float.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ val to_int64 : local_ t -> int64
127127
v}
128128
129129
For convenience, versions of these functions with the [dir] argument hard-coded are
130-
provided. If you are writing performance-critical code you should use the
131-
versions with the hard-coded arguments (e.g. [iround_down_exn]). The [_exn] ones
130+
provided. If you are writing performance-critical code you should use the
131+
versions with the hard-coded arguments (e.g. [iround_down_exn]). The [_exn] ones
132132
are the fastest.
133133
134134
The following properties hold:
@@ -700,7 +700,7 @@ val ieee_mantissa : local_ t -> Int63.t
700700
module Terse : sig
701701
type nonrec t = t [@@deriving_inline sexp, sexp_grammar]
702702

703-
include Sexplib0.Sexpable.S with type t := t
703+
include Sexplib0.Sexpable.S_any with type t := t
704704

705705
val t_sexp_grammar : t Sexplib0.Sexp_grammar.t
706706

src/fn.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ open! Import
22

33
let const c _ = c
44

5-
external ignore : (_[@local_opt]) -> unit = "%ignore"
5+
external ignore : ('a : any). ('a[@local_opt]) -> unit = "%ignore" [@@layout_poly]
66

77
(* this has the same behavior as [Stdlib.ignore] *)
88

@@ -17,8 +17,14 @@ let forever f =
1717
| e -> e
1818
;;
1919

20-
external id : ('a[@local_opt]) -> ('a[@local_opt]) = "%identity"
21-
external ( |> ) : 'a -> (('a -> 'b)[@local_opt]) -> 'b = "%revapply"
20+
external id : ('a : any). ('a[@local_opt]) -> ('a[@local_opt]) = "%identity"
21+
[@@layout_poly]
22+
23+
external ( |> )
24+
: ('a : any) ('b : any).
25+
'a -> (('a -> 'b)[@local_opt]) -> 'b
26+
= "%revapply"
27+
[@@layout_poly]
2228

2329
(* The typical use case for these functions is to pass in functional arguments and get
2430
functions as a result. *)

src/fn.mli

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ open! Import
66
77
See {{:https://github.com/janestreet/ppx_pipebang} ppx_pipebang} for
88
further details. *)
9-
external ( |> ) : 'a -> (('a -> 'b)[@local_opt]) -> 'b = "%revapply"
9+
external ( |> )
10+
: ('a : any) ('b : any).
11+
'a -> (('a -> 'b)[@local_opt]) -> 'b
12+
= "%revapply"
13+
[@@layout_poly]
1014

1115
(** Produces a function that just returns its first argument. *)
1216
val const : 'a -> _ -> 'a
1317

1418
(** Ignores its argument and returns [()]. *)
15-
external ignore : (_[@local_opt]) -> unit = "%ignore"
19+
external ignore : ('a : any). ('a[@local_opt]) -> unit = "%ignore"
20+
[@@layout_poly]
1621

1722
(** Negates a boolean function. *)
1823
val non : ('a -> bool) -> 'a -> bool
@@ -27,7 +32,8 @@ val apply_n_times : n:int -> local_ ('a -> 'a) -> 'a -> 'a
2732
(** The identity function.
2833
2934
See also: {!Sys.opaque_identity}. *)
30-
external id : ('a[@local_opt]) -> ('a[@local_opt]) = "%identity"
35+
external id : ('a : any). ('a[@local_opt]) -> ('a[@local_opt]) = "%identity"
36+
[@@layout_poly]
3137

3238
(** [compose f g x] is [f (g x)]. *)
3339
val compose : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c

src/hash_set.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Accessors = struct
1414
let hashable = hashable
1515
let clear = Hashtbl.clear
1616
let length = Hashtbl.length
17+
let capacity = Hashtbl.capacity
1718
let mem = Hashtbl.mem
1819
let is_empty t = Hashtbl.is_empty t
1920

src/hash_set_intf.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module type Accessors = sig
4040
val diff : 'a t -> 'a t -> 'a t
4141
val of_hashtbl_keys : ('a, _) Hashtbl.t -> 'a t
4242
val to_hashtbl : 'key t -> f:local_ ('key -> 'data) -> ('key, 'data) Hashtbl.t
43+
val capacity : _ t -> int
4344
end
4445

4546
type ('key, 'z) create_options = ('key, unit, 'z) Hashtbl_intf.create_options
@@ -172,7 +173,7 @@ module type Hash_set = sig
172173
module Poly : sig
173174
type nonrec 'a t = 'a t [@@deriving_inline sexp, sexp_grammar]
174175

175-
include Sexplib0.Sexpable.S1 with type 'a t := 'a t
176+
include Sexplib0.Sexpable.S_any1 with type 'a t := 'a t
176177

177178
val t_sexp_grammar : 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t
178179

src/hashtbl.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,9 @@ let merge =
638638
let maybe_set t ~key ~f d =
639639
match f ~key d with
640640
| None -> ()
641-
| Some v -> set t ~key ~data:v
641+
| Some v -> add_exn t ~key ~data:v
642642
in
643643
fun t_left t_right ~f ->
644-
if not (Hashable.equal t_left.hashable t_right.hashable)
645-
then invalid_arg "Hashtbl.merge: different 'hashable' values";
646644
let new_t =
647645
create
648646
~growth_allowed:t_left.growth_allowed

src/indexed_container.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ struct
152152
let filteri t ~f =
153153
filter_mapi t ~f:(fun i x -> if f i x then Some x else None) [@nontail]
154154
;;
155+
156+
let partition_mapi t ~f =
157+
let array = Array.mapi (to_array t) ~f in
158+
let xs =
159+
Array.fold_right array ~init:[] ~f:(fun either acc ->
160+
match (either : _ Either0.t) with
161+
| First x -> x :: acc
162+
| Second _ -> acc)
163+
in
164+
let ys =
165+
Array.fold_right array ~init:[] ~f:(fun either acc ->
166+
match (either : _ Either0.t) with
167+
| First _ -> acc
168+
| Second x -> x :: acc)
169+
in
170+
of_list xs, of_list ys
171+
;;
172+
173+
let partitioni_tf t ~f =
174+
partition_mapi t ~f:(fun i x -> if f i x then First x else Second x) [@nontail]
175+
;;
155176
end
156177

157178
module Make_with_creators (T : Make_with_creators_arg) = struct

0 commit comments

Comments
 (0)