Simon Peyton Jones pushed to branch wip/T26115 at Glasgow Haskell Compiler / GHC
Commits:
-
c1f7d8ea
by Simon Peyton Jones at 2025-07-21T12:07:01+01:00
-
38758a5d
by Simon Peyton Jones at 2025-07-21T12:07:01+01:00
-
ed5d029b
by Simon Peyton Jones at 2025-07-21T12:07:01+01:00
30 changed files:
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Infer.hs
- compiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Default.hs
- compiler/GHC/Tc/Solver/Equality.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Solve.hs
- + compiler/GHC/Tc/Solver/Solve.hs-boot
- compiler/GHC/Tc/Zonk/Type.hs
- testsuite/tests/deriving/should_compile/T20815.hs
- testsuite/tests/impredicative/T17332.stderr
- testsuite/tests/quantified-constraints/T15290a.stderr
- testsuite/tests/quantified-constraints/T19690.stderr
- testsuite/tests/quantified-constraints/T19921.stderr
- testsuite/tests/quantified-constraints/T21006.stderr
- testsuite/tests/typecheck/should_compile/T12427a.stderr
- testsuite/tests/typecheck/should_fail/T14605.hs
- testsuite/tests/typecheck/should_fail/T14605.stderr
- testsuite/tests/typecheck/should_fail/T15801.stderr
- testsuite/tests/typecheck/should_fail/T18640a.stderr
- testsuite/tests/typecheck/should_fail/T18640b.stderr
- testsuite/tests/typecheck/should_fail/T19627.stderr
- testsuite/tests/typecheck/should_fail/T21530b.stderr
- testsuite/tests/typecheck/should_fail/T22912.stderr
- testsuite/tests/typecheck/should_fail/tcfail174.stderr
Changes:
| ... | ... | @@ -32,12 +32,12 @@ import GHC.Types.Basic |
| 32 | 32 | import GHC.Data.BooleanFormula
|
| 33 | 33 | import GHC.Core.Class ( className, classSCSelIds )
|
| 34 | 34 | import GHC.Core.ConLike ( conLikeName )
|
| 35 | -import GHC.Core.FVs
|
|
| 36 | 35 | import GHC.Core.DataCon ( dataConNonlinearType )
|
| 37 | 36 | import GHC.Types.FieldLabel
|
| 38 | 37 | import GHC.Hs
|
| 39 | 38 | import GHC.Hs.Syn.Type
|
| 40 | 39 | import GHC.Utils.Monad ( concatMapM, MonadIO(liftIO) )
|
| 40 | +import GHC.Utils.FV ( fvVarList, filterFV )
|
|
| 41 | 41 | import GHC.Types.Id ( isDataConId_maybe )
|
| 42 | 42 | import GHC.Types.Name ( Name, nameSrcSpan, nameUnique, wiredInNameTyThing_maybe, getName )
|
| 43 | 43 | import GHC.Types.Name.Env ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
|
| ... | ... | @@ -45,8 +45,8 @@ import GHC.Types.Name.Reader ( RecFieldInfo(..), WithUserRdr(..) ) |
| 45 | 45 | import GHC.Types.SrcLoc
|
| 46 | 46 | import GHC.Core.Type ( Type, ForAllTyFlag(..) )
|
| 47 | 47 | import GHC.Core.TyCon ( TyCon, tyConClass_maybe )
|
| 48 | -import GHC.Core.Predicate
|
|
| 49 | 48 | import GHC.Core.InstEnv
|
| 49 | +import GHC.Core.Predicate ( isEvId )
|
|
| 50 | 50 | import GHC.Tc.Types
|
| 51 | 51 | import GHC.Tc.Types.Evidence
|
| 52 | 52 | import GHC.Types.Var ( Id, Var, EvId, varName, varType, varUnique )
|
| ... | ... | @@ -672,22 +672,16 @@ instance ToHie (Context (Located Name)) where |
| 672 | 672 | instance ToHie (Context (Located (WithUserRdr Name))) where
|
| 673 | 673 | toHie (C c (L l (WithUserRdr _ n))) = toHie $ C c (L l n)
|
| 674 | 674 | |
| 675 | -evVarsOfTermList :: EvTerm -> [EvId]
|
|
| 676 | -evVarsOfTermList (EvExpr e) = exprSomeFreeVarsList isEvVar e
|
|
| 677 | -evVarsOfTermList (EvTypeable _ ev) =
|
|
| 678 | - case ev of
|
|
| 679 | - EvTypeableTyCon _ e -> concatMap evVarsOfTermList e
|
|
| 680 | - EvTypeableTyApp e1 e2 -> concatMap evVarsOfTermList [e1,e2]
|
|
| 681 | - EvTypeableTrFun e1 e2 e3 -> concatMap evVarsOfTermList [e1,e2,e3]
|
|
| 682 | - EvTypeableTyLit e -> evVarsOfTermList e
|
|
| 683 | -evVarsOfTermList (EvFun{}) = []
|
|
| 675 | +hieEvIdsOfTerm :: EvTerm -> [EvId]
|
|
| 676 | +-- Returns only EvIds satisfying relevantEvId
|
|
| 677 | +hieEvIdsOfTerm tm = fvVarList (filterFV isEvId (evTermFVs tm))
|
|
| 684 | 678 | |
| 685 | 679 | instance ToHie (EvBindContext (LocatedA TcEvBinds)) where
|
| 686 | 680 | toHie (EvBindContext sc sp (L span (EvBinds bs)))
|
| 687 | 681 | = concatMapM go $ bagToList bs
|
| 688 | 682 | where
|
| 689 | 683 | go evbind = do
|
| 690 | - let evDeps = evVarsOfTermList $ eb_rhs evbind
|
|
| 684 | + let evDeps = hieEvIdsOfTerm $ eb_rhs evbind
|
|
| 691 | 685 | depNames = EvBindDeps $ map varName evDeps
|
| 692 | 686 | concatM $
|
| 693 | 687 | [ toHie (C (EvidenceVarBind (EvLetBind depNames) (combineScopes sc (mkScope span)) sp)
|
| ... | ... | @@ -708,7 +702,7 @@ instance ToHie (LocatedA HsWrapper) where |
| 708 | 702 | toHie $ C (EvidenceVarBind EvWrapperBind (mkScope osp) (getRealSpanA osp))
|
| 709 | 703 | $ L osp a
|
| 710 | 704 | (WpEvApp a) ->
|
| 711 | - concatMapM (toHie . C EvidenceVarUse . L osp) $ evVarsOfTermList a
|
|
| 705 | + concatMapM (toHie . C EvidenceVarUse . L osp) $ hieEvIdsOfTerm a
|
|
| 712 | 706 | _ -> pure []
|
| 713 | 707 | |
| 714 | 708 | instance HiePass p => HasType (LocatedA (HsBind (GhcPass p))) where
|
| ... | ... | @@ -1432,13 +1432,13 @@ See Note [Eta reduction for data families] in GHC.Core.Coercion.Axiom |
| 1432 | 1432 | -- EarlyDerivSpec from it.
|
| 1433 | 1433 | mk_eqn_from_mechanism :: DerivSpecMechanism -> DerivM EarlyDerivSpec
|
| 1434 | 1434 | mk_eqn_from_mechanism mechanism
|
| 1435 | - = do DerivEnv { denv_overlap_mode = overlap_mode
|
|
| 1436 | - , denv_tvs = tvs
|
|
| 1437 | - , denv_cls = cls
|
|
| 1438 | - , denv_inst_tys = inst_tys
|
|
| 1439 | - , denv_ctxt = deriv_ctxt
|
|
| 1440 | - , denv_skol_info = skol_info
|
|
| 1441 | - , denv_warn = warn } <- ask
|
|
| 1435 | + = do env@(DerivEnv { denv_overlap_mode = overlap_mode
|
|
| 1436 | + , denv_tvs = tvs
|
|
| 1437 | + , denv_cls = cls
|
|
| 1438 | + , denv_inst_tys = inst_tys
|
|
| 1439 | + , denv_ctxt = deriv_ctxt
|
|
| 1440 | + , denv_skol_info = skol_info
|
|
| 1441 | + , denv_warn = warn }) <- ask
|
|
| 1442 | 1442 | user_ctxt <- askDerivUserTypeCtxt
|
| 1443 | 1443 | doDerivInstErrorChecks1 mechanism
|
| 1444 | 1444 | loc <- lift getSrcSpanM
|
| ... | ... | @@ -1446,7 +1446,7 @@ mk_eqn_from_mechanism mechanism |
| 1446 | 1446 | case deriv_ctxt of
|
| 1447 | 1447 | InferContext wildcard ->
|
| 1448 | 1448 | do { (inferred_constraints, tvs', inst_tys', mechanism')
|
| 1449 | - <- inferConstraints mechanism
|
|
| 1449 | + <- inferConstraints mechanism env
|
|
| 1450 | 1450 | ; return $ InferTheta $ DS
|
| 1451 | 1451 | { ds_loc = loc
|
| 1452 | 1452 | , ds_name = dfun_name, ds_tvs = tvs'
|
| ... | ... | @@ -66,7 +66,7 @@ import Data.Maybe |
| 66 | 66 | |
| 67 | 67 | ----------------------
|
| 68 | 68 | |
| 69 | -inferConstraints :: DerivSpecMechanism
|
|
| 69 | +inferConstraints :: DerivSpecMechanism -> DerivEnv
|
|
| 70 | 70 | -> DerivM (ThetaSpec, [TyVar], [TcType], DerivSpecMechanism)
|
| 71 | 71 | -- inferConstraints figures out the constraints needed for the
|
| 72 | 72 | -- instance declaration generated by a 'deriving' clause on a
|
| ... | ... | @@ -83,12 +83,12 @@ inferConstraints :: DerivSpecMechanism |
| 83 | 83 | -- Generate a sufficiently large set of constraints that typechecking the
|
| 84 | 84 | -- generated method definitions should succeed. This set will be simplified
|
| 85 | 85 | -- before being used in the instance declaration
|
| 86 | -inferConstraints mechanism
|
|
| 87 | - = do { DerivEnv { denv_tvs = tvs
|
|
| 88 | - , denv_cls = main_cls
|
|
| 89 | - , denv_inst_tys = inst_tys } <- ask
|
|
| 90 | - ; wildcard <- isStandaloneWildcardDeriv
|
|
| 91 | - ; let infer_constraints :: DerivM (ThetaSpec, [TyVar], [TcType], DerivSpecMechanism)
|
|
| 86 | +inferConstraints mechanism (DerivEnv { denv_ctxt = ctxt
|
|
| 87 | + , denv_tvs = tvs
|
|
| 88 | + , denv_cls = main_cls
|
|
| 89 | + , denv_inst_tys = inst_tys })
|
|
| 90 | + = do { let wildcard = isStandaloneWildcardDeriv ctxt
|
|
| 91 | + infer_constraints :: DerivM (ThetaSpec, [TyVar], [TcType], DerivSpecMechanism)
|
|
| 92 | 92 | infer_constraints =
|
| 93 | 93 | case mechanism of
|
| 94 | 94 | DerivSpecStock{dsm_stock_dit = dit}
|
| ... | ... | @@ -169,12 +169,12 @@ inferConstraintsStock dit@(DerivInstTys { dit_cls_tys = cls_tys |
| 169 | 169 | , dit_tc_args = tc_args
|
| 170 | 170 | , dit_rep_tc = rep_tc
|
| 171 | 171 | , dit_rep_tc_args = rep_tc_args })
|
| 172 | - = do DerivEnv { denv_tvs = tvs
|
|
| 172 | + = do DerivEnv { denv_ctxt = ctxt
|
|
| 173 | + , denv_tvs = tvs
|
|
| 173 | 174 | , denv_cls = main_cls
|
| 174 | 175 | , denv_inst_tys = inst_tys } <- ask
|
| 175 | - wildcard <- isStandaloneWildcardDeriv
|
|
| 176 | - |
|
| 177 | - let inst_ty = mkTyConApp tc tc_args
|
|
| 176 | + let wildcard = isStandaloneWildcardDeriv ctxt
|
|
| 177 | + inst_ty = mkTyConApp tc tc_args
|
|
| 178 | 178 | tc_binders = tyConBinders rep_tc
|
| 179 | 179 | choose_level bndr
|
| 180 | 180 | | isNamedTyConBinder bndr = KindLevel
|
| ... | ... | @@ -370,13 +370,14 @@ inferConstraintsStock dit@(DerivInstTys { dit_cls_tys = cls_tys |
| 370 | 370 | -- derived instance context.
|
| 371 | 371 | inferConstraintsAnyclass :: DerivM ThetaSpec
|
| 372 | 372 | inferConstraintsAnyclass
|
| 373 | - = do { DerivEnv { denv_cls = cls
|
|
| 373 | + = do { DerivEnv { denv_ctxt = ctxt
|
|
| 374 | + , denv_cls = cls
|
|
| 374 | 375 | , denv_inst_tys = inst_tys } <- ask
|
| 375 | 376 | ; let gen_dms = [ (sel_id, dm_ty)
|
| 376 | 377 | | (sel_id, Just (_, GenericDM dm_ty)) <- classOpItems cls ]
|
| 377 | - ; wildcard <- isStandaloneWildcardDeriv
|
|
| 378 | 378 | |
| 379 | - ; let meth_pred :: (Id, Type) -> PredSpec
|
|
| 379 | + ; let wildcard = isStandaloneWildcardDeriv ctxt
|
|
| 380 | + meth_pred :: (Id, Type) -> PredSpec
|
|
| 380 | 381 | -- (Id,Type) are the selector Id and the generic default method type
|
| 381 | 382 | -- NB: the latter is /not/ quantified over the class variables
|
| 382 | 383 | -- See Note [Gathering and simplifying constraints for DeriveAnyClass]
|
| ... | ... | @@ -408,10 +409,10 @@ inferConstraintsAnyclass |
| 408 | 409 | inferConstraintsCoerceBased :: [Type] -> Type
|
| 409 | 410 | -> DerivM ThetaSpec
|
| 410 | 411 | inferConstraintsCoerceBased cls_tys rep_ty = do
|
| 411 | - DerivEnv { denv_tvs = tvs
|
|
| 412 | + DerivEnv { denv_ctxt = ctxt
|
|
| 413 | + , denv_tvs = tvs
|
|
| 412 | 414 | , denv_cls = cls
|
| 413 | 415 | , denv_inst_tys = inst_tys } <- ask
|
| 414 | - sa_wildcard <- isStandaloneWildcardDeriv
|
|
| 415 | 416 | let -- rep_ty might come from:
|
| 416 | 417 | -- GeneralizedNewtypeDeriving / DerivSpecNewtype:
|
| 417 | 418 | -- the underlying type of the newtype ()
|
| ... | ... | @@ -426,6 +427,7 @@ inferConstraintsCoerceBased cls_tys rep_ty = do |
| 426 | 427 | -- we are going to get all the methods for the final
|
| 427 | 428 | -- dictionary
|
| 428 | 429 | deriv_origin = mkDerivOrigin sa_wildcard
|
| 430 | + sa_wildcard = isStandaloneWildcardDeriv ctxt
|
|
| 429 | 431 | |
| 430 | 432 | -- Next we collect constraints for the class methods
|
| 431 | 433 | -- If there are no methods, we don't need any constraints
|
| ... | ... | @@ -574,7 +576,7 @@ Consider the `deriving Alt` part of this example (from the passing part of |
| 574 | 576 | T20815a):
|
| 575 | 577 | |
| 576 | 578 | class Alt f where
|
| 577 | - some :: Applicative f => f a -> f [a]
|
|
| 579 | + some :: forall a. Applicative f => f a -> f [a]
|
|
| 578 | 580 | |
| 579 | 581 | newtype T f a = T (f a) deriving Alt
|
| 580 | 582 |
| ... | ... | @@ -35,11 +35,11 @@ import GHC.Tc.Deriv.Generate |
| 35 | 35 | import GHC.Tc.Deriv.Functor
|
| 36 | 36 | import GHC.Tc.Deriv.Generics
|
| 37 | 37 | import GHC.Tc.Errors.Types
|
| 38 | -import GHC.Tc.Types.Constraint (WantedConstraints, mkNonCanonical)
|
|
| 38 | +import GHC.Tc.Types.Constraint (WantedConstraints, mkNonCanonical, mkSimpleWC)
|
|
| 39 | 39 | import GHC.Tc.Types.Origin
|
| 40 | 40 | import GHC.Tc.Utils.Monad
|
| 41 | 41 | import GHC.Tc.Utils.TcType
|
| 42 | -import GHC.Tc.Utils.Unify (tcSubTypeSigma)
|
|
| 42 | +import GHC.Tc.Utils.Unify (tcSubTypeSigma, buildImplicationFor)
|
|
| 43 | 43 | import GHC.Tc.Zonk.Type
|
| 44 | 44 | |
| 45 | 45 | import GHC.Core.Class
|
| ... | ... | @@ -71,7 +71,6 @@ import GHC.Utils.Error |
| 71 | 71 | import GHC.Utils.Unique (sameUnique)
|
| 72 | 72 | |
| 73 | 73 | import Control.Monad.Trans.Reader
|
| 74 | -import Data.Foldable (traverse_)
|
|
| 75 | 74 | import Data.Maybe
|
| 76 | 75 | import qualified GHC.LanguageExtensions as LangExt
|
| 77 | 76 | import GHC.Data.List.SetOps (assocMaybe)
|
| ... | ... | @@ -92,12 +91,9 @@ isStandaloneDeriv = asks (go . denv_ctxt) |
| 92 | 91 | -- | Is GHC processing a standalone deriving declaration with an
|
| 93 | 92 | -- extra-constraints wildcard as the context?
|
| 94 | 93 | -- (e.g., @deriving instance _ => Eq (Foo a)@)
|
| 95 | -isStandaloneWildcardDeriv :: DerivM Bool
|
|
| 96 | -isStandaloneWildcardDeriv = asks (go . denv_ctxt)
|
|
| 97 | - where
|
|
| 98 | - go :: DerivContext -> Bool
|
|
| 99 | - go (InferContext wildcard) = isJust wildcard
|
|
| 100 | - go (SupplyContext {}) = False
|
|
| 94 | +isStandaloneWildcardDeriv :: DerivContext -> Bool
|
|
| 95 | +isStandaloneWildcardDeriv (InferContext wildcard) = isJust wildcard
|
|
| 96 | +isStandaloneWildcardDeriv (SupplyContext {}) = False
|
|
| 101 | 97 | |
| 102 | 98 | -- | Return 'InstDeclCtxt' if processing with a standalone @deriving@
|
| 103 | 99 | -- declaration or 'DerivClauseCtxt' if processing a @deriving@ clause.
|
| ... | ... | @@ -563,11 +559,17 @@ data PredSpec |
| 563 | 559 | SimplePredSpec
|
| 564 | 560 | { sps_pred :: TcPredType
|
| 565 | 561 | -- ^ The constraint to emit as a wanted
|
| 562 | + -- Usually just a simple predicate like (Eq a) or (ki ~# Type),
|
|
| 563 | + -- but (hack) in the case of GHC.Tc.Deriv.Infer.inferConstraintsCoerceBased,
|
|
| 564 | + -- it can be a forall-constraint
|
|
| 565 | + |
|
| 566 | 566 | , sps_origin :: CtOrigin
|
| 567 | 567 | -- ^ The origin of the constraint
|
| 568 | + |
|
| 568 | 569 | , sps_type_or_kind :: TypeOrKind
|
| 569 | 570 | -- ^ Whether the constraint is a type or kind
|
| 570 | 571 | }
|
| 572 | + |
|
| 571 | 573 | | -- | A special 'PredSpec' that is only used by @DeriveAnyClass@. This
|
| 572 | 574 | -- will check if @stps_ty_actual@ is a subtype of (i.e., more polymorphic
|
| 573 | 575 | -- than) @stps_ty_expected@ in the constraint solving machinery, emitting an
|
| ... | ... | @@ -677,8 +679,8 @@ captureThetaSpecConstraints :: |
| 677 | 679 | -- @deriving@ declaration
|
| 678 | 680 | -> ThetaSpec -- ^ The specs from which constraints will be created
|
| 679 | 681 | -> TcM (TcLevel, WantedConstraints)
|
| 680 | -captureThetaSpecConstraints user_ctxt theta =
|
|
| 681 | - pushTcLevelM $ mk_wanteds theta
|
|
| 682 | +captureThetaSpecConstraints user_ctxt theta
|
|
| 683 | + = pushTcLevelM $ mk_wanteds theta
|
|
| 682 | 684 | where
|
| 683 | 685 | -- Create the constraints we need to solve. For stock and newtype
|
| 684 | 686 | -- deriving, these constraints will be simple wanted constraints
|
| ... | ... | @@ -689,34 +691,49 @@ captureThetaSpecConstraints user_ctxt theta = |
| 689 | 691 | mk_wanteds :: ThetaSpec -> TcM WantedConstraints
|
| 690 | 692 | mk_wanteds preds
|
| 691 | 693 | = do { (_, wanteds) <- captureConstraints $
|
| 692 | - traverse_ emit_constraints preds
|
|
| 694 | + mapM_ (emitPredSpecConstraints user_ctxt) preds
|
|
| 693 | 695 | ; pure wanteds }
|
| 694 | 696 | |
| 695 | - -- Emit the appropriate constraints depending on what sort of
|
|
| 696 | - -- PredSpec we are dealing with.
|
|
| 697 | - emit_constraints :: PredSpec -> TcM ()
|
|
| 698 | - emit_constraints ps =
|
|
| 699 | - case ps of
|
|
| 700 | - -- For constraints like (C a, Ord b), emit the
|
|
| 701 | - -- constraints directly as simple wanted constraints.
|
|
| 702 | - SimplePredSpec { sps_pred = wanted
|
|
| 703 | - , sps_origin = orig
|
|
| 704 | - , sps_type_or_kind = t_or_k
|
|
| 705 | - } -> do
|
|
| 706 | - ev <- newWanted orig (Just t_or_k) wanted
|
|
| 707 | - emitSimple (mkNonCanonical ev)
|
|
| 708 | - |
|
| 709 | - -- For DeriveAnyClass, check if ty_actual is a subtype of
|
|
| 710 | - -- ty_expected, which emits an implication constraint as a
|
|
| 711 | - -- side effect. See
|
|
| 712 | - -- Note [Gathering and simplifying constraints for DeriveAnyClass].
|
|
| 713 | - -- in GHC.Tc.Deriv.Infer.
|
|
| 714 | - SubTypePredSpec { stps_ty_actual = ty_actual
|
|
| 715 | - , stps_ty_expected = ty_expected
|
|
| 716 | - , stps_origin = orig
|
|
| 717 | - } -> do
|
|
| 718 | - _ <- tcSubTypeSigma orig user_ctxt ty_actual ty_expected
|
|
| 719 | - return ()
|
|
| 697 | +emitPredSpecConstraints :: UserTypeCtxt -> PredSpec -> TcM ()
|
|
| 698 | +--- Emit the appropriate constraints depending on what sort of
|
|
| 699 | +-- PredSpec we are dealing with.
|
|
| 700 | +emitPredSpecConstraints _ (SimplePredSpec { sps_pred = wanted_pred
|
|
| 701 | + , sps_origin = orig
|
|
| 702 | + , sps_type_or_kind = t_or_k })
|
|
| 703 | + -- For constraints like (C a) or (Ord b), emit the
|
|
| 704 | + -- constraints directly as simple wanted constraints.
|
|
| 705 | + | isRhoTy wanted_pred
|
|
| 706 | + = do { ev <- newWanted orig (Just t_or_k) wanted_pred
|
|
| 707 | + ; emitSimple (mkNonCanonical ev) }
|
|
| 708 | + |
|
| 709 | + | otherwise
|
|
| 710 | + -- Forall-constraints, which come exclusively from
|
|
| 711 | + -- GHC.Tc.Deriv.Infer.inferConstraintsCoerceBased.
|
|
| 712 | + -- For these we want to emit an implication constraint, and NOT a
|
|
| 713 | + -- forall-constraint. Why? Because forall-constraints are solved all-or-nothing,
|
|
| 714 | + -- but here when we are trying to infer the context for an instance decl, we
|
|
| 715 | + -- need that half-solved implication. See deriving/should_compile/T20815
|
|
| 716 | + -- and Note [Inferred contexts from method constraints]
|
|
| 717 | + = do { let skol_info_anon = DerivSkol wanted_pred
|
|
| 718 | + ; skol_info <- mkSkolemInfo skol_info_anon
|
|
| 719 | + ; (_wrapper, tv_prs, givens, wanted_rho) <- topSkolemise skol_info wanted_pred
|
|
| 720 | + -- _wrapper: we ignore the evidence from all these constraints
|
|
| 721 | + ; (tc_lvl, ev) <- pushTcLevelM $ newWanted orig (Just t_or_k) wanted_rho
|
|
| 722 | + ; let skol_tvs = map (binderVar . snd) tv_prs
|
|
| 723 | + ; (implic, _) <- buildImplicationFor tc_lvl skol_info_anon skol_tvs
|
|
| 724 | + givens (mkSimpleWC [ev])
|
|
| 725 | + ; emitImplications implic }
|
|
| 726 | + |
|
| 727 | +emitPredSpecConstraints user_ctxt
|
|
| 728 | + (SubTypePredSpec { stps_ty_actual = ty_actual
|
|
| 729 | + , stps_ty_expected = ty_expected
|
|
| 730 | + , stps_origin = orig })
|
|
| 731 | +-- For DeriveAnyClass, check if ty_actual is a subtype of ty_expected,
|
|
| 732 | +-- which emits an implication constraint as a side effect. See
|
|
| 733 | +-- Note [Gathering and simplifying constraints for DeriveAnyClass]
|
|
| 734 | +-- in GHC.Tc.Deriv.Infer.
|
|
| 735 | + = do { _ <- tcSubTypeSigma orig user_ctxt ty_actual ty_expected
|
|
| 736 | + ; return () }
|
|
| 720 | 737 | |
| 721 | 738 | {-
|
| 722 | 739 | ************************************************************************
|
| ... | ... | @@ -623,7 +623,8 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics |
| 623 | 623 | -- report2: we suppress these if there are insolubles elsewhere in the tree
|
| 624 | 624 | report2 = [ ("Implicit params", is_ip, False, mkGroupReporter mkIPErr)
|
| 625 | 625 | , ("Irreds", is_irred, False, mkGroupReporter mkIrredErr)
|
| 626 | - , ("Dicts", is_dict, False, mkGroupReporter mkDictErr) ]
|
|
| 626 | + , ("Dicts", is_dict, False, mkGroupReporter mkDictErr)
|
|
| 627 | + , ("Quantified", is_qc, False, mkGroupReporter mkQCErr) ]
|
|
| 627 | 628 | |
| 628 | 629 | -- report3: suppressed errors should be reported as categorized by either report1
|
| 629 | 630 | -- or report2. Keep this in sync with the suppress function above
|
| ... | ... | @@ -687,6 +688,9 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics |
| 687 | 688 | is_irred _ (IrredPred {}) = True
|
| 688 | 689 | is_irred _ _ = False
|
| 689 | 690 | |
| 691 | + is_qc _ (ForAllPred {}) = True
|
|
| 692 | + is_qc _ _ = False
|
|
| 693 | + |
|
| 690 | 694 | -- See situation (1) of Note [Suppressing confusing errors]
|
| 691 | 695 | is_ww_fundep item _ = is_ww_fundep_item item
|
| 692 | 696 | is_ww_fundep_item = isWantedWantedFunDepOrigin . errorItemOrigin
|
| ... | ... | @@ -2214,6 +2218,15 @@ Warn of loopy local equalities that were dropped. |
| 2214 | 2218 | ************************************************************************
|
| 2215 | 2219 | -}
|
| 2216 | 2220 | |
| 2221 | +mkQCErr :: HasDebugCallStack => SolverReportErrCtxt -> NonEmpty ErrorItem -> TcM SolverReport
|
|
| 2222 | +mkQCErr ctxt items
|
|
| 2223 | + | item1 :| _ <- tryFilter (not . ei_suppress) items
|
|
| 2224 | + -- Ignore multiple qc-errors on the same line
|
|
| 2225 | + = do { let msg = mkPlainMismatchMsg $
|
|
| 2226 | + CouldNotDeduce (getUserGivens ctxt) (item1 :| []) Nothing
|
|
| 2227 | + ; return $ important ctxt msg }
|
|
| 2228 | + |
|
| 2229 | + |
|
| 2217 | 2230 | mkDictErr :: HasDebugCallStack => SolverReportErrCtxt -> NonEmpty ErrorItem -> TcM SolverReport
|
| 2218 | 2231 | mkDictErr ctxt orig_items
|
| 2219 | 2232 | = do { inst_envs <- tcGetInstEnvs
|
| ... | ... | @@ -2231,8 +2244,8 @@ mkDictErr ctxt orig_items |
| 2231 | 2244 | ; return $
|
| 2232 | 2245 | SolverReport
|
| 2233 | 2246 | { sr_important_msg = SolverReportWithCtxt ctxt err
|
| 2234 | - , sr_supplementary =
|
|
| 2235 | - [ SupplementaryImportErrors imps | imps <- maybeToList (NE.nonEmpty imp_errs) ]
|
|
| 2247 | + , sr_supplementary = [ SupplementaryImportErrors imps
|
|
| 2248 | + | imps <- maybeToList (NE.nonEmpty imp_errs) ]
|
|
| 2236 | 2249 | , sr_hints = hints
|
| 2237 | 2250 | }
|
| 2238 | 2251 | }
|
| ... | ... | @@ -460,6 +460,7 @@ finishApp tc_head@(tc_fun,_) tc_args app_res_rho res_wrap |
| 460 | 460 | ; res_expr <- if isTagToEnum tc_fun
|
| 461 | 461 | then tcTagToEnum tc_head tc_args app_res_rho
|
| 462 | 462 | else return (rebuildHsApps tc_head tc_args)
|
| 463 | + ; traceTc "End tcApp }" (ppr tc_fun)
|
|
| 463 | 464 | ; return (mkHsWrap res_wrap res_expr) }
|
| 464 | 465 | |
| 465 | 466 | checkResultTy :: HsExpr GhcRn
|
| ... | ... | @@ -1481,6 +1481,7 @@ expandRecordUpd record_expr possible_parents rbnds res_ty |
| 1481 | 1481 | vcat [ text "relevant_con:" <+> ppr relevant_con
|
| 1482 | 1482 | , text "res_ty:" <+> ppr res_ty
|
| 1483 | 1483 | , text "ds_res_ty:" <+> ppr ds_res_ty
|
| 1484 | + , text "ds_expr:" <+> ppr ds_expr
|
|
| 1484 | 1485 | ]
|
| 1485 | 1486 | |
| 1486 | 1487 | ; return (ds_expr, ds_res_ty, RecordUpdCtxt relevant_cons upd_fld_names ex_tvs) }
|
| ... | ... | @@ -1036,8 +1036,7 @@ findInferredDiff annotated_theta inferred_theta |
| 1036 | 1036 | -- See `Note [Quantification and partial signatures]` Wrinkle 2
|
| 1037 | 1037 | |
| 1038 | 1038 | ; return (map (box_pred . ctPred) $
|
| 1039 | - bagToList $
|
|
| 1040 | - wc_simple residual) }
|
|
| 1039 | + bagToList residual) }
|
|
| 1041 | 1040 | where
|
| 1042 | 1041 | box_pred :: PredType -> PredType
|
| 1043 | 1042 | box_pred pred = case classifyPredType pred of
|
| ... | ... | @@ -1188,8 +1188,8 @@ tryDefaultGroup wanteds (Proposal assignments) |
| 1188 | 1188 | ; new_wanteds <- sequence [ new_wtd_ct wtd
|
| 1189 | 1189 | | CtWanted wtd <- map ctEvidence wanteds
|
| 1190 | 1190 | ]
|
| 1191 | - ; residual_wc <- solveSimpleWanteds (listToBag new_wanteds)
|
|
| 1192 | - ; return $ if isEmptyWC residual_wc then Just (tvs, subst) else Nothing }
|
|
| 1191 | + ; residual <- solveSimpleWanteds (listToBag new_wanteds)
|
|
| 1192 | + ; return $ if isEmptyBag residual then Just (tvs, subst) else Nothing }
|
|
| 1193 | 1193 | |
| 1194 | 1194 | | otherwise
|
| 1195 | 1195 | = return Nothing
|
| ... | ... | @@ -10,6 +10,8 @@ module GHC.Tc.Solver.Equality( |
| 10 | 10 | |
| 11 | 11 | import GHC.Prelude
|
| 12 | 12 | |
| 13 | +import {-# SOURCE #-} GHC.Tc.Solver.Solve( trySolveImplication )
|
|
| 14 | + |
|
| 13 | 15 | import GHC.Tc.Solver.Irred( solveIrred )
|
| 14 | 16 | import GHC.Tc.Solver.Dict( matchLocalInst, chooseInstance )
|
| 15 | 17 | import GHC.Tc.Solver.Rewrite
|
| ... | ... | @@ -468,7 +470,7 @@ can_eq_nc_forall :: CtEvidence -> EqRel |
| 468 | 470 | -- See Note [Solving forall equalities]
|
| 469 | 471 | |
| 470 | 472 | can_eq_nc_forall ev eq_rel s1 s2
|
| 471 | - | CtWanted (WantedCt { ctev_dest = orig_dest }) <- ev
|
|
| 473 | + | CtWanted (WantedCt { ctev_dest = orig_dest, ctev_loc = loc }) <- ev
|
|
| 472 | 474 | = do { let (bndrs1, phi1, bndrs2, phi2) = split_foralls s1 s2
|
| 473 | 475 | flags1 = binderFlags bndrs1
|
| 474 | 476 | flags2 = binderFlags bndrs2
|
| ... | ... | @@ -479,11 +481,11 @@ can_eq_nc_forall ev eq_rel s1 s2 |
| 479 | 481 | , ppr flags1, ppr flags2 ]
|
| 480 | 482 | ; canEqHardFailure ev s1 s2 }
|
| 481 | 483 | |
| 482 | - else do {
|
|
| 483 | - traceTcS "Creating implication for polytype equality" (ppr ev)
|
|
| 484 | - ; let free_tvs = tyCoVarsOfTypes [s1,s2]
|
|
| 485 | - empty_subst1 = mkEmptySubst $ mkInScopeSet free_tvs
|
|
| 486 | - ; skol_info <- mkSkolemInfo (UnifyForAllSkol phi1)
|
|
| 484 | + else
|
|
| 485 | + do { let free_tvs = tyCoVarsOfTypes [s1,s2]
|
|
| 486 | + empty_subst1 = mkEmptySubst $ mkInScopeSet free_tvs
|
|
| 487 | + skol_info_anon = UnifyForAllSkol phi1
|
|
| 488 | + ; skol_info <- mkSkolemInfo skol_info_anon
|
|
| 487 | 489 | ; (subst1, skol_tvs) <- tcInstSkolTyVarsX skol_info empty_subst1 $
|
| 488 | 490 | binderVars bndrs1
|
| 489 | 491 | |
| ... | ... | @@ -522,16 +524,34 @@ can_eq_nc_forall ev eq_rel s1 s2 |
| 522 | 524 | |
| 523 | 525 | init_subst2 = mkEmptySubst (substInScopeSet subst1)
|
| 524 | 526 | |
| 527 | + ; traceTcS "Generating wanteds" (ppr s1 $$ ppr s2)
|
|
| 528 | + |
|
| 525 | 529 | -- Generate the constraints that live in the body of the implication
|
| 526 | 530 | -- See (SF5) in Note [Solving forall equalities]
|
| 527 | 531 | ; (lvl, (all_co, wanteds)) <- pushLevelNoWorkList (ppr skol_info) $
|
| 528 | 532 | unifyForAllBody ev (eqRelRole eq_rel) $ \uenv ->
|
| 529 | 533 | go uenv skol_tvs init_subst2 bndrs1 bndrs2
|
| 530 | 534 | |
| 531 | - ; emitTvImplicationTcS lvl (getSkolemInfo skol_info) skol_tvs wanteds
|
|
| 532 | - |
|
| 533 | - ; setWantedEq orig_dest all_co
|
|
| 534 | - ; stopWith ev "Deferred polytype equality" } }
|
|
| 535 | + -- Solve the implication right away, using `trySolveImplication`
|
|
| 536 | + -- See (SF6) in Note [Solving forall equalities]
|
|
| 537 | + ; traceTcS "Trying to solve the implication" (ppr s1 $$ ppr s2 $$ ppr wanteds)
|
|
| 538 | + ; ev_binds_var <- newNoTcEvBinds
|
|
| 539 | + ; solved <- trySolveImplication $
|
|
| 540 | + (implicationPrototype (ctLocEnv loc))
|
|
| 541 | + { ic_tclvl = lvl
|
|
| 542 | + , ic_binds = ev_binds_var
|
|
| 543 | + , ic_info = skol_info_anon
|
|
| 544 | + , ic_warn_inaccessible = False
|
|
| 545 | + , ic_skols = skol_tvs
|
|
| 546 | + , ic_given = []
|
|
| 547 | + , ic_wanted = emptyWC { wc_simple = wanteds } }
|
|
| 548 | + |
|
| 549 | + ; if solved
|
|
| 550 | + then do { zonked_all_co <- zonkCo all_co
|
|
| 551 | + -- ToDo: explain this zonk
|
|
| 552 | + ; setWantedEq orig_dest zonked_all_co
|
|
| 553 | + ; stopWith ev "Polytype equality: solved" }
|
|
| 554 | + else canEqSoftFailure IrredShapeReason ev s1 s2 } }
|
|
| 535 | 555 | |
| 536 | 556 | | otherwise
|
| 537 | 557 | = do { traceTcS "Omitting decomposition of given polytype equality" $
|
| ... | ... | @@ -556,7 +576,8 @@ can_eq_nc_forall ev eq_rel s1 s2 |
| 556 | 576 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 557 | 577 | To solve an equality between foralls
|
| 558 | 578 | [W] (forall a. t1) ~ (forall b. t2)
|
| 559 | -the basic plan is simple: just create the implication constraint
|
|
| 579 | +the basic plan is simple: use `trySolveImplication` to solve the
|
|
| 580 | +implication constraint
|
|
| 560 | 581 | [W] forall a. { t1 ~ (t2[a/b]) }
|
| 561 | 582 | |
| 562 | 583 | The evidence we produce is a ForAllCo; see the typing rule for
|
| ... | ... | @@ -601,6 +622,21 @@ There are lots of wrinkles of course: |
| 601 | 622 | especially Refl ones. We use the `unifyForAllBody` wrapper for `uType`,
|
| 602 | 623 | because we want to /gather/ the equality constraint (to put in the implication)
|
| 603 | 624 | rather than /emit/ them into the monad, as `wrapUnifierTcS` does.
|
| 625 | + |
|
| 626 | +(SF6) We solve the implication on the spot, using `trySolveImplication`. In
|
|
| 627 | + the past we instead generated an `Implication` to be solved later. Nice in
|
|
| 628 | + some ways but it added complexity:
|
|
| 629 | + - We needed a `wl_implics` field of `WorkList` to collect
|
|
| 630 | + these emitted implications
|
|
| 631 | + - The types of `solveSimpleWanteds` and friends were more complicated
|
|
| 632 | + - Trickily, an `EvFun` had to contain an `EvBindsVar` ref-cell, which made
|
|
| 633 | + `evVarsOfTerm` harder. Now an `EvFun` just contains the bindings.
|
|
| 634 | + The disadvantage of solve-on-the-spot is that if we fail we are simply
|
|
| 635 | + left with an unsolved (forall a. blah) ~ (forall b. blah), and it may
|
|
| 636 | + not be clear /why/ we couldn't solve it. But on balance the error messages
|
|
| 637 | + improve: it is easier to undertand that
|
|
| 638 | + (forall a. a->a) ~ (forall b. b->Int)
|
|
| 639 | + is insoluble than it is to understand a message about matching `a` with `Int`.
|
|
| 604 | 640 | -}
|
| 605 | 641 | |
| 606 | 642 | {- Note [Unwrap newtypes first]
|
| ... | ... | @@ -834,18 +870,26 @@ canTyConApp ev eq_rel both_generative (ty1,tc1,tys1) (ty2,tc2,tys2) |
| 834 | 870 | = do { inerts <- getInertSet
|
| 835 | 871 | ; if can_decompose inerts
|
| 836 | 872 | then canDecomposableTyConAppOK ev eq_rel tc1 (ty1,tys1) (ty2,tys2)
|
| 837 | - else canEqSoftFailure ev eq_rel ty1 ty2 }
|
|
| 873 | + else assert (eq_rel == ReprEq) $
|
|
| 874 | + canEqSoftFailure ReprEqReason ev ty1 ty2 }
|
|
| 838 | 875 | |
| 839 | 876 | -- See Note [Skolem abstract data] in GHC.Core.Tycon
|
| 840 | 877 | | tyConSkolem tc1 || tyConSkolem tc2
|
| 841 | 878 | = do { traceTcS "canTyConApp: skolem abstract" (ppr tc1 $$ ppr tc2)
|
| 842 | 879 | ; finishCanWithIrred AbstractTyConReason ev }
|
| 843 | 880 | |
| 844 | - | otherwise -- Different TyCons
|
|
| 845 | - = if both_generative -- See (TC2) and (TC3) in
|
|
| 846 | - -- Note [Canonicalising TyCon/TyCon equalities]
|
|
| 847 | - then canEqHardFailure ev ty1 ty2
|
|
| 848 | - else canEqSoftFailure ev eq_rel ty1 ty2
|
|
| 881 | + -- Different TyCons
|
|
| 882 | + | NomEq <- eq_rel
|
|
| 883 | + = canEqHardFailure ev ty1 ty2
|
|
| 884 | + |
|
| 885 | + -- Different TyCons, eq_rel = ReprEq
|
|
| 886 | + -- See (TC2) and (TC3) in
|
|
| 887 | + -- Note [Canonicalising TyCon/TyCon equalities]
|
|
| 888 | + | both_generative
|
|
| 889 | + = canEqHardFailure ev ty1 ty2
|
|
| 890 | + |
|
| 891 | + | otherwise
|
|
| 892 | + = canEqSoftFailure ReprEqReason ev ty1 ty2
|
|
| 849 | 893 | where
|
| 850 | 894 | -- See Note [Decomposing TyConApp equalities]
|
| 851 | 895 | -- and Note [Decomposing newtype equalities]
|
| ... | ... | @@ -1417,20 +1461,18 @@ canDecomposableFunTy ev eq_rel af f1@(ty1,m1,a1,r1) f2@(ty2,m2,a2,r2) |
| 1417 | 1461 | |
| 1418 | 1462 | -- | Call canEqSoftFailure when canonicalizing an equality fails, but if the
|
| 1419 | 1463 | -- equality is representational, there is some hope for the future.
|
| 1420 | -canEqSoftFailure :: CtEvidence -> EqRel -> TcType -> TcType
|
|
| 1464 | +canEqSoftFailure :: CtIrredReason -> CtEvidence -> TcType -> TcType
|
|
| 1421 | 1465 | -> TcS (StopOrContinue (Either IrredCt a))
|
| 1422 | -canEqSoftFailure ev NomEq ty1 ty2
|
|
| 1423 | - = canEqHardFailure ev ty1 ty2
|
|
| 1424 | -canEqSoftFailure ev ReprEq ty1 ty2
|
|
| 1466 | +canEqSoftFailure reason ev ty1 ty2
|
|
| 1425 | 1467 | = do { (redn1, rewriters1) <- rewrite ev ty1
|
| 1426 | 1468 | ; (redn2, rewriters2) <- rewrite ev ty2
|
| 1427 | 1469 | -- We must rewrite the types before putting them in the
|
| 1428 | 1470 | -- inert set, so that we are sure to kick them out when
|
| 1429 | 1471 | -- new equalities become available
|
| 1430 | - ; traceTcS "canEqSoftFailure with ReprEq" $
|
|
| 1472 | + ; traceTcS "canEqSoftFailure" $
|
|
| 1431 | 1473 | vcat [ ppr ev, ppr redn1, ppr redn2 ]
|
| 1432 | 1474 | ; new_ev <- rewriteEqEvidence (rewriters1 S.<> rewriters2) ev NotSwapped redn1 redn2
|
| 1433 | - ; finishCanWithIrred ReprEqReason new_ev }
|
|
| 1475 | + ; finishCanWithIrred reason new_ev }
|
|
| 1434 | 1476 | |
| 1435 | 1477 | -- | Call when canonicalizing an equality fails with utterly no hope.
|
| 1436 | 1478 | canEqHardFailure :: CtEvidence -> TcType -> TcType
|
| ... | ... | @@ -2681,7 +2723,7 @@ tryInertEqs :: EqCt -> SolverStage () |
| 2681 | 2723 | tryInertEqs work_item@(EqCt { eq_ev = ev, eq_eq_rel = eq_rel })
|
| 2682 | 2724 | = Stage $
|
| 2683 | 2725 | do { inerts <- getInertCans
|
| 2684 | - ; if | Just (ev_i, swapped) <- inertsCanDischarge inerts work_item
|
|
| 2726 | + ; if | Just (ev_i, swapped) <- inertsEqsCanDischarge inerts work_item
|
|
| 2685 | 2727 | -> do { setEvBindIfWanted ev EvCanonical $
|
| 2686 | 2728 | evCoercion (maybeSymCo swapped $
|
| 2687 | 2729 | downgradeRole (eqRelRole eq_rel)
|
| ... | ... | @@ -2692,10 +2734,10 @@ tryInertEqs work_item@(EqCt { eq_ev = ev, eq_eq_rel = eq_rel }) |
| 2692 | 2734 | | otherwise
|
| 2693 | 2735 | -> continueWith () }
|
| 2694 | 2736 | |
| 2695 | -inertsCanDischarge :: InertCans -> EqCt
|
|
| 2696 | - -> Maybe ( CtEvidence -- The evidence for the inert
|
|
| 2697 | - , SwapFlag ) -- Whether we need mkSymCo
|
|
| 2698 | -inertsCanDischarge inerts (EqCt { eq_lhs = lhs_w, eq_rhs = rhs_w
|
|
| 2737 | +inertsEqsCanDischarge :: InertCans -> EqCt
|
|
| 2738 | + -> Maybe ( CtEvidence -- The evidence for the inert
|
|
| 2739 | + , SwapFlag ) -- Whether we need mkSymCo
|
|
| 2740 | +inertsEqsCanDischarge inerts (EqCt { eq_lhs = lhs_w, eq_rhs = rhs_w
|
|
| 2699 | 2741 | , eq_ev = ev_w, eq_eq_rel = eq_rel })
|
| 2700 | 2742 | | (ev_i : _) <- [ ev_i | EqCt { eq_ev = ev_i, eq_rhs = rhs_i
|
| 2701 | 2743 | , eq_eq_rel = eq_rel }
|
| ... | ... | @@ -2741,7 +2783,7 @@ inertsCanDischarge inerts (EqCt { eq_lhs = lhs_w, eq_rhs = rhs_w |
| 2741 | 2783 | -- Prefer the one that has no rewriters
|
| 2742 | 2784 | -- See (CE4) in Note [Combining equalities]
|
| 2743 | 2785 | |
| 2744 | -inertsCanDischarge _ _ = Nothing
|
|
| 2786 | +inertsEqsCanDischarge _ _ = Nothing
|
|
| 2745 | 2787 | |
| 2746 | 2788 | |
| 2747 | 2789 |
| ... | ... | @@ -154,17 +154,6 @@ So we arrange to put these particular class constraints in the wl_eqs. |
| 154 | 154 | NB: since we do not currently apply the substitution to the
|
| 155 | 155 | inert_solved_dicts, the knot-tying still seems a bit fragile.
|
| 156 | 156 | But this makes it better.
|
| 157 | - |
|
| 158 | -Note [Residual implications]
|
|
| 159 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 160 | -The wl_implics in the WorkList are the residual implication
|
|
| 161 | -constraints that are generated while solving or canonicalising the
|
|
| 162 | -current worklist. Specifically, when canonicalising
|
|
| 163 | - (forall a. t1 ~ forall a. t2)
|
|
| 164 | -from which we get the implication
|
|
| 165 | - (forall a. t1 ~ t2)
|
|
| 166 | -See GHC.Tc.Solver.Monad.deferTcSForAllEq
|
|
| 167 | - |
|
| 168 | 157 | -}
|
| 169 | 158 | |
| 170 | 159 | -- See Note [WorkList priorities]
|
| ... | ... | @@ -186,8 +175,6 @@ data WorkList |
| 186 | 175 | -- in GHC.Tc.Types.Constraint for more details.
|
| 187 | 176 | |
| 188 | 177 | , wl_rest :: [Ct]
|
| 189 | - |
|
| 190 | - , wl_implics :: Bag Implication -- See Note [Residual implications]
|
|
| 191 | 178 | }
|
| 192 | 179 | |
| 193 | 180 | isNominalEqualityCt :: Ct -> Bool
|
| ... | ... | @@ -202,15 +189,12 @@ isNominalEqualityCt ct |
| 202 | 189 | |
| 203 | 190 | appendWorkList :: WorkList -> WorkList -> WorkList
|
| 204 | 191 | appendWorkList
|
| 205 | - (WL { wl_eqs_N = eqs1_N, wl_eqs_X = eqs1_X, wl_rw_eqs = rw_eqs1
|
|
| 206 | - , wl_rest = rest1, wl_implics = implics1 })
|
|
| 207 | - (WL { wl_eqs_N = eqs2_N, wl_eqs_X = eqs2_X, wl_rw_eqs = rw_eqs2
|
|
| 208 | - , wl_rest = rest2, wl_implics = implics2 })
|
|
| 192 | + (WL { wl_eqs_N = eqs1_N, wl_eqs_X = eqs1_X, wl_rw_eqs = rw_eqs1, wl_rest = rest1 })
|
|
| 193 | + (WL { wl_eqs_N = eqs2_N, wl_eqs_X = eqs2_X, wl_rw_eqs = rw_eqs2, wl_rest = rest2 })
|
|
| 209 | 194 | = WL { wl_eqs_N = eqs1_N ++ eqs2_N
|
| 210 | 195 | , wl_eqs_X = eqs1_X ++ eqs2_X
|
| 211 | 196 | , wl_rw_eqs = rw_eqs1 ++ rw_eqs2
|
| 212 | - , wl_rest = rest1 ++ rest2
|
|
| 213 | - , wl_implics = implics1 `unionBags` implics2 }
|
|
| 197 | + , wl_rest = rest1 ++ rest2 }
|
|
| 214 | 198 | |
| 215 | 199 | workListSize :: WorkList -> Int
|
| 216 | 200 | workListSize (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs, wl_rest = rest })
|
| ... | ... | @@ -268,9 +252,6 @@ extendWorkListNonEq :: Ct -> WorkList -> WorkList |
| 268 | 252 | -- Extension by non equality
|
| 269 | 253 | extendWorkListNonEq ct wl = wl { wl_rest = ct : wl_rest wl }
|
| 270 | 254 | |
| 271 | -extendWorkListImplic :: Implication -> WorkList -> WorkList
|
|
| 272 | -extendWorkListImplic implic wl = wl { wl_implics = implic `consBag` wl_implics wl }
|
|
| 273 | - |
|
| 274 | 255 | extendWorkListCt :: Ct -> WorkList -> WorkList
|
| 275 | 256 | -- Agnostic about what kind of constraint
|
| 276 | 257 | extendWorkListCt ct wl
|
| ... | ... | @@ -294,18 +275,18 @@ extendWorkListCts :: Cts -> WorkList -> WorkList |
| 294 | 275 | extendWorkListCts cts wl = foldr extendWorkListCt wl cts
|
| 295 | 276 | |
| 296 | 277 | isEmptyWorkList :: WorkList -> Bool
|
| 297 | -isEmptyWorkList (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs
|
|
| 298 | - , wl_rest = rest, wl_implics = implics })
|
|
| 299 | - = null eqs_N && null eqs_X && null rw_eqs && null rest && isEmptyBag implics
|
|
| 278 | +isEmptyWorkList (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X
|
|
| 279 | + , wl_rw_eqs = rw_eqs, wl_rest = rest })
|
|
| 280 | + = null eqs_N && null eqs_X && null rw_eqs && null rest
|
|
| 300 | 281 | |
| 301 | 282 | emptyWorkList :: WorkList
|
| 302 | 283 | emptyWorkList = WL { wl_eqs_N = [], wl_eqs_X = []
|
| 303 | - , wl_rw_eqs = [], wl_rest = [], wl_implics = emptyBag }
|
|
| 284 | + , wl_rw_eqs = [], wl_rest = [] }
|
|
| 304 | 285 | |
| 305 | 286 | -- Pretty printing
|
| 306 | 287 | instance Outputable WorkList where
|
| 307 | - ppr (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs
|
|
| 308 | - , wl_rest = rest, wl_implics = implics })
|
|
| 288 | + ppr (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X
|
|
| 289 | + , wl_rw_eqs = rw_eqs, wl_rest = rest })
|
|
| 309 | 290 | = text "WL" <+> (braces $
|
| 310 | 291 | vcat [ ppUnless (null eqs_N) $
|
| 311 | 292 | text "Eqs_N =" <+> vcat (map ppr eqs_N)
|
| ... | ... | @@ -315,9 +296,6 @@ instance Outputable WorkList where |
| 315 | 296 | text "RwEqs =" <+> vcat (map ppr rw_eqs)
|
| 316 | 297 | , ppUnless (null rest) $
|
| 317 | 298 | text "Non-eqs =" <+> vcat (map ppr rest)
|
| 318 | - , ppUnless (isEmptyBag implics) $
|
|
| 319 | - ifPprDebug (text "Implics =" <+> vcat (map ppr (bagToList implics)))
|
|
| 320 | - (text "(Implics omitted)")
|
|
| 321 | 299 | ])
|
| 322 | 300 | |
| 323 | 301 | {- *********************************************************************
|
| ... | ... | @@ -120,19 +120,17 @@ simplify_loop n limit definitely_redo_implications |
| 120 | 120 | , int (lengthBag simples) <+> text "simples to solve" ])
|
| 121 | 121 | ; traceTcS "simplify_loop: wc =" (ppr wc)
|
| 122 | 122 | |
| 123 | - ; (unifs1, wc1) <- reportUnifications $ -- See Note [Superclass iteration]
|
|
| 124 | - solveSimpleWanteds simples
|
|
| 123 | + ; (unifs1, simples1) <- reportUnifications $ -- See Note [Superclass iteration]
|
|
| 124 | + solveSimpleWanteds simples
|
|
| 125 | 125 | -- Any insoluble constraints are in 'simples' and so get rewritten
|
| 126 | 126 | -- See Note [Rewrite insolubles] in GHC.Tc.Solver.InertSet
|
| 127 | 127 | |
| 128 | 128 | ; wc2 <- if not definitely_redo_implications -- See Note [Superclass iteration]
|
| 129 | 129 | && unifs1 == 0 -- for this conditional
|
| 130 | - && isEmptyBag (wc_impl wc1)
|
|
| 131 | - then return (wc { wc_simple = wc_simple wc1 }) -- Short cut
|
|
| 132 | - else do { implics2 <- solveNestedImplications $
|
|
| 133 | - implics `unionBags` (wc_impl wc1)
|
|
| 134 | - ; return (wc { wc_simple = wc_simple wc1
|
|
| 135 | - , wc_impl = implics2 }) }
|
|
| 130 | + then return (wc { wc_simple = simples1 }) -- Short cut
|
|
| 131 | + else do { implics1 <- solveNestedImplications implics
|
|
| 132 | + ; return (wc { wc_simple = simples1
|
|
| 133 | + , wc_impl = implics1 }) }
|
|
| 136 | 134 | |
| 137 | 135 | ; unif_happened <- resetUnificationFlag
|
| 138 | 136 | ; csTraceTcS $ text "unif_happened" <+> ppr unif_happened
|
| ... | ... | @@ -262,6 +260,11 @@ more meaningful error message (see T19627) |
| 262 | 260 | This also applies for quantified constraints; see `-fqcs-fuel` compiler flag and `QCI.qci_pend_sc` field.
|
| 263 | 261 | -}
|
| 264 | 262 | |
| 263 | +{- ********************************************************************************
|
|
| 264 | +* *
|
|
| 265 | +* Solving implication constraints *
|
|
| 266 | +* *
|
|
| 267 | +******************************************************************************** -}
|
|
| 265 | 268 | |
| 266 | 269 | solveNestedImplications :: Bag Implication
|
| 267 | 270 | -> TcS (Bag Implication)
|
| ... | ... | @@ -282,8 +285,37 @@ solveNestedImplications implics |
| 282 | 285 | |
| 283 | 286 | ; return unsolved_implics }
|
| 284 | 287 | |
| 288 | +{- Note [trySolveImplication]
|
|
| 289 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 290 | +`trySolveImplication` may be invoked while solving simple wanteds, notably from
|
|
| 291 | +`solveWantedForAll`. It returns a Bool to say if solving succeeded or failed.
|
|
| 292 | + |
|
| 293 | +It uses `nestImplicTcS` to build a nested scope. One subtle point is that
|
|
| 294 | +`nestImplicTcS` uses the `inert_givens` (not the `inert_cans`) of the current
|
|
| 295 | +inert set to initialse the `InertSet` of the nested scope. It is super-important not
|
|
| 296 | +to pollute the sub-solving problem with the unsolved Wanteds of the current scope.
|
|
| 297 | + |
|
| 298 | +Whenever we do `solveSimpleGivens`, we snapshot the `inert_cans` into `inert_givens`.
|
|
| 299 | +(At that moment there should be no Wanteds.)
|
|
| 300 | +-}
|
|
| 301 | + |
|
| 302 | +trySolveImplication :: Implication -> TcS Bool
|
|
| 303 | +-- See Note [trySolveImplication]
|
|
| 304 | +trySolveImplication (Implic { ic_tclvl = tclvl
|
|
| 305 | + , ic_binds = ev_binds_var
|
|
| 306 | + , ic_given = given_ids
|
|
| 307 | + , ic_wanted = wanteds
|
|
| 308 | + , ic_env = ct_loc_env
|
|
| 309 | + , ic_info = info })
|
|
| 310 | + = nestImplicTcS ev_binds_var tclvl $
|
|
| 311 | + do { let loc = mkGivenLoc tclvl info ct_loc_env
|
|
| 312 | + givens = mkGivens loc given_ids
|
|
| 313 | + ; solveSimpleGivens givens
|
|
| 314 | + ; residual_wanted <- solveWanteds wanteds
|
|
| 315 | + ; return (isSolvedWC residual_wanted) }
|
|
| 316 | + |
|
| 285 | 317 | solveImplication :: Implication -- Wanted
|
| 286 | - -> TcS Implication -- Simplified implication (empty or singleton)
|
|
| 318 | + -> TcS Implication -- Simplified implication
|
|
| 287 | 319 | -- Precondition: The TcS monad contains an empty worklist and given-only inerts
|
| 288 | 320 | -- which after trying to solve this implication we must restore to their original value
|
| 289 | 321 | solveImplication imp@(Implic { ic_tclvl = tclvl
|
| ... | ... | @@ -291,6 +323,7 @@ solveImplication imp@(Implic { ic_tclvl = tclvl |
| 291 | 323 | , ic_given = given_ids
|
| 292 | 324 | , ic_wanted = wanteds
|
| 293 | 325 | , ic_info = info
|
| 326 | + , ic_env = ct_loc_env
|
|
| 294 | 327 | , ic_status = status })
|
| 295 | 328 | | isSolvedStatus status
|
| 296 | 329 | = return imp -- Do nothing
|
| ... | ... | @@ -308,7 +341,7 @@ solveImplication imp@(Implic { ic_tclvl = tclvl |
| 308 | 341 | -- Solve the nested constraints
|
| 309 | 342 | ; (has_given_eqs, given_insols, residual_wanted)
|
| 310 | 343 | <- nestImplicTcS ev_binds_var tclvl $
|
| 311 | - do { let loc = mkGivenLoc tclvl info (ic_env imp)
|
|
| 344 | + do { let loc = mkGivenLoc tclvl info ct_loc_env
|
|
| 312 | 345 | givens = mkGivens loc given_ids
|
| 313 | 346 | ; solveSimpleGivens givens
|
| 314 | 347 | |
| ... | ... | @@ -534,7 +567,7 @@ neededEvVars implic@(Implic { ic_info = info |
| 534 | 567 | , ic_need_implic = old_need_implic -- See (TRC1)
|
| 535 | 568 | })
|
| 536 | 569 | = do { ev_binds <- TcS.getTcEvBindsMap ev_binds_var
|
| 537 | - ; tcvs <- TcS.getTcEvTyCoVars ev_binds_var
|
|
| 570 | + ; used_cos <- TcS.getTcEvTyCoVars ev_binds_var
|
|
| 538 | 571 | |
| 539 | 572 | ; let -- Find the variables needed by `implics`
|
| 540 | 573 | new_need_implic@(ENS { ens_dms = dm_seeds, ens_fvs = other_seeds })
|
| ... | ... | @@ -544,7 +577,8 @@ neededEvVars implic@(Implic { ic_info = info |
| 544 | 577 | -- Get the variables needed by the solved bindings
|
| 545 | 578 | -- (It's OK to use a non-deterministic fold here
|
| 546 | 579 | -- because add_wanted is commutative.)
|
| 547 | - seeds_w = nonDetStrictFoldEvBindMap add_wanted tcvs ev_binds
|
|
| 580 | + used_covars = coVarsOfCos used_cos
|
|
| 581 | + seeds_w = nonDetStrictFoldEvBindMap add_wanted used_covars ev_binds
|
|
| 548 | 582 | |
| 549 | 583 | need_ignoring_dms = findNeededGivenEvVars ev_binds (other_seeds `unionVarSet` seeds_w)
|
| 550 | 584 | need_from_dms = findNeededGivenEvVars ev_binds dm_seeds
|
| ... | ... | @@ -565,7 +599,7 @@ neededEvVars implic@(Implic { ic_info = info |
| 565 | 599 | ; traceTcS "neededEvVars" $
|
| 566 | 600 | vcat [ text "old_need_implic:" <+> ppr old_need_implic
|
| 567 | 601 | , text "new_need_implic:" <+> ppr new_need_implic
|
| 568 | - , text "tcvs:" <+> ppr tcvs
|
|
| 602 | + , text "used_covars:" <+> ppr used_covars
|
|
| 569 | 603 | , text "need_ignoring_dms:" <+> ppr need_ignoring_dms
|
| 570 | 604 | , text "need_from_dms:" <+> ppr need_from_dms
|
| 571 | 605 | , text "need:" <+> ppr need
|
| ... | ... | @@ -589,7 +623,7 @@ neededEvVars implic@(Implic { ic_info = info |
| 589 | 623 | add_wanted :: EvBind -> VarSet -> VarSet
|
| 590 | 624 | add_wanted (EvBind { eb_info = info, eb_rhs = rhs }) needs
|
| 591 | 625 | | EvBindGiven{} <- info = needs -- Add the rhs vars of the Wanted bindings only
|
| 592 | - | otherwise = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 626 | + | otherwise = nestedEvIdsOfTerm rhs `unionVarSet` needs
|
|
| 593 | 627 | |
| 594 | 628 | is_dm_skol :: SkolemInfoAnon -> Bool
|
| 595 | 629 | is_dm_skol (MethSkol _ is_dm) = is_dm
|
| ... | ... | @@ -611,7 +645,7 @@ findNeededGivenEvVars ev_binds seeds |
| 611 | 645 | | Just ev_bind <- lookupEvBind ev_binds v
|
| 612 | 646 | , EvBind { eb_info = EvBindGiven, eb_rhs = rhs } <- ev_bind
|
| 613 | 647 | -- Look at Given bindings only
|
| 614 | - = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 648 | + = nestedEvIdsOfTerm rhs `unionVarSet` needs
|
|
| 615 | 649 | | otherwise
|
| 616 | 650 | = needs
|
| 617 | 651 | |
| ... | ... | @@ -1008,17 +1042,13 @@ solveSimpleWanteds simples |
| 1008 | 1042 | else return (n, wc2) } -- Done
|
| 1009 | 1043 | |
| 1010 | 1044 | |
| 1011 | -solve_simple_wanteds :: WantedConstraints -> TcS WantedConstraints
|
|
| 1045 | +solve_simple_wanteds :: Cts -> TcS Cts
|
|
| 1012 | 1046 | -- Try solving these constraints
|
| 1013 | 1047 | -- Affects the unification state (of course) but not the inert set
|
| 1014 | 1048 | -- The result is not necessarily zonked
|
| 1015 | -solve_simple_wanteds (WC { wc_simple = simples1, wc_impl = implics1, wc_errors = errs })
|
|
| 1016 | - = nestTcS $
|
|
| 1017 | - do { solveSimples simples1
|
|
| 1018 | - ; (implics2, unsolved) <- getUnsolvedInerts
|
|
| 1019 | - ; return (WC { wc_simple = unsolved
|
|
| 1020 | - , wc_impl = implics1 `unionBags` implics2
|
|
| 1021 | - , wc_errors = errs }) }
|
|
| 1049 | +solve_simple_wanteds simples
|
|
| 1050 | + = nestTcS $ do { solveSimples simples
|
|
| 1051 | + ; getUnsolvedInerts }
|
|
| 1022 | 1052 | |
| 1023 | 1053 | {- Note [The solveSimpleWanteds loop]
|
| 1024 | 1054 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -1038,9 +1068,10 @@ Solving a bunch of simple constraints is done in a loop, |
| 1038 | 1068 | |
| 1039 | 1069 | -- The main solver loop implements Note [Basic Simplifier Plan]
|
| 1040 | 1070 | ---------------------------------------------------------------
|
| 1071 | + |
|
| 1041 | 1072 | solveSimples :: Cts -> TcS ()
|
| 1042 | --- Returns the final InertSet in TcS
|
|
| 1043 | --- Has no effect on work-list or residual-implications
|
|
| 1073 | +-- Solve this bag of constraints,
|
|
| 1074 | +-- returning the final InertSet in TcS
|
|
| 1044 | 1075 | -- The constraints are initially examined in left-to-right order
|
| 1045 | 1076 | |
| 1046 | 1077 | solveSimples cts
|
| ... | ... | @@ -1124,14 +1155,15 @@ solveCt (CEqCan (EqCt { eq_ev = ev, eq_eq_rel = eq_rel |
| 1124 | 1155 | , eq_lhs = lhs, eq_rhs = rhs }))
|
| 1125 | 1156 | = solveEquality ev eq_rel (canEqLHSType lhs) rhs
|
| 1126 | 1157 | |
| 1127 | -solveCt (CQuantCan (QCI { qci_ev = ev, qci_pend_sc = pend_sc }))
|
|
| 1128 | - = do { ev <- rewriteEvidence ev
|
|
| 1158 | +solveCt (CQuantCan qci@(QCI { qci_ev = ev }))
|
|
| 1159 | + = do { ev' <- rewriteEvidence ev
|
|
| 1129 | 1160 | -- It is (much) easier to rewrite and re-classify than to
|
| 1130 | 1161 | -- rewrite the pieces and build a Reduction that will rewrite
|
| 1131 | 1162 | -- the whole constraint
|
| 1132 | - ; case classifyPredType (ctEvPred ev) of
|
|
| 1133 | - ForAllPred tvs theta body_pred ->
|
|
| 1134 | - Stage $ solveForAll ev tvs theta body_pred pend_sc
|
|
| 1163 | + ; case classifyPredType (ctEvPred ev') of
|
|
| 1164 | + ForAllPred tvs theta body_pred
|
|
| 1165 | + -> solveForAll (qci { qci_ev = ev', qci_tvs = tvs
|
|
| 1166 | + , qci_theta = theta, qci_body = body_pred })
|
|
| 1135 | 1167 | _ -> pprPanic "SolveCt" (ppr ev) }
|
| 1136 | 1168 | |
| 1137 | 1169 | solveCt (CDictCan (DictCt { di_ev = ev, di_pend_sc = pend_sc }))
|
| ... | ... | @@ -1165,7 +1197,7 @@ solveNC ev |
| 1165 | 1197 | -- And then re-classify
|
| 1166 | 1198 | ; case classifyPredType (ctEvPred ev) of
|
| 1167 | 1199 | ClassPred cls tys -> solveDictNC ev cls tys
|
| 1168 | - ForAllPred tvs th p -> Stage $ solveForAllNC ev tvs th p
|
|
| 1200 | + ForAllPred tvs th p -> solveForAllNC ev tvs th p
|
|
| 1169 | 1201 | IrredPred {} -> solveIrred (IrredCt { ir_ev = ev, ir_reason = IrredShapeReason })
|
| 1170 | 1202 | EqPred eq_rel ty1 ty2 -> solveEquality ev eq_rel ty1 ty2
|
| 1171 | 1203 | -- EqPred only happens if (say) `c` is unified with `a ~# b`,
|
| ... | ... | @@ -1256,50 +1288,49 @@ type signature. |
| 1256 | 1288 | --
|
| 1257 | 1289 | -- Precondition: the constraint has already been rewritten by the inert set.
|
| 1258 | 1290 | solveForAllNC :: CtEvidence -> [TcTyVar] -> TcThetaType -> TcPredType
|
| 1259 | - -> TcS (StopOrContinue Void)
|
|
| 1291 | + -> SolverStage Void
|
|
| 1260 | 1292 | solveForAllNC ev tvs theta body_pred
|
| 1261 | - | Just (cls,tys) <- getClassPredTys_maybe body_pred
|
|
| 1262 | - , classHasSCs cls
|
|
| 1263 | - = do { dflags <- getDynFlags
|
|
| 1264 | - -- Either expand superclasses (Givens) or provide fuel to do so (Wanteds)
|
|
| 1265 | - ; if isGiven ev
|
|
| 1266 | - then
|
|
| 1267 | - -- See Note [Eagerly expand given superclasses]
|
|
| 1268 | - -- givensFuel dflags: See Note [Expanding Recursive Superclasses and ExpansionFuel]
|
|
| 1269 | - do { sc_cts <- mkStrictSuperClasses (givensFuel dflags) ev tvs theta cls tys
|
|
| 1270 | - ; emitWork (listToBag sc_cts)
|
|
| 1271 | - ; solveForAll ev tvs theta body_pred doNotExpand }
|
|
| 1272 | - else
|
|
| 1273 | - -- See invariants (a) and (b) in QCI.qci_pend_sc
|
|
| 1274 | - -- qcsFuel dflags: See Note [Expanding Recursive Superclasses and ExpansionFuel]
|
|
| 1275 | - -- See Note [Quantified constraints]
|
|
| 1276 | - do { solveForAll ev tvs theta body_pred (qcsFuel dflags) }
|
|
| 1277 | - }
|
|
| 1293 | + = do { fuel <- simpleStage mk_super_classes
|
|
| 1294 | + ; solveForAll (QCI { qci_ev = ev, qci_tvs = tvs, qci_theta = theta
|
|
| 1295 | + , qci_body = body_pred, qci_pend_sc = fuel }) }
|
|
| 1278 | 1296 | |
| 1279 | - | otherwise
|
|
| 1280 | - = solveForAll ev tvs theta body_pred doNotExpand
|
|
| 1297 | + where
|
|
| 1298 | + mk_super_classes :: TcS ExpansionFuel
|
|
| 1299 | + mk_super_classes
|
|
| 1300 | + | Just (cls,tys) <- getClassPredTys_maybe body_pred
|
|
| 1301 | + , classHasSCs cls
|
|
| 1302 | + = do { dflags <- getDynFlags
|
|
| 1303 | + -- Either expand superclasses (Givens) or provide fuel to do so (Wanteds)
|
|
| 1304 | + ; if isGiven ev
|
|
| 1305 | + then
|
|
| 1306 | + -- See Note [Eagerly expand given superclasses]
|
|
| 1307 | + -- givensFuel dflags: See Note [Expanding Recursive Superclasses and ExpansionFuel]
|
|
| 1308 | + do { sc_cts <- mkStrictSuperClasses (givensFuel dflags) ev tvs theta cls tys
|
|
| 1309 | + ; emitWork (listToBag sc_cts)
|
|
| 1310 | + ; return doNotExpand }
|
|
| 1311 | + else
|
|
| 1312 | + -- See invariants (a) and (b) in QCI.qci_pend_sc
|
|
| 1313 | + -- qcsFuel dflags: See Note [Expanding Recursive Superclasses and ExpansionFuel]
|
|
| 1314 | + -- See Note [Quantified constraints]
|
|
| 1315 | + return (qcsFuel dflags)
|
|
| 1316 | + }
|
|
| 1317 | + |
|
| 1318 | + | otherwise
|
|
| 1319 | + = return doNotExpand
|
|
| 1281 | 1320 | |
| 1282 | 1321 | -- | Solve a canonical quantified constraint.
|
| 1283 | 1322 | --
|
| 1284 | 1323 | -- Precondition: the constraint has already been rewritten by the inert set.
|
| 1285 | -solveForAll :: CtEvidence -> [TcTyVar] -> TcThetaType -> PredType -> ExpansionFuel
|
|
| 1286 | - -> TcS (StopOrContinue Void)
|
|
| 1287 | -solveForAll ev tvs theta body_pred fuel =
|
|
| 1288 | - case ev of
|
|
| 1289 | - CtGiven {} ->
|
|
| 1290 | - -- See Note [Solving a Given forall-constraint]
|
|
| 1291 | - do { addInertForAll qci
|
|
| 1292 | - ; stopWith ev "Given forall-constraint" }
|
|
| 1293 | - CtWanted wtd ->
|
|
| 1294 | - -- See Note [Solving a Wanted forall-constraint]
|
|
| 1295 | - runSolverStage $
|
|
| 1296 | - do { tryInertQCs qci
|
|
| 1297 | - ; Stage $ solveWantedForAll_implic wtd tvs theta body_pred
|
|
| 1298 | - }
|
|
| 1299 | - where
|
|
| 1300 | - qci = QCI { qci_ev = ev, qci_tvs = tvs
|
|
| 1301 | - , qci_body = body_pred, qci_pend_sc = fuel }
|
|
| 1302 | - |
|
| 1324 | +solveForAll :: QCInst -> SolverStage Void
|
|
| 1325 | +solveForAll qci@(QCI { qci_ev = ev, qci_tvs = tvs, qci_theta = theta, qci_body = pred })
|
|
| 1326 | + = case ev of
|
|
| 1327 | + CtGiven {} ->
|
|
| 1328 | + -- See Note [Solving a Given forall-constraint]
|
|
| 1329 | + do { simpleStage (addInertForAll qci)
|
|
| 1330 | + ; stopWithStage ev "Given forall-constraint" }
|
|
| 1331 | + CtWanted wtd ->
|
|
| 1332 | + do { tryInertQCs qci
|
|
| 1333 | + ; solveWantedForAll qci tvs theta pred wtd }
|
|
| 1303 | 1334 | |
| 1304 | 1335 | tryInertQCs :: QCInst -> SolverStage ()
|
| 1305 | 1336 | tryInertQCs qc
|
| ... | ... | @@ -1310,7 +1341,8 @@ tryInertQCs qc |
| 1310 | 1341 | try_inert_qcs :: QCInst -> [QCInst] -> TcS (StopOrContinue ())
|
| 1311 | 1342 | try_inert_qcs (QCI { qci_ev = ev_w }) inerts =
|
| 1312 | 1343 | case mapMaybe matching_inert inerts of
|
| 1313 | - [] -> continueWith ()
|
|
| 1344 | + [] -> do { traceTcS "tryInertQCs:nothing" (ppr ev_w $$ ppr inerts)
|
|
| 1345 | + ; continueWith () }
|
|
| 1314 | 1346 | ev_i:_ ->
|
| 1315 | 1347 | do { traceTcS "tryInertQCs:KeepInert" (ppr ev_i)
|
| 1316 | 1348 | ; setEvBindIfWanted ev_w EvCanonical (ctEvTerm ev_i)
|
| ... | ... | @@ -1323,57 +1355,72 @@ try_inert_qcs (QCI { qci_ev = ev_w }) inerts = |
| 1323 | 1355 | = Nothing
|
| 1324 | 1356 | |
| 1325 | 1357 | -- | Solve a (canonical) Wanted quantified constraint by emitting an implication.
|
| 1326 | ---
|
|
| 1327 | 1358 | -- See Note [Solving a Wanted forall-constraint]
|
| 1328 | -solveWantedForAll_implic :: WantedCtEvidence -> [TcTyVar] -> TcThetaType -> PredType -> TcS (StopOrContinue Void)
|
|
| 1329 | -solveWantedForAll_implic
|
|
| 1330 | - wtd@(WantedCt { ctev_dest = dest, ctev_loc = loc, ctev_rewriters = rewriters })
|
|
| 1331 | - tvs theta body_pred =
|
|
| 1332 | - -- We are about to do something irreversible (turning a quantified constraint
|
|
| 1333 | - -- into an implication), so wrap the inner call in solveCompletelyIfRequired
|
|
| 1334 | - -- to ensure we can roll back if we can't solve the implication fully.
|
|
| 1335 | - -- See Note [TcSSpecPrag] in GHC.Tc.Solver.Monad.
|
|
| 1336 | - solveCompletelyIfRequired (mkNonCanonical $ CtWanted wtd) $
|
|
| 1337 | - |
|
| 1338 | - -- This setSrcSpan is important: the emitImplicationTcS uses that
|
|
| 1339 | - -- TcLclEnv for the implication, and that in turn sets the location
|
|
| 1340 | - -- for the Givens when solving the constraint (#21006)
|
|
| 1341 | - TcS.setSrcSpan (getCtLocEnvLoc $ ctLocEnv loc) $
|
|
| 1342 | - do { let empty_subst = mkEmptySubst $ mkInScopeSet $
|
|
| 1343 | - tyCoVarsOfTypes (body_pred:theta) `delVarSetList` tvs
|
|
| 1344 | - is_qc = IsQC (ctLocOrigin loc)
|
|
| 1345 | - |
|
| 1346 | - -- rec {..}: see Note [Keeping SkolemInfo inside a SkolemTv]
|
|
| 1359 | +solveWantedForAll :: QCInst -> [TcTyVar] -> TcThetaType -> PredType
|
|
| 1360 | + -> WantedCtEvidence -> SolverStage Void
|
|
| 1361 | +solveWantedForAll qci tvs theta body_pred
|
|
| 1362 | + wtd@(WantedCt { ctev_dest = dest, ctev_loc = ct_loc
|
|
| 1363 | + , ctev_rewriters = rewriters })
|
|
| 1364 | + = Stage $
|
|
| 1365 | + TcS.setSrcSpan (getCtLocEnvLoc loc_env) $
|
|
| 1366 | + -- This setSrcSpan is important: the emitImplicationTcS uses that
|
|
| 1367 | + -- TcLclEnv for the implication, and that in turn sets the location
|
|
| 1368 | + -- for the Givens when solving the constraint (#21006)
|
|
| 1369 | + |
|
| 1370 | + do { -- rec {..}: see Note [Keeping SkolemInfo inside a SkolemTv]
|
|
| 1347 | 1371 | -- in GHC.Tc.Utils.TcType
|
| 1348 | 1372 | -- Very like the code in tcSkolDFunType
|
| 1349 | - ; rec { skol_info <- mkSkolemInfo skol_info_anon
|
|
| 1373 | + rec { skol_info <- mkSkolemInfo skol_info_anon
|
|
| 1350 | 1374 | ; (subst, skol_tvs) <- tcInstSkolTyVarsX skol_info empty_subst tvs
|
| 1351 | 1375 | ; let inst_pred = substTy subst body_pred
|
| 1352 | 1376 | inst_theta = substTheta subst theta
|
| 1353 | 1377 | skol_info_anon = InstSkol is_qc (get_size inst_pred) }
|
| 1354 | 1378 | |
| 1355 | - ; given_ev_vars <- mapM newEvVar inst_theta
|
|
| 1356 | - ; (lvl, (w_id, wanteds))
|
|
| 1357 | - <- pushLevelNoWorkList (ppr skol_info) $
|
|
| 1358 | - do { let loc' = setCtLocOrigin loc (ScOrigin is_qc NakedSc)
|
|
| 1359 | - -- Set the thing to prove to have a ScOrigin, so we are
|
|
| 1360 | - -- careful about its termination checks.
|
|
| 1361 | - -- See (QC-INV) in Note [Solving a Wanted forall-constraint]
|
|
| 1362 | - ; wanted_ev <- newWantedNC loc' rewriters inst_pred
|
|
| 1363 | - -- NB: inst_pred can be an equality
|
|
| 1364 | - ; return ( wantedCtEvEvId wanted_ev
|
|
| 1365 | - , unitBag (mkNonCanonical $ CtWanted wanted_ev)) }
|
|
| 1366 | - |
|
| 1367 | - ; traceTcS "solveForAll" (ppr given_ev_vars $$ ppr wanteds $$ ppr w_id)
|
|
| 1368 | - ; ev_binds <- emitImplicationTcS lvl skol_info_anon skol_tvs given_ev_vars wanteds
|
|
| 1369 | - |
|
| 1370 | - ; setWantedEvTerm dest EvCanonical $
|
|
| 1371 | - EvFun { et_tvs = skol_tvs, et_given = given_ev_vars
|
|
| 1372 | - , et_binds = ev_binds, et_body = w_id }
|
|
| 1373 | - |
|
| 1374 | - ; stopWith (CtWanted wtd) "Wanted forall-constraint (implication)"
|
|
| 1375 | - }
|
|
| 1379 | + ; given_ev_vars <- mapM newEvVar inst_theta
|
|
| 1380 | + ; (lvl, (w_id, wanteds))
|
|
| 1381 | + <- pushLevelNoWorkList (ppr skol_info) $
|
|
| 1382 | + do { let ct_loc' = setCtLocOrigin ct_loc (ScOrigin is_qc NakedSc)
|
|
| 1383 | + -- Set the thing to prove to have a ScOrigin, so we are
|
|
| 1384 | + -- careful about its termination checks.
|
|
| 1385 | + -- See (QC-INV) in Note [Solving a Wanted forall-constraint]
|
|
| 1386 | + ; wanted_ev <- newWantedNC ct_loc' rewriters inst_pred
|
|
| 1387 | + -- NB: inst_pred can be an equality
|
|
| 1388 | + ; return ( wantedCtEvEvId wanted_ev
|
|
| 1389 | + , unitBag (mkNonCanonical $ CtWanted wanted_ev)) }
|
|
| 1390 | + |
|
| 1391 | + ; traceTcS "solveForAll {" (ppr skol_tvs $$ ppr given_ev_vars $$ ppr wanteds $$ ppr w_id)
|
|
| 1392 | + |
|
| 1393 | + -- Try to solve the constraint completely
|
|
| 1394 | + ; ev_binds_var <- TcS.newTcEvBinds
|
|
| 1395 | + ; solved <- trySolveImplication $
|
|
| 1396 | + (implicationPrototype loc_env)
|
|
| 1397 | + { ic_tclvl = lvl
|
|
| 1398 | + , ic_binds = ev_binds_var
|
|
| 1399 | + , ic_info = skol_info_anon
|
|
| 1400 | + , ic_warn_inaccessible = False
|
|
| 1401 | + , ic_skols = skol_tvs
|
|
| 1402 | + , ic_given = given_ev_vars
|
|
| 1403 | + , ic_wanted = emptyWC { wc_simple = wanteds } }
|
|
| 1404 | + ; traceTcS "solveForAll }" (ppr solved)
|
|
| 1405 | + ; evbs <- TcS.getTcEvBindsMap ev_binds_var
|
|
| 1406 | + ; if not solved
|
|
| 1407 | + then do { -- Not completely solved; abandon that attempt and add the
|
|
| 1408 | + -- original constraint to the inert set
|
|
| 1409 | + addInertForAll qci
|
|
| 1410 | + ; stopWith (CtWanted wtd) "Wanted forall-constraint:unsolved" }
|
|
| 1411 | + |
|
| 1412 | + else do { -- Completely solved; build an evidence term
|
|
| 1413 | + setWantedEvTerm dest EvCanonical $
|
|
| 1414 | + EvFun { et_tvs = skol_tvs, et_given = given_ev_vars
|
|
| 1415 | + , et_binds = evBindMapBinds evbs, et_body = w_id }
|
|
| 1416 | + ; stopWith (CtWanted wtd) "Wanted forall-constraint:solved" } }
|
|
| 1376 | 1417 | where
|
| 1418 | + loc_env = ctLocEnv ct_loc
|
|
| 1419 | + is_qc = IsQC (ctLocOrigin ct_loc)
|
|
| 1420 | + |
|
| 1421 | + empty_subst = mkEmptySubst $ mkInScopeSet $
|
|
| 1422 | + tyCoVarsOfTypes (body_pred:theta) `delVarSetList` tvs
|
|
| 1423 | + |
|
| 1377 | 1424 | -- Getting the size of the head is a bit horrible
|
| 1378 | 1425 | -- because of the special treament for class predicates
|
| 1379 | 1426 | get_size pred = case classifyPredType pred of
|
| ... | ... | @@ -1384,36 +1431,68 @@ solveWantedForAll_implic |
| 1384 | 1431 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1385 | 1432 | Solving a wanted forall (quantified) constraint
|
| 1386 | 1433 | [W] df :: forall a b. (Eq a, Ord b) => C x a b
|
| 1387 | -is delightfully easy. Just build an implication constraint
|
|
| 1434 | +is delightfully easy in principle. Just build an implication constraint
|
|
| 1388 | 1435 | forall ab. (g1::Eq a, g2::Ord b) => [W] d :: C x a
|
| 1389 | 1436 | and discharge df thus:
|
| 1390 | 1437 | df = /\ab. \g1 g2. let <binds> in d
|
| 1391 | 1438 | where <binds> is filled in by solving the implication constraint.
|
| 1392 | 1439 | All the machinery is to hand; there is little to do.
|
| 1393 | 1440 | |
| 1394 | -We can take a more straightforward parth when there is a matching Given, e.g.
|
|
| 1395 | - [W] dg :: forall c d. (Eq c, Ord d) => C x c d
|
|
| 1396 | -In this case, it's better to directly solve the Wanted from the Given, instead
|
|
| 1397 | -of building an implication. This is more than a simple optimisation; see
|
|
| 1398 | -Note [Solving Wanted QCs from Given QCs].
|
|
| 1441 | +There are some tricky corners though:
|
|
| 1442 | + |
|
| 1443 | +(WFA1) We can take a more straightforward path when there is a matching Given, e.g.
|
|
| 1444 | + [W] dg :: forall c d. (Eq c, Ord d) => C x c d
|
|
| 1445 | + In this case, it's better to directly solve the Wanted from the Given, instead
|
|
| 1446 | + of building an implication. This is more than a simple optimisation; see
|
|
| 1447 | + Note [Solving Wanted QCs from Given QCs].
|
|
| 1448 | + |
|
| 1449 | +(WFA2) Termination: see #19690. We want to maintain the invariant (QC-INV):
|
|
| 1450 | + |
|
| 1451 | + (QC-INV) Every quantified constraint returns a non-bottom dictionary
|
|
| 1452 | + |
|
| 1453 | + just as every top-level instance declaration guarantees to return a non-bottom
|
|
| 1454 | + dictionary. But as #19690 shows, it is possible to get a bottom dictionary
|
|
| 1455 | + by superclass selection if we aren't careful. The situation is very similar
|
|
| 1456 | + to that described in Note [Recursive superclasses] in GHC.Tc.TyCl.Instance;
|
|
| 1457 | + and we use the same solution:
|
|
| 1458 | + |
|
| 1459 | + * Give the Givens a CtOrigin of (GivenOrigin (InstSkol IsQC head_size))
|
|
| 1460 | + * Give the Wanted a CtOrigin of (ScOrigin IsQC NakedSc)
|
|
| 1461 | + |
|
| 1462 | + Both of these things are done in solveForAll. Now the mechanism described
|
|
| 1463 | + in Note [Solving superclass constraints] in GHC.Tc.TyCl.Instance takes over.
|
|
| 1464 | + |
|
| 1465 | +(WFA3) We do not actually emit an implication to solve later. Rather we
|
|
| 1466 | + try to solve it completely immediately using `trySolveImplication`
|
|
| 1467 | + - If successful, we can build evidence
|
|
| 1468 | + - If unsuccessful, we abandon the attempt and add the unsolved
|
|
| 1469 | + forall-constraint to the inert set.
|
|
| 1399 | 1470 | |
| 1471 | + Several reasons for this "solve immediately" approach
|
|
| 1400 | 1472 | |
| 1401 | -The tricky point is about termination: see #19690. We want to maintain
|
|
| 1402 | -the invariant (QC-INV):
|
|
| 1473 | + - It saves quite a bit of plumbing, tracking the emitted implications for
|
|
| 1474 | + later solving; and the evidence would have to contain as-yet-incomplte
|
|
| 1475 | + bindings which complicates tracking of unused Givens.
|
|
| 1403 | 1476 | |
| 1404 | - (QC-INV) Every quantified constraint returns a non-bottom dictionary
|
|
| 1477 | + - We get better error messages, about failing to solve, say
|
|
| 1478 | + (forall a. a->a) ~ (forall b. b->Int)
|
|
| 1405 | 1479 | |
| 1406 | -just as every top-level instance declaration guarantees to return a non-bottom
|
|
| 1407 | -dictionary. But as #19690 shows, it is possible to get a bottom dicionary
|
|
| 1408 | -by superclass selection if we aren't careful. The situation is very similar
|
|
| 1409 | -to that described in Note [Recursive superclasses] in GHC.Tc.TyCl.Instance;
|
|
| 1410 | -and we use the same solution:
|
|
| 1480 | + - Consider
|
|
| 1481 | + f :: forall f a. (Ix a, forall x. Eq x => Eq (f x)) => a -> f a
|
|
| 1482 | + {-# SPECIALISE f :: forall f. (forall x. Eq x => Eq (f x)) => Int -> f Int #-}
|
|
| 1483 | + This SPECIALISE is treated like an expression with a type signature, so
|
|
| 1484 | + we instantiate the constraints, simplify them and re-generalise. From the
|
|
| 1485 | + instantiation we get [W] d :: (forall x. Eq a => Eq (f x))
|
|
| 1486 | + and we want to generalise over that. We do not want to attempt to solve it
|
|
| 1487 | + and then get stuck, and emit an error message. If we can't solve it, better
|
|
| 1488 | + to leave it alone.
|
|
| 1411 | 1489 | |
| 1412 | -* Give the Givens a CtOrigin of (GivenOrigin (InstSkol IsQC head_size))
|
|
| 1413 | -* Give the Wanted a CtOrigin of (ScOrigin IsQC NakedSc)
|
|
| 1490 | + We still need to simplify quantified constraints that can be
|
|
| 1491 | + /fully solved/ from instances, otherwise we would never be able to
|
|
| 1492 | + specialise them away. Example: {-# SPECIALISE f @[] @a #-}.
|
|
| 1414 | 1493 | |
| 1415 | -Both of these things are done in solveForAll. Now the mechanism described
|
|
| 1416 | -in Note [Solving superclass constraints] in GHC.Tc.TyCl.Instance takes over.
|
|
| 1494 | + You might worry about the wasted work, but it is seldom repeated (because the
|
|
| 1495 | + constraint solver seldom iterates much).
|
|
| 1417 | 1496 | |
| 1418 | 1497 | Note [Solving a Given forall-constraint]
|
| 1419 | 1498 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -1576,13 +1655,13 @@ runTcPluginsGiven |
| 1576 | 1655 | -- work) and a bag of insolubles. The boolean indicates whether
|
| 1577 | 1656 | -- 'solveSimpleWanteds' should feed the updated wanteds back into the
|
| 1578 | 1657 | -- main solver.
|
| 1579 | -runTcPluginsWanted :: WantedConstraints -> TcS (Bool, WantedConstraints)
|
|
| 1580 | -runTcPluginsWanted wc@(WC { wc_simple = simples1 })
|
|
| 1658 | +runTcPluginsWanted :: Cts -> TcS (Bool, Cts)
|
|
| 1659 | +runTcPluginsWanted simples1
|
|
| 1581 | 1660 | | isEmptyBag simples1
|
| 1582 | - = return (False, wc)
|
|
| 1661 | + = return (False, simples1)
|
|
| 1583 | 1662 | | otherwise
|
| 1584 | 1663 | = do { solvers <- getTcPluginSolvers
|
| 1585 | - ; if null solvers then return (False, wc) else
|
|
| 1664 | + ; if null solvers then return (False, simples1) else
|
|
| 1586 | 1665 | |
| 1587 | 1666 | do { given <- getInertGivens
|
| 1588 | 1667 | ; wanted <- TcS.zonkSimples simples1 -- Plugin requires zonked inputs
|
| ... | ... | @@ -1604,8 +1683,7 @@ runTcPluginsWanted wc@(WC { wc_simple = simples1 }) |
| 1604 | 1683 | ; mapM_ setEv solved_wanted
|
| 1605 | 1684 | |
| 1606 | 1685 | ; traceTcS "Finished plugins }" (ppr new_wanted)
|
| 1607 | - ; return ( notNull (pluginNewCts p)
|
|
| 1608 | - , wc { wc_simple = all_new_wanted } ) } }
|
|
| 1686 | + ; return ( notNull (pluginNewCts p), all_new_wanted ) } }
|
|
| 1609 | 1687 | where
|
| 1610 | 1688 | setEv :: (EvTerm,Ct) -> TcS ()
|
| 1611 | 1689 | setEv (ev,ct) = case ctEvidence ct of
|
| 1 | +module GHC.Tc.Solver.Solve where
|
|
| 2 | + |
|
| 3 | +import Prelude( Bool )
|
|
| 4 | +import GHC.Tc.Solver.Monad( TcS )
|
|
| 5 | +import GHC.Tc.Types.Constraint( Cts, Implication )
|
|
| 6 | + |
|
| 7 | +solveSimpleWanteds :: Cts -> TcS Cts
|
|
| 8 | +trySolveImplication :: Implication -> TcS Bool |
| ... | ... | @@ -746,8 +746,12 @@ zonk_bind (XHsBindsLR (AbsBinds { abs_tvs = tyvars, abs_ev_vars = evs |
| 746 | 746 | runZonkBndrT (zonkTyBndrsX tyvars ) $ \ new_tyvars ->
|
| 747 | 747 | runZonkBndrT (zonkEvBndrsX evs ) $ \ new_evs ->
|
| 748 | 748 | runZonkBndrT (zonkTcEvBinds_s ev_binds) $ \ new_ev_binds ->
|
| 749 | - do { (new_val_bind, new_exports) <- mfix $ \ ~(new_val_binds, _) ->
|
|
| 750 | - runZonkBndrT (extendIdZonkEnvRec $ collectHsBindsBinders CollNoDictBinders new_val_binds) $ \ _ ->
|
|
| 749 | + do { (new_val_bind, new_exports) <- mfix $ \ ~(new_val_binds, new_exports) ->
|
|
| 750 | + let new_bndrs = collectHsBindsBinders CollNoDictBinders new_val_binds
|
|
| 751 | + ++ map abe_poly new_exports
|
|
| 752 | + -- Tie the knot with the `abe_poly` binders too, since they
|
|
| 753 | + -- may be mentioned in the `abe_prags` of the `exports`
|
|
| 754 | + in runZonkBndrT (extendIdZonkEnvRec new_bndrs) $ \ _ ->
|
|
| 751 | 755 | do { new_val_binds <- mapM zonk_val_bind val_binds
|
| 752 | 756 | ; new_exports <- mapM zonk_export exports
|
| 753 | 757 | ; return (new_val_binds, new_exports)
|
| ... | ... | @@ -854,6 +858,7 @@ zonkLTcSpecPrags ps |
| 854 | 858 | ; skol_tvs_ref <- lift $ newTcRef []
|
| 855 | 859 | ; setZonkType (SkolemiseFlexi skol_tvs_ref) $
|
| 856 | 860 | -- SkolemiseFlexi: see Note [Free tyvars on rule LHS]
|
| 861 | + |
|
| 857 | 862 | runZonkBndrT (zonkCoreBndrsX bndrs) $ \ bndrs' ->
|
| 858 | 863 | do { spec_e' <- zonkLExpr spec_e
|
| 859 | 864 | ; skol_tvs <- lift $ readTcRef skol_tvs_ref
|
| ... | ... | @@ -1759,7 +1764,7 @@ zonkEvTerm (EvFun { et_tvs = tvs, et_given = evs |
| 1759 | 1764 | , et_binds = ev_binds, et_body = body_id })
|
| 1760 | 1765 | = runZonkBndrT (zonkTyBndrsX tvs) $ \ new_tvs ->
|
| 1761 | 1766 | runZonkBndrT (zonkEvBndrsX evs) $ \ new_evs ->
|
| 1762 | - runZonkBndrT (zonkTcEvBinds ev_binds) $ \ new_ev_binds ->
|
|
| 1767 | + runZonkBndrT (zonkEvBinds ev_binds) $ \ new_ev_binds ->
|
|
| 1763 | 1768 | do { new_body_id <- zonkIdOcc body_id
|
| 1764 | 1769 | ; return (EvFun { et_tvs = new_tvs, et_given = new_evs
|
| 1765 | 1770 | , et_binds = new_ev_binds, et_body = new_body_id }) }
|
| ... | ... | @@ -12,3 +12,5 @@ instance Alt [] where |
| 12 | 12 | (<!>) = (++)
|
| 13 | 13 | |
| 14 | 14 | newtype L a = L [a] deriving (Functor, Alt)
|
| 15 | + |
|
| 16 | +newtype T f a = T (f a) deriving (Functor, Alt) |
| 1 | - |
|
| 2 | 1 | T17332.hs:13:7: error: [GHC-05617]
|
| 3 | - • Could not solve: ‘a’
|
|
| 4 | - arising from the head of a quantified constraint
|
|
| 2 | + • Could not solve: ‘forall (a :: Constraint). a’
|
|
| 5 | 3 | arising from a use of ‘MkDict’
|
| 6 | 4 | • In the expression: MkDict
|
| 7 | 5 | In an equation for ‘aux’: aux = MkDict
|
| 6 | + |
| 1 | 1 | T15290a.hs:25:12: error: [GHC-18872]
|
| 2 | - • Couldn't match representation of type: m (Int, IntStateT m a1)
|
|
| 3 | - with that of: m (Int, StateT Int m a1)
|
|
| 2 | + • Couldn't match representation of type: forall a.
|
|
| 3 | + StateT Int m (StateT Int m a) -> StateT Int m a
|
|
| 4 | + with that of: forall a.
|
|
| 5 | + IntStateT m (IntStateT m a) -> IntStateT m a
|
|
| 4 | 6 | arising from a use of ‘coerce’
|
| 5 | - Note: We cannot know what roles the parameters to ‘m’ have;
|
|
| 6 | - we must assume that the role is nominal.
|
|
| 7 | 7 | • In the expression:
|
| 8 | 8 | coerce
|
| 9 | 9 | @(forall a. StateT Int m (StateT Int m a) -> StateT Int m a)
|
| 1 | - |
|
| 2 | 1 | T19690.hs:12:16: error: [GHC-05617]
|
| 3 | - • Could not deduce ‘c’
|
|
| 4 | - arising from the head of a quantified constraint
|
|
| 5 | - arising from a use of ‘go’
|
|
| 6 | - from the context: Hold c
|
|
| 7 | - bound by a quantified context at T19690.hs:12:16-17
|
|
| 2 | + • Could not solve: ‘Hold c => c’ arising from a use of ‘go’
|
|
| 8 | 3 | • In the expression: go
|
| 9 | 4 | In an equation for ‘anythingDict’:
|
| 10 | 5 | anythingDict
|
| ... | ... | @@ -12,5 +7,4 @@ T19690.hs:12:16: error: [GHC-05617] |
| 12 | 7 | where
|
| 13 | 8 | go :: (Hold c => c) => Dict c
|
| 14 | 9 | go = Dict
|
| 15 | - • Relevant bindings include
|
|
| 16 | - anythingDict :: Dict c (bound at T19690.hs:12:1) |
|
| 10 | + |
| 1 | - |
|
| 2 | 1 | T19921.hs:29:8: error: [GHC-05617]
|
| 3 | - • Could not deduce ‘r’
|
|
| 4 | - arising from the head of a quantified constraint
|
|
| 5 | - arising from the head of a quantified constraint
|
|
| 2 | + • Could not solve: ‘((x \/ y) \/ z) ⇒ (x \/ (y \/ z))’
|
|
| 6 | 3 | arising from a use of ‘Dict’
|
| 7 | - from the context: (x \/ y) \/ z
|
|
| 8 | - bound by a quantified context at T19921.hs:29:8-11
|
|
| 9 | - or from: (x ⇒ r, (y \/ z) ⇒ r)
|
|
| 10 | - bound by a quantified context at T19921.hs:29:8-11
|
|
| 11 | 4 | • In the expression: Dict
|
| 12 | 5 | In an equation for ‘dict’: dict = Dict
|
| 6 | + |
| 1 | - |
|
| 2 | 1 | T21006.hs:14:10: error: [GHC-05617]
|
| 3 | - • Could not deduce ‘c’
|
|
| 4 | - arising from the head of a quantified constraint
|
|
| 2 | + • Could not solve: ‘forall b (c :: Constraint).
|
|
| 3 | + (Determines b, Determines c) =>
|
|
| 4 | + c’
|
|
| 5 | 5 | arising from the superclasses of an instance declaration
|
| 6 | - from the context: (Determines b, Determines c)
|
|
| 7 | - bound by a quantified context at T21006.hs:14:10-15
|
|
| 8 | 6 | • In the instance declaration for ‘OpCode’
|
| 7 | + |
| 1 | - |
|
| 2 | 1 | T12427a.hs:17:29: error: [GHC-91028]
|
| 3 | 2 | • Couldn't match expected type ‘p’
|
| 4 | 3 | with actual type ‘(forall b. [b] -> [b]) -> Int’
|
| ... | ... | @@ -24,12 +23,11 @@ T12427a.hs:28:6: error: [GHC-91028] |
| 24 | 23 | • In the pattern: T1 _ x1
|
| 25 | 24 | In a pattern binding: T1 _ x1 = undefined
|
| 26 | 25 | |
| 27 | -T12427a.hs:41:6: error: [GHC-25897]
|
|
| 28 | - • Couldn't match type ‘b’ with ‘[b]’
|
|
| 26 | +T12427a.hs:41:6: error: [GHC-83865]
|
|
| 27 | + • Couldn't match type: forall b. [b] -> [b]
|
|
| 28 | + with: forall a. a -> a
|
|
| 29 | 29 | Expected: (forall b. [b] -> [b]) -> Int
|
| 30 | 30 | Actual: (forall a. a -> a) -> Int
|
| 31 | - ‘b’ is a rigid type variable bound by
|
|
| 32 | - the type [b] -> [b]
|
|
| 33 | - at T12427a.hs:41:1-19
|
|
| 34 | 31 | • In the pattern: T1 _ x3
|
| 35 | 32 | In a pattern binding: T1 _ x3 = undefined
|
| 33 | + |
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | --
|
| 7 | 7 | -- The ticket #14605 has a much longer example that
|
| 8 | 8 | -- also fails; it does not use ImpredicativeTypes
|
| 9 | +--
|
|
| 10 | +-- The error message is not great; but it's an obscure program
|
|
| 9 | 11 | |
| 10 | 12 | module T14605 where
|
| 11 | 13 |
| 1 | - |
|
| 2 | -T14605.hs:14:13: error: [GHC-10283]
|
|
| 3 | - • Couldn't match representation of type ‘x’ with that of ‘()’
|
|
| 1 | +T14605.hs:16:13: error: [GHC-18872]
|
|
| 2 | + • Couldn't match representation of type: forall x. ()
|
|
| 3 | + with that of: forall x. x
|
|
| 4 | 4 | arising from a use of ‘coerce’
|
| 5 | - ‘x’ is a rigid type variable bound by
|
|
| 6 | - the type ()
|
|
| 7 | - at T14605.hs:14:1-49
|
|
| 8 | 5 | • In the expression: coerce @(forall x. ()) @(forall x. x)
|
| 9 | 6 | In an equation for ‘duplicate’:
|
| 10 | 7 | duplicate = coerce @(forall x. ()) @(forall x. x)
|
| 8 | + |
| 1 | - |
|
| 2 | -T15801.hs:52:10: error: [GHC-18872]
|
|
| 3 | - • Couldn't match representation of type: UnOp op_a -> UnOp b
|
|
| 4 | - with that of: op_a --> b
|
|
| 5 | - arising from the head of a quantified constraint
|
|
| 1 | +T15801.hs:52:10: error: [GHC-05617]
|
|
| 2 | + • Could not solve: ‘forall (op_a :: Op (*)) (b :: Op (*)).
|
|
| 3 | + op_a -#- b’
|
|
| 6 | 4 | arising from the superclasses of an instance declaration
|
| 7 | 5 | • In the instance declaration for ‘OpRíki (Op (*))’
|
| 6 | + |
| 1 | - |
|
| 2 | -T18640a.hs:12:1: error: [GHC-25897]
|
|
| 3 | - • Couldn't match kind ‘a’ with ‘*’
|
|
| 4 | - Expected: forall (b :: k). * -> *
|
|
| 5 | - Actual: forall (b :: k). * -> a
|
|
| 6 | - ‘a’ is a rigid type variable bound by
|
|
| 7 | - the type family declaration for ‘F2’
|
|
| 8 | - at T18640a.hs:12:17
|
|
| 1 | +T18640a.hs:12:1: error: [GHC-83865]
|
|
| 2 | + • Couldn't match expected kind: forall (b :: k). * -> *
|
|
| 3 | + with actual kind: forall (b :: k). * -> a
|
|
| 9 | 4 | • In the type family declaration for ‘F2’
|
| 5 | + |
| 1 | - |
|
| 2 | -T18640b.hs:14:10: error: [GHC-25897]
|
|
| 3 | - • Couldn't match kind ‘k’ with ‘a’
|
|
| 4 | - Expected kind ‘forall b -> a’, but ‘F1’ has kind ‘forall k -> k’
|
|
| 5 | - ‘k’ is a rigid type variable bound by
|
|
| 6 | - the type k
|
|
| 7 | - at T18640b.hs:14:3-11
|
|
| 8 | - ‘a’ is a rigid type variable bound by
|
|
| 9 | - a family instance declaration
|
|
| 10 | - at T18640b.hs:14:6
|
|
| 1 | +T18640b.hs:14:10: error: [GHC-83865]
|
|
| 2 | + • Expected kind ‘forall b -> a’, but ‘F1’ has kind ‘forall k -> k’
|
|
| 11 | 3 | • In the type ‘F1’
|
| 12 | 4 | In the type family declaration for ‘F3’
|
| 5 | + |
| ... | ... | @@ -18,28 +18,3 @@ T19627.hs:108:3: error: [GHC-05617] |
| 18 | 18 | Not (p a b) -> b <#- a
|
| 19 | 19 | In the class declaration for ‘Lol’
|
| 20 | 20 | |
| 21 | -T19627.hs:108:3: error: [GHC-05617]
|
|
| 22 | - • Could not deduce ‘Not (Not (p0 a1 b1)) ~ p0 a1 b1’
|
|
| 23 | - arising from a superclass required to satisfy ‘Prop (p0 a1 b1)’,
|
|
| 24 | - arising from the head of a quantified constraint
|
|
| 25 | - arising from a superclass required to satisfy ‘Iso p0’,
|
|
| 26 | - arising from a superclass required to satisfy ‘Lol p0’,
|
|
| 27 | - arising from a type ambiguity check for
|
|
| 28 | - the type signature for ‘apartR’
|
|
| 29 | - from the context: Lol p
|
|
| 30 | - bound by the type signature for:
|
|
| 31 | - apartR :: forall (p :: * -> * -> *) a b.
|
|
| 32 | - Lol p =>
|
|
| 33 | - Not (p a b) -> b <#- a
|
|
| 34 | - at T19627.hs:108:3-34
|
|
| 35 | - or from: (Prop a1, Prop b1)
|
|
| 36 | - bound by a quantified context at T19627.hs:108:3-34
|
|
| 37 | - The type variable ‘p0’ is ambiguous
|
|
| 38 | - • In the ambiguity check for ‘apartR’
|
|
| 39 | - To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
|
|
| 40 | - When checking the class method:
|
|
| 41 | - apartR :: forall (p :: * -> * -> *) a b.
|
|
| 42 | - Lol p =>
|
|
| 43 | - Not (p a b) -> b <#- a
|
|
| 44 | - In the class declaration for ‘Lol’
|
|
| 45 | - |
| 1 | - |
|
| 2 | 1 | T21530b.hs:9:5: error: [GHC-83865]
|
| 3 | - • Couldn't match type: Eq a => a -> String
|
|
| 4 | - with: a -> String
|
|
| 2 | + • Couldn't match type: forall a. (Show a, Eq a) => a -> String
|
|
| 3 | + with: forall a. Show a => a -> String
|
|
| 5 | 4 | Expected: (forall a. Show a => a -> String) -> String
|
| 6 | 5 | Actual: (forall a. (Show a, Eq a) => a -> String) -> String
|
| 7 | 6 | • In the expression: f
|
| 8 | 7 | In an equation for ‘g’: g = f
|
| 8 | + |
| 1 | - |
|
| 2 | -T22912.hs:17:16: error: [GHC-39999]
|
|
| 3 | - • Could not deduce ‘Implies c’
|
|
| 4 | - arising from the head of a quantified constraint
|
|
| 1 | +T22912.hs:17:16: error: [GHC-05617]
|
|
| 2 | + • Could not solve: ‘Exactly (Implies c) => Implies c’
|
|
| 5 | 3 | arising from a use of ‘go’
|
| 6 | - from the context: Exactly (Implies c)
|
|
| 7 | - bound by a quantified context at T22912.hs:17:16-17
|
|
| 8 | - Possible fix:
|
|
| 9 | - add (Implies c) to the context of
|
|
| 10 | - the type signature for:
|
|
| 11 | - anythingDict :: forall (c :: Constraint). Dict c
|
|
| 12 | - or If the constraint looks soluble from a superclass of the instance context,
|
|
| 13 | - read 'Undecidable instances and loopy superclasses' in the user manual
|
|
| 14 | 4 | • In the expression: go
|
| 15 | 5 | In an equation for ‘anythingDict’:
|
| 16 | 6 | anythingDict
|
| ... | ... | @@ -18,3 +8,4 @@ T22912.hs:17:16: error: [GHC-39999] |
| 18 | 8 | where
|
| 19 | 9 | go :: (Exactly (Implies c) => Implies c) => Dict c
|
| 20 | 10 | go = Dict
|
| 11 | + |
| 1 | - |
|
| 2 | -tcfail174.hs:20:14: error: [GHC-25897]
|
|
| 3 | - • Couldn't match type ‘a1’ with ‘a’
|
|
| 1 | +tcfail174.hs:20:14: error: [GHC-83865]
|
|
| 2 | + • Couldn't match type: forall a1. a1 -> a1
|
|
| 3 | + with: forall x. x -> a
|
|
| 4 | 4 | Expected: Capture (forall x. x -> a)
|
| 5 | 5 | Actual: Capture (forall a. a -> a)
|
| 6 | - ‘a1’ is a rigid type variable bound by
|
|
| 7 | - the type a -> a
|
|
| 8 | - at tcfail174.hs:20:1-14
|
|
| 9 | - ‘a’ is a rigid type variable bound by
|
|
| 10 | - the inferred type of h1 :: Capture a
|
|
| 11 | - at tcfail174.hs:20:1-14
|
|
| 12 | 6 | • In the first argument of ‘Capture’, namely ‘g’
|
| 13 | 7 | In the expression: Capture g
|
| 14 | 8 | In an equation for ‘h1’: h1 = Capture g
|
| 15 | 9 | • Relevant bindings include
|
| 16 | 10 | h1 :: Capture a (bound at tcfail174.hs:20:1)
|
| 17 | 11 | |
| 18 | -tcfail174.hs:23:14: error: [GHC-25897]
|
|
| 19 | - • Couldn't match type ‘a’ with ‘b’
|
|
| 12 | +tcfail174.hs:23:14: error: [GHC-83865]
|
|
| 13 | + • Couldn't match type: forall a. a -> a
|
|
| 14 | + with: forall x. x -> b
|
|
| 20 | 15 | Expected: Capture (forall x. x -> b)
|
| 21 | 16 | Actual: Capture (forall a. a -> a)
|
| 22 | - ‘a’ is a rigid type variable bound by
|
|
| 23 | - the type a -> a
|
|
| 24 | - at tcfail174.hs:1:1
|
|
| 25 | - ‘b’ is a rigid type variable bound by
|
|
| 26 | - the type signature for:
|
|
| 27 | - h2 :: forall b. Capture b
|
|
| 28 | - at tcfail174.hs:22:1-15
|
|
| 29 | 17 | • In the first argument of ‘Capture’, namely ‘g’
|
| 30 | 18 | In the expression: Capture g
|
| 31 | 19 | In an equation for ‘h2’: h2 = Capture g
|
| 32 | 20 | • Relevant bindings include
|
| 33 | 21 | h2 :: Capture b (bound at tcfail174.hs:23:1)
|
| 22 | + |