Compiler Plugins For GHC: Week Five
Welcome to the fourth instalment in this ongoing series! How have compiler plugins progressed this week?
Haddocking GHC Internals If we’re going to have any hope of people other than GHC developers writing plugins, there needs to be accessible documentation about the relevant parts of the compiler. The lions share of my time last week was taken up documenting about 40 of GHCs modules, describing their functions and writing some notes about GHC jargon that is useful to know.
Unfortunately, I don’t yet have an HTML version to show you since Haddock won’t run on GHC’s source code yet due to our use of the C-preprocessor. However, I’m assured that this is being resolved..
Annotation System Enhancements I’ve added the ability for plugins to attach new annotations to Core syntax trees during compilation, rather than just sticking with the ones that were present in the source statically. This means you could now implement e.g. a strictness analysis pass with a seperate pass that used the annotations generated by that pass to perform the worker-wrapper transform.
I’ve additionally added the ability to generate annotations through Template Haskell. This smells like it might be useful to someone.
Phase Aliases Roman Leshchinskiy replied to my previous email on phase control for GHC and came up with some interesting comments. The upshot of this is that I’ve added the ability to specify phase equality, rather than just inequality:
Pan Optimization Sample Plugin My mentor for this project, Sean Seefried, worked on pluggable compilers as part of his doctoral studies. One of the things that came out of that was a GHC plugin that performed a domain-specific optimization known as “image lifting” on his reimplementation of the Pan combinator library for functional image construction.
I’ve ported this plugin to my own compiler plugins framework, and extracted considerable amounts of it’s utility code into GHC itself for use by other plugin authors. I also hope to use it’s codebase as an exemplar of how to write a large compiler plugin.
API Cleanup GHC has grown by accretion, and as a result some of the APIs we provide are inconsistently named, are parts of incomplete sets of functions and so on. I’ve been spending some time refactoring the worst offenders so the code is a bit more presentable, and hopefully the code will be a bit easier to get a handle on for users new to GHC.
Conclusion A good week: I’ve hit all the goals I laid out in the last installment of this series. However, documentation work is a bit tedious and I’m glad I’ve got a large chunk of it out of the way: this leaves me free to work on some more exciting things this week.
This week I’m focusing on polishing off the rough edges in my API and sample plugins, so they are something approaching releasable. I also have numerous annoying to-dos accumulated from the last five weeks that I will ned to take another another look at. This small stuff aside, I’ve just spent the first day of week 6 working on a rather exciting feature that I think will be very useful even for those who do not plan to be plugin authors: you’ll have to wait until my next post to find out about that!
I wouldn't count on Haddock being fixed soon. The 0.8->2.0 transition was "coming soon" for more than a year. In fact, I think there is no Haddock version that works with 6.8.3 yet.
You're documenting the GHC API ?! You have all my thanks and those of the future programmers who will attempt to use this API !
That's really a sore point with the current API (as well as the lack of some high-level abstraction, but that's completely understandable given the origins of the GHC API).
I'm currently working on a port of HaRe (the Haskell Refactorer) to use the GHC API, and one of the first requirement of this port was to modify the GHC API so that the types of the AST components are instances of Data and Typeable. This simple change allows one to use generic programming techniques on the AST produced by GHC, which is extremely useful when you want to manipulate it. In our case, we use the Strafunski library (StrategyLib on Hackage, I'll put the latest version as soon as I get the approval of the authors) which is really nice.
Would you be interested in integrating this change ? Test with a modified 6.8.3 seems to indicate no ill effects.
And again, felicitations for your work, you seems to be doing very well. I'll be happy to sample your additions and changes.
--
Chaddaï
Chaddaï:
Before you get your hopes up, I have to warn you that I'm only documenting the parts of the API that are relevant to GHC Plugins, which means that a lot of modules will still be undocumented! However, I think a lot of the more interesting ones will have at least some documentation.
Regarding Data/Typeable, actually just the other day Thomas Schilling (GHC API GSoC student) posted to cvs-ghc a proposal to add these instances to all AST types in GHC, so you don't need to do anything to get this change in!