[GHC] #14443: Add a plugin phase that allows users to modify HsSyn before the desugarer

GHC ghc-devs at haskell.org
Thu Nov 9 15:42:25 UTC 2017


#14443: Add a plugin phase that allows users to modify HsSyn before the desugarer
-------------------------------------+-------------------------------------
           Reporter:  ocharles       |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14443>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list