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

-11
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

-6
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

+5-5
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

-17
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

-7
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

-27
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

-12
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

-6
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

-6
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

-3
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"

jscomp/ml/ctype.ml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1893,11 +1893,7 @@ let is_instantiable env p =
18931893

18941894

18951895
(* PR#7113: -safe-string should be a global property *)
1896-
let compatible_paths p1 p2 =
1897-
let open Predef in
1898-
Path.same p1 p2 ||
1899-
Path.same p1 path_bytes && Path.same p2 path_string ||
1900-
Path.same p1 path_string && Path.same p2 path_bytes
1896+
let compatible_paths p1 p2 = Path.same p1 p2
19011897

19021898
(* Check for datatypes carefully; see PR#6348 *)
19031899
let rec expands_to_datatype env ty =

jscomp/ml/lambda.ml

-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ type is_safe =
177177

178178
type primitive =
179179
| Pidentity
180-
| Pbytes_to_string
181180
| Pignore
182181
| Prevapply
183182
| Pdirapply
@@ -221,7 +220,6 @@ type primitive =
221220
| Pbigintcomp of comparison
222221
(* String operations *)
223222
| Pstringlength | Pstringrefu | Pstringrefs
224-
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
225223
(* Array operations *)
226224
| Pmakearray of Asttypes.mutable_flag
227225
| Parraylength

jscomp/ml/lambda.mli

-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ type pointer_info =
150150

151151
type primitive =
152152
| Pidentity
153-
| Pbytes_to_string
154153
| Pignore
155154
| Prevapply
156155
| Pdirapply
@@ -193,7 +192,6 @@ type primitive =
193192
| Pbigintcomp of comparison
194193
(* String operations *)
195194
| Pstringlength | Pstringrefu | Pstringrefs
196-
| Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets
197195
(* Array operations *)
198196
| Pmakearray of mutable_flag
199197
| Parraylength

jscomp/ml/predef.ml

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ let ident_create_predef_exn = wrap Ident.create_predef_exn
3131

3232
let ident_int = ident_create "int"
3333
and ident_char = ident_create "char"
34-
and ident_bytes = ident_create "bytes"
3534
and ident_float = ident_create "float"
3635
and ident_bool = ident_create "bool"
3736
and ident_unit = ident_create "unit"
@@ -75,7 +74,6 @@ let type_is_builtin_path_but_option (p : Path.t) : test =
7574

7675
let path_int = Pident ident_int
7776
and path_char = Pident ident_char
78-
and path_bytes = Pident ident_bytes
7977
and path_float = Pident ident_float
8078
and path_bool = Pident ident_bool
8179
and path_unit = Pident ident_unit
@@ -101,7 +99,6 @@ and path_uncurried = Pident ident_uncurried
10199

102100
let type_int = newgenty (Tconstr(path_int, [], ref Mnil))
103101
and type_char = newgenty (Tconstr(path_char, [], ref Mnil))
104-
and type_bytes = newgenty (Tconstr(path_bytes, [], ref Mnil))
105102
and type_float = newgenty (Tconstr(path_float, [], ref Mnil))
106103
and type_bool = newgenty (Tconstr(path_bool, [], ref Mnil))
107104
and type_unit = newgenty (Tconstr(path_unit, [], ref Mnil))
@@ -325,12 +322,11 @@ let common_initial_env add_type add_extension empty_env =
325322

326323
let build_initial_env add_type add_exception empty_env =
327324
let common = common_initial_env add_type add_exception empty_env in
328-
let res = add_type ident_bytes decl_abstr common in
329325
let decl_type_char =
330326
{decl_abstr with
331327
type_manifest = Some type_int;
332328
type_private = Private} in
333-
add_type ident_char decl_type_char res
329+
add_type ident_char decl_type_char common
334330

335331

336332
let builtin_values =

jscomp/ml/predef.mli

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ open Types
2020
val type_int: type_expr
2121
val type_char: type_expr
2222
val type_string: type_expr
23-
val type_bytes: type_expr
2423
val type_float: type_expr
2524
val type_bool: type_expr
2625
val type_unit: type_expr
@@ -40,7 +39,6 @@ val type_floatarray:type_expr
4039
val path_int: Path.t
4140
val path_char: Path.t
4241
val path_string: Path.t
43-
val path_bytes: Path.t
4442
val path_float: Path.t
4543
val path_bool: Path.t
4644
val path_unit: Path.t

jscomp/ml/printlambda.ml

-13
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ let print_taginfo ppf = function
122122

123123
let primitive ppf = function
124124
| Pidentity -> fprintf ppf "id"
125-
| Pbytes_to_string -> fprintf ppf "bytes_to_string"
126125
| Pignore -> fprintf ppf "ignore"
127126
| Prevapply -> fprintf ppf "revapply"
128127
| Pdirapply -> fprintf ppf "dirapply"
@@ -197,12 +196,6 @@ let primitive ppf = function
197196
| Pstringlength -> fprintf ppf "string.length"
198197
| Pstringrefu -> fprintf ppf "string.unsafe_get"
199198
| Pstringrefs -> fprintf ppf "string.get"
200-
| Pbyteslength -> fprintf ppf "bytes.length"
201-
| Pbytesrefu -> fprintf ppf "bytes.unsafe_get"
202-
| Pbytessetu -> fprintf ppf "bytes.unsafe_set"
203-
| Pbytesrefs -> fprintf ppf "bytes.get"
204-
| Pbytessets -> fprintf ppf "bytes.set"
205-
206199
| Parraylength -> fprintf ppf "array.length"
207200
| Pmakearray Mutable -> fprintf ppf "makearray"
208201
| Pmakearray Immutable -> fprintf ppf "makearray_imm"
@@ -242,7 +235,6 @@ let primitive ppf = function
242235
| Pcreate_extension s -> fprintf ppf "extension[%s]" s
243236
let name_of_primitive = function
244237
| Pidentity -> "Pidentity"
245-
| Pbytes_to_string -> "Pbytes_to_string"
246238
| Pignore -> "Pignore"
247239
| Prevapply -> "Prevapply"
248240
| Pdirapply -> "Pdirapply"
@@ -298,11 +290,6 @@ let name_of_primitive = function
298290
| Pstringlength -> "Pstringlength"
299291
| Pstringrefu -> "Pstringrefu"
300292
| Pstringrefs -> "Pstringrefs"
301-
| Pbyteslength -> "Pbyteslength"
302-
| Pbytesrefu -> "Pbytesrefu"
303-
| Pbytessetu -> "Pbytessetu"
304-
| Pbytesrefs -> "Pbytesrefs"
305-
| Pbytessets -> "Pbytessets"
306293
| Parraylength -> "Parraylength"
307294
| Pmakearray _-> "Pmakearray"
308295
| Parrayrefu -> "Parrayrefu"

0 commit comments

Comments
 (0)