Add a flag to enable inferring HasCallStack constraints
GHC is careful to not infer a HasCallStack constraint for a function, because the user didn't ask for one, it would complicate the type, and because it would incur some runtime overhead. I think this is the right default, but it can make debugging exceptions tedious as you have to manually add HasCallStack constraints to the entire chain of functions in the stack. I sometimes use CPP to give myself a flag to toggle the constraints, but I'd rather not have to resort to CPP.
Instead, it would be nice if GHC supported a -finfer-hascallstack flag (off by default) that would simply generalize over the HasCallStack constraints rather than defaulting them. Then, if my program blows up I can simply recompile with -finfer-hascallstack and get a more informative trace. No manual editing, no preparation with CPP, easy!
Furthermore, if we had such a flag, it might be nice to enable it by default in ghci. The two prime concerns are
- Complicating type signatures. But
:tsolves the HasCallStack constraint before printing the type, so this is only a concern if you use:i. - Runtime overhead. I don't think this is a valid concern in ghci.
I think this would be a nice and simple improvement to the debugging experience.
The downside is that even with -finfer-hascallstack you would not get full call-stacks for functions in an imported module that was compiled normally. So this would not help with e.g. partial functions in base. (It would be really nice to find a solution to this that doesn't involve building modules in multiple ways..)
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |