Tracking down instances from use-sites

Christopher Done chrisdone at
Tue Jun 26 15:40:36 UTC 2018

Hi all,

Given a TypecheckedModule, what's the most direct way given a Var
expression retrieved from the AST, to determine:

1) that it's a class method e.g. `read`
2) that it's a generic call (no instance chosen) e.g. `Read a => a -> String`
3) or if it's a resolved instance, then which instance is it and which
package, module and declaration is that defined in?

Starting with this file that has a TypecheckedModule in it:

I presume at this point that instance resolution has taken place. I'm
not sure that dictionaries or chosen instances are inserted into the
AST, or whether just the resolved types are inserted e.g. `Int ->
String`, where I want e.g. `Read Int`, which might lead me to finding
the matching instance from an InstEnv or so.

I'd like to do some analyses of Haskell codebases, and the fact that
calls to class methods are opaque is a bit of a road-blocker. Any
handy tips? Prior work?

It'd be neat in tooling to just hit a goto-definition key on `read`
and be taken to the instance implementation rather than the class

Also, listing all functions that use throw# or functions defined in
terms of throw# or FFI calls would be helpful, especially for doing
audits. If I could immediately list all partial functions in a
project, then list all call-sites, it would be a very convenient way
when doing an audit to see whether partial functions (such as head)
are used with the proper preconditions or not.

Any tips appreciated,


More information about the ghc-devs mailing list