diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2021-05-04 08:29:21 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-01-26 19:45:22 -0500 |
commit | 590a2918d815edd184a1665e361640a29674cbf3 (patch) | |
tree | d1d6914f8f006b9fe164192e5cd8119584200725 /testsuite | |
parent | e840582943eaa49e739fc9d801d2f0925daac0a0 (diff) | |
download | haskell-590a2918d815edd184a1665e361640a29674cbf3.tar.gz |
Make RULE matching insensitive to eta-expansion
This patch fixes #19790 by making the rule matcher do on-the-fly
eta reduction. See Note [Eta reduction the target] in GHC.Core.Rules
I found I also had to careful about casts when matching; see
Note [Casts in the target] and Note [Casts in the template]
Lots more comments and Notes in the rule matcher
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T19790.hs | 19 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T19790.stderr | 7 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/all.T | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T19790.hs b/testsuite/tests/simplCore/should_compile/T19790.hs new file mode 100644 index 0000000000..98f1d32836 --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T19790.hs @@ -0,0 +1,19 @@ +module T19790 where + +newtype Stream = MkStream { unStream :: Int -> Int } + +fromStream :: Stream -> [Int] +{-# NOINLINE fromStream #-} +fromStream (MkStream f) = map f [1,2] + +toStream :: [Int] -> Stream +{-# NOINLINE toStream #-} +toStream xs = MkStream (\x -> x + length xs) + + +foo :: [Int] -> [Int] +foo xs = fromStream (MkStream (\p -> unStream (toStream xs) p)) + +-- The question is: does this rule fire? It should! +{-# RULES "This rule should fire!" forall xs. fromStream (toStream xs) = xs #-} + diff --git a/testsuite/tests/simplCore/should_compile/T19790.stderr b/testsuite/tests/simplCore/should_compile/T19790.stderr new file mode 100644 index 0000000000..71632231f7 --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T19790.stderr @@ -0,0 +1,7 @@ +Rule fired: Class op + (BUILTIN) +Rule fired: Class op length (BUILTIN) +Rule fired: map (GHC.Base) +Rule fired: fold/build (GHC.Base) +Rule fired: This rule should fire! (T19790) +Rule fired: length (GHC.List) +Rule fired: lengthList (GHC.List) diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T index 7285b91c45..9988457432 100644 --- a/testsuite/tests/simplCore/should_compile/all.T +++ b/testsuite/tests/simplCore/should_compile/all.T @@ -377,5 +377,5 @@ test('T20200a', normal, compile, ['-O2']) test('T20200b', normal, compile, ['-O2']) test('T20200KG', [extra_files(['T20200KGa.hs', 'T20200KG.hs-boot'])], multimod_compile, ['T20200KG', '-v0 -O2 -fspecialise-aggressively']) test('T20639', normal, compile, ['-O2']) - test('T20894', normal, compile, ['-dcore-lint -O1 -ddebug-output']) +test('T19790', normal, compile, ['-O -ddump-rule-firings']) |