Showing posts with label GRIN. Show all posts
Showing posts with label GRIN. Show all posts

Friday, April 10, 2009

A new beginning.

The LHC project has finally resumed development after a few weeks of inactivity. Things have taken big steps in a new direction, however, and nearly everything except the name has changed.
We're no longer a fork of JHC. Maintaining a complete Haskell front-end was too much of a hassle, especially considering we're only interested in optimization on the GRIN level. For this reason, LHC has reinvented itself as an alternative backend to the Glorious Glasgow Haskell Compiler.

The lack of testability was a major problem in the previous version of LHC but hopefully we've learned from our mistakes. The new development efforts will be structured around a decremental reliance on a GRIN evaluator. In other words, we want to run the full testsuite between each and every significant code transformation. That no transformation should change the external behaviour of a GRIN program is a very simple invariant.

The current toolchain looks as following:

david@desktop:basic$ cat Args.hs
import System

main :: IO ()
main = do
as <- getArgs
mapM_ putStrLn as
david@desktop:basic$ ghc -fforce-recomp -O2 -fext-core -c Args.hs
david@desktop:basic$ lhc compile Args.hcr > Args.lhc
david@desktop:basic$ ./Args.lhc One Two Three
One
Two
Three


The contents of 'Args.lhc' is unoptimized GRIN code. It is not by any means efficient or fast but it serves its purpose.

Development will now focus on creating GRIN transformations that reduces the need for the RTS (our GRIN evaluator serves as the RTS).

Wednesday, April 8, 2009

Hello world!

After weeks of development, lhc is finally able to interpret Hello World!

david@desktop:lhc$ cat HelloWorld.hs
module Main where
main = putStr "Hello world\n"
david@desktop:lhc$ ghc -O2 -fext-core HelloWorld.hs -c
david@desktop:lhc$ lhc build HelloWorld.hcr > HelloWorld.grin
Parsing core files...
Tracking core dependencies...
Translating to grin...
Removing dead code...
Printing grin...
david@desktop:lhc$ wc -l HelloWorld.grin
8054 HelloWorld.grin
david@desktop:lhc$ lhc eval HelloWorld.hcr
Parsing core files...
Tracking core dependencies...
Translating to grin...
Removing dead code...
Hello world
Node (Aliased 251 "ghc-prim:GHC.Prim.(#,#)") (ConstructorNode 0) [Empty,HeapPointer 263]


Supported primitives include: indexCharOffAddr#, newPinnedByteArray#, *MutVar, *MVar.

Exceptions are currently ignored and the heap is never garbage collected. However, since I'm evaluating the GRIN (as opposed to translating it to LLVM or C), adding these features should be easy as cake.

Thursday, February 5, 2009

Grin a little.

It has come to my attention that we are not using GRIN to it fullest. More specifically, it seems that the 'eval' and 'update' operations are handled by the RTS. This has unfortunate consequences for both the optimizer and the backend code.
Without an explicit control-flow graph (given by inlining eval/apply), many of our more important transformations cannot be performed. Even worse than the lost optimization opportunities is the increased complexity of the RTS. Dealing with issues of correctness is an annoying distraction from the more enjoyable endeavour of applying optimizations.

Moving away from the magical implementation of 'update' means we have to starting thinking about our memory model. The GRIN paper suggests using a fixed node size with a tail pointer for additional space if necessary. With this scheme we can update common-case nodes without allocating more heap space. However, since we're most likely to encounter complications with respect to concurrency and certain forms of garbage collection, I think a simpler approach is more apt.
Replacing nodes with indirections is very easy to implement, it doesn't clash with any optimizations (the original GRIN approach interfere with fetch movement), and it opens the door for advanced features such as concurrency.

So this is what I'll be working on in the near future. All magic has to be purged from the kingdom so logic and reason can reign supreme.