• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Haskell
  • License
    BSD 3-Clause "New...
  • Created about 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A re-implementation of weeder using HIE files

Weeder

Weeder is an application to perform whole-program dead-code analysis. Dead code is code that is written, but never reachable from any other code. Over the lifetime of a project, this happens as code is added and removed, and leftover code is never cleaned up. While GHC has warnings to detect dead code is a single module, these warnings don't extend across module boundaries - this is where Weeder comes in.

Weeder uses HIE files produced by GHC - these files can be thought of as source code that has been enhanced by GHC, adding full symbol resolution and type information. Weeder builds a dependency graph from these files to understand how code interacts. Once all analysis is done, Weeder performs a traversal of this graph from a set of roots (e.g., your main function), and determines which code is reachable and which code is dead.

Using Weeder

Preparing Your Code for Weeder

To use Weeder, you will need to generate .hie files from your source code.

Cabal

If you use Cabal, this is easily done by adding one line to your cabal.project.local file:

package *
  ghc-options: -fwrite-ide-info

Once this has been added, perform a full rebuild of your project:

cabal clean
cabal build all

Stack

If you use stack, add the following to your stack.yaml:

ghc-options:
  "$locals": -fwrite-ide-info

and rebuild:

stack clean
stack build

Calling Weeder

To call Weeder, you first need to provide a configuration file, weeder.dhall. Weeder uses Dhall as its configuration format, and configuration files have the type:

{ roots : List Text, type-class-roots : Bool }

roots is a list of regular expressions of symbols that are considered as alive. If you're building an executable, the pattern ^Main.main$ is a good starting point - specifying that main is a root. Weeder currently doesn't add all exported functions as roots automatically but in many cases main from a test suite could be a good workaround for that

type-class-roots configures whether or not Weeder should consider anything in a type class instance as a root. Weeder is currently unable to add dependency edges into type class instances, and without this flag may produce false positives. It's recommended to initially set this to True:

{ roots = [ "^Main.main$" ], type-class-roots = True }

Now invoke the weeder executable, and - if your project has weeds - you will see something like the following:

$ weeder
src/Dhall/TH.hs:187: toDeclaration
src/Dhall/TH.hs:196: toNestedHaskellType

… which indicates the location of two unused symbols. (Please note these warnings are just for demonstration and not necessarily weeds in the Dhall project).

Tips

  • You may want to add ^Paths_.* to the roots in weeder.dhall to ignore the Paths_packageName module automatically generated by Cabal.

Limitations

Weeder currently has a few limitations:

Type Class Instances

Weeder is not currently able to analyse whether a type class instance is used. For this reason, Weeder adds all symbols referenced to from a type class instance to the root set, keeping this code alive. In short, this means Weeder might not detect dead code if it's used from a type class instance which is never actually needed.

You can toggle whether Weeder consider type class instances as roots with the type-class-roots configuration option.

Template Haskell

Weeder is currently unable to parse the result of a Template Haskell splice. If some Template Haskell code refers to other source code, this dependency won't be tracked by Weeder, and thus Weeder might end up with false positives.

More Repositories

1

papers

A Git annex repository of papers
696
star
2

zero-to-quake-3

Implementing Quake 3 in Haskell & Vulkan
Haskell
162
star
3

engine.io

A Haskell server implementation of the Engine.IO and Socket.IO (1.0) protocols
Haskell
149
star
4

micro-ci

A tiny CI server built around GitHub and Nix
Haskell
132
star
5

netwire-classics

Classic games recreated in netwire
Haskell
95
star
6

what-it-do

Automatically trace all (showable) binds in do expressions
Haskell
84
star
7

hadoom

A little Doom-like 2.5 game engine
Haskell
82
star
8

Francium

A small web programming library on top of reactive-banana and virtual-dom
HTML
79
star
9

blog

The contents of ocharles.org.uk/blog
Haskell
66
star
10

effect-zoo

Comparing Haskell effect systems for ergonomics and speed
Haskell
65
star
11

assert-explainer

Py.test style assertions in Haskell
Haskell
65
star
12

dhallql

Can we write a querying language with Dhall? Let's find out!
64
star
13

logging-effect

A very general logging effect for Haskell
Haskell
58
star
14

plhaskell

Write PostgreSQL functions in Haskell
Haskell
54
star
15

pandoc-live

Automatically refresh Pandoc documents in your web browser
JavaScript
51
star
16

hlint-source-plugin

Run HLint as part of normal compilation
Haskell
47
star
17

BookBrainz

MusicBrainz for books? Why not!
Haskell
35
star
18

hs-quake-3

Quake 3 map viewer written in Haskell
Haskell
34
star
19

digestive-functors-aeson

Run digestive-functors against a JSON document
Haskell
34
star
20

virtual-dom

Haskell (GHCJS) bindings to the virtual-dom project
Haskell
26
star
21

dhall-build

Drive the Nix build system using the Dhall configuration language
Haskell
26
star
22

nix-build-cache

Extends stdenv.mkDerivation based builds with a distributed build cache on Amazon S3.
Nix
24
star
23

transformers-eff

An approach to managing composable effects, ala mtl/transformers/extensible-effects/Eff
Haskell
24
star
24

hsfmt

A Haskell code formatter using prettyprinter and the GHC API
Haskell
24
star
25

libsystemd-journal

Haskell bindings to libsystemd-journal
Haskell
21
star
26

rio-effect

An effect system similar to mtl with explicit dictionary passing.
Haskell
17
star
27

haskell-opentracing

Haskell libraries for OpenTracing.io
Haskell
16
star
28

snaplet-oauth2

OAuth 2 authentication for Snap applications
Haskell
14
star
29

opaleye-tf

An alternative interface to Opaleye, built around type families
Haskell
13
star
30

Elasticsearch

Haskell API to elasticsearch's REST interface
Haskell
12
star
31

tasty-rerun

Rerun previous test suite runs to run only failing tests
Haskell
12
star
32

language-postgresql

A PostgreSQL AST/parser for Haskell
Haskell
11
star
33

prometheus-effect

Yet another Haskell Prometheus client
Haskell
11
star
34

ocharles.org.uk--Getting-Started-with-Netwire-and-SDL

Code to accompany my blog post "Getting Started with Netwire and SDL"
Haskell
10
star
35

listenbrainz-client

A client to the ListenBrainz project
Haskell
10
star
36

exhaustive

Compile time checks that a computation considers producing data through all possible constructors
Haskell
10
star
37

dhall-agda

Dhall, formalised in Agda
10
star
38

json-assertions

Test that your (Aeson) JSON encoding matches your expectation
Haskell
8
star
39

snap-cors

Add CORS headers to Snap applications
Nix
8
star
40

excursions

A single collection of various experiments before they turn into more polished work.
Haskell
8
star
41

hydra-continuous-deployment-tutorial

Nix
8
star
42

tasty-ant-xml

A tasty ingredient to output test results in XML, using the Ant schema. This XML can be consumed by the Jenkins continuous integration framework.
Haskell
8
star
43

diff-drv

Calculate the differences between two Nix .drvs
Nix
7
star
44

Orgdex

An org-mode file indexer/search tool
Haskell
7
star
45

dotcharles

My dotfiles
Nix
6
star
46

pipes-postgresql-simple

A pipes wrapper for postgresql-simple
Haskell
6
star
47

snaplet-socketio

Communicate with Socket.IO clients as part of a Snap website
Haskell
6
star
48

ekg-carbon

An EKG backend to send statistics to Carbon (part of Graphite monitoring tools)
Haskell
6
star
49

diff3

3-way diff algorithm for Haskell
Haskell
6
star
50

ekg-bosun

Send Haskell EKG metrics to Bosun servers
Haskell
6
star
51

network-carbon

A Haskell implementation of the Carbon protocol (part of the Graphite monitoring tools)
Haskell
5
star
52

reactive-banana-gtk

High-level bindings using reactive-banana to GTK3
Haskell
5
star
53

fused-effects-backpack

5
star
54

SSAO-example

A demonstration of screen-space ambient occlusion using OpenGL & Haskell
Haskell
5
star
55

mb-collector

A command line tool to add media files to your MusicBrainz collection
Perl
4
star
56

pipes-tar

A Haskell library for streaming the contents of tar files
Haskell
4
star
57

Xapian-Haskell

A FFI to Xapian for Haskell
Haskell
4
star
58

haskell-anki-decks

A collection of decks for learning various bits about Haskell and Haskell libraries.
4
star
59

OCharles-Blog-Factories

Accompanying code to my "Implement factories" article
Perl
3
star
60

Catalyst-View-HTML-Zoom

Catalyst templating on rollerskates. Woosh!
Perl
3
star
61

Web-MusicBrainz

Haskell implementation of the MusicBrainz API
Haskell
3
star
62

CatalystX-Profile

Profile Catalyst applications with Devel::NYTProf
Perl
3
star
63

netwire-platformer

A platformer game in Netwire 5
Haskell
3
star
64

varnish-cache-invalidation

This project contains my prototype for doing Varnish cache invalidation with RabbitMQ and pg_amqp
Haskell
3
star
65

dhall.js

Work with Dhall values in JavaScript
JavaScript
3
star
66

dot-files

Lua
3
star
67

musicbrainz-rewrite

A rewrite of MusicBrainz using DBIx::Class, Moose, Catalyst, and various other technologies
Perl
3
star
68

algebraic-mtl

A variation of the mtl, where type classes only contain algebraic effects/effect constructors
Haskell
3
star
69

Raskell

Community ratings for Hackage, the Haskell package database
Haskell
3
star
70

ant-plus

Haskell ANT+ bindings
Haskell
3
star
71

snap-error-collector

Collect errors from Snap applications and periodically flush them (via email, etc)
Haskell
3
star
72

Perl-Conditions

Implementing Lisp style conditions and restarts in Perl 5
Perl
2
star
73

Perlanet-DBIx-Class

A Perlanet that "renders" to a DBIx::Class database, and stores all feeds and posts there
Perl
2
star
74

reactive-html

A small API for building reactive web applications with reactive-banana & GHCJS
Haskell
2
star
75

test-xml-element

Test the properties of a single XML element
Perl
2
star
76

VotingGame

A little voting game for triaging our MusicBrainz bug tracker
Haskell
2
star
77

prometheus-push

Push prometheus-client metrics to a push gateway
Haskell
2
star
78

nes-playground

Playground for my work on the New Edit System. Mostly pure PG SQL.
2
star
79

MooseX-Types-DBIx-Class

MooseX::Types for DBIx::Class
Perl
2
star
80

Test-Magpie

Spying test doubles, just like Mockito
Perl
2
star
81

Slothmarks

A REST server like delicious (motivation for Sloth)
Perl
2
star
82

can-google-count

Scripts for my paper "Can Google Count?"
Perl
2
star
83

hedgehog-scenarios

A collection of test scenarios we'd like to be able to express in Hedgehog
Haskell
2
star
84

monadplus

Generalized filter combinators
Haskell
2
star
85

storable-sop

A generic implementation of Storable using the machinery provided by generics-sop
Haskell
1
star
86

Sloth

A Plack backed REST framework
Perl
1
star
87

monad-yield

Just playing with some ideas of type class based streaming. Don't expect much atm!
Haskell
1
star
88

Test-Mock

A mocking framework for Perl inspired by JMock
Perl
1
star
89

hydra-ocharles-projects

My Hydra configuration to build all of my own libraries
Nix
1
star
90

dhall-doc

Document your Dhall types
Haskell
1
star
91

snaplet-ekg

A Snap Snaplet to add Ekg monitor to your web application
Haskell
1
star
92

Fey-SQL-Pg

PostgreSQL specific extensions for Fey
Perl
1
star
93

Data-TreeValidator

Easy validation and transformation of tree structures
Perl
1
star
94

MBChatLogger-index

A seach indexer for MBChatLogger's RDF output
Haskell
1
star
95

pipes-crypto

Cryptographic pipes
Haskell
1
star
96

SQL-Abstract-Plugin-InsertReturning

Adds 'RETURNING' support to SQL::Abstract->insert
Perl
1
star
97

SPOJ-solutions

My solutions to SPOJ challenges (spoilers!)
Common Lisp
1
star
98

musicbrainz-server-database-only

MusicBrainz database import/replication code
Perl
1
star
99

agda-nixfmt

A pretty printer for Nix expressions, written in Agda because I'm a masochist
Agda
1
star
100

reactive-banana-fireworks-benchmark

A benchmark of particle physics (firework sparks) for reactive-banana
Haskell
1
star