From 4154cf16dd8296529efd5bf06e0913d90fe753af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 11 Jun 2024 16:56:03 +0200 Subject: [PATCH] Distinguish float arrays --- compiler/lib/eval.ml | 12 +- compiler/lib/generate.ml | 3 + compiler/lib/global_flow.ml | 18 +- compiler/lib/parse_bytecode.ml | 20 +- compiler/lib/specialize_js.ml | 79 +++- compiler/tests-full/stdlib.cma.expected.js | 481 +++++++++++---------- 6 files changed, 355 insertions(+), 258 deletions(-) diff --git a/compiler/lib/eval.ml b/compiler/lib/eval.ml index 3f2e68afa7..5ad80ea0fe 100644 --- a/compiler/lib/eval.ml +++ b/compiler/lib/eval.ml @@ -259,7 +259,17 @@ let eval_instr info ((x, loc) as i) = let c = Constant (Int c) in Flow.Info.update_def info x c; [ Let (x, c), loc ]) - | Let (_, Prim (Extern ("caml_array_unsafe_get" | "caml_array_unsafe_set"), _)) -> + | Let + ( _ + , Prim + ( ( Extern + ( "caml_array_unsafe_get" + | "caml_array_unsafe_set" + | "caml_floatarray_unsafe_get" + | "caml_floatarray_unsafe_set" + | "caml_array_unsafe_set_addr" ) + | Array_get ) + , _ ) ) -> (* Fresh parameters can be introduced for these primitives in Specialize_js, which would make the call to [the_const_of] below fail. *) diff --git a/compiler/lib/generate.ml b/compiler/lib/generate.ml index 1e24e2e7f5..9bc7fca2d4 100644 --- a/compiler/lib/generate.ml +++ b/compiler/lib/generate.ml @@ -2041,7 +2041,10 @@ let init () = ; "caml_array_unsafe_get_float", "caml_array_unsafe_get" ; "caml_floatarray_unsafe_get", "caml_array_unsafe_get" ; "caml_array_unsafe_set_float", "caml_array_unsafe_set" + ; "caml_array_unsafe_set_addr", "caml_array_unsafe_set" ; "caml_floatarray_unsafe_set", "caml_array_unsafe_set" + ; "caml_check_bound_gen", "caml_check_bound" + ; "caml_check_bound_float", "caml_check_bound" ; "caml_alloc_dummy_float", "caml_alloc_dummy" ; "caml_make_array", "%identity" ; "caml_ensure_stack_capacity", "%identity" diff --git a/compiler/lib/global_flow.ml b/compiler/lib/global_flow.ml index ea49dcccfd..02da100b0d 100644 --- a/compiler/lib/global_flow.ml +++ b/compiler/lib/global_flow.ml @@ -153,7 +153,15 @@ let expr_deps blocks st x e = | Constant _ | Prim ((Vectlength | Not | IsInt | Eq | Neq | Lt | Le | Ult), _) | Block _ -> () | Special _ -> () - | Prim ((Extern ("caml_check_bound" | "caml_array_unsafe_get") | Array_get), l) -> + | Prim + ( ( Extern + ( "caml_check_bound" + | "caml_check_bound_float" + | "caml_check_bound_gen" + | "caml_array_unsafe_get" + | "caml_floatarray_unsafe_get" ) + | Array_get ) + , l ) -> (* The analysis knowns about these primitives, and will compute an approximation of the value they return based on an approximation of their arguments *) @@ -424,8 +432,12 @@ let propagate st ~update approx x = | Phi _ | Expr _ -> assert false) known | Top -> Top) - | Prim (Extern "caml_check_bound", [ Pv y; _ ]) -> Var.Tbl.get approx y - | Prim ((Array_get | Extern "caml_array_unsafe_get"), [ Pv y; _ ]) -> ( + | Prim + ( Extern ("caml_check_bound" | "caml_check_bound_float" | "caml_check_bound_gen") + , [ Pv y; _ ] ) -> Var.Tbl.get approx y + | Prim + ( (Array_get | Extern ("caml_array_unsafe_get" | "caml_floatarray_unsafe_get")) + , [ Pv y; _ ] ) -> ( if st.fast then Domain.others else diff --git a/compiler/lib/parse_bytecode.ml b/compiler/lib/parse_bytecode.ml index a46ceda5f2..8a6d46c0e8 100644 --- a/compiler/lib/parse_bytecode.ml +++ b/compiler/lib/parse_bytecode.ml @@ -1554,7 +1554,17 @@ and compile infos pc state instrs = let x, state = State.fresh_var state loc in if debug_parser () then Format.printf "%a = %a[%d]@." Var.print x Var.print y n; - compile infos (pc + 2) state ((Let (x, Field (y, n)), loc) :: instrs) + compile + infos + (pc + 2) + state + (( Let + ( x + , Prim + ( Extern "caml_floatarray_unsafe_get" + , [ Pv y; Pc (Int (Int32.of_int n)) ] ) ) + , loc ) + :: instrs) | SETFIELD0 -> let y, _ = State.accu state in let z, _ = State.peek 0 state in @@ -1628,7 +1638,13 @@ and compile infos pc state instrs = infos (pc + 2) (State.pop 1 state) - ((Let (x, const 0l), loc) :: (Set_field (y, n, z), loc) :: instrs) + (( Let + ( x + , Prim + ( Extern "caml_floatarray_unsafe_set" + , [ Pv y; Pc (Int (Int32.of_int n)); Pv z ] ) ) + , loc ) + :: instrs) | VECTLENGTH -> let y, _ = State.accu state in let x, state = State.fresh_var state loc in diff --git a/compiler/lib/specialize_js.ml b/compiler/lib/specialize_js.ml index 84d4c8626f..9fdce562be 100644 --- a/compiler/lib/specialize_js.ml +++ b/compiler/lib/specialize_js.ml @@ -195,48 +195,90 @@ let specialize_instrs info l = the array access. The bound checking function returns the array, which allows to produce more compact code. *) match i with - | Let (x, Prim (Extern "caml_array_get", [ y; z ])) - | Let (x, Prim (Extern "caml_array_get_float", [ y; z ])) - | Let (x, Prim (Extern "caml_array_get_addr", [ y; z ])) -> + | Let + ( x + , Prim + ( Extern + (( "caml_array_get" + | "caml_array_get_float" + | "caml_floatarray_get" + | "caml_array_get_addr" ) as prim) + , [ y; z ] ) ) -> let idx = match the_int info z with | Some idx -> `Cst idx | None -> `Var z in + let instr y = + let prim = + match prim with + | "caml_array_get" -> Extern "caml_array_unsafe_get" + | "caml_array_get_float" | "caml_floatarray_get" -> + Extern "caml_floatarray_unsafe_get" + | "caml_array_get_addr" -> Array_get + | _ -> assert false + in + Let (x, Prim (prim, [ y; z ])), loc + in if List.mem (y, idx) ~set:checks then - let acc = - (Let (x, Prim (Extern "caml_array_unsafe_get", [ y; z ])), loc) :: acc - in + let acc = instr y :: acc in aux info checks r acc else + let check = + match prim with + | "caml_array_get" -> "caml_check_bound_gen" + | "caml_array_get_float" | "caml_floatarray_get" -> + "caml_check_bound_float" + | "caml_array_get_addr" -> "caml_check_bound" + | _ -> assert false + in let y' = Code.Var.fresh () in let acc = - (Let (x, Prim (Extern "caml_array_unsafe_get", [ Pv y'; z ])), loc) - :: (Let (y', Prim (Extern "caml_check_bound", [ y; z ])), noloc) - :: acc + instr (Pv y') :: (Let (y', Prim (Extern check, [ y; z ])), noloc) :: acc in aux info ((y, idx) :: checks) r acc - | Let (x, Prim (Extern "caml_array_set", [ y; z; t ])) - | Let (x, Prim (Extern "caml_array_set_float", [ y; z; t ])) - | Let (x, Prim (Extern "caml_array_set_addr", [ y; z; t ])) -> + | Let + ( x + , Prim + ( Extern + (( "caml_array_set" + | "caml_array_set_float" + | "caml_floatarray_set" + | "caml_array_set_addr" ) as prim) + , [ y; z; t ] ) ) -> let idx = match the_int info z with | Some idx -> `Cst idx | None -> `Var z in + let instr y = + let prim = + match prim with + | "caml_array_set" -> "caml_array_unsafe_set" + | "caml_array_set_float" | "caml_floatarray_set" -> + "caml_floatarray_unsafe_set" + | "caml_array_set_addr" -> "caml_array_unsafe_set_addr" + | _ -> assert false + in + Let (x, Prim (Extern prim, [ y; z; t ])), loc + in if List.mem (y, idx) ~set:checks then - let acc = - (Let (x, Prim (Extern "caml_array_unsafe_set", [ y; z; t ])), loc) :: acc - in + let acc = instr y :: acc in aux info checks r acc else + let check = + match prim with + | "caml_array_set" -> "caml_check_bound_gen" + | "caml_array_set_float" | "caml_floatarray_set" -> + "caml_check_bound_float" + | "caml_array_set_addr" -> "caml_check_bound" + | _ -> assert false + in let y' = Code.Var.fresh () in let acc = - (Let (x, Prim (Extern "caml_array_unsafe_set", [ Pv y'; z; t ])), loc) - :: (Let (y', Prim (Extern "caml_check_bound", [ y; z ])), noloc) - :: acc + instr (Pv y') :: (Let (y', Prim (Extern check, [ y; z ])), noloc) :: acc in aux info ((y, idx) :: checks) r acc | _ -> @@ -270,6 +312,7 @@ let f_once p = ( "caml_array_set" | "caml_array_unsafe_set" | "caml_array_set_float" + | "caml_floatarray_set" | "caml_array_set_addr" | "caml_array_unsafe_set_float" | "caml_floatarray_unsafe_set" ) diff --git a/compiler/tests-full/stdlib.cma.expected.js b/compiler/tests-full/stdlib.cma.expected.js index bf666c55da..019f19cab4 100644 --- a/compiler/tests-full/stdlib.cma.expected.js +++ b/compiler/tests-full/stdlib.cma.expected.js @@ -1216,6 +1216,7 @@ var runtime = globalThis.jsoo_runtime, cst_Obj_extension_constructor$1 = "Obj.extension_constructor", + caml_check_bound = runtime.caml_check_bound, caml_obj_tag = runtime.caml_obj_tag; /*<>*/ function caml_call1(f, a0){ return (f.l >= 0 ? f.l : f.l = f.length) == 1 @@ -1229,9 +1230,14 @@ function is_block(a){ /*<>*/ return 1 - (typeof a === "number" ? 1 : 0); /*<>*/ } + function double_field(x, i){ + /*<>*/ return caml_check_bound(x, i)[1 + i]; + /*<>*/ } + function set_double_field(x, i, v){ + /*<>*/ caml_check_bound(x, i)[1 + i] = v; + /*<>*/ return 0; + /*<>*/ } var - double_field = runtime.caml_array_get, - set_double_field = runtime.caml_array_set, cst_Obj_extension_constructor = cst_Obj_extension_constructor$1, cst_Obj_extension_constructor$0 = cst_Obj_extension_constructor$1; function of_val(x){ @@ -8094,8 +8100,7 @@ runtime = globalThis.jsoo_runtime, cst_Float_array_blit$1 = "Float.array.blit", cst_float_ml = "float.ml", - caml_array_get = runtime.caml_array_get, - caml_array_set = runtime.caml_array_set, + caml_check_bound = runtime.caml_check_bound, caml_float_compare = runtime.caml_float_compare, caml_floatarray_blit = runtime.caml_floatarray_blit, caml_floatarray_create = runtime.caml_floatarray_create, @@ -8162,8 +8167,8 @@ "Float.Array.map2: arrays must have the same length"; function is_integer(x){ /*<>*/ var - _ax_ = x == /*<>*/ runtime.caml_trunc_float(x) ? 1 : 0; - return _ax_ ? is_finite(x) : _ax_; + _aX_ = x == /*<>*/ runtime.caml_trunc_float(x) ? 1 : 0; + return _aX_ ? is_finite(x) : _aX_; /*<>*/ } function succ(x){ /*<>*/ return /*<>*/ caml_nextafter_float @@ -8264,32 +8269,32 @@ (10, 100, 0, x); /*<>*/ } function unsafe_fill(a, ofs, len, v){ - /*<>*/ var _av_ = (ofs + len | 0) - 1 | 0; - if(_av_ >= ofs){ + /*<>*/ var _aV_ = (ofs + len | 0) - 1 | 0; + if(_aV_ >= ofs){ var i = ofs; for(;;){ /*<>*/ a[1 + i] = v; - /*<>*/ /*<>*/ var _aw_ = i + 1 | 0; - if(_av_ === i) break; - i = _aw_; + /*<>*/ /*<>*/ var _aW_ = i + 1 | 0; + if(_aV_ === i) break; + i = _aW_; } } return 0; /*<>*/ } function check(a, ofs, len, msg){ - /*<>*/ var _ar_ = ofs < 0 ? 1 : 0; - if(_ar_) - var _as_ = _ar_; + /*<>*/ var _aR_ = ofs < 0 ? 1 : 0; + if(_aR_) + var _aS_ = _aR_; else{ - var _at_ = len < 0 ? 1 : 0; - if(_at_) - var _as_ = _at_; + var _aT_ = len < 0 ? 1 : 0; + if(_aT_) + var _aS_ = _aT_; else var - _au_ = (ofs + len | 0) < 0 ? 1 : 0, - _as_ = _au_ || (a.length - 1 < (ofs + len | 0) ? 1 : 0); + _aU_ = (ofs + len | 0) < 0 ? 1 : 0, + _aS_ = _aU_ || (a.length - 1 < (ofs + len | 0) ? 1 : 0); } - return _as_ ? /*<>*/ caml_call1(Stdlib[1], msg) : _as_; + return _aS_ ? /*<>*/ caml_call1(Stdlib[1], msg) : _aS_; /*<>*/ } function make(n, v){ /*<>*/ /*<>*/ var @@ -8304,16 +8309,16 @@ /*<>*/ var /*<>*/ res = /*<>*/ caml_floatarray_create(l), - /*<>*/ _ap_ = l - 1 | 0, - /*<>*/ _ao_ = 0; - if(_ap_ >= 0){ - var i = _ao_; + /*<>*/ _aP_ = l - 1 | 0, + /*<>*/ _aO_ = 0; + if(_aP_ >= 0){ + var i = _aO_; for(;;){ /*<>*/ res[1 + i] = /*<>*/ caml_call1(f, i); - /*<>*/ /*<>*/ var _aq_ = i + 1 | 0; - if(_ap_ === i) break; - i = _aq_; + /*<>*/ /*<>*/ var _aQ_ = i + 1 | 0; + if(_aP_ === i) break; + i = _aQ_; } } /*<>*/ return res; @@ -8328,15 +8333,15 @@ (sx, /*<>*/ caml_floatarray_create(0)); if(0 < sy){ /*<>*/ var - _am_ = sx - 1 | 0, - /*<>*/ _al_ = 0; - if(_am_ >= 0){ - var x = _al_; + _aM_ = sx - 1 | 0, + /*<>*/ _aL_ = 0; + if(_aM_ >= 0){ + var x = _aL_; for(;;){ /*<>*/ res[1 + x] = make(sy, v); - /*<>*/ /*<>*/ var _an_ = x + 1 | 0; - if(_am_ === x) break; - x = _an_; + /*<>*/ /*<>*/ var _aN_ = x + 1 | 0; + if(_aM_ === x) break; + x = _aN_; } } } @@ -8352,31 +8357,31 @@ (sx, /*<>*/ caml_floatarray_create(0)); if(0 < sy){ /*<>*/ var - _ag_ = sx - 1 | 0, - /*<>*/ _af_ = 0; - if(_ag_ >= 0){ - var x = _af_; + _aG_ = sx - 1 | 0, + /*<>*/ _aF_ = 0; + if(_aG_ >= 0){ + var x = _aF_; for(;;){ /*<>*/ var /*<>*/ row = /*<>*/ caml_floatarray_create(sy), - /*<>*/ _ai_ = sy - 1 | 0, - /*<>*/ _ah_ = 0; - if(_ai_ >= 0){ - var y = _ah_; + /*<>*/ _aI_ = sy - 1 | 0, + /*<>*/ _aH_ = 0; + if(_aI_ >= 0){ + var y = _aH_; for(;;){ /*<>*/ row[1 + y] = /*<>*/ caml_call2(f, x, y); /*<>*/ /*<>*/ var - _ak_ = y + 1 | 0; - if(_ai_ === y) break; - y = _ak_; + _aK_ = y + 1 | 0; + if(_aI_ === y) break; + y = _aK_; } } /*<>*/ res[1 + x] = row; - /*<>*/ /*<>*/ var _aj_ = x + 1 | 0; - if(_ag_ === x) break; - x = _aj_; + /*<>*/ /*<>*/ var _aJ_ = x + 1 | 0; + if(_aG_ === x) break; + x = _aJ_; } } } @@ -8463,7 +8468,7 @@ /*<>*/ return /*<>*/ caml_call2 (Stdlib_List[11], a.length - 1, - function(_ae_){ /*<>*/ return a[1 + _ae_];}); + function(_aE_){ /*<>*/ return a[1 + _aE_];}); /*<>*/ } function of_list(l){ /*<>*/ var @@ -8483,16 +8488,16 @@ /*<>*/ } function iter(f, a){ /*<>*/ var - _ac_ = a.length - 2 | 0, - /*<>*/ _ab_ = 0; - if(_ac_ >= 0){ - var i = _ab_; + _aC_ = a.length - 2 | 0, + /*<>*/ _aB_ = 0; + if(_aC_ >= 0){ + var i = _aB_; for(;;){ /*<>*/ /*<>*/ caml_call1 (f, a[1 + i]); - /*<>*/ /*<>*/ var _ad_ = i + 1 | 0; - if(_ac_ === i) break; - i = _ad_; + /*<>*/ /*<>*/ var _aD_ = i + 1 | 0; + if(_aC_ === i) break; + i = _aD_; } } return 0; @@ -8502,16 +8507,16 @@ /*<>*/ return /*<>*/ caml_call1 (Stdlib[1], cst_Float_Array_iter2_arrays_m); /*<>*/ var - _$_ = a.length - 2 | 0, - /*<>*/ ___ = 0; - if(_$_ >= 0){ - var i = ___; + _az_ = a.length - 2 | 0, + /*<>*/ _ay_ = 0; + if(_az_ >= 0){ + var i = _ay_; for(;;){ /*<>*/ /*<>*/ caml_call2 (f, a[1 + i], b[1 + i]); - /*<>*/ /*<>*/ var _aa_ = i + 1 | 0; - if(_$_ === i) break; - i = _aa_; + /*<>*/ /*<>*/ var _aA_ = i + 1 | 0; + if(_az_ === i) break; + i = _aA_; } } return 0; @@ -8521,32 +8526,32 @@ l = a.length - 1, /*<>*/ r = /*<>*/ caml_floatarray_create(l), - /*<>*/ _Y_ = l - 1 | 0, - /*<>*/ _X_ = 0; - if(_Y_ >= 0){ - var i = _X_; + /*<>*/ _aw_ = l - 1 | 0, + /*<>*/ _av_ = 0; + if(_aw_ >= 0){ + var i = _av_; for(;;){ /*<>*/ r[1 + i] = /*<>*/ caml_call1(f, a[1 + i]); - /*<>*/ /*<>*/ var _Z_ = i + 1 | 0; - if(_Y_ === i) break; - i = _Z_; + /*<>*/ /*<>*/ var _ax_ = i + 1 | 0; + if(_aw_ === i) break; + i = _ax_; } } /*<>*/ return r; /*<>*/ } function map_inplace(f, a){ /*<>*/ var - _V_ = a.length - 2 | 0, - /*<>*/ _U_ = 0; - if(_V_ >= 0){ - var i = _U_; + _at_ = a.length - 2 | 0, + /*<>*/ _as_ = 0; + if(_at_ >= 0){ + var i = _as_; for(;;){ /*<>*/ a[1 + i] = /*<>*/ caml_call1(f, a[1 + i]); - /*<>*/ /*<>*/ var _W_ = i + 1 | 0; - if(_V_ === i) break; - i = _W_; + /*<>*/ /*<>*/ var _au_ = i + 1 | 0; + if(_at_ === i) break; + i = _au_; } } return 0; @@ -8561,32 +8566,32 @@ /*<>*/ var /*<>*/ r = /*<>*/ caml_floatarray_create(la), - /*<>*/ _S_ = la - 1 | 0, - /*<>*/ _R_ = 0; - if(_S_ >= 0){ - var i = _R_; + /*<>*/ _aq_ = la - 1 | 0, + /*<>*/ _ap_ = 0; + if(_aq_ >= 0){ + var i = _ap_; for(;;){ /*<>*/ r[1 + i] = /*<>*/ caml_call2(f, a[1 + i], b[1 + i]); - /*<>*/ /*<>*/ var _T_ = i + 1 | 0; - if(_S_ === i) break; - i = _T_; + /*<>*/ /*<>*/ var _ar_ = i + 1 | 0; + if(_aq_ === i) break; + i = _ar_; } } /*<>*/ return r; /*<>*/ } function iteri(f, a){ /*<>*/ var - _P_ = a.length - 2 | 0, - /*<>*/ _O_ = 0; - if(_P_ >= 0){ - var i = _O_; + _an_ = a.length - 2 | 0, + /*<>*/ _am_ = 0; + if(_an_ >= 0){ + var i = _am_; for(;;){ /*<>*/ /*<>*/ caml_call2 (f, i, a[1 + i]); - /*<>*/ /*<>*/ var _Q_ = i + 1 | 0; - if(_P_ === i) break; - i = _Q_; + /*<>*/ /*<>*/ var _ao_ = i + 1 | 0; + if(_an_ === i) break; + i = _ao_; } } return 0; @@ -8596,32 +8601,32 @@ l = a.length - 1, /*<>*/ r = /*<>*/ caml_floatarray_create(l), - /*<>*/ _M_ = l - 1 | 0, - /*<>*/ _L_ = 0; - if(_M_ >= 0){ - var i = _L_; + /*<>*/ _ak_ = l - 1 | 0, + /*<>*/ _aj_ = 0; + if(_ak_ >= 0){ + var i = _aj_; for(;;){ /*<>*/ r[1 + i] = /*<>*/ caml_call2(f, i, a[1 + i]); - /*<>*/ /*<>*/ var _N_ = i + 1 | 0; - if(_M_ === i) break; - i = _N_; + /*<>*/ /*<>*/ var _al_ = i + 1 | 0; + if(_ak_ === i) break; + i = _al_; } } /*<>*/ return r; /*<>*/ } function mapi_inplace(f, a){ /*<>*/ var - _J_ = a.length - 2 | 0, - /*<>*/ _I_ = 0; - if(_J_ >= 0){ - var i = _I_; + _ah_ = a.length - 2 | 0, + /*<>*/ _ag_ = 0; + if(_ah_ >= 0){ + var i = _ag_; for(;;){ /*<>*/ a[1 + i] = /*<>*/ caml_call2(f, i, a[1 + i]); - /*<>*/ /*<>*/ var _K_ = i + 1 | 0; - if(_J_ === i) break; - i = _K_; + /*<>*/ /*<>*/ var _ai_ = i + 1 | 0; + if(_ah_ === i) break; + i = _ai_; } } return 0; @@ -8629,15 +8634,15 @@ function fold_left(f, x, a){ /*<>*/ var /*<>*/ r = [0, x], - _G_ = a.length - 2 | 0, - /*<>*/ _F_ = 0; - if(_G_ >= 0){ - var i = _F_; + _ae_ = a.length - 2 | 0, + /*<>*/ _ad_ = 0; + if(_ae_ >= 0){ + var i = _ad_; for(;;){ r[1] = /*<>*/ caml_call2(f, r[1], a[1 + i]); - /*<>*/ /*<>*/ var _H_ = i + 1 | 0; - if(_G_ === i) break; - i = _H_; + /*<>*/ /*<>*/ var _af_ = i + 1 | 0; + if(_ae_ === i) break; + i = _af_; } } return r[1]; @@ -8645,14 +8650,14 @@ function fold_right(f, a, x){ /*<>*/ var /*<>*/ r = [0, x], - /*<>*/ _D_ = a.length - 2 | 0; - if(_D_ >= 0){ - var i = _D_; + /*<>*/ _ab_ = a.length - 2 | 0; + if(_ab_ >= 0){ + var i = _ab_; for(;;){ r[1] = /*<>*/ caml_call2(f, a[1 + i], r[1]); - /*<>*/ /*<>*/ var _E_ = i - 1 | 0; + /*<>*/ /*<>*/ var _ac_ = i - 1 | 0; if(0 === i) break; - i = _E_; + i = _ac_; } } return r[1]; @@ -8752,42 +8757,46 @@ i31 = ((i + i | 0) + i | 0) + 1 | 0, /*<>*/ x = [0, i31]; if((i31 + 2 | 0) < l){ + /*<>*/ var + /*<>*/ _W_ = i31 + 1 | 0, + /*<>*/ _X_ = caml_check_bound(a, _W_)[1 + _W_]; if ( /*<>*/ caml_call2 - (cmp, - /*<>*/ caml_array_get(a, i31), - /*<>*/ caml_array_get(a, i31 + 1 | 0)) + (cmp, caml_check_bound(a, i31)[1 + i31], _X_) < 0) x[1] = i31 + 1 | 0; + /*<>*/ var + /*<>*/ _Y_ = i31 + 2 | 0, + /*<>*/ _Z_ = caml_check_bound(a, _Y_)[1 + _Y_], + ___ = x[1]; if ( /*<>*/ caml_call2 - (cmp, - /*<>*/ caml_array_get(a, x[1]), - /*<>*/ caml_array_get(a, i31 + 2 | 0)) + (cmp, caml_check_bound(a, ___)[1 + ___], _Z_) < 0) x[1] = i31 + 2 | 0; return x[1]; } - /*<>*/ if - ((i31 + 1 | 0) < l - && - 0 + if((i31 + 1 | 0) < l){ + /*<>*/ var + _$_ = i31 + 1 | 0, + /*<>*/ _aa_ = caml_check_bound(a, _$_)[1 + _$_]; + /*<>*/ if + (0 > /*<>*/ caml_call2 - (cmp, - /*<>*/ caml_array_get(a, i31), - /*<>*/ caml_array_get(a, i31 + 1 | 0))) - /*<>*/ return i31 + 1 | 0; + (cmp, caml_check_bound(a, i31)[1 + i31], _aa_)) + /*<>*/ return i31 + 1 | 0; + } if(i31 < l) /*<>*/ return i31; /*<>*/ throw /*<>*/ caml_maybe_attach_backtrace ([0, Bottom, i], 1); /*<>*/ } - var l = a.length - 1, _x_ = ((l + 1 | 0) / 3 | 0) - 1 | 0; - if(_x_ >= 0){ - var i$6 = _x_; + var l = a.length - 1, _Q_ = ((l + 1 | 0) / 3 | 0) - 1 | 0; + if(_Q_ >= 0){ + var i$6 = _Q_; for(;;){ /*<>*/ /*<>*/ var - e$1 = /*<>*/ caml_array_get(a, i$6); + e$1 = caml_check_bound(a, i$6)[1 + i$6]; /*<>*/ try{ var i = i$6; /*<>*/ for(;;){ @@ -8797,43 +8806,41 @@ (0 >= /*<>*/ caml_call2 - (cmp, /*<>*/ caml_array_get(a, j), e$1)) + (cmp, caml_check_bound(a, j)[1 + j], e$1)) break; - /*<>*/ /*<>*/ caml_array_set - (a, i, /*<>*/ caml_array_get(a, j)); + /*<>*/ /*<>*/ var + _N_ = caml_check_bound(a, j)[1 + j]; + /*<>*/ caml_check_bound(a, i)[1 + i] = _N_; i = j; } - /*<>*/ /*<>*/ caml_array_set - (a, i, e$1); + /*<>*/ caml_check_bound(a, i)[1 + i] = e$1; } catch(exn$0){ var exn = caml_wrap_exception(exn$0); if(exn[1] !== Bottom) throw caml_maybe_attach_backtrace(exn, 0); var i$0 = exn[2]; - /*<>*/ /*<>*/ caml_array_set - (a, i$0, e$1); + /*<>*/ caml_check_bound(a, i$0)[1 + i$0] = e$1; } - /*<>*/ /*<>*/ var _C_ = i$6 - 1 | 0; + /*<>*/ /*<>*/ var _V_ = i$6 - 1 | 0; if(0 === i$6) break; - i$6 = _C_; + i$6 = _V_; } } - /*<>*/ /*<>*/ var _y_ = l - 1 | 0; - if(_y_ >= 2){ - var i$4 = _y_; + /*<>*/ /*<>*/ var _R_ = l - 1 | 0; + if(_R_ >= 2){ + var i$4 = _R_; for(;;){ /*<>*/ /*<>*/ var - e$0 = /*<>*/ caml_array_get(a, i$4); - /*<>*/ /*<>*/ caml_array_set - (a, i$4, /*<>*/ caml_array_get(a, 0)); + e$0 = caml_check_bound(a, i$4)[1 + i$4]; + /*<>*/ a[1 + i$4] = caml_check_bound(a, 0)[1]; var i$5 = 0; /*<>*/ try{ var i$1 = i$5; /*<>*/ for(;;){ - /*<>*/ /*<>*/ var - j$0 = maxson(i$4, i$1); - /*<>*/ /*<>*/ caml_array_set - (a, i$1, /*<>*/ caml_array_get(a, j$0)); + /*<>*/ var + /*<>*/ j$0 = maxson(i$4, i$1), + /*<>*/ _O_ = caml_check_bound(a, j$0)[1 + j$0]; + /*<>*/ caml_check_bound(a, i$1)[1 + i$1] = _O_; i$1 = j$0; } } @@ -8855,37 +8862,36 @@ (0 <= /*<>*/ caml_call2 - (cmp, /*<>*/ caml_array_get(a, father), e$0)) + (cmp, caml_check_bound(a, father)[1 + father], e$0)) break; - /*<>*/ /*<>*/ caml_array_set - (a, i$3, /*<>*/ caml_array_get(a, father)); + /*<>*/ /*<>*/ var + _P_ = caml_check_bound(a, father)[1 + father]; + /*<>*/ caml_check_bound(a, i$3)[1 + i$3] = _P_; if(0 >= father) break b; i$3 = father; } - /*<>*/ /*<>*/ caml_array_set - (a, i$3, e$0); + /*<>*/ caml_check_bound(a, i$3)[1 + i$3] = e$0; break a; } - /*<>*/ /*<>*/ caml_array_set - (a, 0, e$0); + /*<>*/ caml_check_bound(a, 0)[1] = e$0; } - /*<>*/ /*<>*/ var _B_ = i$4 - 1 | 0; + /*<>*/ /*<>*/ var _U_ = i$4 - 1 | 0; if(2 === i$4) break; - i$4 = _B_; + i$4 = _U_; } } } - var _z_ = 1 < l ? 1 : 0; - if(_z_){ + var _S_ = 1 < l ? 1 : 0; + if(_S_){ /*<>*/ /*<>*/ var - e = /*<>*/ caml_array_get(a, 1); - /*<>*/ /*<>*/ caml_array_set - (a, 1, /*<>*/ caml_array_get(a, 0)); - var _A_ = /*<>*/ caml_array_set(a, 0, e); + e = caml_check_bound(a, 1)[2]; + /*<>*/ a[2] = caml_check_bound(a, 0)[1]; + /*<>*/ a[1] = e; + var _T_ = 0; } else - var _A_ = _z_; - /*<>*/ return _A_; + var _T_ = _S_; + /*<>*/ return _T_; /*<>*/ } function stable_sort(cmp, a){ function merge(src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs){ @@ -8893,9 +8899,9 @@ src1r = src1ofs + src1len | 0, src2r = src2ofs + src2len | 0, /*<>*/ s2$1 = - /*<>*/ caml_array_get(src2, src2ofs), + caml_check_bound(src2, src2ofs)[1 + src2ofs], /*<>*/ s1$1 = - /*<>*/ caml_array_get(a, src1ofs), + caml_check_bound(a, src1ofs)[1 + src1ofs], i1 = src1ofs, s1 = s1$1, i2 = src2ofs, @@ -8904,30 +8910,26 @@ /*<>*/ for(;;) /*<>*/ if (0 < /*<>*/ caml_call2(cmp, s1, s2)){ - /*<>*/ /*<>*/ caml_array_set - (dst, d, s2); + /*<>*/ caml_check_bound(dst, d)[1 + d] = s2; /*<>*/ /*<>*/ var i2$0 = i2 + 1 | 0; if(i2$0 >= src2r) return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); /*<>*/ var /*<>*/ d$0 = d + 1 | 0, - /*<>*/ s2$0 = - /*<>*/ caml_array_get(src2, i2$0); + /*<>*/ s2$0 = caml_check_bound(src2, i2$0)[1 + i2$0]; i2 = i2$0; s2 = s2$0; d = d$0; } else{ - /*<>*/ /*<>*/ caml_array_set - (dst, d, s1); + /*<>*/ caml_check_bound(dst, d)[1 + d] = s1; /*<>*/ /*<>*/ var i1$0 = i1 + 1 | 0; if(i1$0 >= src1r) return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); /*<>*/ var /*<>*/ d$1 = d + 1 | 0, - /*<>*/ s1$0 = - /*<>*/ caml_array_get(a, i1$0); + /*<>*/ s1$0 = caml_check_bound(a, i1$0)[1 + i1$0]; i1 = i1$0; s1 = s1$0; d = d$1; @@ -8935,34 +8937,36 @@ /*<>*/ } function isortto(srcofs, dst, dstofs, len){ /*<>*/ var - _v_ = len - 1 | 0, - /*<>*/ _u_ = 0; - if(_v_ >= 0){ - var i = _u_; + _F_ = len - 1 | 0, + /*<>*/ _E_ = 0; + if(_F_ >= 0){ + var i = _E_; for(;;){ /*<>*/ var - /*<>*/ e = - /*<>*/ caml_array_get(a, srcofs + i | 0), + _G_ = srcofs + i | 0, + /*<>*/ e = caml_check_bound(a, _G_)[1 + _G_], /*<>*/ j = [0, (dstofs + i | 0) - 1 | 0]; for(;;){ if(dstofs > j[1]) break; + var _H_ = j[1]; /*<>*/ if (0 >= /*<>*/ caml_call2 - (cmp, /*<>*/ caml_array_get(dst, j[1]), e)) + (cmp, caml_check_bound(dst, _H_)[1 + _H_], e)) break; - /*<>*/ /*<>*/ caml_array_set - (dst, - j[1] + 1 | 0, - /*<>*/ caml_array_get(dst, j[1])); + /*<>*/ var + _I_ = j[1], + /*<>*/ _J_ = caml_check_bound(dst, _I_)[1 + _I_], + _K_ = j[1] + 1 | 0; + /*<>*/ caml_check_bound(dst, _K_)[1 + _K_] = _J_; j[1]--; } - /*<>*/ /*<>*/ caml_array_set - (dst, j[1] + 1 | 0, e); - /*<>*/ /*<>*/ var _w_ = i + 1 | 0; - if(_v_ === i) break; - i = _w_; + var _L_ = j[1] + 1 | 0; + /*<>*/ caml_check_bound(dst, _L_)[1 + _L_] = e; + /*<>*/ /*<>*/ var _M_ = i + 1 | 0; + if(_F_ === i) break; + i = _M_; } } return 0; @@ -8988,20 +8992,19 @@ /*<>*/ return merge(l2, l1, t, 0, l2, a, 0); /*<>*/ } function shuffle(rand, a){ - /*<>*/ var _s_ = a.length - 2 | 0; - if(_s_ >= 1){ - var i = _s_; + /*<>*/ var _C_ = a.length - 2 | 0; + if(_C_ >= 1){ + var i = _C_; for(;;){ /*<>*/ var /*<>*/ j = /*<>*/ caml_call1(rand, i + 1 | 0), /*<>*/ v = a[1 + i]; - /*<>*/ a[1 + i] = - /*<>*/ caml_array_get(a, j); + /*<>*/ a[1 + i] = caml_check_bound(a, j)[1 + j]; /*<>*/ a[1 + j] = v; - var _t_ = i - 1 | 0; + var _D_ = i - 1 | 0; if(1 === i) break; - i = _t_; + i = _D_; } } return 0; @@ -9012,14 +9015,14 @@ /*<>*/ return 0; /*<>*/ var /*<>*/ x = a[1 + i], - /*<>*/ _q_ = i + 1 | 0; + /*<>*/ _A_ = i + 1 | 0; /*<>*/ return [0, x, - function(_r_){ /*<>*/ return aux(_q_, _r_);}]; + function(_B_){ /*<>*/ return aux(_A_, _B_);}]; /*<>*/ } - /*<>*/ var _o_ = 0; - /*<>*/ return function(_p_){ - /*<>*/ return aux(_o_, _p_);}; + /*<>*/ var _y_ = 0; + /*<>*/ return function(_z_){ + /*<>*/ return aux(_y_, _z_);}; /*<>*/ } function to_seqi(a){ function aux(i, param){ @@ -9027,14 +9030,14 @@ /*<>*/ return 0; /*<>*/ var /*<>*/ x = a[1 + i], - /*<>*/ _m_ = i + 1 | 0; + /*<>*/ _w_ = i + 1 | 0; /*<>*/ return [0, [0, i, x], - function(_n_){ /*<>*/ return aux(_m_, _n_);}]; + function(_x_){ /*<>*/ return aux(_w_, _x_);}]; /*<>*/ } - /*<>*/ var _k_ = 0; - /*<>*/ return function(_l_){ - /*<>*/ return aux(_k_, _l_);}; + /*<>*/ var _u_ = 0; + /*<>*/ return function(_v_){ + /*<>*/ return aux(_u_, _v_);}; /*<>*/ } function of_seq(i$2){ /*<>*/ var @@ -9069,16 +9072,16 @@ /*<>*/ r = /*<>*/ caml_make_vect (l, /*<>*/ caml_call1(f, a[1])), - /*<>*/ _i_ = l - 1 | 0, - /*<>*/ _h_ = 1; - if(_i_ >= 1){ - var i = _h_; + /*<>*/ _s_ = l - 1 | 0, + /*<>*/ _r_ = 1; + if(_s_ >= 1){ + var i = _r_; for(;;){ /*<>*/ r[1 + i] = /*<>*/ caml_call1(f, a[1 + i]); - /*<>*/ /*<>*/ var _j_ = i + 1 | 0; - if(_i_ === i) break; - i = _j_; + /*<>*/ /*<>*/ var _t_ = i + 1 | 0; + if(_s_ === i) break; + i = _t_; } } /*<>*/ return r; @@ -9088,16 +9091,16 @@ l = a.length - 1, /*<>*/ r = /*<>*/ caml_floatarray_create(l), - /*<>*/ _f_ = l - 1 | 0, - /*<>*/ _e_ = 0; - if(_f_ >= 0){ - var i = _e_; + /*<>*/ _p_ = l - 1 | 0, + /*<>*/ _o_ = 0; + if(_p_ >= 0){ + var i = _o_; for(;;){ /*<>*/ r[1 + i] = /*<>*/ caml_call1(f, a[1 + i]); - /*<>*/ /*<>*/ var _g_ = i + 1 | 0; - if(_f_ === i) break; - i = _g_; + /*<>*/ /*<>*/ var _q_ = i + 1 | 0; + if(_p_ === i) break; + i = _q_; } } /*<>*/ return r; @@ -9136,9 +9139,14 @@ seeded_hash, hash, [0, - function(_d_){ /*<>*/ return _d_.length - 1;}, - caml_array_get, - caml_array_set, + function(_n_){ /*<>*/ return _n_.length - 1;}, + function(_m_, _l_){ + /*<>*/ return caml_check_bound(_m_, _l_)[1 + _l_]; + }, + function(_k_, _j_, _i_){ + /*<>*/ caml_check_bound(_k_, _j_)[1 + _j_] = _i_; + return 0; + }, make, caml_floatarray_create, init, @@ -9180,9 +9188,14 @@ map_to_array, map_from_array], [0, - function(_c_){ /*<>*/ return _c_.length - 1;}, - caml_array_get, - caml_array_set, + function(_h_){ /*<>*/ return _h_.length - 1;}, + function(_g_, _f_){ + /*<>*/ return caml_check_bound(_g_, _f_)[1 + _f_]; + }, + function(_e_, _d_, _c_){ + /*<>*/ caml_check_bound(_e_, _d_)[1 + _d_] = _c_; + return 0; + }, make, caml_floatarray_create, init,