Skip to content

Commit a2ec2e4

Browse files
v0.18~preview.130.05+548
1 parent 6779e91 commit a2ec2e4

38 files changed

+407
-1115
lines changed

core.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ depends: [
3535
"stdio"
3636
"time_now"
3737
"typerep"
38+
"univ_map"
3839
"variantslib"
3940
"dune" {>= "3.11.0"}
4041
]

core/src/date0.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,16 @@ let first_strictly_after t ~on:dow =
642642
add_days tplus1 diff
643643
;;
644644

645+
let last_date_in_month ~year ~month =
646+
create_exn ~y:year ~m:month ~d:(days_in_month ~year ~month)
647+
;;
648+
649+
let all_dates_in_month ~year ~month =
650+
dates_between
651+
~min:(create_exn ~y:year ~m:month ~d:1)
652+
~max:(last_date_in_month ~year ~month)
653+
;;
654+
645655
module For_quickcheck = struct
646656
open Quickcheck
647657

core/src/date0_intf.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ module type Date0 = sig
254254
Incorrect for September 1752. *)
255255
val days_in_month : year:int -> month:Month.t -> int
256256

257+
(** [last_date_in_month ~year ~month] returns the last date in [month] and [year]. *)
258+
val last_date_in_month : year:int -> month:Month.t -> t
259+
260+
(** [all_dates_in_month ~year ~month] returns all dates in [month] and [year]. *)
261+
val all_dates_in_month : year:int -> month:Month.t -> t list
262+
257263
(** [is_leap_year ~year] returns true if [year] is considered a leap year *)
258264
val is_leap_year : year:int -> bool
259265

@@ -301,7 +307,7 @@ module type Date0 = sig
301307

302308
module Stable : sig
303309
module V1 : sig
304-
type nonrec t = t [@@deriving equal, hash, sexp_grammar] [@@immediate]
310+
type nonrec t = t [@@deriving equal, hash, sexp_grammar, string] [@@immediate]
305311

306312
(** [to_int] and [of_int_exn] convert to/from the underlying integer
307313
representation. *)

core/src/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
(library
88
(foreign_stubs
99
(language c)
10-
(names bigstring_stubs md5_stubs array_stubs gc_stubs time_ns_stubs
10+
(names bigstring_stubs md5_stubs array_stubs gc_stubs
1111
timezone_js_loader_stubs)
1212
(flags :standard -D_LARGEFILE64_SOURCE))
1313
(name core)
1414
(public_name core)
15-
(install_c_headers time_ns_stubs)
1615
(libraries base base_bigstring base_for_tests base_quickcheck bin_prot
1716
command fieldslib filename_base heap_block bin_prot.shape
1817
ppx_diff.diffable ppx_expect.config_types jane-street-headers base.md5

core/src/error.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
include Base.Error
22
include Info.Extend (Base.Error)
33

4-
let failwiths ?strict ~here message a sexp_of_a =
5-
raise (create ?strict ~here message a sexp_of_a)
4+
let failwiths ?strict ?(here = Stdlib.Lexing.dummy_pos) message a sexp_of_a =
5+
let here = if Source_code_position0.is_dummy here then None else Some here in
6+
raise (create ?strict ?here message a sexp_of_a)
67
;;
78

89
let failwithp ?strict here message a sexp_of_a =

core/src/error.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include Info_intf.Extension with type t := t
2929
[~here:Source_code_position.t] to avoid a circular dependency. *)
3030
val failwiths
3131
: ?strict:unit
32-
-> here:Lexing.position
32+
-> ?here:Stdlib.Lexing.position
3333
-> string
3434
-> 'a
3535
-> ('a -> Base.Sexp.t)

core/src/gc.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,20 @@ module Expert = struct
496496
()
497497
;;
498498

499-
(* [add_finalizer_exn] is the same as [add_finalizer]. However, their types in
499+
(* [add_finalizer_ignore] is the same as [add_finalizer]. However, their types in
500500
core_gc.mli are different, and the type of [add_finalizer] guarantees that it always
501501
receives a heap block, which ensures that it will not raise, while
502502
[add_finalizer_exn] accepts any type, and so may raise. *)
503+
let add_finalizer_ignore x f =
504+
try Stdlib.Gc.finalise (fun x -> Exn.handle_uncaught_and_exit (fun () -> f x)) x with
505+
| Invalid_argument _ -> ()
506+
;;
507+
503508
let add_finalizer_exn x f =
504509
try Stdlib.Gc.finalise (fun x -> Exn.handle_uncaught_and_exit (fun () -> f x)) x with
505510
| Invalid_argument _ ->
506-
ignore (Heap_block.create x : _ Heap_block.t option);
507-
(* If [Heap_block.create] succeeds then [x] is static data and so
511+
ignore (Heap_block.create_exn x : _ Heap_block.t);
512+
(* If [Heap_block.create_exn] succeeds then [x] is static data and so
508513
we can simply drop the finaliser. *)
509514
()
510515
;;
@@ -519,11 +524,16 @@ module Expert = struct
519524
()
520525
;;
521526

527+
let add_finalizer_last_ignore x f =
528+
try Stdlib.Gc.finalise_last (fun () -> Exn.handle_uncaught_and_exit f) x with
529+
| Invalid_argument _ -> ()
530+
;;
531+
522532
let add_finalizer_last_exn x f =
523533
try Stdlib.Gc.finalise_last (fun () -> Exn.handle_uncaught_and_exit f) x with
524534
| Invalid_argument _ ->
525-
ignore (Heap_block.create x : _ Heap_block.t option);
526-
(* If [Heap_block.create] succeeds then [x] is static data and so
535+
ignore (Heap_block.create_exn x : _ Heap_block.t);
536+
(* If [Heap_block.create_exn] succeeds then [x] is static data and so
527537
we can simply drop the finaliser. *)
528538
()
529539
;;
@@ -546,6 +556,11 @@ module Expert = struct
546556
let f = protect_finalizer x f in
547557
add_finalizer_exn x f
548558
;;
559+
560+
let add_finalizer_ignore x f =
561+
let f = protect_finalizer x f in
562+
add_finalizer_ignore x f
563+
;;
549564
end
550565

551566
let finalize_release = Stdlib.Gc.finalise_release

core/src/gc.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,14 @@ module Expert : sig
647647
648648
[add_finalizer_exn b f] is like [add_finalizer], but will raise if [b] is not a heap
649649
block.
650+
651+
[add_finalizer_ignore b f] is like [add_finalizer], but will ignore the error, if
652+
any. This means that the finalizer may not ever run.
650653
*)
651654
val add_finalizer : 'a Heap_block.t -> ('a Heap_block.t -> unit) -> unit
652655

653656
val add_finalizer_exn : 'a -> ('a -> unit) -> unit
657+
val add_finalizer_ignore : 'a -> ('a -> unit) -> unit
654658

655659
(** Same as {!add_finalizer} except that the function is not called until the value has
656660
become unreachable for the last time. This means that the finalization function
@@ -660,6 +664,7 @@ module Expert : sig
660664
val add_finalizer_last : 'a Heap_block.t -> (unit -> unit) -> unit
661665

662666
val add_finalizer_last_exn : 'a -> (unit -> unit) -> unit
667+
val add_finalizer_last_ignore : 'a -> (unit -> unit) -> unit
663668

664669
module With_leak_protection : sig
665670
(** The versions of [add_finalizer] that protect against memory leaks on circular
@@ -673,6 +678,7 @@ module Expert : sig
673678

674679
val add_finalizer : 'a Heap_block.t -> ('a Heap_block.t -> unit) -> unit
675680
val add_finalizer_exn : 'a -> ('a -> unit) -> unit
681+
val add_finalizer_ignore : 'a -> ('a -> unit) -> unit
676682

677683
(** Make a function [f] safe to use with [Stdlib.Gc.finalise f' x], despite [f]
678684
potentially containing references back to [x].

core/src/map.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ module Make_tree_S1 (Key : Comparator.S1) = struct
353353
let find_multi a b = find_multi a b ~comparator
354354
let change a b ~f = change a b ~f ~comparator
355355
let update a b ~f = update a b ~f ~comparator
356+
let update_and_return a b ~f = update_and_return a b ~f ~comparator
356357
let find_exn a b = find_exn a b ~comparator
357358
let find a b = find a b ~comparator
358359
let remove a b = remove a b ~comparator

core/src/map.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ val change : ('k, 'v, 'cmp) t -> 'k -> f:('v option -> 'v option) -> ('k, 'v, 'c
352352
(** [update t key ~f] is [change t key ~f:(fun o -> Some (f o))]. *)
353353
val update : ('k, 'v, 'cmp) t -> 'k -> f:('v option -> 'v) -> ('k, 'v, 'cmp) t
354354

355+
(** [update_and_return t key ~f] is like [update t key ~f], but also returns the new
356+
value. *)
357+
val update_and_return
358+
: ('k, 'v, 'cmp) t
359+
-> 'k
360+
-> f:('v option -> 'v)
361+
-> 'v * ('k, 'v, 'cmp) t
362+
355363
(** Returns the value bound to the given key if it exists, and [None] otherwise. *)
356364
val find : ('k, 'v, 'cmp) t -> 'k -> 'v option
357365

0 commit comments

Comments
 (0)