Skip to content

Commit 11fd9e0

Browse files
committed
use iter instead of folder
count_collects is a good example showing the simplification
1 parent 9e2d0ec commit 11fd9e0

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

jscomp/core/js_pass_get_used.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,19 @@ let count_collects
5252
(* collect used status*)
5353
(stats : int Hash_ident.t)
5454
(* collect all def sites *)
55-
(defined_idents : J.variable_declaration Hash_ident.t) : Js_fold.fold
55+
(defined_idents : J.variable_declaration Hash_ident.t) : Js_iter.iter
5656
=
5757
object (self)
58-
inherit Js_fold.fold
59-
58+
inherit Js_iter.iter
6059
method! variable_declaration
6160
({ident; value ; property = _ ; ident_info = _} as v)
6261
=
6362
Hash_ident.add defined_idents ident v;
6463
match value with
65-
| None ->
66-
self
64+
| None -> ()
6765
| Some x
6866
-> self#expression x
69-
method! ident id = add_use stats id; self
70-
67+
method! ident id = add_use stats id
7168
end
7269

7370

@@ -76,5 +73,5 @@ let get_stats (program : J.program) : J.variable_declaration Hash_ident.t
7673
let stats : int Hash_ident.t = Hash_ident.create 83 in
7774
let defined_idents : J.variable_declaration Hash_ident.t = Hash_ident.create 83 in
7875
let my_export_set = program.export_set in
79-
let _ : Js_fold.fold = (count_collects stats defined_idents) #program program in
76+
(count_collects stats defined_idents) #program program;
8077
post_process_stats my_export_set defined_idents stats

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102774,22 +102774,19 @@ let count_collects
102774102774
(* collect used status*)
102775102775
(stats : int Hash_ident.t)
102776102776
(* collect all def sites *)
102777-
(defined_idents : J.variable_declaration Hash_ident.t) : Js_fold.fold
102777+
(defined_idents : J.variable_declaration Hash_ident.t) : Js_iter.iter
102778102778
=
102779102779
object (self)
102780-
inherit Js_fold.fold
102781-
102780+
inherit Js_iter.iter
102782102781
method! variable_declaration
102783102782
({ident; value ; property = _ ; ident_info = _} as v)
102784102783
=
102785102784
Hash_ident.add defined_idents ident v;
102786102785
match value with
102787-
| None ->
102788-
self
102786+
| None -> ()
102789102787
| Some x
102790102788
-> self#expression x
102791-
method! ident id = add_use stats id; self
102792-
102789+
method! ident id = add_use stats id
102793102790
end
102794102791

102795102792

@@ -102798,7 +102795,7 @@ let get_stats (program : J.program) : J.variable_declaration Hash_ident.t
102798102795
let stats : int Hash_ident.t = Hash_ident.create 83 in
102799102796
let defined_idents : J.variable_declaration Hash_ident.t = Hash_ident.create 83 in
102800102797
let my_export_set = program.export_set in
102801-
let _ : Js_fold.fold = (count_collects stats defined_idents) #program program in
102798+
(count_collects stats defined_idents) #program program;
102802102799
post_process_stats my_export_set defined_idents stats
102803102800

102804102801
end

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102774,22 +102774,19 @@ let count_collects
102774102774
(* collect used status*)
102775102775
(stats : int Hash_ident.t)
102776102776
(* collect all def sites *)
102777-
(defined_idents : J.variable_declaration Hash_ident.t) : Js_fold.fold
102777+
(defined_idents : J.variable_declaration Hash_ident.t) : Js_iter.iter
102778102778
=
102779102779
object (self)
102780-
inherit Js_fold.fold
102781-
102780+
inherit Js_iter.iter
102782102781
method! variable_declaration
102783102782
({ident; value ; property = _ ; ident_info = _} as v)
102784102783
=
102785102784
Hash_ident.add defined_idents ident v;
102786102785
match value with
102787-
| None ->
102788-
self
102786+
| None -> ()
102789102787
| Some x
102790102788
-> self#expression x
102791-
method! ident id = add_use stats id; self
102792-
102789+
method! ident id = add_use stats id
102793102790
end
102794102791

102795102792

@@ -102798,7 +102795,7 @@ let get_stats (program : J.program) : J.variable_declaration Hash_ident.t
102798102795
let stats : int Hash_ident.t = Hash_ident.create 83 in
102799102796
let defined_idents : J.variable_declaration Hash_ident.t = Hash_ident.create 83 in
102800102797
let my_export_set = program.export_set in
102801-
let _ : Js_fold.fold = (count_collects stats defined_idents) #program program in
102798+
(count_collects stats defined_idents) #program program;
102802102799
post_process_stats my_export_set defined_idents stats
102803102800

102804102801
end

lib/4.06.1/whole_compiler.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385256,22 +385256,19 @@ let count_collects
385256385256
(* collect used status*)
385257385257
(stats : int Hash_ident.t)
385258385258
(* collect all def sites *)
385259-
(defined_idents : J.variable_declaration Hash_ident.t) : Js_fold.fold
385259+
(defined_idents : J.variable_declaration Hash_ident.t) : Js_iter.iter
385260385260
=
385261385261
object (self)
385262-
inherit Js_fold.fold
385263-
385262+
inherit Js_iter.iter
385264385263
method! variable_declaration
385265385264
({ident; value ; property = _ ; ident_info = _} as v)
385266385265
=
385267385266
Hash_ident.add defined_idents ident v;
385268385267
match value with
385269-
| None ->
385270-
self
385268+
| None -> ()
385271385269
| Some x
385272385270
-> self#expression x
385273-
method! ident id = add_use stats id; self
385274-
385271+
method! ident id = add_use stats id
385275385272
end
385276385273

385277385274

@@ -385280,7 +385277,7 @@ let get_stats (program : J.program) : J.variable_declaration Hash_ident.t
385280385277
let stats : int Hash_ident.t = Hash_ident.create 83 in
385281385278
let defined_idents : J.variable_declaration Hash_ident.t = Hash_ident.create 83 in
385282385279
let my_export_set = program.export_set in
385283-
let _ : Js_fold.fold = (count_collects stats defined_idents) #program program in
385280+
(count_collects stats defined_idents) #program program;
385284385281
post_process_stats my_export_set defined_idents stats
385285385282

385286385283
end

0 commit comments

Comments
 (0)