4 ms·
Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."
by nitrix 9y ago
Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."
- thu 9y agoI think they use GHC frontend to parse Haskell sources.
- navaati 9y agoNot only parse but do all the type-checking I guess (which is where Haskell is moving the most)
- pdpi 9y agoHaskell is a pretty large language, and (IIRC) the first step in GHC compilation is converting Haskell into Core, which is basically a tiny subset of the language. Parsing the language isn't a very interesting research problem, and more work than it's worth, so Intel have chosen to instead use GHC's frontend to generate Core code, and then consume Core for their compiler backend.
- dllthomas 9y agoNot just parsing - also type checking. And it means free support for all the various GHC language extensions that only change what Core is generated.
- tikhonj 9y agoThink of this as closer to an optimizing backend for GHC than a completely brand-new compiler. It uses GHC to parse, typecheck and desugar Haskell to an intermediate form called Core and uses that to do its own optimization and code generation. A core design principle of Haskell is that while the whole language has gotten relatively complex thanks to all its language features and extensions, almost everything can be simplified to a really small and elegant core language. This core language is a typed lambda calculus that looks a lot like a subset of Haskell except with a few changes like no type inference and different rules for strictness. GHC then uses this pared down version of Haskell (appropriately called Core) for the rest of its optimization and compilation. This means that once the first pass is done with type inference, type checking, typeclass resolution and a lot of other high-level transformations, the rest of the compiler doesn't have to worry about them at all. This makes all of GHCs optimizations easier to implement and maintain, and it lets us add features to Haskell without needing to change the backend.
- zelos 9y agoIf anyone's interested, there's a pretty well written book about the implementation: https://www.microsoft.com/en-us/research/publication/the-implementation-of-functional-programming-languages/ https://www.microsoft.com/en-us/research/publication/the-imp...
- smitherfield 9y agoCore, C--, LLVM… — how many intermediate languages is it going through?!
- mrkgnao 9y agoAlso something called STG.
- name_for_now 9y agoI don't think you can call the STG an IL...
- nickpsecurity 9y agoWe can test that. Is it the target, machine code? If not, are there any optimizations that can happen between the two? If it's not machine code & can be improved, then it's probably safe to classify it as an IL. Or common sense variant: it's not the final language so it's an intermediate language. :)
- jl6 9y agoIs there any chance they might miss an opportunity for optimisation by throwing out the sugar, thereby discarding information about the prgrammer's intent? Or does the sugar carry no such information?
- tikhonj 9y agoThere is, but it's pretty low because language extensions are designed with Core in mind and the desugaring tends to be relatively straightforward. In most cases, the semantics of the "sugar" is defined in terms of a simpler subset of the language, so there is very little the compiler could do differently. More importantly, any modern compiler is very far from the producing the most optimal possible programs. Overall performance could be improved pretty much anywhere, and the tradeoffs involved make operating on the "whole" language a far lower priority than pretty much anything else.
- runeks 9y agoKeep in mind that GHC/Haskell has a gazillion extensions, so parsing Haskell directly is fairly complex.
- mrkgnao 9y agoGHC is an entire library too. It has parsers, AST datatypes, desugarers, typecheckers for both Haskell and Core, multiple intermediate representation libraries, ... and the actual compiler is "just" an application that uses that library. An excellent overview: http://www.aosabook.org/en/ghc.html http://www.aosabook.org/en/ghc.html