rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Compiler should not rely on `Js` or `Belt` module being present

Open cknitt opened this issue 1 year ago • 3 comments

This is in preparation for switching to the Core standard library.

Currently, the compiler relies on the presence of the Js and Belt modules for quite a few things, for example async/await (Js.Promise.unsafe_async/Js.Promise.unsafe_await) or array/list spread (Belt.List.concatMany/Belt.Array.concatMany).

You can find more such usages by searching for Lident "Js" or Lident "Belt" in the compiler sources.

This should be refactored so that functions from the runtime modules (caml_*) are used instead.

cknitt avatar Jun 27 '24 17:06 cknitt

This also applies to type definitions. Js.Re.t is used somewhere, and the JSX PPX is using Js.Nullable.t.

So maybe there should also be a caml_types.res as a source for the type definitions used by Core, Js, Belt, etc.

cknitt avatar Jun 27 '24 17:06 cknitt

The runtime modules are listed in this file BTW:

jscomp/ext/js_runtime_modules.ml

cknitt avatar Jun 29 '24 12:06 cknitt

This fixes arrays spreads to not rely on Belt: https://github.com/rescript-lang/rescript-compiler/pull/7034

zth avatar Sep 12 '24 07:09 zth