Assume at least one evaluation for nested SubDemands (#21081, #21133)
See the new `Note [SubDemand denotes at least one evaluation]`. A demand `n :* sd` on a let binder `x=e` now means > "`x` was evaluated `n` times and in any program trace it is evaluated, `e` is > evaluated deeply in sub-demand `sd`." The "any time it is evaluated" premise is what this patch adds. As a result, we get better nested strictness. For example (T21081) ```hs f :: (Bool, Bool) -> (Bool, Bool) f pr = (case pr of (a,b) -> a /= b, True) -- before: <MP(L,L)> -- after: <MP(SL,SL)> g :: Int -> (Bool, Bool) g x = let y = let z = odd x in (z,z) in f y ``` The change in demand signature "before" to "after" allows us to case-bind `z` here. Similarly good things happen for the `sd` in call sub-demands `Cn(sd)`, which allows for more eta-reduction (which is only sound with `-fno-pedantic-bottoms`, albeit). We also fix #21085, a surprising inconsistency with `Poly` to `Call` sub-demand expansion. In an attempt to fix a regression caused by less inlining due to eta-reduction in T15426, I eta-expanded the definition of `elemIndex` and `elemIndices`, thus fixing #21345 on the go. The main point of this patch is that it fixes #21081 and #21133. Annoyingly, I discovered that more precise demand signatures for join points can transform a program into a lazier program if that join point gets floated to the top-level, see #21392. There is no simple fix at the moment, but !5349 might. Thus, we accept a ~5% regression in `MultiLayerModulesTH_OneShot`, where #21392 bites us in `addListToUniqDSet`. T21392 reliably reproduces the issue. Surprisingly, ghc/alloc perf on Windows improves much more than on other jobs, by 0.4% in the geometric mean and by 2% in T16875. Metric Increase: MultiLayerModulesTH_OneShot Metric Decrease: T16875
Showing
- compiler/GHC/Core/Opt/Arity.hs 3 additions, 0 deletionscompiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/DmdAnal.hs 9 additions, 6 deletionscompiler/GHC/Core/Opt/DmdAnal.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs 6 additions, 3 deletionscompiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Utils.hs 10 additions, 3 deletionscompiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToStg/Prep.hs 6 additions, 4 deletionscompiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Stg/InferTags/Rewrite.hs 1 addition, 2 deletionscompiler/GHC/Stg/InferTags/Rewrite.hs
- compiler/GHC/Stg/Lift/Analysis.hs 1 addition, 1 deletioncompiler/GHC/Stg/Lift/Analysis.hs
- compiler/GHC/Types/Demand.hs 357 additions, 138 deletionscompiler/GHC/Types/Demand.hs
- libraries/base/Data/OldList.hs 4 additions, 4 deletionslibraries/base/Data/OldList.hs
- testsuite/tests/arityanal/should_compile/Arity01.stderr 18 additions, 18 deletionstestsuite/tests/arityanal/should_compile/Arity01.stderr
- testsuite/tests/arityanal/should_compile/Arity05.stderr 13 additions, 13 deletionstestsuite/tests/arityanal/should_compile/Arity05.stderr
- testsuite/tests/arityanal/should_compile/Arity08.stderr 6 additions, 6 deletionstestsuite/tests/arityanal/should_compile/Arity08.stderr
- testsuite/tests/arityanal/should_compile/Arity11.stderr 59 additions, 41 deletionstestsuite/tests/arityanal/should_compile/Arity11.stderr
- testsuite/tests/arityanal/should_compile/Arity14.stderr 17 additions, 17 deletionstestsuite/tests/arityanal/should_compile/Arity14.stderr
- testsuite/tests/arityanal/should_compile/Arity16.stderr 9 additions, 9 deletionstestsuite/tests/arityanal/should_compile/Arity16.stderr
- testsuite/tests/simplCore/should_compile/OpaqueNoSpecialise.stderr 4 additions, 1 deletion.../tests/simplCore/should_compile/OpaqueNoSpecialise.stderr
- testsuite/tests/simplCore/should_compile/T18013.stderr 1 addition, 1 deletiontestsuite/tests/simplCore/should_compile/T18013.stderr
- testsuite/tests/simplCore/should_compile/T21261.hs 12 additions, 8 deletionstestsuite/tests/simplCore/should_compile/T21261.hs
- testsuite/tests/simplCore/should_compile/T21261.stderr 7 additions, 9 deletionstestsuite/tests/simplCore/should_compile/T21261.stderr
- testsuite/tests/simplCore/should_compile/T21261_pedantic.hs 18 additions, 0 deletionstestsuite/tests/simplCore/should_compile/T21261_pedantic.hs
Loading
Please register or sign in to comment