summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T23021.hs
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2023-02-27 21:38:21 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-03-01 04:17:56 -0500
commita2a1a1c08bb520b74b00194a83add82b287b38d5 (patch)
treeefc959b19d4229b4eb04c990fe80947962ff6198 /testsuite/tests/perf/should_run/T23021.hs
parent79ffa170a6b0b152da0e02744869311773733286 (diff)
downloadhaskell-a2a1a1c08bb520b74b00194a83add82b287b38d5.tar.gz
Revert the main payload of "Make `drop` and `dropWhile` fuse (#18964)"
This reverts the bits affecting fusion of `drop` and `dropWhile` of commit 0f7588b5df1fc7a58d8202761bf1501447e48914 and keeps just the small refactoring unifying `flipSeqTake` and `flipSeqScanl'` into `flipSeq`. It also adds a new test for #23021 (which was the reason for reverting) as well as adds a clarifying comment to T18964. Fixes #23021, unfixes #18964. Metric Increase: T18964 Metric Decrease: T18964
Diffstat (limited to 'testsuite/tests/perf/should_run/T23021.hs')
-rw-r--r--testsuite/tests/perf/should_run/T23021.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/T23021.hs b/testsuite/tests/perf/should_run/T23021.hs
new file mode 100644
index 0000000000..f68e7ecbcb
--- /dev/null
+++ b/testsuite/tests/perf/should_run/T23021.hs
@@ -0,0 +1,30 @@
+-- The direct implementation of drop and dropWhile operates in O(1) space.
+-- This regression test asserts that potential fusion rules for dropWhile/drop
+-- maintain that property for the fused pipelines in dropWhile2 and drop2 (which
+-- are marked NOINLINE for that purpose).
+-- #23021 was opened because we had fusion rules in place that did not maintain
+-- this property.
+
+dropWhile2 :: Int -> [Int] -> [Int]
+dropWhile2 n = dropWhile (< n) . dropWhile (< n)
+{-# NOINLINE dropWhile2 #-}
+
+drop2 :: Int -> [Int] -> [Int]
+drop2 n = drop n . drop n
+{-# NOINLINE drop2 #-}
+
+main :: IO ()
+main = do
+ let xs = [0..9999999]
+ print $ last $ dropWhile2 0 xs
+ print $ last $ dropWhile2 1 xs
+ print $ last $ dropWhile2 2 xs
+ print $ last $ dropWhile2 3 xs
+ print $ last $ dropWhile2 4 xs
+ print $ last $ dropWhile2 5 xs
+ print $ last $ drop2 0 xs
+ print $ last $ drop2 1 xs
+ print $ last $ drop2 2 xs
+ print $ last $ drop2 3 xs
+ print $ last $ drop2 4 xs
+ print $ last $ drop2 5 xs