Last active
June 20, 2018 19:09
-
-
Save ndmitchell/54e58f23613bc074b79e9e915dec03bf to your computer and use it in GitHub Desktop.
GHC optimisation differences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output from GhcApi.hs | |
s1 :: Addr# | |
[GblId, Caf=NoCafRefs] | |
s1 = "test"# | |
s2 :: [Char] | |
[GblId] | |
s2 = unpackCString# s1 | |
s3 :: Record | |
[GblId] | |
s3 = Record s2 | |
pick :: String | |
[GblId] | |
pick = case s3 of { Record ds -> ds } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output from ghc -ddump-simpl | |
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} | |
LensOpt.pick1 :: GHC.Prim.Addr# | |
[GblId, | |
Caf=NoCafRefs, | |
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, | |
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 20 0}] | |
LensOpt.pick1 = "test"# | |
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} | |
pick :: String | |
[GblId, | |
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=True, | |
WorkFree=False, Expandable=True, Guidance=IF_ARGS [] 20 0}] | |
pick = GHC.CString.unpackCString# LensOpt.pick1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Program used to compile LensOpt.hs using the GHC API | |
import GHC | |
import GhcPlugins | |
import GHC.Paths | |
main = runGhc (Just libdir) $ do | |
setTargets [] | |
dflags <- getSessionDynFlags | |
setSessionDynFlags dflags{hscTarget = HscNothing} | |
res <- compileToCoreSimplified "LensOpt.hs" | |
liftIO $ writeFile "lens_api.txt" $ showSDoc dflags $ ppr res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Program under test that I would like optimising | |
{-# OPTIONS_GHC -O2 #-} | |
module LensOpt(pick) where | |
import Control.Lens | |
data Record = Record {_field :: String} | |
field = lens _field $ \r x -> r{_field=x} | |
pick = Record "test" ^. field |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment