summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T15426.hs
blob: cbc74d53378326cc72405b9839f043fe47c12360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Control.Exception (evaluate)
import qualified Data.List as L

-- The following will fuse with minimal heap usage provided
-- `findIndices` is marked `INLINABLE` instead of `INLINE`.

unsafeFindIndex p = head . L.findIndices p

main = do evaluate $ L.elemIndex 999999 [(1::Int)..1000000]
          evaluate $ L.elemIndices 999999 [(1::Int)..1000000]
          evaluate $ L.findIndex (>=999999) [(1::Int)..1000000]
          evaluate $ L.findIndices (>=999999) [(1::Int)..1000000]
          evaluate $ unsafeFindIndex (>=999999) [(1::Int)..1000000]

{- Note; see !7997.

You would think those [1..100000] sub-expressions would float to the
top level, be CSE'd, and shared.

But no: until May 22-ish, they are the argument of a strict function
findIndices; and in HEAD SetLevels goes to some trouble not to float
strict arguments. So in HEAD, no sharing happens.

I think the reasoning is bogus, so I changed in; see
"Arguments" in Note [Floating to the top] in SetLevels.

As a result these lists are now floated out and shared.

Just leaving breadcrumbs, in case we later see big perf changes on
this (slightly fragile) benchmark.
-}