diff options
author | Simon Peyton Jones <simon.peytonjones@gmail.com> | 2023-02-07 22:14:56 +0000 |
---|---|---|
committer | Simon Peyton Jones <simon.peytonjones@gmail.com> | 2023-02-15 21:13:58 +0100 |
commit | 1ce710bfd63468f8e088faa354bec4db7967a782 (patch) | |
tree | b6b597e003b2af6123dda64d7ff5ee0a1c132571 /compiler/GHC/Tc/Solver/InertSet.hs | |
parent | 9ca51f9e84abc41ba590203d8bc8df8d6af86db2 (diff) | |
download | haskell-wip/T22924.tar.gz |
Narrow the dont-decompose-newtype testwip/T22924
Following #22924 this patch narrows the test that stops
us decomposing newtypes. The key change is the use of
noGivenNewtypeReprEqs in GHC.Tc.Solver.Canonical.canTyConApp.
We went to and fro on the solution, as you can see in #22924.
The result is carefully documented in
Note [Decomoposing newtype equalities]
On the way I had revert most of
commit 3e827c3f74ef76d90d79ab6c4e71aa954a1a6b90
Author: Richard Eisenberg <rae@cs.brynmawr.edu>
Date: Mon Dec 5 10:14:02 2022 -0500
Do newtype unwrapping in the canonicaliser and rewriter
See Note [Unwrap newtypes first], which has the details.
It turns out that
(a) 3e827c3f makes GHC behave worse on some recursive newtypes
(see one of the tests on this commit)
(b) the finer-grained test (namely noGivenNewtypeReprEqs) renders
3e827c3f unnecessary
Diffstat (limited to 'compiler/GHC/Tc/Solver/InertSet.hs')
-rw-r--r-- | compiler/GHC/Tc/Solver/InertSet.hs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/compiler/GHC/Tc/Solver/InertSet.hs b/compiler/GHC/Tc/Solver/InertSet.hs index 60b422e1fc..3b565f378c 100644 --- a/compiler/GHC/Tc/Solver/InertSet.hs +++ b/compiler/GHC/Tc/Solver/InertSet.hs @@ -21,7 +21,7 @@ module GHC.Tc.Solver.InertSet ( addInertItem, noMatchableGivenDicts, - noGivenIrreds, + noGivenNewtypeReprEqs, mightEqualLater, prohibitedSuperClassSolve, @@ -1537,9 +1537,22 @@ isOuterTyVar tclvl tv -- becomes "outer" even though its level numbers says it isn't. | otherwise = False -- Coercion variables; doesn't much matter -noGivenIrreds :: InertSet -> Bool -noGivenIrreds (IS { inert_cans = inert_cans }) - = isEmptyBag (inert_irreds inert_cans) +noGivenNewtypeReprEqs :: TyCon -> InertSet -> Bool +-- True <=> there is no Irred looking like (N tys1 ~ N tys2) +-- See Note [Decomposing newtype equalities] (EX2) in GHC.Tc.Solver.Canonical +-- This is the only call site. +noGivenNewtypeReprEqs tc inerts + = not (anyBag might_help (inert_irreds (inert_cans inerts))) + where + might_help ct + = case classifyPredType (ctPred ct) of + EqPred ReprEq t1 t2 + | Just (tc1,_) <- tcSplitTyConApp_maybe t1 + , tc == tc1 + , Just (tc2,_) <- tcSplitTyConApp_maybe t2 + , tc == tc2 + -> True + _ -> False -- | Returns True iff there are no Given constraints that might, -- potentially, match the given class consraint. This is used when checking to see if a |