Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • testsuite/tests/perf/compiler/FamAppCachePerf.hs
    1
    +{-# LANGUAGE TypeFamilies, DataKinds, UndecidableInstances #-}
    
    2
    +{-# OPTIONS_GHC -freduction-depth=0 #-}
    
    3
    +
    
    4
    +module FamAppCachePerf where
    
    5
    +
    
    6
    +import Data.Kind
    
    7
    +import GHC.TypeNats
    
    8
    +
    
    9
    +type Id :: Type -> Type
    
    10
    +type family Id a where
    
    11
    +  Id a = a
    
    12
    +
    
    13
    +type F :: Type -> Type
    
    14
    +type family F a where
    
    15
    +  F Int = Int
    
    16
    +
    
    17
    +type G :: Type
    
    18
    +type G = F ( Id Int )
    
    19
    +
    
    20
    +type K :: Type -> Type -> Type
    
    21
    +type family K a b where
    
    22
    +  K
    
    23
    +    ( Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int
    
    24
    +    , Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int
    
    25
    +    , Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int
    
    26
    +    , Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int
    
    27
    +    )
    
    28
    +    b = b
    
    29
    +
    
    30
    +type Loop :: Nat -> Type
    
    31
    +type family Loop n where
    
    32
    +  Loop 0 = Int
    
    33
    +  Loop n =
    
    34
    +    K
    
    35
    +      ( G, G, G, G, G, G, G, G, G, G, G, G, G, G, G, G
    
    36
    +      , G, G, G, G, G, G, G, G, G, G, G, G, G, G, G, G
    
    37
    +      , G, G, G, G, G, G, G, G, G, G, G, G, G, G, G, G
    
    38
    +      , G, G, G, G, G, G, G, G, G, G, G, G, G, G, G, G
    
    39
    +      )
    
    40
    +      ( Loop ( n - 1 ) )
    
    41
    +
    
    42
    +foo :: Loop 3000 -> Int
    
    43
    +foo x = x

  • testsuite/tests/perf/compiler/SimplCastPerf.hs
    1
    +{-# LANGUAGE TypeFamilies, UndecidableInstances #-}
    
    2
    +
    
    3
    +module SimplCastPerf where
    
    4
    +
    
    5
    +infixr 5 :*
    
    6
    +data a :* b
    
    7
    +data HNil
    
    8
    +
    
    9
    +type family Hd a where
    
    10
    +  Hd Int = Bool
    
    11
    +
    
    12
    +type family Wrap a where
    
    13
    +  Wrap (Bool :* r) = Bool :* r
    
    14
    +
    
    15
    +-- A very large type.
    
    16
    +type T =
    
    17
    +  Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    18
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    19
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    20
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    21
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    22
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    23
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    24
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    25
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    26
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    27
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    28
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    29
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    30
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    31
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    32
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    33
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    34
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    35
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    36
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    37
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    38
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    39
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    40
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    41
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    42
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    43
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    44
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    45
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    46
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    47
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    48
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    49
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    50
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    51
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    52
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    53
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    54
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    55
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    56
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    57
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    58
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    59
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    60
    +      :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int :* Int
    
    61
    +      :* Int :* Int :* Int :* HNil
    
    62
    +
    
    63
    +a0 :: Hd Int :* T
    
    64
    +a0 = undefined
    
    65
    +b0 :: Bool :* T
    
    66
    +b0 = a0
    
    67
    +c0 :: Wrap (Bool :* T)
    
    68
    +c0 = b0
    
    69
    +
    
    70
    +a1 :: Hd Int :* T
    
    71
    +a1 = undefined
    
    72
    +b1 :: Bool :* T
    
    73
    +b1 = a1
    
    74
    +c1 :: Wrap (Bool :* T)
    
    75
    +c1 = b1
    
    76
    +
    
    77
    +a2 :: Hd Int :* T
    
    78
    +a2 = undefined
    
    79
    +b2 :: Bool :* T
    
    80
    +b2 = a2
    
    81
    +c2 :: Wrap (Bool :* T)
    
    82
    +c2 = b2
    
    83
    +
    
    84
    +a3 :: Hd Int :* T
    
    85
    +a3 = undefined
    
    86
    +b3 :: Bool :* T
    
    87
    +b3 = a3
    
    88
    +c3 :: Wrap (Bool :* T)
    
    89
    +c3 = b3
    
    90
    +
    
    91
    +a4 :: Hd Int :* T
    
    92
    +a4 = undefined
    
    93
    +b4 :: Bool :* T
    
    94
    +b4 = a4
    
    95
    +c4 :: Wrap (Bool :* T)
    
    96
    +c4 = b4
    
    97
    +
    
    98
    +a5 :: Hd Int :* T
    
    99
    +a5 = undefined
    
    100
    +b5 :: Bool :* T
    
    101
    +b5 = a5
    
    102
    +c5 :: Wrap (Bool :* T)
    
    103
    +c5 = b5
    
    104
    +
    
    105
    +a6 :: Hd Int :* T
    
    106
    +a6 = undefined
    
    107
    +b6 :: Bool :* T
    
    108
    +b6 = a6
    
    109
    +c6 :: Wrap (Bool :* T)
    
    110
    +c6 = b6
    
    111
    +
    
    112
    +a7 :: Hd Int :* T
    
    113
    +a7 = undefined
    
    114
    +b7 :: Bool :* T
    
    115
    +b7 = a7
    
    116
    +c7 :: Wrap (Bool :* T)
    
    117
    +c7 = b7
    
    118
    +
    
    119
    +a8 :: Hd Int :* T
    
    120
    +a8 = undefined
    
    121
    +b8 :: Bool :* T
    
    122
    +b8 = a8
    
    123
    +c8 :: Wrap (Bool :* T)
    
    124
    +c8 = b8
    
    125
    +
    
    126
    +a9 :: Hd Int :* T
    
    127
    +a9 = undefined
    
    128
    +b9 :: Bool :* T
    
    129
    +b9 = a9
    
    130
    +c9 :: Wrap (Bool :* T)
    
    131
    +c9 = b9
    
    132
    +
    
    133
    +data Box =
    
    134
    +  Box
    
    135
    +    { box1, box2, box3, box4, box5, box6, box7, box8, box9, box10 :: Wrap (Bool :* T)
    
    136
    +    }
    
    137
    +
    
    138
    +box :: Box
    
    139
    +box = Box c0 c1 c2 c3 c4 c5 c6 c7 c8 c9

  • testsuite/tests/perf/compiler/T27336.hs
    1
    +{-# LANGUAGE DataKinds, MagicHash, PolyKinds, StandaloneKindSignatures #-}
    
    2
    +{-# LANGUAGE TypeFamilies, TypeOperators, UndecidableInstances #-}
    
    3
    +
    
    4
    +-- Reduced reproducer from https://github.com/kleinreact/clash-crypto-etfr
    
    5
    +
    
    6
    +module T27336 where
    
    7
    +
    
    8
    +import Data.Proxy ( Proxy(..) )
    
    9
    +import GHC.TypeNats ( type (+), CmpNat, Nat, Natural, natVal )
    
    10
    +
    
    11
    +type Max :: Nat -> Nat -> Nat
    
    12
    +type family Max m n where
    
    13
    +  Max m n = OrdCond (CmpNat m n) n n m
    
    14
    +
    
    15
    +type OrdCond :: Ordering -> Nat -> Nat -> Nat -> Nat
    
    16
    +type family OrdCond o lt eq gt where
    
    17
    +  OrdCond LT lt eq gt = lt
    
    18
    +  OrdCond EQ lt eq gt = eq
    
    19
    +  OrdCond GT lt eq gt = gt
    
    20
    +
    
    21
    +data Instruction routine = OP | RUN routine
    
    22
    +
    
    23
    +type Instructions :: forall routine. routine -> [Instruction routine]
    
    24
    +type family Instructions r
    
    25
    +
    
    26
    +type CallDepth :: forall routine. routine -> Nat
    
    27
    +type CallDepth r = 1 + CallDepth# (Instructions r)
    
    28
    +
    
    29
    +type CallDepth# :: forall routine. [Instruction routine] -> Nat
    
    30
    +type family CallDepth# is where
    
    31
    +  CallDepth# (RUN r : is) =
    
    32
    +    -- NB: here we triplicate the redex 'CallDepth# is'; see 'Max'.
    
    33
    +    Max (CallDepth r) (CallDepth# is)
    
    34
    +  CallDepth# (_     : is) = CallDepth# is
    
    35
    +  CallDepth# '[]          = 0
    
    36
    +
    
    37
    +data Routine = L0 | L1 | L2 | L3 | L4 | L5 | L6
    
    38
    +
    
    39
    +type instance Instructions L0 = '[ OP ]
    
    40
    +type instance Instructions L1 = '[ RUN L0, RUN L0 ]
    
    41
    +type instance Instructions L2 = '[ RUN L1, RUN L1 ]
    
    42
    +type instance Instructions L3 = '[ RUN L2, RUN L2 ]
    
    43
    +type instance Instructions L4 = '[ RUN L3, RUN L3 ]
    
    44
    +type instance Instructions L5 = '[ RUN L4, RUN L4 ]
    
    45
    +type instance Instructions L6 = '[ RUN L5, RUN L5 ]
    
    46
    +-- NB: each extra level costs roughly 7x
    
    47
    +
    
    48
    +callDepth :: Natural
    
    49
    +callDepth = natVal ( Proxy :: Proxy (CallDepth L6) )

  • testsuite/tests/perf/compiler/all.T
    ... ... @@ -189,6 +189,32 @@ test ('T13386',
    189 189
           compile,
    
    190 190
           ['-v0 -O0'])
    
    191 191
     
    
    192
    +# Performance test for lookups in the family application cache
    
    193
    +test('FamAppCachePerf',
    
    194
    +     [ only_ways(['normal'])
    
    195
    +     , collect_compiler_residency(20)
    
    196
    +     , collect_compiler_stats('bytes allocated',2)
    
    197
    +     ],
    
    198
    +     compile,
    
    199
    +     ['-v0 -O0'])
    
    200
    +
    
    201
    +test('T27336',
    
    202
    +     [ only_ways(['normal'])
    
    203
    +     , collect_compiler_residency(20)
    
    204
    +     , collect_compiler_stats('bytes allocated',2)
    
    205
    +     ],
    
    206
    +     compile,
    
    207
    +     ['-v0 -O0'])
    
    208
    +
    
    209
    +# Performance test involving pushing casts around in the simplifier
    
    210
    +test('SimplCastPerf',
    
    211
    +     [ only_ways(['normal'])
    
    212
    +     , collect_compiler_residency(20)
    
    213
    +     , collect_compiler_stats('bytes allocated',2)
    
    214
    +     ],
    
    215
    +     compile,
    
    216
    +     ['-v0 -O'])
    
    217
    +
    
    192 218
     #########
    
    193 219
     # The following tests are very sensitive
    
    194 220
     # to coercion optimisation.