Hannes Siebenhandl pushed to branch wip/fendor/hpc-bc-support at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • compiler/GHC/ByteCode/Types.hs
    ... ... @@ -55,6 +55,7 @@ import GHCi.ResolvedBCO ( BCOByteArray(..), mkBCOByteArray )
    55 55
     
    
    56 56
     import Foreign
    
    57 57
     import Data.ByteString (ByteString)
    
    58
    +import Data.ByteString.Short (ShortByteString)
    
    58 59
     import qualified GHC.Exts.Heap as Heap
    
    59 60
     import GHC.Cmm.Expr ( GlobalRegSet, emptyRegSet, regSetToList )
    
    60 61
     import GHC.Unit.Module
    
    ... ... @@ -97,9 +98,9 @@ data CompiledByteCode = CompiledByteCode
    97 98
     -- for example the 'CgInteractiveGuts' from which 'ByteCodeHpcInfo' can be
    
    98 99
     -- derived from
    
    99 100
     data ByteCodeHpcInfo = ByteCodeHpcInfo
    
    100
    -  { bchi_module_name :: !String
    
    101
    +  { bchi_module_name :: !ShortByteString
    
    101 102
       -- ^ Name of the module.
    
    102
    -  , bchi_tickbox_name :: !String
    
    103
    +  , bchi_tickbox_name :: !ShortByteString
    
    103 104
       -- ^ Name of the tick box that has been added via 'CStub'.
    
    104 105
       , bchi_tick_count :: {-# UNPACK #-} !Int
    
    105 106
       -- ^ Number of ticks.
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -252,6 +252,7 @@ import GHC.Types.TyThing
    252 252
     import GHC.Types.Unique.Supply ( uniqFromTag, UniqueTag(BcoTag) )
    
    253 253
     import GHC.Types.Unique.Set
    
    254 254
     
    
    255
    +import GHC.Utils.Encoding.UTF8 ( utf8EncodeShortByteString )
    
    255 256
     import GHC.Utils.Fingerprint ( Fingerprint )
    
    256 257
     import GHC.Utils.Panic
    
    257 258
     import GHC.Utils.Error
    
    ... ... @@ -2210,8 +2211,8 @@ hscGenerateByteCode hsc_env cgguts location = do
    2210 2211
               Strict.Just ByteCodeHpcInfo
    
    2211 2212
                 { bchi_tick_count = hpcInfoTickCount
    
    2212 2213
                 , bchi_hash = hpcInfoHash
    
    2213
    -            , bchi_tickbox_name = Coverage.mkHpcTickLabel platform this_mod
    
    2214
    -            , bchi_module_name = Coverage.mkHpcModuleLabel this_mod
    
    2214
    +            , bchi_tickbox_name = utf8EncodeShortByteString $ Coverage.mkHpcTickLabel platform this_mod
    
    2215
    +            , bchi_module_name = utf8EncodeShortByteString $ Coverage.mkHpcModuleLabel this_mod
    
    2215 2216
                 }
    
    2216 2217
     
    
    2217 2218
         -----------------  Generate byte code ------------------
    

  • compiler/GHC/Runtime/Interpreter.hs
    ... ... @@ -374,7 +374,7 @@ addSptEntry interp fpr ref =
    374 374
       withForeignRef ref $ \val ->
    
    375 375
         interpCmd interp (AddSptEntry fpr val)
    
    376 376
     
    
    377
    -addHpcModule :: Interp -> String -> Int -> Int -> String -> IO ()
    
    377
    +addHpcModule :: Interp -> SBS.ShortByteString -> Int -> Int -> SBS.ShortByteString -> IO ()
    
    378 378
     addHpcModule interp modLabel tickNo hash tickboxes  =
    
    379 379
       interpCmd interp (AddHpcModule modLabel tickNo hash tickboxes)
    
    380 380
     
    

  • libraries/ghci/GHCi/Coverage.hs
    ... ... @@ -8,10 +8,12 @@ module GHCi.Coverage (
    8 8
     import Prelude -- See note [Why do we import Prelude here?]
    
    9 9
     
    
    10 10
     import Control.Exception
    
    11
    +import Data.ByteString.Short (ShortByteString)
    
    12
    +import qualified Data.ByteString.Short as SBS
    
    11 13
     import Data.Word
    
    12 14
     import Foreign
    
    13
    -import Foreign.C.String (withCAString)
    
    14 15
     import GHC.Foreign (CString)
    
    16
    +import GHC.Utils.Encoding.UTF8 (utf8DecodeShortByteString)
    
    15 17
     import GHCi.ObjLink (lookupSymbol)
    
    16 18
     
    
    17 19
     -- | Inform the run-time system that the given module name is instrumented via @hpc@
    
    ... ... @@ -19,22 +21,22 @@ import GHCi.ObjLink (lookupSymbol)
    19 21
     --
    
    20 22
     -- Starts the `hpc` run-time if it hasn't already been started.
    
    21 23
     hpcAddModule ::
    
    22
    -  String ->
    
    24
    +  ShortByteString ->
    
    23 25
       -- ^ Name of the module to instrument
    
    24 26
       Int ->
    
    25 27
       -- ^ Number of hpc ticks in this module
    
    26 28
       Int ->
    
    27 29
       -- ^ 'HpcInfo's 'hpcInfoHash'
    
    28
    -  String ->
    
    30
    +  ShortByteString ->
    
    29 31
       -- ^ Name of the ticks array found in the c-stub.
    
    30 32
       IO ()
    
    31 33
     hpcAddModule modlName ticks hash tickboxes = do
    
    32
    -  withCAString modlName $ \modlNameLiteral -> do
    
    34
    +  SBS.useAsCString modlName $ \modlNameLiteral -> do
    
    33 35
         -- we need to find the reference to the ticks array.
    
    34 36
         lookupSymbol tickboxes >>= \ case
    
    35 37
           Nothing -> do
    
    36 38
             -- the symbol is not found, this is a bug!
    
    37
    -        throwIO $ ErrorCall $ "hpcAddModule: failed to find symbol " <> tickboxes
    
    39
    +        throwIO $ ErrorCall $ "hpcAddModule: failed to find symbol " <> utf8DecodeShortByteString tickboxes
    
    38 40
           Just tickBoxRef -> do
    
    39 41
             -- Calling 'hs_hpc_module' multiple times is safe, it will add the module only once.
    
    40 42
             hpc_register_module modlNameLiteral (fromIntegral ticks) (fromIntegral hash) (castPtr tickBoxRef)
    

  • libraries/ghci/GHCi/Message.hs
    ... ... @@ -112,7 +112,7 @@ data Message a where
    112 112
       -- | Add entries to the Static Pointer Table
    
    113 113
       AddSptEntry :: Fingerprint -> HValueRef -> Message ()
    
    114 114
       -- | Add module to hpc
    
    115
    -  AddHpcModule :: String -> Int -> Int -> String -> Message ()
    
    115
    +  AddHpcModule :: BS.ShortByteString -> Int -> Int -> BS.ShortByteString -> Message ()
    
    116 116
     
    
    117 117
       -- | Malloc some data and return a 'RemotePtr' to it
    
    118 118
       MallocData :: ByteString -> Message (RemotePtr ())