
Ben, Thanks for the in-depth elaboration of what Mathew/Simon were describing! It seems within reach!
Of course, in the case that you have a concrete dictionary you *also* want to know the source location of the instance declaration from which it arose. I'm afraid this may be quite challenging as this isn't information we currently keep. Currently interface files don't really keep any information that might be useful to IDE tooling users. It's possible that we could add such information, although it's unclear exactly what this would look like. It would be great to hear more from tooling users regarding what information they would like to see.
Indeed, not having the exact source location was a stretch, I didn't have high hopes for that. However, the package and module is actually useful. Regarding that, I did find the following field: -- | @is_dfun_name = idName . is_dfun@. -- -- We use 'is_dfun_name' for the visibility check, -- 'instIsVisible', which needs to know the 'Module' which the -- dictionary is defined in. However, we cannot use the 'Module' -- attached to 'is_dfun' since doing so would mean we would -- potentially pull in an entire interface file unnecessarily. -- This was the cause of #12367. , is_dfun_name :: Name So it seems like I could use the Name to get a Module which contains a UnitId (package and version) and ModuleName. If I've already generated the right metadata for that package and module, then I can do the mapping.
Also relevant here is the HIE file GSoC project [1] being worked on this summer of Zubin Duggal (CC'd).
I think this would be a good use-case for that.
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.
This may be non-trivial; you may be able to get something along these lines out of the strictness signature present in IdInfo. However, I suspect this will be a bit fragile (e.g. we don't even run demand analysis with -O0 IIRC).
I was going to start with a very naive approach of creating a dependency graph merely based on presence in a declaration, not on use. E.g. foo = if False then head [] else 123 would still be flagged up as partial, even though upon inspection it isn't. But it uses `head`, so it should arouse suspicion. I'd want to review it myself and determine that it's safe and then mark it safe. In the least, I might mark such code as having potential for bugs. Cheers!