Skip to content

Commit

Permalink
v0.17~preview.129.15+205
Browse files Browse the repository at this point in the history
  • Loading branch information
public-release committed Mar 19, 2024
1 parent 1311ac1 commit 043ffd4
Show file tree
Hide file tree
Showing 85 changed files with 1,736 additions and 1,206 deletions.
2 changes: 1 addition & 1 deletion md5/src/md5_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ val compare : t -> t -> int
val length : int

val to_binary : t -> string
val to_binary_local : (t[@local]) -> (string[@local])
val to_binary_local : t -> string
val of_binary_exn : string -> t

(** assumes the input is 16 bytes without checking *)
Expand Down
14 changes: 7 additions & 7 deletions src/hashtbl_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module type Accessors = sig
{v
let h = Hashtbl.of_alist_exn (module Int) [(1, 4); (5, 6)] in
let h' = Hashtbl.map h ~f:((fun x -> x * 2)[@local]) in
let h' = Hashtbl.map h ~f:(local_ (fun x -> x * 2)) in
Hashtbl.to_alist h';;
- : (int * int) list = [(5, 12); (1, 8)]
v} *)
Expand All @@ -146,7 +146,7 @@ module type Accessors = sig
{v
let h = Hashtbl.of_alist_exn (module Int) [(1, 4); (5, 6)] in
Hashtbl.filter_map h ~f:((fun x -> if x > 5 then Some x else None)[@local])
Hashtbl.filter_map h ~f:(local_ (fun x -> if x > 5 then Some x else None))
|> Hashtbl.to_alist;;
- : (int * int) list = [(5, 6)]
v} *)
Expand Down Expand Up @@ -541,8 +541,8 @@ module type Creators = sig
{v
let h =
Hashtbl.create_mapped (module Int)
~get_key:((fun x -> x)[@local])
~get_data:((fun x -> x + 1)[@local])
~get_key:(local_ (fun x -> x))
~get_data:(local_ (fun x -> x + 1))
[1; 2; 3];;
val h : [ `Duplicate_keys of int list | `Ok of (int, int) Hashtbl.t ] = `Ok <abstr>
Expand Down Expand Up @@ -599,9 +599,9 @@ module type Creators = sig
{v
Hashtbl.group (module Int)
~get_key:((fun x -> x / 2)[@local])
~get_data:((fun x -> x)[@local])
~combine:((fun x y -> x * y)[@local])
~get_key:(local_ (fun x -> x / 2))
~get_data:(local_ (fun x -> x))
~combine:(local_ (fun x y -> x * y))
[ 1; 2; 3; 4]
|> Hashtbl.to_alist;;
- : (int * int) list = [(2, 4); (1, 6); (0, 1)]
Expand Down
2 changes: 1 addition & 1 deletion src/indexed_container_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ end
module type Derived = sig
(** Generic definitions of [foldi] and [iteri] in terms of [fold].
E.g., [iteri ~fold t ~f = ignore (fold t ~init:0 ~f:((fun i x -> f i x; i + 1)[@local]))]. *)
E.g., [iteri ~fold t ~f = ignore (fold t ~init:0 ~f:(local_ (fun i x -> f i x; i + 1)))]. *)

val foldi : fold:('t, 'a, 'acc) fold -> ('t, 'a, 'acc) foldi
val iteri : fold:('t, 'a, int) fold -> ('t, 'a) iteri
Expand Down
2 changes: 1 addition & 1 deletion src/int_string_conversions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ struct
"0b" ^ insert_delimiter_every (to_string_suffix t) ~delimiter ~chars_per_delimiter:4
;;

let sexp_of_t (t : t) : Sexp.t = Atom (to_string t)
let sexp_of_t (t : t) : Sexp.t = Atom (to_string_hum t)
end
end
2 changes: 2 additions & 0 deletions src/option_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module Cheap_option = struct
;;

let[@inline] to_option x = if is_some x then Some (value_unsafe x) else None
let[@inline] to_option_local x = if is_some x then Some (value_unsafe x) else None
let to_sexpable = to_option
let of_sexpable = of_option

Expand Down Expand Up @@ -129,6 +130,7 @@ let init n ~f = Uniform_array.init n ~f:(fun i -> Cheap_option.of_option (f i))
let init_some n ~f = Uniform_array.init n ~f:(fun i -> Cheap_option.some (f i)) [@nontail]
let length = Uniform_array.length
let[@inline] get t i = Cheap_option.to_option (Uniform_array.get t i)
let[@inline] get_local t i = Cheap_option.to_option_local (Uniform_array.get t i)
let get_some_exn t i = Cheap_option.value_exn (Uniform_array.get t i)
let is_none t i = Cheap_option.is_none (Uniform_array.get t i)
let is_some t i = Cheap_option.is_some (Uniform_array.get t i)
Expand Down
4 changes: 4 additions & 0 deletions src/option_array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ val to_array : 'a t -> 'a option Array.t
range 0 to [length t - 1]. *)
val get : 'a t -> int -> 'a option

(** Similar to [get], but allocates result in the caller's stack region instead
of heap. *)
val get_local : 'a t -> int -> 'a option

(** Raises if the element number [i] is [None]. *)
val get_some_exn : 'a t -> int -> 'a

Expand Down
38 changes: 27 additions & 11 deletions src/string_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ module type Utf = sig
characters. Indexes, length, etc. are with respect to [Uchar.t]. *)
include Indexed_container.S0_with_creators with type t := t and type elt = Uchar0.t

(** Counts the number of unicode scalar values in [t]. *)
val length_in_uchars : t -> int

(** [length] could be misinterpreted as counting bytes. We direct users to other,
clearer options. *)
val length : t -> int
[@@alert
length_in_uchars
"Use [length_in_uchars] to count unicode scalar values or [String.length] to \
count bytes"]

(** Produce a sequence of unicode characters. *)
val to_sequence : t -> Uchar0.t Sequence.t

Expand Down Expand Up @@ -57,6 +46,33 @@ module type Utf = sig

(** The name of this encoding scheme; e.g., "UTF-8". *)
val codec_name : string

(** Counts the number of unicode scalar values in [t].
This function is not a good proxy for display width, as some scalar values have
display widths > 1. Many native applications such as terminal emulators use
[wcwidth] (see [man 3 wcwidth]) to compute the display width of a scalar value. See
the uucp library's [Uucp.Break.tty_width_hint] for an implementation of [wcwidth]'s
logic. However, this is merely best-effort, as display widths will vary based on the
font and underlying text shaping engine (see docs on [tty_width_hint] for details).
For applications that support Grapheme clusters (many terminal emulators do not),
[t] should first be split into Grapheme clusters and then the display width of each
of those Grapheme clusters needs to be computed (which is the max display width of
the scalars that are in the cluster).
There are some active efforts to improve the current state of affairs:
- https://github.com/wez/wezterm/issues/4320
- https://www.unicode.org/L2/L2023/23194-text-terminal-wg-report.pdf *)
val length_in_uchars : t -> int

(** [length] could be misinterpreted as counting bytes. We direct users to other,
clearer options. *)
val length : t -> int
[@@alert
length_in_uchars
"Use [length_in_uchars] to count unicode scalar values or [String.length] to \
count bytes"]
end

(** Iterface for Unicode encodings, specialized for string representation. *)
Expand Down
4 changes: 2 additions & 2 deletions test/allocation/test_array_allocation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ open Expect_test_helpers_core
let%expect_test "Array.sort [||] only allocates when computing bounds" =
require_allocation_does_not_exceed (Minor_words 3) [%here] (fun () ->
Array.sort ~compare:Int.compare [||]);
[%expect {||}]
[%expect {| |}]
;;

let%expect_test "Array.sort [| 5; 2; 3; 4; 1 |] only allocates when computing bounds" =
let arr = [| 5; 2; 3; 4; 1 |] in
require_allocation_does_not_exceed (Minor_words 3) [%here] (fun () ->
Array.sort ~compare:Int.compare arr);
[%expect {||}]
[%expect {| |}]
;;

let%expect_test "equal does not allocate" =
Expand Down
2 changes: 1 addition & 1 deletion test/allocation/test_char_allocation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ let%expect_test _ =
let y = Sys.opaque_identity 'b' in
require_no_allocation [%here] (fun () ->
ignore (Sys.opaque_identity (Char.Caseless.equal x y) : bool));
[%expect {||}]
[%expect {| |}]
;;
3 changes: 2 additions & 1 deletion test/allocation/test_hashtbl_allocation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ let%expect_test "find_and_call_1_and_2" =
25
29
33
3_133 |}]
3_133
|}]
;;

let%expect_test ("find_or_add shouldn't allocate" [@tags "no-js"]) =
Expand Down
2 changes: 1 addition & 1 deletion test/allocation/test_option_array_allocation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ let%expect_test _ =
using the build info in version_util, which isn't available while compiling a test.
So we delegate the whole test to this executable: *)
let%bind () = run "bin/test_option_array_allocation.exe" [] in
[%expect {||}];
[%expect {| |}];
return ()
;;
20 changes: 12 additions & 8 deletions test/allocation/test_string_allocation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let%expect_test _ =
let y = Sys.opaque_identity "another" in
require_no_allocation [%here] (fun () ->
ignore (Sys.opaque_identity (String.Caseless.equal x y) : bool));
[%expect {||}]
[%expect {| |}]
;;

let%expect_test "empty substring" =
Expand All @@ -27,7 +27,7 @@ let%expect_test "mem does not allocate" =
let string = Sys.opaque_identity "abracadabra" in
let char = Sys.opaque_identity 'd' in
require_no_allocation [%here] (fun () -> ignore (String.mem string char : bool));
[%expect {||}]
[%expect {| |}]
;;

let%expect_test "fold does not allocate" =
Expand All @@ -36,7 +36,7 @@ let%expect_test "fold does not allocate" =
let f acc c = if Char.equal c char then true else acc in
require_no_allocation [%here] (fun () ->
ignore (String.fold string ~init:false ~f : bool));
[%expect {||}]
[%expect {| |}]
;;

let%expect_test "foldi does not allocate" =
Expand All @@ -45,7 +45,7 @@ let%expect_test "foldi does not allocate" =
let f _i acc c = if Char.equal c char then true else acc in
require_no_allocation [%here] (fun () ->
ignore (String.foldi string ~init:false ~f : bool));
[%expect {||}]
[%expect {| |}]
;;

let%test_module "common prefix and suffix" =
Expand Down Expand Up @@ -135,11 +135,13 @@ let%test_module "common prefix and suffix" =
test_prefix [ "hello"; "help"; "hex" ];
[%expect {|
he
(may allocate) |}];
(may allocate)
|}];
test_suffix [ "crest"; "zest"; "1st" ];
[%expect {|
st
(may allocate) |}]
(may allocate)
|}]
;;

let%expect_test "doubleton, no alloc" =
Expand All @@ -153,11 +155,13 @@ let%test_module "common prefix and suffix" =
test_prefix [ "this"; "that"; "the other"; "these"; "those"; "thy"; "thou" ];
[%expect {|
th
(may allocate) |}];
(may allocate)
|}];
test_suffix [ "fourth"; "fifth"; "sixth"; "seventh"; "eleventh"; "twelfth" ];
[%expect {|
th
(may allocate) |}]
(may allocate)
|}]
;;

let%expect_test "many, no alloc" =
Expand Down
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name base_test)
(libraries base base_container_tests core.base_for_tests base_test_helpers
expect_test_helpers_core.expect_test_helpers_base sexplib sexp_grammar
expect_test_helpers_core.expect_test_helpers_base sexplib
sexp_grammar_validation num stdio)
(preprocess
(pps ppx_jane -dont-apply=pipebang -no-check-on-extensions)))
1 change: 1 addition & 0 deletions test/map_full_interface/base_test_map_full_interface.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(*_ This library deliberately exports nothing. *)
6 changes: 6 additions & 0 deletions test/map_full_interface/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name base_test_map_full_interface)
(libraries base base_quickcheck
expect_test_helpers_core.expect_test_helpers_base sexp_grammar)
(preprocess
(pps ppx_jane)))

0 comments on commit 043ffd4

Please sign in to comment.