Repository navigation
Description
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-allorrescript formatwherever 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, andstringifyWithIndentand the similar variants →stringifywith labelled arguments.List.has→List.some.Stdlib.lazy_t→Lazy.t.Char:charis an alias ofintin v13, soChar.code(c)→candChar.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
...Undefinedfunctions (Belt.Array.getUndefined, …), removed in Remove Belt xxxUndefined API #8377. 12.x has no stdlibUndefinedmodule, so a type-preserving template isn't possible. A deprecation pointing to theoption-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 asr := r.contents + 1andr := r.contents - 1. -
Int.fromString's~radixargument, 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,toArrayWithMapperandforEach→IteratorObject.*.
The targets don't exist in 12.x. These could stay in 13.0 as deprecated aliases with templates, so
migrate-allhandles 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: thetaggedTemplate<'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 usefailwith: Use custom exception insteadinvalid_arg: Use custom exception insteadsucc: Usex => x + 1insteadpred: Usex => x - 1insteadabs: UseMath.absinsteadland: UseInt.bitwiseAndinsteadlor: UseInt.bitwiseOrinsteadlxor: UseInt.bitwiseXorinsteadlnot: UseInt.bitwiseNotinsteadlsl: UseInt.shiftLeftinsteadlsr: UseInt.shiftRightUnsignedinsteadasr: UseInt.shiftRightinsteadmax_int: UseInt.Constants.maxValueinsteadmin_int: UseInt.Constants.minValueinsteadexp: UseMath.expinsteadacos: UseMath.acosinsteadasin: UseMath.asininsteadatan: UseMath.ataninsteadatan2: UseMath.atan2insteadcos: UseMath.cosinsteadcosh: UseMath.coshinsteadlog: UseMath.loginsteadlog10: UseMath.log10insteadlog1p: UseMath.log1pinsteadsin: UseMath.sininsteadsinh: UseMath.sinhinsteadsqrt: UseMath.sqrtinsteadtan: UseMath.taninsteadtanh: UseMath.tanhinsteadceil: UseMath.ceilinsteadfloor: UseMath.floorinsteadabs_float: UseMath.absinsteadmod_float: Use%insteadfloat: UseInt.toFloatinsteadfloat_of_int: UseInt.toFloatinsteadtruncate: UseFloat.toIntinsteadint_of_float: UseFloat.toIntinsteadinfinity: UseFloat.positiveInfinityinsteadneg_infinity: UseFloat.negativeInfinityinsteadnan: UseFloat.naninsteadmax_float: UseFloat.Constants.maxValueinsteadmin_float: UseFloat.Constants.minValueinsteadepsilon_float: UseFloat.Constants.epsiloninsteadfpclass: Do not useclassify_float: Do not useint_of_char: Use typestringandString.charCodeAtinsteadunsafe_char_of_int: Use typestringandString.fromCharCodeinsteadchar_of_int: Use typestringandString.fromCharCodeinsteadfst: UsePair.firstinsteadsnd: UsePair.secondinsteadincr: Do not useincr: UseInt.Ref.incrementinsteaddecr: UseInt.Ref.decrementinsteadstring_of_bool: UseBool.toStringinsteadbool_of_string: UseBool.fromStringinsteadbool_of_string_opt: UseBool.fromStringinsteadstring_of_int: UseInt.toStringinsteadint_of_string: UseInt.fromStringinsteadint_of_string_opt: UseInt.fromStringinsteadstring_get: UseString.getinstead
JSON (13)
parseExn: UseparseOrThrowinsteadparseExnWithReviver: UseparseOrThrowwith optional parameter insteadstringifyWithIndent: Usestringifywith optional parameter insteadstringifyWithReplacer: Usestringifywith optional parameter insteadstringifyWithReplacerAndIndent: Usestringifywith optional parameters insteadstringifyWithFilter: Usestringifywith optional parameter insteadstringifyWithFilterAndIndent: Usestringifywith optional parameters insteadstringifyAnyWithIndent: UsestringifyAnywith optional parameter insteadstringifyAnyWithReplacer: UsestringifyAnywith optional parameter insteadstringifyAnyWithReplacerAndIndent: UsestringifyAnywith optional parameters insteadstringifyAnyWithFilter: UsestringifyAnywith optional parameter insteadstringifyAnyWithFilterAndIndent: UsestringifyAnywith optional parameters insteadclassify: Directly switch on the JSON object instead
List (5)
has: UsesomeinsteadgetAssoc: Use aMapinsteadhasAssoc: Use aMapinsteadremoveAssoc: Use aMapinsteadsetAssoc: Use aMapinstead
Char (9)
code: Use typestringandString.charCodeAtinsteadchr: Use typestringandString.fromCharCodeinsteadescaped: Use typestringinsteadlowercase_ascii: Use typestringandString.toLowerCaseinsteaduppercase_ascii: Use typestringandString.toUpperCaseinsteadt: Use typestringinsteadcompare: Use typestringandString.compareinsteadequal: Use typestringandString.equalinsteadunsafe_chr: Use typestringandString.fromCharCodeinstead
Error (1)
toException: Use functions fromJsExninstead
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 directlyobj: Do not use directlytag: Do not use directlysize: Do not use directlygetField: Do not use directlysetField: Do not use directlydup: Do not use directlyupdateDummy: Do not use directly
Related: #9399 (syntax registry, which could provide removed metadata for syntax migrations).
Activity