From 82942afbcee2e180d590ebf7578288f0fef76f3e Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 28 Feb 2024 01:16:15 +0000 Subject: [PATCH] Add OCaml 5.2 support (#1128) --- src/batArray.mli | 2 ++ src/batBigarray.ml | 2 ++ src/batBigarray.mli | 2 ++ src/batDigest.mli | 23 +++++++++++++++++++++++ src/batGc.mli | 5 ++++- src/batPrintexc.mli | 2 ++ src/batRandom.ml | 6 +++++- src/batRandom.mli | 12 ++++++++++++ src/batUnix.mli | 15 +++++++++++++++ src/batteries_compattest.ml | 6 +++++- 10 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/batArray.mli b/src/batArray.mli index b14b393fe..d2f065224 100644 --- a/src/batArray.mli +++ b/src/batArray.mli @@ -96,6 +96,8 @@ external make : int -> 'a -> 'a array = "caml_make_vect" @since 2.3.0 *) +##V>=5.2##val init_matrix : int -> int -> (int -> int -> 'a) -> 'a array array + ##V>=4.07##val of_seq: 'a Seq.t -> 'a array ##V>=4.07##val to_seq: 'a array -> 'a Seq.t ##V>=4.07##val to_seqi: 'a array -> (int * 'a) Seq.t diff --git a/src/batBigarray.ml b/src/batBigarray.ml index aae051b08..662d247e5 100644 --- a/src/batBigarray.ml +++ b/src/batBigarray.ml @@ -29,6 +29,7 @@ module A = struct include BatArray include BatArray.Labels end module _ = (BatBigarray : module type of Bigarray) because of the somewhat strange interpretation of strengthening in (module type of), we need to explicitly equate each type with its constructor *) +##V>=5.2##type float16_elt = Bigarray.float16_elt = Float16_elt type float32_elt = Bigarray.float32_elt ##V>=4.2## = Float32_elt type float64_elt = Bigarray.float64_elt @@ -68,6 +69,7 @@ type ('a, 'b) kind = ('a,'b) Bigarray.kind ##V>=4.2## | Complex32 : (Complex.t, complex32_elt) kind ##V>=4.2## | Complex64 : (Complex.t, complex64_elt) kind ##V>=4.2## | Char : (char, int8_unsigned_elt) kind +##V>=5.2## | Float16 : (float, float16_elt) kind (* this type is local to Batteries, it is meant to make it easier to port code diff --git a/src/batBigarray.mli b/src/batBigarray.mli index 730ec2fcd..5f12c1d65 100644 --- a/src/batBigarray.mli +++ b/src/batBigarray.mli @@ -83,6 +83,7 @@ module _ = (BatBigarray : module type of Bigarray) because of the somewhat strange interpretation of strengthening in (module type of), we need to explicitly equate each type with its constructor *) +##V>=5.2##type float16_elt = Bigarray.float16_elt = Float16_elt type float32_elt = Bigarray.float32_elt ##V>=4.2## = Float32_elt type float64_elt = Bigarray.float64_elt @@ -122,6 +123,7 @@ type ('a, 'b) kind = ('a,'b) Bigarray.kind ##V>=4.2## | Complex32 : (Complex.t, complex32_elt) kind ##V>=4.2## | Complex64 : (Complex.t, complex64_elt) kind ##V>=4.2## | Char : (char, int8_unsigned_elt) kind (**) +##V>=5.2## | Float16 : (float, float16_elt) kind (** To each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the big array or read back from it. This type is not necessarily the same diff --git a/src/batDigest.mli b/src/batDigest.mli index cd9186ca8..13ce62cfc 100644 --- a/src/batDigest.mli +++ b/src/batDigest.mli @@ -101,3 +101,26 @@ val compare : t -> t -> int val equal : t -> t -> bool (** The equal function for digests. @since 2.5.0 *) + +##V>=5.2##val of_hex : string -> t + +##V>=5.2##module type S = sig +##V>=5.2## type t = string +##V>=5.2## val hash_length : int +##V>=5.2## val compare : t -> t -> int +##V>=5.2## val equal : t -> t -> bool +##V>=5.2## val string : string -> t +##V>=5.2## val bytes : bytes -> t +##V>=5.2## val substring : string -> int -> int -> t +##V>=5.2## val subbytes : bytes -> int -> int -> t +##V>=5.2## val channel : Stdlib.in_channel -> int -> t +##V>=5.2## val file : string -> t +##V>=5.2## val output : Stdlib.out_channel -> t -> unit +##V>=5.2## val input : Stdlib.in_channel -> t +##V>=5.2## val to_hex : t -> string +##V>=5.2## val of_hex : string -> t +##V>=5.2##end +##V>=5.2##module BLAKE128 : S +##V>=5.2##module BLAKE256 : S +##V>=5.2##module BLAKE512 : S +##V>=5.2##module MD5 : S diff --git a/src/batGc.mli b/src/batGc.mli index 95efe174f..ce7dce595 100644 --- a/src/batGc.mli +++ b/src/batGc.mli @@ -430,6 +430,7 @@ val delete_alarm : alarm -> unit ##V>=4.11## notice. *) ##V>=4.11##module Memprof : ##V>=4.11## sig +##V>=5.2## type t = Gc.Memprof.t ##V>=4.12## type allocation_source = Gc.Memprof.allocation_source = Normal | Marshal | Custom ##V>=4.11## type allocation = Gc.Memprof.allocation = private ##V>=4.11## { n_samples : int; @@ -476,7 +477,8 @@ val delete_alarm : alarm -> unit ##V>=4.11## sampling_rate:float -> ##V>=4.11## ?callstack_size:int -> ##V>=4.11## ('minor, 'major) tracker -> -##V>=4.11## unit +##V>=4.11####V<5.2## unit +##V>=5.2## t ##V>=4.11## (** Start the sampling with the given parameters. Fails if ##V>=4.11## sampling is already active. ##V>=4.11## @@ -515,4 +517,5 @@ val delete_alarm : alarm -> unit ##V>=4.11## ##V>=4.11## Calling [stop] when a callback is running can lead to ##V>=4.11## callbacks not being called even though some events happened. *) +##V>=5.2## val discard : t -> unit ##V>=4.11##end diff --git a/src/batPrintexc.mli b/src/batPrintexc.mli index 0ef92bb64..54334bd3e 100644 --- a/src/batPrintexc.mli +++ b/src/batPrintexc.mli @@ -238,6 +238,8 @@ val print : _ BatInnerIO.output -> exn -> unit ##V>=4.2## line_number : int; ##V>=4.2## start_char : int; ##V>=4.2## end_char : int; +##V>=5.2## end_line : int; +##V>=5.2## end_col : int; ##V>=4.2##} ##V>=4.2##(** The type of location information found in backtraces. [start_char] ##V>=4.2## and [end_char] are positions relative to the beginning of the diff --git a/src/batRandom.ml b/src/batRandom.ml index 681f9a5d1..f77befdc2 100644 --- a/src/batRandom.ml +++ b/src/batRandom.ml @@ -28,9 +28,13 @@ let self_init = Random.self_init let bits = Random.bits let int = Random.int ##V>=4.13##let full_int = Random.full_int +##V>=5.2##let int_in_range = Random.int_in_range let int32 = Random.int32 +##V>=5.2##let int32_in_range = Random.int32_in_range let int64 = Random.int64 +##V>=5.2##let int64_in_range = Random.int64_in_range let nativeint = Random.nativeint +##V>=5.2##let nativeint_in_range = Random.nativeint_in_range let float = Random.float let bool = Random.bool let char () = Char.chr (int 256) @@ -70,7 +74,7 @@ struct ##V>=5## external next: t -> (int64[@unboxed]) ##V>=5## = "caml_lxm_next" "caml_lxm_next_unboxed" [@@noalloc] - + end let enum_bits () = BatEnum.from bits diff --git a/src/batRandom.mli b/src/batRandom.mli index 020fc1fd9..c320ccd10 100644 --- a/src/batRandom.mli +++ b/src/batRandom.mli @@ -65,14 +65,20 @@ val int : int -> int ##V>=4.13## ##V>=4.13## @since 3.4.0 and OCaml 4.13.0 *) +##V>=5.2##val int_in_range : min:int -> max:int -> int + val int32 : Int32.t -> Int32.t (** [Random.int32 bound] returns a random integer between 0 (inclusive) and [bound] (exclusive). [bound] must be greater than 0. *) +##V>=5.2##val int32_in_range : min:int32 -> max:int32 -> int32 + val nativeint : Nativeint.t -> Nativeint.t (** [Random.nativeint bound] returns a random integer between 0 (inclusive) and [bound] (exclusive). [bound] must be greater than 0. *) +##V>=5.2##val nativeint_in_range : min:nativeint -> max:nativeint -> nativeint + val int64 : Int64.t -> Int64.t (** [Random.int64 bound] returns a random integer between 0 (inclusive) and [bound] (exclusive). [bound] must be greater than 0. *) @@ -83,6 +89,8 @@ val float : float -> float negative, the result is negative or zero. If [bound] is 0, the result is 0. *) +##V>=5.2##val int64_in_range : min:int64 -> max:int64 -> int64 + val bool : unit -> bool (** [Random.bool ()] returns [true] or [false] with probability 0.5 each. *) @@ -184,9 +192,13 @@ module State : sig val bits : t -> int val int : t -> int -> int ##V>=4.13##val full_int : t -> int -> int +##V>=5.2##val int_in_range : t -> min:int -> max:int -> int val int32 : t -> Int32.t -> Int32.t +##V>=5.2##val int32_in_range : t -> min:int32 -> max:int32 -> int32 val nativeint : t -> Nativeint.t -> Nativeint.t +##V>=5.2##val nativeint_in_range : t -> min:nativeint -> max:nativeint -> nativeint val int64 : t -> Int64.t -> Int64.t +##V>=5.2##val int64_in_range : t -> min:int64 -> max:int64 -> int64 val float : t -> float -> float val bool : t -> bool val char : t -> char diff --git a/src/batUnix.mli b/src/batUnix.mli index b21f9fe08..b765c669b 100644 --- a/src/batUnix.mli +++ b/src/batUnix.mli @@ -337,6 +337,11 @@ val read : file_descr -> Bytes.t -> int -> int -> int [fd], storing them in string [buff], starting at position [ofs] in string [buff]. Return the number of characters actually read. *) +##V>=5.2##val read_bigarray : +##V>=5.2## file_descr -> +##V>=5.2## (_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> +##V>=5.2## int -> int -> int + val write : file_descr -> Bytes.t -> int -> int -> int (** [write fd buff ofs len] writes [len] characters to descriptor [fd], taking them from string [buff], starting at position [ofs] @@ -344,6 +349,11 @@ val write : file_descr -> Bytes.t -> int -> int -> int written. [write] repeats the writing operation until all characters have been written or an error occurs. *) +##V>=5.2##val write_bigarray : +##V>=5.2## file_descr -> +##V>=5.2## (_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> +##V>=5.2## int -> int -> int + val single_write : file_descr -> Bytes.t -> int -> int -> int (** Same as [write], but attempts to write only once. Thus, if an error occurs, [single_write] guarantees that no data @@ -363,6 +373,11 @@ val single_write_substring : file_descr -> string -> int -> int -> int @since 2.3.0 *) +##V>=5.2##val single_write_bigarray : +##V>=5.2## file_descr -> +##V>=5.2## (_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> +##V>=5.2## int -> int -> int + (** {6 Interfacing with the standard input/output library} *) val in_channel_of_descr : file_descr -> in_channel diff --git a/src/batteries_compattest.ml b/src/batteries_compattest.ml index 339a0ddd0..33d265e5d 100644 --- a/src/batteries_compattest.ml +++ b/src/batteries_compattest.ml @@ -3,7 +3,11 @@ open Batteries module Stdlib_verifications = struct (* This module asserts that all the BatFoo modules are actually extensions of stdlib modules, and that no functionality is lost. *) - module Array_t = (Array : module type of Legacy.Array) + module Array_t = + (Array : sig + include module type of Legacy.Array + val shuffle : ?state:Random.State.t -> 'a array -> unit + end) module Buffer_t = (Buffer: sig include module type of Legacy.Buffer