Skip to content

Add migrations for Int.Bitwise #7705

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

Merged
merged 6 commits into from
Jul 24, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/es6/Stdlib_Int.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function clamp(min, max, value) {
}
}

function lnot(x) {
return x ^ -1;
}

let Bitwise = {
lnot: lnot
};

let Ref = {};

let Constants = {
Expand All @@ -75,6 +83,7 @@ export {
range,
rangeWithOptions,
clamp,
Bitwise,
Ref,
}
/* No side effect */
9 changes: 9 additions & 0 deletions lib/js/Stdlib_Int.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function clamp(min, max, value) {
}
}

function lnot(x) {
return x ^ -1;
}

let Bitwise = {
lnot: lnot
};

let Ref = {};

let Constants = {
Expand All @@ -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 */
12 changes: 12 additions & 0 deletions runtime/Stdlib_Int.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
41 changes: 40 additions & 1 deletion runtime/Stdlib_Int.resi
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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)

7 changes: 7 additions & 0 deletions tests/tools_tests/src/migrate/StdlibMigration_Int.res
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Original file line number Diff line number Diff line change
@@ -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)