summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorSimon Peyton Jones <simon.peytonjones@gmail.com>2023-01-17 12:00:15 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-10 06:51:28 -0500
commite45eb82830d6de4d09abb548e190be980dd001b4 (patch)
treed42f91c19d86b8d08018bcf27319410b100b07f4 /testsuite
parentfe9cd6ef1a07d214b76bc286875cbf15985d9a7b (diff)
downloadhaskell-e45eb82830d6de4d09abb548e190be980dd001b4.tar.gz
Refactor the simplifier a bit to fix #22761
The core change in this commit, which fixes #22761, is that * In a Core rule, ru_rhs is always occ-analysed. This means adding a couple of calls to occurAnalyseExpr when building a Rule, in * GHC.Core.Rules.mkRule * GHC.Core.Opt.Simplify.Iteration.simplRules But diagosing the bug made me stare carefully at the code of the Simplifier, and I ended up doing some only-loosely-related refactoring. * I think that RULES could be lost because not every code path did addBndrRules * The code around lambdas was very convoluted It's mainly moving deck chairs around, but I like it more now.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/simplCore/should_compile/T22761.hs40
-rw-r--r--testsuite/tests/simplCore/should_compile/T22761a.hs4
-rw-r--r--testsuite/tests/simplCore/should_compile/all.T1
3 files changed, 45 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T22761.hs b/testsuite/tests/simplCore/should_compile/T22761.hs
new file mode 100644
index 0000000000..a396ecdc94
--- /dev/null
+++ b/testsuite/tests/simplCore/should_compile/T22761.hs
@@ -0,0 +1,40 @@
+module T22761 where
+
+import T22761a
+
+newtype Mod m = Mod m deriving Num
+
+gcdExt :: Integer -> (Integer, Integer)
+gcdExt x = go 0 x
+ where
+ go !_ 0 = (1, 1)
+ go r _ = go r r
+
+pow :: (Num m) => Mod m -> Mod m
+pow x = x*x*x
+{-# NOINLINE [1] pow #-}
+{-# RULES
+"powMod/3/Int" forall x. pow x = x*x*x
+#-}
+
+
+-- GHC puts `boo1` after `wom1` (since they don't appear connected)
+-- Then { wom1 = foo True } rewrites to { wom1 = boo False }
+-- so we need to do glomming. And that triggers the bug
+-- in the RULE for `pow`!
+--
+-- wom2/boo2 are there to still elicit the bug if
+-- GHC reverses its default ordering
+
+{-# RULES
+"wombat1" foo True = boo1 False
+#-}
+
+wom1 = foo True
+boo1 x = x
+
+{-# RULES
+"wombat2" foo True = boo2 False
+#-}
+boo2 x = x
+wom2 = foo True
diff --git a/testsuite/tests/simplCore/should_compile/T22761a.hs b/testsuite/tests/simplCore/should_compile/T22761a.hs
new file mode 100644
index 0000000000..5d40815a2e
--- /dev/null
+++ b/testsuite/tests/simplCore/should_compile/T22761a.hs
@@ -0,0 +1,4 @@
+module T22761a where
+
+{-# NOINLINE [0] foo #-}
+foo x = x
diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T
index 0ef452b743..12e2ecf042 100644
--- a/testsuite/tests/simplCore/should_compile/all.T
+++ b/testsuite/tests/simplCore/should_compile/all.T
@@ -471,5 +471,6 @@ test('T22611', [when(wordsize(32), skip), grep_errmsg(r'\$salterF') ], compile,
test('T22715_2', normal, multimod_compile, ['T22715_2', '-v0 -O -fspecialise-aggressively'])
test('T22802', normal, compile, ['-O'])
test('T15205', normal, compile, ['-O -ddump-simpl -dno-typeable-binds -dsuppress-uniques'])
+test('T22761', normal, multimod_compile, ['T22761', '-O2 -v0'])
test('RewriteHigherOrderPatterns', normal, compile, ['-O -ddump-rule-rewrites -dsuppress-all -dsuppress-uniques'])