-
Notifications
You must be signed in to change notification settings - Fork 13
Labels
Description
This tool doesn't currently support dune's way of renaming modules to wrap libraries and currently only see the cmti files if the libraries are first unwrapped.
Steps to reproduce:
$ cat dune-project
(lang dune 2.0)
(package (name dead))
$ cat dune
(library (public_name dead) (modules lib_mod) (wrapped true))
(executable (public_name dead_bin) (modules dead_bin) (libraries dead))
$ cat lib_mod.ml
let dead () = print_endline "dead code"
let live () = print_endline "live code"
$ cat lib_mod.mli
val dead : unit -> unit
val live : unit -> unit
$ cat dead_bin.ml
let () = Dead.Lib_mod.live ()
(* let () = Lib_mod.live () *)
As-is (wrapped library), scanning the project leads nowhere, as if there was no dead code:
$ dune build
$ dead_code_analyzer _build/default/
Scanning files...
[DONE]
.> UNUSED EXPORTED VALUES:
=========================
Nothing else to report in this section
--------------------------------------------------------------------------------
.> UNUSED METHODS:
=================
Nothing else to report in this section
--------------------------------------------------------------------------------
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
====================================
Nothing else to report in this section
--------------------------------------------------------------------------------
But as soon as you turn (wrapped ...) to false and switch the commented code in dead_bin.ml, then the dead code is actually detected instantly:
$ dune build
$ dead_code_analyzer _build/default/
Scanning files...
[DONE]
.> UNUSED EXPORTED VALUES:
=========================
_build/default/lib_mod.mli:1: dead
Nothing else to report in this section
--------------------------------------------------------------------------------
.> UNUSED METHODS:
=================
Nothing else to report in this section
--------------------------------------------------------------------------------
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
====================================
Nothing else to report in this section
--------------------------------------------------------------------------------
Moved from #16 (comment)