[GHC] #7867: Allow template-haskell to communicate with itself between compilation units through the interface file

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file -----------------------------+---------------------------------------------- Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Component: Template Haskell Version: 7.6.3 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- I'd like to be able to have something like this in the Q monad: type MessageName = String -- or something better, I don't know writeIface :: (Quasi q, Serializable a) => MessageName -> a -> q () readIfaces :: (Quasi q, Serializable a) => MessageName -> q [a] Or instead of returning [a], I'm of course fine with a Monoid, I just need the gathered results for every occurrance of the MessageName. This has to be in the interface file, because I'd like this to work through compilation units, like class instances, I'd like to get every result in the readIfaces call that is ever imported from the current module (transitive closure). Please note, that in a very hacky way this is already possible to do by abusing classes. Namely, I create an empty class for my message type. When I want to send a message, I create a new empty datatype named for the message and I make this an instance of the class. Then on the receiving side I just have to reify the class and I will receive all my instance names/messages. This came up while implementing the HFlags library: http://hackage.haskell.org/package/hflags Maybe I shouldn't be proud of this, but we currently do the hacky way explained above. I would love to have a clean approach. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonpj): * cc: batterseapower (added) * difficulty: => Unknown Comment: [http://www.haskell.org/ghc/docs/latest/html/users_guide/extending- ghc.html#annotation-pragmas Annotations] might do the job. I'm not sure wether TH gives you enough hooks to interact with annotations (Max would know), but they are properly persisted across interface files. Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Description changed by simonpj: Old description:
I'd like to be able to have something like this in the Q monad:
type MessageName = String -- or something better, I don't know writeIface :: (Quasi q, Serializable a) => MessageName -> a -> q () readIfaces :: (Quasi q, Serializable a) => MessageName -> q [a]
Or instead of returning [a], I'm of course fine with a Monoid, I just need the gathered results for every occurrance of the MessageName.
This has to be in the interface file, because I'd like this to work through compilation units, like class instances, I'd like to get every result in the readIfaces call that is ever imported from the current module (transitive closure).
Please note, that in a very hacky way this is already possible to do by abusing classes. Namely, I create an empty class for my message type. When I want to send a message, I create a new empty datatype named for the message and I make this an instance of the class. Then on the receiving side I just have to reify the class and I will receive all my instance names/messages.
This came up while implementing the HFlags library: http://hackage.haskell.org/package/hflags
Maybe I shouldn't be proud of this, but we currently do the hacky way explained above. I would love to have a clean approach.
New description: I'd like to be able to have something like this in the Q monad: {{{ type MessageName = String -- or something better, I don't know writeIface :: (Quasi q, Serializable a) => MessageName -> a -> q () readIfaces :: (Quasi q, Serializable a) => MessageName -> q [a] }}} Or instead of returning `[a]`, I'm of course fine with a `Monoid`, I just need the gathered results for every occurrance of the MessageName. This has to be in the interface file, because I'd like this to work through compilation units, like class instances, I'd like to get every result in the readIfaces call that is ever imported from the current module (transitive closure). Please note, that in a very hacky way this is already possible to do by abusing classes. Namely, I create an empty class for my message type. When I want to send a message, I create a new empty datatype named for the message and I make this an instance of the class. Then on the receiving side I just have to reify the class and I will receive all my instance names/messages. This came up while implementing the `HFlags` library: http://hackage.haskell.org/package/hflags Maybe I shouldn't be proud of this, but we currently do the hacky way explained above. I would love to have a clean approach. -- -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by errge): Hi Simon, Thanks for your reply. I actually found annotations before reporting this issue and my plan was to look into them and if they are persisted in interface files then add some access for them from Template Haskell reify (currently that's not there), but this is what I found: {{{ errge@curry:/tmp $ cat Foo.hs module Foo (foo) where {-# ANN foo "my message" #-} foo x = x errge@curry:/tmp $ ghc -c -o Foo.o Foo.hs Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. errge@curry:/tmp $ cp Foo.hi Foo.hi.old // Edit file to have "my message newer" errge@curry:/tmp $ cat Foo.hs module Foo (foo) where {-# ANN foo "my message newer" #-} foo x = x errge@curry:/tmp $ ghc -c -o Foo.o Foo.hs Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. errge@curry:/tmp $ cmp Foo.hi.old Foo.hi errge@curry:/tmp $ echo $? 0 errge@curry:/tmp $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.6.2 }}} So my annotation is definitely not persisted in the Foo.hi file with 7.6.2. Am I doing something wrong? Is this different with GHC HEAD? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: 3725 | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by errge): * status: new => infoneeded * blockedby: => 3725 Comment: Nevermind my previous comment, I found the relevant bug: http://hackage.haskell.org/trac/ghc/ticket/3725 OK, I will continue by investigating if it's possible to get this stuff from template haskell and if not, how hard would be to add it... I'll get back to this ticket if I have or need further info. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: 3725 | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by igloo): * status: infoneeded => new -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7867: Allow template-haskell to communicate with itself between compilation units through the interface file ---------------------------------+------------------------------------------ Reporter: errge | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: 3725 | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by errge): Ohh, sorry, I forgot to continue this ticket. So, I looked a bit around, and Annotations sounds good and the way to go. I checked, there is no Template Haskell functionality either for getting back annotations when reifying functions or modules (there is no module reification at all). Also, there is no support for generating annotations from TH. If I have time to take care of either one, I'll try, but I'm a bit underqualified :) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7867#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (2)
-
GHC
-
GHC