Skip to content

Commit 1ad3d50

Browse files
authoredApr 1, 2025··
More deprecations in Pervasives; add Stdlib.Pair and Stdlib.Int.Ref (#7371)
* More deprecations in Pervasives * Add Stdlib.Pair * Add Int.Ref.increment/decrement * CHANGELOG * Get rid of Pervasives_mini * Fix CHANGELOG category * Add Pair.equal, Pair.compare
1 parent 9942dbd commit 1ad3d50

15 files changed

+222
-112
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
2323
- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899
2424

25+
#### :nail_care: Polish
26+
27+
- More deprecations in `Pervasives`; add `Stdlib.Pair` and `Stdlib.Int.Ref`. https://github.com/rescript-lang/rescript/pull/7371
28+
2529
# 12.0.0-alpha.10
2630

2731
#### :rocket: New Feature

‎lib/es6/Stdlib.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
118,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -63,6 +63,8 @@ let Option;
6363

6464
let Ordering;
6565

66+
let Pair;
67+
6668
let $$Promise;
6769

6870
let $$RegExp;
@@ -138,6 +140,7 @@ export {
138140
$$Object,
139141
Option,
140142
Ordering,
143+
Pair,
141144
$$Promise,
142145
$$RegExp,
143146
Result,

‎lib/es6/Stdlib_Int.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function bitwiseNot(x) {
6666
return x ^ -1;
6767
}
6868

69+
let Ref = {};
70+
6971
let Constants = {
7072
minValue: -2147483648,
7173
maxValue: 2147483647
@@ -78,5 +80,6 @@ export {
7880
rangeWithOptions,
7981
clamp,
8082
bitwiseNot,
83+
Ref,
8184
}
8285
/* No side effect */

‎lib/es6/Stdlib_Pair.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
4+
function equal(param, param$1, eq1, eq2) {
5+
if (eq1(param[0], param$1[0])) {
6+
return eq2(param[1], param$1[1]);
7+
} else {
8+
return false;
9+
}
10+
}
11+
12+
function compare(param, param$1, cmp1, cmp2) {
13+
let result = cmp1(param[0], param$1[0]);
14+
if (result !== 0) {
15+
return result;
16+
} else {
17+
return cmp2(param[1], param$1[1]);
18+
}
19+
}
20+
21+
export {
22+
equal,
23+
compare,
24+
}
25+
/* No side effect */

‎lib/js/Stdlib.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
118,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -63,6 +63,8 @@ let Option;
6363

6464
let Ordering;
6565

66+
let Pair;
67+
6668
let $$Promise;
6769

6870
let $$RegExp;
@@ -137,6 +139,7 @@ exports.Nullable = Nullable;
137139
exports.$$Object = $$Object;
138140
exports.Option = Option;
139141
exports.Ordering = Ordering;
142+
exports.Pair = Pair;
140143
exports.$$Promise = $$Promise;
141144
exports.$$RegExp = $$RegExp;
142145
exports.Result = Result;

‎lib/js/Stdlib_Int.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function bitwiseNot(x) {
6666
return x ^ -1;
6767
}
6868

69+
let Ref = {};
70+
6971
let Constants = {
7072
minValue: -2147483648,
7173
maxValue: 2147483647
@@ -77,4 +79,5 @@ exports.range = range;
7779
exports.rangeWithOptions = rangeWithOptions;
7880
exports.clamp = clamp;
7981
exports.bitwiseNot = bitwiseNot;
82+
exports.Ref = Ref;
8083
/* No side effect */

‎lib/js/Stdlib_Pair.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
4+
function equal(param, param$1, eq1, eq2) {
5+
if (eq1(param[0], param$1[0])) {
6+
return eq2(param[1], param$1[1]);
7+
} else {
8+
return false;
9+
}
10+
}
11+
12+
function compare(param, param$1, cmp1, cmp2) {
13+
let result = cmp1(param[0], param$1[0]);
14+
if (result !== 0) {
15+
return result;
16+
} else {
17+
return cmp2(param[1], param$1[1]);
18+
}
19+
}
20+
21+
exports.equal = equal;
22+
exports.compare = compare;
23+
/* No side effect */

‎packages/artifacts.txt

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ lib/es6/Stdlib_Nullable.js
186186
lib/es6/Stdlib_Object.js
187187
lib/es6/Stdlib_Option.js
188188
lib/es6/Stdlib_Ordering.js
189+
lib/es6/Stdlib_Pair.js
189190
lib/es6/Stdlib_Promise.js
190191
lib/es6/Stdlib_RegExp.js
191192
lib/es6/Stdlib_Result.js
@@ -358,6 +359,7 @@ lib/js/Stdlib_Nullable.js
358359
lib/js/Stdlib_Object.js
359360
lib/js/Stdlib_Option.js
360361
lib/js/Stdlib_Ordering.js
362+
lib/js/Stdlib_Pair.js
361363
lib/js/Stdlib_Promise.js
362364
lib/js/Stdlib_RegExp.js
363365
lib/js/Stdlib_Result.js
@@ -1151,6 +1153,10 @@ lib/ocaml/Stdlib_Ordering.cmi
11511153
lib/ocaml/Stdlib_Ordering.cmj
11521154
lib/ocaml/Stdlib_Ordering.cmt
11531155
lib/ocaml/Stdlib_Ordering.res
1156+
lib/ocaml/Stdlib_Pair.cmi
1157+
lib/ocaml/Stdlib_Pair.cmj
1158+
lib/ocaml/Stdlib_Pair.cmt
1159+
lib/ocaml/Stdlib_Pair.res
11541160
lib/ocaml/Stdlib_Promise.cmi
11551161
lib/ocaml/Stdlib_Promise.cmj
11561162
lib/ocaml/Stdlib_Promise.cmt

‎runtime/Pervasives.res

+43-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
@deprecated("Do not use. This will be removed in v13")
2-
external /* Internal */
3-
4-
__unsafe_cast: 'a => 'b = "%identity"
2+
external __unsafe_cast: 'a => 'b = "%identity"
53

64
/* Exceptions */
7-
@deprecated(
8-
"`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead"
9-
)
10-
external raise: exn => 'a = "%raise"
11-
12-
@deprecated("Use custom exception instead")
13-
let failwith = s => throw(Failure(s))
14-
15-
@deprecated("Use custom exception instead")
16-
let invalid_arg = s => throw(Invalid_argument(s))
17-
18-
@deprecated("Use custom exception instead") exception Exit
195

206
/**
217
Raises the given exception, terminating execution unless caught by a surrounding try/catch block.
@@ -36,9 +22,25 @@ assertEqual(result, "Caught exception: Out of milk")
3622
*/
3723
external throw: exn => 'a = "%raise"
3824

25+
@deprecated(
26+
"`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead"
27+
)
28+
external raise: exn => 'a = "%raise"
29+
30+
@deprecated("Use custom exception instead")
31+
let failwith = s => throw(Failure(s))
32+
33+
@deprecated("Use custom exception instead")
34+
let invalid_arg = s => throw(Invalid_argument(s))
35+
36+
@deprecated("Use custom exception instead") exception Exit
37+
3938
/* Composition operators */
4039

40+
@deprecated("This will be removed in v13")
4141
external \"|>": ('a, 'a => 'b) => 'b = "%revapply"
42+
43+
@deprecated("This will be removed in v13")
4244
external \"@@": ('a => 'b, 'a) => 'b = "%apply"
4345

4446
/* Debugging */
@@ -92,7 +94,10 @@ external \"||": (bool, bool) => bool = "%sequor"
9294

9395
/* Integer operations */
9496

97+
@deprecated("Use `x => x + 1` instead. This will be removed in v13")
9598
external succ: int => int = "%succint"
99+
100+
@deprecated("Use `x => x - 1` instead. This will be removed in v13")
96101
external pred: int => int = "%predint"
97102

98103
@deprecated("Use `Math.abs` instead. This will be removed in v13")
@@ -103,14 +108,25 @@ let abs = x =>
103108
-x
104109
}
105110

111+
@deprecated("Use `Int.bitwiseAnd` instead. This will be removed in v13")
106112
external land: (int, int) => int = "%andint"
113+
114+
@deprecated("Use `Int.bitwiseOr` instead. This will be removed in v13")
107115
external lor: (int, int) => int = "%orint"
116+
117+
@deprecated("Use `Int.bitwiseXor` instead. This will be removed in v13")
108118
external lxor: (int, int) => int = "%xorint"
109119

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

123+
@deprecated("Use `Int.shiftLeft` instead. This will be removed in v13")
112124
external lsl: (int, int) => int = "%lslint"
125+
126+
@deprecated("Use `Int.shiftRightUnsigned` instead. This will be removed in v13")
113127
external lsr: (int, int) => int = "%lsrint"
128+
129+
@deprecated("Use `Int.shiftRight` instead. This will be removed in v13")
114130
external asr: (int, int) => int = "%asrint"
115131

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

267283
/* Pair operations */
268284

285+
@deprecated("Use `Pair.first` instead. This will be removed in v13")
269286
external fst: (('a, 'b)) => 'a = "%field0"
287+
288+
@deprecated("Use `Pair.second` instead. This will be removed in v13")
270289
external snd: (('a, 'b)) => 'b = "%field1"
271290

272291
/* References */
273292

274293
type ref<'a> = {mutable contents: 'a}
275294
external ref: 'a => ref<'a> = "%makeref"
276-
external \"!": ref<'a> => 'a = "%refget"
277295
external \":=": (ref<'a>, 'a) => unit = "%refset"
296+
297+
@deprecated("Do not use. This will be removed in v13")
298+
external \"!": ref<'a> => 'a = "%refget"
299+
300+
@deprecated("Use `Int.Ref.increment` instead. This will be removed in v13")
278301
external incr: ref<int> => unit = "%incr"
302+
303+
@deprecated("Use `Int.Ref.decrement` instead. This will be removed in v13")
279304
external decr: ref<int> => unit = "%decr"
280305

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

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

331357
/* Miscellaneous */
332358

359+
@deprecated("This will be removed in v13")
333360
type int32 = int

‎runtime/Pervasives_mini.res

-93
This file was deleted.

‎runtime/Stdlib.res

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Nullable = Stdlib_Nullable
2020
module Object = Stdlib_Object
2121
module Option = Stdlib_Option
2222
module Ordering = Stdlib_Ordering
23+
module Pair = Stdlib_Pair
2324
module Promise = Stdlib_Promise
2425
module RegExp = Stdlib_RegExp
2526
module Result = Stdlib_Result

‎runtime/Stdlib_Int.res

+7
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ external shiftRight: (int, int) => int = "%asrint"
107107
external shiftRightUnsigned: (int, int) => int = "%lsrint"
108108

109109
external ignore: int => unit = "%ignore"
110+
111+
module Ref = {
112+
type t = ref<int>
113+
114+
external increment: ref<int> => unit = "%incr"
115+
external decrement: ref<int> => unit = "%decr"
116+
}

‎runtime/Stdlib_Int.resi

+30
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,33 @@ external shiftRightUnsigned: (int, int) => int = "%lsrint"
482482
without having to store or process it further.
483483
*/
484484
external ignore: int => unit = "%ignore"
485+
486+
module Ref: {
487+
type t = ref<int>
488+
489+
/**
490+
`increment(intRef)` increments the value of the provided reference by 1.
491+
492+
## Examples
493+
494+
```rescript
495+
let myRef = ref(4)
496+
Int.Ref.increment(myRef)
497+
assertEqual(myRef.contents, 5)
498+
```
499+
*/
500+
external increment: ref<int> => unit = "%incr"
501+
502+
/**
503+
`decrement(intRef)` decrements the value of the provided reference by 1.
504+
505+
## Examples
506+
507+
```rescript
508+
let myRef = ref(4)
509+
Int.Ref.decrement(myRef)
510+
assertEqual(myRef.contents, 3)
511+
```
512+
*/
513+
external decrement: ref<int> => unit = "%decr"
514+
}

‎runtime/Stdlib_Pair.res

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***
2+
This module provides functions to work with pairs, which are 2-element tuples.
3+
*/
4+
5+
type t<'a, 'b> = ('a, 'b)
6+
7+
/**
8+
`first(pair)` returns the first element of a pair.
9+
10+
## Examples
11+
12+
```rescript
13+
Pair.first((1, 2))->assertEqual(1)
14+
```
15+
*/
16+
external first: (('a, 'b)) => 'a = "%field0"
17+
18+
/**
19+
`second(pair)` returns the second element of a pair.
20+
21+
## Examples
22+
23+
```rescript
24+
Pair.second((1, 2))->assertEqual(2)
25+
```
26+
*/
27+
external second: (('a, 'b)) => 'b = "%field1"
28+
29+
/**
30+
`ignore(option)` ignores the provided pair and returns unit.
31+
32+
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
33+
without having to store or process it further.
34+
*/
35+
external ignore: ('a, 'b) => unit = "%ignore"
36+
37+
/**
38+
`equal(pair1, pair2, f1, f2)` check equality of `pair2` and `pair2` using `f1` for
39+
equality on the first element and `f2` for equality on the second element.
40+
41+
## Examples
42+
43+
```rescript
44+
Pair.equal((1, "test"), (1, "test"), Int.equal, String.equal)->assertEqual(true)
45+
46+
Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal)->assertEqual(false)
47+
```
48+
*/
49+
let equal = ((a1, a2), (b1, b2), eq1, eq2) => eq1(a1, b1) && eq2(a2, b2)
50+
51+
/**
52+
`compare(pair1, pair2, f1, f2)` compares two pairs, using `f1` to compare the first element
53+
and `f2` to compare the second element. Ordering is based on the first element,
54+
if they are equal, the second element is compared.
55+
56+
## Examples
57+
58+
```rescript
59+
Pair.compare((1, "a"), (1, "a"), Int.compare, String.compare)->assertEqual(Ordering.equal)
60+
Pair.compare((1, "a"), (1, "b"), Int.compare, String.compare)->assertEqual(Ordering.less)
61+
Pair.compare((2, "a"), (1, "b"), Int.compare, String.compare)->assertEqual(Ordering.greater)
62+
```
63+
*/
64+
let compare = ((a1, a2), (b1, b2), cmp1, cmp2) =>
65+
switch cmp1(a1, b1) {
66+
| 0. => cmp2(a2, b2)
67+
| result => result
68+
}

‎runtime/rescript.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"-make-runtime",
1010
"-nostdlib",
1111
"-nopervasives",
12-
"-open Pervasives_mini",
12+
"-open Pervasives",
1313
"-no-keep-locs",
1414
"-no-alias-deps",
1515
"-bs-no-version-header",

1 commit comments

Comments
 (1)

github-actions[bot] commented on Apr 1, 2025

@github-actions[bot]

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Syntax Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 1ad3d50 Previous: 3f06468 Ratio
Parse RedBlackTree.res - time/run 1.8409753733333332 ms 1.3461563799999998 ms 1.37
Print RedBlackTree.res - time/run 2.90587894 ms 1.8942094533333333 ms 1.53
Print RedBlackTreeNoComments.res - time/run 2.6725949 ms 1.7506641333333335 ms 1.53
Parse Napkinscript.res - time/run 59.68092712666666 ms 42.33869618 ms 1.41
Print Napkinscript.res - time/run 92.89270593333333 ms 57.47105978 ms 1.62
Parse HeroGraphic.res - time/run 7.478325379999999 ms 5.736426893333333 ms 1.30
Print HeroGraphic.res - time/run 12.11635192 ms 7.840572506666666 ms 1.55

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.