packages feed

wherefrom-compat (empty) → 0.1.0.0

raw patch · 5 files changed

+150/−0 lines, 5 filesdep +basedep +tastydep +tasty-hunit

Dependencies added: base, tasty, tasty-hunit, wherefrom-compat

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for wherefrom-compat++## 0.1.0.0 -- 2024/02/01++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) 2023, Teo Camarasu+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the+   distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ src/GHC/InfoProv/Compat.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE CPP #-}+-- | This module provides a stable interface to access GHC's info provenance information.+-- This is helpful for seeing metadata about heap objects.+module GHC.InfoProv.Compat+  ( InfoProv(..)+  , whereFrom+  ) where++#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)+#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 @-finfo-table-map@ 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+    [name, desc, tyDesc, label, modName, srcFile, srcSpan] <- Just xs+    Just $+      InfoProv+       { ipName = name+       , ipDesc = desc+       , ipTyDesc = tyDesc+       , ipLabel = label+       , ipMod = modName+       , ipSrcFile = srcFile+       , ipSrcSpan = srcSpan+       }+#endif
+ test/Spec.hs view
@@ -0,0 +1,18 @@+import Test.Tasty+import Test.Tasty.HUnit++import GHC.InfoProv.Compat++main :: IO ()+main = defaultMain tests+++foo :: String+foo = "foo"++tests :: TestTree+tests = testGroup "Tests"+  [ testCase "whereFrom works" $ do+     v <- whereFrom foo+     assertBool "whereFrom shouldn't be Nothing" $ v /= Nothing+  ]
+ wherefrom-compat.cabal view
@@ -0,0 +1,51 @@+cabal-version:   3.0+name:            wherefrom-compat+version:         0.1.0.0+synopsis:        A compatibility layer for GHC's 'wherefrom' function+description:+  A compatibility layer for GHC's 'wherefrom' function,+  which exposes info provenance information.+  Each major version of this library exports +  a different version of this interface.++license:         BSD-2-Clause+license-file:    LICENSE+author:          Teo Camarasu+maintainer:      teofilcamarasu@gmail.com+copyright:       The wherefrom-compat contributors+build-type:      Simple+extra-doc-files: CHANGELOG.md+bug-reports:     https://codeberg.org/teo/wherefrom-compat/issues+category:        Compatibility+tested-with:     +  GHC ==9.2.8 +  ||  ==9.4.7 +  ||  ==9.6.3 +  ||  ==9.8.1++common warnings+  ghc-options: -Wall++library+  import:           warnings+  exposed-modules:  GHC.InfoProv.Compat+  build-depends:    base >=4.16.0.0 && <4.20.0.0+  hs-source-dirs:   src+  default-language: Haskell2010++test-suite test+  type:             exitcode-stdio-1.0+  hs-source-dirs:   test+  ghc-options:      -finfo-table-map+  main-is:          Spec.hs+  build-depends:+    , base+    , tasty             ^>=1.5+    , tasty-hunit       ^>=0.10+    , wherefrom-compat++  default-language: Haskell2010++source-repository head+  type:     git+  location: https://codeberg.org/teo/wherefrom-compat.git