Skip to content

Commit

Permalink
Drop Caml runtimes and primitives (#6984)
Browse files Browse the repository at this point in the history
* remove Caml io/formatting/converting stuffs

* remove Lexing/Parsing/Parser completely

* remove Caml_sys completely

* remove hash/digest/Hashtbl

* format jscomp/test again

* restore Hashtbl.hash

* update lib artifacts

* remove stale tests

* remove Caml compile time constants

* remove (almost) Caml String/Bytes/Char/Stream

* remove floatarray

* remove Caml int32/int64/nativeint

* remove uint32 liternal which has never exposed

* migrate caml_{type}_compare/min/max primitives

* Drop OCaml `Array` module

* drop other OCaml DS modules

* fix hashtbl size hint

* rename promise primitive

* remove unused code

* update artifacts

* remove unused module

* Drop `%lazy_force` primitive

* remove unused code

* remove/replace all remain `caml_*` primitives

* Remove unwanted float primitives

* remote unused/unnecessary exn primitives

* migrate dict primitive

* rename #import to %import

* migrate obj and option primitives

* migrate hash primitives

* remove unused code path

* remove unused internal primitives

* migrate already ones from internal primitives

* specialize every primitives in a path

* drop/rename more interfaces

* merge exn primitive modules

* move curry primitive module

* move util primitives

* update artifacts

* fix gentype test

* add empty modules for core OCamlCompat

* rename ref primitives

* bring back a few primitives for Core compatibility

* bring back error reporting on unknown #prim

* add more compat

* Js_runtime_modules -> Primitive_modules

* Remove unused code path

* Remove unused code path (floatarray) in frontend

* remove unused builtin types

* fix binding

* refactor primitive externs

* bring back Array module accessing pattern

* more compat, deprecation, and migrate stdlib-406 dir completely

* cleanup ninja dependencies

Now the only `runtime` dir is the built-in primitive literally

Removed dependency hacks from `ninja.js` and make the dependency graph clearly `others` -> `runtime`

Removed `Belt_internals` module, use compiler primitive instead

Removed `runtime/js`, so made `others/js` only source of JS bindings
Primitives shouldn't rely on JS any binding

* add deprecation on pervasives

* tmp: try fix

* clean a bit

* added %modfloat primitive, added Pervasives.mod_float compat

* added Pervasive string conversion compat

* do not mention Js module

* add clean-rewatch recipe
  • Loading branch information
cometkim authored Sep 27, 2024
1 parent 9c4af76 commit 6d78c58
Show file tree
Hide file tree
Showing 1,082 changed files with 10,742 additions and 107,105 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ checkformat:
clean-gentype:
make -C jscomp/gentype_tests/typescript-react-example clean

clean-rewatch:
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch

clean:
dune clean
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
./scripts/ninja.js clean && rm -f ninja/ninja

clean-all: clean clean-gentype
clean-all: clean clean-gentype clean-rewatch

dev-container:
docker build -t rescript-dev-container docker

.DEFAULT_GOAL := build

.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean clean-all dev-container
.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean-rewatch clean clean-all dev-container
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

We've found a bug for you!
/.../fixtures/modules2.res:1:9-14
/.../fixtures/modules2.res:1:9-19

1 │ let b = List.b
1 │ let b = Belt.List.b
2 │

The value b can't be found in List
The value b can't be found in Belt.List
17 changes: 10 additions & 7 deletions jscomp/build_tests/super_errors/expected/primitives7.res.expected
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@

We've found a bug for you!
/.../fixtures/primitives7.res:3:24
/.../fixtures/primitives7.res:3:23

1 │ /* Wanted list(float), found list(int) */
2 │ let a = list{1, 2, 3}
3 │ List.map(n => n +. 2., a)
3 │ a->Belt.List.map(n => n +. 2.)
4 │

This has type: list<int>
But this function argument is expecting: list<float>

The incompatible parts:
int vs float
This has type: int
But it's being used with the +. operator, which works on: float

Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two.

Possible solutions:
- Ensure all values in this calculation has the type float. You can convert between floats and ints via Belt.Float.toInt and Belt.Int.fromFloat.
- Change the operator to +, which works on int

You can convert int to float with Belt.Int.toFloat.
If this is a literal, try a number with a trailing dot (e.g. 20.).
34 changes: 0 additions & 34 deletions jscomp/build_tests/super_errors/expected/warnings3.res.expected

This file was deleted.

2 changes: 1 addition & 1 deletion jscomp/build_tests/super_errors/fixtures/modules2.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let b = List.b
let b = Belt.List.b
2 changes: 1 addition & 1 deletion jscomp/build_tests/super_errors/fixtures/primitives7.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Wanted list(float), found list(int) */
let a = list{1, 2, 3}
List.map(n => n +. 2., a)
a->Belt.List.map(n => n +. 2.)
3 changes: 0 additions & 3 deletions jscomp/build_tests/super_errors/fixtures/warnings3.res

This file was deleted.

2 changes: 1 addition & 1 deletion jscomp/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ and vident = Id of ident | Qualified of module_id * string option
pattern match we can ignore the first one for simplicity
for example
{[
Qualified (_, Runtime, Some "caml_int_compare")
Qualified (_, Runtime, Some "compare")
]}
*)

Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
| Length _ | Is_null_or_undefined _ | String_append _ | Typeof _ | Js_not _
| Cond _ | FlatCall _ | New _ | Fun _ | Raw_js_code _ | Array _
| Caml_block_tag _ | Object _ | Tagged_template _
| Number (Uint _) ->
false
| Await _ -> false
| Spread _ -> false

Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_block_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

let option_id = Ident.create_persistent Js_runtime_modules.option
let option_id = Ident.create_persistent Primitive_modules.option

let curry_id = Ident.create_persistent Js_runtime_modules.curry
let curry_id = Ident.create_persistent Primitive_modules.curry

let check_additional_id (x : J.expression) : Ident.t option =
match x.expression_desc with
Expand Down
8 changes: 3 additions & 5 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module L = Js_dump_lit

module Curry_gen = struct
let pp_curry_dot f =
P.string f Js_runtime_modules.curry;
P.string f Primitive_modules.curry;
P.string f L.dot

let pp_optimize_curry (f : P.t) (len : int) =
Expand Down Expand Up @@ -642,7 +642,6 @@ and expression_desc cxt ~(level : int) f x : cxt =
| Int { i; c = None } ->
Int32.to_string i
(* check , js convention with ocaml lexical convention *)
| Uint i -> Format.asprintf "%lu" i
| BigInt {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value)
in
let need_paren =
Expand All @@ -651,8 +650,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
else
level = 15 (* Parenthesize as well when followed by a dot. *)
&& s.[0] <> 'I' (* Infinity *)
&& s.[0] <> 'N'
(* NaN *)
&& s.[0] <> 'N' (* NaN *)
in
let action _ = P.string f s in
if need_paren then P.paren f action else action ();
Expand Down Expand Up @@ -722,7 +720,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
| Optional_block (e, identity) ->
expression ~level cxt f
(if identity then e
else E.runtime_call Js_runtime_modules.option "some" [ e ])
else E.runtime_call Primitive_modules.option "some" [ e ])
| Caml_block (el, _, _, Blk_module fields) ->
expression_desc cxt ~level f
(Object (None,
Expand Down
Loading

0 comments on commit 6d78c58

Please sign in to comment.