Skip to content

Implement cardinality analysis

Ilya is well on the way to a cardinality analyser. Today I realised that it'll help a lot with CPS-heavy code. For example, here's what happens with

data DT = DT {
                field1 :: Int
              , field2 :: Int
              , field3 :: Int }
  deriving( Read )

After strictness analysis and simplification we get this:

$wa_sD5 =
  \ (ww_sD1 :: GHC.Prim.Int#)
    (@ b_awu)
    (w_sD3 :: W2.DT -> Text.ParserCombinators.ReadP.P b_awu) ->
    case GHC.Prim.<=# ww_sD1 11 of _ {
      GHC.Types.False -> Text.ParserCombinators.ReadP.Fail @ b_awu;
      GHC.Types.True ->
        Text.Read.Lex.expect1
          a_su6
          @ b_awu
          (\ _ ->
             Text.Read.Lex.expect1
               a_suf
               @ b_awu
               (\ _ ->
                  Text.Read.Lex.expect1
                    a_sum
                    @ b_awu
                    (\ _ ->
                       Text.Read.Lex.expect1
                         a_suv
                         @ b_awu
                         (\ _ ->
                            GHC.Read.$fReadInt5
                              GHC.Read.$fReadInt_$sconvertInt
                              Text.ParserCombinators.ReadPrec.minPrec
                              @ b_awu
                              (\ (a2_XB0 [Dmd=Just L] :: GHC.Types.Int) ->
                                 Text.Read.Lex.expect1
                                   lvl_svA
                                   @ b_awu
                                   (\ _ ->
                                      Text.Read.Lex.expect1
                                        lvl_svE
                                        @ b_awu
                                        (\ _ ->
                                           Text.Read.Lex.expect1
                                             lvl_svI
                                             @ b_awu
                                             (\ _ ->
                                                GHC.Read.$fReadInt5
                                                  GHC.Read.$fReadInt_$sconvertInt
                                                  Text.ParserCombinators.ReadPrec.minPrec
                                                  @ b_awu
                                                  (\ (a2_XBa [Dmd=Just L] :: GHC.Types.Int) ->
...

Look at all those nested continuations! Then the subsequent float-out pass floats out lots of MFEs, but entirely fruitlessly because all these are actually one-shot lambdas.

I'm not certain that the analysis will catch them all, but it might.

Trac metadata
Trac field Value
Version 7.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information