From 44fd7f98f0aad2d3790844261602948d057f2dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 11:40:28 +0200 Subject: [PATCH 1/6] Add Int.Bitwise.land migration --- lib/es6/Stdlib_Int.js | 9 +++++++++ lib/js/Stdlib_Int.js | 9 +++++++++ runtime/Stdlib_Int.res | 12 ++++++++++++ runtime/Stdlib_Int.resi | 18 +++++++++++++++++- .../expected/StdlibMigration_Int.res.expected | 1 + .../src/migrate/StdlibMigration_Int.res | 1 + .../Migrated_StdlibMigration_Array.res | 1 + .../migrated/Migrated_StdlibMigration_Int.res | 1 + 8 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/tools_tests/src/expected/StdlibMigration_Int.res.expected create mode 100644 tests/tools_tests/src/migrate/StdlibMigration_Int.res create mode 100644 tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res diff --git a/lib/es6/Stdlib_Int.js b/lib/es6/Stdlib_Int.js index 4993a6297c..fda2d75c1f 100644 --- a/lib/es6/Stdlib_Int.js +++ b/lib/es6/Stdlib_Int.js @@ -62,6 +62,14 @@ function clamp(min, max, value) { } } +function lnot(x) { + return x ^ -1; +} + +let Bitwise = { + lnot: lnot +}; + let Ref = {}; let Constants = { @@ -75,6 +83,7 @@ export { range, rangeWithOptions, clamp, + Bitwise, Ref, } /* No side effect */ diff --git a/lib/js/Stdlib_Int.js b/lib/js/Stdlib_Int.js index 5e6dbb7ced..cece54b2a0 100644 --- a/lib/js/Stdlib_Int.js +++ b/lib/js/Stdlib_Int.js @@ -62,6 +62,14 @@ function clamp(min, max, value) { } } +function lnot(x) { + return x ^ -1; +} + +let Bitwise = { + lnot: lnot +}; + let Ref = {}; let Constants = { @@ -74,5 +82,6 @@ exports.fromString = fromString; exports.range = range; exports.rangeWithOptions = rangeWithOptions; exports.clamp = clamp; +exports.Bitwise = Bitwise; exports.Ref = Ref; /* No side effect */ diff --git a/runtime/Stdlib_Int.res b/runtime/Stdlib_Int.res index 3228ed4114..cef0ee6b27 100644 --- a/runtime/Stdlib_Int.res +++ b/runtime/Stdlib_Int.res @@ -105,6 +105,18 @@ external shiftLeft: (int, int) => int = "%lslint" external shiftRight: (int, int) => int = "%asrint" external shiftRightUnsigned: (int, int) => int = "%lsrint" +module Bitwise = { + external land: (int, int) => int = "%andint" + external lor: (int, int) => int = "%orint" + external lxor: (int, int) => int = "%xorint" + + external lsl: (int, int) => int = "%lslint" + external lsr: (int, int) => int = "%lsrint" + external asr: (int, int) => int = "%asrint" + + let lnot = x => lxor(x, -1) +} + external ignore: int => unit = "%ignore" module Ref = { diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index 384e351287..fa977e9494 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -186,7 +186,7 @@ Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" - `RangeError`: If `digits` is not between 1 and 100 (inclusive). Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits. - + */ @send @deprecated("Use `toPrecision` instead") external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" @@ -471,6 +471,22 @@ Int.shiftRightUnsigned(4, 1) == 2 */ external shiftRightUnsigned: (int, int) => int = "%lsrint" +module Bitwise = { + @deprecated({ + reason: "Use `Int.bitwiseAnd` instead", + migrate: Int.bitwiseAnd + }) + external land: (int, int) => int = "%andint" + external lor: (int, int) => int = "%orint" + external lxor: (int, int) => int = "%xorint" + + external lsl: (int, int) => int = "%lslint" + external lsr: (int, int) => int = "%lsrint" + external asr: (int, int) => int = "%asrint" + + let lnot: int => int +} + /** `ignore(int)` ignores the provided int and returns unit. diff --git a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected new file mode 100644 index 0000000000..37413b15e4 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected @@ -0,0 +1 @@ +StdlibMigration_Int.res: File did not need migration diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Int.res b/tests/tools_tests/src/migrate/StdlibMigration_Int.res new file mode 100644 index 0000000000..983e50fd57 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Int.res @@ -0,0 +1 @@ +let result = Int.Bitwise.land(1, 2) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res index d398c936d3..4f18613d4e 100644 --- a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res @@ -166,3 +166,4 @@ let reduceRight2 = Array.reduceRight([1, 2, 3], 0, (acc, x) => acc + x) let reduceRighti1 = [1, 2, 3]->Array.reduceRightWithIndex(0, (acc, x, i) => acc + x + i) let reduceRighti2 = Array.reduceRightWithIndex([1, 2, 3], 0, (acc, x, i) => acc + x + i) + diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res new file mode 100644 index 0000000000..37413b15e4 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res @@ -0,0 +1 @@ +StdlibMigration_Int.res: File did not need migration From c6eec41acbc1d405e372c0f2ea750b479b7583ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 13:13:10 +0200 Subject: [PATCH 2/6] Add missing brackets to migration --- runtime/Stdlib_Int.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index fa977e9494..0705436e0a 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -474,7 +474,7 @@ external shiftRightUnsigned: (int, int) => int = "%lsrint" module Bitwise = { @deprecated({ reason: "Use `Int.bitwiseAnd` instead", - migrate: Int.bitwiseAnd + migrate: Int.bitwiseAnd() }) external land: (int, int) => int = "%andint" external lor: (int, int) => int = "%orint" From 9ef29c0be13480187c89d8d6c0de82bd1230f800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 13:18:37 +0200 Subject: [PATCH 3/6] Add migrations for remaining Int.Bitwise functions --- runtime/Stdlib_Int.resi | 24 +++++++++++++++++++ .../expected/StdlibMigration_Int.res.expected | 9 ++++++- .../src/migrate/StdlibMigration_Int.res | 6 +++++ .../migrated/Migrated_StdlibMigration_Int.res | 9 ++++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index 0705436e0a..c3b61bb1af 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -477,13 +477,37 @@ module Bitwise = { migrate: Int.bitwiseAnd() }) external land: (int, int) => int = "%andint" + @deprecated({ + reason: "Use `Int.bitwiseOr` instead", + migrate: Int.bitwiseOr() + }) external lor: (int, int) => int = "%orint" + @deprecated({ + reason: "Use `Int.bitwiseXor` instead", + migrate: Int.bitwiseXor() + }) external lxor: (int, int) => int = "%xorint" + @deprecated({ + reason: "Use `Int.shiftLeft` instead", + migrate: Int.shiftLeft() + }) external lsl: (int, int) => int = "%lslint" + @deprecated({ + reason: "Use `Int.shiftRightUnsigned` instead", + migrate: Int.shiftRightUnsigned() + }) external lsr: (int, int) => int = "%lsrint" + @deprecated({ + reason: "Use `Int.shiftRight` instead", + migrate: Int.shiftRight() + }) external asr: (int, int) => int = "%asrint" + @deprecated({ + reason: "Use `Int.bitwiseNot` instead", + migrate: Int.bitwiseNot() + }) let lnot: int => int } diff --git a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected index 37413b15e4..d38801fc09 100644 --- a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected +++ b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected @@ -1 +1,8 @@ -StdlibMigration_Int.res: File did not need migration +let result = Int.bitwiseAnd(1, 2) +let result = Int.bitwiseOr(1, 2) +let result = Int.bitwiseXor(1, 2) +let result = Int.shiftLeft(1, 2) +let result = Int.shiftRightUnsigned(1, 2) +let result = Int.shiftLeft(1, 2) +let result = Int.bitwiseNot(0) + diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Int.res b/tests/tools_tests/src/migrate/StdlibMigration_Int.res index 983e50fd57..8c587f823e 100644 --- a/tests/tools_tests/src/migrate/StdlibMigration_Int.res +++ b/tests/tools_tests/src/migrate/StdlibMigration_Int.res @@ -1 +1,7 @@ let result = Int.Bitwise.land(1, 2) +let result = Int.Bitwise.lor(1, 2) +let result = Int.Bitwise.lxor(1, 2) +let result = Int.Bitwise.lsl(1, 2) +let result = Int.Bitwise.lsr(1, 2) +let result = Int.Bitwise.asr(1, 2) +let result = Int.Bitwise.lnot(0) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res index 37413b15e4..677d7e37e9 100644 --- a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res @@ -1 +1,8 @@ -StdlibMigration_Int.res: File did not need migration +let result = Int.bitwiseAnd(1, 2) +let result = Int.bitwiseOr(1, 2) +let result = Int.bitwiseXor(1, 2) +let result = Int.shiftLeft(1, 2) +let result = Int.shiftRightUnsigned(1, 2) +let result = Int.shiftRight(1, 2) +let result = Int.bitwiseNot(0) + From fc507e4237d7a9d15094115a9d411463dbd9f34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 13:21:14 +0200 Subject: [PATCH 4/6] Remove newline in toPrecisionWithPrecision doc comment --- runtime/Stdlib_Int.resi | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index c3b61bb1af..67c2ae3f56 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -186,7 +186,6 @@ Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" - `RangeError`: If `digits` is not between 1 and 100 (inclusive). Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits. - */ @send @deprecated("Use `toPrecision` instead") external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" From 55d051b769aebc8f438ba05a9350815b88dd5e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 13:26:50 +0200 Subject: [PATCH 5/6] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a1241e7db..ffb6023adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Configuration fields `bs-dependencies`, `bs-dev-dependencies` and `bsc-flags` are now deprecated in favor of `dependencies`, `dev-dependencies` and `compiler-flags`. https://github.com/rescript-lang/rescript/pull/7658 - Better error message if platform binaries package is not found. https://github.com/rescript-lang/rescript/pull/7698 +- `Int.Bitwise` functions have been deprecated. https://github.com/rescript-lang/rescript/pull/7705 #### :house: Internal From 0e5349ace4104882e27d76b3d7db811df0a5d163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Thu, 24 Jul 2025 13:41:02 +0200 Subject: [PATCH 6/6] Update StdlibMigration_Int expectation --- tests/tools_tests/src/expected/StdlibMigration_Int.res.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected index d38801fc09..677d7e37e9 100644 --- a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected +++ b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected @@ -3,6 +3,6 @@ let result = Int.bitwiseOr(1, 2) let result = Int.bitwiseXor(1, 2) let result = Int.shiftLeft(1, 2) let result = Int.shiftRightUnsigned(1, 2) -let result = Int.shiftLeft(1, 2) +let result = Int.shiftRight(1, 2) let result = Int.bitwiseNot(0)