RE: GHC 7.8 release status

I do need more than a patch, please, please. A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.
Simon
| -----Original Message-----
| From: Thomas Schilling [mailto:nominolo@googlemail.com]
| Sent: 04 September 2013 17:26
| To: Simon Peyton-Jones; Luite Stegeman
| Cc: Nicolas Frisby; "Pedro Magalhães (dreixel@gmail.com)"; Richard
| Eisenberg (eir@cis.upenn.edu); Geoffrey Mainland
| (mainland@cs.drexel.edu); Iavor Diatchki; Austin Seipp; Edsko de Vries;
| Ryan Newton (rrnewton@gmail.com); David Luposchainsky; ghc-
| devs@haskell.org
| Subject: Re: GHC 7.8 release status
|
|
| On 4 Sep 2013, at 15:52, Simon Peyton-Jones

I started a wiki page at: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks
Luite: could you please fill in the hooks that your latest patch defines?
On 4 Sep 2013, at 19:40, Simon Peyton-Jones
I do need more than a patch, please, please. A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.
Simon
| -----Original Message----- | From: Thomas Schilling [mailto:nominolo@googlemail.com] | Sent: 04 September 2013 17:26 | To: Simon Peyton-Jones; Luite Stegeman | Cc: Nicolas Frisby; "Pedro Magalhães (dreixel@gmail.com)"; Richard | Eisenberg (eir@cis.upenn.edu); Geoffrey Mainland | (mainland@cs.drexel.edu); Iavor Diatchki; Austin Seipp; Edsko de Vries; | Ryan Newton (rrnewton@gmail.com); David Luposchainsky; ghc- | devs@haskell.org | Subject: Re: GHC 7.8 release status | | | On 4 Sep 2013, at 15:52, Simon Peyton-Jones
| wrote: | | > Edsko/Thomas/Luite: if you want anything for 7.8 it'll have to be | jolly soon. At the moment I don't even know the motivation or design, | let alone implementation. Could you make a wiki page explaining the | proposed design? Is it really important to do this for 7.8? | | Yes, it is quite important to get this into 7.8. Not having these | features in GHC makes it very difficult for people to adopt GHCJS. One | could argue that GHCJS is not yet production-ready anyway and users that | want to try it can figure out building GHC from source to use it, but | this doesn't quite apply. | | 1. GHCJS targets a wider audience than users brave enough to compile | GHC from source. In addition, the next chance to get these features into | GHC is in a year from now, so when GHCJS becomes more mature then this | will be a major hurdle for adoption. | | 2. These changes are also required for IDE tools which really mustn't | require users to build a custom version of GHC. | | | Luite's design is actually very flexible. It simply allows GHC API | users to provide functions that are called instead of (or in addition | to) existing functions in GHC. Instead of calling, say, "genHardCode", | the driver now looks up whether the user has specified a hook for | genHardCode and calls that instead. | | Currently we only specify a small number of hooks that are sufficient | for our use cases. Future releases of GHC can be extended to include | more hooks, if that is needed. | | Hooks are stored as an untyped map inside the DynFlags (to avoid issues | with circular dependencies). Each hook is looked up using a single- | constructor type and type families are used to make this type safe. | There is one use of unsafeCoerce to avoid having to make every hook | function an instance of Typeable. | | Unlike CorePlugins, it is only a GHC API feature, and users cannot | specify plugins to be added via command line options. If we can come up | with a good design, then we could add this in GHC 7.10, but it is not | necessary at this point. | | Luite: Do you have a link to your latest patch?

I've updated the wiki page, expanding the descriptions and adding code from
the actual implementation: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks
An demo program that uses all hooks here:
https://gist.github.com/luite/6444273
(I've listed the users (or proposers) of every hook, and how they use it,
Thomas / Edsko, can you check that they indeed do what you need?)
The patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks.patc...
In addition to defining the heterogeneous map and the hooks themselves,
extra exports have been added to make it possible for users to actually
make a hook implementation without copying most of the module's source
code. The demo program implements all hooks to check this.
Also the GHCJS patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patc...
It adds the following:
- in DynFlags an extra WayCustom constructor to add a custom 'tag' to
generated files (GHCJS builds multiple architectures to support Template
Haskell among other things, one with the 'js' tag)
- in ForeignCall the JavaScriptCallConv calling convention
- in Platform an ArchJavaScript architecture
- `foreign import javascript' support in the parser and lexer
- The JavaScriptFFI extension that enables the `foreign import javascript'
syntax, only supported on ArchJavaScript (So using it on a regular GHC
would always result in a compile error saying that it's unsupported on the
user's platform)
luite
On Thu, Sep 5, 2013 at 12:17 AM, Thomas Schilling
I started a wiki page at: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks
Luite: could you please fill in the hooks that your latest patch defines?
On 4 Sep 2013, at 19:40, Simon Peyton-Jones
wrote: I do need more than a patch, please, please. A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.
Simon
| -----Original Message----- | From: Thomas Schilling [mailto:nominolo@googlemail.com] | Sent: 04 September 2013 17:26 | To: Simon Peyton-Jones; Luite Stegeman | Cc: Nicolas Frisby; "Pedro Magalhães (dreixel@gmail.com)"; Richard | Eisenberg (eir@cis.upenn.edu); Geoffrey Mainland | (mainland@cs.drexel.edu); Iavor Diatchki; Austin Seipp; Edsko de Vries; | Ryan Newton (rrnewton@gmail.com); David Luposchainsky; ghc- | devs@haskell.org | Subject: Re: GHC 7.8 release status | | | On 4 Sep 2013, at 15:52, Simon Peyton-Jones
| wrote: | | > Edsko/Thomas/Luite: if you want anything for 7.8 it'll have to be | jolly soon. At the moment I don't even know the motivation or design, | let alone implementation. Could you make a wiki page explaining the | proposed design? Is it really important to do this for 7.8? | | Yes, it is quite important to get this into 7.8. Not having these | features in GHC makes it very difficult for people to adopt GHCJS. One | could argue that GHCJS is not yet production-ready anyway and users that | want to try it can figure out building GHC from source to use it, but | this doesn't quite apply. | | 1. GHCJS targets a wider audience than users brave enough to compile | GHC from source. In addition, the next chance to get these features into | GHC is in a year from now, so when GHCJS becomes more mature then this | will be a major hurdle for adoption. | | 2. These changes are also required for IDE tools which really mustn't | require users to build a custom version of GHC. | | | Luite's design is actually very flexible. It simply allows GHC API | users to provide functions that are called instead of (or in addition | to) existing functions in GHC. Instead of calling, say, "genHardCode", | the driver now looks up whether the user has specified a hook for | genHardCode and calls that instead. | | Currently we only specify a small number of hooks that are sufficient | for our use cases. Future releases of GHC can be extended to include | more hooks, if that is needed. | | Hooks are stored as an untyped map inside the DynFlags (to avoid issues | with circular dependencies). Each hook is looked up using a single- | constructor type and type families are used to make this type safe. | There is one use of unsafeCoerce to avoid having to make every hook | function an instance of Typeable. | | Unlike CorePlugins, it is only a GHC API feature, and users cannot | specify plugins to be added via command line options. If we can come up | with a good design, then we could add this in GHC 7.10, but it is not | necessary at this point. | | Luite: Do you have a link to your latest patch?

Hi Luite,
Would we be able to adapt this to get generalized Template Haskell support
for GHC iOS/cross compilation?
Cheers
Luke
On Wed, Sep 4, 2013 at 6:09 PM, Luite Stegeman
I've updated the wiki page, expanding the descriptions and adding code from the actual implementation: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks An demo program that uses all hooks here: https://gist.github.com/luite/6444273 (I've listed the users (or proposers) of every hook, and how they use it, Thomas / Edsko, can you check that they indeed do what you need?) The patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks.patc...
In addition to defining the heterogeneous map and the hooks themselves, extra exports have been added to make it possible for users to actually make a hook implementation without copying most of the module's source code. The demo program implements all hooks to check this.
Also the GHCJS patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patc...
It adds the following: - in DynFlags an extra WayCustom constructor to add a custom 'tag' to generated files (GHCJS builds multiple architectures to support Template Haskell among other things, one with the 'js' tag) - in ForeignCall the JavaScriptCallConv calling convention - in Platform an ArchJavaScript architecture - `foreign import javascript' support in the parser and lexer - The JavaScriptFFI extension that enables the `foreign import javascript' syntax, only supported on ArchJavaScript (So using it on a regular GHC would always result in a compile error saying that it's unsupported on the user's platform)
luite
On Thu, Sep 5, 2013 at 12:17 AM, Thomas Schilling
wrote:
I started a wiki page at: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks
Luite: could you please fill in the hooks that your latest patch defines?
On 4 Sep 2013, at 19:40, Simon Peyton-Jones
wrote: I do need more than a patch, please, please. A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.
Simon
| -----Original Message----- | From: Thomas Schilling [mailto:nominolo@googlemail.com] | Sent: 04 September 2013 17:26 | To: Simon Peyton-Jones; Luite Stegeman | Cc: Nicolas Frisby; "Pedro Magalhães (dreixel@gmail.com)"; Richard | Eisenberg (eir@cis.upenn.edu); Geoffrey Mainland | (mainland@cs.drexel.edu); Iavor Diatchki; Austin Seipp; Edsko de Vries; | Ryan Newton (rrnewton@gmail.com); David Luposchainsky; ghc- | devs@haskell.org | Subject: Re: GHC 7.8 release status | | | On 4 Sep 2013, at 15:52, Simon Peyton-Jones
| wrote: | | > Edsko/Thomas/Luite: if you want anything for 7.8 it'll have to be | jolly soon. At the moment I don't even know the motivation or design, | let alone implementation. Could you make a wiki page explaining the | proposed design? Is it really important to do this for 7.8? | | Yes, it is quite important to get this into 7.8. Not having these | features in GHC makes it very difficult for people to adopt GHCJS. One | could argue that GHCJS is not yet production-ready anyway and users that | want to try it can figure out building GHC from source to use it, but | this doesn't quite apply. | | 1. GHCJS targets a wider audience than users brave enough to compile | GHC from source. In addition, the next chance to get these features into | GHC is in a year from now, so when GHCJS becomes more mature then this | will be a major hurdle for adoption. | | 2. These changes are also required for IDE tools which really mustn't | require users to build a custom version of GHC. | | | Luite's design is actually very flexible. It simply allows GHC API | users to provide functions that are called instead of (or in addition | to) existing functions in GHC. Instead of calling, say, "genHardCode", | the driver now looks up whether the user has specified a hook for | genHardCode and calls that instead. | | Currently we only specify a small number of hooks that are sufficient | for our use cases. Future releases of GHC can be extended to include | more hooks, if that is needed. | | Hooks are stored as an untyped map inside the DynFlags (to avoid issues | with circular dependencies). Each hook is looked up using a single- | constructor type and type families are used to make this type safe. | There is one use of unsafeCoerce to avoid having to make every hook | function an instance of Typeable. | | Unlike CorePlugins, it is only a GHC API feature, and users cannot | specify plugins to be added via command line options. If we can come up | with a good design, then we could add this in GHC 7.10, but it is not | necessary at this point. | | Luite: Do you have a link to your latest patch? _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

Thank you for the wiki page. This is great. For the first time I have something I can get my teeth into. Some comments
· Why aren't you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where
Dyn :: Typeable a => a -> Dynamic
and you want to take advantage of this.
· I don't understand the need for the "key" types and the Hook type to get to the real type. Why not do this:
o As now, DynFlags has a map from TypeRep -> Dynamic, with the invariant that if you look up a typerep tr, then the Dynamic you get has typerep tr.
o When you want to add a new pass, say for DsForeigns, you say
newtype DsForeignsHook = DSF ([LForeignDecl Id ] -> DsM (ForegnStubs, OrdList Binding)) deriving Typeable
o To invoke the hook, GHC looks up the type DsForeignsHook in the hook-map, and gets back a newtype value of type DsForeignsHook, which it unwraps and applies.
o To install the hook GHC provides a function
insertHook : Typeable a => a -> Hooks -> Hooks
No need for these strange "data DsForeignsHook = DsForeignsHook" things, or for the Hook type family. Simple!
· The design *must* list all the hooks that GHC uses and their types. There's no point in adding a hook that GHC doesn't call!
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com]
Sent: 05 September 2013 02:10
To: Thomas Schilling
Cc: Simon Peyton-Jones; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
I've updated the wiki page, expanding the descriptions and adding code from the actual implementation: http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks
An demo program that uses all hooks here: https://gist.github.com/luite/6444273
(I've listed the users (or proposers) of every hook, and how they use it, Thomas / Edsko, can you check that they indeed do what you need?)
The patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks.patc...
In addition to defining the heterogeneous map and the hooks themselves, extra exports have been added to make it possible for users to actually make a hook implementation without copying most of the module's source code. The demo program implements all hooks to check this.
Also the GHCJS patch is here:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patc...
It adds the following:
- in DynFlags an extra WayCustom constructor to add a custom 'tag' to generated files (GHCJS builds multiple architectures to support Template Haskell among other things, one with the 'js' tag)
- in ForeignCall the JavaScriptCallConv calling convention
- in Platform an ArchJavaScript architecture
- `foreign import javascript' support in the parser and lexer
- The JavaScriptFFI extension that enables the `foreign import javascript' syntax, only supported on ArchJavaScript (So using it on a regular GHC would always result in a compile error saying that it's unsupported on the user's platform)
luite
On Thu, Sep 5, 2013 at 12:17 AM, Thomas Schilling
I do need more than a patch, please, please. A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.
Simon
| -----Original Message----- | From: Thomas Schilling [mailto:nominolo@googlemail.commailto:nominolo@googlemail.com] | Sent: 04 September 2013 17:26 | To: Simon Peyton-Jones; Luite Stegeman | Cc: Nicolas Frisby; "Pedro Magalhães (dreixel@gmail.commailto:dreixel@gmail.com)"; Richard | Eisenberg (eir@cis.upenn.edumailto:eir@cis.upenn.edu); Geoffrey Mainland | (mainland@cs.drexel.edumailto:mainland@cs.drexel.edu); Iavor Diatchki; Austin Seipp; Edsko de Vries; | Ryan Newton (rrnewton@gmail.commailto:rrnewton@gmail.com); David Luposchainsky; ghc- | devs@haskell.orgmailto:devs@haskell.org | Subject: Re: GHC 7.8 release status | | | On 4 Sep 2013, at 15:52, Simon Peyton-Jones
mailto:simonpj@microsoft.com> | wrote: | | > Edsko/Thomas/Luite: if you want anything for 7.8 it'll have to be | jolly soon. At the moment I don't even know the motivation or design, | let alone implementation. Could you make a wiki page explaining the | proposed design? Is it really important to do this for 7.8? | | Yes, it is quite important to get this into 7.8. Not having these | features in GHC makes it very difficult for people to adopt GHCJS. One | could argue that GHCJS is not yet production-ready anyway and users that | want to try it can figure out building GHC from source to use it, but | this doesn't quite apply. | | 1. GHCJS targets a wider audience than users brave enough to compile | GHC from source. In addition, the next chance to get these features into | GHC is in a year from now, so when GHCJS becomes more mature then this | will be a major hurdle for adoption. | | 2. These changes are also required for IDE tools which really mustn't | require users to build a custom version of GHC. | | | Luite's design is actually very flexible. It simply allows GHC API | users to provide functions that are called instead of (or in addition | to) existing functions in GHC. Instead of calling, say, "genHardCode", | the driver now looks up whether the user has specified a hook for | genHardCode and calls that instead. | | Currently we only specify a small number of hooks that are sufficient | for our use cases. Future releases of GHC can be extended to include | more hooks, if that is needed. | | Hooks are stored as an untyped map inside the DynFlags (to avoid issues | with circular dependencies). Each hook is looked up using a single- | constructor type and type families are used to make this type safe. | There is one use of unsafeCoerce to avoid having to make every hook | function an instance of Typeable. | | Unlike CorePlugins, it is only a GHC API feature, and users cannot | specify plugins to be added via command line options. If we can come up | with a good design, then we could add this in GHC 7.10, but it is not | necessary at this point. | | Luite: Do you have a link to your latest patch?

· **Why aren’t you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler. No need for these strange “data DsForeignsHook = DsForeignsHook” things, or
for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
**
**· **The design **must** list all the hooks that GHC uses and their types. There’s no point in adding a hook that GHC doesn’t call!
It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness. With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them? I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one: - patch: https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna... - updated hooksDemo: https://gist.github.com/luite/6478973 It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases) luite

Edsko I'm very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best? As I said earlier I'm uncomfortable with doing design work so late in the cycle, and I feel that I don't have time to study the various alternatives properly in the next four days. But since you tell me it's crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with. Does that sound ok? Simon From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs Subject: Re: GHC 7.8 release status * Why aren't you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this. Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler. No need for these strange "data DsForeignsHook = DsForeignsHook" things, or for the Hook type family. Simple! But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose) * The design *must* list all the hooks that GHC uses and their types. There's no point in adding a hook that GHC doesn't call! It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness. With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them? I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one: - patch: https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna... - updated hooksDemo: https://gist.github.com/luite/6478973 It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases) luite

Simon,
I talked to Luite this morning and I think we can come up with a
design that includes the enumeration we prefer, with a single use of
Dynamic in DynFlags -- it involves splitting off a PackageState module
from Packages so that DynFlags doesn't depend on the entirely of
Packages anymore (which would then, transitively, mean that it depends
on Hooks and hence on a large part of ghc), but I think that should be
doable. I'm working on that now.
Edsko
On Mon, Sep 9, 2013 at 3:51 PM, Simon Peyton-Jones
Edsko
I’m very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best?
As I said earlier I’m uncomfortable with doing design work so late in the cycle, and I feel that I don’t have time to study the various alternatives properly in the next four days. But since you tell me it’s crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with.
Does that sound ok?
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
· Why aren’t you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler.
No need for these strange “data DsForeignsHook = DsForeignsHook” things, or for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
· The design *must* list all the hooks that GHC uses and their types. There’s no point in adding a hook that GHC doesn’t call!
It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness.
With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them?
I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one:
- patch: https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna...
- updated hooksDemo: https://gist.github.com/luite/6478973
It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases)
luite
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

Just my 02c: I feel the GHC API is allowed to be less stable and a
little more in-flux than most things. We've never particularly
advertised stability here anyway, so having a design that evolves a
little is reasonable, IMO. Perhaps it being in the release will help
drive more feedback, earlier.
I think we should at least get a full code review in, of course, and
address any outstanding technical concerns (like DLL splitting.) I'll
schedule this for later this week with Edsko and Luite, if nobody has
objections.
On Mon, Sep 9, 2013 at 9:55 AM, Edsko de Vries
Simon,
I talked to Luite this morning and I think we can come up with a design that includes the enumeration we prefer, with a single use of Dynamic in DynFlags -- it involves splitting off a PackageState module from Packages so that DynFlags doesn't depend on the entirely of Packages anymore (which would then, transitively, mean that it depends on Hooks and hence on a large part of ghc), but I think that should be doable. I'm working on that now.
Edsko
On Mon, Sep 9, 2013 at 3:51 PM, Simon Peyton-Jones
wrote: Edsko
I’m very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best?
As I said earlier I’m uncomfortable with doing design work so late in the cycle, and I feel that I don’t have time to study the various alternatives properly in the next four days. But since you tell me it’s crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with.
Does that sound ok?
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
· Why aren’t you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler.
No need for these strange “data DsForeignsHook = DsForeignsHook” things, or for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
· The design *must* list all the hooks that GHC uses and their types. There’s no point in adding a hook that GHC doesn’t call!
It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness.
With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them?
I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one:
- patch: https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna...
- updated hooksDemo: https://gist.github.com/luite/6478973
It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases)
luite
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
-- Regards, Austin - PGP: 4096R/0x91384671

Edsko has done some work of rearranging imports in DynFlags to make the DLL
split work, and I've implemented the hooks on top of this, in a record, as
discussed:
-
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-reco...
final yet, but should be usable for testing)
- demo program: https://gist.github.com/luite/6506064
Some disadvantages:
- as long as the DLL split exists, more restructuring will be required if a
new hook is added to something in a module on which DynFlags depends
- 4 new hs-boot files required, new hooks will often require additional
hs-boot files (when module A has a hook (so A imports Hooks, this can't be
a source import), the hook will often have some types defined by A, so
Hooks will have to import A)
Advantages (over type families / Dynamic hooks):
- Hooks neatly defined together in a single record
I'm not so sure myself, but if everyone agrees that this is better than the
older hooks I'll convert GHCJS to the new implementation later today and
finalize the patch (comments are a bit out of date, and I'm not 100% sure
yet that GHCJS doesn't need another hook for TH support in certain setups)
and update the wiki.
luite
On Mon, Sep 9, 2013 at 4:55 PM, Edsko de Vries
Simon,
I talked to Luite this morning and I think we can come up with a design that includes the enumeration we prefer, with a single use of Dynamic in DynFlags -- it involves splitting off a PackageState module from Packages so that DynFlags doesn't depend on the entirely of Packages anymore (which would then, transitively, mean that it depends on Hooks and hence on a large part of ghc), but I think that should be doable. I'm working on that now.
Edsko
Edsko
I’m very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best?
As I said earlier I’m uncomfortable with doing design work so late in the cycle, and I feel that I don’t have time to study the various alternatives properly in the next four days. But since you tell me it’s crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with.
Does that sound ok?
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
· Why aren’t you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler.
No need for these strange “data DsForeignsHook = DsForeignsHook” things, or for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
· The design *must* list all the hooks that GHC uses and their types. There’s no point in adding a hook that GHC doesn’t call!
It appears to be difficult to define all hooks in one module or have
On Mon, Sep 9, 2013 at 3:51 PM, Simon Peyton-Jones
wrote: them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness.
With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them?
I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one:
- patch:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna...
- updated hooksDemo: https://gist.github.com/luite/6478973
It also adds hscParse' and tcRnModule' exports for Edsko's use case (I
that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these
think phases)
luite
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

I do like the single record.
I would really really like a strong clear Note [blah] on the hooks::Dynamic field of DynFlags. It's *so* non-obvious why it's dynamic, and the reason is a really bad one, namely the windows DLL split nonsense. (Not our fault but still needs very clear signposting.)
I don't understand why we need 4 new hs-boot files. Eg why DsMonad.hs-boot? It should be safely below Hooks.
Linker.hs-boot is solely because of LibrarySpec. It would be possible to push that into HscTypes. (Again with a comment to explain why.)
DriverPipeline is aleady 2,100 lines long, and could reasonably be split with CompPipeline in the PipelineMonad module, say.
In other words, a bit of refactoring might eliminate the loops *and* sometimes arguably improve the code.
I don't feel terribly strongly about all this. It does feel a bit ad hoc... in a variety of places (eg deep in Linker.hs) there are calls to hooks, and it's not clear to me why exactly those are the right places. But I suppose they are simply driven by what has been needed.
Anyway if you two are happy (no one else seems to mind either way) then go ahead.
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com]
Sent: 10 September 2013 08:37
To: Edsko de Vries
Cc: Simon Peyton-Jones; ghc-devs; Edsko de Vries
Subject: Re: GHC 7.8 release status
Edsko has done some work of rearranging imports in DynFlags to make the DLL split work, and I've implemented the hooks on top of this, in a record, as discussed:
- https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-reco... (not final yet, but should be usable for testing)
- demo program: https://gist.github.com/luite/6506064
Some disadvantages:
- as long as the DLL split exists, more restructuring will be required if a new hook is added to something in a module on which DynFlags depends
- 4 new hs-boot files required, new hooks will often require additional hs-boot files (when module A has a hook (so A imports Hooks, this can't be a source import), the hook will often have some types defined by A, so Hooks will have to import A)
Advantages (over type families / Dynamic hooks):
- Hooks neatly defined together in a single record
I'm not so sure myself, but if everyone agrees that this is better than the older hooks I'll convert GHCJS to the new implementation later today and finalize the patch (comments are a bit out of date, and I'm not 100% sure yet that GHCJS doesn't need another hook for TH support in certain setups) and update the wiki.
luite
On Mon, Sep 9, 2013 at 4:55 PM, Edsko de Vries
Edsko
I'm very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best?
As I said earlier I'm uncomfortable with doing design work so late in the cycle, and I feel that I don't have time to study the various alternatives properly in the next four days. But since you tell me it's crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with.
Does that sound ok?
Simon
From: Luite Stegeman [mailto:stegeman@gmail.commailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
* Why aren't you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler.
No need for these strange "data DsForeignsHook = DsForeignsHook" things, or for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
* The design *must* list all the hooks that GHC uses and their types. There's no point in adding a hook that GHC doesn't call!
It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness.
With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them?
I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one:
- patch: https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna...
- updated hooksDemo: https://gist.github.com/luite/6478973
It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases)
luite
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.orgmailto:ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

Hi all,
So I managed to remove 3 out of 4 of the -boot files. The one that
remains, ironically, is the DsMonad.hs-boot. DsMonad has a
(transitive) dependency on Hooks in at least two ways: once through
Finder, which imports Packages, which imports Hooks; but that's easily
solved, because Finder can import PackageState instead. However, it is
less obvious to me how to resolve the following import cycle
- DsMonad imports tcIfaceGlobal from TcIface
- TcIface imports (loadWiredInHomeIface, loadInterface, loadDecls,
findAndReadIface) from LoadIface
- LoadIFace imports Hooks
(There might be still others, this is the most direct one at the moment.)
(Just to be clear, Hooks imports DsMonad because it needs the DsM type
for the dsForeignsHook.)
I'm sure this cycle can be broken somehow, but I'm not familiar enough
with this part of the compiler to see if there is a natural point to
do it. As things stand, we have a DsMonad.hs-boot which just exports
the DsGblEnv, DsLclEnv, and DsM types. I don't know if this is
something we should be worrying about or not?
Just to summarize: the hooks patch as things stand now introduces the
Hooks enumeration, rather than a separate type per hook so that we
have a central and type checked list of all hooks; in order to do
that, it moves some things around (some times moves to HscTypes),
introduces a new module called PipelineMonad as per SPJ's suggestion,
and introduces a single additional boot file for the DsMonad module.
Edsko
On Tue, Sep 10, 2013 at 12:40 PM, Simon Peyton-Jones
I do like the single record.
I would really really like a strong clear Note [blah] on the hooks::Dynamic field of DynFlags. It’s *so* non-obvious why it’s dynamic, and the reason is a really bad one, namely the windows DLL split nonsense. (Not our fault but still needs very clear signposting.)
I don’t understand why we need 4 new hs-boot files. Eg why DsMonad.hs-boot? It should be safely below Hooks.
Linker.hs-boot is solely because of LibrarySpec. It would be possible to push that into HscTypes. (Again with a comment to explain why.)
DriverPipeline is aleady 2,100 lines long, and could reasonably be split with CompPipeline in the PipelineMonad module, say.
In other words, a bit of refactoring might eliminate the loops *and* sometimes arguably improve the code.
I don’t feel terribly strongly about all this. It does feel a bit ad hoc… in a variety of places (eg deep in Linker.hs) there are calls to hooks, and it’s not clear to me why exactly those are the right places. But I suppose they are simply driven by what has been needed.
Anyway if you two are happy (no one else seems to mind either way) then go ahead.
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 10 September 2013 08:37 To: Edsko de Vries Cc: Simon Peyton-Jones; ghc-devs; Edsko de Vries
Subject: Re: GHC 7.8 release status
Edsko has done some work of rearranging imports in DynFlags to make the DLL split work, and I've implemented the hooks on top of this, in a record, as discussed:
- https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-reco... (not final yet, but should be usable for testing)
- demo program: https://gist.github.com/luite/6506064
Some disadvantages:
- as long as the DLL split exists, more restructuring will be required if a new hook is added to something in a module on which DynFlags depends
- 4 new hs-boot files required, new hooks will often require additional hs-boot files (when module A has a hook (so A imports Hooks, this can't be a source import), the hook will often have some types defined by A, so Hooks will have to import A)
Advantages (over type families / Dynamic hooks):
- Hooks neatly defined together in a single record
I'm not so sure myself, but if everyone agrees that this is better than the older hooks I'll convert GHCJS to the new implementation later today and finalize the patch (comments are a bit out of date, and I'm not 100% sure yet that GHCJS doesn't need another hook for TH support in certain setups) and update the wiki.
luite
On Mon, Sep 9, 2013 at 4:55 PM, Edsko de Vries
wrote: Simon,
I talked to Luite this morning and I think we can come up with a design that includes the enumeration we prefer, with a single use of Dynamic in DynFlags -- it involves splitting off a PackageState module from Packages so that DynFlags doesn't depend on the entirely of Packages anymore (which would then, transitively, mean that it depends on Hooks and hence on a large part of ghc), but I think that should be doable. I'm working on that now.
Edsko
On Mon, Sep 9, 2013 at 3:51 PM, Simon Peyton-Jones
wrote: Edsko
I’m very short of time right now. I think you understand the issues here. Can you do a round or two with Luite and emerge with a design that you both think is best?
As I said earlier I’m uncomfortable with doing design work so late in the cycle, and I feel that I don’t have time to study the various alternatives properly in the next four days. But since you tell me it’s crucial for GHCJS, I suppose that a possible compromise is this. We release a GHC with some design for hooks, but specifically say that the hook design is evolving and may well change with the next version. And then you two, with Thomas and other interested parties, work together to evolve a design that everyone is happy with.
Does that sound ok?
Simon
From: Luite Stegeman [mailto:stegeman@gmail.com] Sent: 07 September 2013 22:04 To: Simon Peyton-Jones Cc: Thomas Schilling; Edsko de Vries; ghc-devs
Subject: Re: GHC 7.8 release status
· Why aren’t you using Data.Dynamic for the hook things? You are precisely doing dynamic typing after all. (Moreover I want to change Data.Dynamic so that it says
data Dynamic where Dyn :: Typeable a => a -> Dynamic and you want to take advantage of this.
Ah the goal is to avoid the Typeable constraint on the hooked function, and to identify what things are actually hooks. Wrapping it in a newtype also achieves the first goal and does make the design a bit simpler.
No need for these strange “data DsForeignsHook = DsForeignsHook” things, or for the Hook type family. Simple!
But it means that hooks are no longer recognisable by their type, they're just some Typeable (the type families approach would at least prevent users from accidentally inserting wrong hooks, even though they would still be able to make bogus instances on purpose)
· The design *must* list all the hooks that GHC uses and their types. There’s no point in adding a hook that GHC doesn’t call!
It appears to be difficult to define all hooks in one module or have them in one record because of dependencies and the DLL split on Windows. Re-exporting everything from a single module can be done, but would offer no guarantees about completeness.
With the type families design, everything that's an instance of Hook is a hook, although the definitions are scattered throughout the GHC source. The Dynamic design would just have to rely on a consistent naming convention. Would listing the hooks in comments (in the Hooks module) and on the wiki be a reasonable way to document them?
I've uploaded a new patch, using Dynamic, although I'm not sure if it's an improvement over the original one:
- patch:
https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks-dyna...
- updated hooksDemo: https://gist.github.com/luite/6478973
It also adds hscParse' and tcRnModule' exports for Edsko's use case (I think that makes it somewhat more flexible than exporting another version of hscFileFrontend, since it allows users to write a hook that does something between parsing and typechecking or one that overrides one of these phases)
luite
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

I'm ok with that, thanks.
Can you put your comments below into DsMonad.hs-boot so that we don't lose the reasoning? It's devilish hard to work out *why* a hs-boot file must exist, sometimes.
Maybe also update
http://ghc.haskell.org/trac/ghc/wiki/Commentary/ModuleStructure
which tries to document some these loops too.
Simon
| -----Original Message-----
| From: Edsko de Vries [mailto:edskodevries@gmail.com]
| Sent: 11 September 2013 15:33
| To: Simon Peyton-Jones
| Cc: Luite Stegeman; ghc-devs; Edsko de Vries
| Subject: Re: GHC 7.8 release status
|
| Hi all,
|
| So I managed to remove 3 out of 4 of the -boot files. The one that
| remains, ironically, is the DsMonad.hs-boot. DsMonad has a
| (transitive) dependency on Hooks in at least two ways: once through
| Finder, which imports Packages, which imports Hooks; but that's easily
| solved, because Finder can import PackageState instead. However, it is
| less obvious to me how to resolve the following import cycle
|
| - DsMonad imports tcIfaceGlobal from TcIface
| - TcIface imports (loadWiredInHomeIface, loadInterface, loadDecls,
| findAndReadIface) from LoadIface
| - LoadIFace imports Hooks
|
| (There might be still others, this is the most direct one at the
| moment.)
|
| (Just to be clear, Hooks imports DsMonad because it needs the DsM type
| for the dsForeignsHook.)
|
| I'm sure this cycle can be broken somehow, but I'm not familiar enough
| with this part of the compiler to see if there is a natural point to
| do it. As things stand, we have a DsMonad.hs-boot which just exports
| the DsGblEnv, DsLclEnv, and DsM types. I don't know if this is
| something we should be worrying about or not?
|
| Just to summarize: the hooks patch as things stand now introduces the
| Hooks enumeration, rather than a separate type per hook so that we
| have a central and type checked list of all hooks; in order to do
| that, it moves some things around (some times moves to HscTypes),
| introduces a new module called PipelineMonad as per SPJ's suggestion,
| and introduces a single additional boot file for the DsMonad module.
|
| Edsko
|
| On Tue, Sep 10, 2013 at 12:40 PM, Simon Peyton-Jones
|
participants (6)
-
Austin Seipp
-
Edsko de Vries
-
Luite Stegeman
-
Luke Iannini
-
Simon Peyton-Jones
-
Thomas Schilling