Skip to content

Commit f0ad76b

Browse files
committed
[src] rename "end of analysis" values
+ `eom` is now `eof` (end of file) + `later` is now `at_eof` + `last` is `at_eocb` (end of codebase) + add comments for `eof` in `.mli`s
1 parent c833667 commit f0ad76b

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

src/deadArg.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ open Typedtree
1212

1313
open DeadCommon
1414

15-
let later = ref []
16-
let last = ref []
15+
let at_eof = ref []
16+
let at_eocb = ref []
1717

1818
let met = Hashtbl.create 512
1919

20-
let eom () =
21-
List.iter (fun f -> f ()) !later;
22-
later := [];
20+
let eof () =
21+
List.iter (fun f -> f ()) !at_eof;
22+
at_eof := [];
2323
Hashtbl.reset met
2424

25+
let eocb () =
26+
List.iter (fun f -> f ()) !at_eocb
27+
2528
let increment_count label count_tbl =
2629
let count = Hashtbl.find_opt count_tbl label |> Option.value ~default:0 in
2730
let count = count + 1 in
@@ -62,8 +65,8 @@ let deferrable_register_use label expr builddir loc last_loc count_tbl =
6265
(* TODO:
6366
* What does it mean to have a loc in a signature ?
6467
* When does it happen ? *)
65-
last := register_use :: !last
66-
else if !depth > 0 then later := register_use :: !later
68+
at_eocb := register_use :: !at_eocb
69+
else if !depth > 0 then at_eof := register_use :: !at_eof
6770
else register_use ()
6871
else register_use ()
6972

src/deadArg.mli

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@
99

1010
open Typedtree
1111

12-
val later : (unit -> unit) list ref
13-
(** Functions needing a location in the current file to be processed
14-
before being executed.
15-
It is known that this location will have been processed at the end of
16-
the binding.
17-
Needed because the Tast_mapper run through sequences from the end
18-
because tuples are built from right to left*)
12+
val at_eof : (unit -> unit) list ref
13+
(** Functions deferred to run at the end of the current file's analysis.
14+
They reaqire the analysis of future locations in the current file.
15+
It is known that these locations will have been processed at the end
16+
of the binding.
17+
Needed because the Tast_mapper runs through sequences from the end
18+
because tuples are built from right to left. *)
1919

20-
val last : (unit -> unit) list ref
21-
(** Functions needing a location out of the current file to be processed
22-
before being executed. *)
20+
val eof : unit -> unit
21+
(** To use at the end of a [.cmt]'s analysis:
22+
apply [at_eof] functions + reset internal state *)
23+
24+
val eocb : unit -> unit
25+
(** To use at the end of the codebase analysis:
26+
apply remaining deferred functions which required the analysis of future
27+
locations, their respective files.
28+
[eocb] = end of code base. *)
2329

24-
val eom : unit -> unit
25-
(** Self cleaning *)
2630

2731
val register_uses :
2832
Lexing.position -> (Asttypes.arg_label * expression option) list -> unit

src/deadCode.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ let rec treat_exp exp args =
7878

7979

8080
let value_binding super self x =
81-
let old_later = !DeadArg.later in
82-
DeadArg.later := [];
81+
let at_eof_saved = !DeadArg.at_eof in
82+
DeadArg.at_eof := [];
8383
incr depth;
8484
let open Asttypes in
8585
begin match x with
@@ -111,8 +111,8 @@ let value_binding super self x =
111111
end;
112112

113113
let r = super.Tast_mapper.value_binding self x in
114-
List.iter (fun f -> f()) !DeadArg.later;
115-
DeadArg.later := old_later;
114+
List.iter (fun f -> f()) !DeadArg.at_eof;
115+
DeadArg.at_eof := at_eof_saved;
116116
decr depth;
117117
r
118118

@@ -406,9 +406,9 @@ let clean references loc =
406406
if (fn.[String.length fn - 1] <> 'i' && Utils.unit fn = sourceunit) then
407407
LocHash.remove references loc
408408

409-
let eom loc_dep =
409+
let eof loc_dep =
410410
let state = State.get_current () in
411-
DeadArg.eom();
411+
DeadArg.eof();
412412
List.iter (assoc decs) loc_dep;
413413
List.iter (assoc DeadType.decs) !DeadType.dependencies;
414414
let sourcepath = State.File_infos.get_sourcepath state.State.file_infos in
@@ -422,8 +422,8 @@ let eom loc_dep =
422422
clean loc_dep;
423423
clean !DeadType.dependencies;
424424
end;
425-
VdNode.eom ();
426-
DeadObj.eom ();
425+
VdNode.eof ();
426+
DeadObj.eof ();
427427
DeadType.dependencies := [];
428428
Hashtbl.reset incl
429429

@@ -480,7 +480,7 @@ let rec load_file state fn =
480480
cmt_value_dependencies
481481
else []
482482
in
483-
eom loc_dep
483+
eof loc_dep
484484
| _ -> () (* todo: support partial_implementation? *)
485485
)
486486

@@ -500,7 +500,7 @@ let rec load_file state fn =
500500

501501
(* Prepare the list of opt_args for report *)
502502
let analyze_opt_args () =
503-
List.iter (fun f -> f ()) !DeadArg.last;
503+
DeadArg.eocb ();
504504
let all = ref [] in
505505
let tbl = Hashtbl.create 256 in
506506
let dec_loc loc = Hashtbl.mem main_files (Utils.unit loc.Lexing.pos_fname) in

src/deadCommon.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ module VdNode = struct
321321
end
322322
in loop (func loc) lab occur
323323

324-
let eom () =
324+
let eof () =
325325
let state = State.get_current () in
326326

327327
let sons =

src/deadObj.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let inheritances = Hashtbl.create 512 (* inheritance links loc-> l
2828

2929
let equals = Hashtbl.create 64
3030

31-
let later = ref []
31+
let at_eof = ref []
3232

3333
let last_class = ref Lexing.dummy_pos (* last class met *)
3434

@@ -160,7 +160,7 @@ let locate expr =
160160
in repr_exp expr locate
161161

162162

163-
let eom () =
163+
let eof () =
164164
Hashtbl.reset defined;
165165
last_class := Lexing.dummy_pos
166166

@@ -318,7 +318,7 @@ let class_field f =
318318
add_equal f.cf_loc.Location.loc_start cl_exp.cl_loc.Location.loc_start;
319319
let loc = get_loc path in
320320
let equal () = add_equal cl_exp.cl_loc.Location.loc_start (get_loc path) in (* for uses inside class def *)
321-
if loc == Lexing.dummy_pos then later := equal :: !later
321+
if loc == Lexing.dummy_pos then at_eof := equal :: !at_eof
322322
else equal ()
323323
end;
324324
List.iter (fun (s, _) -> update_overr false s) l
@@ -376,7 +376,7 @@ let coerce expr typ =
376376

377377
let prepare_report () =
378378

379-
List.iter (fun f -> f ()) !later;
379+
List.iter (fun f -> f ()) !at_eof;
380380

381381
let apply_self meth loc1 loc2 =
382382
let loc1 = repr_loc loc1

src/deadObj.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ val coerce:
6060
expression -> Types.type_expr -> unit
6161

6262

63-
val eom :
64-
unit -> unit
63+
val eof : unit -> unit
64+
(** For use at the end of a [.cmt]'s analysis: reset internal state *)
6565

6666

6767
val report :

0 commit comments

Comments
 (0)