packages feed

wherefrom-compat 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+50/−9 lines, 4 files

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for wherefrom-compat +## 0.1.1.0 -- 2024/02/01++* Fix interface around srcFile/srcSpan.+ ## 0.1.0.0 -- 2024/02/01  * First version. Released on an unsuspecting world.
src/GHC/InfoProv/Compat.hs view
@@ -9,7 +9,45 @@ #if MIN_VERSION_base(4,18,0) import GHC.InfoProv (InfoProv(..), whereFrom) #elif MIN_VERSION_base(4,17,0)-import GHC.Stack.CCS (InfoProv(..), whereFrom)+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 <- CCS.whereFrom v+  pure $ do+    ip <- xs+    -- srcFileSpan has the format: `test/Spec.hs:12:1-11`+    (srcFile, _:srcSpan) <- Just . break (== ':') $ CCS.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+       , ipSrcFile = srcFile+       , ipSrcSpan = srcSpan+       } #else import qualified GHC.Stack.CCS as CCS @@ -26,7 +64,7 @@  -- | Get information about where a value originated from. ----- This information is stored statically in a binary when @-finfo-table-map@ is enabled.+-- 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. --@@ -36,7 +74,9 @@ whereFrom v = do   xs <- CCS.whereFrom v   pure $ do-    [name, desc, tyDesc, label, modName, srcFile, srcSpan] <- Just xs+    [name, desc, tyDesc, label, modName, srcFileSpan] <- Just xs+    -- srcFileSpan has the format: `test/Spec.hs:12:1-11`+    (srcFile, _:srcSpan) <- Just $ break (== ':') srcFileSpan     Just $       InfoProv        { ipName = name
test/Spec.hs view
@@ -1,3 +1,4 @@+module Main (main) where import Test.Tasty import Test.Tasty.HUnit @@ -6,13 +7,9 @@ main :: IO () main = defaultMain tests --foo :: String-foo = "foo"- tests :: TestTree tests = testGroup "Tests"   [ testCase "whereFrom works" $ do-     v <- whereFrom foo+     v <- whereFrom main      assertBool "whereFrom shouldn't be Nothing" $ v /= Nothing   ]
wherefrom-compat.cabal view
@@ -1,6 +1,6 @@ cabal-version:   3.0 name:            wherefrom-compat-version:         0.1.0.0+version:         0.1.1.0 synopsis:        A compatibility layer for GHC's 'wherefrom' function description:   A compatibility layer for GHC's 'wherefrom' function,