[GHC] #14474: reify RHS of "value" variable

#14474: reify RHS of "value" variable -------------------------------------+------------------------------------- Reporter: dailectic | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Template | Version: 8.2.1 Haskell | 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: -------------------------------------+------------------------------------- According to the [https://hackage.haskell.org/package/template- haskell-2.12.0.0/docs/Language-Haskell-TH-Syntax.html#t:Info documentation], when reifying value variables "returning the RHS has not yet been implemented because of lack of interest". I'd like to formally request interest since I don't see a ticket here (may have missed it). My motivating example is to make source available for documentation and better error messages. Something like: {{{#!hs printSource :: Name -> Q Exp printSource n = do VarI _ _ (Just dec) <- reify n lift $ pprint dec foo x = x * 2 fooSource = $(printSource 'foo) -- === "\x_0 -> x_0 GHC.Num.* 2" }}} How significant of a change is this? I could take a pass at it if pointed to the relevant bits, having not contributed to GHC before. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14474 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14474: reify RHS of "value" variable -------------------------------------+------------------------------------- Reporter: dailectic | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | 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 goldfire): I don't think this will be so easy. GHC doesn't store the RHS of definitions in a convenient form to be reified into TH. Specifically, when GHC does store the RHS (only for inlinable definitions), it stores it in Core, not Haskell. So part of this work would be translating Core back to Haskell (not impossible). It actually might make a nice project... but the TH AST you get out at the end might not look much like what the user typed in originally. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14474#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14474: reify RHS of "value" variable -------------------------------------+------------------------------------- Reporter: dailectic | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | 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 dailectic): Actually I wouldn't mind just having access to core. Aren't definitions "inlinable" within their own module, or is intra-module inlining handled totally differently? It seems reasonable to only work where core is normally in scope. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14474#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14474: reify RHS of "value" variable -------------------------------------+------------------------------------- Reporter: dailectic | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | 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 goldfire): The problem is that Core doesn't match up with TH syntax. I suppose it really just could return Core, without translating to the TH AST. I'm not sure off the top of my head if all local definitions are inlinable. It wouldn't be hard to experiment and find out, though. GHC also supports cross-module inlining, so there is a chance to work with non-local definitions. The code in question is all in the typecheck/TcSplice module. If you follow the types, this might not be so hard to do, after all. The definitions you're looking for, by the way, are in the `Unfolding` field of the `IdInfo` field of an `Id`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14474#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14474: reify RHS of "value" variable -------------------------------------+------------------------------------- Reporter: dailectic | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | 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 dailectic): Thanks for the pointer, I'll do some digging. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14474#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC