soenkehahn / dead-code-detection

BSD 3-Clause "New" or "Revised" License
25 stars 7 forks source link

Two questions not adressed by --help or readme.md #16

Open metaleap opened 7 years ago

metaleap commented 7 years ago

First, does dead-code-detection find stuff that GHC's -Wall (eg. -Wunused-local-binds, ...) doesn't?

Secondly, this is the current --help text:

dead-code-detection [OPTIONS]
  -i STRING (multiple possible)  --source-dirs=STRING (multiple possible)
  -e STRING (multiple possible)  --ignore=STRING (multiple possible)
                                 --root=STRING (multiple possible)
                                 --version
                                 --include-underscore-names
  -h                             --help                                    show help and exit

I get what -i is (I think, ie. usually src), and reckon --source-dirs is an alias for same. What's -e though, same as --ignore? What gets ignored, identifier names? Module names? Source files? --root is prepended to each source-dir to find specified modules? Even after --help I'm left guessing as of now ;) thanks!

soenkehahn commented 7 years ago

Sorry for the delay.

First, does dead-code-detection find stuff that GHC's -Wall (eg. -Wunused-local-binds, ...) doesn't?

Yes. ghc only reasons about usage of identifiers on a module-by-module basis. So if you have an identifier that is declared in a module and not exported, ghc will warn you, if it isn't used in that module. If you have an identifier that is exported, then ghc will just assume that it might be used in another module and will not warn you, regardless of whether it's actually used in another module or not.

dead-code-detection actually looks at all modules in the source directories and finds identifiers that are globally unused.

For your other questions: Yes, your guesses about -i and --source-dirs are right. -e is an alias for --ignore and allows to pass file names that the tool will then not look at. --root has to be used to specify the entry point(s) of your project and has to be given as module names. So for executables it's usually --root Main. Everything that is accessible -- directly or transitively -- from your root modules, will be considered live code, everything else is dead.

We should

I'll keep this issue open for this.