Skip to content

Instantly share code, notes, and snippets.

@AndreasPK
AndreasPK / Array.hs
Created Aug 2, 2022
Cursed Mixed Array
View Array.hs
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedDatatypes #-}
module Main where
import GHC.Exts
import GHC.IO
import Unsafe.Coerce
import Data.Kind
View FloatOutExample.hs
-- -fno-worker-wrapper -dno-typeable-binds just makes the resulting dump easier to understand.
-- Try uncommenting the second OPTIONS pragma to see the difference float out makes.
{-# OPTIONS_GHC -O -fno-worker-wrapper -ddump-simpl -dsuppress-all -ddump-to-file -fforce-recomp #-}
-- {-# OPTIONS_GHC -fno-full-laziness #-}
module Main(main,g) where
import GHC.Exts
{-# NOINLINE f #-}
View GEither.hs
data Side = LeftSide | RightSide
data GEither c a b where
GLeft :: a -> GEither 'LeftSide a b
GRight :: b -> GEither 'RightSide a b
data LVal = LVal Int
data RVal = RVal Int
data LeftRightMap where
View Packing
{- | Pack types of a known size into as few bytes as possible.
We do so by assigning each instance of the Packable class
a 'Width' in bits.
When combining types we add up their widths using type level computation.
-}
{-# LANGUAGE TypeFamilies #-}
View muchCoreSuchWow.hs
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 17,361, types: 21,327, coercions: 5,089, joins: 99/404}
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
$trModule2 = "Load"#
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
View Download hackage
# First get a list of all packages
cabal list --simple | tee packages.list
# Then compute the locations of their tar files
python3 -c "from fileinput import *; [print(\"https://hackage.haskell.org/package/\"+p+\"/\"+p+\"-\"+ver+\".tar.gz\") for (p,ver) in sorted(dict(map(str.split, input())).items())]" < packages.list | tee files.list
# If you are on windows make sure python didn't use CRLF:
# dos2unix files.list
# Download all the archives - 4 at a time. Some might fail, that is expected.
@AndreasPK
AndreasPK / GHC String->Core
Created Jan 23, 2020
Compile a String to a CoreExpr
View GHC String->Core
module Main where
import GHC
import CoreSyn
import Inst
import Desugar
import TcRnMonad
import TcHsSyn
import RnExpr
import GhcMonad
@AndreasPK
AndreasPK / gist:14bd8376fb48e27b0858d57270e2a956
Created Oct 15, 2019
ghc performance diffs 8.6.5 vs 8.8 vs 8.10*(patch branch)
View gist:14bd8376fb48e27b0858d57270e2a956
Andi@Horzube MINGW64 /e/pan-os-syslog
$ cabal new-run bench -w /e/ghc_layout/_quick/stage1/bin/ghc.exe --allow-newer="*"
Up to date
benchmarking 8-1-Traffic-A ...
benchmarked 8-1-Traffic-A
time 626.4 ns (611.3 ns .. 647.4 ns)
0.987 R² (0.971 R² .. 0.997 R²)
mean 618.7 ns (610.2 ns .. 634.3 ns)
std dev 38.10 ns (25.20 ns .. 65.38 ns)
variance introduced by outliers: 39% (moderately inflated)
View matchFailure.hs
compiler\nativeGen\X86\CodeGen.hs:169:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for `verifyBasicBlock':
Patterns not matched: _ :: [Instr]
|
169 | verifyBasicBlock instrs
-- Verifying basic blocks is cheap, but not cheap enough to enable it unconditionally.
verifyBasicBlock :: [Instr] -> ()
View gist:42cdc931ec29b2ce4cc6b551093e9407
Tue Aug 27 19:56 2019 Time and Allocation Profiling Report (Final)
ghc.exe +RTS -p -RTS Main.hs --make -O -fforce-recomp
total time = 7.72 secs (7721 ticks @ 1000 us, 1 processor)
total alloc = 9,747,651,160 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
simplIdF Simplify compiler\simplCore\Simplify.hs:899:61-79 16.9 18.1