[Git][ghc/ghc][wip/fendor/hpc-bc-support] fixup later
Hannes Siebenhandl pushed to branch wip/fendor/hpc-bc-support at Glasgow Haskell Compiler / GHC Commits: 8cd628b0 by fendor at 2026-04-09T10:09:56+02:00 fixup later - - - - - 5 changed files: - compiler/GHC/ByteCode/Types.hs - compiler/GHC/Driver/Main.hs - compiler/GHC/Runtime/Interpreter.hs - libraries/ghci/GHCi/Coverage.hs - libraries/ghci/GHCi/Message.hs Changes: ===================================== compiler/GHC/ByteCode/Types.hs ===================================== @@ -55,6 +55,7 @@ import GHCi.ResolvedBCO ( BCOByteArray(..), mkBCOByteArray ) import Foreign import Data.ByteString (ByteString) +import Data.ByteString.Short (ShortByteString) import qualified GHC.Exts.Heap as Heap import GHC.Cmm.Expr ( GlobalRegSet, emptyRegSet, regSetToList ) import GHC.Unit.Module @@ -97,9 +98,9 @@ data CompiledByteCode = CompiledByteCode -- for example the 'CgInteractiveGuts' from which 'ByteCodeHpcInfo' can be -- derived from data ByteCodeHpcInfo = ByteCodeHpcInfo - { bchi_module_name :: !String + { bchi_module_name :: !ShortByteString -- ^ Name of the module. - , bchi_tickbox_name :: !String + , bchi_tickbox_name :: !ShortByteString -- ^ Name of the tick box that has been added via 'CStub'. , bchi_tick_count :: {-# UNPACK #-} !Int -- ^ Number of ticks. ===================================== compiler/GHC/Driver/Main.hs ===================================== @@ -252,6 +252,7 @@ import GHC.Types.TyThing import GHC.Types.Unique.Supply ( uniqFromTag, UniqueTag(BcoTag) ) import GHC.Types.Unique.Set +import GHC.Utils.Encoding.UTF8 ( utf8EncodeShortByteString ) import GHC.Utils.Fingerprint ( Fingerprint ) import GHC.Utils.Panic import GHC.Utils.Error @@ -2210,8 +2211,8 @@ hscGenerateByteCode hsc_env cgguts location = do Strict.Just ByteCodeHpcInfo { bchi_tick_count = hpcInfoTickCount , bchi_hash = hpcInfoHash - , bchi_tickbox_name = Coverage.mkHpcTickLabel platform this_mod - , bchi_module_name = Coverage.mkHpcModuleLabel this_mod + , bchi_tickbox_name = utf8EncodeShortByteString $ Coverage.mkHpcTickLabel platform this_mod + , bchi_module_name = utf8EncodeShortByteString $ Coverage.mkHpcModuleLabel this_mod } ----------------- Generate byte code ------------------ ===================================== compiler/GHC/Runtime/Interpreter.hs ===================================== @@ -374,7 +374,7 @@ addSptEntry interp fpr ref = withForeignRef ref $ \val -> interpCmd interp (AddSptEntry fpr val) -addHpcModule :: Interp -> String -> Int -> Int -> String -> IO () +addHpcModule :: Interp -> SBS.ShortByteString -> Int -> Int -> SBS.ShortByteString -> IO () addHpcModule interp modLabel tickNo hash tickboxes = interpCmd interp (AddHpcModule modLabel tickNo hash tickboxes) ===================================== libraries/ghci/GHCi/Coverage.hs ===================================== @@ -8,10 +8,12 @@ module GHCi.Coverage ( import Prelude -- See note [Why do we import Prelude here?] import Control.Exception +import Data.ByteString.Short (ShortByteString) +import qualified Data.ByteString.Short as SBS import Data.Word import Foreign -import Foreign.C.String (withCAString) import GHC.Foreign (CString) +import GHC.Utils.Encoding.UTF8 (utf8DecodeShortByteString) import GHCi.ObjLink (lookupSymbol) -- | Inform the run-time system that the given module name is instrumented via @hpc@ @@ -19,22 +21,22 @@ import GHCi.ObjLink (lookupSymbol) -- -- Starts the `hpc` run-time if it hasn't already been started. hpcAddModule :: - String -> + ShortByteString -> -- ^ Name of the module to instrument Int -> -- ^ Number of hpc ticks in this module Int -> -- ^ 'HpcInfo's 'hpcInfoHash' - String -> + ShortByteString -> -- ^ Name of the ticks array found in the c-stub. IO () hpcAddModule modlName ticks hash tickboxes = do - withCAString modlName $ \modlNameLiteral -> do + SBS.useAsCString modlName $ \modlNameLiteral -> do -- we need to find the reference to the ticks array. lookupSymbol tickboxes >>= \ case Nothing -> do -- the symbol is not found, this is a bug! - throwIO $ ErrorCall $ "hpcAddModule: failed to find symbol " <> tickboxes + throwIO $ ErrorCall $ "hpcAddModule: failed to find symbol " <> utf8DecodeShortByteString tickboxes Just tickBoxRef -> do -- Calling 'hs_hpc_module' multiple times is safe, it will add the module only once. hpc_register_module modlNameLiteral (fromIntegral ticks) (fromIntegral hash) (castPtr tickBoxRef) ===================================== libraries/ghci/GHCi/Message.hs ===================================== @@ -112,7 +112,7 @@ data Message a where -- | Add entries to the Static Pointer Table AddSptEntry :: Fingerprint -> HValueRef -> Message () -- | Add module to hpc - AddHpcModule :: String -> Int -> Int -> String -> Message () + AddHpcModule :: BS.ShortByteString -> Int -> Int -> BS.ShortByteString -> Message () -- | Malloc some data and return a 'RemotePtr' to it MallocData :: ByteString -> Message (RemotePtr ()) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8cd628b0bbc8666f39347e7a2affe800... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8cd628b0bbc8666f39347e7a2affe800... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Hannes Siebenhandl (@fendor)