@@ -46,7 +46,7 @@ module E = Js_exp_make
46
46
TODO: Ident Hashtbl could be improved,
47
47
since in this case it can not be global?
48
48
49
- *)
49
+ *)
50
50
let count_collects () =
51
51
object (self )
52
52
inherit Js_fold. fold as super
@@ -69,13 +69,12 @@ let count_collects () =
69
69
method! variable_declaration
70
70
({ident; value ; property ; ident_info } as v)
71
71
=
72
- Ident_hashtbl. add defined_idents ident v;
73
- match value with
74
- | None
75
- ->
76
- self
77
- | Some x
78
- -> self#expression x
72
+ Ident_hashtbl. add defined_idents ident v;
73
+ match value with
74
+ | None ->
75
+ self
76
+ | Some x
77
+ -> self#expression x
79
78
method! ident id = self#add_use id; self
80
79
method get_stats =
81
80
Ident_hashtbl. iter (fun ident (v : J.variable_declaration ) ->
@@ -85,16 +84,15 @@ let count_collects () =
85
84
let pure =
86
85
match v.value with
87
86
| None -> false (* can not happen *)
88
- | Some x -> Js_analyzer. no_side_effect_expression x
89
- in
87
+ | Some x -> Js_analyzer. no_side_effect_expression x in
90
88
match Ident_hashtbl. find_opt stats ident with
91
- | None ->
89
+ | None ->
90
+ Js_op_util. update_used_stats v.ident_info
91
+ (if pure then Dead_pure else Dead_non_pure )
92
+ | Some num ->
93
+ if ! num = 1 then
92
94
Js_op_util. update_used_stats v.ident_info
93
- (if pure then Dead_pure else Dead_non_pure )
94
- | Some num ->
95
- if ! num = 1 then
96
- Js_op_util. update_used_stats v.ident_info
97
- (if pure then Once_pure else Used )
95
+ (if pure then Once_pure else Used )
98
96
) defined_idents; defined_idents
99
97
end
100
98
@@ -113,29 +111,29 @@ let get_stats program
113
111
*)
114
112
115
113
(* * There is a side effect when traversing dead code, since
116
- we assume that substitue a node would mark a node as dead node,
117
-
114
+ we assume that substitue a node would mark a node as dead node,
115
+
118
116
so if we traverse a dead node, this would get a wrong result.
119
- it does happen in such scenario
120
- {[
121
- let generic_basename is_dir_sep current_dir_name name =
122
- let rec find_end n =
123
- if n < 0 then String.sub name 0 1
124
- else if is_dir_sep name n then find_end (n - 1)
125
- else find_beg n (n + 1)
126
- and find_beg n p =
127
- if n < 0 then String.sub name 0 p
128
- else if is_dir_sep name n then String.sub name (n + 1) (p - n - 1)
129
- else find_beg (n - 1) p
130
- in
131
- if name = ""
132
- then current_dir_name
133
- else find_end (String.length name - 1)
134
- ]}
135
- [find_beg] can potentially be expanded in [find_end] and in [find_end]'s expansion,
136
- if the order is not correct, or even worse, only the wrong one [find_beg] in [find_end] get expanded
137
- (when we forget to recursive apply), then some code non-dead [find_beg] will be marked as dead,
138
- while it is still called
117
+ it does happen in such scenario
118
+ {[
119
+ let generic_basename is_dir_sep current_dir_name name =
120
+ let rec find_end n =
121
+ if n < 0 then String.sub name 0 1
122
+ else if is_dir_sep name n then find_end (n - 1)
123
+ else find_beg n (n + 1)
124
+ and find_beg n p =
125
+ if n < 0 then String.sub name 0 p
126
+ else if is_dir_sep name n then String.sub name (n + 1) (p - n - 1)
127
+ else find_beg (n - 1) p
128
+ in
129
+ if name = ""
130
+ then current_dir_name
131
+ else find_end (String.length name - 1)
132
+ ]}
133
+ [find_beg] can potentially be expanded in [find_end] and in [find_end]'s expansion,
134
+ if the order is not correct, or even worse, only the wrong one [find_beg] in [find_end] get expanded
135
+ (when we forget to recursive apply), then some code non-dead [find_beg] will be marked as dead,
136
+ while it is still called
139
137
*)
140
138
let subst name export_set stats =
141
139
object (self )
@@ -192,29 +190,29 @@ let subst name export_set stats =
192
190
{expression_desc =
193
191
Call ({expression_desc = Var (Id id)},args,_info)}} }
194
192
as st
195
- :: rest
193
+ :: rest
196
194
->
197
195
begin match Ident_hashtbl. find_opt stats id with
198
196
199
197
| Some ({ value =
200
- Some {expression_desc = Fun (false , params, block, _env) ; comment = _};
201
- (* TODO: don't inline method tail call yet,
202
- [this] semantics are weird
203
- *)
204
- property = (Alias | StrictOpt | Strict );
205
- ident_info = {used_stats = Once_pure };
206
- ident = _
207
- } as v)
198
+ Some {expression_desc = Fun (false , params, block, _env) ; comment = _};
199
+ (* TODO: don't inline method tail call yet,
200
+ [this] semantics are weird
201
+ *)
202
+ property = (Alias | StrictOpt | Strict );
203
+ ident_info = {used_stats = Once_pure };
204
+ ident = _
205
+ } as v)
208
206
when Ext_list. same_length params args
209
207
->
210
208
(* Ext_log.dwarn __LOC__ "%s is dead \n %s " id.name *)
211
209
(* (Js_dump.string_of_block [st]); *)
212
210
Js_op_util. update_used_stats v.ident_info Dead_pure ;
213
211
let block =
214
212
Ext_list. fold_right2
215
- params args ( self#block block) (* see #278 before changes*)
216
- (fun param arg acc ->
217
- S. define_variable ~kind: Variable param arg :: acc)
213
+ params args ( self#block block) (* see #278 before changes*)
214
+ (fun param arg acc ->
215
+ S. define_variable ~kind: Variable param arg :: acc)
218
216
in
219
217
(* Mark a function as dead means it will never be scanned,
220
218
here we inline the function
0 commit comments