Skip to content

Commit 1dcc516

Browse files
authored
Merge pull request #2705 from BuckleScript/clean_up
clean up, remove unused code
2 parents 602ed5d + 545b711 commit 1dcc516

Some content is hidden

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

45 files changed

+259
-978
lines changed

jscomp/bin/all_ounit_tests.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,6 +3529,7 @@ val js_array_ctor : string
35293529
val js_type_number : string
35303530
val js_type_string : string
35313531
val js_type_object : string
3532+
val js_type_boolean : string
35323533
val js_undefined : string
35333534
val js_prop_length : string
35343535

@@ -3663,6 +3664,7 @@ let js_array_ctor = "Array"
36633664
let js_type_number = "number"
36643665
let js_type_string = "string"
36653666
let js_type_object = "object"
3667+
let js_type_boolean = "boolean"
36663668
let js_undefined = "undefined"
36673669
let js_prop_length = "length"
36683670

@@ -6895,9 +6897,9 @@ val make_unused : unit -> Ident.t
68956897
val convert : string -> string
68966898

68976899

6898-
val undefined : Ident.t
6900+
68996901
val is_js_or_global : Ident.t -> bool
6900-
val nil : Ident.t
6902+
69016903

69026904

69036905
val compare : Ident.t -> Ident.t -> int
@@ -7219,9 +7221,6 @@ let reset () =
72197221
String_hashtbl.clear js_module_table
72207222

72217223

7222-
let undefined = create_js "undefined"
7223-
let nil = create_js "null"
7224-
72257224
(* Has to be total order, [x < y]
72267225
and [x > y] should be consistent
72277226
flags are not relevant here

jscomp/core/bs_conditional_initial.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
let setup_env () =
2727
#if BS_DEBUG then
28-
Js_config.set_debug_file "pipe_syntax.ml";
28+
Js_config.set_debug_file "gpr_2700_test.ml";
2929
#end
3030
Lexer.replace_directive_bool "BS" true;
3131
Lexer.replace_directive_string "BS_VERSION" Bs_version.version

jscomp/core/j.ml

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -102,68 +102,17 @@ and expression_desc =
102102
| Length of expression * length_object
103103
| Char_of_int of expression
104104
| Char_to_int of expression
105-
| Is_null_undefined_to_boolean of expression
105+
| Is_null_or_undefined of expression
106106
(** where we use a trick [== null ] *)
107-
| Array_of_size of expression
108-
(* used in [#create_array] primitive, note having
109-
uninitilized array is not as bad as in ocaml,
110-
since GC does not rely on it
111-
*)
112107
| Array_copy of expression (* shallow copy, like [x.slice] *)
113-
| Array_append of expression * expression (* For [caml_array_append]*)
114-
(* | Tag_ml_obj of expression *)
115-
| String_append of expression * expression
116108

117-
| Anything_to_number of expression
109+
| String_append of expression * expression
118110
| Bool of bool (* js true/false*)
119111
(* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
120112
[typeof] is an operator
121113
*)
122114
| Typeof of expression
123115
| Js_not of expression (* !v *)
124-
| String_of_small_int_array of expression
125-
(* String.fromCharCode.apply(null, args) *)
126-
(* Convert JS boolean into OCaml boolean
127-
like [+true], note this ast talks using js
128-
terminnology unless explicity stated
129-
*)
130-
| Json_stringify of expression
131-
(* TODO: in the future, it might make sense to group primitivie by type,
132-
which makes optimizations easier
133-
{[ JSON.stringify(value, replacer[, space]) ]}
134-
*)
135-
| Anything_to_string of expression
136-
(* for debugging utitlites,
137-
TODO: [Dump] is not necessary with this primitive
138-
Note that the semantics is slightly different from [JSON.stringify]
139-
{[
140-
JSON.stringify("x")
141-
]}
142-
{[
143-
""x""
144-
]}
145-
{[
146-
JSON.stringify(undefined)
147-
]}
148-
{[
149-
undefined
150-
]}
151-
{[ '' + undefined
152-
]}
153-
{[ 'undefined'
154-
]}
155-
*)
156-
| Dump of Js_op.level * expression list
157-
(* TODO:
158-
add
159-
{[ Assert of bool * expression ]}
160-
*)
161-
(* to support
162-
val log1 : 'a -> unit
163-
val log2 : 'a -> 'b -> unit
164-
val log3 : 'a -> 'b -> 'c -> unit
165-
*)
166-
167116
(* TODO: Add some primitives so that [js inliner] can do a better job *)
168117
| Seq of expression * expression
169118
| Cond of expression * expression * expression
@@ -178,11 +127,6 @@ and expression_desc =
178127
if it's know at compile time, we can turn it into
179128
f(args[0], args[1], ... )
180129
*)
181-
| Bind of expression * expression
182-
(* {[ Bind (a,b) ]}
183-
is literally
184-
{[ a.bind(b) ]}
185-
*)
186130
| Call of expression * expression list * Js_call_info.t
187131
(* Analysze over J expression is hard since,
188132
some primitive call is translated
@@ -250,7 +194,8 @@ and expression_desc =
250194
*)
251195
| Number of number
252196
| Object of property_map
253-
197+
| Undefined
198+
| Null
254199
and for_ident_expression = expression (* pure*)
255200

256201
and finish_ident_expression = expression (* pure *)

jscomp/core/js_analyzer.ml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ let free_variables_of_expression used_idents defined_idents st =
8383

8484
let rec no_side_effect_expression_desc (x : J.expression_desc) =
8585
match x with
86+
| Undefined
87+
| Null
8688
| Bool _
8789
| Var _
8890
| Unicode _ -> true
8991
| Fun _ -> true
9092
| Number _ -> true (* Can be refined later *)
9193
| Access (a,b) -> no_side_effect a && no_side_effect b
92-
| Is_null_undefined_to_boolean b -> no_side_effect b
94+
| Is_null_or_undefined b -> no_side_effect b
9395
| Str (b,_) -> b
9496
| Array (xs,_mutable_flag)
9597
| Caml_block (xs, _mutable_flag, _, _)
@@ -100,10 +102,8 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
100102
the block is mutable does not mean this operation is non-pure
101103
*)
102104
List.for_all no_side_effect xs
103-
| Bind(fn, obj) -> no_side_effect fn && no_side_effect obj
104105
| Object kvs ->
105106
List.for_all (fun (_property_name, y) -> no_side_effect y ) kvs
106-
| Array_append (a,b)
107107
| String_append (a,b)
108108
| Seq (a,b) -> no_side_effect a && no_side_effect b
109109
| Length (e, _)
@@ -115,15 +115,8 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
115115
| Bin (op, a, b) ->
116116
op <> Eq && no_side_effect a && no_side_effect b
117117
| Math _
118-
| Array_of_size _
119118
| Array_copy _
120-
(* | Tag_ml_obj _ *)
121-
| J.Anything_to_number _
122119
| Js_not _
123-
| String_of_small_int_array _
124-
| Json_stringify _
125-
| Anything_to_string _
126-
| Dump _
127120
| Cond _
128121

129122
| FlatCall _
@@ -184,6 +177,8 @@ let rec eq_expression
184177
({expression_desc = x0} : J.expression)
185178
({expression_desc = y0} : J.expression) =
186179
begin match x0 with
180+
| Null -> y0 = Null
181+
| Undefined -> y0 = Undefined
187182
| Number (Int i) ->
188183
begin match y0 with
189184
| Number (Int j) -> i = j
@@ -244,12 +239,6 @@ let rec eq_expression
244239
p0 = p1 && b0 = b1 && eq_expression e0 e1
245240
| _ -> false
246241
end
247-
| Dump (l0,es0) ->
248-
begin match y0 with
249-
| Dump(l1,es1) ->
250-
l0 = l1 && eq_expression_list es0 es1
251-
| _ -> false
252-
end
253242
| Seq (a0,b0) ->
254243
begin match y0 with
255244
| Seq(a1,b1) ->
@@ -264,23 +253,13 @@ let rec eq_expression
264253
| Length _
265254
| Char_of_int _
266255
| Char_to_int _
267-
| Is_null_undefined_to_boolean _
268-
| Array_of_size _
256+
| Is_null_or_undefined _
269257
| Array_copy _
270-
| Array_append _
271258
| String_append _
272-
| Anything_to_number _
273-
274259
| Typeof _
275260
| Js_not _
276-
| String_of_small_int_array _
277-
| Json_stringify _
278-
| Anything_to_string _
279-
280-
281261
| Cond _
282262
| FlatCall _
283-
| Bind _
284263
| String_access _
285264

286265
| New _

0 commit comments

Comments
 (0)