[commit: ghc] master: Narrow the warning for simplifiable constraints (643706e)

git at git.haskell.org git at git.haskell.org
Thu Jun 23 09:16:03 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/643706e44935cd15c2248e5345dadd3e9804688e/ghc

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

commit 643706e44935cd15c2248e5345dadd3e9804688e
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Jun 23 08:50:45 2016 +0100

    Narrow the warning for simplifiable constraints
    
    In Trac #11948 I added the warning
        -Wsimplifiable-class-constraints
    which warns if the class constraints in a type signature are
    simplifiable.
    
    But in fact the fragility it warns about only happens with
    NoMonoLocalBinds, so this patch switches off the warning if
    you have MonoLocalBinds (and suggests using it in the error
    message).
    
    See Note [Simplifiable given constraints] in TcValidity.


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

643706e44935cd15c2248e5345dadd3e9804688e
 compiler/typecheck/TcValidity.hs                     | 20 ++++++++++++++------
 .../should_compile/SomethingShowable.stderr          |  4 ++--
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs
index fb1a567..4653eaa 100644
--- a/compiler/typecheck/TcValidity.hs
+++ b/compiler/typecheck/TcValidity.hs
@@ -863,6 +863,8 @@ check_class_pred env dflags ctxt pred cls tys
 
     -- See Note [Simplifiable given constraints]
     check_simplifiable_class_constraint
+       | xopt LangExt.MonoLocalBinds dflags
+       = return ()
        | DataTyCtxt {} <- ctxt   -- Don't do this check for the "stupid theta"
        = return ()               -- of a data type declaration
        | otherwise
@@ -879,8 +881,8 @@ check_class_pred env dflags ctxt pred cls tys
      = vcat [ hang (text "The constraint" <+> quotes (ppr (tidyType env pred)))
                  2 (text "matches an instance declaration")
             , ppr match
-            , hang (text "This makes type inference very fragile;")
-                 2 (text "try simplifying it using the instance") ]
+            , hang (text "This makes type inference for inner bindings fragile;")
+                 2 (text "either use MonoLocalBinds, or simplify it using the instance") ]
     simplifiable_constraint_warn [] = pprPanic "check_class_pred" (ppr pred)
 
 {- Note [Simplifiable given constraints]
@@ -888,10 +890,16 @@ check_class_pred env dflags ctxt pred cls tys
 A type signature like
    f :: Eq [(a,b)] => a -> b
 is very fragile, for reasons described at length in TcInteract
-Note [Instance and Given overlap].  So this warning discourages uses
-from writing simplifiable class constraints, at least unless the
-top-level instance is explicitly declared as OVERLAPPABLE.
-Trac #11948 provoked me to do this.
+Note [Instance and Given overlap].  As that Note discusses, for the
+most part the clever stuff in TcInteract means that we don't use a
+top-level instance if a local Given might fire, so there is no
+fragility. But if we /infer/ the type of a local let-binding, things
+can go wrong (Trac #11948 is an example, discussed in the Note).
+
+So this warning is switched on only if we have NoMonoLocalBinds; in
+that case the warning discourages uses from writing simplifiable class
+constraints, at least unless the top-level instance is explicitly
+declared as OVERLAPPABLE.
 -}
 
 -------------------------
diff --git a/testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr b/testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr
index 40f15bf..88beccf 100644
--- a/testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr
+++ b/testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr
@@ -9,5 +9,5 @@ Dependent packages: [base-4.9.0.0, ghc-prim-0.5.0.0,
 SomethingShowable.hs:5:1: warning: [-Wsimplifiable-class-constraints (in -Wdefault)]
     The constraint ‘Show Bool’ matches an instance declaration
     instance Show Bool -- Defined in ‘GHC.Show’
-    This makes type inference very fragile;
-      try simplifying it using the instance
+    This makes type inference for inner bindings fragile;
+      either use MonoLocalBinds, or simplify it using the instance



More information about the ghc-commits mailing list