Skip to content

Commit 1beb54d

Browse files
authored
Clean up unused compiler IR definitions (#8551)
* Remove unused integer precedence helper Signed-off-by: Christoph Knittel <ck@cca.io> * Remove unused used-stats formatter Signed-off-by: Christoph Knittel <ck@cca.io> * Remove unused JavaScript IR metadata Signed-off-by: Christoph Knittel <ck@cca.io> * Remove unused JavaScript IR helpers Signed-off-by: Christoph Knittel <ck@cca.io> * Simplify JavaScript array and constructor IR Signed-off-by: Christoph Knittel <ck@cca.io> * Remove stale JavaScript IR scaffolding Signed-off-by: Christoph Knittel <ck@cca.io> * Deduplicate mutability metadata across IRs Signed-off-by: Christoph Knittel <ck@cca.io> * Restore cached block mutability Signed-off-by: Christoph Knittel <ck@cca.io> --------- Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 932ab67 commit 1beb54d

28 files changed

Lines changed: 83 additions & 504 deletions

compiler/core/j.ml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
type mutable_flag = Js_op.mutable_flag
3535
type binop = Js_op.binop
36-
type int_op = Js_op.int_op
37-
type kind = Js_op.kind
3836
type property = Js_op.property
3937
type number = Js_op.number
4038
type ident_info = Js_op.ident_info
@@ -74,7 +72,6 @@ and exception_ident = ident
7472
and for_ident = ident
7573
and for_direction = Js_op.direction_flag
7674
and property_map = (property_name * expression) list
77-
and length_object = Js_op.length_object
7875
and delim = External_arg_spec.delim = DNone | DStarJ | DNoQuotes | DBackQuotes
7976

8077
and record_rest_field = {
@@ -83,7 +80,7 @@ and record_rest_field = {
8380
}
8481

8582
and expression_desc =
86-
| Length of expression * length_object
83+
| Length of expression
8784
| Is_null_or_undefined of expression (** where we use a trick [== null ] *)
8885
| String_append of expression * expression
8986
| Bool of bool (* js true/false*)
@@ -98,9 +95,6 @@ and expression_desc =
9895
| Seq of expression * expression
9996
| Cond of expression * expression * expression
10097
| Bin of binop * expression * expression
101-
(* [int_op] will guarantee return [int32] bits
102-
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *)
103-
(* | Int32_bin of int_op * expression * expression *)
10498
| FlatCall of expression * expression
10599
(* f.apply(null,args) -- Fully applied guaranteed
106100
TODO: once we know args's shape --
@@ -133,7 +127,7 @@ and expression_desc =
133127
All exported declarations have to be OCaml identifiers
134128
2. Javascript dot (need to be preserved/or using quote)
135129
*)
136-
| New of expression * expression list option (* TODO: option remove *)
130+
| New of expression * expression list
137131
| Var of vident
138132
| Fun of {
139133
is_method: bool;
@@ -151,15 +145,13 @@ and expression_desc =
151145
| Raw_js_code of Js_raw_info.t
152146
(* literally raw JS code
153147
*)
154-
| Array of expression list * mutable_flag
148+
| Array of expression list
155149
| Optional_block of expression * bool
156150
(* [true] means [identity] *)
157151
| Caml_block of expression list * mutable_flag * expression * tag_info
158152
(* The third argument is [tag] , forth is [tag_info] *)
159-
(* | Caml_uninitialized_obj of expression * expression *)
160153
(* [tag] and [size] tailed for [Obj.new_block] *)
161154
| Caml_block_tag of expression * string (* e.tag *)
162-
(* | Caml_block_set_length of expression * expression *)
163155
(* It will just fetch tag, to make it safe, when creating it,
164156
we need apply "|0", we don't do it in the
165157
last step since "|0" can potentially be optimized
@@ -334,17 +326,13 @@ and deps_program = {
334326
int_clause;
335327
string_clause;
336328
for_direction;
337-
(* exception_ident; *)
338-
for_direction;
339329
expression_desc;
340330
statement_desc;
341331
for_ident_expression;
342332
label;
343333
finish_ident_expression;
344334
property_map;
345-
length_object;
346335
record_rest_field;
347-
(* for_ident; *)
348336
required_modules;
349337
case_clause;
350338
|];

compiler/core/js_analyzer.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
105105
no_side_effect a && no_side_effect b
106106
| Is_null_or_undefined b -> no_side_effect b
107107
| Str _ -> true
108-
| Array (xs, _mutable_flag) | Caml_block (xs, _mutable_flag, _, _) ->
108+
| Array xs | Caml_block (xs, _, _, _) ->
109109
(* create [immutable] block,
110110
does not really mean that this opreation itself is [pure].
111111
@@ -119,7 +119,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
119119
| None -> true)
120120
&& Ext_list.for_all_snd kvs no_side_effect
121121
| String_append (a, b) | Seq (a, b) -> no_side_effect a && no_side_effect b
122-
| Length (e, _) | Caml_block_tag (e, _) | Typeof e -> no_side_effect e
122+
| Length e | Caml_block_tag (e, _) | Typeof e -> no_side_effect e
123123
| Bin (op, a, b) -> op <> Eq && no_side_effect a && no_side_effect b
124124
| Tagged_template (call_expr, strings, values) ->
125125
no_side_effect call_expr
@@ -311,7 +311,7 @@ let rev_toplevel_flatten block =
311311
| Array_index (a,b) -> is_constant a && is_constant b
312312
| Str (b,_) -> b
313313
| Number _ -> true (* Can be refined later *)
314-
| Array (xs,_mutable_flag) -> Ext_list.for_all xs is_constant
314+
| Array xs -> Ext_list.for_all xs is_constant
315315
| Caml_block(xs, Immutable, tag, _)
316316
-> Ext_list.for_all xs is_constant && is_constant tag
317317
| Bin (_op, a, b) ->

compiler/core/js_arr.ml

Lines changed: 0 additions & 29 deletions
This file was deleted.

compiler/core/js_arr.mli

Lines changed: 0 additions & 27 deletions
This file was deleted.

compiler/core/js_dump.ml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ let raw_snippet_exp_simple_enough (s : string) =
150150
*)
151151
let rec exp_need_paren ?(arrow = false) (e : J.expression) =
152152
match e.expression_desc with
153-
(* | Caml_uninitialized_obj _ *)
154153
| Call ({expression_desc = Raw_js_code _}, _, _) -> true
155154
| Raw_js_code {code_info = Exp _}
156155
| Fun _
@@ -754,8 +753,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
754753
P.paren_group f 0 (fun _ -> arguments cxt f (e :: el)))
755754
else (
756755
Curry_gen.pp_app_any f;
757-
P.paren_group f 0 (fun _ ->
758-
arguments cxt f [e; E.array Mutable el]))))
756+
P.paren_group f 0 (fun _ -> arguments cxt f [e; E.array el]))))
759757
| FlatCall (e, el) ->
760758
P.group f 0 (fun _ ->
761759
let cxt = expression ~level:15 cxt f e in
@@ -939,7 +937,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
939937
P.string f "+";
940938
P.space f;
941939
expression ~level:rght cxt f e2)
942-
| Array (el, _) -> (
940+
| Array el -> (
943941
(* TODO: simplify for singleton list *)
944942
match el with
945943
| [] | [_] -> P.bracket_group f 1 (fun _ -> array_element_list cxt f el)
@@ -955,11 +953,11 @@ and expression_desc cxt ~(level : int) f x : cxt =
955953
Ext_list.map_combine fields el (fun x ->
956954
Js_op.Lit (Ext_ident.convert x)) ))
957955
(*name convention of Record is slight different from modules*)
958-
| Caml_block (el, mutable_flag, _, Blk_record {fields}) ->
956+
| Caml_block (el, _, _, Blk_record {fields}) ->
959957
if
960958
Array.length fields <> 0
961959
&& Ext_array.for_alli fields (fun i (v, _) -> string_of_int i = v)
962-
then expression_desc cxt ~level f (Array (el, mutable_flag))
960+
then expression_desc cxt ~level f (Array el)
963961
else
964962
let fields =
965963
Ext_list.array_list_filter_map fields el (fun (f, opt) x ->
@@ -1050,8 +1048,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
10501048
| Caml_block (_, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested))
10511049
->
10521050
assert false
1053-
| Caml_block (el, mutable_flag, _tag, Blk_tuple) ->
1054-
expression_desc cxt ~level f (Array (el, mutable_flag))
1051+
| Caml_block (el, _, _tag, Blk_tuple) ->
1052+
expression_desc cxt ~level f (Array el)
10551053
| Caml_block_tag (e, tag) ->
10561054
P.group f 1 (fun _ ->
10571055
let cxt = expression ~level:15 cxt f e in
@@ -1072,23 +1070,20 @@ and expression_desc cxt ~(level : int) f x : cxt =
10721070
refer and export
10731071
*)
10741072
cxt)
1075-
| Length (e, _) ->
1073+
| Length e ->
10761074
(*Todo: check parens *)
10771075
P.cond_paren_group f (level > 15) (fun _ ->
10781076
let cxt = expression ~level:15 cxt f e in
10791077
P.string f L.dot;
10801078
P.string f L.length;
10811079
cxt)
1082-
| New (e, el) ->
1080+
| New (e, args) ->
10831081
P.cond_paren_group f (level > 15) (fun _ ->
10841082
P.group f 0 (fun _ ->
10851083
P.string f L.new_;
10861084
P.space f;
10871085
let cxt = expression ~level:16 cxt f e in
1088-
P.paren_group f 0 (fun _ ->
1089-
match el with
1090-
| Some el -> arguments cxt f el
1091-
| None -> cxt)))
1086+
P.paren_group f 0 (fun _ -> arguments cxt f args)))
10921087
| Cond (e, e1, e2) ->
10931088
let action () =
10941089
let cxt = expression ~level:3 cxt f e in
@@ -1200,8 +1195,8 @@ and print_jsx cxt ?(spread_props : J.expression option)
12001195
if n = "children" then
12011196
if fn_name = "jsxs" then
12021197
match e.J.expression_desc with
1203-
| J.Array (xs, _)
1204-
| J.Optional_block ({expression_desc = J.Array (xs, _)}, _) ->
1198+
| J.Array xs | J.Optional_block ({expression_desc = J.Array xs}, _)
1199+
->
12051200
Some xs
12061201
| _ -> Some [e]
12071202
else Some [e]

0 commit comments

Comments
 (0)