wherefrom-compat 0.1.1.1 → 0.2.0.0
raw patch · 3 files changed
+65/−50 lines, 3 filesdep +ghc-heap
Dependencies added: ghc-heap
Files
- CHANGELOG.md +5/−0
- src/GHC/InfoProv/Compat.hs +56/−48
- wherefrom-compat.cabal +4/−2
CHANGELOG.md view
@@ -1,6 +1,11 @@ # Revision history for wherefrom-compat +## 0.2.0.0 -- 2024/05/24++* Migrate to new base-4.20 version of the InfoProv API.+ ## 0.1.1.1 -- 2024/05/24+ * Support GHC-9.10 ## 0.1.1.0 -- 2024/02/01
src/GHC/InfoProv/Compat.hs view
@@ -5,20 +5,26 @@ ( InfoProv(..) , whereFrom ) where--#if MIN_VERSION_base(4,20,0)+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 {- ipName :: String,- ipDesc :: String,- ipTyDesc :: String,- ipLabel :: String,- ipMod :: String,- ipSrcFile :: String,- ipSrcSpan :: String-} deriving (Eq, Show)+data InfoProv = InfoProv + { ipName :: String+ , ipDesc :: ClosureType+ , ipTyDesc :: String+ , ipLabel :: String+ , ipUnitId :: String+ , ipMod :: String+ , ipSrcFile :: String+ , ipSrcSpan :: String+ } + deriving (Eq, Show) +#if MIN_VERSION_base(4,20,0) -- | Get information about where a value originated from. --@@ -36,29 +42,42 @@ Just $ InfoProv { ipName = IP.ipName ip- , ipDesc = show . fromEnum $ IP.ipDesc 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)-import GHC.InfoProv (InfoProv(..), whereFrom)-#elif MIN_VERSION_base(4,17,0)-import qualified GHC.Stack.CCS as CCS -data InfoProv = InfoProv {- ipName :: String,- ipDesc :: String,- ipTyDesc :: String,- ipLabel :: String,- ipMod :: String,- ipSrcFile :: String,- ipSrcSpan :: String-} deriving (Eq, Show)-+-- | Get information about where a value originated from.+--+-- This information is stored statically in a binary when @super-duper@ is enabled.+-- The source positions will be greatly improved by also enabled debug information with @-g3@.+-- Finally you can enable @-fdistinct-constructor-tables@ to get more precise information about data constructor allocations.+--+-- The information is collect by looking at the info table address of a specific closure and then consulting a specially generated map (by @-finfo-table-map@)+-- to find out where we think the best source position to describe that info table arose from.+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 = "" -- not present before base-4.20+ , ipMod = IP.ipMod ip+ , ipSrcFile = IP.ipSrcFile ip+ , ipSrcSpan = IP.ipSrcSpan ip+ }+#elif MIN_VERSION_base(4,17,0) -- | Get information about where a value originated from. --@@ -70,36 +89,24 @@ -- to find out where we think the best source position to describe that info table arose from. whereFrom :: a -> IO (Maybe InfoProv) whereFrom v = do- xs <- CCS.whereFrom v+ xs <- IP.whereFrom v pure $ do ip <- xs -- srcFileSpan has the format: `test/Spec.hs:12:1-11`- (srcFile, _:srcSpan) <- Just . break (== ':') $ CCS.ipLoc ip+ (srcFile, _:srcSpan) <- Just . break (== ':') $ IP.ipLoc ip Just $ InfoProv- { ipName = CCS.ipName ip- , ipDesc = CCS.ipDesc ip- , ipTyDesc = CCS.ipTyDesc ip- , ipLabel = CCS.ipLabel ip- , ipMod = CCS.ipMod ip- -- the following fields are not available in this version of base+ { ipName = IP.ipName ip+ , ipDesc = toEnum . read $ IP.ipDesc ip+ , ipTyDesc = IP.ipTyDesc ip+ , ipLabel = IP.ipLabel ip+ , ipUnitId = "" -- not present before base-4.20+ , ipMod = IP.ipMod ip , ipSrcFile = srcFile , ipSrcSpan = srcSpan } #else-import qualified GHC.Stack.CCS as CCS -data InfoProv = InfoProv {- ipName :: String,- ipDesc :: String,- ipTyDesc :: String,- ipLabel :: String,- ipMod :: String,- ipSrcFile :: String,- ipSrcSpan :: String-} deriving (Eq, Show)-- -- | Get information about where a value originated from. -- -- This information is stored statically in a binary when @super-duper@ is enabled.@@ -110,17 +117,18 @@ -- to find out where we think the best source position to describe that info table arose from. whereFrom :: a -> IO (Maybe InfoProv) whereFrom v = do- xs <- CCS.whereFrom v+ xs <- IP.whereFrom v pure $ do [name, desc, tyDesc, label, modName, srcFileSpan] <- Just xs -- srcFileSpan has the format: `test/Spec.hs:12:1-11`- (srcFile, _:srcSpan) <- Just $ break (== ':') srcFileSpan+ (srcFile, _:srcSpan) <- Just . break (== ':') $ srcFileSpan Just $ InfoProv { ipName = name- , ipDesc = desc+ , ipDesc = toEnum . read $ desc , ipTyDesc = tyDesc , ipLabel = label+ , ipUnitId = "" -- not present before base-4.20 , ipMod = modName , ipSrcFile = srcFile , ipSrcSpan = srcSpan
wherefrom-compat.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: wherefrom-compat-version: 0.1.1.1+version: 0.2.0.0 synopsis: A compatibility layer for GHC's 'wherefrom' function description: A compatibility layer for GHC's 'wherefrom' function,@@ -30,7 +30,9 @@ library import: warnings exposed-modules: GHC.InfoProv.Compat- build-depends: base >=4.16.0.0 && <4.21.0.0+ build-depends: + base >=4.16.0.0 && <4.21.0.0+ , ghc-heap >=9.2 && <9.12 hs-source-dirs: src default-language: Haskell2010