Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Last active April 24, 2019 08:34
Show Gist options
  • Select an option

  • Save chrisdone/83dcdc089b4bbd4a2264de62a06c4ac2 to your computer and use it in GitHub Desktop.

Select an option

Save chrisdone/83dcdc089b4bbd4a2264de62a06c4ac2 to your computer and use it in GitHub Desktop.
Prana demonstration

This is a simple demonstration of what Prana is currently capable of doing:

  1. The script generate.sh will compile
  • ghc-prim
  • integer-gmp
  • base
  1. The binary prana-ghc acts as a replacement for regular ghc, but it also "Recompiles" and outputs .prana files
  2. The resulting "object" .prana files contain STG for each library, and they go in the PRANA_DIR directory
  3. Along with an "index" file that maps numerical references of variables/nodes/data constructors to strings like package:Module.name.
  4. That whole process takes about 15 seconds.
  5. The test suite implements a simple WIP interpreter capable of running the corecursive (or iterative) fibs implementation.
  6. The output includes weigh's asssessment of allocations.
  7. We print the 50th fib.

Note: we implement our own !! just because the real !! uses <# for a check; I've implemented a few primops for testing/demonstration purposes, but plan to derive the bulk of primops with an automated process.

chris@precision:~/Work/chrisdone/prana$ sh regenerate.sh
+ stack build --test --no-run-tests
prana-ghc-8.4: Test running disabled by --no-run-tests flag.
Log files have been written to: /home/chris/Work/chrisdone/prana/.stack-work/logs/
+ rm -r /home/chris/Work/chrisdone/prana/prana-dir/
+ mkdir -p /home/chris/Work/chrisdone/prana/prana-dir/packages/
+ cd /home/chris/Work/chrisdone/prana/ghc-8.4/libraries/ghc-prim/
+ PRANA_DIR=/home/chris/Work/chrisdone/prana/prana-dir/ PRANA_MODE=INSTALL time -p -- ./Setup build --ghc-options=-O0
Preprocessing library for ghc-prim-0.5.2.0..
Building library for ghc-prim-0.5.2.0..
[1 of 8] Compiling GHC.Types
[2 of 8] Compiling GHC.IntWord64
[3 of 8] Compiling GHC.CString
[4 of 8] Compiling GHC.Tuple
[5 of 8] Compiling GHC.PrimopWrappers
[6 of 8] Compiling GHC.Debug
[7 of 8] Compiling GHC.Magic
[8 of 8] Compiling GHC.Classes
[1 of 8] Converting GHC.Types
[2 of 8] Converting GHC.IntWord64
[3 of 8] Converting GHC.CString
[4 of 8] Converting GHC.Tuple
[5 of 8] Converting GHC.PrimopWrappers
[6 of 8] Converting GHC.Debug
[7 of 8] Converting GHC.Magic
[8 of 8] Converting GHC.Classes
Updating index ...
Writing library ghc-prim ...
ignoring (possibly broken) abi-depends field for packages
real 3.08
user 2.89
sys 0.18
+ cd ../integer-gmp/
+ PRANA_DIR=/home/chris/Work/chrisdone/prana/prana-dir/ PRANA_MODE=INSTALL time -p -- ./Setup build --ghc-options=-O0
Preprocessing library for integer-gmp-1.0.2.0..
Building library for integer-gmp-1.0.2.0..
[1 of 5] Compiling GHC.Integer.Type
[2 of 5] Compiling GHC.Integer.Logarithms
[3 of 5] Compiling GHC.Integer.Logarithms.Internals
[4 of 5] Compiling GHC.Integer
[5 of 5] Compiling GHC.Integer.GMP.Internals
[1 of 5] Converting GHC.Integer.Type
[2 of 5] Converting GHC.Integer.Logarithms
[3 of 5] Converting GHC.Integer.Logarithms.Internals
[4 of 5] Converting GHC.Integer
[5 of 5] Converting GHC.Integer.GMP.Internals
Updating index ...
Writing library integer-gmp ...
ignoring (possibly broken) abi-depends field for packages
real 0.80
user 0.67
sys 0.11
+ cd ../base-4.11.1.0/
+ PRANA_DIR=/home/chris/Work/chrisdone/prana/prana-dir/ PRANA_MODE=INSTALL time -p -- ./Setup build --ghc-options=-O0
Preprocessing library for base-4.11.1.0..
Building library for base-4.11.1.0..
[1 of 244] Compiling GHC.Base
...
[244 of 244] Compiling Data.Complex
[1 of 244] Converting GHC.Base
...
[241 of 244] Converting Data.Functor.Product
[242 of 244] Converting Data.Functor.Compose
[243 of 244] Converting Data.Fixed
[244 of 244] Converting Data.Complex
Updating index ...
Writing library base ...
ignoring (possibly broken) abi-depends field for packages
real 11.92
user 11.38
sys 0.56
chris@precision:~/Work/chrisdone/prana$ ls prana-dir -Ralh
prana-dir:
total 14M
drwxrwxr-x 3 chris chris 4.0K Apr 24 09:25 .
drwxrwxr-x 8 chris chris 4.0K Apr 24 09:25 ..
-rw-rw-r-- 1 chris chris 14M Apr 24 09:25 index
drwxrwxr-x 2 chris chris 4.0K Apr 24 09:25 packages
prana-dir/packages:
total 6.9M
drwxrwxr-x 2 chris chris 4.0K Apr 24 09:25 .
drwxrwxr-x 3 chris chris 4.0K Apr 24 09:25 ..
-rw-rw-r-- 1 chris chris 4.3M Apr 24 09:25 base.prana
-rw-rw-r-- 1 chris chris 2.5M Apr 24 09:25 ghc-prim.prana
-rw-rw-r-- 1 chris chris 164K Apr 24 09:25 integer-gmp.prana
-- Input file:
module Fib (it) where
fibs :: [Int]
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
(!!) :: [a] -> Int -> a
xs !! n =
foldr
(\x r k ->
case k of
0 -> x
_ -> r (k - 1))
(error "too large")
xs
n
it :: Int
it = fibs Fib.!! 49
chris@precision:~/Work/chrisdone/prana$ PRANA_MODE=DEV PRANA_DIR=~/Work/chrisdone/prana/prana-dir/ stack test prana-ghc --test-arguments "+RTS -T -RTS" --file-watch
prana-ghc-8.4: test (suite: prana-test, args: +RTS -T -RTS)
[1 of 1] Compiling Fib
[1 of 1] Converting Fib
Loading library ghc-prim ...
Loading library integer-gmp ...
Loading library base ...
main:Fib.it =
579.74 us
(ghc-prim:GHC.Types.I# (IntLit 12586269025))
Case Allocated GCs Max
Eval 1,730,832 1 0
prana-ghc-8.4: Test suite prana-test passed
ExitSuccess
Type help for available commands. Press enter to force a rebuild.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment