Skip to content

Commit 035a175

Browse files
committed
remove (almost) Caml String/Bytes/Char/Stream
1 parent 4d9ee4b commit 035a175

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+57
-3924
lines changed

jscomp/core/js_of_lam_string.ml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ let const_char (i : int) = E.int ~c:i (Int32.of_int @@ i)
3434
(* string [s[i]] expects to return a [ocaml_char] *)
3535
let ref_string e e1 = E.string_index e e1
3636

37-
(* [s[i]] excepts to return a [ocaml_char]
38-
We use normal array for [bytes]
39-
TODO: we can use [Buffer] in the future
40-
*)
41-
let ref_byte e e0 = E.array_index e e0
42-
43-
(* {Bytes.set : bytes -> int -> char -> unit }*)
44-
let set_byte e e0 e1 = E.assign (E.array_index e e0) e1
45-
4637
(**
4738
Note that [String.fromCharCode] also works, but it only
4839
work for small arrays, however, for {bytes_to_string} it is likely the bytes
@@ -59,5 +50,3 @@ let set_byte e e0 e1 = E.assign (E.array_index e e0) e1
5950
Maxiume call stack size exceeded
6051
]}
6152
*)
62-
let bytes_to_string e =
63-
E.runtime_call Js_runtime_modules.bytes_ "to_string" [ e ]

jscomp/core/js_of_lam_string.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@
3030

3131
val ref_string : J.expression -> J.expression -> J.expression
3232

33-
val ref_byte : J.expression -> J.expression -> J.expression
34-
35-
val set_byte : J.expression -> J.expression -> J.expression -> J.expression
36-
3733
val const_char : int -> J.expression
38-
39-
val bytes_to_string : J.expression -> J.expression

jscomp/core/lam_analysis.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
4848
(* more safe to check if arguments are constant *)
4949
(* non-observable side effect *)
5050
| "?sys_get_argv" (* should be fine *)
51-
| "?string_repeat" | "?make_vect" | "?create_bytes" | "?obj_dup"
51+
| "?make_vect" | "?obj_dup"
5252
| "caml_array_dup" | "?nativeint_add" | "?nativeint_div"
5353
| "?nativeint_mod" | "?nativeint_lsr" | "?nativeint_mul" ),
5454
_ ) ->
@@ -63,7 +63,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
6363
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit
6464
| Pjs_object_create _ | Pimport
6565
(* TODO: check *)
66-
| Pbytes_to_string | Pmakeblock _
66+
| Pmakeblock _
6767
(* whether it's mutable or not *)
6868
| Pfield _ | Pval_from_option | Pval_from_option_not_nest
6969
(* NOP The compiler already [t option] is the same as t *)
@@ -81,8 +81,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
8181
| Pandbigint | Porbigint | Pxorbigint | Plslbigint | Pasrbigint
8282
| Pbigintcomp _
8383
(* String operations *)
84-
| Pstringlength | Pstringrefu | Pstringrefs | Pbyteslength | Pbytesrefu
85-
| Pbytesrefs | Pmakearray | Parraylength | Parrayrefu | Parrayrefs
84+
| Pstringlength | Pstringrefu | Pstringrefs
85+
| Pmakearray | Parraylength | Parrayrefu | Parrayrefs
8686
(* Test if the argument is a block or an immediate integer *)
8787
| Pisint | Pis_poly_var_block
8888
(* Test if the (integer) argument is outside an interval *)
@@ -103,7 +103,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
103103
| Pjs_unsafe_downgrade _ | Pdebugger | Pvoid_run | Pfull_apply
104104
| Pjs_fn_method
105105
(* TODO *)
106-
| Praw_js_code _ | Pbytessetu | Pbytessets
106+
| Praw_js_code _
107107
(* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *)
108108
| Parraysets
109109
(* byte swap *)

jscomp/core/lam_compile_primitive.ml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
308308
*)
309309
| [ range; e ] -> E.is_out (E.offset e off) range
310310
| _ -> assert false)
311-
| Pbytes_to_string ->
312-
Js_of_lam_string.bytes_to_string (Ext_list.singleton_exn args)
313311
| Pstringlength -> E.string_length (Ext_list.singleton_exn args)
314-
| Pbyteslength -> E.bytes_length (Ext_list.singleton_exn args)
315-
(* This should only be Pbyteset(u|s), which in js, is an int array
316-
Bytes is an int array in javascript
317-
*)
318-
| Pbytessetu -> (
319-
match args with
320-
| [ e; e0; e1 ] ->
321-
ensure_value_unit cxt.continuation (Js_of_lam_string.set_byte e e0 e1)
322-
| _ -> assert false)
323-
| Pbytessets -> E.runtime_call Js_runtime_modules.bytes "set" args
324-
| Pbytesrefu -> (
325-
match args with
326-
| [ e; e1 ] -> Js_of_lam_string.ref_byte e e1
327-
| _ -> assert false)
328-
| Pbytesrefs -> E.runtime_call Js_runtime_modules.bytes "get" args
329312
| Pstringrefs -> E.runtime_call Js_runtime_modules.string "get" args
330313
(* For bytes and string, they both return [int] in ocaml
331314
we need tell Pbyteref from Pstringref

jscomp/core/lam_convert.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
165165
| Prevapply -> assert false
166166
| Pdirapply -> assert false
167167
| Ploc _ -> assert false (* already compiled away here*)
168-
| Pbytes_to_string (* handled very early *) ->
169-
prim ~primitive:Pbytes_to_string ~args loc
170168
| Pcreate_extension s -> prim ~primitive:(Pcreate_extension s) ~args loc
171169
| Pignore ->
172170
(* Pignore means return unit, it is not an nop *)
@@ -239,11 +237,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
239237
| Pstringrefu -> prim ~primitive:Pstringrefu ~args loc
240238
| Pabsfloat -> assert false
241239
| Pstringrefs -> prim ~primitive:Pstringrefs ~args loc
242-
| Pbyteslength -> prim ~primitive:Pbyteslength ~args loc
243-
| Pbytesrefu -> prim ~primitive:Pbytesrefu ~args loc
244-
| Pbytessetu -> prim ~primitive:Pbytessetu ~args loc
245-
| Pbytesrefs -> prim ~primitive:Pbytesrefs ~args loc
246-
| Pbytessets -> prim ~primitive:Pbytessets ~args loc
247240
| Pisint -> prim ~primitive:Pisint ~args loc
248241
| Pisout -> (
249242
match args with

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ let translate loc (prim_name : string) (args : J.expression list) : J.expression
7777
Location.prerr_warning loc Warnings.Bs_polymorphic_comparison;
7878
call Js_runtime_modules.obj_runtime
7979
(* generated by the compiler, not user facing *)
80-
| "caml_bytes_greaterthan" | "caml_bytes_greaterequal" | "caml_bytes_lessthan"
81-
| "caml_bytes_lessequal" | "caml_bytes_compare" | "caml_bytes_equal" ->
82-
call Js_runtime_modules.bytes
8380
| "caml_string_equal" -> (
8481
match args with [ e0; e1 ] -> E.string_equal e0 e1 | _ -> assert false)
8582
| "caml_string_notequal" -> (
@@ -177,30 +174,6 @@ let translate loc (prim_name : string) (args : J.expression list) : J.expression
177174
call Js_runtime_modules.float
178175
| "?fmod_float" (* float module like js number module *) -> (
179176
match args with [ e0; e1 ] -> E.float_mod e0 e1 | _ -> assert false)
180-
| "?string_repeat" -> (
181-
match args with
182-
| [ n; { expression_desc = Number (Int { i }) } ] -> (
183-
let str = String.make 1 (Char.chr (Int32.to_int i)) in
184-
match n.expression_desc with
185-
| Number (Int { i = 1l }) -> E.str str
186-
| _ ->
187-
E.call
188-
(E.dot (E.str str) "repeat")
189-
[ n ] ~info:Js_call_info.builtin_runtime_call)
190-
| _ -> E.runtime_call Js_runtime_modules.string "make" args)
191-
| "?create_bytes" -> (
192-
(* Bytes.create *)
193-
(* Note that for invalid range, JS raise an Exception RangeError,
194-
here in OCaml it's [Invalid_argument], we have to preserve this semantics.
195-
Also, it's creating a [bytes] which is a js array actually.
196-
*)
197-
match args with
198-
| [ { expression_desc = Number (Int { i; _ }); _ } ] when i < 8l ->
199-
(*Invariants: assuming bytes are [int array]*)
200-
E.array NA
201-
(if i = 0l then []
202-
else Ext_list.init (Int32.to_int i) (fun _ -> E.zero_int_literal))
203-
| _ -> E.runtime_call Js_runtime_modules.bytes "create" args)
204177
(* Note we captured [exception/extension] creation in the early pass, this primitive is
205178
like normal one to set the identifier *)
206179
| "?exn_slot_name" | "?is_extension" -> call Js_runtime_modules.exceptions

jscomp/core/lam_primitive.ml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type record_representation =
3333
(* Inlined record under extension *)
3434

3535
type t =
36-
| Pbytes_to_string
3736
(* Operations on heap blocks *)
3837
| Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag
3938
| Pfield of int * Lam_compat.field_dbg_info
@@ -105,11 +104,6 @@ type t =
105104
| Pstringrefu
106105
| Pstringrefs
107106
| Pstringadd
108-
| Pbyteslength
109-
| Pbytesrefu
110-
| Pbytessetu
111-
| Pbytesrefs
112-
| Pbytessets
113107
(* Array operations *)
114108
| Pmakearray
115109
| Parraylength
@@ -185,7 +179,6 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
185179
| Pcreate_extension a -> (
186180
match rhs with Pcreate_extension b -> a = (b : string) | _ -> false)
187181
| Pwrap_exn -> rhs = Pwrap_exn
188-
| Pbytes_to_string -> rhs = Pbytes_to_string
189182
| Praise -> rhs = Praise
190183
| Psequand -> rhs = Psequand
191184
| Psequor -> rhs = Psequor
@@ -231,11 +224,6 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
231224
| Pstringrefu -> rhs = Pstringrefu
232225
| Pstringrefs -> rhs = Pstringrefs
233226
| Pstringadd -> rhs = Pstringadd
234-
| Pbyteslength -> rhs = Pbyteslength
235-
| Pbytesrefu -> rhs = Pbytesrefu
236-
| Pbytessetu -> rhs = Pbytessetu
237-
| Pbytesrefs -> rhs = Pbytesrefs
238-
| Pbytessets -> rhs = Pbytessets
239227
| Pundefined_to_opt -> rhs = Pundefined_to_opt
240228
| Pnull_to_opt -> rhs = Pnull_to_opt
241229
| Pnull_undefined_to_opt -> rhs = Pnull_undefined_to_opt

jscomp/core/lam_primitive.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type record_representation =
3131
(* Inlined record under extension *)
3232

3333
type t =
34-
| Pbytes_to_string
3534
| Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag
3635
| Pfield of int * Lambda.field_dbg_info
3736
| Psetfield of int * Lambda.set_field_dbg_info
@@ -94,11 +93,6 @@ type t =
9493
| Pstringrefu
9594
| Pstringrefs
9695
| Pstringadd
97-
| Pbyteslength
98-
| Pbytesrefu
99-
| Pbytessetu
100-
| Pbytesrefs
101-
| Pbytessets
10296
(* Array operations *)
10397
| Pmakearray
10498
| Parraylength

jscomp/core/lam_print.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ let primitive ppf (prim : Lam_primitive.t) =
5555
| Pcaml_obj_length -> fprintf ppf "#obj_length"
5656
| Pinit_mod -> fprintf ppf "init_mod!"
5757
| Pupdate_mod -> fprintf ppf "update_mod!"
58-
| Pbytes_to_string -> fprintf ppf "bytes_to_string"
5958
| Pjs_apply -> fprintf ppf "#apply"
6059
| Pjs_runtime_apply -> fprintf ppf "#runtime_apply"
6160
| Pjs_unsafe_downgrade { name; setter } ->
@@ -161,11 +160,6 @@ let primitive ppf (prim : Lam_primitive.t) =
161160
| Pstringlength -> fprintf ppf "string.length"
162161
| Pstringrefu -> fprintf ppf "string.unsafe_get"
163162
| Pstringrefs -> fprintf ppf "string.get"
164-
| Pbyteslength -> fprintf ppf "bytes.length"
165-
| Pbytesrefu -> fprintf ppf "bytes.unsafe_get"
166-
| Pbytessetu -> fprintf ppf "bytes.unsafe_set"
167-
| Pbytesrefs -> fprintf ppf "bytes.get"
168-
| Pbytessets -> fprintf ppf "bytes.set"
169163
| Parraylength -> fprintf ppf "array.length"
170164
| Pmakearray -> fprintf ppf "makearray"
171165
| Parrayrefu -> fprintf ppf "array.unsafe_get"

jscomp/ext/js_runtime_modules.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ let array = "Caml_array"
3030

3131
let string = "Caml_string"
3232

33-
let bytes = "Caml_bytes"
34-
let bytes_ = "Bytes"
35-
3633
let float = "Caml_float"
3734

3835
let hash_primitive = "Caml_hash_primitive"

0 commit comments

Comments
 (0)