Skip to content

Commit 9b911ac

Browse files
authored
Rename Belt functions from Exn to OrThrow (#7581)
* Add Belt.Array.getOrThrow and setOrThrow * Add Belt.Map.getOrThrow and Belt.MutableMap.getOrThrow * Add Belt.Set.getOrThrow and Belt.MutableSet.getOrThrow * Exclude rewatch from biome checks * Add Belt.List.getOrThrow, headOrThrow and tailOrThrow * Add Belt.MutableQueue.peekOrThrow and popOrThrow * Add Belt.Option.getOrThrow * Add Belt.Result.getOrThrow * Update runtime JS output * Add xxxOrThrow functions to specialised Belt Map and Set data structures * Update CHANGELOG entries to be in alpha 15 instead of alpha 14
1 parent 2ed1742 commit 9b911ac

File tree

107 files changed

+562
-137
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

+562
-137
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
#### :boom: Breaking Change
1616

1717
- The legacy rescript cli can be called through rewatch via `rewatch legacy`. Arguments to rewatch need to be passed after the subcommand. Argument `--compiler-args` is now a subcommand `compiler-args`. https://github.com/rescript-lang/rescript/pull/7551
18+
- Rename `Belt` functions ending with `Exn` to end with `OrThrow` https://github.com/rescript-lang/rescript/pull/7581 The following `Exn` functions are now deprecated:
19+
- `Belt.Array.getExn``Belt.Array.getOrThrow`
20+
- `Belt.Array.setExn``Belt.Array.setOrThrow`
21+
- `Belt.Map.getExn``Belt.Map.getOrThrow`
22+
- `Belt.MutableMap.getExn``Belt.MutableMap.getOrThrow`
23+
- `Belt.Set.getExn``Belt.Set.getOrThrow`
24+
- `Belt.MutableSet.getExn``Belt.MutableSet.getOrThrow`
25+
- `Belt.List.getExn``Belt.List.getOrThrow`
26+
- `Belt.List.tailExn``Belt.List.tailOrThrow`
27+
- `Belt.List.headExn``Belt.List.headOrThrow`
28+
- `Belt.MutableQueue.peekExn``Belt.MutableQueue.peekOrThrow`
29+
- `Belt.MutableQueue.popExn``Belt.MutableQueue.popOrThrow`
30+
- `Belt.Option.getExn``Belt.Option.getOrThrow`
31+
- `Belt.Result.getExn``Belt.Result.getOrThrow`
32+
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
1833

1934
#### :bug: Bug fix
2035

analysis/reanalyze/src/ExnLib.ml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
22
let table = Hashtbl.create 15 in
33
let open Exn in
4-
let beltArray = [("getExn", [assertFailure]); ("setExn", [assertFailure])] in
4+
let beltArray =
5+
[
6+
("getExn", [assertFailure]);
7+
("getOrThrow", [assertFailure]);
8+
("setExn", [assertFailure]);
9+
("setOrThrow", [assertFailure]);
10+
]
11+
in
512
let beltList =
6-
[("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])]
13+
[
14+
("getExn", [notFound]);
15+
("getOrThrow", [notFound]);
16+
("headExn", [notFound]);
17+
("headOrThrow", [notFound]);
18+
("tailExn", [notFound]);
19+
("tailOrThrow", [notFound]);
20+
]
721
in
8-
let beltMap = [("getExn", [notFound])] in
22+
let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
923
let beltMutableMap = beltMap in
10-
let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in
11-
let beltMutableSet = [("getExn", [notFound])] in
12-
let beltOption = [("getExn", [notFound])] in
13-
let beltResult = [("getExn", [notFound])] in
14-
let beltSet = [("getExn", [notFound])] in
24+
let beltMutableQueue =
25+
[
26+
("peekExn", [notFound]);
27+
("peekOrThrow", [notFound]);
28+
("popExn", [notFound]);
29+
("popOrThrow", [notFound]);
30+
]
31+
in
32+
let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
33+
let beltMutableSet = beltSet in
34+
let beltOption = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
35+
let beltResult = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
1536
let bsJson =
1637
(* bs-json *)
1738
[

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"tests/tests/**/src/**",
6363
"tests/tools_tests/**/src/**",
6464
"analysis/examples/**/src/**",
65+
"rewatch/**",
6566
"lib/es6/**",
6667
"lib/js/**",
6768
"ninja/**",

lib/es6/Belt_Array.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function get(arr, i) {
1010

1111
}
1212

13-
function getExn(arr, i) {
13+
function getOrThrow(arr, i) {
1414
if (!(i >= 0 && i < arr.length)) {
1515
throw {
1616
RE_EXN_ID: "Assert_failure",
@@ -34,13 +34,13 @@ function set(arr, i, v) {
3434
}
3535
}
3636

37-
function setExn(arr, i, v) {
37+
function setOrThrow(arr, i, v) {
3838
if (!(i >= 0 && i < arr.length)) {
3939
throw {
4040
RE_EXN_ID: "Assert_failure",
4141
_1: [
4242
"Belt_Array.res",
43-
49,
43+
51,
4444
2
4545
],
4646
Error: new Error()
@@ -582,6 +582,10 @@ function init(n, f) {
582582
return v;
583583
}
584584

585+
let getExn = getOrThrow;
586+
587+
let setExn = setOrThrow;
588+
585589
let makeByU = makeBy;
586590

587591
let makeByAndShuffleU = makeByAndShuffle;
@@ -637,8 +641,10 @@ let initU = init;
637641
export {
638642
get,
639643
getExn,
644+
getOrThrow,
640645
set,
641646
setExn,
647+
setOrThrow,
642648
shuffleInPlace,
643649
shuffle,
644650
reverseInPlace,

lib/es6/Belt_List.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function head(x) {
1111

1212
}
1313

14-
function headExn(x) {
14+
function headOrThrow(x) {
1515
if (x !== 0) {
1616
return x.hd;
1717
}
@@ -28,7 +28,7 @@ function tail(x) {
2828

2929
}
3030

31-
function tailExn(x) {
31+
function tailOrThrow(x) {
3232
if (x !== 0) {
3333
return x.tl;
3434
}
@@ -67,7 +67,7 @@ function get(x, n) {
6767
}
6868
}
6969

70-
function getExn(x, n) {
70+
function getOrThrow(x, n) {
7171
if (n < 0) {
7272
throw {
7373
RE_EXN_ID: "Not_found",
@@ -1286,6 +1286,12 @@ function zip(l1, l2) {
12861286

12871287
let size = length;
12881288

1289+
let headExn = headOrThrow;
1290+
1291+
let tailExn = tailOrThrow;
1292+
1293+
let getExn = getOrThrow;
1294+
12891295
let makeByU = makeBy;
12901296

12911297
let mapU = map;
@@ -1357,11 +1363,14 @@ export {
13571363
size,
13581364
head,
13591365
headExn,
1366+
headOrThrow,
13601367
tail,
13611368
tailExn,
1369+
tailOrThrow,
13621370
add,
13631371
get,
13641372
getExn,
1373+
getOrThrow,
13651374
make,
13661375
makeByU,
13671376
makeBy,

lib/es6/Belt_Map.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ function getWithDefault(map, x, def) {
215215
return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp);
216216
}
217217

218-
function getExn(map, x) {
219-
return Belt_MapDict.getExn(map.data, x, map.cmp);
218+
function getOrThrow(map, x) {
219+
return Belt_MapDict.getOrThrow(map.data, x, map.cmp);
220220
}
221221

222222
function has(map, x) {
@@ -273,6 +273,8 @@ let everyU = every;
273273

274274
let someU = some;
275275

276+
let getExn = getOrThrow;
277+
276278
let updateU = update;
277279

278280
let mergeU = merge;
@@ -324,6 +326,7 @@ export {
324326
getUndefined,
325327
getWithDefault,
326328
getExn,
329+
getOrThrow,
327330
remove,
328331
removeMany,
329332
set,

lib/es6/Belt_MapDict.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined;
326326

327327
let getWithDefault = Belt_internalAVLtree.getWithDefault;
328328

329-
let getExn = Belt_internalAVLtree.getExn;
329+
let getExn = Belt_internalAVLtree.getOrThrow;
330+
331+
let getOrThrow = Belt_internalAVLtree.getOrThrow;
330332

331333
let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;
332334

@@ -386,6 +388,7 @@ export {
386388
getUndefined,
387389
getWithDefault,
388390
getExn,
391+
getOrThrow,
389392
checkInvariantInternal,
390393
remove,
391394
removeMany,

lib/es6/Belt_MapInt.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapInt.getUndefined;
218218

219219
let getWithDefault = Belt_internalMapInt.getWithDefault;
220220

221-
let getExn = Belt_internalMapInt.getExn;
221+
let getExn = Belt_internalMapInt.getOrThrow;
222+
223+
let getOrThrow = Belt_internalMapInt.getOrThrow;
222224

223225
let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;
224226

@@ -282,6 +284,7 @@ export {
282284
getUndefined,
283285
getWithDefault,
284286
getExn,
287+
getOrThrow,
285288
checkInvariantInternal,
286289
remove,
287290
removeMany,

lib/es6/Belt_MapString.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapString.getUndefined;
218218

219219
let getWithDefault = Belt_internalMapString.getWithDefault;
220220

221-
let getExn = Belt_internalMapString.getExn;
221+
let getExn = Belt_internalMapString.getOrThrow;
222+
223+
let getOrThrow = Belt_internalMapString.getOrThrow;
222224

223225
let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;
224226

@@ -282,6 +284,7 @@ export {
282284
getUndefined,
283285
getWithDefault,
284286
getExn,
287+
getOrThrow,
285288
checkInvariantInternal,
286289
remove,
287290
removeMany,

lib/es6/Belt_MutableMap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ function getWithDefault(m, x, def) {
257257
return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp);
258258
}
259259

260-
function getExn(m, x) {
261-
return Belt_internalAVLtree.getExn(m.data, x, m.cmp);
260+
function getOrThrow(m, x) {
261+
return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp);
262262
}
263263

264264
function has(m, x) {
@@ -318,6 +318,8 @@ let everyU = every;
318318

319319
let someU = some;
320320

321+
let getExn = getOrThrow;
322+
321323
let updateU = update;
322324

323325
let mapU = map;
@@ -361,6 +363,7 @@ export {
361363
getUndefined,
362364
getWithDefault,
363365
getExn,
366+
getOrThrow,
364367
checkInvariantInternal,
365368
remove,
366369
removeMany,

lib/es6/Belt_MutableMapInt.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ function getWithDefault(d, x, def) {
272272
return Belt_internalMapInt.getWithDefault(d.data, x, def);
273273
}
274274

275-
function getExn(d, x) {
276-
return Belt_internalMapInt.getExn(d.data, x);
275+
function getOrThrow(d, x) {
276+
return Belt_internalMapInt.getOrThrow(d.data, x);
277277
}
278278

279279
let cmpU = cmp;
@@ -288,6 +288,8 @@ let everyU = every;
288288

289289
let someU = some;
290290

291+
let getExn = getOrThrow;
292+
291293
let updateU = update;
292294

293295
let mapU = map;
@@ -329,6 +331,7 @@ export {
329331
getUndefined,
330332
getWithDefault,
331333
getExn,
334+
getOrThrow,
332335
checkInvariantInternal,
333336
remove,
334337
removeMany,

lib/es6/Belt_MutableMapString.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ function getWithDefault(d, x, def) {
272272
return Belt_internalMapString.getWithDefault(d.data, x, def);
273273
}
274274

275-
function getExn(d, x) {
276-
return Belt_internalMapString.getExn(d.data, x);
275+
function getOrThrow(d, x) {
276+
return Belt_internalMapString.getOrThrow(d.data, x);
277277
}
278278

279279
let cmpU = cmp;
@@ -288,6 +288,8 @@ let everyU = every;
288288

289289
let someU = some;
290290

291+
let getExn = getOrThrow;
292+
291293
let updateU = update;
292294

293295
let mapU = map;
@@ -329,6 +331,7 @@ export {
329331
getUndefined,
330332
getWithDefault,
331333
getExn,
334+
getOrThrow,
332335
checkInvariantInternal,
333336
remove,
334337
removeMany,

lib/es6/Belt_MutableQueue.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function peekUndefined(q) {
4949

5050
}
5151

52-
function peekExn(q) {
52+
function peekOrThrow(q) {
5353
let v = q.first;
5454
if (v !== undefined) {
5555
return v.content;
@@ -76,7 +76,7 @@ function pop(q) {
7676
}
7777
}
7878

79-
function popExn(q) {
79+
function popOrThrow(q) {
8080
let x = q.first;
8181
if (x !== undefined) {
8282
let next = x.next;
@@ -260,6 +260,10 @@ function fromArray(arr) {
260260
return q;
261261
}
262262

263+
let peekExn = peekOrThrow;
264+
265+
let popExn = popOrThrow;
266+
263267
let mapU = map;
264268

265269
let forEachU = forEach;
@@ -275,9 +279,11 @@ export {
275279
peek,
276280
peekUndefined,
277281
peekExn,
282+
peekOrThrow,
278283
pop,
279284
popUndefined,
280285
popExn,
286+
popOrThrow,
281287
copy,
282288
size,
283289
mapU,

0 commit comments

Comments
 (0)