[GHC] #11832: Allow reify to yield types in the current declaration group

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: template- | Operating System: Unknown/Multiple haskell reify | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: | TemplateHaskell/Reify -------------------------------------+------------------------------------- Here is the motivation TemplateHaskell/Reify. It would be useful to have a way to obtain types of identifiers in the current declaration group in splices. However, {{{reify}}} is defined to provide information about identifiers in previous declaration groups only. It would be fine to allow {{{reify}}} to work in a scheme combined with {{{addModFinalizer}}} or similar so it is executed when the types are known. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: template-haskell reify => reify * component: Compiler => Template Haskell -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by thomie): * type: bug => feature request -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * owner: => facundo.dominguez -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: new => patch * differential: => Phab:D2286 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by simonpj): I'm confused by the patch. I believe that the poster-child example is this: {{{ f x = $(do { let name = 'x in ; addModFinalizer (reify name >>= \info -> runIO (print info)) ; [| x |]) } }}} Now, the issue is that * the splice is run by the renamer * but you want the finaliser to have access to the type environment giving the type of `x`, which we only have a typecheck time. Rather than mess around with IORefs, why not do this {{{ data HsExpr = ... | HsSpliced [Q ()] (HsExpr ..) .. }}} So the `Spliced` collects the finalisers emitted by the splice, but does not run them. Now when the typechecker finds a `HsSpliced`, it does {{{ tcExpr (Spliced fs e) = do { env <- getLclEnv ; addModFinaliser (setLclEnv env (sequence fs)) ; tcExpr e } }}} That is, it just grabs the env, and emits a new finaliser that sets that env. Much nicer! ------ Generally, could we not combine `addModFinaliser` with `addTopDecls` into one primitive, by offering {{{ later :: Q [Decl] -> Q () }}} It takes a computation and puts it aside for "later" (just like addModFinaliser). But when it finally run, which happens at top level, it can produce some decls which are spliced in. So we have {{{ addModFinaliser thing = later (thing >> return []) addTopDecls dec = later (return dec) }}} Nice! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): That looks better to me if you can somehow implement the {{{Data (Q ())}}} instance that the compiler will request for adding such field in the AST. We could still use a Map to store the finalizers, instead of storing local type environments as we are doing now. Combining {{{addModFinaliser}}} and {{{addTopDecls}}} looks fine to me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by simonpj):
That looks better if you can somehow implement the {{{Data (Q ())}}} instance that the compiler will request for adding such field in the AST.
Well you can wrap it in a newtype and make a hand Data instance that will skip the field. The tail should not wag the dog.
We could still use a Map to store the finalizers, instead of storing local type environments as we are doing now.
I don't understand. Why would you need a Map. I gave a full implementation above. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by facundo.dominguez):
I don't understand. Why would you need a Map. I gave a full implementation above.
Not needed if the dummy Data instance is good enough. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by simonmar): * cc: simonmar (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group
-------------------------------------+-------------------------------------
Reporter: | Owner:
facundo.dominguez | facundo.dominguez
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Template Haskell | Version: 7.10.3
Resolution: | Keywords: reify
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2286
Wiki Page: |
TemplateHaskell/Reify |
-------------------------------------+-------------------------------------
Comment (by Facundo Domínguez

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: fixed | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.3 Resolution: fixed | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by goldfire): Could you add a Release Note about this, as well? See `docs/users_guide/8.2.1-notes.rst`. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: merge Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: fixed | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by bgamari): * status: closed => merge * milestone: => 8.0.2 Comment: Merged to `ghc-8.0` as 8d63419478074728eb03082787ea51d498b3e62e. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: closed Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: fixed | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | Type: feature request | Status: new Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: closed => new * owner: facundo.dominguez => * differential: Phab:D2286 => Phab:D2286 Phab:D2519 * resolution: fixed => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: new Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * owner: => facundo.dominguez -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: new => patch Comment: After last fix, {{{ g :: Int g = 0 f = $(do addModFinalizer $ reify (mkName "g") >>= ... [| return () |] ) }}} couldn't find `g`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by goldfire): When you set the status as `patch`, do you mean that you've fixed this shortcoming? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): I hope so in a patch I submitted today https://phabricator.haskell.org/D2519. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: 8.0.2 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * cc: bgamari (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: patch Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 7.10.3 Resolution: | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.2 => 8.2.1 Comment: Bumping off to 8.0.3. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11832: Allow reify to yield types in the current declaration group -------------------------------------+------------------------------------- Reporter: | Owner: facundo.dominguez | facundo.dominguez Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 7.10.3 Resolution: fixed | Keywords: reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2286 Wiki Page: | Phab:D2519 TemplateHaskell/Reify | -------------------------------------+------------------------------------- Changes (by facundo.dominguez): * status: patch => closed * resolution: => fixed Comment: Closing this as we now have #12818 to track patch D2519. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11832#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC