Dead-code analyzer for OCaml
The tool assumes that .mli files are compiled with -keep-locs (activated by default) and .ml files with -bin-annot. Tracked elements of code are collected by reading .cmi and .cmt files. Uses of such elements are collected by reading typed trees from .cmt files
This tool scans a compiled OCaml project and reports various warnings about suspicious code:
-
Exported values never used. The declaration can be dropped from the interface, and then from the implementation if there is no internal use -- which will be reported by standard OCaml warnings.
For more information, see the Exported values documentation. -
Record fields and variant constructors never used. They can be dropped from the type definition and then the compiler will report the affected locations.
For more information, see the Constructors/Record fields documentation. -
Exported public methods never used. They can be dropped from the class/object.
For more information, see the Methods documentation. -
Optional arguments for which either all call sites or none of them provide a value (other than
None). They can be made mandatory or dropped.
For more information, see the Optional arguments documentation. -
Other stylistic issues:
- patterns matching a value of type
unitwhich are not()(typically,_or a variable); - let-binding to unit
let () = ... in ...(it's usually better to use sequencing); - let-binding of the form
let x = ... in x(the binding is useless); - optional argument in an argument's type:
val f: ... -> (... -> ?_:_ -> ...) -> ...
For more information, see the Coding style documentation.
- patterns matching a value of type
For more information, see the User documentation
- Currently tested and working on OCaml 5.2
- dune >= 3.20
opam install dead_code_analyzer
- Download the sources.
- Build by running
make - Run the
dead_code_analyzerlocated in_build/install/default/bin/
dead_code_analyzer <options> <path>
The given paths can be files and directories.
For more information about the usage, use the -help option, or see the
Usage documentation.
make check runs each subset of the tests sequentially. In case of success,
they all run. Otherwise it stops at the first failing one and prints the diff
between the expected results and the current results.
To run a specific subset of the tests, run make -C check <subset>.
To get statistics about passing/failing tests run make -C check stats.
For each subset of the tests executed, a file check/<subset>.out is generated.
It contains the output of running the dead_code_analyzer on the tests with
annotations on failures:
Should not be detectedfor false positivesNot detectedfor false negatives
You are welcome to clone this repository, open issues and send us back pull requests.
Read CONTRIBUTING.md at the root of this directory for more information on how to contribute.
Tracking the optional arguments uses may consume a lot of memory.
Tracking the methods uses may consume a lot of memory.
For more limitations, see each report section documentation.
Source code is distributed under the conditions stated in file License
This project was initiated by LexiFi (http://www.lexifi.com) and is part of the SecurOCaml project.
Contact: alain.frisch@lexifi.com