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 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..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" @@ -471,6 +470,46 @@ 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" + @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 +} + /** `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..677d7e37e9 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected @@ -0,0 +1,8 @@ +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) + 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..8c587f823e --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Int.res @@ -0,0 +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_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..677d7e37e9 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res @@ -0,0 +1,8 @@ +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) +