
Hi all, I am trying to get a deeper understanding of core's role in GHC and the compilation of functional languages in general. So far I have been through - The hackathon videos, - "A transformation-based optimiser for Haskell", - "An External Representation for the GHC Core Language (DRAFT for GHC5.02)", and - "Secrets of the Glasgow Haskell Compiler inliner". and I am still a bit hazy on a few points: - What role do *the semantics* of core play (i.e. how and where are they taken advantage of)? - Exactly what are the operational and denotational semantics of core? - The headline reasons (and any other arguments that emerge) for having core *and* stg as separate definitions. I have an intuition on a few of these points, but I would love something concrete to latch on to. Thanks Matt R

On Mon, Feb 12, 2007 at 04:45:47PM +1100, Matt Roberts wrote:
Hi all,
I am trying to get a deeper understanding of core's role in GHC and the compilation of functional languages in general. So far I have been through - The hackathon videos, - "A transformation-based optimiser for Haskell", - "An External Representation for the GHC Core Language (DRAFT for GHC5.02)", and - "Secrets of the Glasgow Haskell Compiler inliner".
and I am still a bit hazy on a few points: - What role do *the semantics* of core play (i.e. how and where are they taken advantage of)?
They aren't, at least not directly by the compiler - the semantics are what give people named Simon the courage to implement counterintuitive optimizations without losing sleep. (since they know formally nothing can go wrong)
- Exactly what are the operational and denotational semantics of core? - The headline reasons (and any other arguments that emerge) for having core *and* stg as separate definitions.
I have an intuition on a few of these points, but I would love something concrete to latch on to.
(disclaimer: I am not a GHC hacker, nor have I ever gotten around to actually writing an optimizer.) It's a simple question of expediency and tradeoffs. Core has lots of nice mathematical properties. For instance, Core's call-by-name properties allow the compiler to simply prune unreferenced expressions, without worrying about changing termination behavior. Core expressions can be rearranged by nice pattern matches, and as a strongly typed calculus Core is relatively immune to misoptimization. On the other hand, Core is rather far from the machine, and much is still implicit - invisible and unoptimizable. If GHC only used Core, you would get all the nice large-scale optimizations (fusion comes immediately to mind), but you would pay full price for every forced closure etc - wasted effort could not be optimized away. STG is much closer to the machine. If GHC's desugarer produced STG and Core were removed completely, GHC would still be able to produce nearly perfect code. Every optimization that could be performed at Core, can in principle be performed at STG. In practice things are a bit different. STG, as an impure, strict, untyped langage, is missing the nice properties of Core, and many optimizations that are a no-brainer to write at the Core level, are riddled with side conditions at the lower level. So, to summarize: We have Core because Simon lacks the patience to solve the halting problem and properly perform effects analysis on STG. We have STG because Simon lacks the patience to wait for the 6.6 Simplifier to finish naively graph-reducing every time. (now let's hope that MY intuitions are on the right track!) Stefan

On Feb 12, 2007, at 7:06 AM, Stefan O'Rear wrote:
We have Core because Simon lacks the patience to solve the halting problem and properly perform effects analysis on STG.
We have STG because Simon lacks the patience to wait for the 6.6 Simplifier to finish naively graph-reducing every time.
Are these two different Simons? :-) -- http://wagerlabs.com/

On 2/12/07, Dougal Stanton
Quoth Joel Reymont, nevermore,
Are these two different Simons? :-)
I'm beginning to wonder if Simon is less a name and more a title, meaning "strong in the lambda force" or somesuch. Let's hope they don't go over to the dark side ;-)
I read that "Simon" means "one who listens to or obeys God." Tying this together with Stefan's post, maybe God is sort of like the unwritten denotational semantics for Haskell. Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "Would you be my clock if I promise not to hang you / Too close to the window or the picture of the pope? / I won't set you back and I won't push you forward / I just want to look in your face and see hope" -- Dom Leone

On Feb 12, 2007, at 5:45 AM, Matt Roberts wrote:
- The hackathon videos, - "A transformation-based optimiser for Haskell", - "An External Representation for the GHC Core Language (DRAFT for GHC5.02)", and - "Secrets of the Glasgow Haskell Compiler inliner".
Matt, can you please post pointers to the above? Thanks, Joel -- http://wagerlabs.com/

Hello Joel, Monday, February 12, 2007, 12:23:16 PM, you wrote:
- "Secrets of the Glasgow Haskell Compiler inliner".
Matt, can you please post pointers to the above?
mostly, these are available on papers pages of SM and SPJ: http://research.microsoft.com/~simonpj/ http://research.microsoft.com/~simonpj/Papers/papers.html http://research.microsoft.com/~simonmar/ http://www.haskell.org/~simonmar/bib/bib.html -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On 12/02/2007, at 8:23 PM, Joel Reymont wrote:
On Feb 12, 2007, at 5:45 AM, Matt Roberts wrote:
- The hackathon videos,
@electronic{hack06, Author = {Simon Peyton Jones and Malcolm Wallace and et. al.}, Date-Added = {2007-02-13 09:04:47 +1100}, Date-Modified = {2007-02-13 09:06:09 +1100}, Title = {GHC Hackathon}, Url = {http://hackage.haskell.org/trac/ghc/wiki/Hackathon}}
- "A transformation-based optimiser for Haskell",
@article{jones98, Author = {Simon L. {Peyton Jones} and Andr{\'e} L. M. Santos}, Date-Added = {2007-02-11 21:16:19 +1100}, Date-Modified = {2007-02-11 22:05:31 +1100}, Journal = {Science of Computer Programming}, Number = {1--3}, Pages = {3--47}, Title = {A transformation-based optimiser for {Haskell}}, Url = {citeseer.ist.psu.edu/peytonjones98transformationbased.html}, Volume = {32}, Year = {1998}}
- "An External Representation for the GHC Core Language (DRAFT for GHC5.02)", and
-- these bibligraphic details are not complete yet @electronic{Tolmach01, Author = {Andrew Tolmach}, Date-Added = {2006-11-27 18:21:37 +1100}, Date-Modified = {2007-02-11 22:05:11 +1100}, Title = {An External Representation for the GHC Core Language (DRAFT for GHC5.02)}, Urldate = {November 27 2006}}
- "Secrets of the Glasgow Haskell Compiler inliner".
@article{jones02, Address = {New York, NY, USA}, Author = {Simon Peyton Jones and Simon Marlow}, Date-Added = {2007-02-11 21:25:16 +1100}, Date-Modified = {2007-02-11 21:26:58 +1100}, Doi = {http://dx.doi.org/10.1017/S0956796802004331}, Issn = {0956-7968}, Journal = {J. Funct. Program.}, Number = {5}, Pages = {393--434}, Publisher = {Cambridge University Press}, Rating = {3}, Title = {Secrets of the Glasgow Haskell Compiler inliner}, Volume = {12}, Year = {2002}}
Matt, can you please post pointers to the above?
Thanks, Joel

Hello Matt, Monday, February 12, 2007, 8:45:47 AM, you wrote:
I am trying to get a deeper understanding of core's role in GHC and
i'm not sure but may be these papers that say about STG can help you: Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine. [http://research.microsoft.com/copyright/accept.asp?path=/users/simonpj/paper...] [http://www.haskell.org/ghc/docs/papers/new-rts.ps.gz] [http://www.haskell.org/ghc/docs/papers/run-time-system.ps.gz] -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On 2/11/07, Matt Roberts
- Exactly what are the operational and denotational semantics of core?
Since I don't think this question has been answered yet, here's a mailing list post from Simon PJ that probably answers it: http://www.haskell.org/pipermail/glasgow-haskell-users/2003-February/004849.... That's from 2003, but I don't think the answer has changed since then. If you wrote down a precise operational and/or denotational semantics for Core, you'd probably have a research paper. (Especially if you proved that GHC actually obeys that semantics...) (Disclaimer: my name isn't Simon.) Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "There are no sexist decisions to be made. There are antisexist decisions to be made. And they require tremendous energy and self-scrutiny, as well as moral stamina..." -- Samuel R. Delany

On Feb 12, 2007, at 1:31 PM, Kirsten Chevalier wrote:
On 2/11/07, Matt Roberts
wrote: - Exactly what are the operational and denotational semantics of core?
Since I don't think this question has been answered yet, here's a mailing list post from Simon PJ that probably answers it: http://www.haskell.org/pipermail/glasgow-haskell-users/2003- February/004849.html
That's from 2003, but I don't think the answer has changed since then. If you wrote down a precise operational and/or denotational semantics for Core, you'd probably have a research paper. (Especially if you proved that GHC actually obeys that semantics...) (Disclaimer: my name isn't Simon.)
At the risk of sounding self-promoting, I'd like to point out that the research paper I recently announced defines an intermediate language that is similar to GHC's core in some respects (they are both based on System F_omega). I give a full (call-by-name) operational semantics and type system for the language in my report [1]. You won't find any proofs in the paper, but they're on my medium-term agenda. There is also source code for an interpreter/ bytecode-compiler/shell for this intermediate language [2]. [1] http://www.cs.tufts.edu/tr/techreps/TR-2007-2 [2] http://www.eecs.tufts.edu/~rdocki01/masters.html
Cheers, Kirsten
Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG

On 2/12/07, Robert Dockins
At the risk of sounding self-promoting, I'd like to point out that the research paper I recently announced defines an intermediate language that is similar to GHC's core in some respects (they are both based on System F_omega). I give a full (call-by-name) operational semantics and type system for the language in my report [1]. You won't find any proofs in the paper, but they're on my medium-term agenda. There is also source code for an interpreter/ bytecode-compiler/shell for this intermediate language [2].
[1] http://www.cs.tufts.edu/tr/techreps/TR-2007-2 [2] http://www.eecs.tufts.edu/~rdocki01/masters.html
I was also neglectful in not mentioning this paper: http://www.cse.unsw.edu.au/~chak/papers/SCPD07.html System F with Type Equality Coercions Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. In G. Necula, editor, Proceedings of The Third ACM SIGPLAN Workshop on Types in Language Design and Implementation, ACM Press, 2007. which describes System FC, which is the current incarnation of Core in GHC, and in fact that paper *does* give an operational semantics for it. Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "It's important for us to explain to our nation that life is important. It's not only life of babies, but it's life of children living in, you know, the dark dungeons of the Internet." -- George W. Bush

| I am trying to get a deeper understanding of core's role in GHC and | the compilation of functional languages in general. So far I have You can find lots of stuff here http://hackage.haskell.org/trac/ghc/wiki/Commentary. At the bottom is a link to a lot of GHC-related papers. | - Exactly what are the operational and denotational semantics of core? It'd be good to have a canonical place where this was written down, I agree; but it's totally straightforward. (The operational semantics, at least.) As Kirsten says, the FC paper is the most up to date presentation. | - The headline reasons (and any other arguments that emerge) for | having core *and* stg as separate definitions. You can find a description of STG, which describes the differences from Core, in the Commentary http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/StgSynType There is a lot of stuff in the Commentary! Simon
participants (8)
-
Bulat Ziganshin
-
Dougal Stanton
-
Joel Reymont
-
Kirsten Chevalier
-
Matt Roberts
-
Robert Dockins
-
Simon Peyton-Jones
-
Stefan O'Rear