Skip to content

Commit 4ee4603

Browse files
committed
remove uint32 liternal which has never exposed
1 parent 5e7f5ab commit 4ee4603

File tree

6 files changed

+30
-54
lines changed

6 files changed

+30
-54
lines changed

jscomp/core/js_analyzer.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
209209
| Length _ | Is_null_or_undefined _ | String_append _ | Typeof _ | Js_not _
210210
| Cond _ | FlatCall _ | New _ | Fun _ | Raw_js_code _ | Array _
211211
| Caml_block_tag _ | Object _ | Tagged_template _
212-
| Number (Uint _) ->
213-
false
214212
| Await _ -> false
215213

216214
and eq_expression_list xs ys = Ext_list.for_all2_no_exn xs ys eq_expression

jscomp/core/js_dump.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ and expression_desc cxt ~(level : int) f x : cxt =
661661
| Int { i; c = None } ->
662662
Int32.to_string i
663663
(* check , js convention with ocaml lexical convention *)
664-
| Uint i -> Format.asprintf "%lu" i
665664
| BigInt {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value)
666665
in
667666
let need_paren =
@@ -670,8 +669,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
670669
else
671670
level = 15 (* Parenthesize as well when followed by a dot. *)
672671
&& s.[0] <> 'I' (* Infinity *)
673-
&& s.[0] <> 'N'
674-
(* NaN *)
672+
&& s.[0] <> 'N' (* NaN *)
675673
in
676674
let action _ = P.string f s in
677675
if need_paren then P.paren f action else action ();

jscomp/core/js_exp_make.ml

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -882,31 +882,28 @@ let tag ?comment ?(name=Js_dump_lit.tag) e : t =
882882
let rec int32_bor ?comment (e1 : J.expression) (e2 : J.expression) :
883883
J.expression =
884884
match (e1.expression_desc, e2.expression_desc) with
885-
| Number (Int { i = i1 } | Uint i1), Number (Int { i = i2 }) ->
885+
| Number (Int { i = i1 }), Number (Int { i = i2 }) ->
886886
int ?comment (Int32.logor i1 i2)
887-
| _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ })
887+
| _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l }); _ })
888888
->
889889
int32_bor e1 e2
890-
| Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }), _
890+
| Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l }); _ }), _
891891
->
892892
int32_bor e1 e2
893-
| ( Bin (Lsr, _, { expression_desc = Number (Int { i } | Uint i); _ }),
894-
Number (Int { i = 0l } | Uint 0l) )
893+
| ( Bin (Lsr, _, { expression_desc = Number (Int { i }); _ }),
894+
Number (Int { i = 0l }) )
895895
when i > 0l ->
896896
(* a >>> 3 | 0 -> a >>> 3 *)
897897
e1
898-
| ( Bin (Bor, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }),
899-
Number (Int { i = 0l } | Uint 0l) ) ->
898+
| ( Bin (Bor, e1, { expression_desc = Number (Int { i = 0l }); _ }),
899+
Number (Int { i = 0l }) ) ->
900900
int32_bor e1 e2
901901
| _ -> { comment; expression_desc = Bin (Bor, e1, e2) }
902902

903903
let to_int32 ?comment (e : J.expression) : J.expression =
904904
int32_bor ?comment e zero_int_literal
905905
(* TODO: if we already know the input is int32, [x|0] can be reduced into [x] *)
906906

907-
let uint32 ?comment n : J.expression =
908-
{ expression_desc = Number (Uint n); comment }
909-
910907
let string_comp (cmp : J.binop) ?comment (e0 : t) (e1 : t) =
911908
match (e0.expression_desc, e1.expression_desc) with
912909
| Str { txt = a0; delim = d0 }, Str { txt = a1; delim = d1 } -> (
@@ -931,19 +928,9 @@ let compare_int_aux (cmp : Lam_compat.comparison) (l : int) r =
931928

932929
let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) =
933930
match (cmp, e0.expression_desc, e1.expression_desc) with
934-
| _, Number ((Int _ | Uint _) as l), Number ((Int _ | Uint _) as r) ->
935-
let l =
936-
match l with
937-
| Uint l -> Ext_int.int32_unsigned_to_int l
938-
| Int { i = l } -> Int32.to_int l
939-
| _ -> assert false
940-
in
941-
let r =
942-
match r with
943-
| Uint l -> Ext_int.int32_unsigned_to_int l
944-
| Int { i = l } -> Int32.to_int l
945-
| _ -> assert false
946-
in
931+
| _, Number ((Int { i = l })), Number ((Int { i = r })) ->
932+
let l = Ext_int.int32_unsigned_to_int l in
933+
let r = Int32.to_int r in
947934
bool (compare_int_aux cmp l r)
948935
| ( _,
949936
Call
@@ -1025,20 +1012,17 @@ let js_comp cmp ?comment e0 e1 =
10251012

10261013
let rec int32_lsr ?comment (e1 : J.expression) (e2 : J.expression) :
10271014
J.expression =
1028-
let aux i1 i = uint32 (Int32.shift_right_logical i1 i) in
1015+
let aux i1 i = int (Int32.shift_right_logical i1 i) in
10291016
match (e1.expression_desc, e2.expression_desc) with
1030-
| Number (Int { i = i1 } | Uint i1), Number (Int { i = i2 } | Uint i2) ->
1017+
| Number (Int { i = i1 }), Number (Int { i = i2 }) ->
10311018
aux i1 (Int32.to_int i2)
1032-
| Bin (Lsr, _, _), Number (Int { i = 0l } | Uint 0l) ->
1019+
| Bin (Lsr, _, _), Number (Int { i = 0l }) ->
10331020
e1 (* TODO: more opportunities here *)
10341021
| ( Bin
1035-
(Bor, e1, { expression_desc = Number (Int { i = 0l; _ } | Uint 0l); _ }),
1036-
Number (Int { i = 0l } | Uint 0l) ) ->
1022+
(Bor, e1, { expression_desc = Number (Int { i = 0l; _ }); _ }),
1023+
Number (Int { i = 0l }) ) ->
10371024
int32_lsr ?comment e1 e2
1038-
| _, _ -> { comment; expression_desc = Bin (Lsr, e1, e2) (* uint32 *) }
1039-
1040-
let to_uint32 ?comment (e : J.expression) : J.expression =
1041-
int32_lsr ?comment e zero_int_literal
1025+
| _, _ -> { comment; expression_desc = Bin (Lsr, e1, e2) }
10421026

10431027
(* TODO:
10441028
we can apply a more general optimization here,
@@ -1094,10 +1078,11 @@ let rec is_out ?comment (e : t) (range : t) : t =
10941078
{ expression_desc = Var _; _ },
10951079
{ expression_desc = Number (Int { i = _; _ }) } ) );
10961080
} as e),
1097-
{ expression_desc = Number (Int { i = 0l } | Uint 0l); _ } ) ) ->
1081+
{ expression_desc = Number (Int { i = 0l }); _ } ) ) ->
10981082
(* TODO: check correctness *)
10991083
is_out ?comment e range
1100-
| _, _ -> int_comp ?comment Cgt (to_uint32 e) range
1084+
| _, _ ->
1085+
int_comp ?comment Cgt e range
11011086

11021087
let rec float_add ?comment (e1 : t) (e2 : t) =
11031088
match (e1.expression_desc, e2.expression_desc) with
@@ -1158,7 +1143,7 @@ let int32_asr ?comment e1 e2 : J.expression =
11581143
(** Division by zero is undefined behavior*)
11591144
let int32_div ~checked ?comment (e1 : t) (e2 : t) : t =
11601145
match (e1.expression_desc, e2.expression_desc) with
1161-
| Length _, Number (Int { i = 2l } | Uint 2l) -> int32_asr e1 one_int_literal
1146+
| Length _, Number (Int { i = 2l }) -> int32_asr e1 one_int_literal
11621147
| e1_desc, Number (Int { i = i1 }) when i1 <> 0l -> (
11631148
match e1_desc with
11641149
| Number (Int { i = i0 }) -> int (Int32.div i0 i1)
@@ -1179,8 +1164,8 @@ let float_mul ?comment e1 e2 = bin ?comment Mul e1 e2
11791164

11801165
let int32_lsl ?comment (e1 : J.expression) (e2 : J.expression) : J.expression =
11811166
match (e1, e2) with
1182-
| ( { expression_desc = Number (Int { i = i0 } | Uint i0) },
1183-
{ expression_desc = Number (Int { i = i1 } | Uint i1) } ) ->
1167+
| ( { expression_desc = Number (Int { i = i0 }) },
1168+
{ expression_desc = Number (Int { i = i1 }) } ) ->
11841169
int ?comment (Int32.shift_left i0 (Int32.to_int i1))
11851170
| _ -> { comment; expression_desc = Bin (Lsl, e1, e2) }
11861171

@@ -1196,17 +1181,17 @@ let is_pos_pow n =
11961181

11971182
let int32_mul ?comment (e1 : J.expression) (e2 : J.expression) : J.expression =
11981183
match (e1, e2) with
1199-
| { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }, x
1184+
| { expression_desc = Number (Int { i = 0l }); _ }, x
12001185
when Js_analyzer.no_side_effect_expression x ->
12011186
zero_int_literal
1202-
| x, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }
1187+
| x, { expression_desc = Number (Int { i = 0l }); _ }
12031188
when Js_analyzer.no_side_effect_expression x ->
12041189
zero_int_literal
12051190
| ( { expression_desc = Number (Int { i = i0 }); _ },
12061191
{ expression_desc = Number (Int { i = i1 }); _ } ) ->
12071192
int (Int32.mul i0 i1)
1208-
| e, { expression_desc = Number (Int { i = i0 } | Uint i0); _ }
1209-
| { expression_desc = Number (Int { i = i0 } | Uint i0); _ }, e ->
1193+
| e, { expression_desc = Number (Int { i = i0 }); _ }
1194+
| { expression_desc = Number (Int { i = i0 }); _ }, e ->
12101195
let i = is_pos_pow i0 in
12111196
if i >= 0 then int32_lsl e (small_int i)
12121197
else
@@ -1225,10 +1210,10 @@ let rec int32_bxor ?comment (e1 : t) (e2 : t) : J.expression =
12251210
match (e1.expression_desc, e2.expression_desc) with
12261211
| Number (Int { i = i1 }), Number (Int { i = i2 }) ->
12271212
int ?comment (Int32.logxor i1 i2)
1228-
| _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ })
1213+
| _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l }); _ })
12291214
->
12301215
int32_bxor e1 e2
1231-
| Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }), _
1216+
| Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l }); _ }), _
12321217
->
12331218
int32_bxor e1 e2
12341219
| _ -> { comment; expression_desc = Bin (Bxor, e1, e2) }

jscomp/core/js_exp_make.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ val econd : ?comment:string -> t -> t -> t -> t
108108

109109
val int : ?comment:string -> ?c:int -> int32 -> t
110110

111-
val uint32 : ?comment:string -> int32 -> t
112-
113111
val small_int : int -> t
114112

115113
val bigint : ?comment:string -> bool -> string -> t
@@ -225,8 +223,6 @@ val is_array : t -> t
225223

226224
val to_int32 : ?comment:string -> t -> t
227225

228-
val to_uint32 : ?comment:string -> t -> t
229-
230226
val unchecked_int32_add : ?comment:string -> t -> t -> t
231227

232228
val int32_add : ?comment:string -> t -> t -> t

jscomp/core/js_op.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ type bigint_lit = { positive: bool; value: string }
131131
type number =
132132
| Float of float_lit
133133
| Int of { i : int32; c : int option }
134-
| Uint of int32
135134
| BigInt of bigint_lit
136135

137136
(* becareful when constant folding +/-,

jscomp/core/lam_compile_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
228228
match args with [ e1; e2 ] -> E.bigint_op Lsl e1 e2 | _ -> assert false)
229229
| Plsrint -> (
230230
match args with
231-
| [ e1; { J.expression_desc = Number (Int { i = 0l; _ } | Uint 0l); _ } ]
231+
| [ e1; { J.expression_desc = Number (Int { i = 0l; _ }); _ } ]
232232
->
233233
e1
234234
| [ e1; e2 ] -> E.to_int32 @@ E.int32_lsr e1 e2

0 commit comments

Comments
 (0)