diff options
author | Richard Eisenberg <rae@richarde.dev> | 2022-02-18 23:29:52 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-02-23 08:16:07 -0500 |
commit | a599abbad939820c666ced00ae9eb33706a4f360 (patch) | |
tree | 7b3811972a50da9e81018056cdcdeef158bc22e3 /compiler/GHC/Runtime/Eval.hs | |
parent | 558c7d554b9724abfaa2bcc1f42050e67b36a988 (diff) | |
download | haskell-a599abbad939820c666ced00ae9eb33706a4f360.tar.gz |
Kill derived constraints
Co-authored by: Sam Derbyshire
Previously, GHC had three flavours of constraint:
Wanted, Given, and Derived. This removes Derived constraints.
Though serving a number of purposes, the most important role
of Derived constraints was to enable better error messages.
This job has been taken over by the new RewriterSets, as explained
in Note [Wanteds rewrite wanteds] in GHC.Tc.Types.Constraint.
Other knock-on effects:
- Various new Notes as I learned about under-described bits of GHC
- A reshuffling around the AST for implicit-parameter bindings,
with better integration with TTG.
- Various improvements around fundeps. These were caused by the
fact that, previously, fundep constraints were all Derived,
and Derived constraints would get dropped. Thus, an unsolved
Derived didn't stop compilation. Without Derived, this is no
longer possible, and so we have to be considerably more careful
around fundeps.
- A nice little refactoring in GHC.Tc.Errors to center the work
on a new datatype called ErrorItem. Constraints are converted
into ErrorItems at the start of processing, and this allows for
a little preprocessing before the main classification.
- This commit also cleans up the behavior in generalisation around
functional dependencies. Now, if a variable is determined by
functional dependencies, it will not be quantified. This change
is user facing, but it should trim down GHC's strange behavior
around fundeps.
- Previously, reportWanteds did quite a bit of work, even on an empty
WantedConstraints. This commit adds a fast path.
- Now, GHC will unconditionally re-simplify constraints during
quantification. See Note [Unconditionally resimplify constraints when
quantifying], in GHC.Tc.Solver.
Close #18398.
Close #18406.
Solve the fundep-related non-confluence in #18851.
Close #19131.
Close #19137.
Close #20922.
Close #20668.
Close #19665.
-------------------------
Metric Decrease:
LargeRecord
T9872b
T9872b_defer
T9872d
TcPlugin_RewritePerf
-------------------------
Diffstat (limited to 'compiler/GHC/Runtime/Eval.hs')
-rw-r--r-- | compiler/GHC/Runtime/Eval.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/compiler/GHC/Runtime/Eval.hs b/compiler/GHC/Runtime/Eval.hs index b4bf25b9b3..9f2c257435 100644 --- a/compiler/GHC/Runtime/Eval.hs +++ b/compiler/GHC/Runtime/Eval.hs @@ -1063,15 +1063,11 @@ getDictionaryBindings theta = do let dict_var = mkVanillaGlobal dictName theta loc <- getCtLocM (GivenOrigin (getSkolemInfo unkSkol)) Nothing - -- Generate a wanted here because at the end of constraint - -- solving, most derived constraints get thrown away, which in certain - -- cases, notably with quantified constraints makes it impossible to rule - -- out instances as invalid. (See #18071) return CtWanted { ctev_pred = varType dict_var, ctev_dest = EvVarDest dict_var, - ctev_nosh = WDeriv, - ctev_loc = loc + ctev_loc = loc, + ctev_rewriters = emptyRewriterSet } -- Find instances where the head unifies with the provided type @@ -1132,13 +1128,19 @@ checkForExistence clsInst mb_inst_tys = do -- which otherwise appear as opaque type variables. (See #18262). WC { wc_simple = simples, wc_impl = impls } <- simplifyWantedsTcM wanteds - if allBag allowedSimple simples && solvedImplics impls - then return . Just $ substInstArgs tys (bagToList (mapBag ctPred simples)) clsInst + -- The simples might contain superclasses. This clutters up the output + -- (we want e.g. instance Ord a => Ord (Maybe a), not + -- instance (Ord a, Eq a) => Ord (Maybe a)). So we use mkMinimalBySCs + let simple_preds = map ctPred (bagToList simples) + let minimal_simples = mkMinimalBySCs id simple_preds + + if all allowedSimple minimal_simples && solvedImplics impls + then return . Just $ substInstArgs tys minimal_simples clsInst else return Nothing where - allowedSimple :: Ct -> Bool - allowedSimple ct = isSatisfiablePred (ctPred ct) + allowedSimple :: PredType -> Bool + allowedSimple pred = isSatisfiablePred pred solvedImplics :: Bag Implication -> Bool solvedImplics impls = allBag (isSolvedStatus . ic_status) impls |