{-# LANGUAGE CPP #-}
module GHC.InfoProv.Compat
( InfoProv(..)
, whereFrom
) where
import GHC.Exts.Heap.ClosureTypes
#if MIN_VERSION_base(4,18,0)
import qualified GHC.InfoProv as IP
#else
import qualified GHC.Stack.CCS as IP
#endif
data InfoProv = InfoProv
{ InfoProv -> String
ipName :: String
, InfoProv -> ClosureType
ipDesc :: ClosureType
, InfoProv -> String
ipTyDesc :: String
, InfoProv -> String
ipLabel :: String
, InfoProv -> String
ipUnitId :: String
, InfoProv -> String
ipMod :: String
, InfoProv -> String
ipSrcFile :: String
, InfoProv -> String
ipSrcSpan :: String
}
deriving (InfoProv -> InfoProv -> Bool
(InfoProv -> InfoProv -> Bool)
-> (InfoProv -> InfoProv -> Bool) -> Eq InfoProv
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InfoProv -> InfoProv -> Bool
== :: InfoProv -> InfoProv -> Bool
$c/= :: InfoProv -> InfoProv -> Bool
/= :: InfoProv -> InfoProv -> Bool
Eq, Int -> InfoProv -> ShowS
[InfoProv] -> ShowS
InfoProv -> String
(Int -> InfoProv -> ShowS)
-> (InfoProv -> String) -> ([InfoProv] -> ShowS) -> Show InfoProv
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InfoProv -> ShowS
showsPrec :: Int -> InfoProv -> ShowS
$cshow :: InfoProv -> String
show :: InfoProv -> String
$cshowList :: [InfoProv] -> ShowS
showList :: [InfoProv] -> ShowS
Show)
#if MIN_VERSION_base(4,20,0)
whereFrom :: a -> IO (Maybe InfoProv)
whereFrom :: forall a. a -> IO (Maybe InfoProv)
whereFrom a
v = do
xs <- a -> IO (Maybe InfoProv)
forall a. a -> IO (Maybe InfoProv)
IP.whereFrom a
v
pure $ do
ip <- xs
Just $
InfoProv
{ ipName = IP.ipName ip
, ipDesc = IP.ipDesc ip
, ipTyDesc = IP.ipTyDesc ip
, ipLabel = IP.ipLabel ip
, ipUnitId = IP.ipUnitId ip
, ipMod = IP.ipMod ip
, ipSrcFile = IP.ipSrcFile ip
, ipSrcSpan = IP.ipSrcSpan ip
}
#elif MIN_VERSION_base(4,18,0)
whereFrom :: a -> IO (Maybe InfoProv)
whereFrom v = do
xs <- IP.whereFrom v
pure $ do
ip <- xs
Just $
InfoProv
{ ipName = IP.ipName ip
, ipDesc = toEnum . read $ IP.ipDesc ip
, ipTyDesc = IP.ipTyDesc ip
, ipLabel = IP.ipLabel ip
, ipUnitId = ""
, ipMod = IP.ipMod ip
, ipSrcFile = IP.ipSrcFile ip
, ipSrcSpan = IP.ipSrcSpan ip
}
#elif MIN_VERSION_base(4,17,0)
whereFrom :: a -> IO (Maybe InfoProv)
whereFrom v = do
xs <- IP.whereFrom v
pure $ do
ip <- xs
(srcFile, _:srcSpan) <- Just . break (== ':') $ IP.ipLoc ip
Just $
InfoProv
{ ipName = IP.ipName ip
, ipDesc = toEnum . read $ IP.ipDesc ip
, ipTyDesc = IP.ipTyDesc ip
, ipLabel = IP.ipLabel ip
, ipUnitId = ""
, ipMod = IP.ipMod ip
, ipSrcFile = srcFile
, ipSrcSpan = srcSpan
}
#else
whereFrom :: a -> IO (Maybe InfoProv)
whereFrom v = do
xs <- IP.whereFrom v
pure $ do
[name, desc, tyDesc, label, modName, srcFileSpan] <- Just xs
(srcFile, _:srcSpan) <- Just . break (== ':') $ srcFileSpan
Just $
InfoProv
{ ipName = name
, ipDesc = toEnum . read $ desc
, ipTyDesc = tyDesc
, ipLabel = label
, ipUnitId = ""
, ipMod = modName
, ipSrcFile = srcFile
, ipSrcSpan = srcSpan
}
#endif