Strictness analyser should be smarter
This module:
module Q (foo) where
foo :: String -> [String] -> Bool
#ifdef FIRST
foo x _ | x `seq` x == "." = True
#else
foo x _ | x == "." = True
#endif
foo x xs = x `seq` any (x ==) xs
should be compiled to the same code regardless of whether or not FIRST is defined. However, this is not the case; there is an extra case when FIRST is not defined:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.1
$ ghc -fforce-recomp -ddump-simpl -cpp -O -c Q.hs -DFIRST > 1
$ ghc -fforce-recomp -ddump-simpl -cpp -O -c Q.hs > 2
$ diff -U 1000 1 2
--- 1 2007-11-17 21:02:37.000000000 +0000
+++ 2 2007-11-17 21:02:39.000000000 +0000
@@ -1,33 +1,35 @@
==================== Tidy Core ====================
Q.a :: GHC.Base.Char
[GlobalId]
[NoCafRefs
Str: DmdType m]
Q.a = GHC.Base.C# '.'
Q.lvl :: [GHC.Base.Char]
[GlobalId]
[NoCafRefs
Str: DmdType]
Q.lvl = GHC.Base.: @ GHC.Base.Char Q.a (GHC.Base.[] @ GHC.Base.Char)
Q.foo :: GHC.Base.String -> [GHC.Base.String] -> GHC.Base.Bool
[GlobalId]
[Arity 2
NoCafRefs
Str: DmdType SL]
Q.foo =
- \ (x_a5D :: GHC.Base.String) (ds_d6y :: [GHC.Base.String]) ->
- case GHC.Base.eqString x_a5D Q.lvl of wild_Xc {
+ \ (x_a5D :: GHC.Base.String) (ds_d6w :: [GHC.Base.String]) ->
+ case GHC.Base.eqString x_a5D Q.lvl of wild_B1 {
GHC.Base.False ->
- GHC.List.any @ GHC.Base.String (GHC.Base.eqString x_a5D) ds_d6y;
+ case x_a5D of tpl_Xd { __DEFAULT ->
+ GHC.List.any @ GHC.Base.String (GHC.Base.eqString tpl_Xd) ds_d6w
+ };
GHC.Base.True -> GHC.Base.True
}
==================== Tidy Core Rules ====================
$
There is a little discussion in the thread where this was first reported: http://www.haskell.org/pipermail/glasgow-haskell-users/2004-June/006862.html
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |