Skip to content

More deprecations in Pervasives; add Stdlib.Pair and Stdlib.Int.Ref #7371

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 7 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -16,6 +16,7 @@

- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364
- Fix signature of `throw`. https://github.com/rescript-lang/rescript/pull/7365
- More deprecations in `Pervasives`; add `Stdlib.Pair` and `Stdlib.Int.Ref`. https://github.com/rescript-lang/rescript/pull/7371

#### :house: Internal

Expand Down
5 changes: 4 additions & 1 deletion lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
118,
119,
4
],
Error: new Error()
Expand Down Expand Up @@ -63,6 +63,8 @@ let Option;

let Ordering;

let Pair;

let $$Promise;

let $$RegExp;
Expand Down Expand Up @@ -138,6 +140,7 @@ export {
$$Object,
Option,
Ordering,
Pair,
$$Promise,
$$RegExp,
Result,
Expand Down
3 changes: 3 additions & 0 deletions lib/es6/Stdlib_Int.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function bitwiseNot(x) {
return x ^ -1;
}

let Ref = {};

let Constants = {
minValue: -2147483648,
maxValue: 2147483647
Expand All @@ -78,5 +80,6 @@ export {
rangeWithOptions,
clamp,
bitwiseNot,
Ref,
}
/* No side effect */
1 change: 1 addition & 0 deletions lib/es6/Stdlib_Pair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
5 changes: 4 additions & 1 deletion lib/js/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
118,
119,
4
],
Error: new Error()
Expand Down Expand Up @@ -63,6 +63,8 @@ let Option;

let Ordering;

let Pair;

let $$Promise;

let $$RegExp;
Expand Down Expand Up @@ -137,6 +139,7 @@ exports.Nullable = Nullable;
exports.$$Object = $$Object;
exports.Option = Option;
exports.Ordering = Ordering;
exports.Pair = Pair;
exports.$$Promise = $$Promise;
exports.$$RegExp = $$RegExp;
exports.Result = Result;
Expand Down
3 changes: 3 additions & 0 deletions lib/js/Stdlib_Int.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function bitwiseNot(x) {
return x ^ -1;
}

let Ref = {};

let Constants = {
minValue: -2147483648,
maxValue: 2147483647
Expand All @@ -77,4 +79,5 @@ exports.range = range;
exports.rangeWithOptions = rangeWithOptions;
exports.clamp = clamp;
exports.bitwiseNot = bitwiseNot;
exports.Ref = Ref;
/* No side effect */
1 change: 1 addition & 0 deletions lib/js/Stdlib_Pair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
6 changes: 6 additions & 0 deletions packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ lib/es6/Stdlib_Nullable.js
lib/es6/Stdlib_Object.js
lib/es6/Stdlib_Option.js
lib/es6/Stdlib_Ordering.js
lib/es6/Stdlib_Pair.js
lib/es6/Stdlib_Promise.js
lib/es6/Stdlib_RegExp.js
lib/es6/Stdlib_Result.js
Expand Down Expand Up @@ -358,6 +359,7 @@ lib/js/Stdlib_Nullable.js
lib/js/Stdlib_Object.js
lib/js/Stdlib_Option.js
lib/js/Stdlib_Ordering.js
lib/js/Stdlib_Pair.js
lib/js/Stdlib_Promise.js
lib/js/Stdlib_RegExp.js
lib/js/Stdlib_Result.js
Expand Down Expand Up @@ -1151,6 +1153,10 @@ lib/ocaml/Stdlib_Ordering.cmi
lib/ocaml/Stdlib_Ordering.cmj
lib/ocaml/Stdlib_Ordering.cmt
lib/ocaml/Stdlib_Ordering.res
lib/ocaml/Stdlib_Pair.cmi
lib/ocaml/Stdlib_Pair.cmj
lib/ocaml/Stdlib_Pair.cmt
lib/ocaml/Stdlib_Pair.res
lib/ocaml/Stdlib_Promise.cmi
lib/ocaml/Stdlib_Promise.cmj
lib/ocaml/Stdlib_Promise.cmt
Expand Down
30 changes: 29 additions & 1 deletion runtime/Pervasives.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ external throw: exn => 'a = "%raise"

/* Composition operators */

@deprecated("This will be removed in v13")
external \"|>": ('a, 'a => 'b) => 'b = "%revapply"

@deprecated("This will be removed in v13")
external \"@@": ('a => 'b, 'a) => 'b = "%apply"

/* Debugging */
Expand Down Expand Up @@ -92,7 +95,10 @@ external \"||": (bool, bool) => bool = "%sequor"

/* Integer operations */

@deprecated("Use `x => x + 1` instead. This will be removed in v13")
external succ: int => int = "%succint"

@deprecated("Use `x => x - 1` instead. This will be removed in v13")
external pred: int => int = "%predint"

@deprecated("Use `Math.abs` instead. This will be removed in v13")
Expand All @@ -103,14 +109,25 @@ let abs = x =>
-x
}

@deprecated("Use `Int.bitwiseAnd` instead. This will be removed in v13")
external land: (int, int) => int = "%andint"

@deprecated("Use `Int.bitwiseOr` instead. This will be removed in v13")
external lor: (int, int) => int = "%orint"

@deprecated("Use `Int.bitwiseXor` instead. This will be removed in v13")
external lxor: (int, int) => int = "%xorint"

@deprecated("Use `Int.bitwiseNot` instead. This will be removed in v13")
let lnot = x => lxor(x, -1)

@deprecated("Use `Int.shiftLeft` instead. This will be removed in v13")
external lsl: (int, int) => int = "%lslint"

@deprecated("Use `Int.shiftRightUnsigned` instead. This will be removed in v13")
external lsr: (int, int) => int = "%lsrint"

@deprecated("Use `Int.shiftRight` instead. This will be removed in v13")
external asr: (int, int) => int = "%asrint"

@deprecated("Use `Int.Constants.maxValue` instead. This will be removed in v13")
Expand Down Expand Up @@ -266,16 +283,25 @@ external ignore: 'a => unit = "%ignore"

/* Pair operations */

@deprecated("Use `Pair.first` instead. This will be removed in v13")
external fst: (('a, 'b)) => 'a = "%field0"

@deprecated("Use `Pair.second` instead. This will be removed in v13")
external snd: (('a, 'b)) => 'b = "%field1"

/* References */

type ref<'a> = {mutable contents: 'a}
external ref: 'a => ref<'a> = "%makeref"
external \"!": ref<'a> => 'a = "%refget"
external \":=": (ref<'a>, 'a) => unit = "%refset"

@deprecated("Do not use. This will be removed in v13")
external \"!": ref<'a> => 'a = "%refget"

@deprecated("Use `Int.Ref.increment` instead. This will be removed in v13")
external incr: ref<int> => unit = "%incr"

@deprecated("Use `Int.Ref.decrement` instead. This will be removed in v13")
external decr: ref<int> => unit = "%decr"

/* String conversion functions */
Expand Down Expand Up @@ -310,6 +336,7 @@ external string_of_int: int => string = "String"
@deprecated("Use `Int.fromString` instead. This will be removed in v13") @scope("Number")
external int_of_string: string => int = "parseInt"

@deprecated("Use `Int.fromString` instead. This will be removed in v13")
let int_of_string_opt = s =>
switch int_of_string(s) {
| n if n == %raw("NaN") => None
Expand All @@ -330,4 +357,5 @@ let rec \"@" = (l1, l2) =>

/* Miscellaneous */

@deprecated("This will be removed in v13")
type int32 = int
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cometkim Do you know why this is here at all? It was added in #7108.

1 change: 1 addition & 0 deletions runtime/Stdlib.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Nullable = Stdlib_Nullable
module Object = Stdlib_Object
module Option = Stdlib_Option
module Ordering = Stdlib_Ordering
module Pair = Stdlib_Pair
module Promise = Stdlib_Promise
module RegExp = Stdlib_RegExp
module Result = Stdlib_Result
Expand Down
7 changes: 7 additions & 0 deletions runtime/Stdlib_Int.res
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,10 @@ external shiftRight: (int, int) => int = "%asrint"
external shiftRightUnsigned: (int, int) => int = "%lsrint"

external ignore: int => unit = "%ignore"

module Ref = {
type t = Pervasives.ref<int>

external increment: t => unit = "%incr"
external decrement: t => unit = "%decr"
}
30 changes: 30 additions & 0 deletions runtime/Stdlib_Int.resi
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,33 @@ external shiftRightUnsigned: (int, int) => int = "%lsrint"
without having to store or process it further.
*/
external ignore: int => unit = "%ignore"

module Ref: {
type t = Pervasives.ref<int>

/**
`increment(intRef)` increments the value of the provided reference by 1.

## Examples

```rescript
let myRef = ref(4)
Int.Ref.increment(myRef)
assertEqual(myRef.contents, 5)
```
*/
external increment: t => unit = "%incr"

/**
`decrement(intRef)` decrements the value of the provided reference by 1.

## Examples

```rescript
let myRef = ref(4)
Int.Ref.decrement(myRef)
assertEqual(myRef.contents, 3)
```
*/
external decrement: t => unit = "%decr"
}
35 changes: 35 additions & 0 deletions runtime/Stdlib_Pair.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/***
This module provides functions to work with pairs, which are 2-element tuples.
*/

type t<'a, 'b> = ('a, 'b)

/**
`first(pair)` returns the first element of a pair.

## Examples

```rescript
Pair.first((1, 2))->assertEqual(1)
```
*/
external first: (('a, 'b)) => 'a = "%field0"

/**
`second(pair)` returns the second element of a pair.

## Examples

```rescript
Pair.second((1, 2))->assertEqual(2)
```
*/
external second: (('a, 'b)) => 'b = "%field1"

/**
`ignore(option)` ignores the provided pair and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
without having to store or process it further.
*/
external ignore: ('a, 'b) => unit = "%ignore"
Loading