From 557325f94e62056dc94971831880114322c4bf6a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 3 Sep 2026 09:53:08 +0200 Subject: [PATCH] Remove Int.Ref and the %incr, %decr and %refget builtins None of these were designed for ReScript. %incr, %decr and %refget arrived with OCaml's Pervasives in the 2016 initial export and were carried unexamined through every stdlib reshuffle since. Int.Ref itself was created in April 2025 (#7371) not because anyone wanted it, but as somewhere for the Pervasives.incr deprecation to point; the primitives it wrapped were removed for v13 two weeks ago. Outside this repository, GitHub code search finds no user of either the externals or the API. What the primitive bought was unboxing: expanding at the call site kept the field write syntactically visible, so Lam_pass_eliminate_ref could still turn a local ref into a mutable variable. A call through an ordinary function cannot - the reference appears as a bare Lvar and the pass gives up. That is not special to increment. Its body is six nodes against a small_inline_size of five, and cross-module inlining is off, so the inliner cannot reach it. Writing the update directly does keep the unboxing, and is shorter than the call it replaces: Int.Ref.increment(v) -> v.contents = v.contents + 1 53 call sites across 30 test files change that way, and their generated JavaScript is byte-identical. Only two outputs move: Stdlib_Int loses an empty Ref object and its export, and test_incr_ref loses onExpression - added to pin that the primitive bound its argument before mentioning it twice, which has nothing left to test now that no expansion happens. Lambda.offset_ref and the Offset_ref builtin go with them. Nothing in lambda.ml now builds a term outside the constructors and the traversals. Int.Ref.t went too. It was a type alias for ref introduced alongside the two functions, and with them gone the module held nothing else. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01W8g8qwBARAcvW9MyuKQq8H --- CHANGELOG.md | 1 + compiler/ml/lambda.ml | 36 ------------------- compiler/ml/lambda.mli | 3 -- compiler/ml/translcore.ml | 3 -- packages/@rescript/runtime/Stdlib_Int.res | 7 ---- packages/@rescript/runtime/Stdlib_Int.resi | 30 ---------------- .../@rescript/runtime/lib/es6/Stdlib_Int.mjs | 3 -- .../@rescript/runtime/lib/js/Stdlib_Int.cjs | 3 -- tests/belt_tests/src/bs_queue_test.res | 2 +- tests/tests/src/ari_regress_test.res | 2 +- tests/tests/src/bdd.res | 6 ++-- tests/tests/src/bs_ignore_effect.res | 4 +-- tests/tests/src/complex_while_loop.res | 2 +- .../tests/src/condition_compilation_test.res | 2 +- tests/tests/src/earger_curry_test.res | 8 ++--- tests/tests/src/ffi_arity_test.res | 2 +- tests/tests/src/ffi_js_test.res | 2 +- tests/tests/src/for_loop_test.res | 8 ++--- tests/tests/src/functor_def.res | 2 +- tests/tests/src/global_module_alias_test.res | 12 +++---- tests/tests/src/gpr_1072.res | 10 +++--- tests/tests/src/gpr_1409_test.res | 2 +- tests/tests/src/gpr_1762_test.res | 2 +- tests/tests/src/gpr_2413_test.res | 2 +- tests/tests/src/lazy_test.res | 2 +- tests/tests/src/loop_regression_test.res | 2 +- tests/tests/src/optional_ffi_test.res | 4 +-- tests/tests/src/rec_fun_test.res | 2 +- tests/tests/src/test_fib.res | 2 +- tests/tests/src/test_for_loop.res | 6 ++-- tests/tests/src/test_incr_ref.mjs | 6 ---- tests/tests/src/test_incr_ref.res | 8 +---- tests/tests/src/test_per.res | 3 -- tests/tests/src/test_side_effect_functor.res | 2 +- tests/tests/src/test_simple_ref.res | 2 +- tests/tests/src/test_u.res | 2 +- tests/tests/src/test_while_closure.res | 2 +- tests/tests/src/test_while_side_effect.res | 6 ++-- tests/tests/src/tuple_alloc.res | 4 +-- 39 files changed, 54 insertions(+), 153 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c08b2aa3b3..145b708706e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Correct the structured function details produced by `rescript-tools doc` and exposed by `RescriptTools.Docgen`: parameters now retain labels and optionality, nested functions, tuples, variables, and generic arguments retain their type structure, return types are identified correctly, and non-function values no longer receive fake function details. This changes the published docgen detail schema. https://github.com/rescript-lang/rescript/pull/8576 - Make object-field mutability part of the type. A property has one type for reading and writing. Assignment requires `@set`, except on an inferred open row, where assignment makes the field settable. Private rows are not inferred open rows, so a field in `type t = private {.."x": int}` is writable only when annotated with `@set`. Coercions never grant or widen write capability. Previously, getter and setter types were tracked independently, allowing a property to be written at a different type than it was read and allowing writes through a value coerced to a type without `@set`. https://github.com/rescript-lang/rescript/pull/8597 - Remove the undocumented object-field attribute forms `@get` (bare or with a `null`/`undefined`/`nullable` payload) and `@set({no_get: ...})` on object types. Only bare `@set` marks a field settable; nullable getter types are written directly (`null`, `undefined`, `nullable`). https://github.com/rescript-lang/rescript/pull/8597 +- Remove `Int.Ref` and the `%incr`, `%decr` and `%refget` builtins behind it. Write `r.contents = r.contents + 1` instead; an `external` declared with one of the removed names is now rejected. https://github.com/rescript-lang/rescript/pull/8616 #### :eyeglasses: Spec Compliance diff --git a/compiler/ml/lambda.ml b/compiler/ml/lambda.ml index d1670823642..be06251961c 100644 --- a/compiler/ml/lambda.ml +++ b/compiler/ml/lambda.ml @@ -351,9 +351,6 @@ type builtin = | Primitive of primitive | Eliminated of eliminated | Constant of structured_constant - | Offset_ref of int - (** [%incr] / [%decr]: an assignment through the reference, expanded here - so the caller's own IR carries the form its escape analysis reads. *) type inline_attribute = | Always_inline (* [@inline] or [@inline always] *) @@ -490,35 +487,6 @@ let lambda_false = Lconst Const_js_false (* [r := r.contents + delta]. The reference is mentioned twice, so bind it unless it is already a variable. *) -let offset_ref ~delta r loc = - let assign r = - Lprim - { - primitive = Psetfield (0, ref_field_set_info); - args = - [ - r; - Lprim - { - primitive = Paddint; - args = - [ - Lprim - {primitive = Pfield (0, ref_field_info); args = [r]; loc}; - Lconst (const_int delta); - ]; - loc; - }; - ]; - loc; - } - in - match r with - | Lvar _ -> assign r - | _ -> - let id = Ident.create "ref" in - Llet (Strict, id, r, assign (Lvar id)) - let eq_comparison (p : comparison) (p1 : comparison) = p = p1 let eq_field_dbg_info (x : field_dbg_info) (y : field_dbg_info) = x = y @@ -1269,10 +1237,6 @@ let mk_builtin b args loc = match args with | [] -> Lconst c | _ -> assert false) - | Offset_ref delta -> ( - match args with - | [r] -> offset_ref ~delta r loc - | _ -> assert false) | Eliminated Identity -> ( match args with | [arg] -> arg diff --git a/compiler/ml/lambda.mli b/compiler/ml/lambda.mli index 9273b2a22b2..731dad49568 100644 --- a/compiler/ml/lambda.mli +++ b/compiler/ml/lambda.mli @@ -321,9 +321,6 @@ type builtin = | Primitive of primitive | Eliminated of eliminated | Constant of structured_constant - | Offset_ref of int - (** [%incr] / [%decr]: an assignment through the reference, expanded here - so the caller's own IR carries the form its escape analysis reads. *) type inline_attribute = | Always_inline (* [@inline] or [@inline always] *) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 89dfa49da10..98677338cb2 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -252,8 +252,6 @@ let erased_builtins : (string * Lambda.builtin) array = ("%identity", Eliminated Identity); ("%component_identity", Eliminated Identity); ("%ignore", Eliminated Ignore); - ("%incr", Offset_ref 1); - ("%decr", Offset_ref (-1)); ("%null", Constant Const_js_null); ("%undefined", Constant (Const_js_undefined {is_unit = false})); (* FIXME: Core compatibility *) @@ -268,7 +266,6 @@ let primitive_builtins : (string * Lambda.builtin) array = (* BEGIN Triples for ref data type *) ("%makeref", Pmakeblock Lambda.ref_tag_info); ("%refset", Psetfield (0, Lambda.ref_field_set_info)); - ("%refget", Pfield (0, Lambda.ref_field_info)); (* Finish Triples for ref data type *) ("%field0", Pfield (0, Fld_tuple)); ("%field1", Pfield (1, Fld_tuple)); diff --git a/packages/@rescript/runtime/Stdlib_Int.res b/packages/@rescript/runtime/Stdlib_Int.res index ed9f47baf78..c7bcccf079c 100644 --- a/packages/@rescript/runtime/Stdlib_Int.res +++ b/packages/@rescript/runtime/Stdlib_Int.res @@ -127,10 +127,3 @@ module Bitwise = { } external ignore: int => unit = "%ignore" - -module Ref = { - type t = ref - - external increment: ref => unit = "%incr" - external decrement: ref => unit = "%decr" -} diff --git a/packages/@rescript/runtime/Stdlib_Int.resi b/packages/@rescript/runtime/Stdlib_Int.resi index c0f6fa3d42d..bd71f41fc21 100644 --- a/packages/@rescript/runtime/Stdlib_Int.resi +++ b/packages/@rescript/runtime/Stdlib_Int.resi @@ -520,33 +520,3 @@ module Bitwise: { without having to store or process it further. */ external ignore: int => unit = "%ignore" - -module Ref: { - type t = ref - - /** - `increment(intRef)` increments the value of the provided reference by 1. - - ## Examples - - ```rescript - let myRef = ref(4) - Int.Ref.increment(myRef) - myRef.contents == 5 - ``` - */ - external increment: ref => unit = "%incr" - - /** - `decrement(intRef)` decrements the value of the provided reference by 1. - - ## Examples - - ```rescript - let myRef = ref(4) - Int.Ref.decrement(myRef) - myRef.contents == 3 - ``` - */ - external decrement: ref => unit = "%decr" -} diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs b/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs index 2a64b0de12f..e93e65af227 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs @@ -75,8 +75,6 @@ let Bitwise = { lnot: lnot }; -let Ref = {}; - let Constants = { minValue: -2147483648, maxValue: 2147483647 @@ -89,6 +87,5 @@ export { rangeWithOptions, clamp, Bitwise, - Ref, } /* No side effect */ diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs b/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs index e0e1d119b7f..18c9ac245c5 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs +++ b/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs @@ -75,8 +75,6 @@ let Bitwise = { lnot: lnot }; -let Ref = {}; - let Constants = { minValue: -2147483648, maxValue: 2147483647 @@ -88,5 +86,4 @@ exports.range = range; exports.rangeWithOptions = rangeWithOptions; exports.clamp = clamp; exports.Bitwise = Bitwise; -exports.Ref = Ref; /* No side effect */ diff --git a/tests/belt_tests/src/bs_queue_test.res b/tests/belt_tests/src/bs_queue_test.res index 111fbc31881..1f663f19afc 100644 --- a/tests/belt_tests/src/bs_queue_test.res +++ b/tests/belt_tests/src/bs_queue_test.res @@ -116,7 +116,7 @@ describe(__MODULE__, () => { q, j => { assert(i.contents == j) - Stdlib.Int.Ref.increment(i) + i.contents = i.contents + 1 }, ) }) diff --git a/tests/tests/src/ari_regress_test.res b/tests/tests/src/ari_regress_test.res index d52952d5c87..0e152dea3b2 100644 --- a/tests/tests/src/ari_regress_test.res +++ b/tests/tests/src/ari_regress_test.res @@ -13,7 +13,7 @@ let gg = (x, y) => { let g1 = (x, y) => { let u = x + y - let () = Int.Ref.increment(h) + let () = h.contents = h.contents + 1 (xx, yy) => xx + yy + u } let x = gg(3, 5)(6) diff --git a/tests/tests/src/bdd.res b/tests/tests/src/bdd.res index bbea84aa055..e8870dffae2 100644 --- a/tests/tests/src/bdd.res +++ b/tests/tests/src/bdd.res @@ -71,7 +71,7 @@ let resize = newSize => { let rec insert = (idl, idh, v, ind, bucket, newNode) => if n_items.contents <= sz_1.contents { htab.contents->Array.setUnsafe(ind, list{newNode, ...bucket}) - Int.Ref.increment(n_items) + n_items.contents = n_items.contents + 1 } else { resize(sz_1.contents + sz_1.contents + 2) let ind = Int.bitwiseAnd(hashVal(idl, idh, v), sz_1.contents) @@ -102,7 +102,7 @@ let mkNode = (low, v, high) => { low, v, { - Int.Ref.increment(nodeC) + nodeC.contents = nodeC.contents + 1 nodeC.contents }, high, @@ -276,7 +276,7 @@ let test_hwb = (bdd, vars) => { let ntrue = ref(0) for i in 0 to Array.length(vars) - 1 { if vars->Array.getUnsafe(i) { - Int.Ref.increment(ntrue) + ntrue.contents = ntrue.contents + 1 } } bool_equal( diff --git a/tests/tests/src/bs_ignore_effect.res b/tests/tests/src/bs_ignore_effect.res index 594bd898996..d085bfa8469 100644 --- a/tests/tests/src/bs_ignore_effect.res +++ b/tests/tests/src/bs_ignore_effect.res @@ -15,10 +15,10 @@ let v = ref(0) @obj external config: (~hi: int, ~lo: int, unit) => _ = "" -let h = config(~hi=2, ~lo=0, ignore(Int.Ref.increment(v))) +let h = config(~hi=2, ~lo=0, ignore(v.contents = v.contents + 1)) let z = add( { - Int.Ref.increment(v) + v.contents = v.contents + 1 Float }, 3.0, diff --git a/tests/tests/src/complex_while_loop.res b/tests/tests/src/complex_while_loop.res index 8db77e2aa24..fe40661f95f 100644 --- a/tests/tests/src/complex_while_loop.res +++ b/tests/tests/src/complex_while_loop.res @@ -9,7 +9,7 @@ let f = () => { fib(n.contents) > 10 } { n.contents->Int.toString->Console.log - Int.Ref.increment(n) + n.contents = n.contents + 1 } } diff --git a/tests/tests/src/condition_compilation_test.res b/tests/tests/src/condition_compilation_test.res index 8c2050dd03f..18f1c071b13 100644 --- a/tests/tests/src/condition_compilation_test.res +++ b/tests/tests/src/condition_compilation_test.res @@ -24,7 +24,7 @@ let vv = 3 let v = ref(1) let a = { - let () = Int.Ref.increment(v) + let () = v.contents = v.contents + 1 v.contents } diff --git a/tests/tests/src/earger_curry_test.res b/tests/tests/src/earger_curry_test.res index 88c520c90f5..284e8ad4bbe 100644 --- a/tests/tests/src/earger_curry_test.res +++ b/tests/tests/src/earger_curry_test.res @@ -96,11 +96,11 @@ let f = x => /* let u = */ add5( x, { - Int.Ref.increment(v) + v.contents = v.contents + 1 1 }, { - Int.Ref.increment(v) + v.contents = v.contents + 1 2 }, ... @@ -113,11 +113,11 @@ let g = x => { add5( x, { - Int.Ref.increment(v) + v.contents = v.contents + 1 1 }, { - Int.Ref.increment(v) + v.contents = v.contents + 1 2 }, a, diff --git a/tests/tests/src/ffi_arity_test.res b/tests/tests/src/ffi_arity_test.res index fd652eb5413..be200c79d67 100644 --- a/tests/tests/src/ffi_arity_test.res +++ b/tests/tests/src/ffi_arity_test.res @@ -27,7 +27,7 @@ let fff = () => { /* No inline */ Console.log("x") Console.log("x") - Int.Ref.increment(vvv) + vvv.contents = vvv.contents + 1 } let g = () => fff() diff --git a/tests/tests/src/ffi_js_test.res b/tests/tests/src/ffi_js_test.res index 58151625456..66f4f7f589d 100644 --- a/tests/tests/src/ffi_js_test.res +++ b/tests/tests/src/ffi_js_test.res @@ -70,7 +70,7 @@ describe(__MODULE__, () => { let u = ref(3) let side_effect_config = config( ~kind={ - Int.Ref.increment(u) + u.contents = u.contents + 1 Int }, ~hi=3, diff --git a/tests/tests/src/for_loop_test.res b/tests/tests/src/for_loop_test.res index f4c3cfd09e2..4c96e74bcfe 100644 --- a/tests/tests/src/for_loop_test.res +++ b/tests/tests/src/for_loop_test.res @@ -53,16 +53,16 @@ describe(__MODULE__, () => { let v4 = ref(0) let v5 = ref(0) let inspect_3 = ref(-1) - Int.Ref.increment(v4) + v4.contents = v4.contents + 1 for j in 0 to 1 { - Int.Ref.increment(v5) + v5.contents = v5.contents + 1 let v2 = ref(0) let v3 = u for i in 0 to Array.length(x) - 1 { let _j = i * 2 let k = 2 * u * u let h = 2 * v5.contents - Int.Ref.increment(v2) + v2.contents = v2.contents + 1 arr[i] = _ => v := v.contents + k + v2.contents + v4.contents + v5.contents + h + v3 /* v2 should not be captured */ } @@ -128,7 +128,7 @@ describe(__MODULE__, () => { /* incr v ; */ v := v.contents + i for j in 0 to j_len - 1 { - Int.Ref.increment(v) + v.contents = v.contents + 1 collect(v.contents) arr[i * j_len + j] = _ => vv := vv.contents + v.contents /* v should not be captured inside, diff --git a/tests/tests/src/functor_def.res b/tests/tests/src/functor_def.res index 6c3c3669d69..6784510a6b7 100644 --- a/tests/tests/src/functor_def.res +++ b/tests/tests/src/functor_def.res @@ -1,7 +1,7 @@ let v = ref(0) let f = (x, x) => { - Int.Ref.increment(v) + v.contents = v.contents + 1 x + x } diff --git a/tests/tests/src/global_module_alias_test.res b/tests/tests/src/global_module_alias_test.res index c01b5ddb14b..15f32151f55 100644 --- a/tests/tests/src/global_module_alias_test.res +++ b/tests/tests/src/global_module_alias_test.res @@ -22,18 +22,18 @@ let v = ref(0) module Make = (U: S) => { let () = { - Int.Ref.increment(v) - Int.Ref.increment(v) - Int.Ref.increment(v) + v.contents = v.contents + 1 + v.contents = v.contents + 1 + v.contents = v.contents + 1 } include U } let f = () => { let () = { - Int.Ref.increment(v) - Int.Ref.increment(v) - Int.Ref.increment(v) + v.contents = v.contents + 1 + v.contents = v.contents + 1 + v.contents = v.contents + 1 } module G = F /* local module is not module alias */ module H = G diff --git a/tests/tests/src/gpr_1072.res b/tests/tests/src/gpr_1072.res index 7baea30c2de..6ef2ca77f66 100644 --- a/tests/tests/src/gpr_1072.res +++ b/tests/tests/src/gpr_1072.res @@ -153,7 +153,7 @@ let () = { again4(~y=(), __LINE__, ()) again4( ~x={ - Int.Ref.increment(side_effect) + side_effect.contents = side_effect.contents + 1 () }, ~y=(), @@ -162,11 +162,11 @@ let () = { ) again4( ~x={ - Int.Ref.increment(side_effect) + side_effect.contents = side_effect.contents + 1 () }, ~y={ - Int.Ref.decrement(side_effect) + side_effect.contents = side_effect.contents - 1 () }, __LINE__, @@ -174,13 +174,13 @@ let () = { ) again4( ~y={ - Int.Ref.decrement(side_effect) + side_effect.contents = side_effect.contents - 1 () }, __LINE__, (), ) - again4(~x=Int.Ref.increment(side_effect), ~y=(), __LINE__, ()) + again4(~x=side_effect.contents = side_effect.contents + 1, ~y=(), __LINE__, ()) } /* external again5 : ?x__ignore:([`a of unit -> int | `b of string -> int ] [@string]) */ diff --git a/tests/tests/src/gpr_1409_test.res b/tests/tests/src/gpr_1409_test.res index fb5732b4ced..113c1978d67 100644 --- a/tests/tests/src/gpr_1409_test.res +++ b/tests/tests/src/gpr_1409_test.res @@ -51,7 +51,7 @@ let test6 = (f, x) => { let x = ref(3) mangle( ~_open=?{ - Int.Ref.increment(x) + x.contents = x.contents + 1 Some(x.contents) }, ~xx__hi=?f(x), diff --git a/tests/tests/src/gpr_1762_test.res b/tests/tests/src/gpr_1762_test.res index 6ab203049b9..d6d6442e167 100644 --- a/tests/tests/src/gpr_1762_test.res +++ b/tests/tests/src/gpr_1762_test.res @@ -6,7 +6,7 @@ open Test_utils let v = ref(3) let update = () => { - Int.Ref.increment(v) + v.contents = v.contents + 1 true } diff --git a/tests/tests/src/gpr_2413_test.res b/tests/tests/src/gpr_2413_test.res index e8df3176680..50307f7d0df 100644 --- a/tests/tests/src/gpr_2413_test.res +++ b/tests/tests/src/gpr_2413_test.res @@ -20,7 +20,7 @@ let ff = c => switch { let a = 1 let b = 1 - Int.Ref.increment(c) + c.contents = c.contents + 1 a + c.contents + b } { | (0 | 1 | 2 | 3) as n => n + 1 diff --git a/tests/tests/src/lazy_test.res b/tests/tests/src/lazy_test.res index aeaf89ef050..5a77e036079 100644 --- a/tests/tests/src/lazy_test.res +++ b/tests/tests/src/lazy_test.res @@ -41,7 +41,7 @@ let exotic = x => let l_from_fun = Lazy.make(_ => 3) let forward_test = Lazy.make(() => { let u = ref(3) - Int.Ref.increment(u) + u.contents = u.contents + 1 u.contents }) diff --git a/tests/tests/src/loop_regression_test.res b/tests/tests/src/loop_regression_test.res index 9e318d1d34e..d646f2ec16c 100644 --- a/tests/tests/src/loop_regression_test.res +++ b/tests/tests/src/loop_regression_test.res @@ -10,7 +10,7 @@ let f = () => { acc.contents } else { acc := acc.contents + v.contents - Int.Ref.increment(v) + v.contents = v.contents + 1 loop(n) } loop(10) diff --git a/tests/tests/src/optional_ffi_test.res b/tests/tests/src/optional_ffi_test.res index 72b9825364c..49dc9ca75f4 100644 --- a/tests/tests/src/optional_ffi_test.res +++ b/tests/tests/src/optional_ffi_test.res @@ -11,7 +11,7 @@ function hey(x, y) { let counter = ref(0) let side_effect = x => { - Int.Ref.increment(x) + x.contents = x.contents + 1 x.contents } @@ -21,7 +21,7 @@ let bug_to_fix2 = (f, x) => xx(~x=?f(x), ~y=3, ()) /* : [f x] is done once */ let counter2 = ref(0) let side_effect2 = x => { - Int.Ref.increment(x) + x.contents = x.contents + 1 Some(x.contents) } diff --git a/tests/tests/src/rec_fun_test.res b/tests/tests/src/rec_fun_test.res index 006db5cd2be..4ddb5dd04fa 100644 --- a/tests/tests/src/rec_fun_test.res +++ b/tests/tests/src/rec_fun_test.res @@ -6,7 +6,7 @@ let called = ref(0) let g = () => { let rec v = ref(next) and next = (i, b) => { - Int.Ref.increment(called) + called.contents = called.contents + 1 if b { ignore(v.contents(i, false)) } diff --git a/tests/tests/src/test_fib.res b/tests/tests/src/test_fib.res index f3702806e85..e441546b3f8 100644 --- a/tests/tests/src/test_fib.res +++ b/tests/tests/src/test_fib.res @@ -56,7 +56,7 @@ let f = x => { let sum = ref(0) while v.contents > 0 { sum := sum.contents + v.contents - Int.Ref.decrement(v) + v.contents = v.contents - 1 } sum.contents } diff --git a/tests/tests/src/test_for_loop.res b/tests/tests/src/test_for_loop.res index ad548ae2cd6..4a4579f3b74 100644 --- a/tests/tests/src/test_for_loop.res +++ b/tests/tests/src/test_for_loop.res @@ -52,16 +52,16 @@ let for_6 = (x, u) => { let arr = x->Array.map(_ => _ => ()) let v4 = ref(0) let v5 = ref(0) - Int.Ref.increment(v4) + v4.contents = v4.contents + 1 for j in 0 to 1 { - Int.Ref.increment(v5) + v5.contents = v5.contents + 1 let v2 = ref(0) let v3 = u for i in 0 to Array.length(x) { let _j = i * 2 let k = 2 * u * u let h = 2 * v5.contents - Int.Ref.increment(v2) + v2.contents = v2.contents + 1 arr[i] = _ => v := v.contents + k + v2.contents + v3 + v4.contents + v5.contents + h } } diff --git a/tests/tests/src/test_incr_ref.mjs b/tests/tests/src/test_incr_ref.mjs index f5a7945013f..6e22f1919fb 100644 --- a/tests/tests/src/test_incr_ref.mjs +++ b/tests/tests/src/test_incr_ref.mjs @@ -7,13 +7,7 @@ u = u + 1 | 0; let v; -function onExpression() { - let ref = mkRef(); - ref.contents = ref.contents + 1 | 0; -} - export { v, - onExpression, } /* v Not a pure module */ diff --git a/tests/tests/src/test_incr_ref.res b/tests/tests/src/test_incr_ref.res index 34485d403dd..37c343d7369 100644 --- a/tests/tests/src/test_incr_ref.res +++ b/tests/tests/src/test_incr_ref.res @@ -1,14 +1,8 @@ include ( { let u = ref(0) - let v = Int.Ref.increment(u) + let v = u.contents = u.contents + 1 }: { let v: unit } ) - -/* The reference is an expression, not a variable, so it has to be bound: it - must be evaluated once, not once per mention. */ -@val external mkRef: unit => ref = "mkRef" - -let onExpression = () => Int.Ref.increment(mkRef()) diff --git a/tests/tests/src/test_per.res b/tests/tests/src/test_per.res index 835873593ea..a33c4dfc06e 100644 --- a/tests/tests/src/test_per.res +++ b/tests/tests/src/test_per.res @@ -155,7 +155,4 @@ external snd: (('a, 'b)) => 'b = "%field1" type ref<'a> = {mutable contents: 'a} external ref: 'a => ref<'a> = "%makeref" -external \"!": ref<'a> => 'a = "%refget" external \":=": (ref<'a>, 'a) => unit = "%refset" -external incr: ref => unit = "%incr" -external decr: ref => unit = "%decr" diff --git a/tests/tests/src/test_side_effect_functor.res b/tests/tests/src/test_side_effect_functor.res index c4db8417572..b277cdd7e4f 100644 --- a/tests/tests/src/test_side_effect_functor.res +++ b/tests/tests/src/test_side_effect_functor.res @@ -3,7 +3,7 @@ include ( module M = () => { let v = ref(0) { - Int.Ref.increment(v) + v.contents = v.contents + 1 v.contents->Int.toString->Console.log } let u = 3 diff --git a/tests/tests/src/test_simple_ref.res b/tests/tests/src/test_simple_ref.res index 40682cb8ebb..44fcd26c1bc 100644 --- a/tests/tests/src/test_simple_ref.res +++ b/tests/tests/src/test_simple_ref.res @@ -3,7 +3,7 @@ include ( let v = ref(0) let gen = () => { - Int.Ref.increment(v) + v.contents = v.contents + 1 v.contents } let h = ref(0) diff --git a/tests/tests/src/test_u.res b/tests/tests/src/test_u.res index d7279ea888a..a820f37fa4a 100644 --- a/tests/tests/src/test_u.res +++ b/tests/tests/src/test_u.res @@ -3,7 +3,7 @@ let f = x => { let sum = ref(0) while v.contents > 0 { sum := sum.contents + v.contents - Int.Ref.decrement(v) + v.contents = v.contents - 1 } sum.contents } diff --git a/tests/tests/src/test_while_closure.res b/tests/tests/src/test_while_closure.res index f76afc41953..71841134f9c 100644 --- a/tests/tests/src/test_while_closure.res +++ b/tests/tests/src/test_while_closure.res @@ -44,7 +44,7 @@ let f = () => { while n.contents < count { let j = n.contents arr[j] = _ => v := v.contents + j - Int.Ref.increment(n) + n.contents = n.contents + 1 } } diff --git a/tests/tests/src/test_while_side_effect.res b/tests/tests/src/test_while_side_effect.res index 38f16131659..feb1d470b57 100644 --- a/tests/tests/src/test_while_side_effect.res +++ b/tests/tests/src/test_while_side_effect.res @@ -2,7 +2,7 @@ let v = ref(0) while { v.contents->Int.toString->Console.log - Int.Ref.increment(v) + v.contents = v.contents + 1 v.contents < 10 } { ignore() @@ -18,8 +18,8 @@ let x = ref(3) while { let y = ref(3) x.contents->Int.toString->Console.log - Int.Ref.increment(y) - Int.Ref.increment(x) + y.contents = y.contents + 1 + x.contents = x.contents + 1 fib(x.contents) + fib(x.contents) < 20 } { 3->Int.toString->Console.log diff --git a/tests/tests/src/tuple_alloc.res b/tests/tests/src/tuple_alloc.res index 50287bdef9a..3fc556fd4dc 100644 --- a/tests/tests/src/tuple_alloc.res +++ b/tests/tests/src/tuple_alloc.res @@ -1,10 +1,10 @@ let v = ref(0) -let (reset, incr) = (_ => v := 0, _ => Int.Ref.increment(v)) +let (reset, incr) = (_ => v := 0, _ => v.contents = v.contents + 1) let (reset2, incr2) = { let vv = ref(0) - (() => vv := 0, () => Int.Ref.increment(vv)) + (() => vv := 0, () => vv.contents = vv.contents + 1) } let f = (a, b, d, e) => {