[commit: ghc] wip/nested-cpr: Add Note [non-algebraic or open body type warning] (b8faa4e)

git at git.haskell.org git at git.haskell.org
Wed Dec 4 18:06:08 UTC 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nested-cpr
Link       : http://ghc.haskell.org/trac/ghc/changeset/b8faa4ee51232e395e210e16a9c07b360247301a/ghc

>---------------------------------------------------------------

commit b8faa4ee51232e395e210e16a9c07b360247301a
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Wed Dec 4 17:12:07 2013 +0000

    Add Note [non-algebraic or open body type warning]


>---------------------------------------------------------------

b8faa4ee51232e395e210e16a9c07b360247301a
 compiler/stranal/WwLib.lhs |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/compiler/stranal/WwLib.lhs b/compiler/stranal/WwLib.lhs
index d7c0fd2..4ab2609 100644
--- a/compiler/stranal/WwLib.lhs
+++ b/compiler/stranal/WwLib.lhs
@@ -581,7 +581,7 @@ mkWWcpr_help inner ty res
                     , \e body -> mkUnpackCase e co data_con arg_vars (nested_decon body)
                     )
             |  otherwise
-            -> -- I would be happier if this were a error, but there are nasty corner cases.
+            -> -- See Note [non-algebraic or open body type warning]
                WARN ( True, ptext (sLit "mkWwcpr: non-algebraic or open body type") <+>
                                   (ppr ty) <+> ptext (sLit "but CPR type") <+> ppr (res) )
                mkWWcpr_help inner ty topRes
@@ -613,6 +613,25 @@ mkUnpackCase scrut co boxing_con unpk_args body
     casted_scrut = scrut `mkCast` co
 \end{code}
 
+Note [non-algebraic or open body type warning]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+There are a few cases where the W/W transformation is told that something
+returns a constructor, but the type at hand doesn't really match this. One
+real-world example involves unsafeCoerce:
+  foo = IO a
+  foo = unsafeCoere c_exit
+  foreign import ccall "c_exit" c_exit :: IO ()
+Here CPR will tell you that `foo` returns a () constructor for sure, but trying
+to create a worker/wrapper for type `a` obviously fails.
+(This was a real example until ee8e792  in libraries/base.)
+
+It does not seem feasilbe to avoid all such cases already in the analyser (and
+after all, the analysis is not really wrong), so we simply do nothing here in
+mkWWcpr. But we still want to emit warning with -DDEBUG, to hopefully catch
+other cases where something went avoidably wrong.
+
+
 Note [Profiling and unpacking]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 If the original function looked like



More information about the ghc-commits mailing list