Wolfgang Jeltsch pushed to branch wip/jeltsch/textual-bytecode-output at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • compiler/GHC/ByteCode/Show.hs
    ... ... @@ -8,29 +8,16 @@ module GHC.ByteCode.Show (showByteCode) where
    8 8
     import Prelude ((+), (-), Integral, div)
    
    9 9
     import Control.Arrow ((>>>))
    
    10 10
     import Control.Exception (assert)
    
    11
    -import Data.Eq (Eq, (==))
    
    12
    -import Data.Ord ((<=))
    
    11
    +import Data.Eq ((==))
    
    13 12
     import Data.Bits (FiniteBits, finiteBitSize)
    
    14 13
     import Data.Function (($), id, (.))
    
    15
    -import Data.Tuple (fst, snd, uncurry)
    
    14
    +import Data.Tuple (uncurry)
    
    16 15
     import Data.Bool (Bool, otherwise, not)
    
    17 16
     import Data.Int (Int)
    
    18 17
     import Data.Word (Word)
    
    19
    -import Data.Maybe (Maybe (Nothing, Just), maybe)
    
    18
    +import Data.Maybe (Maybe, maybe)
    
    20 19
     import Data.Either (Either, either)
    
    21
    -import Data.List
    
    22
    -       (
    
    23
    -           length,
    
    24
    -           (++),
    
    25
    -           repeat,
    
    26
    -           map,
    
    27
    -           zipWith,
    
    28
    -           zipWith5,
    
    29
    -           and,
    
    30
    -           take,
    
    31
    -           drop,
    
    32
    -           replicate
    
    33
    -       )
    
    20
    +import Data.List (length, (++), map, zipWith, zipWith4, take, drop, replicate)
    
    34 21
     import Data.String (String)
    
    35 22
     import Data.ByteString (ByteString, unpack)
    
    36 23
     import Data.ByteString.Short (ShortByteString)
    
    ... ... @@ -57,7 +44,6 @@ import GHC.Utils.Outputable
    57 44
            (
    
    58 45
                defaultDumpStyle,
    
    59 46
                SDoc,
    
    60
    -           empty,
    
    61 47
                text,
    
    62 48
                (<>),
    
    63 49
                (<+>),
    
    ... ... @@ -309,57 +295,32 @@ pprBreakpointsData currentModule InternalModBreaks {..}
    309 295
     -- | […]
    
    310 296
     pprBreakpointsInSource :: Module -> ModBreaks -> SDoc
    
    311 297
     pprBreakpointsInSource currentModule ModBreaks {..}
    
    312
    -    = entry (text "breakpoints in source:")                    $
    
    313
    -      assert (modBreaks_module == currentModule)               $
    
    314
    -      assert boundsAreConsistent                               $
    
    315
    -      vcatOrNone                                               $
    
    316
    -      zipWith5 pprBreakpointInSource (indices modBreaks_locs_)
    
    298
    +    = entry (text "breakpoints in source:")                     $
    
    299
    +      assert (modBreaks_module == currentModule)                $
    
    300
    +      assert (bounds modBreaks_locs_ == bounds modBreaks_decls) $
    
    301
    +      assert (bounds modBreaks_locs_ == bounds modBreaks_vars)  $
    
    302
    +      vcatOrNone                                                $
    
    303
    +      zipWith4 pprBreakpointInSource (indices modBreaks_locs_)
    
    317 304
                                          (elems modBreaks_locs_)
    
    318 305
                                          (elems modBreaks_decls)
    
    319 306
                                          (elems modBreaks_vars)
    
    320
    -                                     potentialCostCenterInfos
    
    321
    -    where
    
    322
    -
    
    323
    -    costCenterInfoIsPresent :: Bool
    
    324
    -    costCenterInfoIsPresent = fst (bounds modBreaks_ccs) <=
    
    325
    -                              snd (bounds modBreaks_ccs)
    
    326
    -
    
    327
    -    boundsAreConsistent :: Bool
    
    328
    -    boundsAreConsistent
    
    329
    -        = allAreEqual $
    
    330
    -          [
    
    331
    -              bounds modBreaks_locs_,
    
    332
    -              bounds modBreaks_decls,
    
    333
    -              bounds modBreaks_vars
    
    334
    -          ] ++ if costCenterInfoIsPresent then [bounds modBreaks_ccs] else []
    
    335
    -        where
    
    336
    -
    
    337
    -        allAreEqual :: Eq a => [a] -> Bool
    
    338
    -        allAreEqual list = and $ zipWith (==) list (drop 1 list)
    
    339
    -
    
    340
    -    potentialCostCenterInfos :: [Maybe (ShortByteString, ShortByteString)]
    
    341
    -    potentialCostCenterInfos
    
    342
    -        | costCenterInfoIsPresent = map Just (elems modBreaks_ccs)
    
    343
    -        | otherwise               = repeat Nothing
    
    307
    +      -- The cost center infos in `modBreaks_ccs`, when present, just contain
    
    308
    +      -- textual representations of the declaration paths in `modBreaks_decls`
    
    309
    +      -- and the source spans in `modBreaks_locs_` and are therefore never
    
    310
    +      -- shown.
    
    344 311
     
    
    345 312
     -- | […]
    
    346 313
     pprBreakpointInSource :: BreakTickIndex
    
    347 314
                           -> BinSrcSpan
    
    348 315
                           -> [String]
    
    349 316
                           -> [OccName]
    
    350
    -                      -> Maybe (ShortByteString, ShortByteString)
    
    351 317
                           -> SDoc
    
    352
    -pprBreakpointInSource ix
    
    353
    -                      srcSpan
    
    354
    -                      declarationPath
    
    355
    -                      freeVars
    
    356
    -                      potentialCostCenterInfo
    
    318
    +pprBreakpointInSource ix srcSpan declarationPath freeVars
    
    357 319
         = entry (text "breakpoint" <+> ppr ix <> text ":") $
    
    358 320
           vcat [
    
    359
    -               pprSrcSpan                 $ srcSpan,
    
    360
    -               pprDeclarationPath         $ declarationPath,
    
    361
    -               pprFreeVariables           $ freeVars,
    
    362
    -               pprPotentialCostCenterInfo $ potentialCostCenterInfo
    
    321
    +               pprSrcSpan         $ srcSpan,
    
    322
    +               pprDeclarationPath $ declarationPath,
    
    323
    +               pprFreeVariables   $ freeVars
    
    363 324
                ]
    
    364 325
     
    
    365 326
     -- | […]
    
    ... ... @@ -374,34 +335,6 @@ pprDeclarationPath = entry (text "declaration path:") . vcat . map text
    374 335
     pprFreeVariables :: [OccName] -> SDoc
    
    375 336
     pprFreeVariables = entry (text "free variables:") . hsep . map ppr
    
    376 337
     
    
    377
    --- | […]
    
    378
    -pprPotentialCostCenterInfo :: Maybe (ShortByteString, ShortByteString) -> SDoc
    
    379
    -pprPotentialCostCenterInfo Nothing
    
    380
    -    = empty
    
    381
    -pprPotentialCostCenterInfo (Just costCenterInfo)
    
    382
    -    = vcat [
    
    383
    -               pprCostCenterPath     $ costCenterPath,
    
    384
    -               pprCostCenterLocation $ costCenterLocation
    
    385
    -           ]
    
    386
    -    where
    
    387
    -
    
    388
    -    costCenterPath :: String
    
    389
    -    costCenterPath = utf8DecodeShortByteString (fst costCenterInfo)
    
    390
    -
    
    391
    -    costCenterLocation :: String
    
    392
    -    costCenterLocation = utf8DecodeShortByteString (snd costCenterInfo)
    
    393
    -
    
    394
    -    -- The structure of the cost center information is apparent from the
    
    395
    -    -- implementation of 'GHC.HsToCore.Breakpoints.mkModBreaks'.
    
    396
    -
    
    397
    --- | […]
    
    398
    -pprCostCenterPath :: String -> SDoc
    
    399
    -pprCostCenterPath = entry (text "cost center path:") . text
    
    400
    -
    
    401
    --- | […]
    
    402
    -pprCostCenterLocation :: String -> SDoc
    
    403
    -pprCostCenterLocation = entry (text "cost center location:") . text
    
    404
    -
    
    405 338
     -- | […]
    
    406 339
     pprBreakpointsInByteCode :: Module -> IntMap CgBreakInfo -> SDoc
    
    407 340
     pprBreakpointsInByteCode currentModule