Find and remove dead code and unused APIs in OCaml projects
1(** {1 File caching}
2
3 Efficient caching of file contents for prune analysis operations. Files are
4 read once and cached as line arrays to minimize I/O operations during symbol
5 analysis and removal operations. *)
6
7type t
8(** The cache type. Handles file content caching and modification tracking. *)
9
10val pp : Format.formatter -> t -> unit
11(** [pp fmt t] pretty-prints cache information (file count and modification
12 status). *)
13
14(** {2 Cache operations} *)
15
16val v : unit -> t
17(** [v ()] creates a new empty cache. *)
18
19val clear : t -> unit
20(** [clear cache] removes all entries from the cache. *)
21
22(** {2 File operations} *)
23
24val load : t -> string -> (unit, [ `Msg of string ]) result
25(** [load cache file] loads a file into the cache if not already present. *)
26
27val line : t -> string -> int -> string option
28(** [line cache file line_num] returns line [line_num] (1-indexed) from [file].
29 Returns [None] if the file is not loaded or line number is out of bounds. *)
30
31val replace_line : t -> string -> int -> string -> unit
32(** [replace_line cache file line_num new_content] replaces line [line_num]
33 (1-indexed) in [file] with [new_content]. Does nothing if file not loaded.
34*)
35
36val clear_line : t -> string -> int -> unit
37(** [clear_line cache file line_num] replaces line [line_num] with an empty
38 string. *)
39
40val line_count : t -> string -> int option
41(** [line_count cache file] returns the number of lines in [file], or [None] if
42 the file is not loaded. *)
43
44val has_changes : t -> string -> bool
45(** [has_changes cache file] returns true if [file] has pending changes to be
46 written. *)
47
48val count_lines_removed : t -> int
49(** [count_lines_removed cache] returns the total number of lines that were
50 cleared across all files. *)
51
52val is_file_empty : t -> string -> bool
53(** [is_file_empty cache file] returns true if the file contains only blank
54 lines. *)
55
56(** {2 AST caching} *)
57
58type ast_entry =
59 | Implementation of Parsetree.structure
60 | Interface of Parsetree.signature (** AST representation for cached files *)
61
62val ast : t -> string -> (ast_entry, [ `Msg of string ]) result
63(** [ast cache file] returns the parsed AST for [file], parsing and caching it
64 if necessary. Returns an error if the file is not loaded or parsing fails.
65*)
66
67(** {2 File content access} *)
68
69val file_content : t -> string -> string option
70(** [file_content cache file] returns the current content of [file] from cache
71 as a single string. Returns [None] if the file is not loaded. *)
72
73val write : t -> string -> (unit, [ `Msg of string ]) result
74(** [write cache file] writes the cached content of [file] to disk. Returns an
75 error if the file is not loaded or if the write fails. *)