[Git][ghc/ghc][wip/t22707] Don't suppress *all* Wanteds.

Richard Eisenberg (@rae) gitlab at gitlab.haskell.org
Tue Jan 31 22:43:30 UTC 2023



Richard Eisenberg pushed to branch wip/t22707 at Glasgow Haskell Compiler / GHC


Commits:
4280524c by Richard Eisenberg at 2023-01-31T17:43:19-05:00
Don't suppress *all* Wanteds.

Close #22707

- - - - -


5 changed files:

- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Types/Constraint.hs
- + testsuite/tests/typecheck/should_fail/T22707.hs
- + testsuite/tests/typecheck/should_fail/T22707.stderr
- testsuite/tests/typecheck/should_fail/all.T


Changes:

=====================================
compiler/GHC/Tc/Errors.hs
=====================================
@@ -476,6 +476,10 @@ mkErrorItem ct
                             , ei_m_reason = m_reason
                             , ei_suppress = suppress }}
 
+-- | Actually report this 'ErrorItem'.
+unsuppressErrorItem :: ErrorItem -> ErrorItem
+unsuppressErrorItem ei = ei { ei_suppress = False }
+
 ----------------------------------------------------------------
 reportWanteds :: SolverReportErrCtxt -> TcLevel -> WantedConstraints -> TcM ()
 reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics
@@ -489,17 +493,17 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics
                                          , text "tidy_items =" <+> ppr tidy_items
                                          , text "tidy_errs =" <+> ppr tidy_errs ])
 
-       -- This check makes sure that we aren't suppressing the only error that will
-       -- actually stop compilation
-       ; assertPprM
-           ( do { errs_already <- ifErrsM (return True) (return False)
-                ; return $
-                    errs_already ||                  -- we already reported an error (perhaps from an outer implication)
-                    null simples ||                  -- no errors to report here
-                    any ignoreConstraint simples ||  -- one error is ignorable (is reported elsewhere)
-                    not (all ei_suppress tidy_items) -- not all errors are suppressed
-                } )
-           (vcat [text "reportWanteds is suppressing all errors"])
+         -- See Wrinkle at end of Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint
+         -- If * there are no errors already reported
+         --    * no constraint should be ignored (ignored constraints always lead to an
+         --      error elsewhere), AND
+         --    * all the current error items are suppressed
+         -- then unsuppress the lot. This makes sure we don't forget to report an error
+         -- at all.
+       ; tidy_items <- ifErrsM (return tidy_items) $
+           return $ if any ignoreConstraint simples || not (all ei_suppress tidy_items)
+                    then tidy_items
+                    else map unsuppressErrorItem tidy_items
 
          -- First, deal with any out-of-scope errors:
        ; let (out_of_scope, other_holes, not_conc_errs) = partition_errors tidy_errs


=====================================
compiler/GHC/Tc/Types/Constraint.hs
=====================================
@@ -2127,10 +2127,10 @@ uses GHC.Tc.Utils.anyUnfilledCoercionHoles to look through any filled coercion
 holes. The idea is that we wish to report the "root cause" -- the error that
 rewrote all the others.
 
-Worry: It seems possible that *all* unsolved wanteds are rewritten by other
-unsolved wanteds, so that e.g. w1 has w2 in its rewriter set, and w2 has
-w1 in its rewiter set. We are unable to come up with an example of this in
-practice, however, and so we believe this case cannot happen.
+Wrinkle: In #22707, we have a case where all of the Wanteds have rewritten
+each other. In order to report /some/ error in this case, we simply report
+all the Wanteds. The user will get a perhaps-confusing error message, but
+they've written a confusing program!
 
 Note [Avoiding rewriting cycles]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


=====================================
testsuite/tests/typecheck/should_fail/T22707.hs
=====================================
@@ -0,0 +1,17 @@
+module T22707 where
+
+newtype Cont o i a = Cont {runCont ::(a -> i) -> o }
+t1:: Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
+t1 c = Cont $ \ati1tti2 -> (runCont c) (ati1tti2 $ \a -> evalCont (t1 c) >>== \ati1 -> return ati1 a )
+evalCont:: Cont o a a -> o
+evalCont c = (runCont c)id
+instance Monad (Cont p p) where
+  return a = Cont ($ a)
+  (>>=) = (>>==)
+class PMonad m where
+  (>>==):: m p q a -> (a -> m q r b) -> m p r b
+instance PMonad Cont where
+ (Cont cont) >>== afmb = Cont $ \bti -> cont $ \a -> (runCont . afmb) a bti
+main:: IO ()
+main = putStrLn "bug"
+er
\ No newline at end of file


=====================================
testsuite/tests/typecheck/should_fail/T22707.stderr
=====================================
@@ -0,0 +1,16 @@
+
+T22707.hs:5:37: error: [GHC-18872]
+    • Couldn't match kind ‘*’ with ‘GHC.Types.RuntimeRep’
+      When matching types
+        p0 :: *
+        GHC.Types.LiftedRep :: GHC.Types.RuntimeRep
+      Expected: Cont o i1 a
+        Actual: Cont (i2 -> o) i1 a
+    • In the first argument of ‘runCont’, namely ‘c’
+      In the expression:
+        (runCont c)
+          (ati1tti2 $ \ a -> evalCont (t1 c) >>== \ ati1 -> return ati1 a)
+      In the second argument of ‘($)’, namely
+        ‘\ ati1tti2
+           -> (runCont c)
+                (ati1tti2 $ \ a -> evalCont (t1 c) >>== \ ati1 -> ...)’


=====================================
testsuite/tests/typecheck/should_fail/all.T
=====================================
@@ -321,6 +321,7 @@ test('T7856', normal, compile_fail, [''])
 test('T7869', normal, compile_fail, [''])
 test('T7892', normal, compile_fail, [''])
 test('T7809', normal, compile_fail, [''])
+test('T22707', normal, compile_fail, [''])
 test('T7989', normal, compile_fail, [''])
 test('T8034', normal, compile_fail, [''])
 test('T8142', normal, compile_fail, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4280524cca31b03473be6b82c03c24f92923c727

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4280524cca31b03473be6b82c03c24f92923c727
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230131/42c4361c/attachment-0001.html>


More information about the ghc-commits mailing list