Skip to content

Commit

Permalink
Drop OCaml Array module
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Sep 8, 2024
1 parent 23a3ca9 commit 904f3ff
Show file tree
Hide file tree
Showing 137 changed files with 1,117 additions and 5,734 deletions.
2 changes: 1 addition & 1 deletion jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
(
(* more safe to check if arguments are constant *)
(* non-observable side effect *)
"?make_vect" | "?obj_dup" | "caml_array_dup" ),
"?obj_dup" ),
_ ) ->
true
| _, _ -> false)
Expand Down
6 changes: 0 additions & 6 deletions jscomp/core/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ let translate loc (prim_name : string) (args : J.expression list) : J.expression
like normal one to set the identifier *)
| "?exn_slot_name" | "?is_extension" -> call Js_runtime_modules.exceptions
| "?as_js_exn" -> call Js_runtime_modules.caml_js_exceptions
| "?array_sub" -> E.runtime_call Js_runtime_modules.array "sub" args
| "?array_concat" -> E.runtime_call Js_runtime_modules.array "concat" args
(*external concat: 'a array list -> 'a array
Not good for inline *)
| "?array_blit" -> E.runtime_call Js_runtime_modules.array "blit" args
| "?make_vect" -> E.runtime_call Js_runtime_modules.array "make" args
| "?obj_dup" -> call Js_runtime_modules.obj_runtime
| "?obj_tag" -> (
(* Note that in ocaml, [int] has tag [1000] and [string] has tag [252]
Expand Down
4 changes: 2 additions & 2 deletions jscomp/ext/js_runtime_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let bigint = "Primitive_bigint"

let string = "Primitive_string"

let array = "Primitive_array"

let deriving = "Runtime_deriving"

let promise = "Runtime_promise"
Expand All @@ -42,8 +44,6 @@ let exceptions = "Caml_exceptions"

let obj_runtime = "Caml_obj"

let array = "Caml_array"

let hash_primitive = "Caml_hash_primitive"

let hash = "Caml_hash"
Expand Down
99 changes: 0 additions & 99 deletions jscomp/runtime/caml_array.res

This file was deleted.

37 changes: 0 additions & 37 deletions jscomp/runtime/caml_array.resi

This file was deleted.

11 changes: 0 additions & 11 deletions jscomp/runtime/caml_array_extern.res

This file was deleted.

18 changes: 9 additions & 9 deletions jscomp/runtime/caml_module.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type rec shape =
| Class
| Module(array<(shape, string)>)
| Value(Obj.t)
/* ATTENTION: check across versions */
module Array = Caml_array_extern

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

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

module type Empty = {}
Expand Down Expand Up @@ -69,9 +69,9 @@ let init_mod = (loc: (string, int, int), shape: shape) => {
| Module(comps) =>
let v = Obj.repr(module({}: Empty))
set_field(struct_, idx, v)
let len = Array.length(comps)
let len = array_length(comps)
for i in 0 to len - 1 {
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
let (shape, name) = array_unsafe_get(comps, i)
loop(shape, v, name)
}
| Value(v) => set_field(struct_, idx, v)
Expand All @@ -94,16 +94,16 @@ let update_mod = (shape: shape, o: Obj.t, n: Obj.t): unit => {
| Class =>
Caml_obj.update_dummy(o, n)
| Module(comps) =>
for i in 0 to Array.length(comps) - 1 {
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
for i in 0 to array_length(comps) - 1 {
let (shape, name) = array_unsafe_get(comps, i)
aux(shape, get_field(o, name), get_field(n, name), o, name)
}
| Value(_) => ()
}
switch shape {
| Module(comps) =>
for i in 0 to Array.length(comps) - 1 {
let (shape, name) = Caml_array_extern.unsafe_get(comps, i)
for i in 0 to array_length(comps) - 1 {
let (shape, name) = array_unsafe_get(comps, i)
aux(shape, get_field(o, name), get_field(n, name), o, name)
}
| _ => assert(false)
Expand Down
11 changes: 6 additions & 5 deletions jscomp/runtime/caml_obj.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

external array_unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get"

type t = Obj.t

module O = {
Expand Down Expand Up @@ -69,7 +71,6 @@ module O = {
var new_record = u.slice ()
]}
`obj_dup` is a superset of `array_dup`
*/
let obj_dup: Obj.t => Obj.t = %raw(`function(x){
if(Array.isArray(x)){
Expand Down Expand Up @@ -234,7 +235,7 @@ and aux_same_length = (a: array<Obj.t>, b: array<Obj.t>, i, same_length) =>
if i == same_length {
0
} else {
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))

if res != 0 {
res
Expand All @@ -247,7 +248,7 @@ and aux_length_a_short = (a: array<Obj.t>, b: array<Obj.t>, i, short_length) =>
if i == short_length {
-1
} else {
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))

if res != 0 {
res
Expand All @@ -260,7 +261,7 @@ and aux_length_b_short = (a: array<Obj.t>, b: array<Obj.t>, i, short_length) =>
if i == short_length {
1
} else {
let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i))
let res = compare(array_unsafe_get(a, i), array_unsafe_get(b, i))

if res != 0 {
res
Expand Down Expand Up @@ -359,7 +360,7 @@ and aux_equal_length = (a: array<Obj.t>, b: array<Obj.t>, i, same_length) =>
if i == same_length {
true
} else {
equal(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) &&
equal(array_unsafe_get(a, i), array_unsafe_get(b, i)) &&
aux_equal_length(a, b, i + 1, same_length)
}

Expand Down
12 changes: 7 additions & 5 deletions jscomp/runtime/curry.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@

@@uncurried

@get external array_length: array<'a> => int = "length"
@send external array_slice: (array<'a>, int, int) => array<'a> = "slice"
@send external array_concat: (array<'a>, array<'a>) => array<'a> = "concat"

/* Generated by scripts/curry_gen.ml */
external function_length: 'a => int = "#function_length"
external apply_args: ('a => 'b, array<_>) => 'b = "#apply"

let _ = Caml_array.sub /* make the build dependency on Caml_array explicit */
%%private(let sub = Caml_array.sub)
/* Public */
let rec app = (f, args) => {
let init_arity = function_length(f)
Expand All @@ -38,15 +40,15 @@ let rec app = (f, args) => {
} else {
init_arity
} /* arity fixing */
let len = Caml_array_extern.length(args)
let len = array_length(args)
let d = arity - len
if d == 0 {
apply_args(f, args) /* f.apply (null,args) */
} else if d < 0 {
/* TODO: could avoid copy by tracking the index */
app(Obj.magic(apply_args(f, sub(args, 0, arity))), sub(args, arity, -d))
app(Obj.magic(apply_args(f, array_slice(args, 0, arity))), array_slice(args, arity, len))
} else {
Obj.magic(x => app(f, Caml_array_extern.append(args, [x])))
Obj.magic(x => app(f, array_concat(args, [x])))
}
}

Expand Down
19 changes: 19 additions & 0 deletions jscomp/runtime/primitive_array.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@get external length: array<'a> => int = "length"

@get_index external get: (array<'a>, int) => 'a = ""

let get = (xs, index) =>
if index < 0 || index >= length(xs) {
raise(Invalid_argument("index out of bounds"))
} else {
xs->get(index)
}

@set_index external set: (array<'a>, int, 'a) => unit = ""

let set = (xs, index, newval) =>
if index < 0 || index >= length(xs) {
raise(Invalid_argument("index out of bounds"))
} else {
xs->set(index, newval)
}
12 changes: 5 additions & 7 deletions jscomp/runtime/release.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ o runtime/bs_stdlib_mini.cmi : cc runtime/bs_stdlib_mini.resi
bsc_flags = -nostdlib -nopervasives
o runtime/js.cmj runtime/js.cmi : cc runtime/js.res
bsc_flags = $bsc_no_open_flags
o runtime/caml_array.cmj : cc_cmi runtime/caml_array.res | runtime/caml_array.cmi runtime/caml_array_extern.cmj
o runtime/caml_array.cmi : cc runtime/caml_array.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
o runtime/caml_dict.cmj : cc_cmi runtime/caml_dict.res | runtime/caml_dict.cmi
o runtime/caml_dict.cmi : cc runtime/caml_dict.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/caml_exceptions.cmi
Expand All @@ -23,23 +21,23 @@ o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi r
o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
o runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.res | runtime/caml_hash_primitive.cmi
o runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_module.cmi runtime/caml_obj.cmj
o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
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
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
o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj
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
o runtime/caml_splice_call.cmj : cc_cmi runtime/caml_splice_call.res | runtime/caml_splice_call.cmi
o runtime/caml_splice_call.cmi : cc runtime/caml_splice_call.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
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
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
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
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
o runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
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
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
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
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
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
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
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
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
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
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
Loading

0 comments on commit 904f3ff

Please sign in to comment.