Skip to content

Commit 33441df

Browse files
authored
Merge pull request #4893 from rescript-lang/simplify_number
simplify numbers in JS IR
2 parents 7668157 + 58cdd2a commit 33441df

File tree

107 files changed

+1802
-1863
lines changed

Some content is hidden

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

107 files changed

+1802
-1863
lines changed

jscomp/core/j.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ and required_modules = module_id list
7373
currently we always use quote
7474
*)
7575
and property_name = Js_op.property_name
76-
and jsint = Js_op.jsint
76+
and jsint = int32
7777
and ident = Ident.t
7878
and module_id = {
7979
id : ident; kind : Js_op.kind

jscomp/core/js_analyzer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ let rec eq_expression
178178
begin match x0 with
179179
| Null -> y0 = Null
180180
| Undefined -> y0 = Undefined
181-
| Number (Int i) ->
181+
| Number (Int {i}) ->
182182
begin match y0 with
183-
| Number (Int j) -> i = j
183+
| Number (Int {i = j}) -> i = j
184184
| _ -> false
185185
end
186186
| Number (Float _) -> false

jscomp/core/js_dump.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ and expression_desc cxt ~(level:int) f x : cxt =
671671
| Float {f} ->
672672
Js_number.caml_float_literal_to_js_string f
673673
(* attach string here for float constant folding?*)
674-
| Int { i; _}
674+
| Int { i; c = Some c}
675+
-> Format.asprintf "/* %C */%ld" c i
676+
| Int { i; c = None}
675677
-> Int32.to_string i (* check , js convention with ocaml lexical convention *)
676678
| Uint i
677679
-> Format.asprintf "%lu" i

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ val extension_assign :
247247
val assign_by_int :
248248
?comment:string ->
249249
t ->
250-
Js_op.jsint ->
250+
int32 ->
251251
t ->
252252
t
253253

jscomp/core/js_fold.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class virtual fold =
316316
method length_object : length_object -> 'self_type = o#unknown
317317
method label : label -> 'self_type = o#string
318318
method kind : kind -> 'self_type = o#unknown
319-
method jsint : jsint -> 'self_type = o#unknown
319+
method jsint : jsint -> 'self_type = o#int32
320320
method int_op : int_op -> 'self_type = o#unknown
321321
method ident_info : ident_info -> 'self_type = o#unknown
322322
method ident : ident -> 'self_type = o#unknown

jscomp/core/js_map.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class virtual map =
338338
method length_object : length_object -> length_object = o#unknown
339339
method label : label -> label = o#string
340340
method kind : kind -> kind = o#unknown
341-
method jsint : jsint -> jsint = o#unknown
341+
method jsint : jsint -> jsint = o#int32
342342
method int_op : int_op -> int_op = o#unknown
343343
method ident_info : ident_info -> ident_info = o#unknown
344344
method ident : ident -> ident = o#unknown

jscomp/core/js_of_lam_string.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module E = Js_exp_make
4040
*)
4141

4242
let const_char (i : char) =
43-
E.int ~comment:("\"" ^ String.escaped (String.make 1 i) ^ "\"")
43+
E.int
4444
~c:i (Int32.of_int @@ Char.code i)
4545

4646
let caml_char_of_int (v : J.expression) = v

jscomp/core/js_op.ml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,13 @@ type property_name =
153153
type 'a access =
154154
| Getter
155155
| Setter
156-
type jsint = Int32.t
157-
158-
type int_or_char =
159-
{ i : jsint;
160-
(* we can not use [int] on 32 bit platform, if we dont use
161-
[Int32.t], we need a configuration step
162-
*)
163-
c : char option
164-
}
165156

166157
(* literal char *)
167158
type float_lit = { f : string } [@@unboxed]
168159

169160
type number =
170161
| Float of float_lit
171-
| Int of int_or_char
162+
| Int of { i : int32; c : char option}
172163
| Uint of int32
173164

174165
(* becareful when constant folding +/-,

jscomp/core/lam_analysis.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ let rec no_side_effects (lam : Lam.t) : bool =
5858
| "caml_make_vect"
5959
| "caml_create_bytes"
6060
| "caml_obj_dup"
61-
| "caml_array_dup"
61+
| "caml_array_dup"
62+
63+
| "nativeint_add"
64+
| "nativeint_div"
65+
| "nativeint_mod"
66+
| "nativeint_lsr"
67+
| "nativeint_mul"
68+
6269
), _ -> true
6370
| "caml_ml_open_descriptor_in", [Lconst ( (Const_int {i = 0l}))] -> true
6471
| "caml_ml_open_descriptor_out",

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,21 @@ let translate loc (prim_name : string)
9898
| _ -> assert false
9999
end
100100
| "caml_int32_of_int"
101-
| "caml_nativeint_of_int"
102-
| "caml_nativeint_of_int32" ->
101+
->
103102
begin match args with
104103
| [e] -> e
105104
| _ -> assert false
106105
end
107106
| "caml_int32_of_float"
108107
| "caml_int_of_float"
109-
| "caml_nativeint_of_float" ->
108+
->
110109
begin match args with
111110
| [e] -> E.to_int32 e
112111
| _ -> assert false
113112
end
114113
| "caml_int32_to_float"
115-
| "caml_int32_to_int"
116-
| "caml_nativeint_to_int"
117-
| "caml_nativeint_to_float"
118-
| "caml_nativeint_to_int32" ->
114+
| "caml_int32_to_int"
115+
->
119116
begin match args with
120117
| [e] -> e (* TODO: do more checking when [to_int32]*)
121118
| _ -> assert false
@@ -290,11 +287,6 @@ let translate loc (prim_name : string)
290287
| "caml_int32_equal_null"
291288
| "caml_int32_equal_nullable"
292289
| "caml_int32_equal_undefined"
293-
294-
295-
| "caml_nativeint_equal_null"
296-
| "caml_nativeint_equal_nullable"
297-
| "caml_nativeint_equal_undefined"
298290
->
299291
begin match args with
300292
| [e0;e1]
@@ -355,7 +347,7 @@ let translate loc (prim_name : string)
355347
end
356348
| "caml_int_compare"
357349
| "caml_int32_compare"
358-
| "caml_nativeint_compare"
350+
359351
| "caml_float_compare"
360352

361353
| "caml_string_compare"
@@ -365,7 +357,7 @@ let translate loc (prim_name : string)
365357
| "caml_int_min"
366358
| "caml_float_min"
367359
| "caml_string_min"
368-
| "caml_nativeint_min"
360+
369361
| "caml_int32_min"
370362

371363
->
@@ -381,7 +373,7 @@ let translate loc (prim_name : string)
381373
| "caml_int_max"
382374
| "caml_float_max"
383375
| "caml_string_max"
384-
| "caml_nativeint_max"
376+
385377
| "caml_int32_max"
386378
->
387379
begin match args with

0 commit comments

Comments
 (0)