Skip to content

Commit 2b9a97b

Browse files
committed
fix an inconsistent API, more coverage
1 parent 6fadcbe commit 2b9a97b

40 files changed

+400
-204
lines changed

jscomp/others/belt_Map.mli

+5-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ val getUndefined: ('k, 'a, 'id) t -> 'k -> 'a Js.undefined
200200
val getWithDefault:
201201
('k, 'a, 'id) t -> 'k -> 'a -> 'a
202202
val getExn: ('k, 'a, 'id) t -> 'k -> 'a
203-
val checkInvariantInternal: _ t -> bool
203+
val checkInvariantInternal: _ t -> unit
204+
(**
205+
{b raise} when invariant is not helld
206+
*)
207+
204208
(****************************************************************************)
205209

206210
val remove: ('k, 'a, 'id) t -> 'k -> ('k, 'a, 'id) t

jscomp/others/belt_MapDict.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ val getExn:
122122
cmp:('k, 'id) cmp ->
123123
'a
124124

125-
val checkInvariantInternal: _ t -> bool
125+
val checkInvariantInternal: _ t -> unit
126+
(**
127+
{b raise} when invariant is not helld
128+
*)
126129

127130
val remove:
128131
('a, 'b, 'id) t -> 'a ->

jscomp/others/belt_MapInt.mli

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ val get: 'a t -> key -> 'a option
6161
val getUndefined: 'a t -> key -> 'a Js.undefined
6262
val getWithDefault: 'a t -> key -> 'a -> 'a
6363
val getExn: 'a t -> key -> 'a
64-
val checkInvariantInternal: _ t -> bool
64+
65+
val checkInvariantInternal: _ t -> unit
66+
(**
67+
{b raise} when invariant is not helld
68+
*)
69+
6570
(****************************************************************************)
6671

6772
val remove: 'a t -> key -> 'a t
@@ -144,4 +149,9 @@ val mapWithKeyU: 'a t -> (key -> 'a -> 'b [@bs]) -> 'b t
144149
val mapWithKey: 'a t -> (key -> 'a -> 'b) -> 'b t
145150

146151

147-
val checkInvariantInternal: _ t -> bool
152+
val checkInvariantInternal: _ t -> unit
153+
(**
154+
{b raise} when invariant is not helld
155+
*)
156+
157+

jscomp/others/belt_MapString.mli

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ val get: 'a t -> key -> 'a option
6161
val getUndefined: 'a t -> key -> 'a Js.undefined
6262
val getWithDefault: 'a t -> key -> 'a -> 'a
6363
val getExn: 'a t -> key -> 'a
64-
val checkInvariantInternal: _ t -> bool
64+
65+
val checkInvariantInternal: _ t -> unit
66+
(**
67+
{b raise} when invariant is not helld
68+
*)
69+
6570
(****************************************************************************)
6671

6772
val remove: 'a t -> key -> 'a t
@@ -144,4 +149,9 @@ val mapWithKeyU: 'a t -> (key -> 'a -> 'b [@bs]) -> 'b t
144149
val mapWithKey: 'a t -> (key -> 'a -> 'b) -> 'b t
145150

146151

147-
val checkInvariantInternal: _ t -> bool
152+
val checkInvariantInternal: _ t -> unit
153+
(**
154+
{b raise} when invariant is not helld
155+
*)
156+
157+

jscomp/others/belt_MutableMap.mli

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ val getUndefined: ('k, 'a, 'id) t -> 'k -> 'a Js.undefined
156156
val getWithDefault:
157157
('k, 'a, 'id) t -> 'k -> 'a -> 'a
158158
val getExn: ('k, 'a, 'id) t -> 'k -> 'a
159-
val checkInvariantInternal: _ t -> bool
159+
val checkInvariantInternal: _ t -> unit
160+
(**
161+
{b raise} when invariant is not helld
162+
*)
163+
160164
(****************************************************************************)
161165

162166
(*TODO: add functional [merge, partition, keep, split]*)

jscomp/others/belt_MutableMapInt.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ val get: 'a t -> key -> 'a option
9595
val getUndefined: 'a t -> key -> 'a Js.undefined
9696
val getWithDefault: 'a t -> key -> 'a -> 'a
9797
val getExn: 'a t -> key -> 'a
98-
val checkInvariantInternal: _ t -> bool
98+
val checkInvariantInternal: _ t -> unit
99+
(**
100+
{b raise} when invariant is not helld
101+
*)
102+
103+
99104

100105
(****************************************************************************)
101106

jscomp/others/belt_MutableMapString.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ val get: 'a t -> key -> 'a option
9595
val getUndefined: 'a t -> key -> 'a Js.undefined
9696
val getWithDefault: 'a t -> key -> 'a -> 'a
9797
val getExn: 'a t -> key -> 'a
98-
val checkInvariantInternal: _ t -> bool
98+
val checkInvariantInternal: _ t -> unit
99+
(**
100+
{b raise} when invariant is not helld
101+
*)
102+
103+
99104

100105
(****************************************************************************)
101106

jscomp/others/belt_MutableSet.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ val split: ('elt, 'id) t -> 'elt -> (('elt, 'id) t * ('elt, 'id) t) * bool
179179
[l,r] are freshly made, no sharing with [s]
180180
*)
181181

182-
val checkInvariantInternal: _ t -> bool
182+
val checkInvariantInternal: _ t -> unit
183+
(**
184+
{b raise} when invariant is not helld
185+
*)
183186

184187
(*
185188
[add0] was not exposed for various reasons:

jscomp/others/belt_MutableSetInt.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ val split: t -> elt -> (t * t) * bool
114114
[split s key] return a fresh copy of each
115115
*)
116116

117-
val checkInvariantInternal: t -> bool
117+
val checkInvariantInternal: t -> unit
118+
(**
119+
{b raise} when invariant is not helld
120+
*)
121+
122+
118123

119124

jscomp/others/belt_MutableSetString.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ val split: t -> elt -> (t * t) * bool
114114
[split s key] return a fresh copy of each
115115
*)
116116

117-
val checkInvariantInternal: t -> bool
117+
val checkInvariantInternal: t -> unit
118+
(**
119+
{b raise} when invariant is not helld
120+
*)
121+
122+
118123

119124

jscomp/others/belt_Set.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ let ofSortedArrayUnsafe (type elt) (type identity) xs ~(id : (elt,identity) id )
154154

155155
let getData = S.data
156156

157-
let getDict (type elt) (type identity) (m : (elt,identity) t) : (elt, identity) id =
157+
let getId (type elt) (type identity) (m : (elt,identity) t) : (elt, identity) id =
158158
let module T = struct
159159
type nonrec identity = identity
160160
type nonrec t = elt
161161
let cmp = S.cmp m
162162
end in
163163
(module T)
164164

165-
let packDictData (type elt) (type identity) ~(id : (elt, identity) id) ~data =
165+
let packIdData (type elt) (type identity) ~(id : (elt, identity) id) ~data =
166166
let module M = (val id) in
167167
S.t ~cmp:M.cmp ~data
168168

jscomp/others/belt_Set.mli

+7-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ val split: ('elt, 'id) t -> 'elt -> (('elt, 'id) t * ('elt, 'id) t) * bool
207207
@return a tuple [((smaller, larger), present)],
208208
[present] is true when [ele] exist in [set]
209209
*)
210-
val checkInvariantInternal: _ t -> bool
210+
val checkInvariantInternal: _ t -> unit
211+
(**
212+
{b raise} when invariant is not helld
213+
*)
214+
211215

212216
(****************************************************************************)
213217
(** Below are operations only when better performance needed,
@@ -216,6 +220,6 @@ val checkInvariantInternal: _ t -> bool
216220
*)
217221

218222
val getData: ('k,'id) t -> ('k,'id) Belt_SetDict.t
219-
val getDict: ('k,'id) t -> ('k,'id) id
220-
val packDictData: id:('k, 'id) id -> data:('k, 'id) Belt_SetDict.t -> ('k, 'id) t
223+
val getId: ('k,'id) t -> ('k,'id) id
224+
val packIdData: id:('k, 'id) id -> data:('k, 'id) Belt_SetDict.t -> ('k, 'id) t
221225

jscomp/others/belt_SetDict.mli

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,9 @@ val split: ('elt, 'id) t -> 'elt ->
148148
cmp:('elt, 'id) cmp ->
149149
(('elt, 'id) t * ('elt, 'id) t) * bool
150150

151-
val checkInvariantInternal: _ t -> bool
151+
val checkInvariantInternal: _ t -> unit
152+
(**
153+
{b raise} when invariant is not helld
154+
*)
155+
152156

jscomp/others/belt_SetInt.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,9 @@ val split: t -> elt -> (t * t) * bool
127127

128128

129129

130-
val checkInvariantInternal: t -> bool
130+
val checkInvariantInternal: t -> unit
131+
(**
132+
{b raise} when invariant is not helld
133+
*)
134+
135+

jscomp/others/belt_SetString.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,9 @@ val split: t -> elt -> (t * t) * bool
127127

128128

129129

130-
val checkInvariantInternal: t -> bool
130+
val checkInvariantInternal: t -> unit
131+
(**
132+
{b raise} when invariant is not helld
133+
*)
134+
135+

jscomp/others/belt_internalAVLset.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ let toList s =
294294

295295
let rec checkInvariantInternal (v : _ t) =
296296
match toOpt v with
297-
| None -> true
297+
| None -> ()
298298
| Some n ->
299299
let l,r = left n , right n in
300300
let diff = height l - height r in
301-
diff <=2 && diff >= -2 && checkInvariantInternal l && checkInvariantInternal r
301+
[%assert diff <=2 && diff >= -2];
302+
checkInvariantInternal l;
303+
checkInvariantInternal r
302304

303305

304306

jscomp/others/belt_internalAVLset.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ val lengthNode: 'a node -> int
9595
val size: 'a t -> int
9696

9797
val toList: 'a t -> 'a list
98-
val checkInvariantInternal : _ t -> bool
98+
val checkInvariantInternal: _ t -> unit
99+
(**
100+
{b raise} when invariant is not helld
101+
*)
99102
val fillArray: 'a node -> int -> 'a array -> int
100103
val toArray: 'a t -> 'a array
101104
val ofSortedArrayAux : 'a array -> int -> int -> 'a t

jscomp/others/belt_internalAVLtree.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ let toList s =
361361

362362
let rec checkInvariantInternal (v : _ t) =
363363
match toOpt v with
364-
| None -> true
364+
| None -> ()
365365
| Some n ->
366366
let l,r = left n , right n in
367367
let diff = height l - height r in
368-
diff <=2 && diff >= -2 && checkInvariantInternal l && checkInvariantInternal r
368+
[%assert diff <=2 && diff >= -2 ];
369+
checkInvariantInternal l;
370+
checkInvariantInternal r
369371

370372

371373
let rec fillArrayKey n i arr =

jscomp/others/belt_internalAVLtree.mli

+5-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ val lengthNode : ('a, 'b) node -> int
129129
val size : ('a,'b) t -> int
130130

131131
val toList : ('a,'b) t -> ('a * 'b) list
132-
val checkInvariantInternal : ('a,'b) t -> bool
132+
val checkInvariantInternal : ('a,'b) t -> unit
133+
(**
134+
{b raise} when invariant is not helld
135+
*)
136+
133137

134138
val fillArray : ('a,'b) node -> int -> ('a * 'b) array -> int
135139

jscomp/others/map.cppo.mli

+12-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ val get: 'a t -> key -> 'a option
6565
val getUndefined: 'a t -> key -> 'a Js.undefined
6666
val getWithDefault: 'a t -> key -> 'a -> 'a
6767
val getExn: 'a t -> key -> 'a
68-
val checkInvariantInternal: _ t -> bool
68+
69+
val checkInvariantInternal: _ t -> unit
70+
(**
71+
{b raise} when invariant is not helld
72+
*)
73+
6974
(****************************************************************************)
7075

7176
val remove: 'a t -> key -> 'a t
@@ -148,4 +153,9 @@ val mapWithKeyU: 'a t -> (key -> 'a -> 'b [@bs]) -> 'b t
148153
val mapWithKey: 'a t -> (key -> 'a -> 'b) -> 'b t
149154

150155

151-
val checkInvariantInternal: _ t -> bool
156+
val checkInvariantInternal: _ t -> unit
157+
(**
158+
{b raise} when invariant is not helld
159+
*)
160+
161+

jscomp/others/mapm.cppo.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ val get: 'a t -> key -> 'a option
9898
val getUndefined: 'a t -> key -> 'a Js.undefined
9999
val getWithDefault: 'a t -> key -> 'a -> 'a
100100
val getExn: 'a t -> key -> 'a
101-
val checkInvariantInternal: _ t -> bool
101+
val checkInvariantInternal: _ t -> unit
102+
(**
103+
{b raise} when invariant is not helld
104+
*)
105+
106+
102107

103108
(****************************************************************************)
104109

jscomp/others/set.cppo.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ val split: t -> elt -> (t * t) * bool
130130

131131

132132

133-
val checkInvariantInternal: t -> bool
133+
val checkInvariantInternal: t -> unit
134+
(**
135+
{b raise} when invariant is not helld
136+
*)
137+
138+

jscomp/others/setm.cppo.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ val split: t -> elt -> (t * t) * bool
117117
[split s key] return a fresh copy of each
118118
*)
119119

120-
val checkInvariantInternal: t -> bool
120+
val checkInvariantInternal: t -> unit
121+
(**
122+
{b raise} when invariant is not helld
123+
*)
124+
125+
121126

122127

jscomp/test/.depend

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ gpr_2250_test.cmj : mt.cmj
302302
gpr_2316_test.cmj : mt.cmj ../runtime/js.cmj
303303
gpr_2474.cmj :
304304
gpr_2487.cmj : ../others/belt.cmj
305+
gpr_2503_test.cmj : ../runtime/js.cmj
305306
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
306307
gpr_441.cmj :
307308
gpr_459_test.cmj : mt.cmj

jscomp/test/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
239239
bs_poly_mutable_map_test\
240240
imm_map_bench\
241241
gpr_2487\
242+
gpr_2503_test\
242243
# bs_uncurry_test
243244
# needs Lam to get rid of Uncurry arity first
244245
# simple_derive_test

jscomp/test/bs_map_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ var v = Belt_Array.makeByAndShuffle(1000000, (function (i) {
5858

5959
var u = Belt_MapInt.ofArray(v);
6060

61-
b("File \"bs_map_test.ml\", line 27, characters 4-11", Belt_MapInt.checkInvariantInternal(u));
61+
Belt_MapInt.checkInvariantInternal(u);
6262

6363
var firstHalf = Belt_Array.slice(v, 0, 2000);
6464

6565
var xx = Belt_Array.reduce(firstHalf, u, (function (acc, param) {
6666
return Belt_MapInt.remove(acc, param[0]);
6767
}));
6868

69-
b("File \"bs_map_test.ml\", line 31, characters 4-11", Belt_MapInt.checkInvariantInternal(u));
69+
Belt_MapInt.checkInvariantInternal(u);
7070

71-
b("File \"bs_map_test.ml\", line 32, characters 4-11", Belt_MapInt.checkInvariantInternal(xx));
71+
Belt_MapInt.checkInvariantInternal(xx);
7272

7373
Mt.from_pair_suites("bs_map_test.ml", suites[0]);
7474

jscomp/test/bs_map_test.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ let () =
2424
let v =
2525
(A.makeByAndShuffle 1_000_000 (fun i -> (i,i))) in
2626
let u = M.ofArray v in
27-
b __LOC__ (M.checkInvariantInternal u);
27+
(M.checkInvariantInternal u);
2828
let firstHalf = A.slice v 0 2_000 in
2929
let xx = A.reduce firstHalf u
3030
(fun acc (x,_) -> M.remove acc x) in
31-
b __LOC__ (M.checkInvariantInternal u);
32-
b __LOC__ (M.checkInvariantInternal xx);
31+
(M.checkInvariantInternal u);
32+
(M.checkInvariantInternal xx);
3333

3434

3535
;; Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)