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

#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

#14443: Add a plugin phase that allows users to modify HsSyn before the desugarer -------------------------------------+------------------------------------- Reporter: ocharles | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Shayan-Najd): That's similar to what [https://ghc.haskell.org/trac/ghc/wiki/NativeMetaprogramming| native metaprogramming] would eventually allow you to do. Meanwhile, can't you already do this with Template Haskell (with a bit of more syntactic noise)? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14443#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14443: Add a plugin phase that allows users to modify HsSyn before the desugarer -------------------------------------+------------------------------------- Reporter: ocharles | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ocharles):
Meanwhile, can't you already do this with Template Haskell (with a bit of more syntactic noise)?
I don't believe I can, as I need access to the type checker to see which things I can `Show`. Thanks for the link to Native Metaprogramming, I'll have a read. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14443#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14443: Add a plugin phase that allows users to modify HsSyn before the desugarer -------------------------------------+------------------------------------- Reporter: ocharles | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #14709 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * related: => #14709 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14443#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC