Skip to content

Instantly share code, notes, and snippets.

@AndreasPK
AndreasPK / Lib.hs
Last active February 18, 2023 23:29
Unknown call overhead.
module Lib where
import Data.Vector as V
type LookupCached a = Int -> a
mkCache :: [a] -> LookupCached a
mkCache xs =
let !cache = V.fromList xs
in V.unsafeIndex cache
@AndreasPK
AndreasPK / Array.hs
Created August 2, 2022 18:26
Cursed Mixed Array
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedDatatypes #-}
module Main where
import GHC.Exts
import GHC.IO
import Unsafe.Coerce
import Data.Kind
-- -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 #-}
@AndreasPK
AndreasPK / GEither.hs
Created July 29, 2021 13:23
GADT map stuff
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
{- | 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 #-}
==================== 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}
# 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 January 23, 2020 11:17
Compile a String to a CoreExpr
module Main where
import GHC
import CoreSyn
import Inst
import Desugar
import TcRnMonad
import TcHsSyn
import RnExpr
import GhcMonad
@AndreasPK
AndreasPK / gist:14bd8376fb48e27b0858d57270e2a956
Created October 15, 2019 16:50
ghc performance diffs 8.6.5 vs 8.8 vs 8.10*(patch branch)
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)
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] -> ()