Add a plugin phase that allows users to modify HsSyn before the desugarer
I'm currently playing around with a little project that attempts to replicate py.test. For context about py.test, see https://docs.pytest.org/en/latest/example/reportingdemo.html#tbreportdemo, but essentially it's a Python library that provides an assert :: Bool -> IO () function, with the magic that if the assertion fails, it shows you some context about the Bool expression:
def test_simple(self):
def f():
return 42
def g():
return 43
> assert f() == g()
E assert 42 == 43
For example, shows that f() evaluated to 42.
I'd like to do something like this for Haskell, and a GHC plugin seemed like the right place to do this. I first wrote a core-to-core plugin (https://github.com/ocharles/assert-explainer/blob/e6a669680cd214f23a4213e2f945f4468998fb1d/plugin/AssertExplainer.hs) which finds free variables and and attempts to Show them. This works, but I'd like to do more.
As an example of something I'd like to do, I would like to let my users write assert (and [x > 0 | x <- [-1, 0]). This is a failing assertion, and I would like to show a kind of evaluation trace, something like
and [x > 0 | x <- [-1, 0] = and [False, False] = False
To do this, I really need access to HsSyn, not CoreExpr. Template Haskell won't do, because I don't know what I can Show - I really need access to the type checker as well.
A plugin that fires right before the desugarer would be really nice for this kind of task.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |