Skip to content

Commit 1869fd3

Browse files
authored
add a test case;some clean up before unicode (rescript-lang#5043)
* clean up string API to prepare unicode support * add a complex test case * fix CI
1 parent 89d82b9 commit 1869fd3

19 files changed

+3820
-3904
lines changed

jscomp/build_tests/ocamlgraph/libx/bitv.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ let to_string v =
451451
let n = v.length in
452452
let s = Bytes.make n '0' in
453453
for i = 0 to n - 1 do
454-
if unsafe_get v i then s.[i] <- '1'
454+
if unsafe_get v i then Bytes.set s i '1'
455455
done;
456456
Bytes.to_string s
457457

jscomp/main/builtin_cmi_datasets.ml

+5-5
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

+5-5
Large diffs are not rendered by default.

jscomp/stdlib-406/string.ml

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@
2323

2424
external length : string -> int = "%string_length"
2525
external get : string -> int -> char = "%string_safe_get"
26-
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
27-
external create : int -> bytes = "caml_create_bytes"
2826
external unsafe_get : string -> int -> char = "%string_unsafe_get"
29-
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
27+
3028
external unsafe_blit : string -> int -> bytes -> int -> int -> unit
3129
= "caml_blit_string" [@@noalloc]
32-
external unsafe_fill : bytes -> int -> int -> char -> unit
33-
= "caml_fill_bytes" [@@noalloc]
3430

3531
module B = Bytes
3632

@@ -41,12 +37,8 @@ external make : int -> char -> string = "caml_string_repeat"
4137

4238
let init n f =
4339
B.init n f |> bts
44-
let copy s =
45-
B.copy (bos s) |> bts
4640
let sub s ofs len =
4741
B.sub (bos s) ofs len |> bts
48-
let fill =
49-
B.fill
5042
let blit =
5143
B.blit_string
5244

jscomp/stdlib-406/string.mli

-35
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,7 @@ external get : string -> int -> char = "%string_safe_get"
5858
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
5959

6060

61-
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
62-
[@@ocaml.deprecated "Use Bytes.set instead."]
63-
(** [String.set s n c] modifies byte sequence [s] in place,
64-
replacing the byte at index [n] with [c].
65-
You can also write [s.[n] <- c] instead of [String.set s n c].
6661

67-
Raise [Invalid_argument] if [n] is not a valid index in [s].
68-
69-
@deprecated This is a deprecated alias of {!Bytes.set}.[ ] *)
70-
71-
external create : int -> bytes = "caml_create_bytes"
72-
[@@ocaml.deprecated "Use Bytes.create instead."]
73-
(** [String.create n] returns a fresh byte sequence of length [n].
74-
The sequence is uninitialized and contains arbitrary bytes.
75-
76-
Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}.
77-
78-
@deprecated This is a deprecated alias of {!Bytes.create}.[ ] *)
7962

8063
val make : int -> char -> string
8164
(** [String.make n c] returns a fresh string of length [n],
@@ -93,11 +76,6 @@ val init : int -> (int -> char) -> string
9376
@since 4.02.0
9477
*)
9578

96-
val copy : string -> string [@@ocaml.deprecated]
97-
(** Return a copy of the given string.
98-
99-
@deprecated Because strings are immutable, it doesn't make much
100-
sense to make identical copies of them. *)
10179

10280
val sub : string -> int -> int -> string
10381
(** [String.sub s start len] returns a fresh string of length [len],
@@ -107,15 +85,7 @@ val sub : string -> int -> int -> string
10785
Raise [Invalid_argument] if [start] and [len] do not
10886
designate a valid substring of [s]. *)
10987

110-
val fill : bytes -> int -> int -> char -> unit
111-
[@@ocaml.deprecated "Use Bytes.fill instead."]
112-
(** [String.fill s start len c] modifies byte sequence [s] in place,
113-
replacing [len] bytes with [c], starting at [start].
114-
115-
Raise [Invalid_argument] if [start] and [len] do not
116-
designate a valid range of [s].
11788

118-
@deprecated This is a deprecated alias of {!Bytes.fill}.[ ] *)
11989

12090
val blit : string -> int -> bytes -> int -> int -> unit
12191
(** Same as {!Bytes.blit_string}. *)
@@ -338,11 +308,6 @@ val split_on_char: char -> string -> string list
338308
(* The following is for system use only. Do not call directly. *)
339309

340310
external unsafe_get : string -> int -> char = "%string_unsafe_get"
341-
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
342-
[@@ocaml.deprecated]
343311
external unsafe_blit :
344312
string -> int -> bytes -> int -> int -> unit
345313
= "caml_blit_string" [@@noalloc]
346-
external unsafe_fill :
347-
bytes -> int -> int -> char -> unit = "caml_fill_bytes" [@@noalloc]
348-
[@@ocaml.deprecated]

jscomp/stdlib-406/stringLabels.mli

-37
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ external get : string -> int -> char = "%string_safe_get"
2424
2525
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
2626

27-
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
28-
[@@ocaml.deprecated "Use BytesLabels.set instead."]
29-
(** [String.set s n c] modifies byte sequence [s] in place,
30-
replacing the byte at index [n] with [c].
31-
You can also write [s.[n] <- c] instead of [String.set s n c].
32-
33-
Raise [Invalid_argument] if [n] is not a valid index in [s].
34-
35-
@deprecated This is a deprecated alias of {!BytesLabels.set}. *)
36-
37-
external create : int -> bytes = "caml_create_bytes"
38-
[@@ocaml.deprecated "Use BytesLabels.create instead."]
39-
(** [String.create n] returns a fresh byte sequence of length [n].
40-
The sequence is uninitialized and contains arbitrary bytes.
41-
42-
Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}.
43-
44-
@deprecated This is a deprecated alias of {!BytesLabels.create}. *)
4527

4628
val make : int -> char -> string
4729
(** [String.make n c] returns a fresh string of length [n],
@@ -56,8 +38,6 @@ val init : int -> f:(int -> char) -> string
5638
Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}.
5739
@since 4.02.0 *)
5840

59-
val copy : string -> string [@@ocaml.deprecated]
60-
(** Return a copy of the given string. *)
6141

6242
val sub : string -> pos:int -> len:int -> string
6343
(** [String.sub s start len] returns a fresh string of length [len],
@@ -67,15 +47,6 @@ val sub : string -> pos:int -> len:int -> string
6747
Raise [Invalid_argument] if [start] and [len] do not
6848
designate a valid substring of [s]. *)
6949

70-
val fill : bytes -> pos:int -> len:int -> char -> unit
71-
[@@ocaml.deprecated "Use BytesLabels.fill instead."]
72-
(** [String.fill s start len c] modifies byte sequence [s] in place,
73-
replacing [len] bytes by [c], starting at [start].
74-
75-
Raise [Invalid_argument] if [start] and [len] do not
76-
designate a valid substring of [s].
77-
78-
@deprecated This is a deprecated alias of {!BytesLabels.fill}. *)
7950

8051
val blit :
8152
src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int
@@ -293,11 +264,3 @@ val split_on_char: sep:char -> string -> string list
293264
(* The following is for system use only. Do not call directly. *)
294265

295266
external unsafe_get : string -> int -> char = "%string_unsafe_get"
296-
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
297-
[@@ocaml.deprecated]
298-
external unsafe_blit :
299-
src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int ->
300-
unit = "caml_blit_string" [@@noalloc]
301-
external unsafe_fill :
302-
bytes -> pos:int -> len:int -> char -> unit = "caml_fill_bytes" [@@noalloc]
303-
[@@ocaml.deprecated]

jscomp/test/build.ninja

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ o test/key_word_property.cmi test/key_word_property.cmj : cc test/key_word_prope
409409
o test/key_word_property2.cmi test/key_word_property2.cmj : cc test/key_word_property2.ml | test/export_keyword.cmj $stdlib
410410
o test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj : cc test/key_word_property_plus_test.ml | test/global_mangles.cmj test/mt.cmj $stdlib
411411
o test/label_uncurry.cmi test/label_uncurry.cmj : cc test/label_uncurry.ml | $stdlib
412+
o test/large_integer_pat.cmi test/large_integer_pat.cmj : cc test/large_integer_pat.ml | $stdlib
412413
o test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj : cc test/large_record_duplication_test.ml | test/mt.cmj $stdlib
413414
o test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow.ml | $stdlib
414415
o test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.re | $stdlib

0 commit comments

Comments
 (0)