Skip to content

Rename Belt functions from Exn to OrThrow #7581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@
- `List.getExn``List.getOrThrow`
- `List.tailExn``List.tailOrThrow`
- `List.headExn``List.headOrThrow`
- `Belt.Array.getExn``Belt.Array.getOrThrow`
- `Belt.Array.setExn``Belt.Array.setOrThrow`
- `Belt.Map.getExn``Belt.Map.getOrThrow`
- `Belt.MutableMap.getExn``Belt.MutableMap.getOrThrow`
- `Belt.Set.getExn``Belt.Set.getOrThrow`
- `Belt.MutableSet.getExn``Belt.MutableSet.getOrThrow`
- `Belt.List.getExn``Belt.List.getOrThrow`
- `Belt.List.tailExn``Belt.List.tailOrThrow`
- `Belt.List.headExn``Belt.List.headOrThrow`
- `Belt.MutableQueue.peekExn``Belt.MutableQueue.peekOrThrow`
- `Belt.MutableQueue.popExn``Belt.MutableQueue.popOrThrow`
- `Belt.Option.getExn``Belt.Option.getOrThrow`
- `Belt.Result.getExn``Belt.Result.getOrThrow`
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554, https://github.com/rescript-lang/rescript/pull/7581

#### :rocket: New Feature

Expand Down
37 changes: 29 additions & 8 deletions analysis/reanalyze/src/ExnLib.ml
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
let table = Hashtbl.create 15 in
let open Exn in
let beltArray = [("getExn", [assertFailure]); ("setExn", [assertFailure])] in
let beltArray =
[
("getExn", [assertFailure]);
("getOrThrow", [assertFailure]);
("setExn", [assertFailure]);
("setOrThrow", [assertFailure]);
]
in
let beltList =
[("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])]
[
("getExn", [notFound]);
("getOrThrow", [notFound]);
("headExn", [notFound]);
("headOrThrow", [notFound]);
("tailExn", [notFound]);
("tailOrThrow", [notFound]);
]
in
let beltMap = [("getExn", [notFound])] in
let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
let beltMutableMap = beltMap in
let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in
let beltMutableSet = [("getExn", [notFound])] in
let beltOption = [("getExn", [notFound])] in
let beltResult = [("getExn", [notFound])] in
let beltSet = [("getExn", [notFound])] in
let beltMutableQueue =
[
("peekExn", [notFound]);
("peekOrThrow", [notFound]);
("popExn", [notFound]);
("popOrThrow", [notFound]);
]
in
let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
let beltMutableSet = beltSet in
let beltOption = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
let beltResult = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
let bsJson =
(* bs-json *)
[
Expand Down
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"tests/tests/**/src/**",
"tests/tools_tests/**/src/**",
"analysis/examples/**/src/**",
"rewatch/**",
"lib/es6/**",
"lib/js/**",
"ninja/**",
Expand Down
12 changes: 9 additions & 3 deletions lib/es6/Belt_Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function get(arr, i) {

}

function getExn(arr, i) {
function getOrThrow(arr, i) {
if (!(i >= 0 && i < arr.length)) {
throw {
RE_EXN_ID: "Assert_failure",
Expand All @@ -34,13 +34,13 @@ function set(arr, i, v) {
}
}

function setExn(arr, i, v) {
function setOrThrow(arr, i, v) {
if (!(i >= 0 && i < arr.length)) {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"Belt_Array.res",
49,
51,
2
],
Error: new Error()
Expand Down Expand Up @@ -582,6 +582,10 @@ function init(n, f) {
return v;
}

let getExn = getOrThrow;

let setExn = setOrThrow;

let makeByU = makeBy;

let makeByAndShuffleU = makeByAndShuffle;
Expand Down Expand Up @@ -637,8 +641,10 @@ let initU = init;
export {
get,
getExn,
getOrThrow,
set,
setExn,
setOrThrow,
shuffleInPlace,
shuffle,
reverseInPlace,
Expand Down
15 changes: 12 additions & 3 deletions lib/es6/Belt_List.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function head(x) {

}

function headExn(x) {
function headOrThrow(x) {
if (x !== 0) {
return x.hd;
}
Expand All @@ -28,7 +28,7 @@ function tail(x) {

}

function tailExn(x) {
function tailOrThrow(x) {
if (x !== 0) {
return x.tl;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ function get(x, n) {
}
}

function getExn(x, n) {
function getOrThrow(x, n) {
if (n < 0) {
throw {
RE_EXN_ID: "Not_found",
Expand Down Expand Up @@ -1286,6 +1286,12 @@ function zip(l1, l2) {

let size = length;

let headExn = headOrThrow;

let tailExn = tailOrThrow;

let getExn = getOrThrow;

let makeByU = makeBy;

let mapU = map;
Expand Down Expand Up @@ -1357,11 +1363,14 @@ export {
size,
head,
headExn,
headOrThrow,
tail,
tailExn,
tailOrThrow,
add,
get,
getExn,
getOrThrow,
make,
makeByU,
makeBy,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Belt_Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ function getWithDefault(map, x, def) {
return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp);
}

function getExn(map, x) {
return Belt_MapDict.getExn(map.data, x, map.cmp);
function getOrThrow(map, x) {
return Belt_MapDict.getOrThrow(map.data, x, map.cmp);
}

function has(map, x) {
Expand Down Expand Up @@ -273,6 +273,8 @@ let everyU = every;

let someU = some;

let getExn = getOrThrow;

let updateU = update;

let mergeU = merge;
Expand Down Expand Up @@ -324,6 +326,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
remove,
removeMany,
set,
Expand Down
5 changes: 4 additions & 1 deletion lib/es6/Belt_MapDict.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined;

let getWithDefault = Belt_internalAVLtree.getWithDefault;

let getExn = Belt_internalAVLtree.getExn;
let getExn = Belt_internalAVLtree.getOrThrow;

let getOrThrow = Belt_internalAVLtree.getOrThrow;

let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;

Expand Down Expand Up @@ -386,6 +388,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
5 changes: 4 additions & 1 deletion lib/es6/Belt_MapInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapInt.getUndefined;

let getWithDefault = Belt_internalMapInt.getWithDefault;

let getExn = Belt_internalMapInt.getExn;
let getExn = Belt_internalMapInt.getOrThrow;

let getOrThrow = Belt_internalMapInt.getOrThrow;

let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;

Expand Down Expand Up @@ -282,6 +284,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
5 changes: 4 additions & 1 deletion lib/es6/Belt_MapString.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapString.getUndefined;

let getWithDefault = Belt_internalMapString.getWithDefault;

let getExn = Belt_internalMapString.getExn;
let getExn = Belt_internalMapString.getOrThrow;

let getOrThrow = Belt_internalMapString.getOrThrow;

let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;

Expand Down Expand Up @@ -282,6 +284,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Belt_MutableMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ function getWithDefault(m, x, def) {
return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp);
}

function getExn(m, x) {
return Belt_internalAVLtree.getExn(m.data, x, m.cmp);
function getOrThrow(m, x) {
return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp);
}

function has(m, x) {
Expand Down Expand Up @@ -318,6 +318,8 @@ let everyU = every;

let someU = some;

let getExn = getOrThrow;

let updateU = update;

let mapU = map;
Expand Down Expand Up @@ -361,6 +363,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Belt_MutableMapInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) {
return Belt_internalMapInt.getWithDefault(d.data, x, def);
}

function getExn(d, x) {
return Belt_internalMapInt.getExn(d.data, x);
function getOrThrow(d, x) {
return Belt_internalMapInt.getOrThrow(d.data, x);
}

let cmpU = cmp;
Expand All @@ -288,6 +288,8 @@ let everyU = every;

let someU = some;

let getExn = getOrThrow;

let updateU = update;

let mapU = map;
Expand Down Expand Up @@ -329,6 +331,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Belt_MutableMapString.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) {
return Belt_internalMapString.getWithDefault(d.data, x, def);
}

function getExn(d, x) {
return Belt_internalMapString.getExn(d.data, x);
function getOrThrow(d, x) {
return Belt_internalMapString.getOrThrow(d.data, x);
}

let cmpU = cmp;
Expand All @@ -288,6 +288,8 @@ let everyU = every;

let someU = some;

let getExn = getOrThrow;

let updateU = update;

let mapU = map;
Expand Down Expand Up @@ -329,6 +331,7 @@ export {
getUndefined,
getWithDefault,
getExn,
getOrThrow,
checkInvariantInternal,
remove,
removeMany,
Expand Down
10 changes: 8 additions & 2 deletions lib/es6/Belt_MutableQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function peekUndefined(q) {

}

function peekExn(q) {
function peekOrThrow(q) {
let v = q.first;
if (v !== undefined) {
return v.content;
Expand All @@ -76,7 +76,7 @@ function pop(q) {
}
}

function popExn(q) {
function popOrThrow(q) {
let x = q.first;
if (x !== undefined) {
let next = x.next;
Expand Down Expand Up @@ -260,6 +260,10 @@ function fromArray(arr) {
return q;
}

let peekExn = peekOrThrow;

let popExn = popOrThrow;

let mapU = map;

let forEachU = forEach;
Expand All @@ -275,9 +279,11 @@ export {
peek,
peekUndefined,
peekExn,
peekOrThrow,
pop,
popUndefined,
popExn,
popOrThrow,
copy,
size,
mapU,
Expand Down
Loading
Loading