Skip to content

Commit 1b70446

Browse files
committed
tweak 406 stdlib to make js differ smaller
1 parent 914c6b4 commit 1b70446

File tree

9 files changed

+78
-9
lines changed

9 files changed

+78
-9
lines changed

jscomp/stdlib-406/gc.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ let allocated_bytes () =
9797

9898

9999
external finalise : ('a -> unit) -> 'a -> unit = "caml_final_register"
100+
#if BS then
101+
let finalise_last = fun _ _ : unit -> ()
102+
#else
100103
external finalise_last : (unit -> unit) -> 'a -> unit =
101104
"caml_final_register_called_without_value"
105+
#end
102106
external finalise_release : unit -> unit = "caml_final_release"
103107

104108

jscomp/stdlib-406/hashtbl.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ let flip_ongoing_traversal h =
5656
(* To pick random seeds if requested *)
5757

5858
let randomized_default =
59-
let params =
59+
#if BS then false
60+
#else
61+
let params =
6062
try Sys.getenv "OCAMLRUNPARAM" with Not_found ->
6163
try Sys.getenv "CAMLRUNPARAM" with Not_found -> "" in
6264
String.contains params 'R'
65+
#end
6366

6467
let randomized = ref randomized_default
6568

jscomp/stdlib-406/obj.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ external size : t -> int = "%obj_size"
2828
external reachable_words : t -> int = "caml_obj_reachable_words"
2929
external field : t -> int -> t = "%obj_field"
3030
external set_field : t -> int -> t -> unit = "%obj_set_field"
31+
#if BS then
32+
external floatarray_get : floatarray -> int -> float = "%array_safe_get"
33+
external floatarray_set :
34+
floatarray -> int -> float -> unit = "%array_safe_set"
35+
#else
3136
external floatarray_get : floatarray -> int -> float = "caml_floatarray_get"
3237
external floatarray_set :
3338
floatarray -> int -> float -> unit = "caml_floatarray_set"
39+
#end
3440
let [@inline always] double_field x i = floatarray_get (obj x : floatarray) i
3541
let [@inline always] set_double_field x i v =
3642
floatarray_set (obj x : floatarray) i v
@@ -93,7 +99,7 @@ module Ephemeron = struct
9399

94100
external create: int -> t = "caml_ephe_create"
95101

96-
let length x = size(repr x) - 2
102+
let length x = size(repr x) - 2 (*-FIXME*)
97103

98104
external get_key: t -> int -> obj_t option = "caml_ephe_get_key"
99105
external get_key_copy: t -> int -> obj_t option = "caml_ephe_get_key_copy"

jscomp/stdlib-406/spacetime.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
(* special exception on linking described in the file LICENSE. *)
1212
(* *)
1313
(**************************************************************************)
14-
14+
#if BS then
15+
let spacetime_enabled : unit -> bool = fun _ -> false
16+
let enabled = false
17+
#else
1518
external spacetime_enabled : unit -> bool
1619
= "caml_spacetime_enabled" [@@noalloc]
1720

1821
let enabled = spacetime_enabled ()
19-
22+
#end
2023
let if_spacetime_enabled f =
2124
if enabled then f () else ()
2225

jscomp/stdlib-406/string.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module B = Bytes
3636

3737
let bts = B.unsafe_to_string
3838
let bos = B.unsafe_of_string
39-
39+
(*-FIXME: replaced by Belt.String.repeat *)
4040
let make n c =
4141
B.make n c |> bts
4242
let init n f =

jscomp/stdlib-406/sys.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@ let catch_break on =
129129
else
130130
set_signal sigint Signal_default
131131

132-
132+
#if BS then
133+
let enable_runtime_warnings : bool -> unit = fun _ -> ()
134+
let runtime_warnings_enabled : unit -> bool = fun _ -> false
135+
#else
133136
external enable_runtime_warnings: bool -> unit =
134137
"caml_ml_enable_runtime_warnings"
135138
external runtime_warnings_enabled: unit -> bool =
136139
"caml_ml_runtime_warnings_enabled"
137-
140+
#end
138141
(* The version string is found in file ../VERSION *)
139142

140143
let ocaml_version = "4.06.2+BS"

jscomp/test/adt_optimize_test.ml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,43 @@ let f8 = function
105105
| T65 _ -> 2
106106
| _ -> 3
107107

108-
108+
(*
109+
ocaml402
110+
{[
111+
(function param/1098
112+
(catch
113+
(catch
114+
(catch
115+
(switch param/1098
116+
case int 0: (exit 11)
117+
case int 1: (exit 11)
118+
case int 2: (exit 11)
119+
case tag 0: (exit 12)
120+
case tag 1: (exit 12)
121+
default: (exit 13))
122+
with (13) 3)
123+
with (11) 1)
124+
with (12) 2))
125+
]}
126+
127+
ocaml406
128+
{[
129+
(function param/1069
130+
(catch
131+
(catch
132+
(switch param/1069
133+
case int 3: (exit 10)
134+
case tag 0: (exit 9)
135+
case tag 1: (exit 9)
136+
case tag 2: (exit 10)
137+
case tag 3: (exit 10)
138+
default: 1)
139+
with (10) 3)
140+
with (9) 2))
141+
]}
142+
143+
144+
*)
109145
let f9 = function
110146
| T60
111147
| T61

jscomp/test/local_exception_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let u = B
99
exception D of int
1010

1111
let d = D 3
12-
#if OCAML_VERSION =~ "<4.03.0" then (* Not allowed *)
12+
#if 0 then (* Not allowed *)
1313
exception A of int
1414
(* intentionally overridden ,
1515
so that we can not tell the differrence, only by [id]*)

jscomp/test/recursive_module.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
4+
5+
16
module rec Int32 : sig
27
type t
38
type buffer
@@ -14,3 +19,12 @@ module rec Int3 : sig
1419
end = Int3
1520

1621

22+
23+
(* expect raise Undefined_recursive_module *)
24+
;; eq __LOC__ 4
25+
(try ignore (Int3.u 3); 3
26+
with Undefined_recursive_module _ -> 4)
27+
28+
29+
let () =
30+
Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)