Skip to content

Release a 12.x that prepares projects for v13: deprecations, migrate templates and formatter migrations #9404

Todo

Description

@fhammerschmidt

Summary

Before 13.0 ships, release a 12.x version that prepares projects for v13. Everything that v13 removes should:

  • warn on 12.x;
  • be fixed automatically by rescript-tools migrate-all or rescript format wherever the change is mechanical.

Then upgrading becomes: update to the latest 12.x, run the migrations, fix the remaining warnings, switch to 13.

These findings come from writing the v13 migration guide (rescript-lang/rescript-lang.org#1488). I went through the breaking changes of 13.0.0-alpha.1 to alpha.7 and compared the 12.x runtime (maintenance/12.x) with v13.0.0-alpha.7. The highlights of alpha.7 already say "run rescript-tools migrate-all with 12.3.2 before upgrading", but 12.3.2 isn't released, and several gaps remain.

Today

rescript-tools migrate rewrites calls to deprecated APIs that have a migrate: template. It has no syntax rewrites.

Status Count
Removed in v13, deprecated in 12.x with a migrate: template (excluding Belt) ~1,160
Removed in v13, deprecated in 12.x without a template ~135 (list below)
Removed in v13, never deprecated in 12.x see section 2

The formatter already performs two v13 syntax migrations on 12.3.1. %re("/b/g") is printed as /b/g, because regex literals parse to %re and the printer writes them back as literals. (. a, b) => ... is printed as (a, b) => .... It leaves every other removed form unchanged.

Proposal

1. Add migrate: templates for deprecated APIs that lack them

Most of the ~135 are plain renames:

  • Pervasives: float_of_int → Int.toFloat, fst → Pair.first, string_of_int → Int.toString, the math functions → Math.*.
  • JSON: parseExn → parseOrThrow, and stringifyWithIndent and the similar variants → stringify with labelled arguments.
  • List.has → List.some.
  • Stdlib.lazy_t → Lazy.t.
  • Char: char is an alias of int in v13, so Char.code(c) → c and Char.chr(i) → i.

The full list is below. Some entries can't be templated, such as List.setAssoc → Map and the internal Obj operations. Their deprecation messages are enough.

2. Deprecate APIs that v13 removes without any warning on 12.x

  • Belt's 69 ...Undefined functions (Belt.Array.getUndefined, …), removed in Remove Belt xxxUndefined API #8377. 12.x has no stdlib Undefined module, so a type-preserving template isn't possible. A deprecation pointing to the option-returning version is still needed, so users get a warning.

  • Int.Ref.increment/decrement, removed in Remove Int.Ref and the %incr, %decr and %refget builtins #8616. These can be templated as r := r.contents + 1 and r := r.contents - 1.

  • Int.fromString's ~radix argument, removed in Stricter number parsing #8129. It should be deprecated. Radix 16 and 2 could be templated as a "0x" or "0b" prefix.

  • The iterator API, reworked in Fix iterator / iterable typedefs, add generator typedefs #8355:

    • Array/Dict/Map/Set.fromIterator → fromIterable, which needs a coercion: Array.fromIterable((map->Map.keys :> Iterable.t<_>)).
    • Iterator.toArray, toArrayWithMapper and forEach → IteratorObject.*.

    The targets don't exist in 12.x. These could stay in 13.0 as deprecated aliases with templates, so migrate-all handles them when run on v13.

3. Formatter migrations on 12.x

Each target below compiles on 12.3.1; I checked each one. Making the 12.x formatter write the new form would migrate projects with no extra tool:

v12 form Printed as What 12.x needs
%debugger debugger() Add external debugger: unit => unit = "%debugger" to 12.x Pervasives; a hand-written one compiles to debugger; on 12.3.1. Then print the debugger extension as a call, following the %re case in res_printer.ml.
break, continue as identifiers \"break", \"continue" Escape them in the printer through a printer-only keyword list. The 12.x parser must stay unchanged.
@unboxed on constructors @unboxed on the type Move the attribute when every payload constructor, or the only constructor, has it. That has the same meaning (see #9040), except when a payload is a single-field inline record. Leave that case to the existing deprecation warning.

Record syntax for dicts (let d: dict<int> = {foo: 1} → dict{"foo": 1}) needs type information, so it belongs in rescript-tools migrate. dict{} is available in 12.x.

These can't be automated, and stay documentation-only:

  • @deriving(abstract) and @deriving(jsConverter).
  • %external.
  • @taggedTemplate: the taggedTemplate<'param, 'output> type doesn't exist in 12.x.

4. Release and point to it

Release this as the last 12.x minor, then refer to it from the v13 changelog highlights and the migration guide instead of "12.3.2".

Open questions

  • APIs that only exist in v13 (fromIterable, IteratorObject, …): keep deprecated aliases in 13.0, or add forward-compatible versions to 12.x?
  • Opt-in or default: should the formatter migrations always apply, or only behind a flag such as rescript format --migrate?
APIs removed in v13 that are deprecated in 12.x without a migrate: template

Pervasives (61)

  • __unsafe_cast: Do not use
  • failwith: Use custom exception instead
  • invalid_arg: Use custom exception instead
  • succ: Use x => x + 1 instead
  • pred: Use x => x - 1 instead
  • abs: Use Math.abs instead
  • land: Use Int.bitwiseAnd instead
  • lor: Use Int.bitwiseOr instead
  • lxor: Use Int.bitwiseXor instead
  • lnot: Use Int.bitwiseNot instead
  • lsl: Use Int.shiftLeft instead
  • lsr: Use Int.shiftRightUnsigned instead
  • asr: Use Int.shiftRight instead
  • max_int: Use Int.Constants.maxValue instead
  • min_int: Use Int.Constants.minValue instead
  • exp: Use Math.exp instead
  • acos: Use Math.acos instead
  • asin: Use Math.asin instead
  • atan: Use Math.atan instead
  • atan2: Use Math.atan2 instead
  • cos: Use Math.cos instead
  • cosh: Use Math.cosh instead
  • log: Use Math.log instead
  • log10: Use Math.log10 instead
  • log1p: Use Math.log1p instead
  • sin: Use Math.sin instead
  • sinh: Use Math.sinh instead
  • sqrt: Use Math.sqrt instead
  • tan: Use Math.tan instead
  • tanh: Use Math.tanh instead
  • ceil: Use Math.ceil instead
  • floor: Use Math.floor instead
  • abs_float: Use Math.abs instead
  • mod_float: Use % instead
  • float: Use Int.toFloat instead
  • float_of_int: Use Int.toFloat instead
  • truncate: Use Float.toInt instead
  • int_of_float: Use Float.toInt instead
  • infinity: Use Float.positiveInfinity instead
  • neg_infinity: Use Float.negativeInfinity instead
  • nan: Use Float.nan instead
  • max_float: Use Float.Constants.maxValue instead
  • min_float: Use Float.Constants.minValue instead
  • epsilon_float: Use Float.Constants.epsilon instead
  • fpclass: Do not use
  • classify_float: Do not use
  • int_of_char: Use type string and String.charCodeAt instead
  • unsafe_char_of_int: Use type string and String.fromCharCode instead
  • char_of_int: Use type string and String.fromCharCode instead
  • fst: Use Pair.first instead
  • snd: Use Pair.second instead
  • incr: Do not use
  • incr: Use Int.Ref.increment instead
  • decr: Use Int.Ref.decrement instead
  • string_of_bool: Use Bool.toString instead
  • bool_of_string: Use Bool.fromString instead
  • bool_of_string_opt: Use Bool.fromString instead
  • string_of_int: Use Int.toString instead
  • int_of_string: Use Int.fromString instead
  • int_of_string_opt: Use Int.fromString instead
  • string_get: Use String.get instead

JSON (13)

  • parseExn: Use parseOrThrow instead
  • parseExnWithReviver: Use parseOrThrow with optional parameter instead
  • stringifyWithIndent: Use stringify with optional parameter instead
  • stringifyWithReplacer: Use stringify with optional parameter instead
  • stringifyWithReplacerAndIndent: Use stringify with optional parameters instead
  • stringifyWithFilter: Use stringify with optional parameter instead
  • stringifyWithFilterAndIndent: Use stringify with optional parameters instead
  • stringifyAnyWithIndent: Use stringifyAny with optional parameter instead
  • stringifyAnyWithReplacer: Use stringifyAny with optional parameter instead
  • stringifyAnyWithReplacerAndIndent: Use stringifyAny with optional parameters instead
  • stringifyAnyWithFilter: Use stringifyAny with optional parameter instead
  • stringifyAnyWithFilterAndIndent: Use stringifyAny with optional parameters instead
  • classify: Directly switch on the JSON object instead

List (5)

  • has: Use some instead
  • getAssoc: Use a Map instead
  • hasAssoc: Use a Map instead
  • removeAssoc: Use a Map instead
  • setAssoc: Use a Map instead

Char (9)

  • code: Use type string and String.charCodeAt instead
  • chr: Use type string and String.fromCharCode instead
  • escaped: Use type string instead
  • lowercase_ascii: Use type string and String.toLowerCase instead
  • uppercase_ascii: Use type string and String.toUpperCase instead
  • t: Use type string instead
  • compare: Use type string and String.compare instead
  • equal: Use type string and String.equal instead
  • unsafe_chr: Use type string and String.fromCharCode instead

Error (1)

  • toException: Use functions from JsExn instead

Stdlib (top level) (1)

  • lazy_t: Use Lazy.t instead

Js_* (37)

t, undefined, promise, sortInPlace, append, setMonthD, setTime, setUTCMonthD, setUTCTime, fromList, Kind, tagged_t, classify, test, deserializeUnsafe, serializeExn, isSomeValue, castToArrayLike, substr, substrAtMost, anchor, link, array_like, entries, entries, Int32_array, Int32_array, of_buffer, of_buffer, undefined_val, null_val, t, test, tagged_t, classify, test, testAny

Obj (8)

  • repr: Do not use directly
  • obj: Do not use directly
  • tag: Do not use directly
  • size: Do not use directly
  • getField: Do not use directly
  • setField: Do not use directly
  • dup: Do not use directly
  • updateDummy: Do not use directly

Related: #9399 (syntax registry, which could provide removed metadata for syntax migrations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions