Skip to content

Instantly share code, notes, and snippets.

@alpmestan

alpmestan/Foo.hs Secret

Last active January 24, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpmestan/145fc5783f00bab9214b7302418aef49 to your computer and use it in GitHub Desktop.
Save alpmestan/145fc5783f00bab9214b7302418aef49 to your computer and use it in GitHub Desktop.
-- this is the input file we're processing
module Foo where
{-# ANN module () #-}
-- ... many things ...
convertAnnotationWrapper :: ForeignHValue -> TcM (Either MsgDoc Serialized)
convertAnnotationWrapper fhv = do
liftIO (putStrLn "§§§ in convertAnnotationWrapper")
dflags <- getDynFlags
liftIO (putStrLn "§§§ got the dynflag")
if gopt Opt_ExternalInterpreter dflags
then do
liftIO (putStrLn "§§§ we have an external interpreter") >> (Right <$> runTH THAnnWrapper fhv)
else do
liftIO (putStrLn "§§§ no external interpreter!")
annotation_wrapper <- liftIO $ wormhole dflags fhv
liftIO (putStrLn "§§§ after wormhole, about to return")
let serialized_data = case unsafeCoerce# annotation_wrapper of
AnnotationWrapper value | let serialized = toSerialized serializeWithData value ->
-- Got the value and dictionaries: build the serialized value and
-- call it a day. We ensure that we seq the entire serialized value
-- in order that any errors in the user-written code for the
-- annotation are exposed at this point. This is also why we are
-- doing all this stuff inside the context of runMeta: it has the
-- facilities to deal with user error in a meta-level expression
seqSerialized serialized `seq` serialized
liftIO (evaluate serialized_data)
liftIO (putStrLn "§§§ unsafeCoerce# went fine, leaving convertAnnotationWrapper")
return $ Right serialized_data
-- ... many other things ...
[... a lot of things before ...]
§§§ in convertAnnotationWrapper
§§§ got the dynflag
§§§ no external interpreter!
§§§ after wormhole, about to return
Segmentation fault (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment