From dbe89b767c35e96f01e8fb78022a6dcceac569c4 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 1 Dec 2026 21:25:47 +0000 Subject: [PATCH] Mark small Belt functions @inline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: Since #9479, other modules inline `@inline` functions, and #9484 marked the stdlib's small helpers, but Belt marked none, so every call to a one-line Belt wrapper such as `Belt.Option.getWithDefault` stayed a call. 33 functions are now `@inline`, chosen from the exported functions whose bodies other modules can store: - `Belt.Option` (9): `keep`, `forEach`, `mapWithDefault`, `map`, `flatMap`, `getWithDefault`, `orElse`, `isSome`, `isNone`; - `Belt.Result` (8): `mapWithDefault`, `map`, `flatMap`, `getWithDefault`, `isOk`, `isError`, `eq`, `cmp`; - lookups (5): `Belt.Array.get` and `set`, `Belt.List.head`, `tail` and `add`; - accessors (11): `size` of the six hash maps and sets, `isEmpty`, `size` and `peek` of `MutableQueue`, `isEmpty` and `top` of `MutableStack`. JS modified (a caller of Belt): Example: let computeArea = ((x, y, z)) => x * y * Belt.Option.getWithDefault(z, 1) let size = (q: Belt.MutableQueue.t) => Belt.MutableQueue.size(q) let hashSize = (h: Belt.HashMap.Int.t) => Belt.HashMap.Int.size(h) Before (js): function computeArea(param) { return (param[0] * param[1] | 0) * Belt_Option.getWithDefault(param[2], 1) | 0; } let size = Belt_MutableQueue.size; let hashSize = Belt_HashMapInt.size; After (js): function computeArea(param) { let z = param[2]; return (param[0] * param[1] | 0) * ( z !== undefined ? Primitive_option.valFromOption(z) : 1 ) | 0; } function size(q) { return q.length; } function hashSize(h) { return h.size; } JS modified (a Belt.Result caller): Example: let isOk = (a: result) => Belt.Result.isOk(a) let rcmp = (a: result, b) => Belt.Result.cmp(a, b, (x, y) => x - y) Before (js): let isOk = Belt_Result.isOk; function rcmp(a, b) { return Belt_Result.cmp(a, b, (x, y) => x - y | 0); } After (js): function isOk(a) { return a.TAG === "Ok"; } function rcmp(a, b) { if (a.TAG === "Ok") { if (b.TAG === "Ok") { return a._0 - b._0 | 0; } else { return 1; } } else if (b.TAG === "Ok") { return -1; } else { return 0; } } Review: What was left out? The wrappers of the map and set modules (`Belt.Map`, `Set`, the `Mutable…` ones and their `Int` and `String` variants): inlined, each call named Belt's internal modules (`Belt_internalAVLset`, `Belt_internalBucketsType`), read the `data` and `cmp` fields and moved its arguments into temporaries, so callers got longer and harder to read. For the same reason the constructors (`make`, `fromArray`, `clear`, `copy`, `MutableStack.push`): each call became a record literal or an internal call. `Int` and `Float` `fromString` added a temporary at every call. `Option.eq` and `cmp` came out larger, as `Option.equal` and `compare` did in #9484. Every `…OrThrow` and `…Exn` helper stays a call, and so do loops and functions that call module-local helpers, such as `List.length`, `Array.every` and `MutableStack.size`. Review: Why are the `…U` aliases not marked? An alias such as `let mapU = map` stores no body, so other modules still call it, and giving each its own body would change Belt's JavaScript. They are all deprecated. Review: How is a wrong `@inline` caught? Warning 113: Belt builds with warnings as errors. `MutableSet.mergeMany` failed it (it calls the module-local `addArrayMutate`) and is not marked. Belt's own JavaScript is unchanged, apart from the `assert` positions in `Belt_Array`, which move down by the added `@inline` lines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq Signed-off-by: Christoph Knittel --- changes/belt-inline-helpers.feature.md | 1 + packages/@rescript/belt/src/Belt_Array.res | 2 + packages/@rescript/belt/src/Belt_HashMap.res | 3 + .../@rescript/belt/src/Belt_HashMapInt.res | 3 + .../@rescript/belt/src/Belt_HashMapString.res | 3 + packages/@rescript/belt/src/Belt_HashSet.res | 3 + .../@rescript/belt/src/Belt_HashSetInt.res | 3 + .../@rescript/belt/src/Belt_HashSetString.res | 3 + packages/@rescript/belt/src/Belt_List.res | 3 + .../@rescript/belt/src/Belt_MutableQueue.res | 3 + .../@rescript/belt/src/Belt_MutableStack.res | 2 + packages/@rescript/belt/src/Belt_Option.res | 9 +++ packages/@rescript/belt/src/Belt_Result.res | 8 ++ .../testrepo/packages/dep02/src/Array.mjs | 19 +++-- .../src/ImmutableArray.res.js | 7 +- .../src/Records.res.js | 55 +++++++++++-- .../src/TestImmutableArray.res.js | 13 +++- .../src/nested/Tuples.res.js | 12 ++- .../src/nested/Types.res.js | 12 ++- .../src/belt_deferred_signature_copy_test.mjs | 9 ++- .../belt/src/belt_hashmap_test.mjs | 10 +-- .../belt/src/belt_hashset_int_test.mjs | 8 +- .../runtime_tests/belt/src/belt_list_test.mjs | 11 +-- .../belt/src/belt_result_alias_test.mjs | 10 --- .../runtime_tests/belt/src/bs_array_test.mjs | 26 ++++--- .../runtime_tests/belt/src/bs_queue_test.mjs | 78 ++++++++++--------- .../runtime_tests/belt/src/bs_stack_test.mjs | 2 +- 27 files changed, 218 insertions(+), 100 deletions(-) create mode 100644 changes/belt-inline-helpers.feature.md diff --git a/changes/belt-inline-helpers.feature.md b/changes/belt-inline-helpers.feature.md new file mode 100644 index 00000000000..a849a2a793a --- /dev/null +++ b/changes/belt-inline-helpers.feature.md @@ -0,0 +1 @@ +- Mark small Belt functions `@inline`, so calls to them compile to the code they run: the `Belt.Option` and `Belt.Result` combinators such as `map` and `getWithDefault`, `Belt.Result.eq` and `cmp`, `Belt.Array.get` and `set`, `Belt.List.head`, `tail` and `add`, and the `size`, `isEmpty`, `peek` and `top` accessors of the hash maps and sets, `MutableQueue` and `MutableStack`. diff --git a/packages/@rescript/belt/src/Belt_Array.res b/packages/@rescript/belt/src/Belt_Array.res index 11afbf34d54..9f21c8716c9 100644 --- a/packages/@rescript/belt/src/Belt_Array.res +++ b/packages/@rescript/belt/src/Belt_Array.res @@ -16,6 +16,7 @@ external getUnsafe: (t<'a>, int) => 'a = "%array_unsafe_get" external setUnsafe: (t<'a>, int, 'a) => unit = "%array_unsafe_set" /* external get: 'a t -> int -> 'a = "%array_safe_get" */ +@inline let get = (arr, i) => if i >= 0 && i < length(arr) { Some(getUnsafe(arr, i)) @@ -30,6 +31,7 @@ let getOrThrow = (arr, i) => { let getExn = getOrThrow +@inline let set = (arr, i, v) => if i >= 0 && i < length(arr) { setUnsafe(arr, i, v) diff --git a/packages/@rescript/belt/src/Belt_HashMap.res b/packages/@rescript/belt/src/Belt_HashMap.res index 340ff3f75fb..8567fe9a05b 100644 --- a/packages/@rescript/belt/src/Belt_HashMap.res +++ b/packages/@rescript/belt/src/Belt_HashMap.res @@ -14,7 +14,10 @@ type id<'a, 'id> = Belt_Id.hashable<'a, 'id> type t<'a, 'b, 'id> = N.t, eq<'a, 'id>, 'a, 'b> let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_HashMapInt.res b/packages/@rescript/belt/src/Belt_HashMapInt.res index 3782945bb62..41368d68f5d 100644 --- a/packages/@rescript/belt/src/Belt_HashMapInt.res +++ b/packages/@rescript/belt/src/Belt_HashMapInt.res @@ -173,7 +173,10 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_HashMapString.res b/packages/@rescript/belt/src/Belt_HashMapString.res index 9e442090c7a..2fdae9b756c 100644 --- a/packages/@rescript/belt/src/Belt_HashMapString.res +++ b/packages/@rescript/belt/src/Belt_HashMapString.res @@ -173,7 +173,10 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_HashSet.res b/packages/@rescript/belt/src/Belt_HashSet.res index d35e746c3f3..9e06bcc5f2a 100644 --- a/packages/@rescript/belt/src/Belt_HashSet.res +++ b/packages/@rescript/belt/src/Belt_HashSet.res @@ -142,7 +142,10 @@ let make = (type value identity, ~hintSize, ~id: id) => { } let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_HashSetInt.res b/packages/@rescript/belt/src/Belt_HashSetInt.res index 11bf5c2d6db..a082126dbe6 100644 --- a/packages/@rescript/belt/src/Belt_HashSetInt.res +++ b/packages/@rescript/belt/src/Belt_HashSetInt.res @@ -125,7 +125,10 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_HashSetString.res b/packages/@rescript/belt/src/Belt_HashSetString.res index 9de78e2e326..50f12c7e0f7 100644 --- a/packages/@rescript/belt/src/Belt_HashSetString.res +++ b/packages/@rescript/belt/src/Belt_HashSetString.res @@ -125,7 +125,10 @@ let has = (h, key) => { let make = (~hintSize) => C.make(~hintSize, ~hash=(), ~eq=()) let clear = C.clear + +@inline let size = h => h.C.size + let forEach = N.forEach let reduce = N.reduce let logStats = N.logStats diff --git a/packages/@rescript/belt/src/Belt_List.res b/packages/@rescript/belt/src/Belt_List.res index 1bcc9b2b103..c6c9072ac5e 100644 --- a/packages/@rescript/belt/src/Belt_List.res +++ b/packages/@rescript/belt/src/Belt_List.res @@ -62,6 +62,7 @@ external mutableCell: ('a, t<'a>) => t<'a> = "%makemutablelist" - the cell is not empty */ +@inline let head = x => switch x { | list{} => None @@ -76,6 +77,7 @@ let headOrThrow = x => let headExn = headOrThrow +@inline let tail = x => switch x { | list{} => None @@ -90,6 +92,7 @@ let tailOrThrow = x => let tailExn = tailOrThrow +@inline let add = (xs, x) => list{x, ...xs} /* Assume `n >=0` */ diff --git a/packages/@rescript/belt/src/Belt_MutableQueue.res b/packages/@rescript/belt/src/Belt_MutableQueue.res index 3912f22629b..0f9a2d2bf2e 100644 --- a/packages/@rescript/belt/src/Belt_MutableQueue.res +++ b/packages/@rescript/belt/src/Belt_MutableQueue.res @@ -47,6 +47,7 @@ let add = (q, x) => { } } +@inline let peek = q => switch q.first { /* same here could be v */ @@ -130,8 +131,10 @@ let rec copyMapAux = (qRes, prev, cell, f) => let map = (q, f) => copyMapAux({length: q.length, first: None, last: None}, None, q.first, f) +@inline let isEmpty = q => q.length == 0 +@inline let size = q => q.length let rec iterAux = (cell, f) => diff --git a/packages/@rescript/belt/src/Belt_MutableStack.res b/packages/@rescript/belt/src/Belt_MutableStack.res index 7b5db2a48a7..04c42f9e0ad 100644 --- a/packages/@rescript/belt/src/Belt_MutableStack.res +++ b/packages/@rescript/belt/src/Belt_MutableStack.res @@ -19,12 +19,14 @@ let copy = (s: t<_>): t<_> => {root: s.root} let push = (s, x) => s.root = Some({head: x, tail: s.root}) +@inline let top = s => switch s.root { | None => None | Some(x) => Some(x.head) } +@inline let isEmpty = s => s.root == None let pop = s => diff --git a/packages/@rescript/belt/src/Belt_Option.res b/packages/@rescript/belt/src/Belt_Option.res index 3c155b5055e..333c16960b8 100644 --- a/packages/@rescript/belt/src/Belt_Option.res +++ b/packages/@rescript/belt/src/Belt_Option.res @@ -4,12 +4,14 @@ * SPDX-License-Identifier: MIT */ +@inline let keep = (opt, p) => switch opt { | Some(x) as some if p(x) => some | _ => None } +@inline let forEach = (opt, f) => switch opt { | Some(x) => f(x) @@ -26,42 +28,49 @@ let getExn = getOrThrow external getUnsafe: option<'a> => 'a = "%identity" +@inline let mapWithDefault = (opt, default, f) => switch opt { | Some(x) => f(x) | None => default } +@inline let map = (opt, f) => switch opt { | Some(x) => Some(f(x)) | None => None } +@inline let flatMap = (opt, f) => switch opt { | Some(x) => f(x) | None => None } +@inline let getWithDefault = (opt, default) => switch opt { | Some(x) => x | None => default } +@inline let orElse = (opt, other) => switch opt { | Some(_) as some => some | None => other } +@inline let isSome = x => switch x { | Some(_) => true | None => false } +@inline let isNone = x => x == None let eq = (a, b, f) => diff --git a/packages/@rescript/belt/src/Belt_Result.res b/packages/@rescript/belt/src/Belt_Result.res index 23bbbfa4d8b..4e8a9688c78 100644 --- a/packages/@rescript/belt/src/Belt_Result.res +++ b/packages/@rescript/belt/src/Belt_Result.res @@ -16,42 +16,49 @@ let getOrThrow = x => let getExn = getOrThrow +@inline let mapWithDefault = (opt, default, f) => switch opt { | Ok(x) => f(x) | Error(_) => default } +@inline let map = (opt, f) => switch opt { | Ok(x) => Ok(f(x)) | Error(y) => Error(y) } +@inline let flatMap = (opt, f) => switch opt { | Ok(x) => f(x) | Error(y) => Error(y) } +@inline let getWithDefault = (opt, default) => switch opt { | Ok(x) => x | Error(_) => default } +@inline let isOk = x => switch x { | Ok(_) => true | Error(_) => false } +@inline let isError = x => switch x { | Ok(_) => false | Error(_) => true } +@inline let eq = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(a, b) @@ -60,6 +67,7 @@ let eq = (a, b, f) => | (Error(_), Error(_)) => true } +@inline let cmp = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(a, b) diff --git a/tests/build_tests/testrepo/packages/dep02/src/Array.mjs b/tests/build_tests/testrepo/packages/dep02/src/Array.mjs index 2af3e832d3c..2f55f77b460 100644 --- a/tests/build_tests/testrepo/packages/dep02/src/Array.mjs +++ b/tests/build_tests/testrepo/packages/dep02/src/Array.mjs @@ -9,7 +9,9 @@ function includes(prim0, prim1) { } function head(t) { - return Belt_Array.get(t, 0); + if (0 < t.length) { + return Primitive_option.some(t[0]); + } } function take(t, n) { @@ -17,7 +19,10 @@ function take(t, n) { } function last(t) { - return Belt_Array.get(t, t.length - 1 | 0); + let i = t.length - 1 | 0; + if (i >= 0 && i < t.length) { + return Primitive_option.some(t[i]); + } } function isEmpty(t) { @@ -90,8 +95,8 @@ function eqBy(_xs, _ys, fn) { while (true) { let ys = _ys; let xs = _xs; - let match = Belt_Array.get(xs, 0); - let match$1 = Belt_Array.get(ys, 0); + let match = 0 < xs.length ? Primitive_option.some(xs[0]) : undefined; + let match$1 = 0 < ys.length ? Primitive_option.some(ys[0]) : undefined; if (match === undefined) { return match$1 === undefined; } @@ -189,7 +194,7 @@ function indexOfBy(t, fn, value) { let _idx = 0; while (true) { let idx = _idx; - let value$p = Belt_Array.get(t, idx); + let value$p = idx >= 0 && idx < t.length ? Primitive_option.some(t[idx]) : undefined; if (value$p === undefined) { return; } @@ -202,8 +207,8 @@ function indexOfBy(t, fn, value) { } function swapAt(t, i, j) { - let match = Belt_Array.get(t, i); - let match$1 = Belt_Array.get(t, j); + let match = i >= 0 && i < t.length ? Primitive_option.some(t[i]) : undefined; + let match$1 = j >= 0 && j < t.length ? Primitive_option.some(t[j]) : undefined; if (match === undefined) { return t; } diff --git a/tests/gentype_tests/typescript-react-example/src/ImmutableArray.res.js b/tests/gentype_tests/typescript-react-example/src/ImmutableArray.res.js index b3685b361d1..47016c8679b 100644 --- a/tests/gentype_tests/typescript-react-example/src/ImmutableArray.res.js +++ b/tests/gentype_tests/typescript-react-example/src/ImmutableArray.res.js @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Belt_Array from "@rescript/belt/lib/es6/src/Belt_Array.res.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function fromArray(a) { return a.slice(0); @@ -18,7 +19,11 @@ function size(a) { return a.length; } -let get = Belt_Array.get; +function get(a, x) { + if (x >= 0 && x < a.length) { + return Primitive_option.some(a[x]); + } +} let getExn = Belt_Array.getExn; diff --git a/tests/gentype_tests/typescript-react-example/src/Records.res.js b/tests/gentype_tests/typescript-react-example/src/Records.res.js index 005782730a3..f1cba758389 100644 --- a/tests/gentype_tests/typescript-react-example/src/Records.res.js +++ b/tests/gentype_tests/typescript-react-example/src/Records.res.js @@ -2,11 +2,13 @@ import * as Belt_List from "@rescript/belt/lib/es6/src/Belt_List.res.js"; import * as Belt_Array from "@rescript/belt/lib/es6/src/Belt_Array.res.js"; -import * as Belt_Option from "@rescript/belt/lib/es6/src/Belt_Option.res.js"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function computeArea(param) { - return (param.x * param.y | 0) * Belt_Option.mapWithDefault(param.z, 1, n => n) | 0; + let z = param.z; + return (param.x * param.y | 0) * ( + z !== undefined ? Primitive_option.valFromOption(z) : 1 + ) | 0; } function coord2d(x, y) { @@ -17,14 +19,38 @@ function coord2d(x, y) { }; } -let getOpt = Belt_Option.mapWithDefault; +function getOpt(opt, $$default, foo) { + if (opt !== undefined) { + return foo(Primitive_option.valFromOption(opt)); + } else { + return $$default; + } +} function findAddress(business) { - return Belt_Option.mapWithDefault(business.address, /* [] */0, a => ({hd: a, tl: /* [] */0})); + let opt = business.address; + if (opt !== undefined) { + return {hd: Primitive_option.valFromOption(opt), tl: /* [] */0}; + } else { + return /* [] */0; + } } function findAllAddresses(businesses) { - return Belt_List.toArray(Belt_List.flatten(Belt_List.fromArray(Belt_Array.map(businesses, business => Belt_List.concat(Belt_Option.mapWithDefault(business.address, /* [] */0, a => ({hd: a, tl: /* [] */0})), Belt_Option.mapWithDefault(business.owner, /* [] */0, p => Belt_Option.mapWithDefault(p.address, /* [] */0, a => ({hd: a, tl: /* [] */0})))))))); + return Belt_List.toArray(Belt_List.flatten(Belt_List.fromArray(Belt_Array.map(businesses, business => { + let opt = business.address; + let tmp = opt !== undefined ? ({hd: Primitive_option.valFromOption(opt), tl: /* [] */0}) : /* [] */0; + let opt$1 = business.owner; + let f = p => { + let opt = p.address; + if (opt !== undefined) { + return {hd: Primitive_option.valFromOption(opt), tl: /* [] */0}; + } else { + return /* [] */0; + } + }; + return Belt_List.concat(tmp, opt$1 !== undefined ? f(Primitive_option.valFromOption(opt$1)) : /* [] */0); + })))); } function getPayload(param) { @@ -54,15 +80,28 @@ function getPayloadRecordPlusOne(param) { } function findAddress2(business) { - return Belt_Option.mapWithDefault(Primitive_option.fromNullable(business.address2), /* [] */0, a => ({hd: a, tl: /* [] */0})); + let opt = business.address2; + if (!(opt == null)) { + return {hd: opt, tl: /* [] */0}; + } else { + return /* [] */0; + } } function computeArea3(o) { - return (o.x * o.y | 0) * Belt_Option.mapWithDefault(Primitive_option.fromNullable(o.z), 1, n => n) | 0; + let tmp = o.x * o.y | 0; + let opt = o.z; + return tmp * ( + opt == null ? 1 : opt + ) | 0; } function computeArea4(o) { - return (o.x * o.y | 0) * Belt_Option.mapWithDefault(o.z, 1, n => n) | 0; + let tmp = o.x * o.y | 0; + let opt = o.z; + return tmp * ( + opt !== undefined ? Primitive_option.valFromOption(opt) : 1 + ) | 0; } function testMyRec(x) { diff --git a/tests/gentype_tests/typescript-react-example/src/TestImmutableArray.res.js b/tests/gentype_tests/typescript-react-example/src/TestImmutableArray.res.js index 07280d49f1f..31704263f5b 100644 --- a/tests/gentype_tests/typescript-react-example/src/TestImmutableArray.res.js +++ b/tests/gentype_tests/typescript-react-example/src/TestImmutableArray.res.js @@ -1,18 +1,25 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Belt_Array from "@rescript/belt/lib/es6/src/Belt_Array.res.js"; import * as ImmutableArray from "./ImmutableArray.res.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function testImmutableArrayGet(arr) { return ImmutableArray.$$Array.get(arr, 3); } function testBeltArrayGet(arr) { - return Belt_Array.get(arr, 3); + if (3 < arr.length) { + return Primitive_option.some(arr[3]); + } } function testBeltArraySet(arr) { - return Belt_Array.set(arr, 3, 4); + if (3 < arr.length) { + arr[3] = 4; + return true; + } else { + return false; + } } export { diff --git a/tests/gentype_tests/typescript-react-example/src/nested/Tuples.res.js b/tests/gentype_tests/typescript-react-example/src/nested/Tuples.res.js index eb4b380db0c..6686cee3b11 100644 --- a/tests/gentype_tests/typescript-react-example/src/nested/Tuples.res.js +++ b/tests/gentype_tests/typescript-react-example/src/nested/Tuples.res.js @@ -1,17 +1,23 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Belt_Option from "@rescript/belt/lib/es6/src/Belt_Option.res.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function testTuple(param) { return param[0] + param[1] | 0; } function computeArea(param) { - return (param[0] * param[1] | 0) * Belt_Option.mapWithDefault(param[2], 1, n => n) | 0; + let z = param[2]; + return (param[0] * param[1] | 0) * ( + z !== undefined ? Primitive_option.valFromOption(z) : 1 + ) | 0; } function computeAreaWithIdent(param) { - return (param[0] * param[1] | 0) * Belt_Option.mapWithDefault(param[2], 1, n => n) | 0; + let z = param[2]; + return (param[0] * param[1] | 0) * ( + z !== undefined ? Primitive_option.valFromOption(z) : 1 + ) | 0; } function computeAreaNoConverters(param) { diff --git a/tests/gentype_tests/typescript-react-example/src/nested/Types.res.js b/tests/gentype_tests/typescript-react-example/src/nested/Types.res.js index 6072a36bdfd..35fdf7d5b1b 100644 --- a/tests/gentype_tests/typescript-react-example/src/nested/Types.res.js +++ b/tests/gentype_tests/typescript-react-example/src/nested/Types.res.js @@ -1,13 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Belt_List from "@rescript/belt/lib/es6/src/Belt_List.res.js"; -import * as Belt_Option from "@rescript/belt/lib/es6/src/Belt_Option.res.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function swap(tree) { + let tmp = tree.label; + let opt = tree.right; + let tmp$1 = opt !== undefined ? Primitive_option.some(swap(Primitive_option.valFromOption(opt))) : undefined; + let opt$1 = tree.left; return { - label: tree.label, - left: Belt_Option.map(tree.right, swap), - right: Belt_Option.map(tree.left, swap) + label: tmp, + left: tmp$1, + right: opt$1 !== undefined ? Primitive_option.some(swap(Primitive_option.valFromOption(opt$1))) : undefined }; } diff --git a/tests/runtime_tests/belt/src/belt_deferred_signature_copy_test.mjs b/tests/runtime_tests/belt/src/belt_deferred_signature_copy_test.mjs index 64658a08c64..b17a1bb89cd 100644 --- a/tests/runtime_tests/belt/src/belt_deferred_signature_copy_test.mjs +++ b/tests/runtime_tests/belt/src/belt_deferred_signature_copy_test.mjs @@ -8,6 +8,7 @@ import * as Belt_Array from "@rescript/belt/src/Belt_Array.mjs"; import * as Test_utils from "./test_utils.mjs"; import * as Belt_Option from "@rescript/belt/src/Belt_Option.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; let C = { D: undefined @@ -39,7 +40,11 @@ let set = Belt_Set.fromArray([ ], IntCmp); function orZero(x) { - return Belt_Option.getWithDefault(x, 0); + if (x !== undefined) { + return Primitive_option.valFromOption(x); + } else { + return 0; + } } let Extended = { @@ -103,7 +108,7 @@ Mocha.describe("Belt_deferred_signature_copy_test", () => { Test_utils.eq("File \"belt_deferred_signature_copy_test.res\", line 59, characters 7-14", 2, 2); }); Mocha.test("include and recursive modules", () => { - Test_utils.eq("File \"belt_deferred_signature_copy_test.res\", line 62, characters 7-14", 0, Belt_Option.getWithDefault(undefined, 0)); + Test_utils.eq("File \"belt_deferred_signature_copy_test.res\", line 62, characters 7-14", 0, 0); Test_utils.eq("File \"belt_deferred_signature_copy_test.res\", line 63, characters 7-14", 3, Tree.size({ TAG: "Node", _0: [ diff --git a/tests/runtime_tests/belt/src/belt_hashmap_test.mjs b/tests/runtime_tests/belt/src/belt_hashmap_test.mjs index 0999ac84eda..272422f758d 100644 --- a/tests/runtime_tests/belt/src/belt_hashmap_test.mjs +++ b/tests/runtime_tests/belt/src/belt_hashmap_test.mjs @@ -27,7 +27,7 @@ Mocha.describe("Belt_hashmap_test", () => { let u = Belt_Array.concat(Array_data_util.randomRange(30, 100), Array_data_util.randomRange(40, 120)); let v = Belt_Array.zip(u, u); let xx = Belt_HashMap.fromArray(v, Y); - Test_utils.eq("File \"belt_hashmap_test.res\", line 21, characters 7-14", Belt_HashMap.size(xx), 91); + Test_utils.eq("File \"belt_hashmap_test.res\", line 21, characters 7-14", xx.size, 91); Test_utils.eq("File \"belt_hashmap_test.res\", line 22, characters 7-14", Belt_SortArray.stableSortBy(Belt_HashMap.keysToArray(xx), cmp), Array_data_util.range(30, 120)); }); Mocha.test("mergeMany", () => { @@ -50,21 +50,21 @@ Mocha.describe("Belt_hashmap_test", () => { ] ]); Test_utils.eq("File \"belt_hashmap_test.res\", line 27, characters 7-14", Belt_HashMap.get(empty, 2), 2); - Test_utils.eq("File \"belt_hashmap_test.res\", line 28, characters 7-14", Belt_HashMap.size(empty), 3); + Test_utils.eq("File \"belt_hashmap_test.res\", line 28, characters 7-14", empty.size, 3); }); Mocha.test("remove", () => { let u = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); let v = Belt_HashMap.make(40, Y); Belt_HashMap.mergeMany(v, Belt_Array.zip(u, u)); - Test_utils.eq("File \"belt_hashmap_test.res\", line 35, characters 7-14", Belt_HashMap.size(v), 100001); + Test_utils.eq("File \"belt_hashmap_test.res\", line 35, characters 7-14", v.size, 100001); for (let i = 0; i <= 1000; ++i) { Belt_HashMap.remove(v, i); } - Test_utils.eq("File \"belt_hashmap_test.res\", line 39, characters 7-14", Belt_HashMap.size(v), 99000); + Test_utils.eq("File \"belt_hashmap_test.res\", line 39, characters 7-14", v.size, 99000); for (let i$1 = 0; i$1 <= 2000; ++i$1) { Belt_HashMap.remove(v, i$1); } - Test_utils.eq("File \"belt_hashmap_test.res\", line 43, characters 7-14", Belt_HashMap.size(v), 98000); + Test_utils.eq("File \"belt_hashmap_test.res\", line 43, characters 7-14", v.size, 98000); Test_utils.ok("File \"belt_hashmap_test.res\", line 44, characters 7-14", Belt_Array.every(Array_data_util.range(2001, 100000), x => Belt_HashMap.has(v, x))); }); }); diff --git a/tests/runtime_tests/belt/src/belt_hashset_int_test.mjs b/tests/runtime_tests/belt/src/belt_hashset_int_test.mjs index 9f692d8cc6f..ab31f6740e8 100644 --- a/tests/runtime_tests/belt/src/belt_hashset_int_test.mjs +++ b/tests/runtime_tests/belt/src/belt_hashset_int_test.mjs @@ -24,7 +24,7 @@ Mocha.describe("Belt_hashset_int_test", () => { Mocha.test("fromArray", () => { let u = Belt_Array.concat(Array_data_util.randomRange(30, 100), Array_data_util.randomRange(40, 120)); let v = Belt_HashSetInt.fromArray(u); - Test_utils.eq("File \"belt_hashset_int_test.res\", line 22, characters 7-14", Belt_HashSetInt.size(v), 91); + Test_utils.eq("File \"belt_hashset_int_test.res\", line 22, characters 7-14", v.size, 91); let xs = Belt_SetInt.toArray(Belt_SetInt.fromArray(Belt_HashSetInt.toArray(v))); Test_utils.eq("File \"belt_hashset_int_test.res\", line 24, characters 7-14", xs, Array_data_util.range(30, 120)); Test_utils.eq("File \"belt_hashset_int_test.res\", line 26, characters 7-14", Belt_HashSetInt.reduce(v, 0, add), 6825); @@ -34,15 +34,15 @@ Mocha.describe("Belt_hashset_int_test", () => { let u = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); let v = Belt_HashSetInt.make(40); Belt_HashSetInt.mergeMany(v, u); - Test_utils.eq("File \"belt_hashset_int_test.res\", line 34, characters 7-14", Belt_HashSetInt.size(v), 100001); + Test_utils.eq("File \"belt_hashset_int_test.res\", line 34, characters 7-14", v.size, 100001); for (let i = 0; i <= 1000; ++i) { Belt_HashSetInt.remove(v, i); } - Test_utils.eq("File \"belt_hashset_int_test.res\", line 38, characters 7-14", Belt_HashSetInt.size(v), 99000); + Test_utils.eq("File \"belt_hashset_int_test.res\", line 38, characters 7-14", v.size, 99000); for (let i$1 = 0; i$1 <= 2000; ++i$1) { Belt_HashSetInt.remove(v, i$1); } - Test_utils.eq("File \"belt_hashset_int_test.res\", line 42, characters 7-14", Belt_HashSetInt.size(v), 98000); + Test_utils.eq("File \"belt_hashset_int_test.res\", line 42, characters 7-14", v.size, 98000); }); Mocha.test("stableSortInPlace", () => { let u0 = Belt_HashSetInt.fromArray(Array_data_util.randomRange(0, 100000)); diff --git a/tests/runtime_tests/belt/src/belt_list_test.mjs b/tests/runtime_tests/belt/src/belt_list_test.mjs index e65ba30b768..9b117154250 100644 --- a/tests/runtime_tests/belt/src/belt_list_test.mjs +++ b/tests/runtime_tests/belt/src/belt_list_test.mjs @@ -6,6 +6,7 @@ import * as Belt_Array from "@rescript/belt/src/Belt_Array.mjs"; import * as Test_utils from "./test_utils.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function sum(xs) { let v = 0; @@ -475,13 +476,13 @@ Mocha.describe("Belt_list_test", () => { Mocha.test("head/tail etc.", () => { let succx = x => x + 1 | 0; Test_utils.eq("File \"belt_list_test.res\", line 230, characters 7-14", [ - Belt_List.head(length_10_id), - Belt_List.tail(length_10_id) + length_10_id !== 0 ? Primitive_option.some(length_10_id.hd) : undefined, + length_10_id !== 0 ? length_10_id.tl : undefined ], [ 0, Belt_List.drop(length_10_id, 1) ]); - Test_utils.eq("File \"belt_list_test.res\", line 231, characters 7-14", Belt_List.head(/* [] */0), undefined); + Test_utils.eq("File \"belt_list_test.res\", line 231, characters 7-14", /* [] */0 !== 0 ? Primitive_option.some(/* [] */(0).hd) : undefined, undefined); Test_utils.throws("File \"belt_list_test.res\", line 232, characters 11-18", () => Belt_List.headExn(/* [] */0)); Test_utils.throws("File \"belt_list_test.res\", line 233, characters 11-18", () => { Belt_List.tailExn(/* [] */0); @@ -496,7 +497,7 @@ Mocha.describe("Belt_list_test", () => { Test_utils.eq("File \"belt_list_test.res\", line 237, characters 7-14", Belt_List.headExn({hd: 1, tl: /* [] */0}), 1); Test_utils.eq("File \"belt_list_test.res\", line 238, characters 7-14", Belt_List.tailExn({hd: 1, tl: /* [] */0}), /* [] */0); Belt_List.forEachWithIndex(length_10_id, (i, x) => Test_utils.eq("File \"belt_list_test.res\", line 239, characters 50-57", Belt_List.get(length_10_id, i), x)); - Test_utils.eq("File \"belt_list_test.res\", line 240, characters 7-14", Belt_List.tail(/* [] */0), undefined); + Test_utils.eq("File \"belt_list_test.res\", line 240, characters 7-14", /* [] */0 !== 0 ? /* [] */(0).tl : undefined, undefined); Test_utils.eq("File \"belt_list_test.res\", line 241, characters 7-14", Belt_List.drop(/* [] */0, 3), undefined); Test_utils.eq("File \"belt_list_test.res\", line 242, characters 7-14", Belt_List.mapWithIndex(/* [] */0, (i, x) => i + x | 0), /* [] */0); Test_utils.eq("File \"belt_list_test.res\", line 243, characters 7-14", Belt_List.get(length_10_id, -1), undefined); @@ -553,7 +554,7 @@ Mocha.describe("Belt_list_test", () => { Test_utils.eq("File \"belt_list_test.res\", line 302, characters 7-14", Belt_List.some2({hd: 0, tl: {hd: 3, tl: /* [] */0}}, {hd: 3, tl: {hd: 2, tl: /* [] */0}}, (x, y) => x > y), true); Test_utils.eq("File \"belt_list_test.res\", line 303, characters 7-14", Belt_List.some2({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}, {hd: -1, tl: {hd: -2, tl: /* [] */0}}, (x, y) => x === y), false); }); - Mocha.test("add", () => Test_utils.eq("File \"belt_list_test.res\", line 307, characters 7-14", Belt_List.add(Belt_List.add(/* [] */0, 3), 2), {hd: 2, tl: {hd: 3, tl: /* [] */0}})); + Mocha.test("add", () => Test_utils.eq("File \"belt_list_test.res\", line 307, characters 7-14", {hd: 2, tl: {hd: 3, tl: /* [] */0}}, {hd: 2, tl: {hd: 3, tl: /* [] */0}})); Mocha.test("cmp", () => { Test_utils.ok("File \"belt_list_test.res\", line 311, characters 7-14", Belt_List.cmp({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}, {hd: 0, tl: {hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}}, Primitive_int.compare) > 0); Test_utils.ok("File \"belt_list_test.res\", line 312, characters 7-14", Belt_List.cmp({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: {hd: 4, tl: /* [] */0}}}}, {hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}, Primitive_int.compare) > 0); diff --git a/tests/runtime_tests/belt/src/belt_result_alias_test.mjs b/tests/runtime_tests/belt/src/belt_result_alias_test.mjs index c2db2db3003..4d11a49592a 100644 --- a/tests/runtime_tests/belt/src/belt_result_alias_test.mjs +++ b/tests/runtime_tests/belt/src/belt_result_alias_test.mjs @@ -1,15 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Belt_Result from "@rescript/belt/src/Belt_Result.mjs"; -Belt_Result.map({ - TAG: "Ok", - _0: "Test" -}, r => "Value: " + r); - -Belt_Result.getWithDefault(Belt_Result.map({ - TAG: "Error", - _0: "error" -}, r => "Value: " + r), "success"); /* Not a pure module */ diff --git a/tests/runtime_tests/belt/src/bs_array_test.mjs b/tests/runtime_tests/belt/src/bs_array_test.mjs index 2e7ab8e8869..9d9545310e1 100644 --- a/tests/runtime_tests/belt/src/bs_array_test.mjs +++ b/tests/runtime_tests/belt/src/bs_array_test.mjs @@ -6,6 +6,7 @@ import * as Belt_Array from "@rescript/belt/src/Belt_Array.mjs"; import * as Test_utils from "./test_utils.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function push(prim0, prim1) { prim0.push(prim1); @@ -25,11 +26,11 @@ Mocha.describe("Bs_array_test", () => { 2 ]; Test_utils.eq("File \"bs_array_test.res\", line 22, characters 6-13", [ - Belt_Array.get(v, 0), - Belt_Array.get(v, 1), - Belt_Array.get(v, 2), - Belt_Array.get(v, 3), - Belt_Array.get(v, -1) + 0 < v.length ? Primitive_option.some(v[0]) : undefined, + 1 < v.length ? Primitive_option.some(v[1]) : undefined, + 2 < v.length ? Primitive_option.some(v[2]) : undefined, + 3 < v.length ? Primitive_option.some(v[3]) : undefined, + undefined ], [ 1, 2, @@ -68,15 +69,20 @@ Mocha.describe("Bs_array_test", () => { 0, 1 ], 2, 0)); - Test_utils.ok("File \"bs_array_test.res\", line 37, characters 7-14", !Belt_Array.set([ + let arr = [ 1, 2 - ], 2, 0)); + ]; + Test_utils.ok("File \"bs_array_test.res\", line 37, characters 7-14", !( + 2 < arr.length ? (arr[2] = 0, true) : false + )); let v$1 = [ 1, 2 ]; - if (!Belt_Array.set(v$1, 0, 0)) { + if (!( + 0 < v$1.length ? (v$1[0] = 0, true) : false + )) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -92,7 +98,9 @@ Mocha.describe("Bs_array_test", () => { 1, 2 ]; - if (!Belt_Array.set(v$2, 1, 0)) { + if (!( + 1 < v$2.length ? (v$2[1] = 0, true) : false + )) { throw { RE_EXN_ID: "Assert_failure", _1: [ diff --git a/tests/runtime_tests/belt/src/bs_queue_test.mjs b/tests/runtime_tests/belt/src/bs_queue_test.mjs index 8ee291545d3..577effd591d 100644 --- a/tests/runtime_tests/belt/src/bs_queue_test.mjs +++ b/tests/runtime_tests/belt/src/bs_queue_test.mjs @@ -23,7 +23,7 @@ function queueAdd(q, x) { Mocha.describe("Bs_queue_test", () => { Mocha.test("basic queue operations", () => { let q = Belt_MutableQueue.make(); - if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && Belt_MutableQueue.size(q) === 0)) { + if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -34,7 +34,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)), [1]) && Belt_MutableQueue.size(q) === 1)) { + if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)), [1]) && q.length === 1)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -48,7 +48,7 @@ Mocha.describe("Bs_queue_test", () => { if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 2), q)), [ 1, 2 - ]) && Belt_MutableQueue.size(q) === 2)) { + ]) && q.length === 2)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -63,7 +63,7 @@ Mocha.describe("Bs_queue_test", () => { 1, 2, 3 - ]) && Belt_MutableQueue.size(q) === 3)) { + ]) && q.length === 3)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -79,7 +79,7 @@ Mocha.describe("Bs_queue_test", () => { 2, 3, 4 - ]) && Belt_MutableQueue.size(q) === 4)) { + ]) && q.length === 4)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -105,7 +105,7 @@ Mocha.describe("Bs_queue_test", () => { 2, 3, 4 - ]) && Belt_MutableQueue.size(q) === 3)) { + ]) && q.length === 3)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -130,7 +130,7 @@ Mocha.describe("Bs_queue_test", () => { if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [ 3, 4 - ]) && Belt_MutableQueue.size(q) === 2)) { + ]) && q.length === 2)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -152,7 +152,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [4]) && Belt_MutableQueue.size(q) === 1)) { + if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [4]) && q.length === 1)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -174,7 +174,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && Belt_MutableQueue.size(q) === 0)) { + if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -244,7 +244,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q) === 0) { + if (q.length === 0) { return; } throw { @@ -388,7 +388,7 @@ Mocha.describe("Bs_queue_test", () => { Belt_MutableQueue.add(q, i); } Belt_MutableQueue.clear(q); - if (Belt_MutableQueue.size(q) !== 0) { + if (q.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -485,7 +485,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q1) !== 10) { + if (q1.length !== 10) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -496,7 +496,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 10) { + if (q2.length !== 10) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -536,7 +536,7 @@ Mocha.describe("Bs_queue_test", () => { }); Mocha.test("queue size and isEmpty operations", () => { let q = Belt_MutableQueue.make(); - if (!Belt_MutableQueue.isEmpty(q)) { + if (q.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -549,7 +549,7 @@ Mocha.describe("Bs_queue_test", () => { } for (let i = 1; i <= 10; ++i) { Belt_MutableQueue.add(q, i); - if (Belt_MutableQueue.size(q) !== i) { + if (q.length !== i) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -560,7 +560,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.isEmpty(q)) { + if (q.length === 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -573,7 +573,7 @@ Mocha.describe("Bs_queue_test", () => { } } for (let i$1 = 10; i$1 >= 1; --i$1) { - if (Belt_MutableQueue.size(q) !== i$1) { + if (q.length !== i$1) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -584,7 +584,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.isEmpty(q)) { + if (q.length === 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -597,7 +597,7 @@ Mocha.describe("Bs_queue_test", () => { } Belt_MutableQueue.popExn(q); } - if (Belt_MutableQueue.size(q) !== 0) { + if (q.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -608,7 +608,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.isEmpty(q)) { + if (q.length === 0) { return; } throw { @@ -645,7 +645,7 @@ Mocha.describe("Bs_queue_test", () => { Mocha.test("queue transfer operations - empty to empty", () => { let q1 = Belt_MutableQueue.make(); let q2 = Belt_MutableQueue.make(); - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -667,7 +667,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 0) { + if (q2.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -690,7 +690,7 @@ Mocha.describe("Bs_queue_test", () => { }; } Belt_MutableQueue.transfer(q1, q2); - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -712,7 +712,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 0) { + if (q2.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -742,7 +742,7 @@ Mocha.describe("Bs_queue_test", () => { for (let i = 1; i <= 4; ++i) { Belt_MutableQueue.add(q1, i); } - if (Belt_MutableQueue.size(q1) !== 4) { + if (q1.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -769,7 +769,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 0) { + if (q2.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -792,7 +792,7 @@ Mocha.describe("Bs_queue_test", () => { }; } Belt_MutableQueue.transfer(q1, q2); - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -814,7 +814,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 4) { + if (q2.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -849,7 +849,7 @@ Mocha.describe("Bs_queue_test", () => { for (let i = 5; i <= 8; ++i) { Belt_MutableQueue.add(q2, i); } - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -871,7 +871,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 4) { + if (q2.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -899,7 +899,7 @@ Mocha.describe("Bs_queue_test", () => { }; } Belt_MutableQueue.transfer(q1, q2); - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -921,7 +921,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 4) { + if (q2.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -959,7 +959,7 @@ Mocha.describe("Bs_queue_test", () => { for (let i$1 = 5; i$1 <= 8; ++i$1) { Belt_MutableQueue.add(q2, i$1); } - if (Belt_MutableQueue.size(q1) !== 4) { + if (q1.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -986,7 +986,7 @@ Mocha.describe("Bs_queue_test", () => { Error: new Error() }; } - if (Belt_MutableQueue.size(q2) !== 4) { + if (q2.length !== 4) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1014,7 +1014,7 @@ Mocha.describe("Bs_queue_test", () => { }; } Belt_MutableQueue.transfer(q1, q2); - if (Belt_MutableQueue.size(q1) !== 0) { + if (q1.length !== 0) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1046,7 +1046,7 @@ Mocha.describe("Bs_queue_test", () => { 3, 4 ]; - if (Belt_MutableQueue.size(q2) !== 8) { + if (q2.length !== 8) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1095,8 +1095,10 @@ Mocha.describe("Bs_queue_test", () => { 2, 3 ]); - Test_utils.ok("File \"bs_queue_test.res\", line 196, characters 7-14", Belt_MutableQueue.isEmpty(Belt_MutableQueue.fromArray([]))); - Test_utils.ok("File \"bs_queue_test.res\", line 197, characters 7-14", Belt_MutableQueue.isEmpty(Belt_MutableQueue.map(Belt_MutableQueue.fromArray([]), x => x + 1 | 0))); + let q$1 = Belt_MutableQueue.fromArray([]); + Test_utils.ok("File \"bs_queue_test.res\", line 196, characters 7-14", q$1.length === 0); + let q$2 = Belt_MutableQueue.map(Belt_MutableQueue.fromArray([]), x => x + 1 | 0); + Test_utils.ok("File \"bs_queue_test.res\", line 197, characters 7-14", q$2.length === 0); }); }); diff --git a/tests/runtime_tests/belt/src/bs_stack_test.mjs b/tests/runtime_tests/belt/src/bs_stack_test.mjs index e6c8f4b34d1..246a4bcabb4 100644 --- a/tests/runtime_tests/belt/src/bs_stack_test.mjs +++ b/tests/runtime_tests/belt/src/bs_stack_test.mjs @@ -14,7 +14,7 @@ function inOrder(v) { Belt_MutableStack.push(s, v$1); current = v$1.left; }; - while (!Belt_MutableStack.isEmpty(s)) { + while (s.root !== undefined) { current = Belt_MutableStack.popOrThrow(s); let v$2 = current; Belt_MutableQueue.add(q, v$2.value);