Skip to content

Commit 8271f74

Browse files
committed
clean up && deprecate the usage of @ which is not stack safe
1 parent 67c30f8 commit 8271f74

File tree

2 files changed

+14
-185
lines changed

2 files changed

+14
-185
lines changed

jscomp/stdlib-406/pervasives.ml

+8-94
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616
(* type 'a option = None | Some of 'a *)
1717

1818
(* Exceptions *)
19-
#if BS
20-
#else
21-
external register_named_value : string -> 'a -> unit
22-
= "caml_register_named_value"
23-
24-
let () =
25-
(* for asmrun/fail.c *)
26-
register_named_value "Pervasives.array_bound_error"
27-
(Invalid_argument "index out of bounds")
28-
#end
2919

3020
external raise : exn -> 'a = "%raise"
3121
external raise_notrace : exn -> 'a = "%raise_notrace"
@@ -61,16 +51,8 @@ external ( > ) : 'a -> 'a -> bool = "%greaterthan"
6151
external ( <= ) : 'a -> 'a -> bool = "%lessequal"
6252
external ( >= ) : 'a -> 'a -> bool = "%greaterequal"
6353
external compare : 'a -> 'a -> int = "%compare"
64-
65-
#if BS
6654
external min : 'a -> 'a -> 'a = "%bs_min"
6755
external max : 'a -> 'a -> 'a = "%bs_max"
68-
#else
69-
let min x y = if x <= y then x else y
70-
let max x y = if x >= y then x else y
71-
72-
#end
73-
7456
external ( == ) : 'a -> 'a -> bool = "%eq"
7557
external ( != ) : 'a -> 'a -> bool = "%noteq"
7658

@@ -117,34 +99,19 @@ external ( +. ) : float -> float -> float = "%addfloat"
11799
external ( -. ) : float -> float -> float = "%subfloat"
118100
external ( *. ) : float -> float -> float = "%mulfloat"
119101
external ( /. ) : float -> float -> float = "%divfloat"
120-
#if BS
102+
121103
external ( ** ) : float -> float -> float = "pow" [@@bs.val] [@@bs.scope "Math"]
122104
external exp : float -> float = "exp" [@@bs.val][@@bs.scope "Math"]
123-
#else
124-
external ( ** ) : float -> float -> float = "caml_power_float" "pow"
125-
[@@unboxed] [@@noalloc]
126-
external exp : float -> float = "caml_exp_float" "exp" [@@unboxed] [@@noalloc]
127-
#end
128105
external expm1 : float -> float = "caml_expm1_float" "caml_expm1"
129106
[@@unboxed] [@@noalloc]
130-
#if BS
107+
131108
external acos : float -> float = "acos" [@@bs.val] [@@bs.scope "Math"]
132109
external asin : float -> float = "asin" [@@bs.val] [@@bs.scope "Math"]
133110
external atan : float -> float = "atan" [@@bs.val] [@@bs.scope "Math"]
134111
external atan2 : float -> float -> float = "atan2" [@@bs.val] [@@bs.scope "Math"]
135-
#else
136-
external acos : float -> float = "caml_acos_float" "acos"
137-
[@@unboxed] [@@noalloc]
138-
external asin : float -> float = "caml_asin_float" "asin"
139-
[@@unboxed] [@@noalloc]
140-
external atan : float -> float = "caml_atan_float" "atan"
141-
[@@unboxed] [@@noalloc]
142-
external atan2 : float -> float -> float = "caml_atan2_float" "atan2"
143-
[@@unboxed] [@@noalloc]
144-
#end
145112
external hypot : float -> float -> float
146113
= "caml_hypot_float" "caml_hypot" [@@unboxed] [@@noalloc]
147-
#if BS
114+
148115
external cos : float -> float = "cos" [@@bs.val] [@@bs.scope "Math"]
149116
external cosh : float -> float = "cosh" [@@bs.val] [@@bs.scope "Math"]
150117
external log : float -> float = "log" [@@bs.val] [@@bs.scope "Math"]
@@ -158,29 +125,6 @@ external tanh : float -> float = "tanh" [@@bs.val] [@@bs.scope "Math"]
158125
external ceil : float -> float = "ceil" [@@bs.val] [@@bs.scope "Math"]
159126
external floor : float -> float = "floor" [@@bs.val] [@@bs.scope "Math"]
160127
external abs_float : float -> float = "abs"[@@bs.val] [@@bs.scope "Math"]
161-
#else
162-
external cos : float -> float = "caml_cos_float" "cos" [@@unboxed] [@@noalloc]
163-
external cosh : float -> float = "caml_cosh_float" "cosh"
164-
[@@unboxed] [@@noalloc]
165-
external log : float -> float = "caml_log_float" "log" [@@unboxed] [@@noalloc]
166-
external log10 : float -> float = "caml_log10_float" "log10"
167-
[@@unboxed] [@@noalloc]
168-
external log1p : float -> float = "caml_log1p_float" "caml_log1p"
169-
[@@unboxed] [@@noalloc]
170-
external sin : float -> float = "caml_sin_float" "sin" [@@unboxed] [@@noalloc]
171-
external sinh : float -> float = "caml_sinh_float" "sinh"
172-
[@@unboxed] [@@noalloc]
173-
external sqrt : float -> float = "caml_sqrt_float" "sqrt"
174-
[@@unboxed] [@@noalloc]
175-
external tan : float -> float = "caml_tan_float" "tan" [@@unboxed] [@@noalloc]
176-
external tanh : float -> float = "caml_tanh_float" "tanh"
177-
[@@unboxed] [@@noalloc]
178-
external ceil : float -> float = "caml_ceil_float" "ceil"
179-
[@@unboxed] [@@noalloc]
180-
external floor : float -> float = "caml_floor_float" "floor"
181-
[@@unboxed] [@@noalloc]
182-
external abs_float : float -> float = "%absfloat"
183-
#end
184128
external copysign : float -> float -> float
185129
= "caml_copysign_float" "caml_copysign"
186130
[@@unboxed] [@@noalloc]
@@ -195,34 +139,14 @@ external float_of_int : int -> float = "%floatofint"
195139
external truncate : float -> int = "%intoffloat"
196140
external int_of_float : float -> int = "%intoffloat"
197141

198-
#if BS (* better unused finding *)
199-
#else
200-
external float_of_bits : int64 -> float
201-
= "caml_int64_float_of_bits" "caml_int64_float_of_bits_unboxed"
202-
[@@unboxed] [@@noalloc]
203-
#end
204-
#if BS
142+
205143
let infinity = 0x1p2047
206144
let neg_infinity = -0x1p2047
207145
external nan : float = "NaN"
208146
[@@bs.val] [@@bs.scope "Number"]
209147
let max_float = 1.79769313486231571e+308 (*0x1.ffff_ffff_ffff_fp+1023*)
210148
let min_float = 2.22507385850720138e-308 (* 0x1p-1022 *)
211149
let epsilon_float = 2.22044604925031308e-16 (* 0x1p-52 *)
212-
#else
213-
let infinity =
214-
float_of_bits 0x7F_F0_00_00_00_00_00_00L
215-
let neg_infinity =
216-
float_of_bits 0xFF_F0_00_00_00_00_00_00L
217-
let nan =
218-
float_of_bits 0x7F_F0_00_00_00_00_00_01L
219-
let max_float =
220-
float_of_bits 0x7F_EF_FF_FF_FF_FF_FF_FFL
221-
let min_float =
222-
float_of_bits 0x00_10_00_00_00_00_00_00L
223-
let epsilon_float =
224-
float_of_bits 0x3C_B0_00_00_00_00_00_00L
225-
#end
226150

227151

228152

@@ -232,7 +156,7 @@ type fpclass =
232156
| FP_zero
233157
| FP_infinite
234158
| FP_nan
235-
#if BS
159+
236160
let classify_float (x : float) : fpclass =
237161
if ([%raw{|isFinite|}] : _ -> _ [@bs]) x [@bs] then
238162
if abs_float x >= (* 0x1p-1022 *) (* 2.22507385850720138e-308*) min_float then
@@ -243,10 +167,7 @@ let classify_float (x : float) : fpclass =
243167
if ([%raw{|isNaN|}] : _ -> _ [@bs]) x [@bs] then
244168
FP_nan
245169
else FP_infinite
246-
#else
247-
external classify_float : (float [@unboxed]) -> fpclass =
248-
"caml_classify_float" "caml_classify_float_unboxed" [@@noalloc]
249-
#end
170+
250171
(* String and byte sequence operations -- more in modules String and Bytes *)
251172

252173
external string_length : string -> int = "%string_length"
@@ -285,10 +206,6 @@ type ('a, 'b) result = ('a, 'b) Belt.Result.t =
285206
| Error of 'b
286207

287208
(* String conversion functions *)
288-
#if BS
289-
#else
290-
external format_int : string -> int -> string = "caml_format_int"
291-
#end
292209
external format_float : string -> float -> string = "caml_format_float"
293210

294211
let string_of_bool b =
@@ -303,12 +220,9 @@ let bool_of_string_opt = function
303220
| "false" -> Some false
304221
| _ -> None
305222

306-
#if BS
223+
307224
external string_of_int : int -> string = "String" [@@bs.val]
308-
#else
309-
let string_of_int n =
310-
format_int "%d" n
311-
#end
225+
312226
external int_of_string : string -> int = "caml_int_of_string"
313227

314228
let int_of_string_opt s =

jscomp/stdlib-406/pervasives.mli

+6-91
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,9 @@ val infinity : float
620620
val neg_infinity : float
621621
(** Negative infinity. *)
622622

623-
#if BS then
623+
624624
external nan : float = "NaN" [@@bs.val] [@@bs.scope "Number"]
625625
(* we could also use [0. /. 0.] *)
626-
#else
627-
val nan : float
628-
#end
629626
(** A special floating-point value denoting the result of an
630627
undefined operation such as [0.0 /. 0.0]. Stands for
631628
'not a number'. Any floating-point operation with [nan] as
@@ -652,12 +649,8 @@ type fpclass =
652649
| FP_nan (** Not a number: result of an undefined operation *)
653650
(** The five classes of floating-point numbers, as determined by
654651
the {!Pervasives.classify_float} function. *)
655-
#if BS then
652+
656653
val classify_float : float -> fpclass
657-
#else
658-
external classify_float : (float [@unboxed]) -> fpclass =
659-
"caml_classify_float" "caml_classify_float_unboxed" [@@noalloc]
660-
#end
661654
(** Return the class of the given floating-point number:
662655
normal, subnormal, zero, infinite, or not a number. *)
663656

@@ -666,11 +659,7 @@ external classify_float : (float [@unboxed]) -> fpclass =
666659
667660
More string operations are provided in module {!String}.
668661
*)
669-
#if BS then
670662
external (^) : string -> string -> string = "#string_append"
671-
#else
672-
val ( ^ ) : string -> string -> string
673-
#end
674663
(** String concatenation.
675664
Right-associative operator at precedence level 5/11. *)
676665

@@ -719,11 +708,8 @@ val bool_of_string_opt: string -> bool option
719708
@since 4.05
720709
*)
721710

722-
#if BS then
711+
723712
external string_of_int : int -> string = "String" [@@bs.val]
724-
#else
725-
val string_of_int : int -> string
726-
#end
727713
(** Return the string representation of an integer, in decimal. *)
728714

729715
external int_of_string : string -> int = "caml_int_of_string"
@@ -791,9 +777,11 @@ external snd : 'a * 'b -> 'b = "%field1"
791777
*)
792778

793779
val ( @ ) : 'a list -> 'a list -> 'a list
794-
(** List concatenation. Not tail-recursive (length of the first argument).
780+
[@@ocaml.deprecated "Use Belt.List.append instead"]
781+
(** List concatenation. Tail-recursive (length of the first argument).
795782
Right-associative operator at precedence level 5/11. *)
796783

784+
797785
type int32 = int
798786

799787

@@ -867,79 +855,6 @@ type ('a, 'b) result = ('a, 'b) Belt.Result.t =
867855
| Ok of 'a
868856
| Error of 'b
869857

870-
(** {1 Operations on format strings} *)
871-
872-
(** Format strings are character strings with special lexical conventions
873-
that defines the functionality of formatted input/output functions. Format
874-
strings are used to read data with formatted input functions from module
875-
{!Scanf} and to print data with formatted output functions from modules
876-
{!Printf} and {!Format}.
877-
878-
Format strings are made of three kinds of entities:
879-
- {e conversions specifications}, introduced by the special character ['%']
880-
followed by one or more characters specifying what kind of argument to
881-
read or print,
882-
- {e formatting indications}, introduced by the special character ['@']
883-
followed by one or more characters specifying how to read or print the
884-
argument,
885-
- {e plain characters} that are regular characters with usual lexical
886-
conventions. Plain characters specify string literals to be read in the
887-
input or printed in the output.
888-
889-
There is an additional lexical rule to escape the special characters ['%']
890-
and ['@'] in format strings: if a special character follows a ['%']
891-
character, it is treated as a plain character. In other words, ["%%"] is
892-
considered as a plain ['%'] and ["%@"] as a plain ['@'].
893-
894-
For more information about conversion specifications and formatting
895-
indications available, read the documentation of modules {!Scanf},
896-
{!Printf} and {!Format}.
897-
*)
898-
899-
(** Format strings have a general and highly polymorphic type
900-
[('a, 'b, 'c, 'd, 'e, 'f) format6].
901-
The two simplified types, [format] and [format4] below are
902-
included for backward compatibility with earlier releases of
903-
OCaml.
904-
905-
The meaning of format string type parameters is as follows:
906-
907-
- ['a] is the type of the parameters of the format for formatted output
908-
functions ([printf]-style functions);
909-
['a] is the type of the values read by the format for formatted input
910-
functions ([scanf]-style functions).
911-
912-
- ['b] is the type of input source for formatted input functions and the
913-
type of output target for formatted output functions.
914-
For [printf]-style functions from module {!Printf}, ['b] is typically
915-
[out_channel];
916-
for [printf]-style functions from module {!Format}, ['b] is typically
917-
{!Format.formatter};
918-
for [scanf]-style functions from module {!Scanf}, ['b] is typically
919-
{!Scanf.Scanning.in_channel}.
920-
921-
Type argument ['b] is also the type of the first argument given to
922-
user's defined printing functions for [%a] and [%t] conversions,
923-
and user's defined reading functions for [%r] conversion.
924-
925-
- ['c] is the type of the result of the [%a] and [%t] printing
926-
functions, and also the type of the argument transmitted to the
927-
first argument of [kprintf]-style functions or to the
928-
[kscanf]-style functions.
929-
930-
- ['d] is the type of parameters for the [scanf]-style functions.
931-
932-
- ['e] is the type of the receiver function for the [scanf]-style functions.
933-
934-
- ['f] is the final result type of a formatted input/output function
935-
invocation: for the [printf]-style functions, it is typically [unit];
936-
for the [scanf]-style functions, it is typically the result type of the
937-
receiver function.
938-
*)
939-
940-
941-
942-
943858

944859
(** {1 Program termination} *)
945860

0 commit comments

Comments
 (0)