From b9e3f330a29830537cfd1a3d64490280585c65bc Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Tue, 2 Apr 2024 09:36:03 +0200 Subject: [PATCH] Use native bigint type --- package-lock.json | 10 ++--- package.json | 4 +- scripts/DocTests.mjs | 4 +- src/Core__BigInt.res | 50 +++++++++++----------- src/Core__DataView.res | 8 ++-- src/Core__Type.res | 4 +- src/Core__Type.resi | 2 +- src/intl/Core__Intl__NumberFormat.res | 14 +++--- src/intl/Core__Intl__PluralRules.res | 5 +-- src/typed-arrays/Core__BigInt64Array.res | 7 ++- src/typed-arrays/Core__BigUint64Array.res | 7 ++- test/ObjectTests.mjs | 2 +- test/TempTests.mjs | 2 +- test/Test.mjs | 2 +- test/TypedArrayTests.res | 2 +- test/intl/Intl__CollatorTest.mjs | 4 +- test/intl/Intl__DateTimeFormatTest.mjs | 2 +- test/intl/Intl__ListFormatTest.mjs | 2 +- test/intl/Intl__NumberFormatTest.mjs | 2 +- test/intl/Intl__RelativeTimeFormatTest.mjs | 2 +- test/intl/Intl__SegmenterTest.mjs | 2 +- 21 files changed, 64 insertions(+), 73 deletions(-) diff --git a/package-lock.json b/package-lock.json index 701ec34b..10a4868a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,10 +11,10 @@ "devDependencies": { "@babel/code-frame": "7.18.6", "@rescript/tools": "^0.5.0", - "rescript": "11.1.0-rc.2" + "rescript": "11.1.0-rc.6" }, "peerDependencies": { - "rescript": ">=11.0.0 || ^11.1.0-rc.2" + "rescript": "^11.1.0-rc.6" } }, "node_modules/@babel/code-frame": { @@ -148,9 +148,9 @@ "dev": true }, "node_modules/rescript": { - "version": "11.1.0-rc.2", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.1.0-rc.2.tgz", - "integrity": "sha512-kCUtmsODEUF1Eth5ppc+yIK79HLI7CwRs1R4iopDek4FC58IqHSLT3K1XHGB39YCWuOuV9WMly+wksHRJcSLcw==", + "version": "11.1.0-rc.6", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.1.0-rc.6.tgz", + "integrity": "sha512-chaNkU5xvWC+NOKflmNiQDMj8wu1Vk+SX9vUH84m9gT9cGE49ml1rG25XUPlKQ4EJ+AR+0XYLfxxvzjKYC+qvQ==", "dev": true, "hasInstallScript": true, "bin": { diff --git a/package.json b/package.json index 3cfe7ed4..fd2b5b56 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,11 @@ "src/**/*.mjs" ], "peerDependencies": { - "rescript": ">=11.0.0 || ^11.1.0-rc.2" + "rescript": "^11.1.0-rc.6" }, "devDependencies": { "@babel/code-frame": "7.18.6", "@rescript/tools": "^0.5.0", - "rescript": "11.1.0-rc.2" + "rescript": "11.1.0-rc.6" } } diff --git a/scripts/DocTests.mjs b/scripts/DocTests.mjs index 4be7afab..609de09f 100644 --- a/scripts/DocTests.mjs +++ b/scripts/DocTests.mjs @@ -65,7 +65,7 @@ function prepareCompiler() { stdio: "ignore", cwd: compilerDir }); - var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json")), undefined); + var dict = JSON.parse(Fs.readFileSync(Path.join(corePath, "package.json"))); var currentCoreVersion; if (!Array.isArray(dict) && (dict === null || typeof dict !== "object") && typeof dict !== "number" && typeof dict !== "string" && typeof dict !== "boolean") { throw { @@ -179,7 +179,7 @@ function extractDocFromFile(file) { "doc", file ]); - return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString(), undefined)); + return Tools_Docgen.decodeFromJson(JSON.parse(spawn.stdout.toString())); } function getExamples(param) { diff --git a/src/Core__BigInt.res b/src/Core__BigInt.res index 2f2ab991..1ebbcf83 100644 --- a/src/Core__BigInt.res +++ b/src/Core__BigInt.res @@ -1,40 +1,38 @@ -type t = Js.Types.bigint_val +@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN" +@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN" -@val external asIntN: (~width: int, t) => t = "BigInt.asIntN" -@val external asUintN: (~width: int, t) => t = "BigInt.asUintN" +@val external fromString: string => bigint = "BigInt" +@val external fromInt: int => bigint = "BigInt" +@val external fromFloat: float => bigint = "BigInt" -@val external fromString: string => t = "BigInt" -@val external fromInt: int => t = "BigInt" -@val external fromFloat: float => t = "BigInt" +@send external toString: bigint => string = "toString" +@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString" +@send external toLocaleString: bigint => string = "toLocaleString" -@send external toString: t => string = "toString" -@send external toStringWithRadix: (t, ~radix: int) => string = "toString" -@send external toLocaleString: t => string = "toLocaleString" - -@val external toFloat: t => float = "Number" +@val external toFloat: bigint => float = "Number" let toInt = t => t->toFloat->Core__Int.fromFloat -external \"+": (t, t) => t = "%addfloat" -external \"-": (t, t) => t = "%subfloat" -external \"*": (t, t) => t = "%mulfloat" -external \"/": (t, t) => t = "%divfloat" +external \"+": (bigint, bigint) => bigint = "%addfloat" +external \"-": (bigint, bigint) => bigint = "%subfloat" +external \"*": (bigint, bigint) => bigint = "%mulfloat" +external \"/": (bigint, bigint) => bigint = "%divfloat" -external add: (t, t) => t = "%addfloat" -external sub: (t, t) => t = "%subfloat" -external mul: (t, t) => t = "%mulfloat" -external div: (t, t) => t = "%divfloat" +external add: (bigint, bigint) => bigint = "%addfloat" +external sub: (bigint, bigint) => bigint = "%subfloat" +external mul: (bigint, bigint) => bigint = "%mulfloat" +external div: (bigint, bigint) => bigint = "%divfloat" -@noalloc external mod: (t, t) => t = "?fmod_float" +@noalloc external mod: (bigint, bigint) => bigint = "?fmod_float" -external land: (t, t) => t = "%andint" -external lor: (t, t) => t = "%orint" -external lxor: (t, t) => t = "%xorint" +external land: (bigint, bigint) => bigint = "%andint" +external lor: (bigint, bigint) => bigint = "%orint" +external lxor: (bigint, bigint) => bigint = "%xorint" -external lsl: (t, t) => t = "%lslint" -external asr: (t, t) => t = "%asrint" +external lsl: (bigint, bigint) => bigint = "%lslint" +external asr: (bigint, bigint) => bigint = "%asrint" -let exp = (x: t, y: t) => { +let exp = (x: bigint, y: bigint) => { let _ = x let _ = y %raw(`x ** y`) diff --git a/src/Core__DataView.res b/src/Core__DataView.res index c40c92ad..83e09368 100644 --- a/src/Core__DataView.res +++ b/src/Core__DataView.res @@ -20,8 +20,8 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i @send external getFloat32: t => float = "getFloat32" @send external getFloat64: t => float = "getFloat64" -@send external getBigInt64: t => Core__BigInt.t = "getBigInt64" -@send external getBigUint64: t => Core__BigInt.t = "getBigUint64" +@send external getBigInt64: t => bigint = "getBigInt64" +@send external getBigUint64: t => bigint = "getBigUint64" @send external setInt8: (t, int) => unit = "setInt8" @send external setUint8: (t, int) => unit = "setUint8" @@ -33,5 +33,5 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i @send external setFloat32: (t, float) => unit = "setFloat32" @send external setFloat64: (t, float) => unit = "setFloat64" -@send external setBigInt64: (t, Core__BigInt.t) => unit = "setBigInt64" -@send external setBigUint64: (t, Core__BigInt.t) => unit = "setBigUint64" +@send external setBigInt64: (t, bigint) => unit = "setBigInt64" +@send external setBigUint64: (t, bigint) => unit = "setBigUint64" diff --git a/src/Core__Type.res b/src/Core__Type.res index 4680f491..3e89dacd 100644 --- a/src/Core__Type.res +++ b/src/Core__Type.res @@ -15,7 +15,7 @@ module Classify = { | Object(object) | Function(function) | Symbol(Core__Symbol.t) - | BigInt(Core__BigInt.t) + | BigInt(bigint) @val external _internalClass: 'a => string = "Object.prototype.toString.call" external _asBool: 'a => bool = "%identity" @@ -24,7 +24,7 @@ module Classify = { external _asObject: 'a => object = "%identity" external _asFunction: 'a => function = "%identity" external _asSymbol: 'a => Core__Symbol.t = "%identity" - external _asBigInt: 'a => Core__BigInt.t = "%identity" + external _asBigInt: 'a => bigint = "%identity" let classify = value => { switch _internalClass(value) { diff --git a/src/Core__Type.resi b/src/Core__Type.resi index c5d1d9be..35820cff 100644 --- a/src/Core__Type.resi +++ b/src/Core__Type.resi @@ -59,7 +59,7 @@ module Classify: { | Object(object) | Function(function) | Symbol(Core__Symbol.t) - | BigInt(Core__BigInt.t) + | BigInt(bigint) /** `classify(anyValue)` diff --git a/src/intl/Core__Intl__NumberFormat.res b/src/intl/Core__Intl__NumberFormat.res index 3929e8cf..befcc891 100644 --- a/src/intl/Core__Intl__NumberFormat.res +++ b/src/intl/Core__Intl__NumberFormat.res @@ -194,20 +194,16 @@ external formatIntToParts: (t, int) => array = "formatToParts" external formatIntRangeToParts: (t, ~start: int, ~end: int) => array = "formatRange" -@send external formatBigInt: (t, Core__BigInt.t) => string = "format" +@send external formatBigInt: (t, bigint) => string = "format" @send -external formatBigIntRange: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => array = - "formatRange" +external formatBigIntRange: (t, ~start: bigint, ~end: bigint) => array = "formatRange" @send -external formatBigIntToParts: (t, Core__BigInt.t) => array = "formatToParts" +external formatBigIntToParts: (t, bigint) => array = "formatToParts" @send -external formatBigIntRangeToParts: ( - t, - ~start: Core__BigInt.t, - ~end: Core__BigInt.t, -) => array = "formatRange" +external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array = + "formatRange" @send external formatString: (t, string) => string = "format" diff --git a/src/intl/Core__Intl__PluralRules.res b/src/intl/Core__Intl__PluralRules.res index 7831df0a..f69756ed 100644 --- a/src/intl/Core__Intl__PluralRules.res +++ b/src/intl/Core__Intl__PluralRules.res @@ -50,7 +50,7 @@ type rule = [#zero | #one | #two | #few | #many | #other] @send external select: (t, float) => rule = "select" @send external selectInt: (t, int) => rule = "select" -@send external selectBigInt: (t, Core__BigInt.t) => rule = "select" +@send external selectBigInt: (t, bigint) => rule = "select" @send external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange" @@ -59,5 +59,4 @@ external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange" external selectRangeInt: (t, ~start: int, ~end: int) => rule = "selectRange" @send -external selectRangeBigInt: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => rule = - "selectRange" +external selectRangeBigInt: (t, ~start: bigint, ~end: bigint) => rule = "selectRange" diff --git a/src/typed-arrays/Core__BigInt64Array.res b/src/typed-arrays/Core__BigInt64Array.res index 96b0e792..ba327c35 100644 --- a/src/typed-arrays/Core__BigInt64Array.res +++ b/src/typed-arrays/Core__BigInt64Array.res @@ -1,6 +1,6 @@ /** The `BigInt64Array` typed array represents an array of 64-bit signed integers in platform byte order. See [BigInt64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array) */ -type t = Core__TypedArray.t +type t = Core__TypedArray.t module Constants = { /**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT) @@ -12,7 +12,7 @@ module Constants = { /** `fromArray` creates a `BigInt64Array` from an array of values. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array) */ @new -external fromArray: array => t = "BigInt64Array" +external fromArray: array => t = "BigInt64Array" /** `fromBuffer` creates a `BigInt64Array` from an `ArrayBuffer.t`. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array) @@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigInt64Array.from" /** `fromArrayLikeOrIterableWithMap` creates a `BigInt64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ @val -external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t = - "BigInt64Array.from" +external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigInt64Array.from" diff --git a/src/typed-arrays/Core__BigUint64Array.res b/src/typed-arrays/Core__BigUint64Array.res index f0b6ac53..3e2e2a47 100644 --- a/src/typed-arrays/Core__BigUint64Array.res +++ b/src/typed-arrays/Core__BigUint64Array.res @@ -1,6 +1,6 @@ /** The `BigUint64Array` typed array represents an array of 64-bit unsigned integers in platform byte order. See [BigUint64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array) */ -type t = Core__TypedArray.t +type t = Core__TypedArray.t module Constants = { /**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT) @@ -12,7 +12,7 @@ module Constants = { /** `fromArray` creates a `BigUint64Array` from an array of values. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array) */ @new -external fromArray: array => t = "BigUint64Array" +external fromArray: array => t = "BigUint64Array" /** `fromBuffer` creates a `BigUint64Array` from an `ArrayBuffer.t`. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array) @@ -51,5 +51,4 @@ external fromArrayLikeOrIterable: 'a => t = "BigUint64Array.from" /** `fromArrayLikeOrIterableWithMap` creates a `BigUint64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ @val -external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => Core__BigInt.t) => t = - "BigUint64Array.from" +external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigUint64Array.from" diff --git a/test/ObjectTests.mjs b/test/ObjectTests.mjs index 2ad5a9a1..fd6355a2 100644 --- a/test/ObjectTests.mjs +++ b/test/ObjectTests.mjs @@ -386,7 +386,7 @@ Test.run([ 32 ], "is: bigint" - ], Caml_obj.equal(BigInt("123"), BigInt("123")), eq, true); + ], BigInt("123") === BigInt("123"), eq, true); Test.run([ [ diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 5a6c5551..4239421f 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -98,7 +98,7 @@ console.info("JSON"); console.info("---"); -var json = JSON.parse("{\"foo\": \"bar\"}", undefined); +var json = JSON.parse("{\"foo\": \"bar\"}"); var json$1 = Core__JSON.Classify.classify(json); diff --git a/test/Test.mjs b/test/Test.mjs index 170e6501..1fe28b2a 100644 --- a/test/Test.mjs +++ b/test/Test.mjs @@ -13,7 +13,7 @@ function print(value) { if (match === "object" || match === "bigint") { return Util.inspect(value); } else if (match === "string") { - return Core__Option.getExn(JSON.stringify(value, undefined, undefined)); + return Core__Option.getExn(JSON.stringify(value)); } else { return String(value); } diff --git a/test/TypedArrayTests.res b/test/TypedArrayTests.res index 91608e3a..746a18c2 100644 --- a/test/TypedArrayTests.res +++ b/test/TypedArrayTests.res @@ -32,7 +32,7 @@ let assertWillThrow = (message, f) => { } } -let areSame = (x: BigInt.t, y: BigInt.t) => BigInt.toString(x) == BigInt.toString(y) +let areSame = (x: bigint, y: bigint) => BigInt.toString(x) == BigInt.toString(y) // What's going on here? // assertTrue("big ints if different then not equal", () => num1 != num2) diff --git a/test/intl/Intl__CollatorTest.mjs b/test/intl/Intl__CollatorTest.mjs index a42c8e08..1548f993 100644 --- a/test/intl/Intl__CollatorTest.mjs +++ b/test/intl/Intl__CollatorTest.mjs @@ -24,7 +24,7 @@ var collator = new Intl.Collator(["en-US"], { Intl.Collator.supportedLocalesOf([ "en-US", "en-GB" - ], undefined); + ]); Intl.Collator.supportedLocalesOf([ "en-US", @@ -37,7 +37,7 @@ console.log(collator.resolvedOptions()); console.log(collator.compare("hi", "hï")); -console.log(Intl.Collator.supportedLocalesOf(["hi"], undefined)); +console.log(Intl.Collator.supportedLocalesOf(["hi"])); export { _collator , diff --git a/test/intl/Intl__DateTimeFormatTest.mjs b/test/intl/Intl__DateTimeFormatTest.mjs index 62e31e91..2d95e6d9 100644 --- a/test/intl/Intl__DateTimeFormatTest.mjs +++ b/test/intl/Intl__DateTimeFormatTest.mjs @@ -9,7 +9,7 @@ console.log("Intl.DateTimeFormat"); Intl.DateTimeFormat.supportedLocalesOf([ "en-US", "en-GB" - ], undefined); + ]); Intl.DateTimeFormat.supportedLocalesOf([ "en-US", diff --git a/test/intl/Intl__ListFormatTest.mjs b/test/intl/Intl__ListFormatTest.mjs index f4bb15e8..70d37c18 100644 --- a/test/intl/Intl__ListFormatTest.mjs +++ b/test/intl/Intl__ListFormatTest.mjs @@ -23,7 +23,7 @@ var _formatter = new Intl.ListFormat([ Intl.ListFormat.supportedLocalesOf([ "en-US", "en-GB" - ], undefined); + ]); Intl.ListFormat.supportedLocalesOf([ "en-US", diff --git a/test/intl/Intl__NumberFormatTest.mjs b/test/intl/Intl__NumberFormatTest.mjs index 9f8e02d9..dfde8138 100644 --- a/test/intl/Intl__NumberFormatTest.mjs +++ b/test/intl/Intl__NumberFormatTest.mjs @@ -15,7 +15,7 @@ var currencyFormatter = new Intl.NumberFormat(["fr-FR"], { console.log(Intl.NumberFormat.supportedLocalesOf([ "fr-FR", "en-US" - ], undefined)); + ])); console.log(currencyFormatter.format(123.23)); diff --git a/test/intl/Intl__RelativeTimeFormatTest.mjs b/test/intl/Intl__RelativeTimeFormatTest.mjs index 2afbbac3..9575d4e5 100644 --- a/test/intl/Intl__RelativeTimeFormatTest.mjs +++ b/test/intl/Intl__RelativeTimeFormatTest.mjs @@ -8,7 +8,7 @@ console.log("Intl.RelativeTimeFormat"); Intl.RelativeTimeFormat.supportedLocalesOf([ "en-US", "en-GB" - ], undefined); + ]); Intl.RelativeTimeFormat.supportedLocalesOf([ "en-US", diff --git a/test/intl/Intl__SegmenterTest.mjs b/test/intl/Intl__SegmenterTest.mjs index c1d6ecf0..707b4009 100644 --- a/test/intl/Intl__SegmenterTest.mjs +++ b/test/intl/Intl__SegmenterTest.mjs @@ -8,7 +8,7 @@ console.log("Intl.Segmenter"); Intl.Segmenter.supportedLocalesOf([ "en-US", "en-GB" - ], undefined); + ]); Intl.Segmenter.supportedLocalesOf([ "en-US",