Skip to content

Conversation

@cometkim
Copy link
Member

@cometkim cometkim commented Aug 27, 2024

Resolves #5779

Rationale

This removes runtime modules and primitives that exist for OCaml compatibility.

The original BuckleScript tried distinguishing between OCaml-inherited primitives and custom primitives (?prim) and js primitives (#prim), but it didn't stick well.

Since we gave up OCaml compatibility, it added unnecessary complexity with indirection, making it hard to predict where specialization would be performed.

So here I unify all primitives into a single prefix grammar of %. There is still # primitive, but it exists temporarily for compatibility or is meant to be internal to the compiler and not exposed to the frontend.

Changes

This PR contains many breaking changes

  • Removed unused code path
  • Removed unnecessary test files
  • Changed runtime semantics
    • Primitive_object.updateDummy (formally Caml_obj.update_dummy) behavior is now the same as the Object.assign and doesn't specially handle Array instances. See discussion from Improve obj dup using spread syntax #7043. But this is safer because it is only used in module rec bindings.
    • Removes the ascii bound restriction of char primitives.
    • String.get: (string, int) => char behavior is now the same as the String.prototype.codePointAt. It was potentially buggy with existing char primitives, but this fixes it. See RFC: Revise char primitive #7028
  • Dropped built-in types
    • int32 (use int instead)
    • int64
    • uint32
    • nativeint
    • floatarray (use Float32Array or Float64Array instead)
    • bytes (use ArrayBuffer or Uinr8Array instead)
  • Renamed primitives
    • comparison
      • caml_{type}_compare -> %{type}order (e.g. %intorder)
      • caml_{type}_min -> %{type}min (e.g. %intmin)
      • caml_{type}_max -> %{type}max (e.g. %intmax)
      • %bs_min -> %min
      • %bs_max -> %max
      • %bs_equal_null -> %equal_null
      • %bs_equal_undefined -> %equal_undefined
      • %bs_equal_nullable -> %equal_nullable
      • #unsafe_lt -> %unsafe_lt
      • #unsafe_gt -> %unsafe_gt
      • #unsafe_le -> %unsafe_le
      • #unsafe_ge -> %unsafe_ge
      • #unsafe_eq -> %unsafe_eq
      • #unsafe_neq -> %unsafe_neq
      • %bs_equal_null -> %equal_null
      • %bs_equal_undefined -> %equal_undefined
      • %bs_equal_nullable -> %equal_nullable
    • js
      • #debugger -> %debugger
      • #typeof -> %typeof
      • #null -> %null
      • #undefined -> %undefined
    • ref
      • %makemutable -> %makeref
      • %bs_field0 -> %refget
      • %bs_set_field0 -> %refset
    • dict
      • ?create_dict -> %makedict
    • list
      • #makemutablelist -> %makemutablelist
    • promise
      • ?await -> %await
    • module
      • #import -> %import
    • curry
      • #apply{N} -> %curry_apply{N}
    • option
      • #is_nullable -> %is_nullable
      • #nullable_to_opt -> %nullable_to_opt
      • #null_to_opt -> %null_to_opt
      • #undefined_to_opt -> %undefined_to_opt
    • exceptions
      • #wrap_exn -> %wrap_exn
    • hash
      • #hash -> %hash
      • #hash_mix_int -> %hash_mix_int
      • #hash_mix_string -> %hash_mix_string
      • #hash_final_mix -> %hash_final_mix
    • etc
      • #unsafe_to_method -> %unsafe_to_method
      • #function_length -> %function_arity
  • Dropped primitives
    • ?obj_dup (from Improve obj dup using spread syntax #7043)
    • formatting
      • ?hexstring_of_float
      • ?float_of_string
      • ?int_of_string
      • ?int64_of_string
      • ?int64_format
      • ?format_int
      • ?format_float
    • parsing
      • ?lex_engine
      • ?new_lex_engine
      • ?parse_engine
      • ?set_parser_trace
    • hashing
      • ?md5_string
    • string
      • ?string_repeat
    • bytes
      • ?create_bytes
      • ?bytes_length
      • ?bytes_safe_get
      • ?bytes_safe_set
      • ?bytes_unsafe_get
      • ?bytes_unsafe_set
      • caml_bytes_*
    • int64
      • %int64_*
      • caml_int64_*
    • bigint
      • ?bigint_div
      • ?bigint_mod
      • %bigint_of_int32
      • %bigint_to_int32
    • float
      • ?int_of_float (%intoffloat is still available)
      • ?float_of_int (%floatofint is still available)
      • ?int_float_of_bits
      • ?int_bits_of_float
      • ?fmod_float
      • ?modf_float
      • ?ldexp_float
      • ?frexp_float
      • ?copysign_float
      • ?expm1_float
      • ?hypot_float
    • exn
      • ?exn_slot_name
      • ?is_extension
      • ?as_js_exn
      • %reraise
      • %raise_notrace
    • lazy
      • %lazy_force (Use Lazy.force instead)
  • Dropped BS compile-time constants
    • %backend_type
    • %word_size
    • %int_size
    • %max_wosize
  • Dropped OCaml literal
    • 0u (uint32) literal
    • 0l (int32) literal
    • 0L (int64) literal
  • Dropped Js functions (which was not Js)
    • Js.isCamlExceptionOrOpenVariant
  • Dropped pervasive functions
    • format_float
    • string_of_bool
    • bool_of_string
    • bool_of_string_opt
    • string_of_int
    • int_of_string
    • int_of_string_opt
    • string_of_float
    • float_of_string
    • float_of_string_opt
    • print_string
    • print_int
    • print_float
    • print_endline
    • print_newline
    • prerr_endline
    • prerr_newline
    • valid_float_lexem
  • Dropped OCaml std modules
    • Arg
    • Callback
    • Genlex
    • Lexing
    • Parsing
    • Parsing
    • Digest
    • Random
    • Bytes
    • Uchar
    • Buffer
    • Stream
    • Filename
    • Int32
    • Int64
    • String partially
    • Char partially
    • Array
    • Sort
    • List
    • Set
    • Map
    • Hashtbl (except Hashtbl.hash)
    • Map
    • Stack
    • Queue
    • Complex
  • Modified primitive runtime modules
    • Caml_module -> Primitive_module
    • Caml_obj -> Primitive_object
    • Caml_array -> Primitive_array
    • Caml_char -> Primitive_char
    • Caml_string -> Primitive_string
    • Caml_exceptions, Caml_js_exceptions -> Primitive_exceptions
    • Caml_hash, Caml_hash_primitive -> Primitive_hash
    • Caml_lazy -> Primitive_lazy
    • Caml_module -> Primitive_module
    • Caml_option -> Primitive_option
    • Curry -> Primitive_curry
    • Runtime_promise -> Primitive_promise
    • Runtime_dict -> Primitive_dict
    • Runtime_deriving -> Primitive_util
    • x -> Primitive_bool
    • x -> Primitive_int
    • x -> Primitive_float
    • x -> Primitive_bigint
    • Caml_format -> x
    • Caml_sys -> x
    • Caml_lexer -> x
    • Caml_parser -> x
    • Caml_md5 -> x
    • Caml_int32 -> x
    • Caml_int64 -> x
    • Caml_splice_call -> x (from improve variadic call using spread syntax #7030)

Note for future refactoring

All primitives except # prefixed should eventually be treated as "features" and documented. We can rename all by a new convention for primitive names, but the old names should be kept for a while for compatibility.

Primitives are declared in two different places because they are processed separately before and after Lam_convert. It is difficult to change and to determine the types used or not used, resulting in many dangerous assertions.

Ultimately, I want to consolidate the primitive declarations into one place and make them easier to manage.

@DZakh
Copy link
Member

DZakh commented Aug 27, 2024

Like it

@cometkim cometkim force-pushed the drop-caml branch 2 times, most recently from 035a175 to 6737fe8 Compare August 27, 2024 20:31
@cometkim cometkim mentioned this pull request Sep 5, 2024
@cometkim cometkim force-pushed the drop-caml branch 5 times, most recently from 904f3ff to 3fe91d0 Compare September 8, 2024 21:20
@cometkim cometkim force-pushed the drop-caml branch 6 times, most recently from 1ffebf9 to 83d9bce Compare September 10, 2024 21:56
@cometkim cometkim force-pushed the drop-caml branch 5 times, most recently from fe725f5 to e263f97 Compare September 22, 2024 17:50
@cometkim cometkim changed the title WIP: Drop Caml runtimes and primitives Drop Caml runtimes and primitives Sep 22, 2024
@cometkim cometkim marked this pull request as ready for review September 22, 2024 18:26
@cometkim
Copy link
Member Author

Could you just bring back the "cargo clean" in the Makefile in some form or other a discussed above? Then good to go from my point of view.

Added clean-rewatch, and rebased

@zth
Copy link
Member

zth commented Sep 27, 2024

Merge! Merge! Merge!

😁

@cknitt cknitt merged commit 6d78c58 into rescript-lang:master Sep 27, 2024
20 checks passed
@cknitt
Copy link
Member

cknitt commented Sep 27, 2024

Merged! 🎉

@cometkim cometkim deleted the drop-caml branch September 27, 2024 15:03
cometkim added a commit that referenced this pull request Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants