{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RecordWildCards #-}
module GHC.Types.Tickish (
GenTickish(..),
CoreTickish, StgTickish, CmmTickish,
XTickishId,
tickishCounts,
tickishHasNoScope,
tickishHasSoftScope,
tickishFloatable,
tickishCanSplit,
mkNoCount,
mkNoScope,
tickishIsCode,
isProfTick,
TickishPlacement(..),
tickishPlace,
tickishContains,
combineTickish_maybe,
tickishCommutable,
bestSourceNote,
BreakpointId(..), BreakTickIndex
) where
import GHC.Prelude
import GHC.Data.FastString
import Control.DeepSeq
import GHC.Core.Type
import GHC.Unit.Module
import GHC.Types.CostCentre
import GHC.Types.SrcLoc ( RealSrcSpan, containsSpan, srcSpanFile )
import GHC.Types.Var
import GHC.Utils.Panic
import Language.Haskell.Syntax.Extension ( NoExtField )
import Data.Data
import Data.List ( partition )
import Data.Maybe ( listToMaybe, mapMaybe )
import GHC.Utils.Binary
import GHC.Utils.Outputable (Outputable (ppr), text, (<+>))
data TickishPass
= TickishPassCore
| TickishPassStg
| TickishPassCmm
type family XBreakpoint (pass :: TickishPass)
type instance XBreakpoint 'TickishPassCore = NoExtField
type instance XBreakpoint 'TickishPassStg = Type
type instance XBreakpoint 'TickishPassCmm = NoExtField
type family XTickishId (pass :: TickishPass)
type instance XTickishId 'TickishPassCore = Id
type instance XTickishId 'TickishPassStg = Id
type instance XTickishId 'TickishPassCmm = NoExtField
type CoreTickish = GenTickish 'TickishPassCore
type StgTickish = GenTickish 'TickishPassStg
type CmmTickish = GenTickish 'TickishPassCmm
data GenTickish pass =
ProfNote {
forall (pass :: TickishPass). GenTickish pass -> CostCentre
profNoteCC :: CostCentre,
forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount :: !Bool,
forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope :: !Bool
}
| HpcTick {
forall (pass :: TickishPass). GenTickish pass -> Module
tickModule :: Module,
forall (pass :: TickishPass). GenTickish pass -> Int
tickId :: !Int
}
| Breakpoint
{ forall (pass :: TickishPass). GenTickish pass -> XBreakpoint pass
breakpointExt :: XBreakpoint pass
, forall (pass :: TickishPass). GenTickish pass -> BreakpointId
breakpointId :: !BreakpointId
, forall (pass :: TickishPass). GenTickish pass -> [XTickishId pass]
breakpointFVs :: [XTickishId pass]
}
| SourceNote
{ forall (pass :: TickishPass). GenTickish pass -> RealSrcSpan
sourceSpan :: RealSrcSpan
, forall (pass :: TickishPass). GenTickish pass -> LexicalFastString
sourceName :: LexicalFastString
}
deriving instance Eq (GenTickish 'TickishPassCore)
deriving instance Ord (GenTickish 'TickishPassCore)
deriving instance Data (GenTickish 'TickishPassCore)
deriving instance Data (GenTickish 'TickishPassStg)
deriving instance Eq (GenTickish 'TickishPassCmm)
deriving instance Ord (GenTickish 'TickishPassCmm)
deriving instance Data (GenTickish 'TickishPassCmm)
type BreakTickIndex = Int
data BreakpointId = BreakpointId
{ BreakpointId -> Module
bi_tick_mod :: !Module
, BreakpointId -> Int
bi_tick_index :: !BreakTickIndex
}
deriving (BreakpointId -> BreakpointId -> Bool
(BreakpointId -> BreakpointId -> Bool)
-> (BreakpointId -> BreakpointId -> Bool) -> Eq BreakpointId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BreakpointId -> BreakpointId -> Bool
== :: BreakpointId -> BreakpointId -> Bool
$c/= :: BreakpointId -> BreakpointId -> Bool
/= :: BreakpointId -> BreakpointId -> Bool
Eq, Eq BreakpointId
Eq BreakpointId =>
(BreakpointId -> BreakpointId -> Ordering)
-> (BreakpointId -> BreakpointId -> Bool)
-> (BreakpointId -> BreakpointId -> Bool)
-> (BreakpointId -> BreakpointId -> Bool)
-> (BreakpointId -> BreakpointId -> Bool)
-> (BreakpointId -> BreakpointId -> BreakpointId)
-> (BreakpointId -> BreakpointId -> BreakpointId)
-> Ord BreakpointId
BreakpointId -> BreakpointId -> Bool
BreakpointId -> BreakpointId -> Ordering
BreakpointId -> BreakpointId -> BreakpointId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BreakpointId -> BreakpointId -> Ordering
compare :: BreakpointId -> BreakpointId -> Ordering
$c< :: BreakpointId -> BreakpointId -> Bool
< :: BreakpointId -> BreakpointId -> Bool
$c<= :: BreakpointId -> BreakpointId -> Bool
<= :: BreakpointId -> BreakpointId -> Bool
$c> :: BreakpointId -> BreakpointId -> Bool
> :: BreakpointId -> BreakpointId -> Bool
$c>= :: BreakpointId -> BreakpointId -> Bool
>= :: BreakpointId -> BreakpointId -> Bool
$cmax :: BreakpointId -> BreakpointId -> BreakpointId
max :: BreakpointId -> BreakpointId -> BreakpointId
$cmin :: BreakpointId -> BreakpointId -> BreakpointId
min :: BreakpointId -> BreakpointId -> BreakpointId
Ord, Typeable BreakpointId
Typeable BreakpointId =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BreakpointId -> c BreakpointId)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BreakpointId)
-> (BreakpointId -> Constr)
-> (BreakpointId -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BreakpointId))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BreakpointId))
-> ((forall b. Data b => b -> b) -> BreakpointId -> BreakpointId)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r)
-> (forall u. (forall d. Data d => d -> u) -> BreakpointId -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> BreakpointId -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId)
-> Data BreakpointId
BreakpointId -> Constr
BreakpointId -> DataType
(forall b. Data b => b -> b) -> BreakpointId -> BreakpointId
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BreakpointId -> u
forall u. (forall d. Data d => d -> u) -> BreakpointId -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BreakpointId
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BreakpointId -> c BreakpointId
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BreakpointId)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BreakpointId)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BreakpointId -> c BreakpointId
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BreakpointId -> c BreakpointId
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BreakpointId
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BreakpointId
$ctoConstr :: BreakpointId -> Constr
toConstr :: BreakpointId -> Constr
$cdataTypeOf :: BreakpointId -> DataType
dataTypeOf :: BreakpointId -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BreakpointId)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BreakpointId)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BreakpointId)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BreakpointId)
$cgmapT :: (forall b. Data b => b -> b) -> BreakpointId -> BreakpointId
gmapT :: (forall b. Data b => b -> b) -> BreakpointId -> BreakpointId
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BreakpointId -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BreakpointId -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BreakpointId -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BreakpointId -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BreakpointId -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BreakpointId -> m BreakpointId
Data)
instance Outputable BreakpointId where
ppr :: BreakpointId -> SDoc
ppr BreakpointId{Module
bi_tick_mod :: BreakpointId -> Module
bi_tick_mod :: Module
bi_tick_mod, Int
bi_tick_index :: BreakpointId -> Int
bi_tick_index :: Int
bi_tick_index} =
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"BreakpointId" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
bi_tick_mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
bi_tick_index
instance NFData BreakpointId where
rnf :: BreakpointId -> ()
rnf BreakpointId{Module
bi_tick_mod :: BreakpointId -> Module
bi_tick_mod :: Module
bi_tick_mod, Int
bi_tick_index :: BreakpointId -> Int
bi_tick_index :: Int
bi_tick_index} =
Module -> ()
forall a. NFData a => a -> ()
rnf Module
bi_tick_mod () -> () -> ()
forall a b. a -> b -> b
`seq` Int -> ()
forall a. NFData a => a -> ()
rnf Int
bi_tick_index
instance Binary BreakpointId where
get :: ReadBinHandle -> IO BreakpointId
get ReadBinHandle
bh = Module -> Int -> BreakpointId
Module -> Int -> BreakpointId
BreakpointId (Module -> Int -> BreakpointId)
-> IO Module -> IO (Int -> BreakpointId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadBinHandle -> IO Module
forall a. Binary a => ReadBinHandle -> IO a
get ReadBinHandle
bh IO (Int -> BreakpointId) -> IO Int -> IO BreakpointId
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadBinHandle -> IO Int
forall a. Binary a => ReadBinHandle -> IO a
get ReadBinHandle
bh
put_ :: WriteBinHandle -> BreakpointId -> IO ()
put_ WriteBinHandle
bh BreakpointId {Int
Module
bi_tick_mod :: BreakpointId -> Module
bi_tick_index :: BreakpointId -> Int
bi_tick_mod :: Module
bi_tick_index :: Int
..} = WriteBinHandle -> Module -> IO ()
forall a. Binary a => WriteBinHandle -> a -> IO ()
put_ WriteBinHandle
bh Module
bi_tick_mod IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> WriteBinHandle -> Int -> IO ()
forall a. Binary a => WriteBinHandle -> a -> IO ()
put_ WriteBinHandle
bh Int
bi_tick_index
tickishCounts :: GenTickish pass -> Bool
tickishCounts :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCounts = \case
ProfNote { profNoteCount :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount = Bool
counts } -> Bool
counts
HpcTick {} -> Bool
True
Breakpoint {} -> Bool
True
SourceNote {} -> Bool
False
tickishHasNoScope :: GenTickish pass -> Bool
tickishHasNoScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishHasNoScope = \case
ProfNote { profNoteScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope = Bool
scopes } -> Bool -> Bool
not Bool
scopes
HpcTick {} -> Bool
True
Breakpoint {} -> Bool
False
SourceNote {} -> Bool
False
tickishHasSoftScope :: GenTickish pass -> Bool
tickishHasSoftScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishHasSoftScope = \case
ProfNote { profNoteScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope = Bool
scopes } -> Bool -> Bool
not Bool
scopes
HpcTick {} -> Bool
True
Breakpoint {} -> Bool
False
SourceNote {} -> Bool
True
tickishFloatable :: GenTickish pass -> Bool
tickishFloatable :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishFloatable GenTickish pass
t = GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishHasSoftScope GenTickish pass
t Bool -> Bool -> Bool
&& Bool -> Bool
not (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCounts GenTickish pass
t)
tickishCanSplit :: GenTickish pass -> Bool
tickishCanSplit :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCanSplit ProfNote{profNoteScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope = Bool
True, profNoteCount :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount = Bool
True}
= Bool
True
tickishCanSplit GenTickish pass
_ = Bool
False
mkNoCount :: GenTickish pass -> GenTickish pass
mkNoCount :: forall (pass :: TickishPass). GenTickish pass -> GenTickish pass
mkNoCount GenTickish pass
n | Bool -> Bool
not (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCounts GenTickish pass
n) = GenTickish pass
n
| Bool -> Bool
not (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCanSplit GenTickish pass
n) = String -> GenTickish pass
forall a. HasCallStack => String -> a
panic String
"mkNoCount: Cannot split!"
mkNoCount n :: GenTickish pass
n@ProfNote{} = let n' :: GenTickish pass
n' = GenTickish pass
n {profNoteCount = False}
in Bool -> GenTickish pass -> GenTickish pass
forall a. HasCallStack => Bool -> a -> a
assert (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount GenTickish pass
n) GenTickish pass
n'
mkNoCount GenTickish pass
_ = String -> GenTickish pass
forall a. HasCallStack => String -> a
panic String
"mkNoCount: Undefined split!"
mkNoScope :: GenTickish pass -> GenTickish pass
mkNoScope :: forall (pass :: TickishPass). GenTickish pass -> GenTickish pass
mkNoScope GenTickish pass
n | GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishHasNoScope GenTickish pass
n = GenTickish pass
n
| Bool -> Bool
not (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
tickishCanSplit GenTickish pass
n) = String -> GenTickish pass
forall a. HasCallStack => String -> a
panic String
"mkNoScope: Cannot split!"
mkNoScope n :: GenTickish pass
n@ProfNote{} = let n' :: GenTickish pass
n' = GenTickish pass
n {profNoteScope = False}
in Bool -> GenTickish pass -> GenTickish pass
forall a. HasCallStack => Bool -> a -> a
assert (GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount GenTickish pass
n) GenTickish pass
n'
mkNoScope GenTickish pass
_ = String -> GenTickish pass
forall a. HasCallStack => String -> a
panic String
"mkNoScope: Undefined split!"
tickishIsCode :: GenTickish pass -> Bool
tickishIsCode :: forall (pass :: TickishPass). GenTickish pass -> Bool
tickishIsCode SourceNote{} = Bool
False
tickishIsCode ProfNote{} = Bool
True
tickishIsCode Breakpoint{} = Bool
True
tickishIsCode HpcTick{} = Bool
True
isProfTick :: GenTickish pass -> Bool
isProfTick :: forall (pass :: TickishPass). GenTickish pass -> Bool
isProfTick ProfNote{} = Bool
True
isProfTick GenTickish pass
_ = Bool
False
data TickishPlacement =
PlaceRuntime
| PlaceNonLam
| PlaceCostCentre
deriving (TickishPlacement -> TickishPlacement -> Bool
(TickishPlacement -> TickishPlacement -> Bool)
-> (TickishPlacement -> TickishPlacement -> Bool)
-> Eq TickishPlacement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TickishPlacement -> TickishPlacement -> Bool
== :: TickishPlacement -> TickishPlacement -> Bool
$c/= :: TickishPlacement -> TickishPlacement -> Bool
/= :: TickishPlacement -> TickishPlacement -> Bool
Eq,Int -> TickishPlacement -> ShowS
[TickishPlacement] -> ShowS
TickishPlacement -> String
(Int -> TickishPlacement -> ShowS)
-> (TickishPlacement -> String)
-> ([TickishPlacement] -> ShowS)
-> Show TickishPlacement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TickishPlacement -> ShowS
showsPrec :: Int -> TickishPlacement -> ShowS
$cshow :: TickishPlacement -> String
show :: TickishPlacement -> String
$cshowList :: [TickishPlacement] -> ShowS
showList :: [TickishPlacement] -> ShowS
Show)
instance Outputable TickishPlacement where
ppr :: TickishPlacement -> SDoc
ppr = String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc)
-> (TickishPlacement -> String) -> TickishPlacement -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TickishPlacement -> String
forall a. Show a => a -> String
show
tickishPlace :: GenTickish pass -> TickishPlacement
tickishPlace :: forall (pass :: TickishPass). GenTickish pass -> TickishPlacement
tickishPlace n :: GenTickish pass
n@ProfNote{}
| GenTickish pass -> Bool
forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount GenTickish pass
n = TickishPlacement
PlaceRuntime
| Bool
otherwise = TickishPlacement
PlaceCostCentre
tickishPlace HpcTick{} = TickishPlacement
PlaceRuntime
tickishPlace Breakpoint{} = TickishPlacement
PlaceRuntime
tickishPlace SourceNote{} = TickishPlacement
PlaceNonLam
combineTickish_maybe :: Eq (GenTickish pass)
=> GenTickish pass -> GenTickish pass -> Maybe (GenTickish pass)
combineTickish_maybe :: forall (pass :: TickishPass).
Eq (GenTickish pass) =>
GenTickish pass -> GenTickish pass -> Maybe (GenTickish pass)
combineTickish_maybe
(ProfNote { profNoteCC :: forall (pass :: TickishPass). GenTickish pass -> CostCentre
profNoteCC = CostCentre
cc1, profNoteCount :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount = Bool
cnt1, profNoteScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope = Bool
scope1 })
(ProfNote { profNoteCC :: forall (pass :: TickishPass). GenTickish pass -> CostCentre
profNoteCC = CostCentre
cc2, profNoteCount :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteCount = Bool
cnt2, profNoteScope :: forall (pass :: TickishPass). GenTickish pass -> Bool
profNoteScope = Bool
scope2 })
| CostCentre
cc1 CostCentre -> CostCentre -> Bool
forall a. Eq a => a -> a -> Bool
== CostCentre
cc2
, Bool -> Bool
not Bool
cnt1 Bool -> Bool -> Bool
|| Bool -> Bool
not Bool
cnt2
= GenTickish pass -> Maybe (GenTickish pass)
GenTickish pass -> Maybe (GenTickish pass)
forall a. a -> Maybe a
Just (GenTickish pass -> Maybe (GenTickish pass))
-> GenTickish pass -> Maybe (GenTickish pass)
forall a b. (a -> b) -> a -> b
$ ProfNote { profNoteCC :: CostCentre
profNoteCC = CostCentre
cc1
, profNoteCount :: Bool
profNoteCount = Bool
cnt1 Bool -> Bool -> Bool
|| Bool
cnt2
, profNoteScope :: Bool
profNoteScope = Bool
scope1 Bool -> Bool -> Bool
|| Bool
scope2
}
combineTickish_maybe t1 :: GenTickish pass
t1@(SourceNote RealSrcSpan
sp1 LexicalFastString
n1) t2 :: GenTickish pass
t2@(SourceNote RealSrcSpan
sp2 LexicalFastString
n2)
| LexicalFastString
n1 LexicalFastString -> LexicalFastString -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFastString
n2
, RealSrcSpan
sp1 RealSrcSpan -> RealSrcSpan -> Bool
`containsSpan` RealSrcSpan
sp2
= GenTickish pass -> Maybe (GenTickish pass)
forall a. a -> Maybe a
Just GenTickish pass
t1
| LexicalFastString
n1 LexicalFastString -> LexicalFastString -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFastString
n2
, RealSrcSpan
sp2 RealSrcSpan -> RealSrcSpan -> Bool
`containsSpan` RealSrcSpan
sp1
= GenTickish pass -> Maybe (GenTickish pass)
forall a. a -> Maybe a
Just GenTickish pass
t2
combineTickish_maybe t1 :: GenTickish pass
t1@(HpcTick {}) t2 :: GenTickish pass
t2@(HpcTick {})
| GenTickish pass
t1 GenTickish pass -> GenTickish pass -> Bool
forall a. Eq a => a -> a -> Bool
== GenTickish pass
t2
= GenTickish pass -> Maybe (GenTickish pass)
forall a. a -> Maybe a
Just GenTickish pass
t1
combineTickish_maybe t1 :: GenTickish pass
t1@(Breakpoint {}) t2 :: GenTickish pass
t2@(Breakpoint {})
| GenTickish pass
t1 GenTickish pass -> GenTickish pass -> Bool
forall a. Eq a => a -> a -> Bool
== GenTickish pass
t2
= GenTickish pass -> Maybe (GenTickish pass)
forall a. a -> Maybe a
Just GenTickish pass
t1
combineTickish_maybe GenTickish pass
_ GenTickish pass
_ = Maybe (GenTickish pass)
forall a. Maybe a
Nothing
tickishCommutable :: GenTickish pass -> GenTickish pass -> Bool
tickishCommutable :: forall (pass :: TickishPass).
GenTickish pass -> GenTickish pass -> Bool
tickishCommutable
(ProfNote { profNoteCC :: forall (pass :: TickishPass). GenTickish pass -> CostCentre
profNoteCC = CostCentre
cc1 }) (ProfNote { profNoteCC :: forall (pass :: TickishPass). GenTickish pass -> CostCentre
profNoteCC = CostCentre
cc2 })
= CostCentre
cc1 CostCentre -> CostCentre -> Bool
forall a. Eq a => a -> a -> Bool
== CostCentre
cc2
tickishCommutable GenTickish pass
t1 GenTickish pass
t2
| GenTickish pass -> TickishPlacement
forall (pass :: TickishPass). GenTickish pass -> TickishPlacement
tickishPlace GenTickish pass
t1 TickishPlacement -> TickishPlacement -> Bool
forall a. Eq a => a -> a -> Bool
/= GenTickish pass -> TickishPlacement
forall (pass :: TickishPass). GenTickish pass -> TickishPlacement
tickishPlace GenTickish pass
t2
= Bool
True
| Bool
otherwise
= Bool
False
tickishContains :: Eq (GenTickish pass)
=> GenTickish pass -> GenTickish pass -> Bool
tickishContains :: forall (pass :: TickishPass).
Eq (GenTickish pass) =>
GenTickish pass -> GenTickish pass -> Bool
tickishContains (SourceNote RealSrcSpan
sp1 LexicalFastString
n1) (SourceNote RealSrcSpan
sp2 LexicalFastString
n2)
= RealSrcSpan -> RealSrcSpan -> Bool
containsSpan RealSrcSpan
sp1 RealSrcSpan
sp2 Bool -> Bool -> Bool
&& LexicalFastString
n1 LexicalFastString -> LexicalFastString -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFastString
n2
tickishContains GenTickish pass
t1 GenTickish pass
t2
= GenTickish pass
t1 GenTickish pass -> GenTickish pass -> Bool
forall a. Eq a => a -> a -> Bool
== GenTickish pass
t2
bestSourceNote
:: Bool
-> FastString
-> [GenTickish pass]
-> Maybe (RealSrcSpan, LexicalFastString)
bestSourceNote :: forall (pass :: TickishPass).
Bool
-> FastString
-> [GenTickish pass]
-> Maybe (RealSrcSpan, LexicalFastString)
bestSourceNote Bool
accept_outside_loc FastString
this_file [GenTickish pass]
ticks
= [(RealSrcSpan, LexicalFastString)]
-> Maybe (RealSrcSpan, LexicalFastString)
forall a. [a] -> Maybe a
listToMaybe ([(RealSrcSpan, LexicalFastString)]
-> Maybe (RealSrcSpan, LexicalFastString))
-> [(RealSrcSpan, LexicalFastString)]
-> Maybe (RealSrcSpan, LexicalFastString)
forall a b. (a -> b) -> a -> b
$
if Bool
accept_outside_loc
then [(RealSrcSpan, LexicalFastString)]
here [(RealSrcSpan, LexicalFastString)]
-> [(RealSrcSpan, LexicalFastString)]
-> [(RealSrcSpan, LexicalFastString)]
forall a. [a] -> [a] -> [a]
++ [(RealSrcSpan, LexicalFastString)]
elsewhere
else [(RealSrcSpan, LexicalFastString)]
here
where
([(RealSrcSpan, LexicalFastString)]
here, [(RealSrcSpan, LexicalFastString)]
elsewhere)
= ((RealSrcSpan, LexicalFastString) -> Bool)
-> [(RealSrcSpan, LexicalFastString)]
-> ([(RealSrcSpan, LexicalFastString)],
[(RealSrcSpan, LexicalFastString)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ((FastString
this_file FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
==) (FastString -> Bool)
-> ((RealSrcSpan, LexicalFastString) -> FastString)
-> (RealSrcSpan, LexicalFastString)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RealSrcSpan -> FastString
srcSpanFile (RealSrcSpan -> FastString)
-> ((RealSrcSpan, LexicalFastString) -> RealSrcSpan)
-> (RealSrcSpan, LexicalFastString)
-> FastString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RealSrcSpan, LexicalFastString) -> RealSrcSpan
forall a b. (a, b) -> a
fst)
([(RealSrcSpan, LexicalFastString)]
-> ([(RealSrcSpan, LexicalFastString)],
[(RealSrcSpan, LexicalFastString)]))
-> [(RealSrcSpan, LexicalFastString)]
-> ([(RealSrcSpan, LexicalFastString)],
[(RealSrcSpan, LexicalFastString)])
forall a b. (a -> b) -> a -> b
$ (GenTickish pass -> Maybe (RealSrcSpan, LexicalFastString))
-> [GenTickish pass] -> [(RealSrcSpan, LexicalFastString)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe GenTickish pass -> Maybe (RealSrcSpan, LexicalFastString)
forall {pass :: TickishPass}.
GenTickish pass -> Maybe (RealSrcSpan, LexicalFastString)
source_location [GenTickish pass]
ticks
source_location :: GenTickish pass -> Maybe (RealSrcSpan, LexicalFastString)
source_location (SourceNote RealSrcSpan
span LexicalFastString
name) = (RealSrcSpan, LexicalFastString)
-> Maybe (RealSrcSpan, LexicalFastString)
forall a. a -> Maybe a
Just (RealSrcSpan
span, LexicalFastString
name)
source_location GenTickish pass
_ = Maybe (RealSrcSpan, LexicalFastString)
forall a. Maybe a
Nothing