Skip to content

Commit 2d26286

Browse files
committed
Drop OCaml Array module
1 parent 23a3ca9 commit 2d26286

File tree

137 files changed

+1117
-5734
lines changed

Some content is hidden

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

137 files changed

+1117
-5734
lines changed

jscomp/core/lam_analysis.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
4646
(
4747
(* more safe to check if arguments are constant *)
4848
(* non-observable side effect *)
49-
"?make_vect" | "?obj_dup" | "caml_array_dup" ),
49+
"?obj_dup" ),
5050
_ ) ->
5151
true
5252
| _, _ -> false)

jscomp/core/lam_dispatch_primitive.ml

-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ let translate loc (prim_name : string) (args : J.expression list) : J.expression
136136
like normal one to set the identifier *)
137137
| "?exn_slot_name" | "?is_extension" -> call Js_runtime_modules.exceptions
138138
| "?as_js_exn" -> call Js_runtime_modules.caml_js_exceptions
139-
| "?array_sub" -> E.runtime_call Js_runtime_modules.array "sub" args
140-
| "?array_concat" -> E.runtime_call Js_runtime_modules.array "concat" args
141-
(*external concat: 'a array list -> 'a array
142-
Not good for inline *)
143-
| "?array_blit" -> E.runtime_call Js_runtime_modules.array "blit" args
144-
| "?make_vect" -> E.runtime_call Js_runtime_modules.array "make" args
145139
| "?obj_dup" -> call Js_runtime_modules.obj_runtime
146140
| "?obj_tag" -> (
147141
(* Note that in ocaml, [int] has tag [1000] and [string] has tag [252]

jscomp/ext/js_runtime_modules.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ let bigint = "Primitive_bigint"
3232

3333
let string = "Primitive_string"
3434

35+
let array = "Primitive_array"
36+
3537
let deriving = "Runtime_deriving"
3638

3739
let promise = "Runtime_promise"
@@ -42,8 +44,6 @@ let exceptions = "Caml_exceptions"
4244

4345
let obj_runtime = "Caml_obj"
4446

45-
let array = "Caml_array"
46-
4747
let hash_primitive = "Caml_hash_primitive"
4848

4949
let hash = "Caml_hash"

jscomp/runtime/caml_array.res

-99
This file was deleted.

jscomp/runtime/caml_array.resi

-37
This file was deleted.

jscomp/runtime/caml_array_extern.res

-11
This file was deleted.

jscomp/runtime/caml_module.res

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ type rec shape =
3535
| Class
3636
| Module(array<(shape, string)>)
3737
| Value(Obj.t)
38-
/* ATTENTION: check across versions */
39-
module Array = Caml_array_extern
4038

41-
@set_index external set_field: (Obj.t, string, Obj.t) => unit = ""
39+
@get external array_length: array<'a> => int = "length"
40+
@get_index external array_unsafe_get: (array<'a>, int) => 'a = ""
4241

42+
@set_index external set_field: (Obj.t, string, Obj.t) => unit = ""
4343
@get_index external get_field: (Obj.t, string) => Obj.t = ""
4444

4545
module type Empty = {}
@@ -69,9 +69,9 @@ let init_mod = (loc: (string, int, int), shape: shape) => {
6969
| Module(comps) =>
7070
let v = Obj.repr(module({}: Empty))
7171
set_field(struct_, idx, v)
72-
let len = Array.length(comps)
72+
let len = array_length(comps)
7373
for i in 0 to len - 1 {
74-
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
74+
let (shape, name) = array_unsafe_get(comps, i)
7575
loop(shape, v, name)
7676
}
7777
| Value(v) => set_field(struct_, idx, v)
@@ -94,16 +94,16 @@ let update_mod = (shape: shape, o: Obj.t, n: Obj.t): unit => {
9494
| Class =>
9595
Caml_obj.update_dummy(o, n)
9696
| Module(comps) =>
97-
for i in 0 to Array.length(comps) - 1 {
98-
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
97+
for i in 0 to array_length(comps) - 1 {
98+
let (shape, name) = array_unsafe_get(comps, i)
9999
aux(shape, get_field(o, name), get_field(n, name), o, name)
100100
}
101101
| Value(_) => ()
102102
}
103103
switch shape {
104104
| Module(comps) =>
105-
for i in 0 to Array.length(comps) - 1 {
106-
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
105+
for i in 0 to array_length(comps) - 1 {
106+
let (shape, name) = array_unsafe_get(comps, i)
107107
aux(shape, get_field(o, name), get_field(n, name), o, name)
108108
}
109109
| _ => assert(false)

jscomp/runtime/caml_obj.res

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

25+
external array_unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get"
26+
2527
type t = Obj.t
2628

2729
module O = {
@@ -69,7 +71,6 @@ module O = {
6971
var new_record = u.slice ()
7072
7173
]}
72-
`obj_dup` is a superset of `array_dup`
7374
*/
7475
let obj_dup: Obj.t => Obj.t = %raw(`function(x){
7576
if(Array.isArray(x)){
@@ -234,7 +235,7 @@ and aux_same_length = (a: array<Obj.t>, b: array<Obj.t>, i, same_length) =>
234235
if i == same_length {
235236
0
236237
} else {
237-
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
238+
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))
238239

239240
if res != 0 {
240241
res
@@ -247,7 +248,7 @@ and aux_length_a_short = (a: array<Obj.t>, b: array<Obj.t>, i, short_length) =>
247248
if i == short_length {
248249
-1
249250
} else {
250-
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
251+
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))
251252

252253
if res != 0 {
253254
res
@@ -260,7 +261,7 @@ and aux_length_b_short = (a: array<Obj.t>, b: array<Obj.t>, i, short_length) =>
260261
if i == short_length {
261262
1
262263
} else {
263-
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
264+
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))
264265

265266
if res != 0 {
266267
res
@@ -359,7 +360,7 @@ and aux_equal_length = (a: array<Obj.t>, b: array<Obj.t>, i, same_length) =>
359360
if i == same_length {
360361
true
361362
} else {
362-
equal(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) &&
363+
equal(array_unsafe_get(a, i), array_unsafe_get(b, i)) &&
363364
aux_equal_length(a, b, i + 1, same_length)
364365
}
365366

jscomp/runtime/curry.res

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424

2525
@@uncurried
2626

27+
@get external array_length: array<'a> => int = "length"
28+
@send external array_slice: (array<'a>, int, int) => array<'a> = "slice"
29+
@send external array_concat: (array<'a>, array<'a>) => array<'a> = "concat"
30+
2731
/* Generated by scripts/curry_gen.ml */
2832
external function_length: 'a => int = "#function_length"
2933
external apply_args: ('a => 'b, array<_>) => 'b = "#apply"
3034

31-
let _ = Caml_array.sub /* make the build dependency on Caml_array explicit */
32-
%%private(let sub = Caml_array.sub)
3335
/* Public */
3436
let rec app = (f, args) => {
3537
let init_arity = function_length(f)
@@ -38,15 +40,15 @@ let rec app = (f, args) => {
3840
} else {
3941
init_arity
4042
} /* arity fixing */
41-
let len = Caml_array_extern.length(args)
43+
let len = array_length(args)
4244
let d = arity - len
4345
if d == 0 {
4446
apply_args(f, args) /* f.apply (null,args) */
4547
} else if d < 0 {
4648
/* TODO: could avoid copy by tracking the index */
47-
app(Obj.magic(apply_args(f, sub(args, 0, arity))), sub(args, arity, -d))
49+
app(Obj.magic(apply_args(f, array_slice(args, 0, arity))), array_slice(args, arity, len))
4850
} else {
49-
Obj.magic(x => app(f, Caml_array_extern.append(args, [x])))
51+
Obj.magic(x => app(f, array_concat(args, [x])))
5052
}
5153
}
5254

jscomp/runtime/primitive_array.res

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@get external length: array<'a> => int = "length"
2+
3+
@get_index external get: (array<'a>, int) => 'a = ""
4+
5+
let get = (xs, index) =>
6+
if index < 0 || index >= length(xs) {
7+
raise(Invalid_argument("index out of bounds"))
8+
} else {
9+
xs->get(index)
10+
}
11+
12+
@set_index external set: (array<'a>, int, 'a) => unit = ""
13+
14+
let set = (xs, index, newval) =>
15+
if index < 0 || index >= length(xs) {
16+
raise(Invalid_argument("index out of bounds"))
17+
} else {
18+
xs->set(index, newval)
19+
}

jscomp/runtime/release.ninja

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ o runtime/bs_stdlib_mini.cmi : cc runtime/bs_stdlib_mini.resi
1313
bsc_flags = -nostdlib -nopervasives
1414
o runtime/js.cmj runtime/js.cmi : cc runtime/js.res
1515
bsc_flags = $bsc_no_open_flags
16-
o runtime/caml_array.cmj : cc_cmi runtime/caml_array.res | runtime/caml_array.cmi runtime/caml_array_extern.cmj
17-
o runtime/caml_array.cmi : cc runtime/caml_array.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
1816
o runtime/caml_dict.cmj : cc_cmi runtime/caml_dict.res | runtime/caml_dict.cmi
1917
o runtime/caml_dict.cmi : cc runtime/caml_dict.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2018
o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/caml_exceptions.cmi
@@ -23,23 +21,23 @@ o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi r
2321
o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2422
o runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.res | runtime/caml_hash_primitive.cmi
2523
o runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
26-
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
24+
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_module.cmi runtime/caml_obj.cmj
2725
o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
28-
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/primitive_bool.cmj runtime/primitive_float.cmj runtime/primitive_int.cmj runtime/primitive_string.cmj
26+
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_obj.cmi runtime/caml_option.cmj runtime/primitive_bool.cmj runtime/primitive_float.cmj runtime/primitive_int.cmj runtime/primitive_string.cmj
2927
o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3028
o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj
3129
o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
3230
o runtime/caml_splice_call.cmj : cc_cmi runtime/caml_splice_call.res | runtime/caml_splice_call.cmi
3331
o runtime/caml_splice_call.cmi : cc runtime/caml_splice_call.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
34-
o runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj : cc runtime/caml_array_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3532
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
3633
o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
37-
o runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.res | runtime/bs_stdlib_mini.cmi runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj
34+
o runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
35+
o runtime/primitive_array.cmi runtime/primitive_array.cmj : cc runtime/primitive_array.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3836
o runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj : cc runtime/primitive_bigint.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3937
o runtime/primitive_bool.cmi runtime/primitive_bool.cmj : cc runtime/primitive_bool.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4038
o runtime/primitive_float.cmi runtime/primitive_float.cmj : cc runtime/primitive_float.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj runtime/primitive_float_extern.cmj
4139
o runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj : cc runtime/primitive_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4240
o runtime/primitive_int.cmi runtime/primitive_int.cmj : cc runtime/primitive_int.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4341
o runtime/primitive_string.cmi runtime/primitive_string.cmj : cc runtime/primitive_string.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj runtime/primitive_string_extern.cmj
4442
o runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj : cc runtime/primitive_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
45-
o runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_dict.cmi runtime/caml_dict.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj runtime/primitive_bool.cmi runtime/primitive_bool.cmj runtime/primitive_float.cmi runtime/primitive_float.cmj runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj runtime/primitive_int.cmi runtime/primitive_int.cmj runtime/primitive_string.cmi runtime/primitive_string.cmj runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj
43+
o runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml_dict.cmi runtime/caml_dict.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj runtime/primitive_array.cmi runtime/primitive_array.cmj runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj runtime/primitive_bool.cmi runtime/primitive_bool.cmj runtime/primitive_float.cmi runtime/primitive_float.cmj runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj runtime/primitive_int.cmi runtime/primitive_int.cmj runtime/primitive_string.cmi runtime/primitive_string.cmj runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj

0 commit comments

Comments
 (0)